};
#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;
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);
/* 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++;
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;