/[global]/global/gtags/gtags.c
ViewVC logotype

Diff of /global/gtags/gtags.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.151 by h-iwamoto, Fri Nov 4 17:42:14 2005 UTC revision 1.152 by shigio, Sat Nov 5 14:07:10 2005 UTC
# Line 345  main(int argc, char **argv) Line 345  main(int argc, char **argv)
345                           * files other than source code. In this case, file id                           * files other than source code. In this case, file id
346                           * doesn't exist in GPATH.                           * doesn't exist in GPATH.
347                           */                           */
348                          fid = gpath_path2fid(p);                          fid = gpath_path2fid(p, NULL);
349                          if (fid) {                          if (fid) {
350                                  fputs("/S/", stdout);                                  fputs("/S/", stdout);
351                                  fputs(fid, stdout);                                  fputs(fid, stdout);
# Line 409  main(int argc, char **argv) Line 409  main(int argc, char **argv)
409          } else if (do_find) {          } else if (do_find) {
410                  /*                  /*
411                   * This code is used by htags(1) to traverse file system.                   * This code is used by htags(1) to traverse file system.
                  *  
                  * If the --other option is not specified, 'gtags --find'  
                  * read GPATH instead of traversing file. But if the option  
                  * is specified, it traverse file system every time.  
                  * It is because gtags doesn't record the paths other than  
                  * source file in GPATH.  
                  * Since it is slow, gtags should record not only source  
                  * files but also other files in GPATH in the future.  
                  * But it needs adding a new format version.  
412                   */                   */
413                  const char *path;                  const char *path;
414                  const char *local = (argc) ? argv[0] : NULL;                  const char *local = (argc) ? argv[0] : NULL;
415    
416                  for (vfind_open(local, other_files); (path = vfind_read()) != NULL; ) {                  getdbpath(cwd, root, dbpath, 0);
417                    gfind_open(dbpath, local, other_files);
418                    while ((path = gfind_read()) != NULL) {
419                          fputs(path, stdout);                          fputs(path, stdout);
420                          fputc('\n', stdout);                          fputc('\n', stdout);
421                  }                  }
422                  vfind_close();                  gfind_close();
423                  exit(0);                  exit(0);
424          } else if (do_sort) {          } else if (do_sort) {
425                  /*                  /*
# Line 703  incremental(const char *dbpath, const ch Line 696  incremental(const char *dbpath, const ch
696          time_t gtags_mtime;          time_t gtags_mtime;
697          STRBUF *addlist = strbuf_open(0);          STRBUF *addlist = strbuf_open(0);
698          STRBUF *deletelist = strbuf_open(0);          STRBUF *deletelist = strbuf_open(0);
699            STRBUF *addlist_other = strbuf_open(0);
700            STRBUF *deletelist_other = strbuf_open(0);
701          IDSET *deleteset;          IDSET *deleteset;
702          int updated = 0;          int updated = 0;
703          const char *path;          const char *path;
704            int i, limit;
705    
706          if (vflag) {          if (vflag) {
707                  fprintf(stderr, " Tag found in '%s'.\n", dbpath);                  fprintf(stderr, " Tag found in '%s'.\n", dbpath);
# Line 732  incremental(const char *dbpath, const ch Line 728  incremental(const char *dbpath, const ch
728          total = 0;          total = 0;
729          while ((path = find_read()) != NULL) {          while ((path = find_read()) != NULL) {
730                  const char *fid;                  const char *fid;
731                    int other = 0;
732    
733                  /* a blank at the head of path means 'NOT SOURCE'. */                  /* a blank at the head of path means 'NOT SOURCE'. */
734                  if (*path == ' ')                  if (*path == ' ') {
735                          continue;                          if (test("b", ++path))
736                                    continue;
737                            other = 1;
738                    }
739                  if (stat(path, &statp) < 0)                  if (stat(path, &statp) < 0)
740                          die("stat failed '%s'.", path);                          die("stat failed '%s'.", path);
741                  if ((fid = gpath_path2fid(path)) == NULL) {                  fid = gpath_path2fid(path, NULL);
742                          strbuf_puts0(addlist, path);                  if (other) {
743                          total++;                          if (fid == NULL)
744                  } else if (gtags_mtime < statp.st_mtime) {                                  strbuf_puts0(addlist_other, path);
745                          strbuf_puts0(addlist, path);                  } else {
746                          total++;                          if (fid == NULL) {
747                          idset_add(deleteset, atoi(fid));                                  strbuf_puts0(addlist, path);
748                                    total++;
749                            } else if (gtags_mtime < statp.st_mtime) {
750                                    strbuf_puts0(addlist, path);
751                                    total++;
752                                    idset_add(deleteset, atoi(fid));
753                            }
754                  }                  }
755          }          }
756          find_close();          find_close();
757          /*          /*
758           * make delete list.           * make delete list.
759             *
760             * deletelist: source files
761             * deletelist_other: other files
762           */           */
763          {          limit = gpath_nextkey();
764            for (i = 1; i < limit; i++) {
765                  char fid[32];                  char fid[32];
766                  int i, limit = gpath_nextkey();                  int other;
767    
768                  for (i = 1; i < limit; i++) {                  snprintf(fid, sizeof(fid), "%d", i);
769                          snprintf(fid, sizeof(fid), "%d", i);                  if ((path = gpath_fid2path(fid, &other)) == NULL)
770                          if ((path = gpath_fid2path(fid)) == NULL)                          continue;
771                                  continue;                  if (!test("f", path)) {
772                          if (!test("f", path)) {                          if (other) {
773                                    strbuf_puts0(deletelist_other, path);
774                            } else {
775                                  strbuf_puts0(deletelist, path);                                  strbuf_puts0(deletelist, path);
776                                  idset_add(deleteset, i);                                  idset_add(deleteset, i);
777                          }                          }
778                  }                  }
779          }          }
780          gpath_close();          gpath_close();
         if (strbuf_getlen(addlist) + strbuf_getlen(deletelist))  
                 updated = 1;  
