#include "shred.h"
/* control bits */
-int remove_braces = 0;
-int remove_whitespace = 0;
-int remove_comments = 0;
+static int remove_braces = 0;
+static int remove_whitespace = 0;
+static int remove_comments = 0;
static char *c_patterns[] = {
/* Idioms that don't convey any meaning in isolation */
static linenum_t linecount;
-void analyzer_init(void)
+void analyzer_init(unsigned int flags)
/* initialize line filtering */
{
int i;
shell_patterns[i]);
exit(1);
}
+
+ if (flags & CAPC_FLAG)
+ remove_braces = remove_whitespace = 1;
+ if (flags & R_FLAG)
+ remove_comments = 1;
+ if (flags & W_FLAG)
+ remove_whitespace = 1;
}
static unsigned char active = 0;
free(text);
}
+void analyzer_dump(char *buf)
+/* dump a Normalization line representing current options */
+{
+ strcpy(buf, "line-oriented, ");
+ if (remove_whitespace)
+ strcat(buf, "remove-whitespace, ");
+ if (remove_comments)
+ strcat(buf, "remove-comments, ");
+ if (remove_braces)
+ strcat(buf, "remove-braces, ");
+ if (buf[0])
+ buf[strlen(buf)-2] = '\0';
+}
+
/* our method table */
struct analyzer_t linebyline =
{
mode: analyzer_mode,
get: analyzer_get,
free: analyzer_free,
+ dump: analyzer_dump,
};
#ifdef TEST
chunk_buffer[chunk_count-1].end = linenumber;
}
-static void write_options(char *buf)
-/* dump a Normalization line representing current options */
-{
- buf[0] = '\0';
- if (remove_whitespace)
- strcat(buf, "remove-whitespace, ");
- if (remove_comments)
- strcat(buf, "remove-comments, ");
- if (remove_braces)
- strcat(buf, "remove-braces, ");
- if (buf[0])
- buf[strlen(buf)-2] = '\0';
- else
- strcpy(buf, "none");
-}
-
static void write_scf(const char *tree, FILE *ofp)
/* generate shred file for given tree */
{
fputs("#SCF-A 2.0\n", ofp);
fputs("Generator-Program: comparator 1.0\n", ofp);
fputs("Hash-Method: " HASHMETHOD "\n", ofp);
- write_options(buf);
+ linebyline.dump(buf);
fprintf(ofp, "Normalization: %s\n", buf);
fprintf(ofp, "Root: %s\n", tree);
fprintf(ofp, "Shred-Size: %d\n", shredsize);
char buf[BUFSIZ];
scf->hash_method = HASHMETHOD;
- write_options(buf);
+ linebyline.dump(buf);
scf->normalization = strdup(buf);
scf->shred_size = shredsize;
scf->generator_program = "comparator " VERSION;
extern char *optarg; /* set by getopt */
extern int optind; /* set by getopt */
- int status, file_only, compile_only, argcount, mergecount;
+ int status, file_only, compile_only, argcount, mergecount, flags;
struct scf_t *scf;
char *dir, *outfile;
- compile_only = file_only = nofilter = 0;
+ compile_only = file_only = nofilter = flags = 0;
dir = outfile = NULL;
while ((status = getopt(argc, argv, "cCd:hm:no:rs:vwx")) != EOF)
{
break;
case 'C':
- remove_whitespace = remove_braces = 1;
+ flags |= CAPC_FLAG;
break;
case 'd':
break;
case 'r':
- remove_comments = 1;
+ flags |= R_FLAG;
break;
case 's':
break;
case 'w':
- remove_whitespace = 1;
+ flags |= W_FLAG;
break;
case 'x':
usage();
report_time(NULL);
- linebyline.init();
+ linebyline.init(flags);
/* special case if user gave exactly one tree */
if (!compile_only && argcount == 1)
struct analyzer_t /* structure describing a feature analyzer */
{
- void (*init)(void);
+ unsigned int flags;
+#define CAPC_FLAG 0x01
+#define R_FLAG 0x02
+#define W_FLAG 0x04
+ void (*init)(unsigned int);
void (*mode)(int);
feature_t *(*get)(const struct filehdr_t *, FILE *, linenum_t *);
void (*free)(const char *);
+ void (*dump)(char *);
};
/* control bits, meant to be set at startup */
-extern int remove_braces;
-extern int remove_whitespace;
-extern int remove_comments;
extern int verbose, debug, nofilter;
extern int shredsize, minsize;