/** * * \fn double *read_special_frequencies(const char *file) * * \brief Reads the file "special_frequencies.txt" if it exists. * If no file exists, then no special frequencies are useable. * * \param file pointer on the filename. * * \return Returns the pointer on an array containing doubles if file * has been successfully opened and read, otherwise returns NULL. * */ double *read_special_frequencies(const char *file) { double *l_pfrq = NULL; double l_value; int l_count; int l_allocated = 0; int l_new_size; if((l_pfrq = (double *)malloc(ALLOC_CHUNK_SIZE * sizeof(double))) != NULL) { l_allocated += ALLOC_CHUNK_SIZE; if(FGC_SUCCESS(parser_init(file))) { l_count = 0; while(FGC_SUCCESS(parser_get_next_value(&l_value))) { if(l_count >= l_allocated) { l_new_size = ALLOC_CHUNK_SIZE * (l_count / ALLOC_CHUNK_SIZE + 1); l_pfrq = (double *)realloc(l_pfrq, l_new_size * sizeof(double)); l_allocated += ALLOC_CHUNK_SIZE; } l_pfrq[l_count] = l_value; l_count++; } /* Last value of the array must be -1.0 which is the terminator. */ if(l_count == l_allocated) l_pfrq = (double *)realloc(l_pfrq, (l_count + 1) * sizeof(double)); l_pfrq[l_count] = -1.0; } else { // failed to open file parser_exit(); free(l_pfrq); return 0; } } parser_exit(); return(l_pfrq); }
void parsefile(char *const *argv, const char *cwd, const char *root, const char *dbpath, int db) { int count = 0; int file_count = 0; STRBUF *sb = strbuf_open(0); char *langmap; const char *plugin_parser, *av; char path[MAXPATHLEN]; struct parsefile_data data; if (db == GRTAGS + GSYMS) data.target = TARGET_REF|TARGET_SYM; else data.target = 1 << db; data.extractmethod = getconfb("extractmethod"); if (getconfs("langmap", sb)) langmap = check_strdup(strbuf_value(sb)); else langmap = NULL; strbuf_reset(sb); if (getconfs("gtags_parser", sb)) plugin_parser = strbuf_value(sb); else plugin_parser = NULL; data.cv = convert_open(type, format, root, cwd, dbpath, stdout); if (gpath_open(dbpath, 0) < 0) die("GPATH not found."); if (data.target == TARGET_REF || data.target == TARGET_SYM) { data.dbop = dbop_open(makepath(dbpath, dbname(GTAGS), NULL), 0, 0, 0); if (data.dbop == NULL) die("%s not found.", dbname(GTAGS)); } else { data.dbop = NULL; } data.fid = NULL; parser_init(langmap, plugin_parser); if (langmap != NULL) free(langmap); if (*argv && file_list) args_open_both(argv, file_list); else if (*argv) args_open(argv); else if (file_list) args_open_filelist(file_list); else args_open_nop(); while ((av = args_read()) != NULL) { /* * convert the path into relative to the root directory of source tree. */ if (normalize(av, get_root_with_slash(), cwd, path, sizeof(path)) == NULL) if (!qflag) fprintf(stderr, "'%s' is out of source tree.\n", path + 2); /* * Memorize the file id of the path. This is used in put_syms(). */ { static char s_fid[MAXFIDLEN]; const char *p = gpath_path2fid(path, NULL); if (!p) { if (!qflag) fprintf(stderr, "'%s' not found in GPATH.\n", path + 2); continue; } strlimcpy(s_fid, p, sizeof(s_fid)); data.fid = s_fid; } if (!test("f", makepath(root, path, NULL))) { if (test("d", NULL)) { if (!qflag) fprintf(stderr, "'%s' is a directory.\n", av); } else { if (!qflag) fprintf(stderr, "'%s' not found.\n", av); } continue; } if (lflag && !locatestring(path, localprefix, MATCH_AT_FIRST)) continue; data.count = 0; parse_file(path, 0, put_syms, &data); count += data.count; file_count++; } args_close(); parser_exit(); /* * Settlement */ if (data.dbop != NULL) dbop_close(data.dbop); gpath_close(); convert_close(data.cv); strbuf_close(sb); if (vflag) { print_count(count); fprintf(stderr, " (no index used).\n"); } }
/* * createtags: create tags file * * i) dbpath dbpath directory * i) root root directory of source tree */ void createtags(const char *dbpath, const char *root) { STATISTICS_TIME *tim; STRBUF *sb = strbuf_open(0); struct put_func_data data; int openflags, flags, seqno; const char *path; tim = statistics_time_start("Time of creating %s and %s.", dbname(GTAGS), dbname(GRTAGS)); if (vflag) fprintf(stderr, "[%s] Creating '%s' and '%s'.\n", now(), dbname(GTAGS), dbname(GRTAGS)); openflags = cflag ? GTAGS_COMPACT : 0; data.gtop[GTAGS] = gtags_open(dbpath, root, GTAGS, GTAGS_CREATE, openflags); data.gtop[GTAGS]->flags = 0; if (extractmethod) data.gtop[GTAGS]->flags |= GTAGS_EXTRACTMETHOD; data.gtop[GRTAGS] = gtags_open(dbpath, root, GRTAGS, GTAGS_CREATE, openflags); data.gtop[GRTAGS]->flags = data.gtop[GTAGS]->flags; flags = 0; if (debug) flags |= PARSER_DEBUG; if (wflag) flags |= PARSER_WARNING; /* * Add tags to GTAGS and GRTAGS. */ if (file_list) find_open_filelist(file_list, root); else find_open(NULL); seqno = 0; while ((path = find_read()) != NULL) { if (*path == ' ') { path++; if (!test("b", path)) gpath_put(path, GPATH_OTHER); continue; } gpath_put(path, GPATH_SOURCE); data.fid = gpath_path2fid(path, NULL); if (data.fid == NULL) die("GPATH is corrupted.('%s' not found)", path); seqno++; if (vflag) fprintf(stderr, " [%d] extracting tags of %s\n", seqno, path + 2); if (debug) fprintf(stderr, "[%s]\n", path + 2); parse_file(path, flags, put_syms, &data); gtags_flush(data.gtop[GTAGS], data.fid); gtags_flush(data.gtop[GRTAGS], data.fid); } total = seqno; parser_exit(); find_close(); statistics_time_end(tim); tim = statistics_time_start("Time of flushing B-tree cache"); gtags_close(data.gtop[GTAGS]); gtags_close(data.gtop[GRTAGS]); statistics_time_end(tim); strbuf_reset(sb); if (getconfs("GTAGS_extra", sb)) { tim = statistics_time_start("Time of executing GTAGS_extra command"); if (system(strbuf_value(sb))) fprintf(stderr, "GTAGS_extra command failed: %s\n", strbuf_value(sb)); statistics_time_end(tim); } strbuf_reset(sb); if (getconfs("GRTAGS_extra", sb)) { tim = statistics_time_start("Time of executing GRTAGS_extra command"); if (system(strbuf_value(sb))) fprintf(stderr, "GRTAGS_extra command failed: %s\n", strbuf_value(sb)); statistics_time_end(tim); } strbuf_close(sb); }
/* * updatetags: update tag file. * * i) dbpath directory in which tag file exist * i) root root directory of source tree * i) deleteset bit array of fid of deleted or modified files * i) addlist \0 separated list of added or modified files */ void updatetags(const char *dbpath, const char *root, IDSET *deleteset, STRBUF *addlist) { struct put_func_data data; int seqno, flags; const char *path, *start, *end; if (vflag) fprintf(stderr, "[%s] Updating '%s' and '%s'.\n", now(), dbname(GTAGS), dbname(GRTAGS)); /* * Open tag files. */ data.gtop[GTAGS] = gtags_open(dbpath, root, GTAGS, GTAGS_MODIFY, 0); if (test("f", makepath(dbpath, dbname(GRTAGS), NULL))) { data.gtop[GRTAGS] = gtags_open(dbpath, root, GRTAGS, GTAGS_MODIFY, 0); } else { /* * If you set NULL to data.gtop[GRTAGS], parse_file() doesn't write to * GRTAGS. See put_syms(). */ data.gtop[GRTAGS] = NULL; } /* * Delete tags from GTAGS. */ if (!idset_empty(deleteset)) { if (vflag) { char fid[MAXFIDLEN]; int total = idset_count(deleteset); unsigned int id; seqno = 1; for (id = idset_first(deleteset); id != END_OF_ID; id = idset_next(deleteset)) { snprintf(fid, sizeof(fid), "%d", id); path = gpath_fid2path(fid, NULL); if (path == NULL) die("GPATH is corrupted."); fprintf(stderr, " [%d/%d] deleting tags of %s\n", seqno++, total, path + 2); } } gtags_delete(data.gtop[GTAGS], deleteset); if (data.gtop[GRTAGS] != NULL) gtags_delete(data.gtop[GRTAGS], deleteset); } /* * Set flags. */ data.gtop[GTAGS]->flags = 0; if (extractmethod) data.gtop[GTAGS]->flags |= GTAGS_EXTRACTMETHOD; data.gtop[GRTAGS]->flags = data.gtop[GTAGS]->flags; flags = 0; if (debug) flags |= PARSER_DEBUG; if (wflag) flags |= PARSER_WARNING; /* * Add tags to GTAGS and GRTAGS. */ start = strbuf_value(addlist); end = start + strbuf_getlen(addlist); seqno = 0; for (path = start; path < end; path += strlen(path) + 1) { gpath_put(path, GPATH_SOURCE); data.fid = gpath_path2fid(path, NULL); if (data.fid == NULL) die("GPATH is corrupted.('%s' not found)", path); if (vflag) fprintf(stderr, " [%d/%d] extracting tags of %s\n", ++seqno, total, path + 2); if (debug) fprintf(stderr, "[%s]\n", path + 2); parse_file(path, flags, put_syms, &data); gtags_flush(data.gtop[GTAGS], data.fid); if (data.gtop[GRTAGS] != NULL) gtags_flush(data.gtop[GRTAGS], data.fid); } parser_exit(); gtags_close(data.gtop[GTAGS]); if (data.gtop[GRTAGS] != NULL) gtags_close(data.gtop[GRTAGS]); }