/** * gtags_delete: delete records belong to set of fid. * * @param[in] gtop #GTOP structure * @param[in] deleteset bit array of fid */ void gtags_delete(GTOP *gtop, IDSET *deleteset) { const char *tagline; int fid; long id; #ifdef USE_SQLITE3 if (gtop->dbop->openflags & DBOP_SQLITE3) { STRBUF *where = strbuf_open(0); strbuf_puts(where, "("); for (id = idset_first(deleteset); id != END_OF_ID; id = idset_next(deleteset)) { strbuf_puts(where, "'"); strbuf_putn(where, id); strbuf_puts(where, "',"); } strbuf_unputc(where, ','); strbuf_puts(where, ")"); dbop_delete(gtop->dbop, strbuf_value(where)); strbuf_close(where); } else #endif for (tagline = dbop_first(gtop->dbop, NULL, NULL, 0); tagline; tagline = dbop_next(gtop->dbop)) { /* * Extract path from the tag line. */ fid = atoi(tagline); /* * If the file id exists in the deleteset, delete the tagline. */ if (idset_contains(deleteset, fid)) dbop_delete(gtop->dbop, NULL); } }
/** * Return the number of bits. * * @param[in] idset idset structure * @return number of bits */ unsigned int idset_count(IDSET *idset) { unsigned int id, count = 0; for (id = idset_first(idset); id != END_OF_ID; id = idset_next(idset)) count++; return count; }
/* * 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]); }