781          /*          /*
782           * execute updating.           * execute updating.
783           */           */
784          if (updated) {          if (strbuf_getlen(addlist) + strbuf_getlen(deletelist)) {
785                  int db;                  int db;
786    
787                  for (db = GTAGS; db < GTAGLIM; db++) {                  for (db = GTAGS; db < GTAGLIM; db++) {
# Line 785  incremental(const char *dbpath, const ch Line 795  incremental(const char *dbpath, const ch
795                                  fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(db));                                  fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(db));
796                          updatetags(dbpath, root, deleteset, addlist, db);                          updatetags(dbpath, root, deleteset, addlist, db);
797                  }                  }
798                    updated = 1;
799          }          }
800          if (strbuf_getlen(deletelist) > 0) {          if (strbuf_getlen(deletelist) + strbuf_getlen(deletelist_other) + strbuf_getlen(addlist_other) > 0) {
801                  const char *start = strbuf_value(deletelist);                  const char *start, *end, *p;
                 const char *end = start + strbuf_getlen(deletelist);  
                 const char *p;  
802    
803                    if (vflag)
804                            fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(0));
805                  gpath_open(dbpath, 2);                  gpath_open(dbpath, 2);
806                  for (p = start; p < end; p += strlen(p) + 1) {                  if (strbuf_getlen(deletelist) > 0) {
807                          gpath_delete(p);                          start = strbuf_value(deletelist);
808                            end = start + strbuf_getlen(deletelist);
809    
810                            for (p = start; p < end; p += strlen(p) + 1)
811                                    gpath_delete(p);
812                    }
813                    if (strbuf_getlen(deletelist_other) > 0) {
814                            start = strbuf_value(deletelist_other);
815                            end = start + strbuf_getlen(deletelist_other);
816    
817                            for (p = start; p < end; p += strlen(p) + 1)
818                                    gpath_delete(p);
819                    }
820                    if (strbuf_getlen(addlist_other) > 0) {
821                            start = strbuf_value(addlist_other);
822                            end = start + strbuf_getlen(addlist_other);
823    
824                            for (p = start; p < end; p += strlen(p) + 1)
825                                    gpath_put(p, 1);
826                  }                  }
827                  gpath_close();                  gpath_close();
828                    updated = 1;
829          }          }
830          if (updated) {          if (updated) {
831                  int db;                  int db;
# Line 819  incremental(const char *dbpath, const ch Line 849  incremental(const char *dbpath, const ch
849          }          }
850          strbuf_close(addlist);          strbuf_close(addlist);
851          strbuf_close(deletelist);          strbuf_close(deletelist);
852            strbuf_close(addlist_other);
853            strbuf_close(deletelist_other);
854          idset_close(deleteset);          idset_close(deleteset);
855    
856          return updated;          return updated;
# Line 873  updatetags(const char *dbpath, const cha Line 905  updatetags(const char *dbpath, const cha
905                  for (i = 0; i < deleteset->max; i++) {                  for (i = 0; i < deleteset->max; i++) {
906                          if (idset_contains(deleteset, i)) {                          if (idset_contains(deleteset, i)) {
907                                  snprintf(fid, sizeof(fid), "%d", i);                                  snprintf(fid, sizeof(fid), "%d", i);
908                                  path = gpath_fid2path(fid);                                  path = gpath_fid2path(fid, NULL);
909                                  if (path == NULL)                                  if (path == NULL)
910                                          die("GPATH is corrupted.");                                          die("GPATH is corrupted.");
911                                  fprintf(stderr, " [%d/%d] deleting tags of %s\n", seqno++, total, path + 2);                                  fprintf(stderr, " [%d/%d] deleting tags of %s\n", seqno++, total, path + 2);

Legend:
Removed from v.1.151  
changed lines
  Added in v.1.152

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26