/[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.158 by shigio, Mon Nov 7 23:56:30 2005 UTC revision 1.159 by h-iwamoto, Tue Nov 8 17:22:43 2005 UTC
# Line 24  Line 24 
24  #endif  #endif
25  #include <sys/types.h>  #include <sys/types.h>
26  #include <sys/stat.h>  #include <sys/stat.h>
 #include <errno.h>  
27    
28  #include <ctype.h>  #include <ctype.h>
29  #include <utime.h>  #include <utime.h>
# Line 91  int do_sort; Line 90  int do_sort;
90  int do_relative;  int do_relative;
91  int do_absolute;  int do_absolute;
92  int cxref;  int cxref;
 int do_expand;  
93  int gtagsconf;  int gtagsconf;
94  int gtagslabel;  int gtagslabel;
95  int debug;  int debug;
 int secure_mode;  
96  const char *extra_options;  const char *extra_options;
97  const char *info_string;  const char *info_string;
98  const char *file_list;  const char *file_list;
# Line 135  static struct option const long_options[ Line 132  static struct option const long_options[
132          {"convert", no_argument, &do_convert, 1},          {"convert", no_argument, &do_convert, 1},
133          {"cxref", no_argument, &cxref, 1},          {"cxref", no_argument, &cxref, 1},
134          {"debug", no_argument, &debug, 1},          {"debug", no_argument, &debug, 1},
         {"expand", required_argument, &do_expand, 1},  
135          {"gtagsconf", required_argument, &gtagsconf, 1},          {"gtagsconf", required_argument, &gtagsconf, 1},
136          {"gtagslabel", required_argument, &gtagslabel, 1},          {"gtagslabel", required_argument, &gtagslabel, 1},
137          {"relative", no_argument, &do_relative, 1},          {"relative", no_argument, &do_relative, 1},
         {"secure", no_argument, &secure_mode, 1},  
138          {"sort", no_argument, &do_sort, 1},          {"sort", no_argument, &do_sort, 1},
139          {"version", no_argument, &show_version, 1},          {"version", no_argument, &show_version, 1},
140          {"help", no_argument, &show_help, 1},          {"help", no_argument, &show_help, 1},
# Line 198  put_lines(char *lines, struct dup_entry Line 193  put_lines(char *lines, struct dup_entry
193  int  int
194  main(int argc, char **argv)  main(int argc, char **argv)
195  {  {
         char root[MAXPATHLEN+1];  
196          char dbpath[MAXPATHLEN+1];          char dbpath[MAXPATHLEN+1];
197          char cwd[MAXPATHLEN+1];          char cwd[MAXPATHLEN+1];
198          STRBUF *sb = strbuf_open(0);          STRBUF *sb = strbuf_open(0);
# Line 292  main(int argc, char **argv) Line 286  main(int argc, char **argv)
286                  STRBUF *ib = strbuf_open(MAXBUFLEN);                  STRBUF *ib = strbuf_open(MAXBUFLEN);
287                  const char *fid;                  const char *fid;
288                  char *p, *q;                  char *p, *q;
                 int c, type;  
289    
290                  /*                  /*
291                   * [Job]                   * [Job]
# Line 305  main(int argc, char **argv) Line 298  main(int argc, char **argv)
298                   *                              v                   *                              v
299                   * <a href='http://xxx/global/S/39.html#110'>main</a>\n                   * <a href='http://xxx/global/S/39.html#110'>main</a>\n
300                   *                   *
                  * If the file is not source code, change into the path to CGI script.  
                  * <a href='http://xxx/global/S/ ./README .html#9'>main</a>\n  
                  *                              |  
                  *                              v  
                  * <a href='http://xxx/global/cgi-bin/global.cgi?pattern=README&amp;type=source#9'>main</a>\n  
301                   */                   */
302                  if (gpath_open(".", 0) < 0)                  if (gpath_open(".", 0) < 0)
303                          die("GPATH not found.");                          die("GPATH not found.");
# Line 322  main(int argc, char **argv) Line 310  main(int argc, char **argv)
310                                  printf("%s: ERROR(1): %s", progname, strbuf_value(ib));                                  printf("%s: ERROR(1): %s", progname, strbuf_value(ib));
311                                  continue;                                  continue;
312                          }                          }
313                          /* Print just before "/S/ " and skip "/S/ ". */                          /* Print from the head of line to "/S/". */
314                          for (; p < q; p++)                          for (; p < q; p++)
315                                  putc(*p, stdout);                                  putc(*p, stdout);
316                          for (; *p && *p != ' '; p++)                          for (; *p && *p != ' '; p++)
317                                  ;                                  putc(*p, stdout);
318                          /* Extract path name. */                          /* Extract path name. */
319                          for (q = ++p; *q && *q != ' '; q++)                          for (q = ++p; *q && *q != ' '; q++)
320                                  ;                                  ;
# Line 335  main(int argc, char **argv) Line 323  main(int argc, char **argv)
323                                  continue;                                  continue;
324                          }                          }
325                          *q++ = '\0';                          *q++ = '\0';
326                          /*                          /* Convert path name into URL. */
327                           * Convert path name into URL.                          fid = gpath_path2fid(p, NULL);
328                           * The output of 'global -xgo' and 'global -xPo' may include                          if (fid == NULL)
329                           * lines about files other than source code. In this case,                                  die("GPATH is corrupted.('%s' not found)", p);
330                           * the HTML file corresponding to file id may not exist.                          fputs(fid, stdout);
331                           */                          fputs(q, stdout);
                         fid = gpath_path2fid(p, &type);  
                         if (fid && type == GPATH_SOURCE) {  
                                 fputs("/S/", stdout);  
                                 fputs(fid, stdout);  
                                 fputs(q, stdout);  
                         } else {  
                                 fputs("/cgi-bin/global.cgi?pattern=", stdout);  
                                 p += 2;  
                                 while ((c = (unsigned char)*p++) != '\0') {  
                                         if (isalnum(c))  
                                                 putc(c, stdout);  
                                         else  
                                                 printf("%%%02x", c);  
                                 }  
                                 fputs("&amp;type=source", stdout);  
                                 for (; *q && *q != '#'; q++)  
                                         ;  
                                 if (*q == '\0') {  
                                         printf("%s: ERROR(2): %s", progname, strbuf_value(ib));  
                                         continue;  
                                 }  
                                 fputs(q, stdout);  
                         }  
