📄 src2html.c
字号:
char lno[32]; const char *filename; strlimcpy(lno, strmake(line, " "), sizeof(lno)); filename = strmake(locatestring(line, " ", MATCH_FIRST) + 1, " ") + 2; /* remove './' */ strbuf_puts(outbuf, gen_href_begin_with_title(upperdir(SRCS), path2fid(filename), HTML, lno, tooltip(type, atoi(lno), filename))); strbuf_puts(outbuf, name); strbuf_puts(outbuf, gen_href_end()); } }}/* * put_include_anchor: output HTML anchor. * * i) inc inc structure * i) path path name for display */voidput_include_anchor(inc, path) struct data *inc; const char *path;{ if (inc->count == 1) strbuf_puts(outbuf, gen_href_begin(NULL, path2fid(strbuf_value(inc->contents)), HTML, NULL)); else { char id[32]; snprintf(id, sizeof(id), "%d", inc->id); strbuf_puts(outbuf, gen_href_begin(upperdir(INCS), id, HTML, NULL)); } strbuf_puts(outbuf, path); strbuf_puts(outbuf, gen_href_end());}/* * Put a reserved word. (if, while, ...) */voidput_reserved_word(word) const char *word;{ strbuf_puts(outbuf, reserved_begin); strbuf_puts(outbuf, word); strbuf_puts(outbuf, reserved_end);}/* * Put a macro (#define,#undef,...) */voidput_macro(word) const char *word;{ strbuf_puts(outbuf, sharp_begin); strbuf_puts(outbuf, word); strbuf_puts(outbuf, sharp_end);}/* * Print warning message when unkown preprocessing directive is found. */voidunknown_preprocessing_directive(word, lineno) const char *word; int lineno;{ word = strtrim(word, TRIM_ALL, NULL); warning("unknown preprocessing directive '%s'. [+%d %s]", word, lineno, curpfile); if (colorize_warned_line) warned = 1;}/* * Print warning message when unexpected eof. */voidunexpected_eof(lineno) int lineno;{ warning("unexpected eof. [+%d %s]", lineno, curpfile); if (colorize_warned_line) warned = 1;}/* * Print warning message when unknown yacc directive is found. */voidunknown_yacc_directive(word, lineno) const char *word; int lineno;{ warning("unknown yacc directive '%s'. [+%d %s]", word, lineno, curpfile); if (colorize_warned_line) warned = 1;}/* * Print warning message when unmatched brace is found. */voidmissing_left(word, lineno) const char *word; int lineno;{ warning("missing left '%s'. [+%d %s]", word, lineno, curpfile); if (colorize_warned_line) warned = 1;}/* * Put a character with HTML quoting. * * If you want to put '<', '>' and '&', you should echoc() instead. */voidput_char(c) int c;{ if (c == '<') strbuf_puts(outbuf, quote_little); else if (c == '>') strbuf_puts(outbuf, quote_great); else if (c == '&') strbuf_puts(outbuf, quote_amp); else strbuf_putc(outbuf, c);}/* * Put a string with HTML quoting. * * If you want to put HTML tag itself, you should echoc() instead. */voidput_string(s) const char *s;{ for (; *s; s++) put_char(*s);}/* * Put brace ('{', '}') */voidput_brace(text) const char *text;{ strbuf_puts(outbuf, brace_begin); strbuf_puts(outbuf, text); strbuf_puts(outbuf, brace_end);}/* * common procedure for line control. */static char lineno_format[32];static const char *guide = NULL;/* * Begin of line processing. */voidput_begin_of_line(lineno) int lineno;{ if (definition_header != NO_HEADER) { if (define_line(lineno)) guide = generate_guide(lineno); else guide = NULL; } if (guide && definition_header == BEFORE_HEADER) { fputs_nl(guide, out); guide = NULL; }}/* * End of line processing. * * i) lineno current line number * gi) outbuf HTML line image * * The outbuf(string buffer) has HTML image of the line. * This function flush and clear it. */voidput_end_of_line(lineno) int lineno;{ fputs(gen_name_number(lineno), out); if (nflag) fprintf(out, lineno_format, lineno); if (warned) fputs(warned_line_begin, out); /* flush output buffer */ fputs(strbuf_value(outbuf), out); strbuf_reset(outbuf); if (warned) fputs(warned_line_end, out); if (guide == NULL) fputc('\n', out); else { if (definition_header == RIGHT_HEADER) fputs(guide, out); fputc('\n', out); if (definition_header == AFTER_HEADER) { fputs_nl(guide, out); } guide = NULL; } warned = 0; /* save for the other job in this module */ last_lineno = lineno;}/* * * src2html: convert source code into HTML * * i) src source file - Read from * i) html HTML file - Write to * i) notsource 1: isn't source, 0: source. */voidsrc2html(src, html, notsource) const char *src; const char *html; int notsource;{ char indexlink[128]; /* * setup lineno format. */ snprintf(lineno_format, sizeof(lineno_format), "%%%dd ", ncol); in = open_input_file(src); out = open_output_file(html); if (Fflag) snprintf(indexlink, sizeof(indexlink), "../files.%s", normal_suffix); else snprintf(indexlink, sizeof(indexlink), "../mains.%s", normal_suffix); /* * load tags belonging to this file. */ if (!notsource) { anchor_load(src); } fputs_nl(gen_page_begin(src, SUBDIR), out); fputs_nl(body_begin, out); /* * print the header */ if (insert_header) fputs(gen_insert_header(SUBDIR), out); fputs(gen_name_string("TOP"), out); fputs(header_begin, out); fputs(fill_anchor(indexlink, src), out); if (cvsweb_url) { STATIC_STRBUF(sb); const char *p; strbuf_clear(sb); strbuf_puts(sb, cvsweb_url); for (p = src; *p; p++) { int c = (unsigned char)*p; if (c == '/' || isalnum(c)) strbuf_putc(sb, c); else strbuf_sprintf(sb, "%%%02x", c); } if (cvsweb_cvsroot) strbuf_sprintf(sb, "?cvsroot=%s", cvsweb_cvsroot); fputs(quote_space, out); fputs(gen_href_begin_simple(strbuf_value(sb)), out); fputs(cvslink_begin, out); fputs("[CVS]", out); fputs(cvslink_end, out); fputs_nl(gen_href_end(), out); /* doesn't close string buffer */ } fputs_nl(header_end, out); fputs(comment_begin, out); fputs("/* ", out); fputs(link_format(anchor_getlinks(0)), out); if (show_position) fprintf(out, "%s[+1 %s]%s", position_begin, src, position_end); fputs(" */", out); fputs_nl(comment_end, out); fputs_nl(hr, out); /* * It is not source file. */ if (notsource) { STRBUF *sb = strbuf_open(0); const char *_; fputs_nl(verbatim_begin, out); last_lineno = 0; while ((_ = strbuf_fgets(sb, in, STRBUF_NOCRLF)) != NULL) { int dst = 0; fputs(gen_name_number(++last_lineno), out); for (; *_; _++) { int c = *_; if (c == '\t') { do { putc(' ', out); } while (++dst % tabs); } else { if (c == '&') fputs(quote_amp, out); else if (c == '<') fputs(quote_little, out); else if (c == '>') fputs(quote_great, out); else fputc(c, out); dst++; } } fputc('\n', out); } fputs_nl(verbatim_end, out); strbuf_close(sb); } /* * It's source code. */ else { const char *basename; struct data *incref; struct anchor *ancref; STATIC_STRBUF(define_index); /* * INCLUDED FROM index. */ basename = locatestring(src, "/", MATCH_LAST); if (basename) basename++; else basename = src; incref = get_included(basename); if (incref) { char s_id[32]; const char *dir, *file, *suffix, *key, *title; fputs(header_begin, out); if (incref->count > 1) { char s_count[32]; snprintf(s_count, sizeof(s_count), "%d", incref->count); snprintf(s_id, sizeof(s_id), "%d", incref->id); dir = upperdir(INCREFS); file = s_id; suffix = HTML; key = NULL; title = tooltip('I', -1, s_count); } else { const char *p = strbuf_value(incref->contents); const char *lno = strmake(p, " "); const char *filename; p = locatestring(p, " ", MATCH_FIRST); if (p == NULL) die("internal error.(incref->contents)"); filename = p + 1; if (filename[0] == '.' && filename[1] == '/') filename += 2; dir = NULL; file = path2fid(filename); suffix = HTML; key = lno; title = tooltip('I', atoi(lno), filename); } fputs(gen_href_begin_with_title(dir, file, suffix, key, title), out); fputs(title_included_from, out); fputs(gen_href_end(), out); fputs_nl(header_end, out); fputs_nl(hr, out); } /* * DEFINITIONS index. */ strbuf_clear(define_index); for (ancref = anchor_first(); ancref; ancref = anchor_next()) { if (ancref->type == 'D') { char tmp[32]; snprintf(tmp, sizeof(tmp), "%d", ancref->lineno); strbuf_puts(define_index, item_begin); strbuf_puts(define_index, gen_href_begin_with_title(NULL, NULL, NULL, tmp, tooltip('R', ancref->lineno, NULL))); strbuf_puts(define_index, gettag(ancref)); strbuf_puts(define_index, gen_href_end()); strbuf_puts_nl(define_index, item_end); } } if (strbuf_getlen(define_index) > 0) { fputs(header_begin, out); fputs(title_define_index, out); fputs_nl(header_end, out); fputs_nl("This source file includes following definitions.", out); fputs_nl(list_begin, out); fputs(strbuf_value(define_index), out); fputs_nl(list_end, out); fputs_nl(hr, out); } /* * print source code */ fputs_nl(verbatim_begin, out); { const char *suffix = locatestring(src, ".", MATCH_LAST); const char *lang = NULL; struct lang_entry *ent; /* * Decide language. */ if (suffix) lang = decide_lang(suffix); /* * Select parser. * If lang == NULL then default parser is selected. */ ent = get_lang_entry(lang); /* * Initialize parser. */ ent->init_proc(in); /* * Execute parser. * Exec_proc() is called repeatedly until returning EOF. */ while (ent->exec_proc()) ; } fputs_nl(verbatim_end, out); } fputs_nl(hr, out); fputs_nl(gen_name_string("BOTTOM"), out); fputs(comment_begin, out); fputs("/* ", out); fputs(link_format(anchor_getlinks(-1)), out); if (show_position) fprintf(out, "%s[+%d %s]%s", position_begin, last_lineno, src, position_end); fputs(" */", out); fputs_nl(comment_end, out); if (insert_footer) fputs(gen_insert_footer(SUBDIR), out); fputs_nl(body_end, out); fputs_nl(gen_page_end(), out); if (!notsource) anchor_unload(); close_output_file(out); close_input_file(in);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -