void cref(char *name, FILE *fp, Table_T identifiers) { char buf[512]; Text_T filename = { 0, "" }; int linenum; if (name) filename = Text_put(name); for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) { Text_T id, line = Text_put(buf); while ((id = getword(&line, first, rest)).len > 0) { Ring_T ring; Table_T files; files = Table_get(identifiers, &id); if (files == NULL) { files = Table_new(0, textcmp, texthash); Table_put(identifiers, copy(id), files); } ring = Table_get(files, &filename); if (ring == NULL) { ring = Ring_new(); Table_put(files, copy(filename), ring); Ring_addlo(ring, Integer_new(linenum)); } else if (Integer_get(Ring_get(ring, 0)) != linenum) Ring_addlo(ring, Integer_new(linenum)); } } }
Text_T File_reader_reader(const char *pathname, const char *filter) { int c, i, max = BUFFSIZE; char *buf = ALLOC(max); Text_T doc; FILE *in; // debug Fmt_register('T', Text_fmt); Fmt_fprint(stderr, "%s\n", pathname); Fmt_fprint(stderr, "BUFFSIZE: %d\n", BUFFSIZE); if ((in = fopen(pathname, "r")) == NULL) err(1, "%s", pathname); for (c = fgetc(in), i = 0; c != EOF; c = fgetc(in), i++) { if (i == max) { // max buf RESIZE(buf, max <<= 1); } buf[i] = c; } doc = Text_put(buf); Fmt_fprint(stderr, "%T\n", &doc); return doc; }