summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorroot <devnull@localhost>1996-11-14 17:37:06 +0000
committerroot <devnull@localhost>1996-11-14 17:37:06 +0000
commit098609bcf66f7418cdc387781dfe2f4bac60ea13 (patch)
tree617cb942ca5b94e58e5ca7a1daea5e55687ec556 /build
parent64a4f1d940106da168e7c584d40da79773c9afff (diff)
downloadrpm-098609bcf66f7418cdc387781dfe2f4bac60ea13.tar.gz
rpm-098609bcf66f7418cdc387781dfe2f4bac60ea13.tar.bz2
rpm-098609bcf66f7418cdc387781dfe2f4bac60ea13.zip
Initial revision
CVS patchset: 1159 CVS date: 1996/11/14 17:37:06
Diffstat (limited to 'build')
-rw-r--r--build/trigger.c149
-rw-r--r--build/trigger.h13
2 files changed, 162 insertions, 0 deletions
diff --git a/build/trigger.c b/build/trigger.c
new file mode 100644
index 000000000..5f9242c4c
--- /dev/null
+++ b/build/trigger.c
@@ -0,0 +1,149 @@
+/* handle triggers */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "trigger.h"
+#include "header.h"
+#include "spec.h"
+#include "specP.h"
+#include "rpmerr.h"
+#include "messages.h"
+#include "rpmlib.h"
+#include "stringbuf.h"
+#include "misc.h"
+
+#define FREE(x) { if (x) free(x); }
+#define CHUNK 8
+
+int addTrigger(struct PackageRec *package,
+ int sense, char *script, char *args)
+{
+ struct TriggerEntry *te;
+ int i;
+ char *arg = NULL;
+ struct ReqComp *rc = NULL;
+ char *version;
+
+ /* add the script */
+ i = package->trigger.used++;
+ if (i == package->trigger.alloced) {
+ /* extend */
+ package->trigger.alloced += CHUNK;
+ package->trigger.triggerScripts =
+ realloc(package->trigger.triggerScripts,
+ package->trigger.alloced *
+ sizeof(*(package->trigger.triggerScripts)));
+ }
+ package->trigger.triggerScripts[i] = strdup(script);
+ message(MESS_DEBUG, "TRIGGER %d:\n%s", i, script);
+
+ /* create the entry (or entries) */
+ te = NULL;
+ while (arg || (arg = strtok(args, " ,\t\n"))) {
+ if (!te) {
+ te = malloc(sizeof(*te));
+ te->flags = sense;
+ }
+ if ((version = strtok(NULL, " ,\t\n"))) {
+ rc = ReqComparisons;
+ while (rc->token && strcmp(version, rc->token)) {
+ rc++;
+ }
+ if (rc->token) {
+ /* read a version */
+ te->flags |= rc->flags;
+ version = strtok(NULL, " ,\t\n");
+ }
+ }
+ if ((te->flags & REQUIRE_SENSEMASK) && !version) {
+ error(RPMERR_BADSPEC, "Version required in trigger");
+ return RPMERR_BADSPEC;
+ }
+ te->name = strdup(arg);
+ te->version = (rc && rc->token && version) ? strdup(version) : NULL;
+ te->index = i;
+
+ message(MESS_DEBUG, "TRIGGER(%s): %s %s %s %d\n",
+ (sense == TRIGGER_ON) ? "on" : "off",
+ te->name,
+ (rc && rc->token) ? rc->token : "NONE",
+ te->version, te->index);
+
+ /* link it in */
+ te->next = package->trigger.trigger;
+ package->trigger.trigger = te;
+ package->trigger.triggerCount++;
+ te = NULL;
+
+ /* prepare for next round */
+ arg = NULL;
+ if (! (rc && rc->token)) {
+ /* No version -- we just read a name */
+ arg = version;
+ }
+ args = NULL;
+ }
+
+ return 0;
+}
+
+void generateTriggerEntries(Header h, struct PackageRec *p)
+{
+ struct TriggerEntry *te;
+ int i;
+ char **nameArray;
+ char **versionArray;
+ int_32 *flagArray;
+ int_32 *indexArray;
+
+ /* Add the scripts */
+
+ if (p->trigger.used) {
+ addEntry(h, RPMTAG_TRIGGERSCRIPTS, STRING_ARRAY_TYPE,
+ p->trigger.triggerScripts, p->trigger.used);
+ }
+
+ /* Add the entries */
+
+ nameArray = malloc(p->trigger.triggerCount * sizeof(*nameArray));
+ versionArray = malloc(p->trigger.triggerCount * sizeof(*versionArray));
+ flagArray = malloc(p->trigger.triggerCount * sizeof(*flagArray));
+ indexArray = malloc(p->trigger.triggerCount * sizeof(*indexArray));
+
+ te = p->trigger.trigger;
+ i = 0;
+ while (te) {
+ nameArray[i] = te->name;
+ versionArray[i] = te->version ? te->version : "";
+ flagArray[i] = te->flags;
+ indexArray[i] = te->index;
+ i++;
+ te = te->next;
+ }
+
+ addEntry(h, RPMTAG_TRIGGERNAME, STRING_ARRAY_TYPE, nameArray, i);
+ addEntry(h, RPMTAG_TRIGGERVERSION, STRING_ARRAY_TYPE, versionArray, i);
+ addEntry(h, RPMTAG_TRIGGERFLAGS, INT32_TYPE, flagArray, i);
+ addEntry(h, RPMTAG_TRIGGERINDEX, INT32_TYPE, indexArray, i);
+}
+
+void freeTriggers(struct TriggerStruct t)
+{
+ char **s;
+ struct TriggerEntry *te;
+
+ s = t.triggerScripts;
+ while (t.used--) {
+ FREE(*s++);
+ }
+ FREE(t.triggerScripts);
+
+ while (t.trigger) {
+ te = t.trigger;
+ t.trigger = t.trigger->next;
+ FREE(te->name);
+ FREE(te->version);
+ free(te);
+ }
+}
diff --git a/build/trigger.h b/build/trigger.h
new file mode 100644
index 000000000..00fc483f4
--- /dev/null
+++ b/build/trigger.h
@@ -0,0 +1,13 @@
+#ifndef _TRIGGER_H_
+#define _TRIGGER_H_
+
+#include "specP.h"
+
+int addTrigger(struct PackageRec *package,
+ int sense, char *script, char *args);
+
+void generateTriggerEntries(Header h, struct PackageRec *p);
+
+void freeTriggers(struct TriggerStruct t);
+
+#endif _TRIGGER_H_