summaryrefslogtreecommitdiffstats
path: root/rpmconstant/rpmconstant.c
diff options
context:
space:
mode:
authornanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c>2005-10-04 04:07:38 +0000
committernanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c>2005-10-04 04:07:38 +0000
commit588601a22c421404c9db24e0a47330d2186977f9 (patch)
treeedf817859fca80f58f52cded432f66d7454e8f27 /rpmconstant/rpmconstant.c
parentfd81fe87c5332d078d504271b7fbbb5ef27f6741 (diff)
downloadperl-RPM4-588601a22c421404c9db24e0a47330d2186977f9.tar
perl-RPM4-588601a22c421404c9db24e0a47330d2186977f9.tar.gz
perl-RPM4-588601a22c421404c9db24e0a47330d2186977f9.tar.bz2
perl-RPM4-588601a22c421404c9db24e0a47330d2186977f9.tar.xz
perl-RPM4-588601a22c421404c9db24e0a47330d2186977f9.zip
- move to trunk
git-svn-id: svn+ssh://haiku.zarb.org/home/projects/rpm4/svn/trunk@35 971eb68f-4bfb-0310-8326-d2484c010a4c
Diffstat (limited to 'rpmconstant/rpmconstant.c')
-rw-r--r--rpmconstant/rpmconstant.c191
1 files changed, 191 insertions, 0 deletions
diff --git a/rpmconstant/rpmconstant.c b/rpmconstant/rpmconstant.c
new file mode 100644
index 0000000..910cb5f
--- /dev/null
+++ b/rpmconstant/rpmconstant.c
@@ -0,0 +1,191 @@
+/* Nanar <nanardon@mandrake.org>
+ * $Id$
+ */
+
+#include <string.h>
+#define RPMCONSTANT_INTERNAL
+#include "rpmconstant.h"
+
+rpmconst rpmconstNew()
+{
+ rpmconst c = NULL;
+ c = xcalloc(1, sizeof(*c));
+ c->list = NULL;
+ c->constant = NULL;
+ return c;
+}
+
+rpmconst rpmconstFree(rpmconst c)
+{
+ free(c);
+ return c = NULL;
+}
+
+void rpmconstInitC(rpmconst c)
+{
+ c->constant = NULL;
+}
+
+int rpmconstNextC(rpmconst c)
+{
+ if (c->list == NULL)
+ return 0;
+ c->constant = c->constant == NULL ?
+ rpmConstantListC(c->list) :
+ rpmConstantNext(c->constant);
+ return c->constant == NULL ? 0 : 1;
+}
+
+
+void rpmconstInitL(rpmconst c)
+{
+ c->list = NULL;
+ c->constant = NULL;
+}
+
+int rpmconstNextL(rpmconst c)
+{
+ c->list = c->list == NULL ?
+ (void *) rpmconstanttype :
+ rpmConstantListNext(c->list);
+ c->constant = NULL;
+ return c->list == NULL ? 0 : 1;
+}
+
+const char * rpmconstContext(rpmconst c)
+{
+ return rpmConstantListContext(c->list);
+}
+
+const char * rpmconstPrefix(rpmconst c)
+{
+ return rpmConstantListPrefix(c->list);
+}
+
+const char * rpmconstName(rpmconst c, int stripprefix)
+{
+ char * name;
+ int len;
+ name = rpmConstantName(c->constant);
+ if (stripprefix && name && rpmConstantListPrefix(c->list)) {
+ len = strlen(rpmConstantListPrefix(c->list));
+ name += len < strlen(name) ? len : 0;
+ }
+ return name;
+}
+
+int rpmconstValue(rpmconst c)
+{
+ return rpmConstantValue(c->constant);
+}
+
+int rpmconstInitToContext(rpmconst c, const char * context)
+{
+ char * lccontext = strdup(context);
+ char * ptr;
+ int rc = 0;
+ for (ptr = lccontext; *ptr != 0; ptr++)
+ *ptr = tolower(*ptr);
+ if (!context) return 0; /* programmer error */
+ rpmconstInitL(c);
+ while (rpmconstNextL(c)) {
+ if (!strcmp(lccontext, rpmconstContext(c))) {
+ rc = 1;
+ break;
+ }
+ }
+ free(lccontext);
+ return rc; /* not found */
+}
+
+int rpmconstNameMatch(rpmconst c, const char * name, int prefixed)
+{
+ char * uc;
+ int rc = 0;
+ char * ucname = strdup(name);
+
+ for (uc = ucname; *uc != 0; uc++)
+ *uc = toupper(*uc);
+
+ if (!prefixed) prefixed = ALLCASE_PREFIX;
+ if (prefixed & WITH_PREFIX)
+ if (strcmp(ucname, rpmconstName(c, PREFIXED_YES)) == 0)
+ rc = 1;
+ if (!rc && (prefixed & WITHOUT_PREFIX))
+ if (strcmp(ucname, rpmconstName(c, PREFIXED_NO)) == 0)
+ rc = 1;
+ free(ucname);
+ return rc;
+}
+
+int rpmconstFindValue(rpmconst c, const int val)
+{
+ rpmconstInitC(c);
+ while (rpmconstNextC(c)) {
+ if (val == rpmconstValue(c))
+ return 1;
+ }
+ return 0;
+}
+
+int rpmconstFindMask(rpmconst c, const int val)
+{
+ rpmconstInitC(c);
+ while (rpmconstNextC(c)) {
+ if (!rpmconstValue(c))
+ continue;
+ if (rpmconstValue(c) & val)
+ return 1;
+ }
+ return 0;
+}
+
+int rpmconstFindName(rpmconst c, const char * name, int prefixed)
+{
+ rpmconstInitC(c);
+ while (rpmconstNextC(c)) {
+ if (rpmconstNameMatch(c, name, prefixed))
+ return 1;
+ }
+ return 0;
+}
+
+int rpmconstantFindValue(char * context, const int val, const char **name, int prefixed)
+{
+ int rc = 0;
+ rpmconst c = rpmconstNew();
+ if (rpmconstInitToContext(c, context))
+ if (rpmconstFindValue(c, val)) {
+ *name = rpmconstName(c, prefixed);
+ rc = 1;
+ }
+ c = rpmconstFree(c);
+ return rc;
+}
+
+int rpmconstantFindMask(char * context, const int val, const char **name, int prefixed)
+{
+ int rc = 0;
+ rpmconst c = rpmconstNew();
+ if (rpmconstInitToContext(c, context))
+ if (rpmconstFindMask(c, val)) {
+ *name = rpmconstName(c, prefixed);
+ rc = rpmconstValue(c);
+ }
+ c = rpmconstFree(c);
+ return rc;
+}
+
+int rpmconstantFindName(char * context, const char * name, int *val, int prefixed)
+{
+ int rc = 0;
+ rpmconst c = rpmconstNew();
+ if (rpmconstInitToContext(c, context)) {
+ if (rpmconstFindName(c, name, prefixed)) {
+ *val |= rpmconstValue(c);
+ rc = 1;
+ }
+ }
+ c = rpmconstFree(c);
+ return rc;
+}