/[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.173 by shigio, Wed Nov 30 02:26:19 2005 UTC revision 1.174 by shigio, Thu Dec 1 02:00:43 2005 UTC
# Line 63  void updatetags(const char *, const char Line 63  void updatetags(const char *, const char
63  void createtags(const char *, const char *, int);  void createtags(const char *, const char *, int);
64  int printconf(const char *);  int printconf(const char *);
65  void set_base_directory(const char *, const char *);  void set_base_directory(const char *, const char *);
 void put_converting(const char *, int, int);  
66    
67  int cflag;                                      /* compact format */  int cflag;                                      /* compact format */
68  int iflag;                                      /* incremental update */  int iflag;                                      /* incremental update */
# Line 87  const char *file_list; Line 86  const char *file_list;
86   */   */
87  int do_path;  int do_path;
88  int fileid;  int fileid;
89  int pathconvert = PATH_RELATIVE;  int convert_type = PATH_RELATIVE;
90  /*  /*
91   * Sort filter   * Sort filter
92   */   */
# Line 161  main(int argc, char **argv) Line 160  main(int argc, char **argv)
160                                          info_string = optarg;                                          info_string = optarg;
161                          } else if (!strcmp(p, "path")) {                          } else if (!strcmp(p, "path")) {
162                                  if (!strcmp("absolute", optarg))                                  if (!strcmp("absolute", optarg))
163                                          pathconvert = PATH_ABSOLUTE;                                          convert_type = PATH_ABSOLUTE;
164                          } else if (!strcmp(p, "format")) {                          } else if (!strcmp(p, "format")) {
165                                  if (!strcmp("ctags", optarg))                                  if (!strcmp("ctags", optarg))
166                                          format = FORMAT_CTAGS;                                          format = FORMAT_CTAGS;
# Line 279  main(int argc, char **argv) Line 278  main(int argc, char **argv)
278                   * main      10 /prj/xxx/src/main.c  main(argc, argv)\n                   * main      10 /prj/xxx/src/main.c  main(argc, argv)\n
279                   * main      22 /prj/xxx/libc/func.c   main(argc, argv)\n                   * main      22 /prj/xxx/libc/func.c   main(argc, argv)\n
280                   */                   */
                 STRBUF *ib = strbuf_open(MAXBUFLEN);  
                 const char *a_root = argv[0];  
                 const char *a_cwd = argv[1];  
                 const char *a_dbpath = argv[2];  
                 const char *ctags_x;  
   
281                  if (argc < 3)                  if (argc < 3)
282                          die("do_path: 3 arguments needed.");                          die("do_path: 3 arguments needed.");
283                  set_base_directory(a_root, a_cwd);                  pathconvert(convert_type, format, fileid, argv[0], argv[1], argv[2], stdin, stdout);
                 if (gpath_open(a_dbpath, 0) < 0)  
                         die("GPATH not found.");  
                 while ((ctags_x = strbuf_fgets(ib, stdin, 0)) != NULL)  
                         put_converting(ctags_x, format, fileid);  
                 gpath_close();  
                 strbuf_close(ib);  
284                  exit(0);                  exit(0);
285          } else if (Iflag) {          } else if (Iflag) {
286                  if (!usable("mkid"))                  if (!usable("mkid"))
# Line 923  printconf(const char *name) Line 910  printconf(const char *name)
910          }          }
911          return exist;          return exist;
912  }  }
 /*  
  * put_converting: convert path into relative or absolute and print.  
  *  
  *      i)      raw output from global(1)  
  *      i)      format  (defined in tagsort.h)  
  *      i)      fileid 1: add fid to the head of line, 0: do nothing  
  */  
 static STRBUF *abspath;  
 static char basedir[MAXPATHLEN+1];  
 static int start_point;  
 void  
 set_base_directory(const char *root, const char *cwd)  
 {  
         abspath = strbuf_open(MAXPATHLEN);  
         strbuf_puts(abspath, root);  
         strbuf_unputc(abspath, '/');  
         start_point = strbuf_getlen(abspath);  
   
         if (strlen(cwd) > MAXPATHLEN)  
                 die("current directory name too long.");  
         strlimcpy(basedir, cwd, sizeof(basedir));  
         /* leave abspath unclosed. */  
 }  
 void  
 put_converting(const char *tagline, int format, int fileid)  
 {  
         char buf[MAXPATHLEN+1];  
         char *path, *p;  
   
         /*  
          * print until path name.  
          */  
         if (format == FORMAT_PATH) {  
                 path = (char *)tagline;  
         } else {        /* FORMAT_CTAGS, FORMAT_CTAGS_X */  
                 int savec = 0;  
                 /*  
                  * Move to the head of path name.  
                  *  
                  * Don't use split() function, since we must support  
                  * following both format:  
                  * ctags:       main    ./main.c     20  
                  * ctags -x:    main      20 ./main.c main()  
                  */  
                 /* skip tag name */  
                 for (p = (char *)tagline; *p && !isspace((unsigned char)*p); p++)  
                         ;  
                 /* skip blanks (and line number) */  
                 for (; *p && *p != '.'; p++)  
                         ;  
                 path = p;  
                 /*  
                  * The --fileid option specified, put file id to the head  
                  * of the output like follows.  
                  *  
                  * 120@main        32 ./main.c main(int argc, char **argv)  
                  * ~~~                ~~~~~~~~~  
                  *  ^                     |  
                  *  +---------------------+  
                  *  
                  * Global.cgi script generated by htags(1) refers it to  
                  * generate anchor.  
                  */  
                 if (fileid) {  
                         for (; *p && !isspace((unsigned char)*p); p++)  
                                 ;  
                         savec = *p;  
                         *p = '\0';  
                         fputs(gpath_path2fid(path, NULL), stdout);  
                         *p = savec;  
                         putc('@', stdout);  
                 }  
                 for (p = (char *)tagline; *p && p < path; p++)  
                         (void)putc(*p, stdout);  
         }  
         if (*path++ == '\0')  
                 return;  
         /*  
          * make absolute path.  
          */  
         strbuf_setlen(abspath, start_point);  
         for (p = path; *p && !isspace((unsigned char)*p); p++)  
                 strbuf_putc(abspath, *p);  
         /*  
          * put path with converting.  
          */  
         if (pathconvert == PATH_ABSOLUTE) {  
                 (void)fputs(strbuf_value(abspath), stdout);  
         } else {  
                 const char *a = strbuf_value(abspath);  
                 const char *b = basedir;  
 #if defined(_WIN32) || defined(__DJGPP__)  
                 /* skip drive char in 'c:/usr/bin' */  
                 while (*a != '/')  
                         a++;  
                 while (*b != '/')  
                         b++;  
 #endif  
                 if (!abs2rel(a, b, buf, sizeof(buf)))  
                         die("abs2rel failed. (path=%s, base=%s).", a, b);  
                 (void)fputs(buf, stdout);  
         }  
         /*  
          * print the rest of the record.  
          */  
         (void)fputs(p, stdout);  
 }  

Legend:
Removed from v.1.173  
changed lines
  Added in v.1.174

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