/* Read the next line from the current input file(s). */ bool d_getline(dstr var) { char *p = var; int c; /* Open the next file if necessary. */ if (!d_file) { if (d_file_num == -1 || d_file_num + 1 >= d_argc) { return false; } d_file_num++; d_file = fopen(d_argv[d_file_num], "r"); if (!d_file) { d_abort("could not open file for reading: ", d_argv[d_file_num]); } d_assign(d_filename, d_argv[d_file_num]); d_line_num = 0; } for (;;) { c = fgetc(d_file); if (c == EOF || c == '\n') { break; } *p++ = c; if (p - var >= MAX_STRING - 1) { fprintf(stderr, "dawk: string length limit reached\n"); break; } } *p = '\0'; if (c == EOF) { fclose(d_file); d_file = NULL; if (p == var) { return d_getline(var); } } else if (c == '\n') { d_line_num++; /* Remove trailing CR if present. */ if (p > var && p[-1] == '\r') { p[-1] = '\0'; } } return true; }
int main(int argc, char *argv[]) { bool found_tag = false; bool do_print = false; dstr line = ""; dstr prefix = ""; d_init(argc, argv); while (d_getline(line)) { if (d_match(line, "/[*] (Function|Type|Enum): (.*)")) { found_tag = true; do_print = false; d_assign(prefix, d_submatch(2)); continue; } if (found_tag && d_match(line, "^ ?\\*/")) { found_tag = false; do_print = true; continue; } if (d_match(line, "^\\{|^$")) { do_print = false; continue; } /* Prototype ends on blank line. */ /* TODO: Should the above regexp match it? If so it doesn't here... */ if (line[0] == 0) { do_print = false; continue; } if (do_print) { printf("%s: %s\n", prefix, line); } if (d_match(line, "\\{ *$|; *$")) { do_print = false; } } return 0; }
int main(int argc, char *argv[]) { dstr line; Aatree * root = &aa_nil; d_init(argc, argv); d_printf("# Index\n"); while ((d_getline(line))) { if (d_match(line, "^\\[([^\\]]*)")) { const char *ref = d_submatch(1); char *s = xstrdup(ref); root = aa_insert(root, s, s); } } pre_order_traversal(root, print_link); aa_destroy(root); return 0; }
static void load_prototypes(const char *filename) { dstr line; const char *name; const char *newtext; const char *file_name; const char *line_number; dstr text; d_open_input(filename); while (d_getline(line)) { if (d_match(line, "([^:]*): ([^:]*):([^:]*):([^:]*)")) { name = d_submatch(1); newtext = d_submatch(2); file_name = d_submatch(3); line_number = d_submatch(4); d_assign(text, lookup_prototype(name)); strcat(text, "\n"); strcat(text, newtext); protos = aa_insert(protos, name, text); d_assign(text, lookup_source(name)); if (strlen(text) == 0) { strcat(text, "https://github.com/liballeg/allegro5/blob/5.1/"); strcat(text, file_name); strcat(text, "#L"); strcat(text, line_number); sources = aa_insert(sources, name, text); } } } d_close_input(); }