Commits

Anonymous committed 6124c3a

Introduce a "caused by" table; record to it; no reconcile yet.

Comments (0)

Files changed (3)

 	for (e = etab->head; e != NULL; e = e->next)
 		event_dump(e);
 }
+
+struct caused_by_table *
+caused_by_table_new(void)
+{
+	struct caused_by_table *ctab;
+
+	MALLOC(ctab, caused_by_table, "caused by table");
+
+	ctab->head = NULL;
+	return(ctab);
+}
+
+struct caused_by *
+caused_by_add(struct caused_by_table *ctab,
+	      struct symstr *ss, struct event *e)
+{
+	struct caused_by *c;
+
+	MALLOC(c, caused_by, "caused by");
+	
+	c->next = ctab->head;
+	c->cause = ss;
+	c->effect = e;
+
+	return(c);
+}
+
+void
+caused_by_reconcile(struct event_table *etab,
+		    struct caused_by_table *ctab)
+{
+	struct caused_by *c;
+	struct event *e;
+
+	for (c = ctab->head; c != NULL; c = c->next) {
+		int match = 0;
+
+		for (e = etab->head; e != NULL; e = e->next) {
+			/* TODO: */
+			/* if c->cause matches e->name, */
+			/* add a consequence from e to */
+			/* to c->effect */
+		}
+
+		if (!match) {
+			/* add an event */
+		}
+	}
+}
 	struct symstr		*later;
 };
 
+struct caused_by_table {
+	struct caused_by        *head;
+};
+
+struct caused_by {
+	struct caused_by	*next;
+	struct symstr		*cause; 	/* name of triggering event */
+	struct event		*effect;	/* event to trigger */
+};
+
+
 struct event_table	*event_table_new(void);
 struct event		*event_new(struct event_table *);
 struct consequence	*event_consequence_append(struct event *,
 int			 event_happen(struct event *, struct equeue *,
 				      struct ehist *);
 
+struct caused_by_table	*caused_by_table_new(void);
+struct caused_by	*caused_by_add(struct caused_by_table *,
+				       struct symstr *,
+				       struct event *);
+void			 caused_by_reconcile(struct event_table *,
+					     struct caused_by_table *);
+
 #endif /* !__EVENT_H */
 #include "etime.h"
 #include "2iota.h"
 
+static struct caused_by_table *caused_by;
+
 /* ---------------- EVENT STRUCTURE (beta-Juliet) ----------------*/
 
 void
 two_iota(struct scan_st *sc)
 {
-	decl(sc);
+        caused_by = caused_by_table_new();
+
+        decl(sc);
 	while (tokeq(sc, ";")) {
 		scan(sc);
 		decl(sc);
 	}
 	scan_expect(sc, ".");
+
+	caused_by_reconcile(event_table, caused_by);
 }
 
 void
 		if (tokeq(sc, "by") || tokeq(sc, "after")) {
 			scan(sc);
 			ss = event_appl_literal(sc);
-			/*
-			 * TODO: add ss to a set of "caused by"'s
-			 * TODO: after parsing, reconcile "caused by"'s
-			*/
+			(void)caused_by_add(caused_by, ss, e);
 		} else {
 			scan_error(sc, "Expected 'by' or 'after'");
 		}