/* * Check whether or not GTAGS exist. * * If GTAGS not found, this function abort with a message. */ static void check_dbpath(void) { char cwd[MAXPATHLEN]; char root[MAXPATHLEN]; char dbpath[MAXPATHLEN]; getdbpath(cwd, root, dbpath, vflag); }
int main(int argc, char **argv) { const char *av = NULL; int db; int optchar; int option_index = 0; while ((optchar = getopt_long(argc, argv, "ace:ifgGIlL:noOpPqrstTuvVx", long_options, &option_index)) != EOF) { switch (optchar) { case 0: break; case 'a': aflag++; break; case 'c': cflag++; setcom(optchar); break; case 'e': av = optarg; break; case 'f': fflag++; xflag++; setcom(optchar); break; case 'g': gflag++; setcom(optchar); break; case 'G': Gflag++; break; case 'i': iflag++; break; case 'I': Iflag++; setcom(optchar); break; case 'l': lflag++; break; case 'L': file_list = optarg; break; case 'n': nflag++; if (optarg) { if (!strcmp(optarg, "sort")) nofilter |= SORT_FILTER; else if (!strcmp(optarg, "path")) nofilter |= PATH_FILTER; } else { nofilter = BOTH_FILTER; } break; case 'o': oflag++; break; case 'O': Oflag++; break; case 'p': pflag++; setcom(optchar); break; case 'P': Pflag++; setcom(optchar); break; case 'q': qflag++; setquiet(); break; case 'r': rflag++; break; case 's': sflag++; break; case 't': tflag++; break; case 'T': Tflag++; break; case 'u': uflag++; setcom(optchar); break; case 'v': vflag++; break; case 'V': Vflag++; break; case 'x': xflag++; break; case ENCODE_PATH: if (strlen(optarg) > 255) die("too many encode chars."); if (strchr(optarg, '/') || strchr(optarg, '.')) die("cannot encode '/' and '.' in the path."); set_encode_chars((unsigned char *)optarg); break; case FROM_HERE: { char *p = optarg; const char *usage = "usage: global --from-here=lineno:path."; context_lineno = p; while (*p && isdigit(*p)) p++; if (*p != ':') die_with_code(2, usage); *p++ = '\0'; if (!*p) die_with_code(2, usage); context_file = p; } break; case RESULT: if (!strcmp(optarg, "ctags-x")) format = FORMAT_CTAGS_X; else if (!strcmp(optarg, "ctags-xid")) format = FORMAT_CTAGS_XID; else if (!strcmp(optarg, "ctags")) format = FORMAT_CTAGS; else if (!strcmp(optarg, "path")) format = FORMAT_PATH; else if (!strcmp(optarg, "grep")) format = FORMAT_GREP; else if (!strcmp(optarg, "cscope")) format = FORMAT_CSCOPE; else die_with_code(2, "unknown format type for the --result option."); break; default: usage(); break; } } if (qflag) vflag = 0; if (show_help) help(); argc -= optind; argv += optind; /* * At first, we pickup pattern from -e option. If it is not found * then use argument which is not option. */ if (!av) { av = *argv; /* * global -g pattern [files ...] * av argv */ if (gflag && av) argv++; } if (show_version) version(av, vflag); /* * only -c, -u, -P and -p allows no argument. */ if (!av) { switch (command) { case 'c': case 'u': case 'p': case 'P': break; case 'f': if (file_list) break; default: usage(); break; } } /* * -u and -p cannot have any arguments. */ if (av) { switch (command) { case 'u': case 'p': usage(); default: break; } } if (tflag) xflag = 0; if (nflag > 1) nosource = 1; /* to keep compatibility */ if (print0) set_print0(); /* * remove leading blanks. */ if (!Iflag && !gflag && av) for (; *av == ' ' || *av == '\t'; av++) ; if (cflag && av && isregex(av)) die_with_code(2, "only name char is allowed with -c option."); /* * get path of following directories. * o current directory * o root of source tree * o dbpath directory * * if GTAGS not found, getdbpath doesn't return. */ getdbpath(cwd, root, dbpath, (pflag && vflag)); /* * print dbpath or rootdir. */ if (pflag) { fprintf(stdout, "%s\n", (rflag) ? root : dbpath); exit(0); } /* * incremental update of tag files. */ if (uflag) { STRBUF *sb = strbuf_open(0); char *gtags = usable("gtags"); if (!gtags) die("gtags command not found."); if (chdir(root) < 0) die("cannot change directory to '%s'.", root); strbuf_puts(sb, gtags); strbuf_puts(sb, " -i"); if (vflag) strbuf_putc(sb, 'v'); strbuf_putc(sb, ' '); strbuf_puts(sb, dbpath); if (system(strbuf_value(sb))) exit(1); strbuf_close(sb); exit(0); } /* * complete function name */ if (cflag) { if (Iflag) completion_idutils(dbpath, root, av); else completion(dbpath, root, av); exit(0); } /* * make local prefix. * local prefix must starts with './' and ends with '/'. */ if (lflag) { STRBUF *sb = strbuf_open(0); strbuf_putc(sb, '.'); if (strcmp(root, cwd) != 0) { char *p = cwd + strlen(root); if (*p != '/') strbuf_putc(sb, '/'); strbuf_puts(sb, p); } strbuf_putc(sb, '/'); localprefix = check_strdup(strbuf_value(sb)); strbuf_close(sb); #ifdef DEBUG fprintf(stderr, "root=%s\n", root); fprintf(stderr, "cwd=%s\n", cwd); fprintf(stderr, "localprefix=%s\n", localprefix); #endif } /* * decide tag type. */ if (context_file) { if (isregex(av)) die_with_code(2, "regular expression is not allowed with the --from-here option."); db = decide_tag_by_context(av, context_file, atoi(context_lineno)); } else { if (rflag && sflag) db = GRTAGS + GSYMS; else db = (rflag) ? GRTAGS : ((sflag) ? GSYMS : GTAGS); } /* * decide format. * The --result option is given to priority more than the -t and -x option. */ if (format == 0) { if (tflag) { /* ctags format */ format = FORMAT_CTAGS; } else if (xflag) { /* print details */ format = FORMAT_CTAGS_X; } else { /* print just a file name */ format = FORMAT_PATH; } } /* * decide path conversion type. */ if (nofilter & PATH_FILTER) type = PATH_THROUGH; else if (aflag) type = PATH_ABSOLUTE; else type = PATH_RELATIVE; /* * exec lid(idutils). */ if (Iflag) { chdir(root); idutils(av, dbpath); } /* * search pattern (regular expression). */ else if (gflag) { chdir(root); grep(av, argv, dbpath); } /* * locate paths including the pattern. */ else if (Pflag) { chdir(root); pathlist(av, dbpath); } /* * parse source files. */ else if (fflag) { chdir(root); parsefile(argv, cwd, root, dbpath, db); } /* * tag search. */ else { tagsearch(av, cwd, root, dbpath, db); } return 0; }
int main(int argc, char **argv) { char c; const char *p, *browser = NULL, *definition = NULL; STRBUF *arg = strbuf_open(0); STRBUF *URL = strbuf_open(0); while (--argc > 0 && ((c = (++argv)[0][0]) == '-' || c == '+')) { if (argv[0][1] == '-') { if (!strcmp("--help", argv[0])) help(); else if (!strcmp("--version", argv[0])) show_version++; else if (!strcmp("--quiet", argv[0])) { qflag++; vflag = 0; } else if (!strcmp("--verbose", argv[0])) { vflag++; qflag = 0; } else usage(); continue; } if (c == '+') { linenumber = atoi(argv[0] + 1); continue; } p = argv[0] + 1; switch (*p) { case 'b': browser = argv[1]; --argc; ++argv; break; case 'd': definition = argv[1]; --argc; ++argv; break; case 'p': pflag++; break; case 'q': qflag++; setquiet(); break; case 'v': vflag++; break; default: usage(); } } if (show_version) version(progname, vflag); /* * Load aliases from .gozillarc. */ load_alias(); /* * Decide browser. */ if (!browser && getenv("BROWSER")) browser = getenv("BROWSER"); if (!browser && alias("BROWSER")) browser = alias("BROWSER"); if (!browser) browser = "mozilla"; /* * Replace alias name. */ if (definition == NULL) { if (argc == 0) usage(); strbuf_puts(arg, argv[0]); /* * Replace with alias value. */ if ((p = alias(strbuf_value(arg))) != NULL) { strbuf_reset(arg); strbuf_puts(arg, p); } } /* * Get URL. */ if (!definition && isprotocol(strbuf_value(arg))) { strbuf_puts(URL, strbuf_value(arg)); } else { getdbpath(cwd, root, dbpath, 0); if (definition) getdefinitionURL(definition, URL); else getURL(strbuf_value(arg), URL); } if (pflag) { fprintf(stdout, "%s\n", strbuf_value(URL)); if (vflag) fprintf(stdout, "using browser '%s'.\n", browser); exit(0); } /* * Show URL's page. */ show_page_by_url(browser, strbuf_value(URL)); exit(0); }