RPA Toolkit
Currently bitmap and abort directive are incompatible. Work in progress to resolve...
authorMartin Stoilov <martin@sigmadrone.org>
Fri, 23 Oct 2015 07:11:32 +0000 (00:11 -0700)
committerMartin Stoilov <martin@sigmadrone.org>
Fri, 23 Oct 2015 07:11:32 +0000 (00:11 -0700)
rpa/rpabitmap.c
rpa/rpacompiler.h
rpa/rpadbex.c
rpa/rpadbexpriv.h
rpa/rparecord.c

index 7e7b3f7..dc1d0c2 100644 (file)
@@ -24,6 +24,7 @@
 #include "rpa/rpaparser.h"
 #include "rpa/rpadbexpriv.h"
 #include "rpa/rpastatpriv.h"
+#include "rpa/rpacompiler.h"
 
 static long rpa_bitmap_set(rarray_t *records, long rec, rpointer userdata);
 
@@ -40,6 +41,8 @@ void rpa_dbex_buildbitmapinfo_for_rule(rpadbex_t *dbex, rparule_t rid)
        rpa_bitmapcompiler_t bc;
        rharray_t *rules = dbex->rules;
        rpa_ruleinfo_t *info;
+       const char *name = rpa_dbex_name(dbex, rid);
+       unsigned long namesize;
 
        r_memset(&bc, 0, sizeof(bc));
        bc.dbex = dbex;
@@ -47,8 +50,11 @@ void rpa_dbex_buildbitmapinfo_for_rule(rpadbex_t *dbex, rparule_t rid)
                rparecord_t *record = rpa_record_get(dbex->records, info->startrec);
                RPA_BITMAP_SETALL(RPA_RECORD2BITMAP(record));
                rpa_recordtree_walk(dbex->records, info->startrec, 0, rpa_bitmap_set, (rpointer)&bc);
+               if (r_harray_lookup_s(dbex->abortrules, rpa_dbex_name(dbex, rid)) >= 0) {
+                       RPA_BITMAP_SETALL(RPA_RECORD2BITMAP(rpa_record_get(dbex->records, info->startrec)));
+                       RPA_BITMAP_SETALL(RPA_RECORD2BITMAP(rpa_record_get(dbex->records, rpa_recordtree_get(dbex->records, info->startrec, RPA_RECORD_END))));
+               }
        }
-
 }
 
 
@@ -70,7 +76,6 @@ ruword rpa_dbex_getrulebitmap(rpadbex_t *dbex, rparule_t rid)
        return bitmap;
 }
 
-
 void rpa_dbex_buildbitmapinfo(rpadbex_t *dbex)
 {
        unsigned int i;
index b779056..bc3cfea 100644 (file)
@@ -137,6 +137,9 @@ void rpa_compiler_rulepref_clear_flag(rpa_compiler_t *co, const char *name, unsi
 void rpa_compiler_rulepref_clear_flag_s(rpa_compiler_t *co, const char *name, unsigned long flag);
 void rpa_compiler_rulepref_set(rpa_compiler_t *co, const char *name, unsigned int namesize, long ruleid, long ruleuid, unsigned long flags);
 void rpa_compiler_rulepref_set_s(rpa_compiler_t *co, const char *name, long ruleid, long ruleuid, unsigned long flags);
+rpa_rulepref_t *rpa_compiler_rulepref(rpa_compiler_t *co, const char *name, unsigned int namesize);
+rpa_rulepref_t *rpa_compiler_rulepref_lookup_s(rpa_compiler_t *co, const char *name);
+
 #ifdef __cplusplus
 }
 #endif
index c68fb89..7f36d8d 100644 (file)
@@ -249,6 +249,7 @@ static int rpa_dbex_rh_abort(rpadbex_t *dbex, long rec)
        unsigned long namesize;
        rarray_t *records = dbex->records;
        rparecord_t *prec;
+       rparule_t notset = 0L;
 
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
        prec = rpa_dbex_record(dbex, rec);
@@ -257,6 +258,7 @@ static int rpa_dbex_rh_abort(rpadbex_t *dbex, long rec)
        if (rpa_dbex_rulename(dbex, rec, &name, &namesize) < 0) {
                return -1;
        }
+       r_harray_add(dbex->abortrules, name, namesize, &notset);
        rpa_compiler_rulepref_set_flag(dbex->co, name, namesize, RPA_RFLAG_ABORTONFAIL);
        rpa_dbex_debug_recordtail(dbex, rec);
        if (rpa_dbex_playchildrecords(dbex, rec) < 0)
@@ -996,6 +998,7 @@ rpadbex_t *rpa_dbex_create(void)
        dbex->records = r_array_create(sizeof(rparecord_t));
        dbex->temprecords = r_array_create(sizeof(rparecord_t));
        dbex->rules = r_harray_create(sizeof(rpa_ruleinfo_t));
+       dbex->abortrules = r_harray_create(sizeof(rparule_t));          /* We never populate the rule id anyway. we use the name for now */
        dbex->recstack = r_array_create(sizeof(unsigned long));
        dbex->inlinestack = r_array_create(sizeof(unsigned long));
        dbex->handlers = r_zmalloc(sizeof(rpa_dbex_recordhandler) * RPA_PRODUCTION_COUNT);
@@ -1045,6 +1048,7 @@ void rpa_dbex_destroy(rpadbex_t *dbex)
                rpa_compiler_destroy(dbex->co);
                rpa_parser_destroy(dbex->pa);
                r_harray_destroy(dbex->rules);
+               r_harray_destroy(dbex->abortrules);
                r_array_destroy(dbex->records);
                r_array_destroy(dbex->temprecords);
                r_array_destroy(dbex->recstack);
@@ -1355,8 +1359,8 @@ void rpa_dbex_close(rpadbex_t *dbex)
                return;
        rpa_dbex_buildruleinfo(dbex);
        rpa_dbex_buildloopinfo(dbex);
-       if (dbex->bitmap)
-               rpa_dbex_buildbitmapinfo(dbex);
+//     if (dbex->bitmap)
+//             rpa_dbex_buildbitmapinfo(dbex);
 }
 
 
@@ -1869,6 +1873,9 @@ int rpa_dbex_compile(rpadbex_t *dbex)
        rpa_dbex_setemit(dbex, TRUE);
 
        for (rid = rpa_dbex_first(dbex); rid >= 0; rid = rpa_dbex_next(dbex, rid)) {
+               if (dbex->bitmap)
+                       rpa_dbex_getrulebitmap(dbex, rid);
+
                if (rpa_dbex_compile_rule(dbex, rid) < 0) {
                        RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_COMPILE);
                        return -1;
index 8eadaa7..c160f7f 100644 (file)
@@ -57,6 +57,7 @@ struct rpadbex_s {
        rarray_t *records;
        rarray_t *temprecords;
        rharray_t *rules;
+       rharray_t *abortrules; // these are rules used in (#!abort rulename) directive
        rarray_t *recstack;
        rarray_t *inlinestack;
        rarray_t *text;
index 02078c7..88e384c 100644 (file)
@@ -389,7 +389,7 @@ void rpa_record_dump(rarray_t *records, long rec)
        n = 90;
        n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, " %5d, %4d", prec->top, prec->size);
 
-#if 0
+#if 1
        r_memset(buf + n, ' ', bufsize - n);
        n = 105;
        n += r_snprintf(buf + n, n < bufsize ? bufsize - n : 0, "[ 0x%016lx ]", prec->userdata);