1 |
/* |
/* |
2 |
* Copyright (c) 1998, 1999, 2000, 2001, 2002, 2003 |
* Copyright (c) 1998, 1999, 2000, 2001, 2002, 2003, 2005 |
3 |
* Tama Communications Corporation |
* Tama Communications Corporation |
4 |
* |
* |
5 |
* This file is part of GNU GLOBAL. |
* This file is part of GNU GLOBAL. |
54 |
struct words *words; |
struct words *words; |
55 |
static int tablesize; |
static int tablesize; |
56 |
|
|
|
/* |
|
|
* language map. |
|
|
* |
|
|
* By default, default_map is used. |
|
|
*/ |
|
|
static const char *default_map = "c:.c.h,yacc:.y,asm:.s.S,java:.java,cpp:.c++.cc.cpp.cxx.hxx.hpp.C.H,php:.php.php3.phtml"; |
|
57 |
static char *langmap; |
static char *langmap; |
58 |
|
|
59 |
int bflag; /* -b: force level 1 block start */ |
int bflag; /* -b: force level 1 block start */ |
70 |
int show_help; |
int show_help; |
71 |
int debug; |
int debug; |
72 |
|
|
73 |
|
/*----------------------------------------------------------------------*/ |
74 |
|
/* Parser switch */ |
75 |
|
/*----------------------------------------------------------------------*/ |
76 |
|
/* |
77 |
|
* This is the linkage section of each parsers. |
78 |
|
* If you want to support new language, you must define parser procedure |
79 |
|
* which requires file name as an argument. |
80 |
|
*/ |
81 |
|
struct lang_entry { |
82 |
|
const char *lang_name; |
83 |
|
void (*parser)(const char *); /* parser procedure */ |
84 |
|
}; |
85 |
|
|
86 |
|
/* |
87 |
|
* The first entry is default language. |
88 |
|
*/ |
89 |
|
static struct lang_entry lang_switch[] = { |
90 |
|
/* lang_name parser_proc */ |
91 |
|
{"c", C}, /* DEFAULT */ |
92 |
|
{"yacc", yacc}, |
93 |
|
{"cpp", Cpp}, |
94 |
|
{"java", java}, |
95 |
|
{"php", php}, |
96 |
|
{"asm", assembler} |
97 |
|
}; |
98 |
|
#define DEFAULT_ENTRY &lang_switch[0] |
99 |
|
/* |
100 |
|
* get language entry. |
101 |
|
* |
102 |
|
* i) lang language name (NULL means 'not specified'.) |
103 |
|
* r) language entry |
104 |
|
*/ |
105 |
|
static struct lang_entry * |
106 |
|
get_lang_entry(lang) |
107 |
|
const char *lang; |
108 |
|
{ |
109 |
|
int i, size = sizeof(lang_switch) / sizeof(struct lang_entry); |
110 |
|
|
111 |
|
/* |
112 |
|
* if language not specified, it assumes default language. |
113 |
|
*/ |
114 |
|
if (lang == NULL) |
115 |
|
return DEFAULT_ENTRY; |
116 |
|
for (i = 0; i < size; i++) |
117 |
|
if (!strcmp(lang, lang_switch[i].lang_name)) |
118 |
|
return &lang_switch[i]; |
119 |
|
/* |
120 |
|
* if specified language not found, it assumes default language. |
121 |
|
*/ |
122 |
|
return DEFAULT_ENTRY; |
123 |
|
} |
124 |
|
|
125 |
static void |
static void |
126 |
usage() |
usage() |
127 |
{ |
{ |
213 |
fprintf(stdout, "Part of GLOBAL\n"); |
fprintf(stdout, "Part of GLOBAL\n"); |
214 |
exit(0); |
exit(0); |
215 |
} |
} |
216 |
setup_langmap(langmap ? langmap : default_map); |
/* |
217 |
|
* If langmap is not passed as argument, environment variable |
218 |
|
* GTAGSLANGMAP should be checked. Gtags(1) call gtags-parser |
219 |
|
* in this method. |
220 |
|
*/ |
221 |
|
if (langmap == NULL) |
222 |
|
langmap = getenv("GTAGSLANGMAP"); |
223 |
|
if (langmap == NULL) |
224 |
|
langmap = DEFAULTLANGMAP; |
225 |
|
setup_langmap(langmap); |
226 |
|
|
227 |
argc -= optind; |
argc -= optind; |
228 |
argv += optind; |
argv += optind; |
278 |
*/ |
*/ |
279 |
for (; argc > 0; argv++, argc--) { |
for (; argc > 0; argv++, argc--) { |
280 |
const char *lang, *suffix; |
const char *lang, *suffix; |
281 |
|
struct lang_entry *ent; |
282 |
|
|
283 |
#if defined(_WIN32) || defined(__DJGPP__) |
#if defined(_WIN32) || defined(__DJGPP__) |
284 |
/* Lower case the file name since names are case insensitive */ |
/* Lower case the file name since names are case insensitive */ |
291 |
lang = decide_lang(suffix); |
lang = decide_lang(suffix); |
292 |
if (lang == NULL) |
if (lang == NULL) |
293 |
continue; |
continue; |
|
|
|
|
/* |
|
|
* Initialize token parser. Php() and assembler() use different parser. |
|
|
*/ |
|
|
if (strcmp(lang, "php") && strcmp(lang, "asm")) |
|
|
if (!opentoken(argv[0])) |
|
|
die("'%s' cannot open.", argv[0]); |
|
|
|
|
|
if (!strcmp(suffix, ".h") && isCpp()) |
|
|
lang = "cpp"; |
|
294 |
if (vflag) |
if (vflag) |
295 |
fprintf(stderr, "suffix '%s' assumed language '%s'.\n", suffix, lang); |
fprintf(stderr, "suffix '%s' assumed language '%s'.\n", suffix, lang); |
296 |
|
/* |
297 |
|
* Select parser. |
298 |
|
* If lang == NULL then default parser is selected. |
299 |
|
*/ |
300 |
|
ent = get_lang_entry(lang); |
301 |
/* |
/* |
302 |
* call language specific parser. |
* call language specific parser. |
303 |
*/ |
*/ |
304 |
if (!strcmp(lang, "c")) { |
ent->parser(argv[0]); |
|
C(0); |
|
|
} else if (!strcmp(lang, "yacc")) { |
|
|
C(YACC); |
|
|
} else if (!strcmp(lang, "asm")) { |
|
|
assembler(argv[0]); |
|
|
} else if (!strcmp(lang, "java")) { |
|
|
java(); |
|
|
} else if (!strcmp(lang, "cpp")) { |
|
|
Cpp(); |
|
|
} else if (!strcmp(lang, "php")) { |
|
|
php(argv[0]); |
|
|
} |
|
|
if (strcmp(lang, "php") && strcmp(lang, "asm")) |
|
|
closetoken(); |
|
305 |
} |
} |
306 |
return 0; |
return 0; |
307 |
} |
} |