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; }
int main(int argc, const char *argv[]) { T suite; Tag_E f, g; char *tb = "table"; Fmt_fprint(stderr, "==> Starting %s <==\n", __FILE__); Lookup_T tbl = Tag_lookup_init(); f = Tag_lookup_tag(&tbl, tb); f |= T_YATTR; Fmt_fprint(stderr, "%s -> %s\n", tb, Tag_type_rep(f)); f = Tag_lookup_tag(&tbl, "html"); f |= T_NATTR; Fmt_fprint(stderr, "%s -> %s\n", "html", Tag_type_rep(f)); Tag_lookup_free(&tbl); g = f | T_YATTR; Fmt_fprint(stderr, "or'ing T_YATTR -> %s\n", Tag_type_rep(g)); /*suite = Test_init();*/ /*Test_add(suite, <func_name>, (void *) doc,*/ /*(const void *) pathname);*/ /*Test_all_run(suite);*/ /*Test_print_results(suite);*/ /*Test_free(&suite);*/ return 0; }
AP_T pop(void) { if (!Stack_empty(sp)) return Stack_pop(sp); else { Fmt_fprint(stderr, "?stack underflow\n"); return AP_new(0); } }
MP_T pop(void) { if (Seq_length(sp) > 0) return Seq_remhi(sp); else { Fmt_fprint(stderr, "?stack underflow\n"); return MP_new(0); } }
static int Test_doc_search_tag(T t, void *s, const void *chk) { Doc_tree_T *dt = (Doc_tree_T *) s; s_terms_T *ts = (s_terms_T *) chk; Match_T r1 = Doc_search_tag(dt, ts->pos, NULL, NULL); Match_T r2 = Doc_search_tag(dt, ts->neg, NULL, NULL); Fmt_fprint(stdout, "results: %d\n", Doc_search_result_size(r1)); Fmt_fprint(stdout, "results: %d\n", Doc_search_result_size(r2)); const char *out = Doc_search_result_print(&r1); Fmt_fprint(stdout, "%s", out); FREE(out); TEST_FUNC_NAME(t); Doc_search_free(&r1); Doc_search_free(&r2); return TEST_FAIL; }
int main(int argc, const char *argv[]) { T suite; /*Match_T *results;*/ Doc_tree_T *dt; /*Text_T *doc = File_reader_reader("data/file_reader_test.html", NULL);*/ Text_T *doc = File_reader_reader("data/doc_build_sieve_test.html", NULL); s_terms_T *ts, *cs; /* init tag search queries */ NEW(ts); ts->pos = "div"; ts->neg = "h2"; /* init content search queries */ NEW(cs); cs->pos = "music"; cs->neg = "is the best"; dt = Doc_builder_builder(doc); Fmt_fprint(stderr, "==> Starting %s <==\n", __FILE__); suite = Test_init(); /*Test_add(suite, Test_doc_results, (void *) dt, (const void *) results);*/ Test_add(suite, Test_doc_search_tag, (void *) dt, (const void *) ts); Test_add(suite, Test_doc_search_content, PREV_INPUT(suite), (const void *) cs); Test_all_run(suite); Test_print_results(suite); Test_free(&suite); return 0; }
int main(int argc, const char *argv[]) { T suite; /*const char *pathname = "data/file_reader_test.html";*/ const char *pathname = "data/arni.html"; /*const char *pathname = "/home/joe/programming/web/rails/notes/learning_rails_3.txt";*/ char *filter = "\n\t"; Fmt_fprint(stderr, "==> Starting %s <==\n", __FILE__); suite = Test_init(); Test_add(suite, Test_file_reader_reader, NULL, (const void *) pathname); /*Test_add(suite, Test_file_reader_reader_filter, (void *) filter,*/ /*(const void *) pathname);*/ Test_all_run(suite); Test_print_results(suite); Test_free(&suite); return 0; }
int main(int argc, char *argv[]) { int c; sp = Stack_new(); Fmt_register('D', AP_fmt); while ((c = getchar()) != EOF) switch (c) { case ' ': case '\t': case '\n': case '\f': case '\r': break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { char buf[512]; { int i = 0; for ( ; c != EOF && isdigit(c); c = getchar(), i++) if (i < (int)sizeof (buf) - 1) buf[i] = c; if (i > (int)sizeof (buf) - 1) { i = (int)sizeof (buf) - 1; Fmt_fprint(stderr, "?integer constant exceeds %d digits\n", i); } buf[i] = 0; if (c != EOF) ungetc(c, stdin); } Stack_push(sp, AP_fromstr(buf, 10, NULL)); break; } case '+': { AP_T y = pop(), x = pop(); Stack_push(sp, AP_add(x, y)); AP_free(&x); AP_free(&y); break; } case '-': { AP_T y = pop(), x = pop(); Stack_push(sp, AP_sub(x, y)); AP_free(&x); AP_free(&y); break; } case '*': { AP_T y = pop(), x = pop(); Stack_push(sp, AP_mul(x, y)); AP_free(&x); AP_free(&y); break; } case '/': { AP_T y = pop(), x = pop(); if (AP_cmpi(y, 0) == 0) { Fmt_fprint(stderr, "?/ by 0\n"); Stack_push(sp, AP_new(0)); } else Stack_push(sp, AP_div(x, y)); AP_free(&x); AP_free(&y); break; } case '%': { AP_T y = pop(), x = pop(); if (AP_cmpi(y, 0) == 0) { Fmt_fprint(stderr, "?%% by 0\n"); Stack_push(sp, AP_new(0)); } else Stack_push(sp, AP_mod(x, y)); AP_free(&x); AP_free(&y); break; } case '^': { AP_T y = pop(), x = pop(); if (AP_cmpi(y, 0) <= 0) { Fmt_fprint(stderr, "?nonpositive power\n"); Stack_push(sp, AP_new(0)); } else Stack_push(sp, AP_pow(x, y, NULL)); AP_free(&x); AP_free(&y); break; } case 'd': { AP_T x = pop(); Stack_push(sp, x); Stack_push(sp, AP_addi(x, 0)); break; } case 'p': { AP_T x = pop(); Fmt_print("%D\n", x); Stack_push(sp, x); break; } case 'f': if (!Stack_empty(sp)) { Stack_T tmp = Stack_new(); while (!Stack_empty(sp)) { AP_T x = pop(); Fmt_print("%D\n", x); Stack_push(tmp, x); } while (!Stack_empty(tmp)) Stack_push(sp, Stack_pop(tmp)); Stack_free(&tmp); } break; case '~': { AP_T x = pop(); Stack_push(sp, AP_neg(x)); AP_free(&x); break; } case 'c': while (!Stack_empty(sp)) { AP_T x = Stack_pop(sp); AP_free(&x); } break; case 'q': while (!Stack_empty(sp)) { AP_T x = Stack_pop(sp); AP_free(&x); } Stack_free(&sp); return EXIT_SUCCESS; default: if (isprint(c)) Fmt_fprint(stderr, "?'%c'", c); else Fmt_fprint(stderr, "?'\\%03o'", c); Fmt_fprint(stderr, " is unimplemented\n"); break; } while (!Stack_empty(sp)) { AP_T x = Stack_pop(sp); AP_free(&x); } Stack_free(&sp); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int c; sp = Seq_new(0); Fmt_register('D', MP_fmt); Fmt_register('U', MP_fmtu); while ((c = getchar()) != EOF) { MP_T x = NULL, y = NULL, z = NULL; TRY switch (c) { default: if (isprint(c)) Fmt_fprint(stderr, "?'%c'", c); else Fmt_fprint(stderr, "?'\\%03o'", c); Fmt_fprint(stderr, " is unimplemented\n"); break; case ' ': case '\t': case '\n': case '\f': case '\r': break; case 'c': while (Seq_length(sp) > 0) { MP_T x = Seq_remhi(sp); FREE(x); } break; case 'q': while (Seq_length(sp) > 0) { MP_T x = Seq_remhi(sp); FREE(x); } Seq_free(&sp); return EXIT_SUCCESS; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { char buf[512]; z = MP_new(0); { int i = 0; for ( ; strchr(&"zyxwvutsrqponmlkjihgfedcba9876543210"[36-ibase], tolower(c)); c = getchar(), i++) if (i < (int)sizeof (buf) - 1) buf[i] = c; if (i > (int)sizeof (buf) - 1) { i = (int)sizeof (buf) - 1; Fmt_fprint(stderr, "?integer constant exceeds %d digits\n", i); } buf[i] = '\0'; if (c != EOF) ungetc(c, stdin); } MP_fromstr(z, buf, ibase, NULL); break; } case '+': y = pop(); x = pop(); z = MP_new(0); (*f->add)(z, x, y); break; case '-': y = pop(); x = pop(); z = MP_new(0); (*f->sub)(z, x, y); break; case '*': y = pop(); x = pop(); z = MP_new(0); (*f->mul)(z, x, y); break; case '/': y = pop(); x = pop(); z = MP_new(0); (*f->div)(z, x, y); break; case '%': y = pop(); x = pop(); z = MP_new(0); (*f->mod)(z, x, y); break; case '&': y = pop(); x = pop(); z = MP_new(0); MP_and(z, x, y); break; case '|': y = pop(); x = pop(); z = MP_new(0); MP_or (z, x, y); break; case '^': y = pop(); x = pop(); z = MP_new(0); MP_xor(z, x, y); break; case '!': z = pop(); MP_not(z, z); break; case '~': z = pop(); MP_neg(z, z); break; case 'i': case 'o': { long n; x = pop(); n = MP_toint(x); if (n < 2 || n > 36) Fmt_fprint(stderr, "?%d is an illegal base\n",n); else if (c == 'i') ibase = n; else obase = n; if (obase == 2 || obase == 8 || obase == 16) f = &u; else f = &s; break; } case 'p': Fmt_print(f->fmt, z = pop(), obase); break; case 'f': { int n = Seq_length(sp); while (--n > 0) Fmt_print(f->fmt, Seq_get(sp, n), obase); break; } case '<': { long s; y = pop(); z = pop(); s = MP_toint(y); if (s < 0 || s > INT_MAX) { Fmt_fprint(stderr, "?%d is an illegal shift amount\n", s); break; }; MP_lshift(z, z, s); break; } case '>': { long s; y = pop(); z = pop(); s = MP_toint(y); if (s < 0 || s > INT_MAX) { Fmt_fprint(stderr, "?%d is an illegal shift amount\n", s); break; }; MP_rshift(z, z, s); break; } case 'k': { long n; x = pop(); n = MP_toint(x); if (n < 2 || n > INT_MAX) Fmt_fprint(stderr, "?%d is an illegal precision\n", n); else if (Seq_length(sp) > 0) Fmt_fprint(stderr, "?nonempty stack\n"); else MP_set(n); break; } case 'd': { MP_T x = pop(); z = MP_new(0); Seq_addhi(sp, x); MP_addui(z, x, 0); break; } } EXCEPT(MP_Overflow) Fmt_fprint(stderr, "?overflow\n"); EXCEPT(MP_Dividebyzero) Fmt_fprint(stderr, "?divide by 0\n"); END_TRY; if (z) Seq_addhi(sp, z); FREE(x); FREE(y); } while (Seq_length(sp) > 0) { MP_T x = Seq_remhi(sp); FREE(x); } Seq_free(&sp); return EXIT_SUCCESS; }