/[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.116 by h-iwamoto, Sun Jun 26 04:57:30 2005 UTC revision 1.117 by h-iwamoto, Mon Jun 27 12:39:51 2005 UTC
# Line 51  Line 51 
51  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
52  #include <unistd.h>  #include <unistd.h>
53  #endif  #endif
54    #ifdef HAVE_LIMITS_H
55    #include <limits.h>
56    #endif
57  #include "getopt.h"  #include "getopt.h"
58    
59  #include "global.h"  #include "global.h"
# Line 63  void onintr(int); Line 66  void onintr(int);
66  int match(const char *, const char *);  int match(const char *, const char *);
67  int main(int, char **);  int main(int, char **);
68  int incremental(const char *, const char *);  int incremental(const char *, const char *);
69  void updatetags(const char *, const char *, STRBUF *, STRBUF *, STRBUF *, int);  void updatetags(const char *, const char *, const unsigned char *, int, STRBUF *, int);
70  void createtags(const char *, const char *, int);  void createtags(const char *, const char *, int);
71  int printconf(const char *);  int printconf(const char *);
72  void set_base_directory(const char *, const char *);  void set_base_directory(const char *, const char *);
# Line 676  incremental(dbpath, root) Line 679  incremental(dbpath, root)
679  {  {
680          struct stat statp;          struct stat statp;
681          time_t gtags_mtime;          time_t gtags_mtime;
682          STRBUF *addlist = strbuf_open(0);          STRBUF *extractlist = strbuf_open(0);
         STRBUF *updatelist = strbuf_open(0);  
683          STRBUF *deletelist = strbuf_open(0);          STRBUF *deletelist = strbuf_open(0);
684            unsigned char *fidset;
685            int max_fid = 0;
686          int updated = 0;          int updated = 0;
687          const char *path;          const char *path;
688    
# Line 696  incremental(dbpath, root) Line 700  incremental(dbpath, root)
700    
701          if (gpath_open(dbpath, 0) < 0)          if (gpath_open(dbpath, 0) < 0)
702                  die("GPATH not found.");                  die("GPATH not found.");
703            fidset = (unsigned char *)calloc((gpath_nextkey() + CHAR_BIT - 1) / CHAR_BIT, 1);
704            if (fidset == NULL)
705                    die("short of memory.");
706          /*          /*
707           * make add list and update list.           * make add list and update list.
708           */           */
709          for (find_open(NULL); (path = find_read()) != NULL; ) {          for (find_open(NULL); (path = find_read()) != NULL; ) {
710                    const char *fid;
711                    int i;
712    
713                  /* a blank at the head of path means 'NOT SOURCE'. */                  /* a blank at the head of path means 'NOT SOURCE'. */
714                  if (*path == ' ')                  if (*path == ' ')
715                          continue;                          continue;
716                  if (stat(path, &statp) < 0)                  if (stat(path, &statp) < 0)
717                          die("stat failed '%s'.", path);                          die("stat failed '%s'.", path);
718                  if (!gpath_path2fid(path))                  if ((fid = gpath_path2fid(path)) == NULL)
719                          strbuf_puts0(addlist, path);                          strbuf_puts0(extractlist, path);
720                  else if (gtags_mtime < statp.st_mtime)                  else if (gtags_mtime < statp.st_mtime) {
721                          strbuf_puts0(updatelist, path);                          strbuf_puts0(extractlist, path);
722                            i = atoi(fid);
723                            fidset[i / CHAR_BIT] |= 1 << (i % CHAR_BIT);
724                            if (i >= max_fid)
725                                    max_fid = i + 1;
726                    }
727          }          }
728          find_close();          find_close();
729          /*          /*
# Line 722  incremental(dbpath, root) Line 737  incremental(dbpath, root)
737                          snprintf(fid, sizeof(fid), "%d", i);                          snprintf(fid, sizeof(fid), "%d", i);
738                          if ((path = gpath_fid2path(fid)) == NULL)                          if ((path = gpath_fid2path(fid)) == NULL)
739                                  continue;                                  continue;
740                          if (!test("f", path))                          if (!test("f", path)) {
741                                  strbuf_puts0(deletelist, path);                                  strbuf_puts0(deletelist, path);
742                                    fidset[i / CHAR_BIT] |= 1 << (i % CHAR_BIT);
743                                    if (i >= max_fid)
744                                            max_fid = i + 1;
745                            }
746                  }                  }
747          }          }
748          gpath_close();          gpath_close();
749          if (strbuf_getlen(addlist) + strbuf_getlen(deletelist) + strbuf_getlen(updatelist))          if (strbuf_getlen(extractlist) + strbuf_getlen(deletelist))
750                  updated = 1;                  updated = 1;
751          /*          /*
752           * execute updating.           * execute updating.
# Line 745  incremental(dbpath, root) Line 764  incremental(dbpath, root)
764                                  continue;                                  continue;
765                          if (vflag)                          if (vflag)
766                                  fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(db));                                  fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(db));
767                          updatetags(dbpath, root, addlist, updatelist, deletelist, db);                          updatetags(dbpath, root, fidset, max_fid, extractlist, db);
768                          if (exitflag)                          if (exitflag)
769                                  exit(1);                                  exit(1);
770                  }                  }
# Line 785  incremental(dbpath, root) Line 804  incremental(dbpath, root)
804                          fprintf(stderr, " Global databases are up to date.\n");                          fprintf(stderr, " Global databases are up to date.\n");
805                  fprintf(stderr, "[%s] Done.\n", now());                  fprintf(stderr, "[%s] Done.\n", now());
806          }          }
807          strbuf_close(addlist);          strbuf_close(extractlist);
808          strbuf_close(deletelist);          strbuf_close(deletelist);
809          strbuf_close(updatelist);          free(fidset);
810          return updated;          return updated;
811  }  }
812  /*  /*
# Line 795  incremental(dbpath, root) Line 814  incremental(dbpath, root)
814   *   *
815   *      i)      dbpath          directory in which tag file exist   *      i)      dbpath          directory in which tag file exist
816   *      i)      root            root directory of source tree   *      i)      root            root directory of source tree
817   *      i)      addlist         \0 separated list of added files   *      i)      fidset          bit array of fid of deleted or modified files
818   *      i)      updatelist      \0 separated list of modified files   *      i)      max_fid         number of bits in bit array
819   *      i)      deletelist      \0 separated list of deleted files   *      i)      extractlist     \0 separated list of added or modified files
820   *      i)      db              GTAGS, GRTAGS, GSYMS   *      i)      db              GTAGS, GRTAGS, GSYMS
821   */   */
822  void  void
823  updatetags(dbpath, root, addlist, updatelist, deletelist, db)  updatetags(dbpath, root, fidset, max_fid, extractlist, db)
824          const char *dbpath;          const char *dbpath;
825          const char *root;          const char *root;
826          STRBUF *addlist;          const unsigned char *fidset;
827          STRBUF *updatelist;          int max_fid;
828          STRBUF *deletelist;          STRBUF *extractlist;
829          int db;          int db;
830  {  {
831          GTOP *gtop;          GTOP *gtop;
832          const char *path;          const char *path;
833          const char *comline;          const char *comline;
834          const char *end1, *end2;          const char *end;
835          STRBUF *sb = strbuf_open(0);          STRBUF *sb = strbuf_open(0);
836          int gflags;          int gflags;
837    
# Line 831  updatetags(dbpath, root, addlist, update Line 850  updatetags(dbpath, root, addlist, update
850    
851          gtop = gtags_open(dbpath, root, db, GTAGS_MODIFY, 0);          gtop = gtags_open(dbpath, root, db, GTAGS_MODIFY, 0);
852    
853          path = strbuf_value(deletelist);          if (max_fid > 0) {
         end1 = path + strbuf_getlen(deletelist);  
         end2 = strbuf_value(updatelist) + strbuf_getlen(updatelist);  
         for (;;) {  
                 if (path == end1)  
                         path = strbuf_value(updatelist);  
                 if (path == end2)  
                         break;  
854                  if (vflag)                  if (vflag)
855                          fprintf(stderr, " deleting tags of %s\n", path);                          fprintf(stderr, " deleting tags\n");
856                  gtags_delete(gtop, path);                  gtags_delete_by_fidset(gtop, fidset, max_fid);
                 if (exitflag)  
                         break;  
                 path += strlen(path) + 1;  
857          }          }
858    
859            if (vflag)
860                    fprintf(stderr, " adding tags\n");
861          gflags = 0;          gflags = 0;
862          if (extractmethod)          if (extractmethod)
863                  gflags |= GTAGS_EXTRACTMETHOD;                  gflags |= GTAGS_EXTRACTMETHOD;
864          if (debug)          if (debug)
865                  gflags |= GTAGS_DEBUG;                  gflags |= GTAGS_DEBUG;
866          path = strbuf_value(addlist);          path = strbuf_value(extractlist);
867          end1 = path + strbuf_getlen(addlist);          end = path + strbuf_getlen(extractlist);
868          end2 = strbuf_value(updatelist) + strbuf_getlen(updatelist);          while (path < end) {
         for (;;) {  
                 if (path == end1)  
                         path = strbuf_value(updatelist);  
                 if (path == end2)  
                         break;  
                 if (vflag)  
                         fprintf(stderr, " adding tags of %s\n", path);  
869                  gtags_add(gtop, comline, path, gflags);                  gtags_add(gtop, comline, path, gflags);
870                  if (exitflag)                  if (exitflag)
871                          break;                          break;

Legend:
Removed from v.1.116  
changed lines
  Added in v.1.117

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