RPA Toolkit
Refined rpa_records_* interface.
authorMartin Stoilov <martin@rpasearch.com>
Wed, 25 May 2011 06:17:08 +0000 (23:17 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Wed, 25 May 2011 06:17:08 +0000 (23:17 -0700)
rgrep/rpagrep.c
rjs/rjs.c
rpa/rparecord.c
rpa/rparecord.h

index fa2d712..ae635e9 100644 (file)
@@ -232,7 +232,7 @@ int rpa_grep_parse(rpa_grep_t *pGrep, const char* buffer, unsigned long size)
        rlong i;
        rchar location[128];
        rpastat_t *hStat;
-       rarray_t *records = rpa_record_array();
+       rarray_t *records = rpa_records_create();
        rparecord_t *prec;
        const char *input = buffer, *start = buffer, *end = buffer + size;
 
@@ -266,8 +266,8 @@ int rpa_grep_parse(rpa_grep_t *pGrep, const char* buffer, unsigned long size)
 
        } else {
                if (pGrep->greptype == RPA_GREPTYPE_PARSE) {
-                       for (i = 0; i < r_array_length(records); i++) {
-                               prec = (rparecord_t *)r_array_slot(records, i);
+                       for (i = 0; i < rpa_records_length(records); i++) {
+                               prec = (rparecord_t *)rpa_records_slot(records, i);
                                if (prec->type & RPA_RECORD_END) {
                                        rpa_grep_output_utf8_string(pGrep, prec->rule);
                                        r_snprintf(location, sizeof(location), " (%ld, %ld)", (rlong)(prec->input - input), (rlong)prec->inputsiz);
@@ -278,13 +278,13 @@ int rpa_grep_parse(rpa_grep_t *pGrep, const char* buffer, unsigned long size)
                                }
                        }
                } else if (pGrep->greptype == RPA_GREPTYPE_PARSEAST) {
-                       for (i = 0; i < r_array_length(records); i++) {
+                       for (i = 0; i < rpa_records_length(records); i++) {
                                rpa_record_dump(records, i);
                        }
 
                }
        }
-       r_array_destroy(records);
+       rpa_records_destroy(records);
        pGrep->cachehit = hStat->cache->hit;
        rpa_stat_destroy(hStat);
        return 0;
index 016c027..e528912 100644 (file)
--- a/rjs/rjs.c
+++ b/rjs/rjs.c
@@ -87,7 +87,7 @@ static rint rjs_engine_parse(rjs_engine_t *jse, const rchar *script, rsize_t siz
 rint rjs_engine_compile(rjs_engine_t *jse, const rchar *script, rsize_t size)
 {
        rvm_codegen_t *topcg = NULL;
-       rarray_t *records = rpa_record_array();
+       rarray_t *records = rpa_records_create();
        jse->co->debug = jse->debugcompile;
 
        if (rjs_engine_parse(jse, script, size, records) < 0) {
@@ -108,18 +108,18 @@ rint rjs_engine_compile(rjs_engine_t *jse, const rchar *script, rsize_t size)
                goto err;
        }
 
-       r_array_destroy(records);
+       rpa_records_destroy(records);
        return 0;
 
 err:
-       r_array_destroy(records);
+       rpa_records_destroy(records);
        return -1;
 }
 
 
 rint rjs_engine_dumpast(rjs_engine_t *jse, const rchar *script, rsize_t size)
 {
-       rarray_t *records = rpa_record_array();
+       rarray_t *records = rpa_records_create();
        if (rjs_engine_parse(jse, script, size, records) < 0) {
 
 
@@ -128,11 +128,11 @@ rint rjs_engine_dumpast(rjs_engine_t *jse, const rchar *script, rsize_t size)
 
        if (records) {
                rlong i;
-               for (i = 0; i < r_array_length(records); i++)
+               for (i = 0; i < rpa_records_length(records); i++)
                        rpa_record_dump(records, i);
        }
 
-       r_array_destroy(records);
+       rpa_records_destroy(records);
        return 0;
 }
 
index a84355b..00dde9f 100644 (file)
@@ -438,10 +438,29 @@ void rpa_record_dumpindented(rarray_t *records, rlong rec, rint level)
 }
 
 
-rarray_t *rpa_record_array()
+rarray_t *rpa_records_create()
 {
        rarray_t *records;
 
        records = r_array_create(sizeof(rparecord_t));
        return records;
 }
+
+void rpa_records_destroy(rarray_t *records)
+{
+       r_array_destroy(records);
+}
+
+
+rlong rpa_records_length(rarray_t *records)
+{
+       return r_array_length(records);
+}
+
+
+rparecord_t *rpa_records_slot(rarray_t *records, rlong index)
+{
+       if (index < 0 || index >= r_array_length(records))
+               return NULL;
+       return (rparecord_t *)r_array_slot(records, index);
+}
index 8a90d58..ea61255 100644 (file)
@@ -94,7 +94,11 @@ void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rval
 rlong rpa_record_getusertype(rarray_t *records, rlong rec);
 rint rpa_record_optchar(rparecord_t *prec, rint defc);
 rint rpa_record_loopchar(rparecord_t *prec, rint defc);
-rarray_t *rpa_record_array();
+rarray_t *rpa_records_create();
+void rpa_records_destroy(rarray_t *records);
+rlong rpa_records_length(rarray_t *records);
+rparecord_t *rpa_records_slot(rarray_t *records, rlong index);
+
 #ifdef __cplusplus
 }
 #endif