332                  }                  }
333                  gpath_close();                  gpath_close();
334                  strbuf_close(ib);                  strbuf_close(ib);
335                  exit(0);                  exit(0);
         } else if (do_expand) {  
                 /*  
                  * The 'gtags --expand' is nearly equivalent with 'expand'.  
                  * We made this command to decrease dependency to external  
                  * command. But now, the --secure option use this command  
                  * positively.  
                  */  
                 FILE *ip;  
                 STRBUF *ib = strbuf_open(MAXBUFLEN);  
   
                 if (argc) {  
                         if (secure_mode) {  
                                 char buf[MAXPATHLEN+1], *path;  
                                 char rootdir[MAXPATHLEN+1];  
   
                                 getdbpath(cwd, root, dbpath, 0);  
                                 snprintf(rootdir, sizeof(rootdir), "%s/", root);  
                                 path = realpath(argv[0], buf);  
                                 if (path == NULL)  
                                         die("realpath(%s, buf) failed. (errno=%d).", argv[0], errno);  
                                 if (!isabspath(path))  
                                         die("realpath(3) is not compatible with BSD version.");  
                                 if (!locatestring(path, rootdir, MATCH_AT_FIRST))  
                                         die("'%s' is out of source tree.", path);  
                         }  
                         ip = fopen(argv[0], "r");  
                         if (ip == NULL)  
                                 exit(1);  
                 } else  
                         ip = stdin;  
                 while (strbuf_fgets(ib, ip, STRBUF_NOCRLF) != NULL)  
                         detab(stdout, strbuf_value(ib));  
                 strbuf_close(ib);  
                 exit(0);  
336          } else if (do_sort) {          } else if (do_sort) {
337                  /*                  /*
338                   * This code and the makedupindex() in htags(1) compose                   * This code and the makedupindex() in htags(1) compose

Legend:
Removed from v.1.158  
changed lines
  Added in v.1.159

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