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 *); |
66 |
void put_converting(const char *, int, int, int); |
void put_converting(const char *, int, int); |
67 |
|
|
68 |
|
#define PATH_RELATIVE 0 |
69 |
|
#define PATH_ABSOLUTE 1 |
70 |
|
|
71 |
int cflag; /* compact format */ |
int cflag; /* compact format */ |
72 |
int iflag; /* incremental update */ |
int iflag; /* incremental update */ |
79 |
int show_version; |
int show_version; |
80 |
int show_help; |
int show_help; |
81 |
int show_config; |
int show_config; |
|
int do_sort; |
|
|
int do_relative; |
|
|
int do_absolute; |
|
|
int ctags; /* option for do_sort */ |
|
|
int cxref; /* option for do_relative and do_absolute */ |
|
|
int fileid; |
|
82 |
int gtagsconf; |
int gtagsconf; |
83 |
int gtagslabel; |
int gtagslabel; |
|
int pathname; |
|
|
int unique; |
|
84 |
int debug; |
int debug; |
|
const char *extra_options; |
|
85 |
const char *info_string; |
const char *info_string; |
86 |
const char *file_list; |
const char *file_list; |
87 |
|
|
88 |
|
/* |
89 |
|
* Path filter |
90 |
|
*/ |
91 |
|
int do_path; |
92 |
|
int fileid; |
93 |
|
int pathconvert = PATH_RELATIVE; |
94 |
|
/* |
95 |
|
* Sort filter |
96 |
|
*/ |
97 |
|
int do_sort; |
98 |
|
int unique; |
99 |
|
int format = TAGSORT_PATH; |
100 |
|
|
101 |
int extractmethod; |
int extractmethod; |
102 |
int total; |
int total; |
103 |
|
|
128 |
{"warning", no_argument, NULL, 'w'}, |
{"warning", no_argument, NULL, 'w'}, |
129 |
|
|
130 |
/* long name only */ |
/* long name only */ |
|
{"absolute", no_argument, &do_absolute, 1}, |
|
131 |
{"config", optional_argument, &show_config, 1}, |
{"config", optional_argument, &show_config, 1}, |
132 |
{"ctags", no_argument, &ctags, 1}, |
{"format", required_argument, NULL, 0}, |
|
{"cxref", no_argument, &cxref, 1}, |
|
133 |
{"debug", no_argument, &debug, 1}, |
{"debug", no_argument, &debug, 1}, |
134 |
{"fileid", no_argument, &fileid, 1}, |
{"fileid", no_argument, &fileid, 1}, |
135 |
{"gtagsconf", required_argument, >agsconf, 1}, |
{"gtagsconf", required_argument, >agsconf, 1}, |
136 |
{"gtagslabel", required_argument, >agslabel, 1}, |
{"gtagslabel", required_argument, >agslabel, 1}, |
|
{"relative", no_argument, &do_relative, 1}, |
|
137 |
{"sort", no_argument, &do_sort, 1}, |
{"sort", no_argument, &do_sort, 1}, |
138 |
{"pathname", no_argument, &pathname, 1}, |
{"path", required_argument, &do_path, 1}, |
139 |
{"unique", no_argument, &unique, 1}, |
{"unique", no_argument, &unique, 1}, |
140 |
{"version", no_argument, &show_version, 1}, |
{"version", no_argument, &show_version, 1}, |
141 |
{"help", no_argument, &show_help, 1}, |
{"help", no_argument, &show_help, 1}, |
162 |
if (!strcmp(p, "config")) { |
if (!strcmp(p, "config")) { |
163 |
if (optarg) |
if (optarg) |
164 |
info_string = optarg; |
info_string = optarg; |
165 |
|
} else if (!strcmp(p, "path")) { |
166 |
|
if (!strcmp("absolute", optarg)) |
167 |
|
pathconvert = PATH_ABSOLUTE; |
168 |
|
} else if (!strcmp(p, "format")) { |
169 |
|
if (!strcmp("ctags", optarg)) |
170 |
|
format = TAGSORT_CTAGS; |
171 |
|
else if (!strcmp("path", optarg)) |
172 |
|
format = TAGSORT_PATH; |
173 |
|
else |
174 |
|
format = TAGSORT_CTAGS_X; |
175 |
} else if (gtagsconf || gtagslabel) { |
} else if (gtagsconf || gtagslabel) { |
176 |
char value[MAXPATHLEN+1]; |
char value[MAXPATHLEN+1]; |
177 |
const char *name = (gtagsconf) ? "GTAGSCONF" : "GTAGSLABEL"; |
const char *name = (gtagsconf) ? "GTAGSCONF" : "GTAGSLABEL"; |
245 |
} |
} |
246 |
exit(0); |
exit(0); |
247 |
} else if (do_sort) { |
} else if (do_sort) { |
|
int format = pathname ? 2 : (ctags ? 1 : 0); |
|
248 |
/* |
/* |
249 |
* A special version of sort command. |
* A special version of sort command. |
250 |
* |
* |
262 |
*/ |
*/ |
263 |
tagsort(unique, format, stdin, stdout); |
tagsort(unique, format, stdin, stdout); |
264 |
exit(0); |
exit(0); |
265 |
} else if (do_relative || do_absolute) { |
} else if (do_path) { |
266 |
/* |
/* |
267 |
* This is the main body of path filter. |
* This is the main body of path filter. |
268 |
* This code extract path name from tag line and |
* This code extract path name from tag line and |
277 |
* main 10 main.c main(argc, argv)\n |
* main 10 main.c main(argc, argv)\n |
278 |
* main 22 ../libc/func.c main(argc, argv)\n |
* main 22 ../libc/func.c main(argc, argv)\n |
279 |
* |
* |
280 |
* Similarly, the --absolute option specified, then |
* Similarly, the --path=absolute option specified, then |
281 |
* v |
* v |
282 |
* main 10 /prj/xxx/src/main.c main(argc, argv)\n |
* main 10 /prj/xxx/src/main.c main(argc, argv)\n |
283 |
* main 22 /prj/xxx/libc/func.c main(argc, argv)\n |
* main 22 /prj/xxx/libc/func.c main(argc, argv)\n |
288 |
const char *a_dbpath = argv[2]; |
const char *a_dbpath = argv[2]; |
289 |
const char *ctags_x; |
const char *ctags_x; |
290 |
|
|
291 |
if (argc < 2) |
if (argc < 3) |
292 |
die("do_relative: 2 arguments needed."); |
die("do_path: 3 arguments needed."); |
293 |
set_base_directory(a_root, a_cwd); |
set_base_directory(a_root, a_cwd); |
294 |
if (gpath_open(a_dbpath, 0) < 0) |
if (gpath_open(a_dbpath, 0) < 0) |
295 |
die("GPATH not found."); |
die("GPATH not found."); |
296 |
while ((ctags_x = strbuf_fgets(ib, stdin, 0)) != NULL) |
while ((ctags_x = strbuf_fgets(ib, stdin, 0)) != NULL) |
297 |
put_converting(ctags_x, do_absolute ? 1 : 0, cxref, fileid); |
put_converting(ctags_x, format, fileid); |
298 |
gpath_close(); |
gpath_close(); |
299 |
strbuf_close(ib); |
strbuf_close(ib); |
300 |
exit(0); |
exit(0); |
930 |
* put_converting: convert path into relative or absolute and print. |
* put_converting: convert path into relative or absolute and print. |
931 |
* |
* |
932 |
* i) raw output from global(1) |
* i) raw output from global(1) |
933 |
* i) absolute 1: absolute, 0: relative |
* i) format (defined in tagsort.h) |
|
* i) cxref 1: -x format, 0: file name only |
|
934 |
* i) fileid 1: add fid to the head of line, 0: do nothing |
* i) fileid 1: add fid to the head of line, 0: do nothing |
935 |
*/ |
*/ |
936 |
static STRBUF *abspath; |
static STRBUF *abspath; |
950 |
/* leave abspath unclosed. */ |
/* leave abspath unclosed. */ |
951 |
} |
} |
952 |
void |
void |
953 |
put_converting(const char *ctags, int absolute, int cxref, int fileid) |
put_converting(const char *tagline, int format, int fileid) |
954 |
{ |
{ |
955 |
char buf[MAXPATHLEN+1]; |
char buf[MAXPATHLEN+1]; |
956 |
char *path, *p; |
char *path, *p; |
958 |
/* |
/* |
959 |
* print until path name. |
* print until path name. |
960 |
*/ |
*/ |
961 |
if (cxref) { |
if (format == TAGSORT_PATH) { |
962 |
|
path = (char *)tagline; |
963 |
|
} else { /* TAGSORT_CTAGS, TAGSORT_CTAGS_X */ |
964 |
int savec = 0; |
int savec = 0; |
965 |
/* |
/* |
966 |
* Move to the head of path name. |
* Move to the head of path name. |
971 |
* ctags -x: main 20 ./main.c main() |
* ctags -x: main 20 ./main.c main() |
972 |
*/ |
*/ |
973 |
/* skip tag name */ |
/* skip tag name */ |
974 |
for (p = (char *)ctags; *p && !isspace((unsigned char)*p); p++) |
for (p = (char *)tagline; *p && !isspace((unsigned char)*p); p++) |
975 |
; |
; |
976 |
/* skip blanks (and line number) */ |
/* skip blanks (and line number) */ |
977 |
for (; *p && *p != '.'; p++) |
for (; *p && *p != '.'; p++) |
998 |
*p = savec; |
*p = savec; |
999 |
putc('@', stdout); |
putc('@', stdout); |
1000 |
} |
} |
1001 |
for (p = (char *)ctags; *p && p < path; p++) |
for (p = (char *)tagline; *p && p < path; p++) |
1002 |
(void)putc(*p, stdout); |
(void)putc(*p, stdout); |
|
} else { |
|
|
path = (char *)ctags; |
|
1003 |
} |
} |
1004 |
if (*path++ == '\0') |
if (*path++ == '\0') |
1005 |
return; |
return; |
1012 |
/* |
/* |
1013 |
* put path with converting. |
* put path with converting. |
1014 |
*/ |
*/ |
1015 |
if (absolute) { |
if (pathconvert == PATH_ABSOLUTE) { |
1016 |
(void)fputs(strbuf_value(abspath), stdout); |
(void)fputs(strbuf_value(abspath), stdout); |
1017 |
} else { |
} else { |
1018 |
const char *a = strbuf_value(abspath); |
const char *a = strbuf_value(abspath); |