]> thyrsus.com Git - comparator.git/commitdiff
Feature analysis is now done through a method table.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 19 Sep 2003 12:15:46 +0000 (12:15 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 19 Sep 2003 12:15:46 +0000 (12:15 +0000)
linebyline.c
main.c
shred.h
shredtree.c

index b3302f3c6d69e0de3f8d67cf737f77f5b317183e..7b212b4633d255bd1c477aaf46d58b8aaa1ecf60 100644 (file)
@@ -260,6 +260,15 @@ void analyzer_free(const char *text)
     free(text);
 }
 
+/* our method table */
+struct analyzer_t linebyline =
+{
+    init: analyzer_init,
+    mode: analyzer_mode,
+    get:  analyzer_get,
+    free: analyzer_free,
+};
+
 #ifdef TEST
 int main(int argc, char *argv[])
 {
diff --git a/main.c b/main.c
index 913f760afa44a9c29dd24e3af09bef386a39d4f8..037b15ddbdc0ba06abf9915769112eb3ea813fae 100644 (file)
--- a/main.c
+++ b/main.c
@@ -522,7 +522,7 @@ main(int argc, char *argv[])
        usage();
 
     report_time(NULL);
-    analyzer_init();
+    linebyline.init();
 
     /* special case if user gave exactly one tree */
     if (!compile_only && argcount == 1)
diff --git a/shred.h b/shred.h
index 8fb366a3e583953456ed905c152279c3ccbad9e5..c40f7f066ec4109fd0b09d7a582b3fcc371cbed7 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -39,26 +39,34 @@ struct hash_t
 };
 #define SORTHASHCMP(s, t) hash_compare((s)->hash.hash, (t)->hash.hash)
 
-struct filehdr_t
+struct filehdr_t       /* file/attributes structure describing input source */
 {
     char       *name;
     linenum_t  length;
     struct filehdr_t *next;
 };
 
-struct sorthash_t
+struct sorthash_t      /* in-core hash with pointer to input source */
 {
     struct hash_t      hash;
     struct filehdr_t   *file;
 };
 
-typedef struct
+typedef struct         /* structure describing an input feature */
 {
     char       *text;
     int                flags;
 }
 feature_t;
 
+struct analyzer_t      /* structure describing a feature analyzer */
+{
+    void (*init)(void);
+    void (*mode)(int);
+    feature_t *(*get)(const struct filehdr_t *, FILE *, linenum_t *);
+    void (*free)(const char *);
+};
+
 /* control bits, meant to be set at startup */
 extern int remove_braces;
 extern int remove_whitespace;
@@ -81,12 +89,8 @@ extern int shredfile(struct filehdr_t *,
                     void (*hook)(struct hash_t, struct filehdr_t *));
 extern void sort_hashes(struct sorthash_t *hashlist, int hashcount);
 
-/* linebyline.c functions */
-extern void analyzer_init(void);
-extern void analyzer_mode(int);
-extern feature_t *analyzer_get(const struct filehdr_t *,
-                              FILE *, linenum_t *linenumber);
-extern void analyzer_free(const char *);
+/* linebyline.c feature analyzer */
+struct analyzer_t linebyline;
 
 /* shredcompare.c functions */
 extern int merge_compare(struct sorthash_t *obarray, int hashcount);
index 16821d0f37c005ed0f16d958d3cb55fe4ad6329a..647397d4cece9f3b730ef327f024128b563de479 100644 (file)
@@ -130,17 +130,17 @@ int shredfile(struct filehdr_t *file,
 
     /* deduce what filtering type we should use */
 #define endswith(suff) !strcmp(suff,file->name+strlen(file->name)-strlen(suff))
-    analyzer_mode(0);
+    linebyline.mode(0);
     if (endswith(".c") || endswith(".h"))
-       analyzer_mode(C_CODE);
+       linebyline.mode(C_CODE);
     else if (endswith(".sh"))
-       analyzer_mode(SHELL_CODE);
+       linebyline.mode(SHELL_CODE);
 #undef endswith
 
     display = (shred *)calloc(sizeof(shred), shredsize);
 
     linenumber = accepted = 0;
-    while ((feature = analyzer_get(file, fp, &linenumber)))
+    while ((feature = linebyline.get(file, fp, &linenumber)))
     {
        accepted++;
 
@@ -154,7 +154,7 @@ int shredfile(struct filehdr_t *file,
            hook(emit_chunk(display, linenumber), file);
 
        /* shreds in progress are shifted down */
-       analyzer_free(display[0].feature);
+       linebyline.free(display[0].feature);
        for (i=1; i < shredsize; i++)
            display[i-1] = display[i];
        display[shredsize-1].feature = NULL;