📄 htags.c
字号:
if (!(p = usable("gtags"))) die("gtags command required but not found."); strlimcpy(gtags_path, p, sizeof(gtags_path)); if (!(p = usable("global"))) die("global command required but not found."); strlimcpy(global_path, p, sizeof(global_path)); snprintf(findcom, sizeof(findcom), "%s --find", gtags_path); /* * Temporary directory. */ if ((p = getenv("TMPDIR")) == NULL) p = getenv("TMP"); if (p != NULL && test("d", p)) tmpdir = p;}/* * load configuration variables. */static voidconfiguration(argc, argv) int argc; char *argv[];{ STRBUF *sb = strbuf_open(0); int i, n; char *p, *q; /* * Setup the GTAGSCONF and the GTAGSLABEL environment variable * according to the --gtagsconf and --gtagslabel option. */ { char *confpath = NULL; char *label = NULL; char *opt_gtagsconf = "--gtagsconf"; char *opt_gtagslabel = "--gtagslabel"; for (i = 1; i < argc; i++) { if ((p = locatestring(argv[i], opt_gtagsconf, MATCH_AT_FIRST))) { if (*p == '\0') { if (++i >= argc) die("%s needs an argument.", opt_gtagsconf); confpath = argv[i]; } else { if (*p++ == '=' && *p) confpath = p; } } else if ((p = locatestring(argv[i], opt_gtagslabel, MATCH_AT_FIRST))) { if (*p == '\0') { if (++i >= argc) die("%s needs an argument.", opt_gtagslabel); label = argv[i]; } else { if (*p++ == '=' && *p) label = p; } } } if (confpath) { char real[MAXPATHLEN]; if (!test("f", confpath)) die("%s file not found.", opt_gtagsconf); if (!realpath(confpath, real)) die("cannot get absolute path of %s file.", opt_gtagsconf); set_env("GTAGSCONF", real); } if (label) set_env("GTAGSLABEL", label); } /* * Config variables. */ strbuf_reset(sb); if (!getconfs("datadir", sb)) die("cannot get datadir directory name."); strlimcpy(datadir, strbuf_value(sb), sizeof(datadir)); if (getconfn("ncol", &n)) { if (n < 1 || n > 10) warning("parameter 'ncol' ignored becase the value (=%d) is too large or too small.", n); else ncol = n; } if (getconfn("tabs", &n)) { if (n < 1 || n > 32) warning("parameter 'tabs' ignored becase the value (=%d) is too large or too small.", n); else tabs = n; } snprintf(stabs, sizeof(stabs), "%d", tabs); strbuf_reset(sb); if (getconfs("gzipped_suffix", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); gzipped_suffix = p; } strbuf_reset(sb); if (getconfs("normal_suffix", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); normal_suffix = p; } strbuf_reset(sb); if (getconfs("definition_header", sb)) { p = strbuf_value(sb); if (!strcmp(p, "no")) definition_header = NO_HEADER; else if (!strcmp(p, "before")) definition_header = BEFORE_HEADER; else if (!strcmp(p, "right")) definition_header = RIGHT_HEADER; else if (!strcmp(p, "after")) definition_header = AFTER_HEADER; } if (getconfb("other_files")) other_files = 1; if (getconfb("enable_grep")) enable_grep = 1; if (getconfb("enable_idutils")) enable_idutils = 1; if (getconfb("full_path")) full_path = 1; if (getconfb("table_list")) table_list = 1; if (getconfb("no_order_list")) no_order_list = 1; if (getconfb("copy_files")) copy_files = 1; if (getconfb("no_map_file")) no_map_file = 1; strbuf_reset(sb); if (getconfs("icon_list", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); icon_list = p; } strbuf_reset(sb); if (getconfs("icon_spec", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); icon_spec = p; } strbuf_reset(sb); if (getconfs("icon_suffix", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); icon_suffix = p; } strbuf_reset(sb); if (getconfs("prolog_script", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); prolog_script = p; } strbuf_reset(sb); if (getconfs("epilog_script", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); epilog_script = p; } if (getconfb("show_position")) show_position = 1; if (getconfb("colorize_warned_line")) colorize_warned_line = 1; strbuf_reset(sb); if (getconfs("script_alias", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); /* remove the last '/' */ q = p + strlen(p) - 1; if (*q == '/') *q = '\0'; script_alias = p; } if (getconfb("symbols")) /* for backward compatibility */ symbol = 1; if (getconfb("symbol")) symbol = 1; if (getconfb("dynamic")) dynamic = 1; strbuf_reset(sb); if (getconfs("body_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("body_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); body_begin = p; body_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("table_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("table_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); table_begin = p; table_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("title_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("title_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); title_begin = p; title_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("comment_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("comment_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); comment_begin = p; comment_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("sharp_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("sharp_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); sharp_begin = p; sharp_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("brace_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("brace_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); brace_begin = p; brace_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("reserved_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("reserved_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); reserved_begin = p; reserved_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("position_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("position_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); position_begin = p; position_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("warned_line_begin", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); strbuf_reset(sb); if (getconfs("warned_line_end", sb)) { q = strdup(strbuf_value(sb)); if (q == NULL) die("short of memory."); warned_line_begin = p; warned_line_end = q; } else { free(p); } } strbuf_reset(sb); if (getconfs("include_file_suffixes", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); include_file_suffixes = p; } strbuf_reset(sb); if (getconfs("langmap", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); langmap = p; } strbuf_reset(sb); if (getconfs("xhtml_version", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); xhtml_version = p; } /* insert htags_options into the head of ARGSV array. */ strbuf_reset(sb); if (getconfs("htags_options", sb)) { p = strdup(strbuf_value(sb)); if (p == NULL) die("short of memory."); htags_options = p; } strbuf_close(sb);}/* * save_environment: save configuration data and arguments. */static voidsave_environment(argc, argv) int argc; char *argv[];{ char command[MAXFILLEN]; STRBUF *sb = strbuf_open(0); STRBUF *save_c = strbuf_open(0); STRBUF *save_a = strbuf_open(0); int i; const char *p; FILE *ip; /* * save config values. */ snprintf(command, sizeof(command), "%s --config", gtags_path); if ((ip = popen(command, "r")) == NULL) die("cannot execute '%s'.", command); while (strbuf_fgets(sb, ip, STRBUF_NOCRLF) != NULL) { for (p = strbuf_value(sb); *p; p++) { if (*p == '\'') { strbuf_putc(save_c, '\''); strbuf_putc(save_c, '"'); strbuf_putc(save_c, '\''); strbuf_putc(save_c, '"'); strbuf_putc(save_c, '\''); } else strbuf_putc(save_c, *p); } } if (pclose(ip) != 0) die("cannot execute '%s'.", command); strbuf_close(sb); save_config = strbuf_value(save_c); /* doesn't close string buffer for save config. */ /* strbuf_close(save_c); */ /* * save arguments. */ { char *opt_gtagsconf = "--gtagsconf"; for (i = 1; i < argc; i++) { char *blank; /* * skip --gtagsconf because it is already read * as config value. */ if ((p = locatestring(argv[i], opt_gtagsconf, MATCH_AT_FIRST))) { if (*p == '\0') i++; continue; } blank = locatestring(argv[i], " ", MATCH_FIRST); strbuf_putc(save_a, ' '); if (blank) strbuf_putc(save_a, '\''); strbuf_puts(save_a, argv[i]); if (blank) strbuf_putc(save_a, '\''); } } save_argv = strbuf_value(save_a); /* doesn't close string buffer for save arguments. */ /* strbuf_close(save_a); */}char **append_options(argc, argv) int *argc; char *argv[];{ STRBUF *sb = strbuf_open(0); const char *p, *opt = strdup(htags_options); int count = 1; int quote = 0; const char **newargv; int i = 0, j = 1; if (!opt) die("Short of memory."); for (p = opt; *p && isspace(*p); p++) ; for (; *p; p++) { int c = *p; if (quote) { if (quote == c) quote = 0; else strbuf_putc(sb, c); } else if (c == '\\') { strbuf_putc(sb, c); } else if (c == '\'' || c == '"') { quote = c; } else if (isspace(c)) { strbuf_putc(sb, '\0'); count++; while (*p && isspace(*p)) p++; p--; } else { strbuf_putc(sb, *p); } } newargv = (const char **)malloc(sizeof(char *) * (*argc + count + 1)); if (!newargv) die("Short of memory."); newargv[i++] = argv[0]; p = strbuf_value(sb); while (count--) { newargv[i++] = p; p += strlen(p) + 1; } while (j < *argc) newargv[i++] = argv[j++]; newargv[i] = NULL; argv = (char **)newargv; *argc = i;#ifdef DEBUG for (i = 0; i < *argc; i++) fprintf(stderr, "argv[%d] = '%s'\n", i, argv[i]);#endif /* doesn't close string buffer. */ return argv;}intmain(argc, argv) int argc; char *argv[];{ const char *path, *av = NULL; int func_total, file_total; char arg_dbpath[MAXPATHLEN]; const char *index = NULL; int optchar; int option_index = 0; time_t start_time, end_time, start_all_time, end_all_time, T_makedupindex, T_makedefineindex, T_makefileindex, T_makeincludeindex, T_makehtml, T_all; arg_dbpath[0] = 0; basic_check(); configuration(argc, argv); setup_langmap(langmap); save_environment(argc, argv);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -