2 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by Shigio Yamaguchi.
15 * 4. Neither the name of the author nor the names of any co-contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
43 #include "locatestring.h"
50 * Access library for gtags.conf (.gtagsrc).
51 * File format is a subset of XXXcap (termcap, printcap) file.
53 #define GTAGSCONF "/etc/global.conf"
54 #define GTAGSRC ".globalrc"
55 #define DEFAULTLABEL "default"
58 static int allowed_nest_level = 8;
61 static void trim __P((char *));
62 static char *readrecord __P((const char *));
63 static void includelabel __P((STRBUF *, const char *, int));
72 for (f = b = l; *f; f++) {
73 if (colon && isspace(*f))
76 if ((*b++ = *f) == ':')
88 while ((p = mgets(fp, NULL, MGETS_CONT|MGETS_SKIPCOM)) != NULL) {
91 if ((q = strmake(p, "|:")) == NULL)
92 die1("illegal configuration file format (%s).", p);
93 if (!strcmp(label, q)) {
94 if (!(p = locatestring(p, ":", MATCH_FIRST)))
95 die("illegal configuration file format.");
98 die("short of memory.");
113 includelabel(sb, label, level)
120 if (++level > allowed_nest_level)
121 die("nested include= (or tc=) over flow.");
122 if (!(savep = p = readrecord(label)))
123 die1("label '%s' not found.", label);
124 while ((q = locatestring(p, ":include=", MATCH_FIRST)) || (q = locatestring(p, ":tc=", MATCH_FIRST))) {
125 char inclabel[MAXPROPLEN+1], *c = inclabel;
127 strnputs(sb, p, q - p);
128 q = locatestring(q, "=", MATCH_FIRST) + 1;
129 while (*q && *q != ':')
132 includelabel(sb, inclabel, level);
139 * configpath: get path of configuration file.
143 static char config[MAXPATHLEN+1];
146 if ((p = getenv("GTAGSCONF")) != NULL) {
151 } else if ((p = getenv("HOME")) && test("r", makepath(p, GTAGSRC)))
152 strcpy(config, makepath(p, GTAGSRC));
153 else if (test("r", GTAGSCONF))
154 strcpy(config, GTAGSCONF);
160 * openconf: load configuration file.
162 * go) line specified entry
167 const char *label, *config;
172 config = configpath();
174 * if configuration file is not found, default values are set
175 * for upper compatibility.
179 strputs(sb, "suffixes=c,h,y,s,S,java:");
180 strputs(sb, "skip=y.tab.c,y.tab.h,SCCS/,RCS/,CVS/:");
181 strputs(sb, "format=standard:");
182 strputs(sb, "extractmethod:");
183 strputs(sb, "GTAGS=gctags %s:");
184 strputs(sb, "GRTAGS=gctags -r %s:");
185 strputs(sb, "GSYMS=gctags -s %s:");
186 line = strdup(strvalue(sb));
188 die("short of memory.");
193 if ((label = getenv("GTAGSLABEL")) == NULL)
195 if (!(fp = fopen(config, "r")))
196 die1("cannot open '%s'.", config);
198 includelabel(sb, label, 0);
199 line = strdup(strvalue(sb));
206 * getconfn: get property number
208 * i) name property name
209 * o) num value (if not NULL)
210 * r) 1: found, 0: not found
218 char buf[MAXPROPLEN+1];
222 sprintf(buf, ":%s#", name);
223 if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL) {
232 * getconfs: get property string
234 * i) name property name
235 * o) sb string buffer (if not NULL)
236 * r) 1: found, 0: not found
244 char buf[MAXPROPLEN+1];
250 if (!strcmp(name, "suffixes") || !strcmp(name, "skip") || !strcmp(name, "reserved_words"))
252 sprintf(buf, ":%s=", name);
254 while ((p = locatestring(p, buf, MATCH_FIRST)) != NULL) {
258 for (p += strlen(buf); *p && *p != ':'; p++)
265 * It may be that these code should be moved to applications.
266 * But nothing cannot start without them.
270 if (!strcmp(name, "suffixes")) {
272 strputs(sb, "c,h,y,s,S,java");
273 } else if (!strcmp(name, "skip")) {
275 strputs(sb, "y.tab.c,y.tab.h,SCCS/,RCS/,CVS/");
282 * getconfb: get property bool value
284 * i) name property name
285 * r) 1: TRUE, 0: FALSE
292 char buf[MAXPROPLEN+1];
296 sprintf(buf, ":%s:", name);
297 if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL)