/* * makedefineindex: make definition index (including alphabetic index) * * @param[in] file definition index file * @param[in] total definitions total * @param[out] defines @defines * Globals used (input): * tag cache XXX: should this be global output, not input? */ int makedefineindex(const char *file, int total, STRBUF *defines) { int count = 0; int alpha_count = 0; FILEOP *fileop_MAP = NULL, *fileop_DEFINES, *fileop_ALPHA = NULL; FILE *MAP = NULL; FILE *DEFINES, *STDOUT, *TAGS, *ALPHA = NULL; STRBUF *sb = strbuf_open(0); STRBUF *url = strbuf_open(0); /* Index link */ const char *target = (Fflag) ? "mains" : "_top"; const char *indexlink; const char *index_string = "Index Page"; char command[1024], buf[1024], alpha[32], alpha_f[32], *_; if (!aflag && !Fflag) indexlink = "mains"; else if (Fflag) indexlink = "../defines"; else indexlink = "../mains"; if (map_file) { fileop_MAP = open_output_file(makepath(distpath, "MAP", NULL), 0); MAP = get_descripter(fileop_MAP); } fileop_DEFINES = open_output_file(makepath(distpath, file, NULL), 0); DEFINES = get_descripter(fileop_DEFINES); fputs_nl(gen_page_begin(title_define_index, TOPDIR), DEFINES); fputs_nl(body_begin, DEFINES); fputs(header_begin, DEFINES); if (Fflag) fputs(gen_href_begin(NULL, "defines", normal_suffix, NULL), DEFINES); fputs(title_define_index, DEFINES); if (Fflag) fputs(gen_href_end(), DEFINES); fputs_nl(header_end, DEFINES); if (!aflag && !Fflag) { fputs(gen_href_begin_with_title(NULL, indexlink, normal_suffix, NULL, index_string), DEFINES); if (Iflag) fputs(gen_image(CURRENT, back_icon, ".."), DEFINES); else fputs("[..]", DEFINES); fputs_nl(gen_href_end(), DEFINES); } if (!aflag) { if (!no_order_list) fputs_nl(list_begin, DEFINES); } /* * map DEFINES to STDOUT. */ STDOUT = DEFINES; snprintf(command, sizeof(command), PQUOTE "%s -c" PQUOTE, quote_shell(global_path)); if ((TAGS = popen(command, "r")) == NULL) die("cannot execute '%s'.", command); alpha[0] = '\0'; while ((_ = strbuf_fgets(sb, TAGS, STRBUF_NOCRLF)) != NULL) { const char *tag, *line; char guide[1024], url_for_map[1024]; count++; tag = _; message(" [%d/%d] adding %s", count, total, tag); if (aflag && (alpha[0] == '\0' || !locatestring(tag, alpha, MATCH_AT_FIRST))) { const char *msg = (alpha_count == 1) ? "definition" : "definitions"; int c; if (alpha[0]) { char tmp[128]; snprintf(tmp, sizeof(tmp), "%d %s", alpha_count, msg); strbuf_puts(defines, gen_href_begin_with_title("defines", alpha_f, HTML, NULL, tmp)); strbuf_sprintf(defines, "[%s]", alpha); strbuf_puts_nl(defines, gen_href_end()); alpha_count = 0; if (!no_order_list) fputs_nl(list_end, ALPHA); else fputs_nl(br, ALPHA); fputs(gen_href_begin_with_title(NULL, indexlink, normal_suffix, NULL, index_string), ALPHA); if (Iflag) fputs(gen_image(PARENT, back_icon, ".."), ALPHA); else fputs("[..]", ALPHA); fputs_nl(gen_href_end(), ALPHA); fputs_nl(body_end, ALPHA); fputs_nl(gen_page_end(), ALPHA); close_file(fileop_ALPHA); html_count++; } /* * setup index char (for example, 'a' of '[a]'). * alpha is used for display. * alpha_f is used for part of path. */ c = (unsigned char)*tag; if (c > 127) { int i2 = *(tag + 1) & 0xff; /* * for multi-byte(EUC) code. */ alpha[0] = *tag; alpha[1] = *(tag + 1); alpha[2] = '\0'; snprintf(alpha_f, sizeof(alpha_f), "%03d%03d", c, i2); } else if (isalpha(c) || c == '_') { alpha[0] = *tag; alpha[1] = '\0'; /* * for CD9660 or FAT file system */ if (islower(c)) { alpha_f[0] = 'l'; alpha_f[1] = *tag; alpha_f[2] = '\0'; } else { alpha_f[0] = *tag; alpha_f[1] = '\0'; } } else { alpha[0] = *tag; alpha[1] = '\0'; snprintf(alpha_f, sizeof(alpha_f), "%03d", c); } snprintf(buf, sizeof(buf), "%s/defines/%s.%s", distpath, alpha_f, HTML); fileop_ALPHA = open_output_file(buf, 0); ALPHA = get_descripter(fileop_ALPHA); snprintf(buf, sizeof(buf), "[%s]", alpha); fputs_nl(gen_page_begin(buf, SUBDIR), ALPHA); fputs_nl(body_begin, ALPHA); fprintf(ALPHA, "%s[%s]%s\n", header_begin, alpha, header_end); fputs(gen_href_begin_with_title(NULL, indexlink, normal_suffix, NULL, index_string), ALPHA); if (Iflag) fputs(gen_image(PARENT, back_icon, ".."), ALPHA); else fputs("[..]", ALPHA); fputs_nl(gen_href_end(), ALPHA); if (!no_order_list) fputs_nl(list_begin, ALPHA); else fprintf(ALPHA, "%s%s\n", br, br); STDOUT = ALPHA; } alpha_count++; /* * generating url for function definition. */ line = cache_get(GTAGS, tag); strbuf_reset(url); if (line == NULL) die("internal error in makedefineindex()."); /* * About the format of 'line', please see the head comment of cache.c. */ if (*line == ' ') { const char *fid = line + 1; const char *enumber = nextstring(fid); snprintf(url_for_map, sizeof(url_for_map), "%s/%s.%s", DEFS, fid, HTML); if (dynamic) { if (*action != '/' && aflag) strbuf_puts(url, "../"); strbuf_puts(url, action); strbuf_sprintf(url, "?pattern=%s%stype=definitions", tag, quote_amp); } else { if (aflag) strbuf_puts(url, "../"); strbuf_sprintf(url, "%s/%s.%s", DEFS, fid, HTML); } snprintf(guide, sizeof(guide), "Multiple defined in %s places.", enumber); } else { const char *lno = line; const char *fid = nextstring(line); const char *path = gpath_fid2path(fid, NULL); path += 2; /* remove './' */ snprintf(url_for_map, sizeof(url_for_map), "%s/%s.%s#L%s", SRCS, fid, HTML, lno); if (aflag) strbuf_puts(url, "../"); strbuf_sprintf(url, "%s/%s.%s#L%s", SRCS, fid, HTML, lno); snprintf(guide, sizeof(guide), "Defined at %s in %s.", lno, path); } if (!no_order_list) fputs(item_begin, STDOUT); fputs(gen_href_begin_with_title_target(NULL, strbuf_value(url), NULL, NULL, guide, target), STDOUT); fputs(tag, STDOUT); fputs(gen_href_end(), STDOUT); if (!no_order_list) fputs(item_end, STDOUT); else fputs(br, STDOUT); fputc('\n', STDOUT); if (map_file) fprintf(MAP, "%s\t%s\n", tag, url_for_map); } if (pclose(TAGS) != 0) die("terminated abnormally '%s' (errno = %d).", command, errno); if (aflag && alpha[0]) { char tmp[128]; const char *msg = (alpha_count == 1) ? "definition" : "definitions"; snprintf(tmp, sizeof(tmp), "%d %s", alpha_count, msg); strbuf_puts(defines, gen_href_begin_with_title("defines", alpha_f, HTML, NULL, tmp)); strbuf_sprintf(defines, "[%s]", alpha); strbuf_puts_nl(defines, gen_href_end()); if (!no_order_list) fputs_nl(list_end, ALPHA); else fputs_nl(br, ALPHA); fputs(gen_href_begin_with_title(NULL, indexlink, normal_suffix, NULL, index_string), ALPHA); if (Iflag) fputs(gen_image(PARENT, back_icon, ".."), ALPHA); else fputs("[..]", ALPHA); fputs_nl(gen_href_end(), ALPHA); fputs_nl(body_end, ALPHA); fputs_nl(gen_page_end(), ALPHA); close_file(fileop_ALPHA); html_count++; fputs(strbuf_value(defines), DEFINES); } if (!no_order_list && !aflag) fputs_nl(list_end, DEFINES); if (!aflag && !Fflag) { fputs(gen_href_begin_with_title(NULL, "mains", normal_suffix, NULL, index_string), DEFINES); if (Iflag) fputs(gen_image(CURRENT, back_icon, ".."), DEFINES); else fputs("[..]", DEFINES); fputs_nl(gen_href_end(), DEFINES); } fputs_nl(body_end, DEFINES); fputs_nl(gen_page_end(), DEFINES); close_file(fileop_DEFINES); html_count++; if (map_file) close_file(fileop_MAP); strbuf_close(sb); strbuf_close(url); return count; }
/* * Make duplicate object index. * * If referred tag is only one, direct link which points the tag is generated. * Else if two or more tag exists, indirect link which points the tag list * is generated. */ int makedupindex(void) { STRBUF *sb = strbuf_open(0); STRBUF *tmp = strbuf_open(0); STRBUF *command = strbuf_open(0); int definition_count = 0; char srcdir[MAXPATHLEN]; int db; FILEOP *fileop = NULL; FILE *op = NULL; FILE *ip = NULL; snprintf(srcdir, sizeof(srcdir), "../%s", SRCS); for (db = GTAGS; db < GTAGLIM; db++) { const char *kind = kinds[db]; const char *option = options[db]; int writing = 0; int count = 0; int entry_count = 0; const char *ctags_xid, *ctags_x; char tag[IDENTLEN], prev[IDENTLEN], first_line[MAXBUFLEN]; if (gtags_exist[db] == 0) continue; prev[0] = 0; first_line[0] = 0; /* * construct command line. */ strbuf_reset(command); strbuf_sprintf(command, "%s -x%s --result=ctags-xid --encode-path=\" \t\" --nofilter=path", quote_shell(global_path), option); /* * Optimization when the --dynamic option is specified. */ if (dynamic) { strbuf_puts(command, " --nosource"); if (db != GSYMS) strbuf_puts(command, " --nofilter=sort"); } strbuf_puts(command, " \".*\""); if ((ip = popen(strbuf_value(command), "r")) == NULL) die("cannot execute command '%s'.", strbuf_value(command)); while ((ctags_xid = strbuf_fgets(sb, ip, STRBUF_NOCRLF)) != NULL) { char fid[MAXFIDLEN]; ctags_x = parse_xid(ctags_xid, fid, NULL); /* tag name */ (void)strcpy_withterm(tag, ctags_x, sizeof(tag), ' '); if (strcmp(prev, tag)) { count++; if (vflag) fprintf(stderr, " [%d] adding %s %s\n", count, kind, tag); if (writing) { if (!dynamic) { fputs_nl(gen_list_end(), op); fputs_nl(body_end, op); fputs_nl(gen_page_end(), op); close_file(fileop); html_count++; } writing = 0; /* * cache record: " <fid>\0<entry number>\0" */ strbuf_reset(tmp); strbuf_putc(tmp, ' '); strbuf_putn(tmp, count - 1); strbuf_putc(tmp, '\0'); strbuf_putn(tmp, entry_count); cache_put(db, prev, strbuf_value(tmp), strbuf_getlen(tmp) + 1); } /* single entry */ if (first_line[0]) { char fid[MAXFIDLEN]; const char *ctags_x = parse_xid(first_line, fid, NULL); const char *lno = nextelement(ctags_x); strbuf_reset(tmp); strbuf_puts_withterm(tmp, lno, ' '); strbuf_putc(tmp, '\0'); strbuf_puts(tmp, fid); cache_put(db, prev, strbuf_value(tmp), strbuf_getlen(tmp) + 1); } /* * Chop the tail of the line. It is not important. * strlimcpy(first_line, ctags_x, sizeof(first_line)); */ strncpy(first_line, ctags_xid, sizeof(first_line)); first_line[sizeof(first_line) - 1] = '\0'; strlimcpy(prev, tag, sizeof(prev)); entry_count = 0; } else { /* duplicate entry */ if (first_line[0]) { char fid[MAXFIDLEN]; const char *ctags_x = parse_xid(first_line, fid, NULL); if (!dynamic) { char path[MAXPATHLEN]; snprintf(path, sizeof(path), "%s/%s/%d.%s", distpath, dirs[db], count, HTML); fileop = open_output_file(path, cflag); op = get_descripter(fileop); fputs_nl(gen_page_begin(tag, SUBDIR), op); fputs_nl(body_begin, op); fputs_nl(gen_list_begin(), op); fputs_nl(gen_list_body(srcdir, ctags_x, fid), op); } writing = 1; entry_count++; first_line[0] = 0; } if (!dynamic) { fputs_nl(gen_list_body(srcdir, ctags_x, fid), op); } entry_count++; } } if (db == GTAGS) definition_count = count; if (pclose(ip) != 0) die("'%s' failed.", strbuf_value(command)); if (writing) { if (!dynamic) { fputs_nl(gen_list_end(), op); fputs_nl(body_end, op); fputs_nl(gen_page_end(), op); close_file(fileop); html_count++; } /* * cache record: " <fid>\0<entry number>\0" */ strbuf_reset(tmp); strbuf_putc(tmp, ' '); strbuf_putn(tmp, count); strbuf_putc(tmp, '\0'); strbuf_putn(tmp, entry_count); cache_put(db, prev, strbuf_value(tmp), strbuf_getlen(tmp) + 1); } if (first_line[0]) { char fid[MAXFIDLEN]; const char *ctags_x = parse_xid(first_line, fid, NULL); const char *lno = nextelement(ctags_x); strbuf_reset(tmp); strbuf_puts_withterm(tmp, lno, ' '); strbuf_putc(tmp, '\0'); strbuf_puts(tmp, fid); cache_put(db, prev, strbuf_value(tmp), strbuf_getlen(tmp) + 1); } } strbuf_close(sb); strbuf_close(tmp); strbuf_close(command); return definition_count; }
/* * makecflowindex: make call-tree based on cflow's output * * i) output output file name * i) cflow_file input file which is the output of Cflow with --format=posix */ int makecflowindex(const char *output, const char *cflow_file) { STRBUF *input = strbuf_open(0); FILE *ip, *op; char *cflow_posix, *p; const char *m0 = "Gave up making call-tree because of illegal POSIX cflow format."; const char *m1 = ""; const char *title = locatestring(output, "callee", MATCH_AT_FIRST) ? title_callee_tree : title_call_tree; int line = 0; int status = 0; #define ERROR do { warning("%s\n%s:%d %s.", m0, cflow_file, line, m1); status = -1; goto finish; } while(0) /* * If syntax error occured then stop the jobs and return error status. * Don't die() because htags has already done a lot of work. */ if ((ip = fopen(cflow_file, "r")) == NULL) { warning("cannot open cflow file '%s'.", cflow_file); return -1; } if ((op = fopen(makepath(distpath, output, NULL), "w")) == NULL) { warning("cannot create file '%s'.", output); fclose(ip); return -1; } fputs_nl(gen_page_begin(title, TOPDIR), op); fputs_nl(body_begin, op); fputs(header_begin, op); fputs(gen_href_begin_simple(output), op); /* fputs(gen_href_begin(NULL, "cflow", normal_suffix, NULL), op);*/ fputs(title, op); fputs(gen_href_end(), op); fputs_nl(header_end, op); fputs_nl(verbatim_begin, op); /* * Cflow's output format (with the --format=posix) * +---------------------------------------------------------------- * | 25 isregex: int (const char *s), <libutil/char.c 54>... * | 32 func: 10 * +---------------------------------------------------------------- * cflow_posix * v * 25 isregex: int ... , <libutil/char.c 54>... * ^ ^ ^ ^ * anchor name path lineno * * cflow_posix * v * 32 func: 10 * ^ ^ ^ * anchor name lineno */ while ((cflow_posix = strbuf_fgets(input, ip, STRBUF_NOCRLF)) != NULL) { char *anchor, *name, *path, *lineno; char *anchor_end, *name_end, *path_end, *lineno_end; anchor = name = path = lineno = anchor_end = name_end = path_end = lineno_end = NULL; line++; for (p = cflow_posix; *p && isspace(*p); p++) ; m1 = "line number at the head not found"; if (!*p || !isdigit(*p)) ERROR; anchor = p; /* anchor */ for (; *p && isdigit(*p); p++) ; if (!*p || !isspace(*p)) ERROR; anchor_end = p; /* seek to the function name */ for (; *p; p++) { /* skip special characters of HTML like '├'*/ if (*p == '&') { for (p++; *p && *p != ';'; p++) ; if (*p != ';') ERROR; } else if (isalpha(*p) || *p == '_') break; } m1 = "function name not found"; if (!*p || !isalpha(*p)) ERROR; name = p; /* name */ for (; *p && *p != ':'; p++) ; if (*p != ':') ERROR; name_end = p++; if (*p++ != ' ') ERROR; if (isdigit(*p)) { /* (1) name: 999 */ lineno = p; /* lineno */ for (; *p && isdigit(*p); p++) ; lineno_end = p; } else if (*p == '<' && *(p + 1) == '>') { /* (2) name: <> */ ; } else { /* (3) name: ... <path lineno> */ m1 = "<path lineno> not found"; for (; *p && *p != '<'; p++) ; if (!*p++) ERROR; path = p; m1 = "path not found"; for (; *p && !isspace(*p); p++) if (*p == '>') ERROR; if (!*p || *p != ' ') ERROR; path_end = p++; m1 = "lineno not found"; if (!isdigit(*p)) ERROR; lineno = p; for (; *p && isdigit(*p); p++) ; if (*p != '>') ERROR; lineno_end = p; } /* * print anchor */ fprintf(op, gen_name_number(atoi(anchor))); /* * print until name */ fwrite(cflow_posix, name - cflow_posix, 1, op); /* * print name */ if (path) { const char *fid = NULL; int path_save = *path_end; int lineno_save = *lineno_end; *path_end = *lineno_end = 0; if (test("f", path) && (fid = path2fid_readonly(path)) != NULL) fprintf(op, gen_href_begin(SRCS, fid, HTML, lineno)); else path = lineno = NULL; /* not to print </a> */ *path_end = path_save; *lineno_end = lineno_save; } else if (lineno) { int lineno_save = *lineno_end; *lineno_end = 0; fprintf(op, gen_href_begin(NULL, NULL, NULL, lineno)); *lineno_end = lineno_save; } fwrite(name, name_end - name, 1, op); if (path || lineno) fputs(gen_href_end(), op); /* * print the rest */ for (p = name_end; *p; p++) { if (*p == '<') fputs(quote_little, op); else if (*p == '>') fputs(quote_great, op); else fputc(*p, op); } fputc('\n', op); } finish: fputs_nl(verbatim_end, op); fputs_nl(body_end, op); fputs_nl(gen_page_end(), op); strbuf_close(input); fclose(ip); fclose(op); return status; }
/** * makehelp: make help file */ static void makehelp(const char *file) { const char **label = Iflag ? anchor_comment : anchor_label; const char **icons = anchor_icons; const char **msg = anchor_msg; int n, last = 7; FILE *op; op = fopen(makepath(distpath, file, NULL), "w"); if (!op) die("cannot make help file."); fputs_nl(gen_page_begin("HELP", TOPDIR), op); fputs_nl(body_begin, op); fputs(header_begin, op); fputs("Usage of Links", op); fputs_nl(header_end, op); if (!Iflag) fputs(verbatim_begin, op); fputs("/* ", op); for (n = 0; n <= last; n++) { if (Iflag) { fputs(gen_image(CURRENT, icons[n], label[n]), op); if (n < last) fputc(' ', op); } else { fprintf(op, "[%s]", label[n]); } } if (show_position) fprintf(op, "[+line file]"); fputs(" */", op); if (!Iflag) fputs_nl(verbatim_end, op); else fputc('\n', op); fputs_nl(define_list_begin, op); for (n = 0; n <= last; n++) { fputs(define_term_begin, op); if (Iflag) { fputs(gen_image(CURRENT, icons[n], label[n]), op); } else { fprintf(op, "[%s]", label[n]); } fputs(define_term_end, op); fputs(define_desc_begin, op); fputs(msg[n], op); fputs_nl(define_desc_end, op); } if (show_position) { fputs(define_term_begin, op); fputs("[+line file]", op); fputs(define_term_end, op); fputs(define_desc_begin, op); fputs("Current position (line number and file name).", op); fputs_nl(define_desc_end, op); } fputs_nl(define_list_end, op); fputs_nl(body_end, op); fputs_nl(gen_page_end(), op); fclose(op); html_count++; }
/*----------------------------------------------------------------------*/ void makeincludeindex(void) { FILE *PIPE; STRBUF *input = strbuf_open(0); char *ctags_x; struct data *inc; char *target = (Fflag) ? "mains" : "_top"; char command[MAXFILLEN]; /* * Pick up include pattern. * * C: #include "xxx.h" * PHP: include("xxx.inc.php"); */ /* * Unlike Perl regular expression, POSIX regular expression doesn't support C-style escape sequence. * Therefore, we can not use "\\t" here. */ snprintf(command, sizeof(command), PQUOTE "%s -gnx --encode-path=\" \t\" \"^[ \t]*(#[ \t]*(import|include)|include[ \t]*\\()\"" PQUOTE, quote_shell(global_path)); if ((PIPE = popen(command, "r")) == NULL) die("cannot execute '%s'.", command); strbuf_reset(input); while ((ctags_x = strbuf_fgets(input, PIPE, STRBUF_NOCRLF)) != NULL) { SPLIT ptable; char buf[MAXBUFLEN]; int is_php = 0; const char *last, *lang, *suffix; if (split(ctags_x, 4, &ptable) < 4) { recover(&ptable); die("too small number of parts in makefileindex()."); } if ((suffix = locatestring(ptable.part[PART_PATH].start, ".", MATCH_LAST)) != NULL && (lang = decide_lang(suffix)) != NULL && strcmp(lang, "php") == 0) is_php = 1; last = extract_lastname(ptable.part[PART_LINE].start, is_php); if (last == NULL || (inc = get_inc(last)) == NULL) continue; recover(&ptable); /* * s/^[^ \t]+/$last/; */ { const char *p; char *q = buf; for (p = last; *p; p++) *q++ = *p; for (p = ctags_x; *p && *p != ' ' && *p != '\t'; p++) ; for (; *p; p++) *q++ = *p; *q = '\0'; } put_included(inc, buf); } if (pclose(PIPE) != 0) die("terminated abnormally '%s' (errno = %d).", command, errno); for (inc = first_inc(); inc; inc = next_inc()) { const char *last = inc->name; int no = inc->id; FILEOP *fileop_INCLUDE; FILE *INCLUDE; if (inc->count > 1) { char path[MAXPATHLEN]; snprintf(path, sizeof(path), "%s/%s/%d.%s", distpath, INCS, no, HTML); fileop_INCLUDE = open_output_file(path, 0); INCLUDE = get_descripter(fileop_INCLUDE); fputs_nl(gen_page_begin(last, SUBDIR), INCLUDE); fputs_nl(body_begin, INCLUDE); fputs_nl(verbatim_begin, INCLUDE); { const char *filename = strbuf_value(inc->contents); int count = inc->count; for (; count; filename += strlen(filename) + 1, count--) { fputs(gen_href_begin_with_title_target(upperdir(SRCS), path2fid(filename), HTML, NULL, NULL, target), INCLUDE); fputs(removedotslash(filename), INCLUDE); fputs_nl(gen_href_end(), INCLUDE); } } fputs_nl(verbatim_end, INCLUDE); fputs_nl(body_end, INCLUDE); fputs_nl(gen_page_end(), INCLUDE); close_file(fileop_INCLUDE); html_count++; /* * inc->contents == NULL means that information already * written to file. */ strbuf_close(inc->contents); inc->contents = NULL; } if (!inc->ref_count) continue; if (inc->ref_count == 1) { SPLIT ptable; char buf[1024]; if (split(strbuf_value(inc->ref_contents), 4, &ptable) < 4) { recover(&ptable); die("too small number of parts in makefileindex()."); } snprintf(buf, sizeof(buf), "%s %s", ptable.part[PART_LNO].start, decode_path(ptable.part[PART_PATH].start)); recover(&ptable); strbuf_reset(inc->ref_contents); strbuf_puts(inc->ref_contents, buf); } else { char path[MAXPATHLEN]; snprintf(path, sizeof(path), "%s/%s/%d.%s", distpath, INCREFS, no, HTML); fileop_INCLUDE = open_output_file(path, 0); INCLUDE = get_descripter(fileop_INCLUDE); fputs_nl(gen_page_begin(last, SUBDIR), INCLUDE); fputs_nl(body_begin, INCLUDE); fputs_nl(gen_list_begin(), INCLUDE); { const char *line = strbuf_value(inc->ref_contents); int count = inc->ref_count; for (; count; line += strlen(line) + 1, count--) fputs_nl(gen_list_body(upperdir(SRCS), line, NULL), INCLUDE); } fputs_nl(gen_list_end(), INCLUDE); fputs_nl(body_end, INCLUDE); fputs_nl(gen_page_end(), INCLUDE); close_file(fileop_INCLUDE); html_count++; /* * inc->ref_contents == NULL means that information already * written to file. */ strbuf_close(inc->ref_contents); inc->ref_contents = NULL; } } strbuf_close(input); }
/** * print directory header. * * @param[in] op file index * @param[in] level 1,2... * @param[in] dir directory name */ static void print_directory_header(FILE *op, int level, const char *dir) { STATIC_STRBUF(sb); const char *top = (Fflag && !tree_view) ? "../files" : "../mains"; if (level == 0) die("print_directory_header: internal error."); strbuf_clear(sb); strbuf_puts(sb, removedotslash(dir)); strbuf_putc(sb, '/'); fputs_nl(gen_page_begin(strbuf_value(sb), SUBDIR), op); fputs_nl(body_begin, op); strbuf_clear(sb); strbuf_sprintf(sb, "%s%sroot%s/", header_begin, gen_href_begin(NULL, top, normal_suffix, NULL), gen_href_end()); fputs(strbuf_value(sb), op); { char path[MAXPATHLEN]; char *p, *q; strlimcpy(path, dir, sizeof(path)); for (p = path + 1; p != NULL; p = strchr(p, '/')) { int save = 0; q = ++p; while (*q && *q != '/') q++; save = *q; if (*q == '/') *q = '\0'; if (save == '/') fputs(gen_href_begin(NULL, path2fid(path), HTML, NULL), op); fputs(p, op); if (save == '/') fputs(gen_href_end(), op); *q = save; fputc('/', op); } } fputs_nl(header_end, op); { char parentdir[MAXPATHLEN]; const char *suffix, *parent; (void)dirpart(dir, parentdir); if (level == 1) { parent = top; suffix = normal_suffix; } else { parent = path2fid(parentdir); suffix = HTML; } fputs(gen_href_begin_with_title(NULL, parent, suffix, NULL, "Parent Directory"), op); } if (Iflag) fputs(gen_image(PARENT, back_icon, ".."), op); else fputs("[..]", op); fputs_nl(gen_href_end(), op); if (table_flist) fputs_nl(flist_begin, op); else if (!no_order_list) fputs_nl(list_begin, op); else { fputs(br, op); fputs_nl(br, op); } }