/** * gpath_put: put path name * * @param[in] path path name * @param[in] type path type * GPATH_SOURCE: source file, * GPATH_OTHER: other file */ const char * gpath_put(const char *path, int type) { static char sfid[MAXFIDLEN]; STATIC_STRBUF(sb); assert(opened > 0); if (_mode == 1 && created) return ""; if (dbop_get(dbop, path) != NULL) return ""; /* * generate new file id for the path. */ snprintf(sfid, sizeof(sfid), "%d", _nextkey++); /* * path => fid mapping. */ strbuf_clear(sb); strbuf_puts(sb, sfid); dbop_put_path(dbop, path, strbuf_value(sb), type == GPATH_OTHER ? "o" : NULL); /* * fid => path mapping. */ strbuf_clear(sb); strbuf_puts(sb, path); dbop_put_path(dbop, sfid, strbuf_value(sb), type == GPATH_OTHER ? "o" : NULL); return (const char *)sfid; }
/* * gpath_put: put path name * * i) path path name * i) type path type * GPATH_SOURCE: source file * GPATH_OTHER: other file */ void gpath_put(const char *path, int type) { char fid[MAXFIDLEN]; STATIC_STRBUF(sb); assert(opened > 0); if (_mode == 1 && created) return; if (dbop_get(dbop, path) != NULL) return; /* * generate new file id for the path. */ snprintf(fid, sizeof(fid), "%d", _nextkey++); /* * path => fid mapping. */ strbuf_clear(sb); strbuf_puts0(sb, fid); if (type == GPATH_OTHER) strbuf_puts0(sb, "o"); dbop_put_withlen(dbop, path, strbuf_value(sb), strbuf_getlen(sb)); /* * fid => path mapping. */ strbuf_clear(sb); strbuf_puts0(sb, path); if (type == GPATH_OTHER) strbuf_puts0(sb, "o"); dbop_put_withlen(dbop, fid, strbuf_value(sb), strbuf_getlen(sb)); }
/** * is_defined_in_GTAGS: whether or not the name is defined in #GTAGS. * * @param[in] gtop * @param[in] name tag name * @return 0: not defined, 1: defined * * @note It is assumed that the input stream is sorted by the tag name. */ static int is_defined_in_GTAGS(GTOP *gtop, const char *name) { static char prev_name[MAXTOKEN+1]; static int prev_result; if (!strcmp(name, prev_name)) return prev_result; strlimcpy(prev_name, name, sizeof(prev_name)); return prev_result = dbop_get(gtop->gtags, prev_name) ? 1 : 0; }
/** * gpath_fid2path: convert id into path * * @param[in] fid file id * @param[out] type path type * GPATH_SOURCE: source file, * GPATH_OTHER: other file * @return path name */ const char * gpath_fid2path(const char *fid, int *type) { const char *path = dbop_get(dbop, fid); assert(opened > 0); if (path && type) { const char *flag = dbop_getflag(dbop); *type = (*flag == 'o') ? GPATH_OTHER : GPATH_SOURCE; } return path; }
/** * gpath_path2fid: convert path into id * * @param[in] path path name * @param[out] type path type * GPATH_SOURCE: source file, * GPATH_OTHER: other file * @return file id */ const char * gpath_path2fid(const char *path, int *type) { const char *fid = dbop_get(dbop, path); assert(opened > 0); if (fid && type) { const char *flag = dbop_getflag(dbop); *type = (*flag == 'o') ? GPATH_OTHER : GPATH_SOURCE; } return fid; }
/** * gpath_delete: delete specified path record * * @param[in] path path name */ void gpath_delete(const char *path) { const char *fid; assert(opened > 0); assert(_mode == 2); assert(path[0] == '.' && path[1] == '/'); fid = dbop_get(dbop, path); if (fid == NULL) return; dbop_delete(dbop, fid); dbop_delete(dbop, path); }
static void put_syms(int type, const char *tag, int lno, const char *path, const char *line_image, void *arg) { struct parsefile_data *data = arg; const char *key; if (format == FORMAT_PATH && data->count > 0) return; switch (type) { case PARSER_DEF: if (!(data->target & TARGET_DEF)) return; break; case PARSER_REF_SYM: if (!(data->target & (TARGET_REF | TARGET_SYM))) return; /* * extract method when class method definition. * * Ex: Class::method(...) * * key = 'method' * data = 'Class::method 103 ./class.cpp ...' */ if (data->extractmethod) { if ((key = locatestring(tag, ".", MATCH_LAST)) != NULL) key++; else if ((key = locatestring(tag, "::", MATCH_LAST)) != NULL) key += 2; else key = tag; } else { key = tag; } if (data->target == TARGET_REF || data->target == TARGET_SYM) { if (dbop_get(data->dbop, key) != NULL) { if (!(data->target & TARGET_REF)) return; } else { if (!(data->target & TARGET_SYM)) return; } } break; default: return; } convert_put_using(data->cv, tag, path, lno, line_image, data->fid); data->count++; }
/** * dbop_getoption: get option */ const char * dbop_getoption(DBOP *dbop, const char *key) { static char buf[1024]; const char *p; if ((p = dbop_get(dbop, key)) == NULL) return NULL; if (dbop->lastsize < strlen(key)) die("invalid format (dbop_getoption)."); for (p += strlen(key); *p && isspace((unsigned char)*p); p++) ; strlimcpy(buf, p, sizeof(buf)); return buf; }
/** * Tag command that supports referenced tag must call this function * to decide whether or not the tag is defined. */ int defined(const char *name) { if (dbop == NULL) { const char *dbpath; /* * gtags(1) set GTAGSDBPATH to the path GTAGS exist. */ if (!(dbpath = getenv("GTAGSDBPATH"))) dbpath = "."; dbop = dbop_open(makepath(dbpath, "GTAGS", NULL), 0, 0, 0); if (dbop == NULL) die("'GTAGS' not found."); } if (dbop_get(dbop, name)) return 1; return 0; }
/* * gpath_open: open gpath tag file * * i) dbpath GTAGSDBPATH * i) mode 0: read only * 1: create * 2: modify * r) 0: normal * -1: error */ int gpath_open(const char *dbpath, int mode) { if (opened > 0) { if (mode != _mode) die("duplicate open with different mode."); opened++; return 0; } /* * We create GPATH just first time. */ _mode = mode; if (mode == 1 && created) mode = 0; dbop = dbop_open(makepath(dbpath, dbname(GPATH), NULL), mode, 0644, 0); if (dbop == NULL) return -1; if (mode == 1) { dbop_putversion(dbop, create_version); _nextkey = 1; } else { int format_version; const char *path = dbop_get(dbop, NEXTKEY); if (path == NULL) die("nextkey not found in GPATH."); _nextkey = atoi(path); format_version = dbop_getversion(dbop); if (format_version > support_version) die("GPATH seems new format. Please install the latest GLOBAL."); else if (format_version < support_version) die("GPATH seems older format. Please remake tag files."); } opened++; return 0; }
int main(int argc, char **argv) { char dbpath[MAXPATHLEN]; char cwd[MAXPATHLEN]; STRBUF *sb = strbuf_open(0); int optchar; int option_index = 0; STATISTICS_TIME *tim; while ((optchar = getopt_long(argc, argv, "cd:f:iuIn:oOqvwse", long_options, &option_index)) != EOF) { switch (optchar) { case 0: /* already flags set */ break; case OPT_CONFIG: show_config = 1; if (optarg) config_name = optarg; break; case OPT_GTAGSCONF: gtagsconf = optarg; break; case OPT_GTAGSLABEL: gtagslabel = optarg; break; case OPT_PATH: do_path = 1; if (!strcmp("absolute", optarg)) convert_type = PATH_ABSOLUTE; else if (!strcmp("relative", optarg)) convert_type = PATH_RELATIVE; else if (!strcmp("through", optarg)) convert_type = PATH_THROUGH; else die("Unknown path type."); break; case OPT_SINGLE_UPDATE: iflag++; single_update = optarg; break; case OPT_ENCODE_PATH: if (strlen(optarg) > 255) die("too many encode chars."); if (strchr(optarg, '/') || strchr(optarg, '.')) die("cannot encode '/' and '.' in the path."); set_encode_chars((unsigned char *)optarg); break; case 'c': cflag++; break; case 'd': dump_target = optarg; break; case 'f': file_list = optarg; break; case 'i': iflag++; break; case 'u': uflag++; iflag++; break; case 'I': Iflag++; break; case 'o': /* * Though the -o(--omit-gsyms) was removed, this code * is left for compatibility. */ break; case 'O': Oflag++; break; case 'q': qflag++; setquiet(); break; case 'w': wflag++; break; case 'v': vflag++; setverbose(); break; default: usage(); break; } } if (gtagsconf) { char path[MAXPATHLEN]; if (realpath(gtagsconf, path) == NULL) die("%s not found.", gtagsconf); set_env("GTAGSCONF", path); } if (gtagslabel) { set_env("GTAGSLABEL", gtagslabel); } if (qflag) vflag = 0; if (show_version) version(NULL, vflag); if (show_help) help(); argc -= optind; argv += optind; /* If dbpath is specified, -O(--objdir) option is ignored. */ if (argc > 0) Oflag = 0; if (show_config) { if (config_name) printconf(config_name); else fprintf(stdout, "%s\n", getconfline()); exit(0); } else if (do_path) { /* * This is the main body of path filter. * This code extract path name from tag line and * replace it with the relative or the absolute path name. * * By default, if we are in src/ directory, the output * should be converted like follws: * * main 10 ./src/main.c main(argc, argv)\n * main 22 ./libc/func.c main(argc, argv)\n * v * main 10 main.c main(argc, argv)\n * main 22 ../libc/func.c main(argc, argv)\n * * Similarly, the --path=absolute option specified, then * v * main 10 /prj/xxx/src/main.c main(argc, argv)\n * main 22 /prj/xxx/libc/func.c main(argc, argv)\n */ STRBUF *ib = strbuf_open(MAXBUFLEN); CONVERT *cv; char *ctags_x; if (argc < 3) die("gtags --path: 3 arguments needed."); cv = convert_open(convert_type, FORMAT_CTAGS_X, argv[0], argv[1], argv[2], stdout); while ((ctags_x = strbuf_fgets(ib, stdin, STRBUF_NOCRLF)) != NULL) convert_put(cv, ctags_x); convert_close(cv); strbuf_close(ib); exit(0); } else if (dump_target) { /* * Dump a tag file. */ DBOP *dbop = NULL; const char *dat = 0; int is_gpath = 0; char* target_file = NULL; if (!test("f", dump_target)) { target_file = strchr(dump_target, ':'); if (target_file == NULL) die("file '%s' not found", dump_target); *target_file++ = 0; //move to the next char, which starts the target file. if (!test("f", dump_target)) { die("file '%s' not found.", dump_target); } } if ((dbop = dbop_open(dump_target, 0, 0, DBOP_RAW)) == NULL) die("file '%s' is not a tag file.", dump_target); /* * The file which has a NEXTKEY record is GPATH. */ if (dbop_get(dbop, NEXTKEY)) is_gpath = 1; if (target_file && !is_gpath) { die("dump target_file can only be used with GPATH"); } if (target_file) { dat = dbop_get(dbop, target_file); if (dat == NULL) { die("target_file %s not found in GPATH", target_file); } time_t t = gpath_mtime(dbop, target_file); printf("%d\n", t); } else { for (dat = dbop_first(dbop, NULL, NULL, 0); dat != NULL; dat = dbop_next(dbop)) { const char *flag = is_gpath ? dbop_getflag(dbop) : ""; if (*flag) if (is_gpath) { time_t t = gpath_mtime(dbop, dbop->lastkey); printf("%s\t%s\t%s\t%s\n", dbop->lastkey, dat, flag, ctime(&t)); } else printf("%s\t%s\t%s\n", dbop->lastkey, dat, flag); else printf("%s\t%s\n", dbop->lastkey, dat); } } dbop_close(dbop); exit(0); } else if (Iflag) { if (!usable("mkid")) die("mkid not found."); } /* * If 'gtags.files' exists, use it as a file list. * If the file_list other than "-" is given, it must be readable file. */ if (file_list == NULL && test("f", GTAGSFILES)) file_list = GTAGSFILES; if (file_list && strcmp(file_list, "-")) { if (test("d", file_list)) die("'%s' is a directory.", file_list); else if (!test("f", file_list)) die("'%s' not found.", file_list); else if (!test("r", file_list)) die("'%s' is not readable.", file_list); } /* * Regularize the path name for single updating (--single-update). */ if (single_update) { static char regular_path_name[MAXPATHLEN]; char *p = single_update; if (!test("f", p)) die("'%s' not found.", p); if (isabspath(p)) die("--single-update requires relative path name."); if (!(p[0] == '.' && p[1] == '/')) { snprintf(regular_path_name, MAXPATHLEN, "./%s", p); p = regular_path_name; } single_update = p; } if (!getcwd(cwd, MAXPATHLEN)) die("cannot get current directory."); canonpath(cwd); /* * Decide directory (dbpath) in which gtags make tag files. * * Gtags create tag files at current directory by default. * If dbpath is specified as an argument then use it. * If the -i option specified and both GTAGS and GRTAGS exists * at one of the candidate directories then gtags use existing * tag files. */ if (iflag) { if (argc > 0) realpath(*argv, dbpath); else if (!gtagsexist(cwd, dbpath, MAXPATHLEN, vflag)) strlimcpy(dbpath, cwd, sizeof(dbpath)); } else { if (argc > 0) realpath(*argv, dbpath); else if (Oflag) { char *objdir = getobjdir(cwd, vflag); if (objdir == NULL) die("Objdir not found."); strlimcpy(dbpath, objdir, sizeof(dbpath)); } else strlimcpy(dbpath, cwd, sizeof(dbpath)); } if (iflag && (!test("f", makepath(dbpath, dbname(GTAGS), NULL)) || !test("f", makepath(dbpath, dbname(GRTAGS), NULL)) || !test("f", makepath(dbpath, dbname(GPATH), NULL)))) { if (wflag) warning("GTAGS, GRTAGS or GPATH not found. -i option ignored."); iflag = 0; } if (!test("d", dbpath)) die("directory '%s' not found.", dbpath); if (vflag) fprintf(stderr, "[%s] Gtags started.\n", now()); /* * load configuration file. */ openconf(); if (getconfb("extractmethod")) extractmethod = 1; strbuf_reset(sb); if (getconfs("langmap", sb)) langmap = check_strdup(strbuf_value(sb)); strbuf_reset(sb); if (getconfs("gtags_parser", sb)) gtags_parser = check_strdup(strbuf_value(sb)); /* * initialize parser. */ if (vflag && gtags_parser) fprintf(stderr, " Using plug-in parser.\n"); parser_init(langmap, gtags_parser); if (vflag && file_list) fprintf(stderr, " Using '%s' as a file list.\n", file_list); /* * Start statistics. */ init_statistics(); /* * incremental update. */ if (iflag) { /* * Version check. If existing tag files are old enough * gtagsopen() abort with error message. */ GTOP *gtop = gtags_open(dbpath, cwd, GTAGS, GTAGS_MODIFY, 0); gtags_close(gtop); /* * GPATH is needed for incremental updating. * Gtags check whether or not GPATH exist, since it may be * removed by mistake. */ if (!test("f", makepath(dbpath, dbname(GPATH), NULL))) die("Old version tag file found. Please remake it."); (void)incremental(dbpath, cwd); print_statistics(statistics); exit(0); } /* * create GTAGS and GRTAGS */ createtags(dbpath, cwd); /* * create idutils index. */ if (Iflag) { tim = statistics_time_start("Time of creating ID"); if (vflag) fprintf(stderr, "[%s] Creating indexes for idutils.\n", now()); strbuf_reset(sb); strbuf_puts(sb, "mkid"); if (vflag) strbuf_puts(sb, " -v"); strbuf_sprintf(sb, " --file='%s/ID'", dbpath); if (vflag) { #ifdef __DJGPP__ if (is_unixy()) /* test for 4DOS as well? */ #endif strbuf_puts(sb, " 1>&2"); } else { strbuf_puts(sb, " >/dev/null"); } if (debug) fprintf(stderr, "executing mkid like: %s\n", strbuf_value(sb)); if (system(strbuf_value(sb))) die("mkid failed: %s", strbuf_value(sb)); if (chmod(makepath(dbpath, "ID", NULL), 0644) < 0) die("cannot chmod ID file."); statistics_time_end(tim); } if (vflag) fprintf(stderr, "[%s] Done.\n", now()); closeconf(); strbuf_close(sb); print_statistics(statistics); return 0; }
int main(int argc, char **argv) { char dbpath[MAXPATHLEN]; char cwd[MAXPATHLEN]; STRBUF *sb = strbuf_open(0); int optchar; int option_index = 0; STATISTICS_TIME *tim; /* * Setup GTAGSCONF and GTAGSLABEL environment variable * according to the --gtagsconf and --gtagslabel option. */ preparse_options(argc, argv); /* * Get the project root directory. */ if (!vgetcwd(cwd, MAXPATHLEN)) die("cannot get current directory."); canonpath(cwd); /* * Load configuration file. */ openconf(cwd); configuration(); setenv_from_config(); { char *env = getenv("GTAGS_OPTIONS"); if (env && *env) argv = prepend_options(&argc, argv, env); } logging_arguments(argc, argv); while ((optchar = getopt_long(argc, argv, "cd:f:iIn:oOqvwse", long_options, &option_index)) != EOF) { switch (optchar) { case 0: /* already flags set */ break; case OPT_CONFIG: show_config = 1; if (optarg) config_name = optarg; break; case OPT_GTAGSCONF: case OPT_GTAGSLABEL: /* These options are already parsed in preparse_options() */ break; case OPT_SINGLE_UPDATE: iflag++; single_update = optarg; break; case OPT_ACCEPT_DOTFILES: set_accept_dotfiles(); break; case 'c': cflag++; break; case 'd': dump_target = optarg; break; case 'f': file_list = optarg; break; case 'i': iflag++; break; case 'I': Iflag++; break; case 'o': /* * Though the -o(--omit-gsyms) was removed, this code * is left for compatibility. */ break; case 'O': Oflag++; break; case 'q': qflag++; setquiet(); break; case 'w': wflag++; break; case 'v': vflag++; setverbose(); break; default: usage(); break; } } if (qflag) vflag = 0; if (show_version) version(NULL, vflag); if (show_help) help(); argc -= optind; argv += optind; /* If dbpath is specified, -O(--objdir) option is ignored. */ if (argc > 0) Oflag = 0; if (show_config) { openconf(setupdbpath(0) == 0 ? get_root() : NULL); if (config_name) printconf(config_name); else fprintf(stdout, "%s\n", getconfline()); exit(0); } else if (dump_target) { /* * Dump a tag file. */ DBOP *dbop = NULL; const char *dat = 0; int is_gpath = 0; if (!test("f", dump_target)) die("file '%s' not found.", dump_target); if ((dbop = dbop_open(dump_target, 0, 0, DBOP_RAW)) == NULL) die("file '%s' is not a tag file.", dump_target); /* * The file which has a NEXTKEY record is GPATH. */ if (dbop_get(dbop, NEXTKEY)) is_gpath = 1; for (dat = dbop_first(dbop, NULL, NULL, 0); dat != NULL; dat = dbop_next(dbop)) { const char *flag = is_gpath ? dbop_getflag(dbop) : ""; if (*flag) printf("%s\t%s\t%s\n", dbop->lastkey, dat, flag); else printf("%s\t%s\n", dbop->lastkey, dat); } dbop_close(dbop); exit(0); } else if (Iflag) { #define REQUIRED_MKID_VERSION "4.5" char *p; if (!usable("mkid")) die("mkid not found."); if (read_first_line("mkid --version", sb)) die("mkid cannot executed."); p = strrchr(strbuf_value(sb), ' '); if (p == NULL) die("invalid version string of mkid: %s", strbuf_value(sb)); switch (check_version(p + 1, REQUIRED_MKID_VERSION) #ifdef _WIN32 || strcmp(p + 1, "3.2.99") == 0 #endif ) { case 1: break; /* OK */ case 0: die("mkid version %s or later is required.", REQUIRED_MKID_VERSION); default: die("invalid version string of mkid: %s", strbuf_value(sb)); } } /* * If 'gtags.files' exists, use it as a file list. * If the file_list other than "-" is given, it must be readable file. */ if (file_list == NULL && test("f", GTAGSFILES)) file_list = GTAGSFILES; if (file_list && strcmp(file_list, "-")) { if (test("d", file_list)) die("'%s' is a directory.", file_list); else if (!test("f", file_list)) die("'%s' not found.", file_list); else if (!test("r", file_list)) die("'%s' is not readable.", file_list); } /* * Regularize the path name for single updating (--single-update). */ if (single_update) { static char regular_path_name[MAXPATHLEN]; char *p = single_update; if (!test("f", p)) die("'%s' not found.", p); #if _WIN32 || __DJGPP__ for (; *p; p++) if (*p == '\\') *p = '/'; p = single_update; #define LOCATEFLAG MATCH_AT_FIRST|IGNORE_CASE #else #define LOCATEFLAG MATCH_AT_FIRST #endif if (isabspath(p)) { char *q = locatestring(p, cwd, LOCATEFLAG); if (q && *q == '/') snprintf(regular_path_name, MAXPATHLEN, "./%s", q + 1); else die("path '%s' is out of the project.", p); } else { if (p[0] == '.' && p[1] == '/') snprintf(regular_path_name, MAXPATHLEN, "%s", p); else snprintf(regular_path_name, MAXPATHLEN, "./%s", p); } single_update = regular_path_name; } /* * Decide directory (dbpath) in which gtags make tag files. * * Gtags create tag files at current directory by default. * If dbpath is specified as an argument then use it. * If the -i option specified and both GTAGS and GRTAGS exists * at one of the candidate directories then gtags use existing * tag files. */ if (iflag) { if (argc > 0) realpath(*argv, dbpath); else if (!gtagsexist(cwd, dbpath, MAXPATHLEN, vflag)) strlimcpy(dbpath, cwd, sizeof(dbpath)); } else { if (argc > 0) realpath(*argv, dbpath); else if (Oflag) { char *objdir = getobjdir(cwd, vflag); if (objdir == NULL) die("Objdir not found."); strlimcpy(dbpath, objdir, sizeof(dbpath)); } else strlimcpy(dbpath, cwd, sizeof(dbpath)); } if (iflag && (!test("f", makepath(dbpath, dbname(GTAGS), NULL)) || !test("f", makepath(dbpath, dbname(GRTAGS), NULL)) || !test("f", makepath(dbpath, dbname(GPATH), NULL)))) { if (wflag) warning("GTAGS, GRTAGS or GPATH not found. -i option ignored."); iflag = 0; } if (!test("d", dbpath)) die("directory '%s' not found.", dbpath); if (vflag) fprintf(stderr, "[%s] Gtags started.\n", now()); /* * initialize parser. */ if (vflag && gtags_parser) fprintf(stderr, " Using plug-in parser.\n"); parser_init(langmap, gtags_parser); if (vflag && file_list) fprintf(stderr, " Using '%s' as a file list.\n", file_list); /* * Start statistics. */ init_statistics(); /* * incremental update. */ if (iflag) { /* * Version check. If existing tag files are old enough * gtagsopen() abort with error message. */ GTOP *gtop = gtags_open(dbpath, cwd, GTAGS, GTAGS_MODIFY, 0); gtags_close(gtop); /* * GPATH is needed for incremental updating. * Gtags check whether or not GPATH exist, since it may be * removed by mistake. */ if (!test("f", makepath(dbpath, dbname(GPATH), NULL))) die("Old version tag file found. Please remake it."); (void)incremental(dbpath, cwd); print_statistics(statistics); exit(0); } /* * create GTAGS and GRTAGS */ createtags(dbpath, cwd); /* * create idutils index. */ if (Iflag) { FILE *op; GFIND *gp; const char *path; tim = statistics_time_start("Time of creating ID"); if (vflag) fprintf(stderr, "[%s] Creating indexes for idutils.\n", now()); strbuf_reset(sb); /* * Since idutils stores the value of PWD in ID file, we need to * force idutils to follow our style. */ #if _WIN32 || __DJGPP__ strbuf_puts(sb, "mkid --files0-from=-"); #else strbuf_sprintf(sb, "PWD=%s mkid --files0-from=-", quote_shell(cwd)); #endif if (vflag) strbuf_puts(sb, " -v"); strbuf_sprintf(sb, " --file=%s/ID", quote_shell(dbpath)); if (vflag) { #ifdef __DJGPP__ if (is_unixy()) /* test for 4DOS as well? */ #endif strbuf_puts(sb, " 1>&2"); } else { strbuf_puts(sb, " >" NULL_DEVICE); #ifdef __DJGPP__ if (is_unixy()) /* test for 4DOS as well? */ #endif strbuf_puts(sb, " 2>&1"); } if (debug) fprintf(stderr, "executing mkid like: %s\n", strbuf_value(sb)); op = popen(strbuf_value(sb), "w"); if (op == NULL) die("cannot execute '%s'.", strbuf_value(sb)); gp = gfind_open(dbpath, NULL, GPATH_BOTH); while ((path = gfind_read(gp)) != NULL) { fputs(path, op); fputc('\0', op); } gfind_close(gp); if (pclose(op) != 0) die("terminated abnormally '%s' (errno = %d).", strbuf_value(sb), errno); if (test("f", makepath(dbpath, "ID", NULL))) if (chmod(makepath(dbpath, "ID", NULL), 0644) < 0) die("cannot chmod ID file."); statistics_time_end(tim); } if (vflag) fprintf(stderr, "[%s] Done.\n", now()); closeconf(); strbuf_close(sb); print_statistics(statistics); return 0; }