diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 1999-01-21 00:55:32 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 1999-01-21 00:55:32 +0000 |
commit | 76b5366091f76c9bc73570149ef5055648fc2c39 (patch) | |
tree | 590d020e0f2a5bea6e09d66d951a674443b21d67 /contrib/global/lib | |
parent | 4b4d01da6f07f7754ff6a6e4f5223e9f0984d1a6 (diff) |
Notes
Diffstat (limited to 'contrib/global/lib')
39 files changed, 878 insertions, 2812 deletions
diff --git a/contrib/global/lib/Makefile b/contrib/global/lib/Makefile index 83d8be057d41b..99d49efabddc9 100644 --- a/contrib/global/lib/Makefile +++ b/contrib/global/lib/Makefile @@ -1,9 +1,8 @@ -LIB= gloutil -SRCS= gtagsop.c tab.c strbuf.c mgets.c defined.c getdbpath.c \ - find.c dbop.c test.c makepath.c locatestring.c pathop.c \ - conf.c strmake.c usable.c token.c -NOPROFILE= noprofile -INTERNALLIB= true -INTERNALSTATICLIB= true +LIB= util +SRCS= tag.o tab.o strop.o mgets.o lookup.o gtagsopen.o getdbpath.o \ + find.o dbname.o dbio.o test.o makepath.o locatestring.o +NOPROFILE= yes +install: + @echo -n .include <bsd.lib.mk> diff --git a/contrib/global/lib/conf.c b/contrib/global/lib/conf.c deleted file mode 100644 index 887663d71e25a..0000000000000 --- a/contrib/global/lib/conf.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * conf.c 30-Jun-98 - * - */ -#include <sys/param.h> -#include <assert.h> -#include <ctype.h> -#include <stdlib.h> -#include <string.h> - -#include "conf.h" -#include "die.h" -#include "gparam.h" -#include "locatestring.h" -#include "makepath.h" -#include "mgets.h" -#include "strbuf.h" -#include "strmake.h" -#include "test.h" -/* - * Access library for gtags.conf (.gtagsrc). - * File format is a subset of XXXcap (termcap, printcap) file. - */ -#define GTAGSCONF "/etc/global.conf" -#define GTAGSRC ".globalrc" -#define DEFAULTLABEL "default" -static FILE *fp; -static char *line; -static int allowed_nest_level = 8; -static int opened; - -static void trim __P((char *)); -static char *readrecord __P((const char *)); -static void includelabel __P((STRBUF *, const char *, int)); - -static void -trim(l) -char *l; -{ - char *f, *b; - int colon = 0; - - for (f = b = l; *f; f++) { - if (colon && isspace(*f)) - continue; - colon = 0; - if ((*b++ = *f) == ':') - colon = 1; - } - *b = 0; -} -static char * -readrecord(label) -const char *label; -{ - char *p, *q; - - rewind(fp); - while ((p = mgets(fp, NULL, MGETS_CONT|MGETS_SKIPCOM)) != NULL) { - trim(p); - for (;;) { - if ((q = strmake(p, "|:")) == NULL) - die1("illegal configuration file format (%s).", p); - if (!strcmp(label, q)) { - if (!(p = locatestring(p, ":", MATCH_FIRST))) - die("illegal configuration file format."); - p = strdup(p); - if (!p) - die("short of memory."); - return p; - } - p += strlen(q); - if (*p == ':') - break; - else if (*p == '|') - p++; - else - assert(0); - } - } - return NULL; -} -static void -includelabel(sb, label, level) -STRBUF *sb; -const char *label; -int level; -{ - char *savep, *p, *q; - - if (++level > allowed_nest_level) - die("nested include= (or tc=) over flow."); - if (!(savep = p = readrecord(label))) - die1("label '%s' not found.", label); - while ((q = locatestring(p, ":include=", MATCH_FIRST)) || (q = locatestring(p, ":tc=", MATCH_FIRST))) { - char inclabel[MAXPROPLEN+1], *c = inclabel; - - strnputs(sb, p, q - p); - q = locatestring(q, "=", MATCH_FIRST) + 1; - while (*q && *q != ':') - *c++ = *q++; - *c = 0; - includelabel(sb, inclabel, level); - p = q; - } - strputs(sb, p); - free(savep); -} -/* - * configpath: get path of configuration file. - */ -char * -configpath() { - static char config[MAXPATHLEN+1]; - char *p; - - if ((p = getenv("GTAGSCONF")) != NULL) { - if (!test("r", p)) - config[0] = 0; - else - strcpy(config, p); - } else if ((p = getenv("HOME")) && test("r", makepath(p, GTAGSRC))) - strcpy(config, makepath(p, GTAGSRC)); - else if (test("r", GTAGSCONF)) - strcpy(config, GTAGSCONF); - else - config[0] = 0; - return config; -} -/* - * openconf: load configuration file. - * - * go) line specified entry - */ -void -openconf() -{ - const char *label, *config; - STRBUF *sb; - - assert(opened == 0); - - config = configpath(); - /* - * if configuration file is not found, default values are set - * for upper compatibility. - */ - if (*config == 0) { - sb = stropen(); - strputs(sb, "suffixes=c,h,y,s,S,java:"); - strputs(sb, "skip=y.tab.c,y.tab.h,SCCS/,RCS/,CVS/:"); - strputs(sb, "format=standard:"); - strputs(sb, "extractmethod:"); - strputs(sb, "GTAGS=gctags %s:"); - strputs(sb, "GRTAGS=gctags -r %s:"); - strputs(sb, "GSYMS=gctags -s %s:"); - line = strdup(strvalue(sb)); - if (!line) - die("short of memory."); - strclose(sb); - opened = 1; - return; - } - if ((label = getenv("GTAGSLABEL")) == NULL) - label = "default"; - if (!(fp = fopen(config, "r"))) - die1("cannot open '%s'.", config); - sb = stropen(); - includelabel(sb, label, 0); - line = strdup(strvalue(sb)); - strclose(sb); - fclose(fp); - opened = 1; - return; -} -/* - * getconfn: get property number - * - * i) name property name - * o) num value (if not NULL) - * r) 1: found, 0: not found - */ -int -getconfn(name, num) -const char *name; -int *num; -{ - char *p; - char buf[MAXPROPLEN+1]; - - if (!opened) - openconf(); - sprintf(buf, ":%s#", name); - if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL) { - p += strlen(buf); - if (num != NULL) - *num = atoi(p); - return 1; - } - return 0; -} -/* - * getconfs: get property string - * - * i) name property name - * o) sb string buffer (if not NULL) - * r) 1: found, 0: not found - */ -int -getconfs(name, sb) -const char *name; -STRBUF *sb; -{ - char *p; - char buf[MAXPROPLEN+1]; - int all = 0; - int exist = 0; - - if (!opened) - openconf(); - if (!strcmp(name, "suffixes") || !strcmp(name, "skip") || !strcmp(name, "reserved_words")) - all = 1; - sprintf(buf, ":%s=", name); - p = line; - while ((p = locatestring(p, buf, MATCH_FIRST)) != NULL) { - if (exist && sb) - strputc(sb, ','); - exist = 1; - for (p += strlen(buf); *p && *p != ':'; p++) - if (sb) - strputc(sb, *p); - if (!all) - break; - } - /* - * It may be that these code should be moved to applications. - * But nothing cannot start without them. - */ - if (!exist) { - exist = 1; - if (!strcmp(name, "suffixes")) { - if (sb) - strputs(sb, "c,h,y,s,S,java"); - } else if (!strcmp(name, "skip")) { - if (sb) - strputs(sb, "y.tab.c,y.tab.h,SCCS/,RCS/,CVS/"); - } else - exist = 0; - } - return exist; -} -/* - * getconfb: get property bool value - * - * i) name property name - * r) 1: TRUE, 0: FALSE - */ -int -getconfb(name) -const char *name; -{ - char *p; - char buf[MAXPROPLEN+1]; - - if (!opened) - openconf(); - sprintf(buf, ":%s:", name); - if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL) - return 1; - return 0; -} -void -closeconf() -{ - if (!opened) - return; - free(line); - opened = 0; -} diff --git a/contrib/global/lib/dbio.c b/contrib/global/lib/dbio.c new file mode 100644 index 0000000000000..c29a91477bdb8 --- /dev/null +++ b/contrib/global/lib/dbio.c @@ -0,0 +1,328 @@ +/* + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. + * + * Redilogibution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redilogibutions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redilogibutions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the dilogibution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Shigio Yamaguchi. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * dbio.c 14-Dec-97 + * + */ +#include <sys/stat.h> + +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "dbio.h" +#include "die.h" +#include "test.h" + +DBT key; /* key of record */ +DBT dat; /* data of record */ +/* + * db_open: open db database. + * + * i) dbname database name + * i) mode 0: read only, 1: write only, 2: read & write + * i) perm file permission + * i) flags + * DBIO_DUP: allow duplicate records. + * DBIO_REMOVE: remove on closed. + * r) descripter for db_xxx() + * + * db_open leaves database permission 0600. please chmod(2) to make public. + */ +DBIO * +db_open(dbname, mode, perm, flags) +char *dbname; +int mode; +int perm; +int flags; +{ + DB *db; + int rw; + BTREEINFO info; + DBIO *dbio; + + /* + * setup argments. + */ + if (mode == 0) + rw = O_RDONLY; + else if (mode == 1) + rw = O_RDWR|O_CREAT|O_TRUNC; + else if (mode == 2) + rw = O_RDWR; + else + die("db_open illegal mode."); + info.flags = (flags & DBIO_DUP) ? R_DUP : 0; + info.cachesize = 500000; + info.maxkeypage = 0; + info.minkeypage = 0; + info.psize = 0; + info.compare = NULL; + info.prefix = NULL; + info.lorder = LITTLE_ENDIAN; + + /* + * if unlink do job normally, those who already open tag file can use + * it until closing. + */ + if (mode == 1 && test("f", dbname)) + (void)unlink(dbname); + db = dbopen(dbname, rw, 0600, DB_BTREE, &info); + if (!db) + die1("db_open failed (dbname = %s).", dbname); + if (!(dbio = (DBIO *)malloc(sizeof(DBIO)))) + die("short of memory."); + strcpy(dbio->dbname, dbname); + dbio->db = db; + dbio->openflags = flags; + dbio->perm = (mode == 1) ? perm : 0; + dbio->lastkey = (char *)0; + dbio->lastdat = (char *)0; + + return dbio; +} +/* + * db_get: get data by a key. + * + * i) dbio descripter + * i) k key + * r) pointer to data + */ +char * +db_get(dbio, k) +DBIO *dbio; +char *k; +{ + DB *db = dbio->db; + int status; + + key.data = k; + key.size = strlen(k)+1; + + status = (*db->get)(db, &key, &dat, 0); + dbio->lastkey = (char *)key.data; + dbio->lastdat = (char *)dat.data; + switch (status) { + case RET_SUCCESS: + break; + case RET_ERROR: + die("db_get failed."); + case RET_SPECIAL: + return((char *)0); + } + return((char *)dat.data); +} +/* + * db_put: put data by a key. + * + * i) dbio descripter + * i) k key + * i) d data + */ +void +db_put(dbio, k, d) +DBIO *dbio; +char *k; +char *d; +{ + DB *db = dbio->db; + int status; + + if (strlen(k) > MAXKEYLEN) + die("primary key too long."); + key.data = k; + key.size = strlen(k)+1; + dat.data = d; + dat.size = strlen(d)+1; + + status = (*db->put)(db, &key, &dat, 0); + switch (status) { + case RET_SUCCESS: + break; + case RET_ERROR: + case RET_SPECIAL: + die("db_put failed."); + } +} +/* + * db_del: delete record by a key. + * + * i) dbio descripter + * i) k key + */ +void +db_del(dbio, k) +DBIO *dbio; +char *k; +{ + DB *db = dbio->db; + int status; + + if (k) { + key.data = k; + key.size = strlen(k)+1; + status = (*db->del)(db, &key, 0); + } else + status = (*db->del)(db, &key, R_CURSOR); + if (status == RET_ERROR) + die("db_del failed."); +} +/* + * db_first: get first record. + * + * i) dbio dbio descripter + * i) k key + * !=NULL: indexed read by key + * ==NULL: sequential read + * i) flags following db_next call take over this. + * DBIO_KEY read key part + * DBIO_PREFIX prefix read + * DBIO_SKIPMETA skip META record + * only valied when sequential read + * r) data + */ +char * +db_first(dbio, k, flags) +DBIO *dbio; +char *k; +int flags; +{ + DB *db = dbio->db; + int status; + + if (flags & DBIO_PREFIX && !k) + flags &= ~DBIO_PREFIX; + if (flags & DBIO_SKIPMETA && k) + flags &= ~DBIO_SKIPMETA; + if (k) { + if (strlen(k) > MAXKEYLEN) + die("primary key too long."); + strcpy(dbio->key, k); + key.data = k; + key.size = strlen(k); + /* + * includes NULL character unless prefix read. + */ + if (!(flags & DBIO_PREFIX)) + key.size++; + dbio->keylen = key.size; + status = (*db->seq)(db, &key, &dat, R_CURSOR); + } else { + dbio->keylen = dbio->key[0] = 0; + for (status = (*db->seq)(db, &key, &dat, R_FIRST); + status == RET_SUCCESS && + flags & DBIO_SKIPMETA && + *((char *)dat.data) == ' '; + status = (*db->seq)(db, &key, &dat, R_NEXT)) + ; + } + dbio->lastkey = (char *)key.data; + dbio->lastdat = (char *)dat.data; + switch (status) { + case RET_SUCCESS: + break; + case RET_ERROR: + die("db_first failed."); + case RET_SPECIAL: + return ((char *)0); + } + dbio->ioflags = flags; + if (flags & DBIO_PREFIX) { + if (strncmp((char *)key.data, dbio->key, dbio->keylen)) + return (char *)0; + } else if (dbio->keylen) { + if (strcmp((char *)key.data, dbio->key)) + return (char *)0; + } + if (flags & DBIO_KEY) { + strcpy(dbio->prev, (char *)key.data); + return (char *)key.data; + } + return ((char *)dat.data); +} +/* + * db_next: get next record. + * + * i) dbio dbio descripter + * r) data + */ +char * +db_next(dbio) +DBIO *dbio; +{ + DB *db = dbio->db; + int flags = dbio->ioflags; + int status; + + while ((status = (*db->seq)(db, &key, &dat, R_NEXT)) == RET_SUCCESS) { + if (flags & DBIO_SKIPMETA) { + if (*((char *)dat.data) == ' ') + continue; + } + if (flags & DBIO_KEY) { + if (!strcmp(dbio->prev, (char *)key.data)) + continue; + if (strlen((char *)key.data) > MAXKEYLEN) + die("primary key too long."); + strcpy(dbio->prev, (char *)key.data); + } + dbio->lastkey = (char *)key.data; + dbio->lastdat = (char *)dat.data; + if (flags & DBIO_PREFIX) { + if (strncmp((char *)key.data, dbio->key, dbio->keylen)) + return (char *)0; + } else if (dbio->keylen) { + if (strcmp((char *)key.data, dbio->key)) + return (char *)0; + } + return (flags & DBIO_KEY) ? (char *)key.data : (char *)dat.data; + } + if (status == RET_ERROR) + die("db_next failed."); + return (char *)0; +} +/* + * db_close: close db + * + * i) dbio dbio descripter + */ +void +db_close(dbio) +DBIO *dbio; +{ + DB *db = dbio->db; + (void)db->close(db); + if (dbio->openflags & DBIO_REMOVE) + (void)unlink(dbio->dbname); + else if (dbio->perm && chmod(dbio->dbname, dbio->perm) < 0) + die("cannot change file mode."); + (void)free(dbio); +} diff --git a/contrib/global/lib/dbop.h b/contrib/global/lib/dbio.h index 38342ca52d042..7c1994e86d692 100644 --- a/contrib/global/lib/dbop.h +++ b/contrib/global/lib/dbio.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redilogibution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,14 +28,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * dbop.h 12-Nov-98 + * dbio.h 14-Dec-97 * */ -#ifndef _DBOP_H_ -#define _DBOP_H_ +#ifndef _DBIO_H_ +#define _DBIO_H_ -#include <sys/param.h> #include <db.h> +#include <sys/param.h> #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 @@ -54,21 +54,22 @@ typedef struct { char prev[MAXKEYLEN+1]; /* previous key value */ char *lastkey; /* the key of last located record */ char *lastdat; /* the data of last located record */ - int openflags; /* flags of dbop_open() */ - int ioflags; /* flags of dbop_first() */ + int openflags; /* flags of db_open() */ + int ioflags; /* flags of db_first() */ int perm; /* file permission */ -} DBOP; +} DBIO; /* * openflags */ -#define DBOP_DUP 1 /* allow duplicate records */ -#define DBOP_REMOVE 2 /* remove file when closed */ +#define DBIO_DUP 1 /* allow duplicate records */ +#define DBIO_REMOVE 2 /* remove file when closed */ /* * ioflags */ -#define DBOP_KEY 1 /* read key part */ -#define DBOP_PREFIX 2 /* prefixed read */ +#define DBIO_KEY 1 /* read key part */ +#define DBIO_PREFIX 2 /* prefixed read */ +#define DBIO_SKIPMETA 4 /* skip META record */ #ifndef __P #if defined(__STDC__) @@ -78,11 +79,11 @@ typedef struct { #endif #endif -DBOP *dbop_open __P((const char *, int, int, int)); -char *dbop_get __P((DBOP *, const char *)); -void dbop_put __P((DBOP *, const char *, const char *)); -void dbop_del __P((DBOP *, const char *)); -char *dbop_first __P((DBOP *, const char *, int)); -char *dbop_next __P((DBOP *)); -void dbop_close __P((DBOP *)); -#endif /* _DBOP_H_ */ +DBIO *db_open __P((char *, int, int, int)); +char *db_get __P((DBIO *, char *)); +void db_put __P((DBIO *, char *, char *)); +void db_del __P((DBIO *, char *)); +char *db_first __P((DBIO *, char *, int)); +char *db_next __P((DBIO *)); +void db_close __P((DBIO *)); +#endif /* _DBIO_H_ */ diff --git a/contrib/global/lib/strmake.c b/contrib/global/lib/dbname.c index da5dea4f25be8..1e68b3a2bf4a7 100644 --- a/contrib/global/lib/strmake.c +++ b/contrib/global/lib/dbname.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,32 +28,21 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * strmake.c 15-May-98 + * dbname.c 20-Oct-97 * */ -#include <stdlib.h> +#include "dbname.h" -#include "strbuf.h" -#include "strmake.h" - -static STRBUF *sb; - -char * -strmake(p, lim) -const char *p; -const char *lim; +static char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"}; +/* + * dbname: return db name + * + * i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS + * r) dbname + */ +char * +dbname(db) +int db; { - const char *c; - - if (sb == NULL) - sb = stropen(); - strstart(sb); - for (; *p; p++) { - for (c = lim; *c; c++) - if (*p == *c) - goto end; - strputc(sb,*p); - } -end: - return strvalue(sb); + return tagslist[db]; } diff --git a/contrib/global/lib/defined.h b/contrib/global/lib/dbname.h index 6d342ac5ec065..17eba363eda48 100644 --- a/contrib/global/lib/defined.h +++ b/contrib/global/lib/dbname.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,12 +28,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * defined.h 2-May-98 + * dbname.h 16-Oct-97 * */ -#ifndef _DEFINED_H_ -#define _DEFINED_H_ +#ifndef _DBNAME_H_ +#define _DBNAME_H_ #ifndef __P #if defined(__STDC__) @@ -43,6 +43,11 @@ #endif #endif -int defined __P((const char *)); +#define GTAGS 0 +#define GRTAGS 1 +#define GSYMS 2 +#define GTAGLIM 3 -#endif /* ! _DEFINED_H_ */ +char *dbname __P((int)); + +#endif /* ! _DBNAME_H_ */ diff --git a/contrib/global/lib/dbop.c b/contrib/global/lib/dbop.c deleted file mode 100644 index 9bd98f3286247..0000000000000 --- a/contrib/global/lib/dbop.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redilogibution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redilogibutions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redilogibutions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the dilogibution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * dbop.c 12-Nov-98 - * - */ -#include <sys/types.h> -#include <sys/stat.h> - -#include <assert.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "dbop.h" -#include "die.h" -#include "test.h" - -static DBT key; /* key of record */ -static DBT dat; /* data of record */ -/* - * dbop_open: open db database. - * - * i) dbname database name - * i) mode 0: read only, 1: create, 2: modify - * i) perm file permission - * i) flags - * DBOP_DUP: allow duplicate records. - * DBOP_REMOVE: remove on closed. - * r) descripter for dbop_xxx() - */ -DBOP * -dbop_open(dbname, mode, perm, flags) -const char *dbname; -int mode; -int perm; -int flags; -{ - DB *db; - int rw = 0; - DBOP *dbop; - BTREEINFO info; - - /* - * setup argments. - */ - switch (mode) { - case 0: - rw = O_RDONLY; - break; - case 1: - rw = O_RDWR|O_CREAT|O_TRUNC; - break; - case 2: - rw = O_RDWR; - break; - default: - assert(0); - } - memset(&info, 0, sizeof(info)); - if (flags & DBOP_DUP) - info.flags |= R_DUP; - info.cachesize = 500000; - - /* - * if unlink do job normally, those who already open tag file can use - * it until closing. - */ - if (mode == 1 && test("f", dbname)) - (void)unlink(dbname); - db = dbopen(dbname, rw, 0600, DB_BTREE, &info); - if (!db) - return NULL; - if (!(dbop = (DBOP *)malloc(sizeof(DBOP)))) - die("short of memory."); - strcpy(dbop->dbname, dbname); - dbop->db = db; - dbop->openflags = flags; - dbop->perm = (mode == 1) ? perm : 0; - dbop->lastkey = NULL; - dbop->lastdat = NULL; - - return dbop; -} -/* - * dbop_get: get data by a key. - * - * i) dbop descripter - * i) name name - * r) pointer to data - */ -char * -dbop_get(dbop, name) -DBOP *dbop; -const char *name; -{ - DB *db = dbop->db; - int status; - - key.data = (char *)name; - key.size = strlen(name)+1; - - status = (*db->get)(db, &key, &dat, 0); - dbop->lastkey = (char *)key.data; - dbop->lastdat = (char *)dat.data; - switch (status) { - case RET_SUCCESS: - break; - case RET_ERROR: - die("cannot read from database."); - case RET_SPECIAL: - return (NULL); - } - return((char *)dat.data); -} -/* - * dbop_put: put data by a key. - * - * i) dbop descripter - * i) name key - * i) data data - */ -void -dbop_put(dbop, name, data) -DBOP *dbop; -const char *name; -const char *data; -{ - DB *db = dbop->db; - int status; - - if (strlen(name) > MAXKEYLEN) - die("primary key too long."); - key.data = (char *)name; - key.size = strlen(name)+1; - dat.data = (char *)data; - dat.size = strlen(data)+1; - - status = (*db->put)(db, &key, &dat, 0); - switch (status) { - case RET_SUCCESS: - break; - case RET_ERROR: - case RET_SPECIAL: - die("cannot write to database."); - } -} -/* - * dbop_del: delete record by a key. - * - * i) dbop descripter - * i) name key - */ -void -dbop_del(dbop, name) -DBOP *dbop; -const char *name; -{ - DB *db = dbop->db; - int status; - - if (name) { - key.data = (char *)name; - key.size = strlen(name)+1; - status = (*db->del)(db, &key, 0); - } else - status = (*db->del)(db, &key, R_CURSOR); - if (status == RET_ERROR) - die("cannot delete record."); -} -/* - * dbop_first: get first record. - * - * i) dbop dbop descripter - * i) name key - * !=NULL: indexed read by key - * ==NULL: sequential read - * i) flags following dbop_next call take over this. - * DBOP_KEY read key part - * DBOP_PREFIX prefix read - * only valied when sequential read - * r) data - */ -char * -dbop_first(dbop, name, flags) -DBOP *dbop; -const char *name; -int flags; -{ - DB *db = dbop->db; - int status; - - if (flags & DBOP_PREFIX && !name) - flags &= ~DBOP_PREFIX; - if (name) { - if (strlen(name) > MAXKEYLEN) - die("primary key too long."); - strcpy(dbop->key, name); - key.data = (char *)name; - key.size = strlen(name); - /* - * includes NULL character unless prefix read. - */ - if (!(flags & DBOP_PREFIX)) - key.size++; - dbop->keylen = key.size; - status = (*db->seq)(db, &key, &dat, R_CURSOR); - } else { - dbop->keylen = dbop->key[0] = 0; - /* skip META records */ - for (status = (*db->seq)(db, &key, &dat, R_FIRST); - status == RET_SUCCESS; - status = (*db->seq)(db, &key, &dat, R_NEXT)) { - int c = (flags & DBOP_KEY) ? *((char *)key.data) : *((char *)dat.data); - if (c != ' ') - break; - } - } - dbop->lastkey = (char *)key.data; - dbop->lastdat = (char *)dat.data; - switch (status) { - case RET_SUCCESS: - break; - case RET_ERROR: - die("dbop_first failed."); - case RET_SPECIAL: - return (NULL); - } - dbop->ioflags = flags; - if (flags & DBOP_PREFIX) { - if (strncmp((char *)key.data, dbop->key, dbop->keylen)) - return NULL; - } else if (dbop->keylen) { - if (strcmp((char *)key.data, dbop->key)) - return NULL; - } - if (flags & DBOP_KEY) { - strcpy(dbop->prev, (char *)key.data); - return (char *)key.data; - } - return ((char *)dat.data); -} -/* - * dbop_next: get next record. - * - * i) dbop dbop descripter - * r) data - * - * Db_next always skip meta records. - */ -char * -dbop_next(dbop) -DBOP *dbop; -{ - DB *db = dbop->db; - int flags = dbop->ioflags; - int status; - - while ((status = (*db->seq)(db, &key, &dat, R_NEXT)) == RET_SUCCESS) { - assert(dat.data != NULL); - if (flags & DBOP_KEY && *((char *)key.data) == ' ') - continue; - else if (*((char *)dat.data) == ' ') - continue; - if (flags & DBOP_KEY) { - if (!strcmp(dbop->prev, (char *)key.data)) - continue; - if (strlen((char *)key.data) > MAXKEYLEN) - die("primary key too long."); - strcpy(dbop->prev, (char *)key.data); - } - dbop->lastkey = (char *)key.data; - dbop->lastdat = (char *)dat.data; - if (flags & DBOP_PREFIX) { - if (strncmp((char *)key.data, dbop->key, dbop->keylen)) - return NULL; - } else if (dbop->keylen) { - if (strcmp((char *)key.data, dbop->key)) - return NULL; - } - return (flags & DBOP_KEY) ? (char *)key.data : (char *)dat.data; - } - if (status == RET_ERROR) - die("dbop_next failed."); - return NULL; -} -/* - * dbop_close: close db - * - * i) dbop dbop descripter - */ -void -dbop_close(dbop) -DBOP *dbop; -{ - DB *db = dbop->db; - - (void)db->close(db); - if (dbop->openflags & DBOP_REMOVE) - (void)unlink(dbop->dbname); - else if (dbop->perm && chmod(dbop->dbname, dbop->perm) < 0) - die("cannot change file mode."); - (void)free(dbop); -} diff --git a/contrib/global/lib/die.h b/contrib/global/lib/die.h index fc0e9e014493a..46813d415953e 100644 --- a/contrib/global/lib/die.h +++ b/contrib/global/lib/die.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,7 +35,7 @@ #define _DIE_H_ #include <stdio.h> -extern const char *progname; +extern char *progname; #define die(a) fprintf(stderr, "%s: ", progname),\ fprintf(stderr, a),\ @@ -46,8 +46,4 @@ extern const char *progname; fprintf(stderr, a, b),\ fputs("\n", stderr),\ exit(1) -#define die2(a,b,c) fprintf(stderr, "%s: ", progname),\ - fprintf(stderr, a, b, c),\ - fputs("\n", stderr),\ - exit(1) #endif /* ! _DIE_H_ */ diff --git a/contrib/global/lib/find.c b/contrib/global/lib/find.c index 4682beec1d6db..10a9bf1cde782 100644 --- a/contrib/global/lib/find.c +++ b/contrib/global/lib/find.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,159 +28,115 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * find.c 1-May-98 + * find.c 20-Oct-97 * */ -/* - * USEFIND use find(1) to traverse directory tree. - * Otherwise, use dirent(3) library. - */ -#define USEFIND - -#include <sys/param.h> - -#include <assert.h> -#include <ctype.h> -#ifndef USEFIND -#include <dirent.h> -#ifndef BSD4_4 -#include <sys/stat.h> -#endif -#endif #include <stdio.h> -#include <stdlib.h> -#include <strings.h> +#include <string.h> +#include <sys/types.h> #include <regex.h> - -#include "conf.h" -#include "die.h" -#include "find.h" +#include <sys/param.h> #include "gparam.h" +#include "find.h" +#include "die.h" #include "locatestring.h" -#include "makepath.h" -#include "strbuf.h" /* * usage of findxxx() * - * findopen(db); + * findopen(); * while (path = findread(&length)) { * ... * } * findclose(); * */ +static char *skippath[] = { + "y.tab.c", + "y.tab.h", + "SCCS/", + "RCS/", +}; +static char *ext[] = { + "c", + "h", + "y", + "s", + "S", +}; +static char findcom[MAXCOMLINE+1]; static regex_t skip_area; -static regex_t *skip = &skip_area; +static regex_t *skip; +static FILE *ip; static int opened; -static void trim __P((char *)); - -/* - * trim: remove blanks and '\'. - */ -static void -trim(s) -char *s; +int +issource(path) +char *path; { char *p; - for (p = s; *s; s++) { - if (isspace(*s)) - continue; - if (*s == '\\' && *(s + 1)) - s++; - *p++ = *s; + if (!(p = locatestring(path, ".", 2))) + return 0; + ++p; + if (sizeof(ext) != 0) { + int i, lim = sizeof(ext)/sizeof(char *); + for (i = 0; i < lim; i++) + if (*ext[i] == *p && !strcmp(ext[i], p)) + return 1; } - *p = 0; + return 0; } -#ifdef USEFIND -/*----------------------------------------------------------------------*/ -/* find command version */ -/*----------------------------------------------------------------------*/ -static FILE *ip; void -findopen() +findopen(void) { - char *findcom, *p, *q; - STRBUF *sb; - char *sufflist = NULL; - char *skiplist = NULL; + char edit[512], *p, *q; + int i, lim; - assert(opened == 0); + if (opened) + die("nested call to findopen."); opened = 1; - - sb = stropen(); - if (!getconfs("suffixes", sb)) - die("cannot get suffixes data."); - sufflist = strdup(strvalue(sb)); - if (!sufflist) - die("short of memory."); - trim(sufflist); - strstart(sb); - if (getconfs("skip", sb)) { - skiplist = strdup(strvalue(sb)); - if (!skiplist) - die("short of memory."); - trim(skiplist); - } - - strstart(sb); - strputs(sb, "find . \\( -type f -o -type l \\) \\("); - for (p = sufflist; p; ) { - char *suff = p; - if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL) - *p++ = 0; - strputs(sb, " -name '*."); - strputs(sb, suff); - strputs(sb, "'"); - if (p) - strputs(sb, " -o"); + p = findcom; + strcpy(p, "find . \\( -type f -o -type l \\) \\("); + p += strlen(p); + lim = sizeof(ext)/sizeof(char *); + for (i = 0; i < lim; i++) { + sprintf(p, " -name '*.%s'%s", ext[i], (i + 1 < lim) ? " -o" : ""); + p += strlen(p); } - strputs(sb, " \\) -print"); - findcom = strvalue(sb); - - if (skiplist) { - char *reg; - STRBUF *sbb = stropen(); + sprintf(p, " \\) -print"); + if (sizeof(skippath) != 0) { + int i, lim = sizeof(skippath)/sizeof(char *); /* * construct regular expression. */ - strputc(sbb, '('); /* ) */ - for (p = skiplist; p; ) { - char *skipf = p; - if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL) - *p++ = 0; - strputc(sbb, '/'); - for (q = skipf; *q; q++) { + p = edit; + *p++ = '('; + for (i = 0; i < lim; i++) { + *p++ = '/'; + for (q = skippath[i]; *q; q++) { if (*q == '.') - strputc(sbb, '\\'); - strputc(sbb, *q); + *p++ = '\\'; + *p++ = *q; } if (*(q - 1) != '/') - strputc(sbb, '$'); - if (p) - strputc(sbb, '|'); + *p++ = '$'; + *p++ = '|'; } - strputc(sbb, ')'); - reg = strvalue(sbb); + *(p - 1) = ')'; + *p = 0; /* * compile regular expression. */ - if (regcomp(skip, reg, REG_EXTENDED|REG_NEWLINE) != 0) + skip = &skip_area; + if (regcomp(skip, edit, REG_EXTENDED|REG_NEWLINE) != 0) die("cannot compile regular expression."); - strclose(sbb); } else { skip = (regex_t *)0; } if (!(ip = popen(findcom, "r"))) die("cannot execute find."); - strclose(sb); - if (sufflist) - free(sufflist); - if (skiplist) - free(skiplist); } char * findread(length) @@ -189,12 +145,8 @@ int *length; static char path[MAXPATHLEN+1]; char *p; - assert(opened == 1); while (fgets(path, MAXPATHLEN, ip)) { if (!skip || regexec(skip, path, 0, 0, 0) != 0) { - /* - * chop(path) - */ p = path + strlen(path) - 1; if (*p != '\n') die("output of find(1) is wrong (findread)."); @@ -204,242 +156,11 @@ int *length; return path; } } - return NULL; + return (char *)0; } void findclose(void) { - assert(opened == 1); pclose(ip); opened = 0; } -#else /* USEFIND */ -/*----------------------------------------------------------------------*/ -/* dirent version findxxx() */ -/*----------------------------------------------------------------------*/ -#define STACKSIZE 50 -static char dir[MAXPATHLEN+1]; /* directory path */ -static struct { - STRBUF *sb; - char *dirp, *start, *end, *p; -} stack[STACKSIZE], *topp, *curp; /* stack */ - -static regex_t suff_area; -static regex_t *suff = &suff_area; - -static int -getdirs(dir, sb) -char *dir; -STRBUF *sb; -{ - DIR *dirp; - struct dirent *dp; -#ifndef BSD4_4 - struct stat st; -#endif - - if ((dirp = opendir(dir)) == NULL) - return -1; - while ((dp = readdir(dirp)) != NULL) { -#ifdef BSD4_4 - if (dp->d_namlen == 1 && dp->d_name[0] == '.') - continue; - if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.') - continue; - if (dp->d_type == DT_DIR) - strputc(sb, 'd'); - else if (dp->d_type == DT_REG) - strputc(sb, 'f'); - else if (dp->d_type == DT_LNK) - strputc(sb, 'l'); - else - strputc(sb, ' '); - strnputs(sb, dp->d_name, (int)dp->d_namlen); -#else - if (stat(path, &st) < 0) { - fprintf(stderr, "cannot stat '%s'. (Ignored)\n", path); - continue; - } - if (S_ISDIR(st.st_mode)) - strputc(sb, 'd'); - else if (S_ISREG(st.st_mode)) - strputc(sb, 'f'); - else if (S_ISLNK(st.st_mode)) - strputc(sb, 'l'); - else - strputc(sb, ' '); - strputs(sb, dp->d_name); -#endif /* BSD4_4 */ - strputc(sb, '\0'); - } - (void)closedir(dirp); - return 0; -} -void -findopen() -{ - STRBUF *sb = stropen(); - char *sufflist = NULL; - char *skiplist = NULL; - - assert(opened == 0); - opened = 1; - - /* - * setup stack. - */ - curp = &stack[0]; - topp = curp + STACKSIZE; - strcpy(dir, "."); - - curp->dirp = dir + strlen(dir); - curp->sb = stropen(); - if (getdirs(dir, curp->sb) < 0) - die("cannot open '.' directory."); - curp->start = curp->p = strvalue(curp->sb); - curp->end = curp->start + strbuflen(curp->sb); - - /* - * preparing regular expression. - */ - strstart(sb); - if (!getconfs("suffixes", sb)) - die("cannot get suffixes data."); - sufflist = strdup(strvalue(sb)); - if (!sufflist) - die("short of memory."); - trim(sufflist); - strstart(sb); - if (getconfs("skip", sb)) { - skiplist = strdup(strvalue(sb)); - if (!skiplist) - die("short of memory."); - trim(skiplist); - } - { - char *p; - - strstart(sb); - strputc(sb, '('); /* ) */ - for (p = sufflist; p; ) { - char *suffp = p; - if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL) - *p++ = 0; - strputs(sb, "\\."); - strputs(sb, suffp); - strputc(sb, '$'); - if (p) - strputc(sb, '|'); - } - strputc(sb, ')'); - /* - * compile regular expression. - */ - if (regcomp(suff, strvalue(sb), REG_EXTENDED) != 0) - die("cannot compile regular expression."); - } - if (skiplist) { - char *p, *q; - /* - * construct regular expression. - */ - strstart(sb); - strputc(sb, '('); /* ) */ - for (p = skiplist; p; ) { - char *skipf = p; - if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL) - *p++ = 0; - strputc(sb, '/'); - for (q = skipf; *q; q++) { - if (*q == '.') - strputc(sb, '\\'); - strputc(sb, *q); - } - if (*(q - 1) != '/') - strputc(sb, '$'); - if (p) - strputc(sb, '|'); - } - strputc(sb, ')'); - /* - * compile regular expression. - */ - if (regcomp(skip, strvalue(sb), REG_EXTENDED) != 0) - die("cannot compile regular expression."); - } else { - skip = (regex_t *)0; - } - strclose(sb); - if (sufflist) - free(sufflist); - if (skiplist) - free(skiplist); -} -char * -findread(length) -int *length; -{ - static char val[MAXPATHLEN+1]; - - for (;;) { - while (curp->p < curp->end) { - char type = *(curp->p); - char *unit = curp->p + 1; - - curp->p += strlen(curp->p) + 1; - if (type == 'f' || type == 'l') { - char *path = makepath(dir, unit); - if (regexec(suff, path, 0, 0, 0) != 0) - continue; - if (skip && regexec(skip, path, 0, 0, 0) == 0) - continue; - strcpy(val, path); - return val; - } - if (type == 'd') { - STRBUF *sb = stropen(); - char *dirp = curp->dirp; - - strcat(dirp, "/"); - strcat(dirp, unit); - if (getdirs(dir, sb) < 0) { - fprintf(stderr, "cannot open directory '%s'. (Ignored)\n", dir); - strclose(sb); - *(curp->dirp) = 0; - continue; - } - /* - * Push stack. - */ - if (++curp >= topp) - die("directory stack over flow."); - curp->dirp = dirp + strlen(dirp); - curp->sb = sb; - curp->start = curp->p = strvalue(sb); - curp->end = curp->start + strbuflen(sb); - } - } - strclose(curp->sb); - curp->sb = NULL; - if (curp == &stack[0]) - break; - /* - * Pop stack. - */ - curp--; - *(curp->dirp) = 0; - } - return NULL; -} -void -findclose(void) -{ - assert(opened == 1); - for (curp = &stack[0]; curp < topp; curp++) - if (curp->sb != NULL) - strclose(curp->sb); - else - break; - opened = 0; -} -#endif /* !USEFIND */ diff --git a/contrib/global/lib/find.h b/contrib/global/lib/find.h index ae16f7230872f..bb140e05ddcba 100644 --- a/contrib/global/lib/find.h +++ b/contrib/global/lib/find.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/contrib/global/lib/getdbpath.c b/contrib/global/lib/getdbpath.c index 4529988ed6c86..73f1a4f480556 100644 --- a/contrib/global/lib/getdbpath.c +++ b/contrib/global/lib/getdbpath.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,10 +41,12 @@ #include "die.h" #include "getdbpath.h" +#include "locatestring.h" #include "test.h" -static const char *makeobjdirprefix; /* obj partition */ -static const char *makeobjdir; /* obj directory */ +static char *makeobjdirprefix; /* obj partition */ +static char *makeobjdir; /* obj directory */ +static int bsd; /* if BSD */ /* * gtagsexist: test whether GTAGS's existence. @@ -65,15 +67,17 @@ char *dbpath; strcpy(dbpath, candidate); return 1; } - sprintf(path, "%s/%s/GTAGS", candidate, makeobjdir); - if (test("fr", path)) { - sprintf(dbpath, "%s/%s", candidate, makeobjdir); - return 1; - } - sprintf(path, "%s%s/GTAGS", makeobjdirprefix, candidate); - if (test("fr", path)) { - sprintf(dbpath, "%s%s", makeobjdirprefix, candidate); - return 1; + if (bsd) { + sprintf(path, "%s/%s/GTAGS", candidate, makeobjdir); + if (test("fr", path)) { + sprintf(dbpath, "%s/%s", candidate, makeobjdir); + return 1; + } + sprintf(path, "%s%s/GTAGS", makeobjdirprefix, candidate); + if (test("fr", path)) { + sprintf(dbpath, "%s%s", makeobjdirprefix, candidate); + return 1; + } } return 0; } @@ -106,14 +110,17 @@ char *dbpath; if (!strcmp(cwd, "/")) die("It's root directory! What are you doing?"); - if ((p = getenv("MAKEOBJDIRPREFIX")) != NULL) - makeobjdirprefix = p; - else - makeobjdirprefix = "/usr/obj"; - if ((p = getenv("MAKEOBJDIR")) != NULL) - makeobjdir = p; - else - makeobjdir = "obj"; + if (getenv("OSTYPE") && locatestring(getenv("OSTYPE"), "BSD", 0)) { + if ((p = getenv("MAKEOBJDIRPREFIX")) != NULL) + makeobjdirprefix = p; + else + makeobjdirprefix = "/usr/obj"; + if ((p = getenv("MAKEOBJDIR")) != NULL) + makeobjdir = p; + else + makeobjdir = "obj"; + bsd = 1; + } if ((p = getenv("GTAGSROOT")) != NULL) { if (*p != '/') diff --git a/contrib/global/lib/getdbpath.h b/contrib/global/lib/getdbpath.h index 063d2367055af..193dfffc596ab 100644 --- a/contrib/global/lib/getdbpath.h +++ b/contrib/global/lib/getdbpath.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/contrib/global/lib/global.h b/contrib/global/lib/global.h index 5ab2ca563dc43..7fbc2b8ef230d 100644 --- a/contrib/global/lib/global.h +++ b/contrib/global/lib/global.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,30 +28,27 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * global.h 2-May-98 + * global.h 16-Oct-97 * */ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#include "conf.h" -#include "dbop.h" -#include "defined.h" -#include "die.h" -#include "find.h" -#include "getdbpath.h" #include "gparam.h" -#include "gtagsop.h" -#include "locatestring.h" +#include "dbname.h" #include "makepath.h" +#include "dbio.h" +#include "locatestring.h" #include "mgets.h" -#include "pathop.h" -#include "strbuf.h" -#include "strmake.h" +#include "die.h" +#include "find.h" +#include "getdbpath.h" +#include "strop.h" +#include "gtagsopen.h" +#include "lookup.h" #include "tab.h" +#include "tag.h" #include "test.h" -#include "token.h" -#include "usable.h" #endif /* ! _GLOBAL_H_ */ diff --git a/contrib/global/lib/gparam.h b/contrib/global/lib/gparam.h index 8a13c7e64349f..8a506c465cae6 100644 --- a/contrib/global/lib/gparam.h +++ b/contrib/global/lib/gparam.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,17 +28,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * gparam.h 16-Jul-98 + * gparam.h 16-Oct-97 * */ #ifndef _GPARAM_H_ #define _GPARAM_H_ -#define MAXFILLEN 1024 /* max length of filter */ -#define IDENTLEN 512 /* max length of ident */ -#define MAXENVLEN 1024 /* max length of env */ -#define MAXBUFLEN 1024 /* max length of buffer */ -#define MAXPROPLEN 1024 /* max length of property */ -#define MAXARGLEN 512 /* max length of argment */ +#define MAXCOMLINE 1024 /* max length of filter */ +#define IDENTLEN 512 /* max length of ident */ +#define MAXENVLEN 1024 /* max length of env */ +#define MAXBUFLEN 1024 /* max length of buffer */ #endif /* ! _GPARAM_H_ */ diff --git a/contrib/global/lib/gtagsop.c b/contrib/global/lib/gtagsop.c deleted file mode 100644 index 41635695fef34..0000000000000 --- a/contrib/global/lib/gtagsop.c +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * gtagsop.c 12-Nov-98 - * - */ -#include <assert.h> -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "dbop.h" -#include "die.h" -#include "gtagsop.h" -#include "locatestring.h" -#include "makepath.h" -#include "mgets.h" -#include "pathop.h" -#include "strbuf.h" -#include "strmake.h" -#include "tab.h" - -static char *genrecord __P((GTOP *)); -static int belongto __P((GTOP *, char *, char *)); - -static int support_version = 2; /* acceptable format version */ -static const char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"}; -/* - * dbname: return db name - * - * i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS - * r) dbname - */ -const char * -dbname(db) -int db; -{ - assert(db >= 0 && db < GTAGLIM); - return tagslist[db]; -} -/* - * makecommand: make command line to make global tag file - * - * i) comline skelton command line - * i) path path name - * o) sb command line - */ -void -makecommand(comline, path, sb) -char *comline; -char *path; -STRBUF *sb; -{ - char *p; - - if (!(p = strmake(comline, "%"))) - die1("'%%s' is needed in tag command line. (%s)\n", comline); - strputs(sb, p); - strputs(sb, path); - if (!(p = locatestring(comline, "%s", MATCH_FIRST))) - die1("'%%s' is needed in tag command line. (%s)\n", comline); - strputs(sb, p+2); -} -/* - * formatcheck: check format of tag command's output - * - * i) line input - * i) flags flag - * r) 0: normal - * -1: tag name - * -2: line number - * -3: path - * - * [example of right format] - * - * $1 $2 $3 $4 - * ---------------------------------------------------- - * main 83 ./ctags.c main(argc, argv) - */ -int -formatcheck(line, flags) -char *line; -int flags; -{ - char *p, *q; - /* - * $1 = tagname: allowed any char except sepalator. - */ - p = q = line; - while (*p && !isspace(*p)) - p++; - while (*p && isspace(*p)) - p++; - if (p == q) - return -1; - /* - * $2 = line number: must be digit. - */ - q = p; - while (*p && !isspace(*p)) - if (!isdigit(*p)) - return -2; - else - p++; - if (p == q) - return -2; - while (*p && isspace(*p)) - p++; - /* - * $3 = path: - * standard format: must start with './'. - * compact format: must be digit. - */ - if (flags & GTAGS_PATHINDEX) { - while (*p && !isspace(*p)) - if (!isdigit(*p)) - return -3; - else - p++; - } else { - if (!(*p == '.' && *(p + 1) == '/' && *(p + 2))) - return -3; - } - return 0; -} -/* - * gtagsopen: open global tag. - * - * i) dbpath dbpath directory - * i) root root directory (needed when compact format) - * i) db GTAGS, GRTAGS, GSYMS - * i) mode GTAGS_READ: read only - * GTAGS_CREATE: create tag - * GTAGS_MODIFY: modify tag - * i) flags GTAGS_COMPACT - * GTAGS_PATHINDEX - * r) GTOP structure - * - * when error occurred, gtagopen doesn't return. - * GTAGS_PATHINDEX needs GTAGS_COMPACT. - */ -GTOP * -gtagsopen(dbpath, root, db, mode, flags) -char *dbpath; -char *root; -int db; -int mode; -int flags; -{ - GTOP *gtop; - int dbmode = 0; - - if ((gtop = (GTOP *)calloc(sizeof(GTOP), 1)) == NULL) - die("short of memory."); - gtop->db = db; - gtop->mode = mode; - switch (gtop->mode) { - case GTAGS_READ: - dbmode = 0; - break; - case GTAGS_CREATE: - dbmode = 1; - break; - case GTAGS_MODIFY: - dbmode = 2; - break; - default: - assert(0); - } - - /* - * allow duplicate records. - */ - gtop->dbop = dbop_open(makepath(dbpath, dbname(db)), dbmode, 0644, DBOP_DUP); - if (gtop->dbop == NULL) { - if (dbmode == 1) - die1("cannot make %s.", dbname(db)); - die1("%s not found.", dbname(db)); - } - /* - * decide format version. - */ - gtop->format_version = 1; - gtop->format = GTAGS_STANDARD; - /* - * This is a special case. GSYMS had compact format even if - * format version 1. - */ - if (db == GSYMS) - gtop->format |= GTAGS_COMPACT; - if (gtop->mode == GTAGS_CREATE) { - if (flags & GTAGS_COMPACT) { - char buf[80]; - - gtop->format_version = 2; - sprintf(buf, "%s %d", VERSIONKEY, gtop->format_version); - dbop_put(gtop->dbop, VERSIONKEY, buf); - gtop->format |= GTAGS_COMPACT; - dbop_put(gtop->dbop, COMPACTKEY, COMPACTKEY); - if (flags & GTAGS_PATHINDEX) { - gtop->format |= GTAGS_PATHINDEX; - dbop_put(gtop->dbop, PATHINDEXKEY, PATHINDEXKEY); - } - } - } else { - /* - * recognize format version of GTAGS. 'format version record' - * is saved as a META record in GTAGS and GRTAGS. - * if 'format version record' is not found, it's assumed - * version 1. - */ - char *p; - - if ((p = dbop_get(gtop->dbop, VERSIONKEY)) != NULL) { - for (p += strlen(VERSIONKEY); *p && isspace(*p); p++) - ; - gtop->format_version = atoi(p); - } - if (gtop->format_version > support_version) - die("GTAGS seems new format. Please install the latest GLOBAL."); - if (gtop->format_version > 1) { - if (dbop_get(gtop->dbop, COMPACTKEY) != NULL) - gtop->format |= GTAGS_COMPACT; - if (dbop_get(gtop->dbop, PATHINDEXKEY) != NULL) - gtop->format |= GTAGS_PATHINDEX; - } - } - if (gtop->format & GTAGS_PATHINDEX || gtop->mode != GTAGS_READ) { - if (pathopen(dbpath, dbmode) < 0) { - if (dbmode == 1) - die("cannot create GPATH."); - else - die("GPATH not found."); - } - } - /* - * Stuff for compact format. - */ - if (gtop->format & GTAGS_COMPACT) { - assert(root != NULL); - strcpy(gtop->root, root); - if (gtop->mode != GTAGS_READ) - gtop->sb = stropen(); - } - return gtop; -} -/* - * gtagsput: put tag record with packing. - * - * i) gtop descripter of GTOP - * i) tag tag name - * i) record ctags -x image - */ -void -gtagsput(gtop, tag, record) -GTOP *gtop; -char *tag; -char *record; -{ - char *p, *q; - char lno[10]; - char path[MAXPATHLEN+1]; - - if (gtop->format == GTAGS_STANDARD) { - entab(record); - dbop_put(gtop->dbop, tag, record); - return; - } - /* - * gtop->format & GTAGS_COMPACT - */ - p = record; /* ignore $1 */ - while (*p && !isspace(*p)) - p++; - while (*p && isspace(*p)) - p++; - q = lno; /* lno = $2 */ - while (*p && !isspace(*p)) - *q++ = *p++; - *q = 0; - while (*p && isspace(*p)) - p++; - q = path; /* path = $3 */ - while (*p && !isspace(*p)) - *q++ = *p++; - *q = 0; - /* - * First time, it occurs, because 'prev_tag' and 'prev_path' are NULL. - */ - if (strcmp(gtop->prev_tag, tag) || strcmp(gtop->prev_path, path)) { - if (gtop->prev_tag[0]) - dbop_put(gtop->dbop, gtop->prev_tag, strvalue(gtop->sb)); - strcpy(gtop->prev_tag, tag); - strcpy(gtop->prev_path, path); - /* - * Start creating new record. - */ - strstart(gtop->sb); - strputs(gtop->sb, strmake(record, " \t")); - strputc(gtop->sb, ' '); - strputs(gtop->sb, path); - strputc(gtop->sb, ' '); - strputs(gtop->sb, lno); - } else { - strputc(gtop->sb, ','); - strputs(gtop->sb, lno); - } -} -/* - * gtagsadd: add tags belonging to the path into tag file. - * - * i) gtop descripter of GTOP - * i) comline tag command line - * i) path source file - * i) flags GTAGS_UNIQUE, GTAGS_EXTRACTMETHOD - */ -void -gtagsadd(gtop, comline, path, flags) -GTOP *gtop; -char *comline; -char *path; -int flags; -{ - char *tagline; - FILE *ip; - STRBUF *sb = stropen(); - - /* - * add path index if not yet. - */ - pathput(path); - /* - * make command line. - */ - makecommand(comline, path, sb); - /* - * Compact format. - */ - if (gtop->format & GTAGS_PATHINDEX) { - char *pno; - - if ((pno = pathget(path)) == NULL) - die1("GPATH is corrupted.('%s' not found)", path); - strputs(sb, "| sed 's!"); - strputs(sb, path); - strputs(sb, "!"); - strputs(sb, pno); - strputs(sb, "!'"); - } - if (gtop->format & GTAGS_COMPACT) - strputs(sb, "| sort +0 -1 +1n -2"); - if (flags & GTAGS_UNIQUE) - strputs(sb, "| uniq"); - if (!(ip = popen(strvalue(sb), "r"))) - die1("cannot execute '%s'.", strvalue(sb)); - while ((tagline = mgets(ip, NULL, MGETS_TAILCUT)) != NULL) { - char *tag, *p; - - if (formatcheck(tagline, gtop->format) < 0) - die1("illegal parser output.\n'%s'", tagline); - tag = strmake(tagline, " \t"); /* tag = $1 */ - /* - * extract method when class method definition. - * - * Ex: Class::method(...) - * - * key = 'method' - * data = 'Class::method 103 ./class.cpp ...' - */ - if (flags & GTAGS_EXTRACTMETHOD) { - if ((p = locatestring(tag, ".", MATCH_LAST)) != NULL) - tag = p + 1; - else if ((p = locatestring(tag, "::", MATCH_LAST)) != NULL) - tag = p + 2; - } - gtagsput(gtop, tag, tagline); - } - pclose(ip); - strclose(sb); -} -/* - * belongto: wheather or not record belongs to the path. - * - * i) gtop GTOP structure - * i) path path name (in standard format) - * path number (in compact format) - * i) p record - * r) 1: belong, 0: not belong - */ -static int -belongto(gtop, path, p) -GTOP *gtop; -char *path; -char *p; -{ - char *q; - int length = strlen(path); - - /* - * seek to path part. - */ - if (gtop->format & GTAGS_PATHINDEX) { - for (q = p; *q && !isspace(*q); q++) - ; - if (*q == 0) - die1("illegal tag format. '%s'", p); - for (; *q && isspace(*q); q++) - ; - } else - q = locatestring(p, "./", MATCH_FIRST); - if (*q == 0) - die1("illegal tag format. '%s'", p); - if (!strncmp(q, path, length) && isspace(*(q + length))) - return 1; - return 0; -} -/* - * gtagsdelete: delete records belong to path. - * - * i) gtop GTOP structure - * i) path path name - */ -void -gtagsdelete(gtop, path) -GTOP *gtop; -char *path; -{ - char *p, *key; - int length; - - /* - * In compact format, a path is saved as a file number. - */ - key = path; - if (gtop->format & GTAGS_PATHINDEX) - if ((key = pathget(path)) == NULL) - die1("GPATH is corrupted.('%s' not found)", path); - length = strlen(key); - /* - * read sequentially, because db(1) has just one index. - */ - for (p = dbop_first(gtop->dbop, NULL, 0); p; p = dbop_next(gtop->dbop)) - if (belongto(gtop, key, p)) - dbop_del(gtop->dbop, NULL); - /* - * don't delete from path index. - */ -} -/* - * gtagsfirst: return first record - * - * i) gtop GTOP structure - * i) tag tag name - * i) flags GTOP_PREFIX prefix read - * GTOP_KEY read key only - * r) record - */ -char * -gtagsfirst(gtop, tag, flags) -GTOP *gtop; -char *tag; -int flags; -{ - int dbflags = 0; - char *line; - - gtop->flags = flags; - if (flags & GTOP_PREFIX && tag != NULL) - dbflags |= DBOP_PREFIX; - if (flags & GTOP_KEY) - dbflags |= DBOP_KEY; - if ((line = dbop_first(gtop->dbop, tag, dbflags)) == NULL) - return NULL; - if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) - return line; - /* - * Compact format. - */ - gtop->line = line; /* gtop->line = $0 */ - gtop->opened = 0; - return genrecord(gtop); -} -/* - * gtagsnext: return followed record - * - * i) gtop GTOP structure - * r) record - * NULL end of tag - */ -char * -gtagsnext(gtop) -GTOP *gtop; -{ - char *line; - - /* - * If it is standard format or only key. - * Just return it. - */ - if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) - return dbop_next(gtop->dbop); - /* - * gtop->format & GTAGS_COMPACT - */ - if ((line = genrecord(gtop)) != NULL) - return line; - /* - * read next record. - */ - if ((line = dbop_next(gtop->dbop)) == NULL) - return line; - gtop->line = line; /* gtop->line = $0 */ - gtop->opened = 0; - return genrecord(gtop); -} -/* - * gtagsclose: close tag file - * - * i) gtop GTOP structure - */ -void -gtagsclose(gtop) -GTOP *gtop; -{ - if (gtop->format & GTAGS_PATHINDEX || gtop->mode != GTAGS_READ) - pathclose(); - if (gtop->sb && gtop->prev_tag[0]) - dbop_put(gtop->dbop, gtop->prev_tag, strvalue(gtop->sb)); - if (gtop->sb) - strclose(gtop->sb); - dbop_close(gtop->dbop); - free(gtop); -} -static char * -genrecord(gtop) -GTOP *gtop; -{ - static char output[MAXBUFLEN+1]; - char path[MAXPATHLEN+1]; - static char buf[1]; - char *buffer = buf; - char *lnop; - int tagline; - - if (!gtop->opened) { - char *p, *q; - - gtop->opened = 1; - p = gtop->line; - q = gtop->tag; /* gtop->tag = $1 */ - while (!isspace(*p)) - *q++ = *p++; - *q = 0; - for (; isspace(*p) ; p++) - ; - if (gtop->format & GTAGS_PATHINDEX) { /* gtop->path = $2 */ - char *name; - - q = path; - while (!isspace(*p)) - *q++ = *p++; - *q = 0; - if ((name = pathget(path)) == NULL) - die1("GPATH is corrupted.('%s' not found)", path); - strcpy(gtop->path, name); - } else { - q = gtop->path; - while (!isspace(*p)) - *q++ = *p++; - *q = 0; - } - for (; isspace(*p) ; p++) - ; - gtop->lnop = p; /* gtop->lnop = $3 */ - - if (gtop->root) - sprintf(path, "%s/%s", gtop->root, >op->path[2]); - else - sprintf(path, "%s", >op->path[2]); - if ((gtop->fp = fopen(path, "r")) != NULL) { - buffer = mgets(gtop->fp, NULL, MGETS_TAILCUT); - gtop->lno = 1; - } - } - - lnop = gtop->lnop; - if (*lnop >= '0' && *lnop <= '9') { - /* get line number */ - for (tagline = 0; *lnop >= '0' && *lnop <= '9'; lnop++) - tagline = tagline * 10 + *lnop - '0'; - if (*lnop == ',') - lnop++; - gtop->lnop = lnop; - if (gtop->fp) { - if (gtop->lno == tagline) - return output; - while (gtop->lno < tagline) { - if (!(buffer = mgets(gtop->fp, NULL, MGETS_TAILCUT))) - die1("unexpected end of file. '%s'", path); - gtop->lno++; - } - } - if (strlen(gtop->tag) >= 16 && tagline >= 1000) - sprintf(output, "%-16s %4d %-16s %s", - gtop->tag, tagline, gtop->path, buffer); - else - sprintf(output, "%-16s%4d %-16s %s", - gtop->tag, tagline, gtop->path, buffer); - return output; - } - if (gtop->opened && gtop->fp != NULL) { - gtop->opened = 0; - fclose(gtop->fp); - } - return NULL; -} diff --git a/contrib/global/lib/gtagsop.h b/contrib/global/lib/gtagsop.h deleted file mode 100644 index c6e75d72a63e2..0000000000000 --- a/contrib/global/lib/gtagsop.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * gtagsop.h 23-Dec-97 - * - */ - -#ifndef _GTOP_H_ -#define _GTOP_H_ -#include <stdio.h> -#include "dbop.h" -#include "gparam.h" -#include "strbuf.h" - -#define VERSIONKEY " __.VERSION" -#define COMPACTKEY " __.COMPACT" -#define PATHINDEXKEY " __.PATHINDEX" - -#define GTAGS 0 -#define GRTAGS 1 -#define GSYMS 2 -#define GTAGLIM 3 - -#define GTAGS_READ 0 -#define GTAGS_CREATE 1 -#define GTAGS_MODIFY 2 - -/* gtagsopen() */ -#define GTAGS_STANDARD 0 /* standard format */ -#define GTAGS_COMPACT 1 /* compact format */ -#define GTAGS_PATHINDEX 2 /* use path index */ -/* gtagsadd() */ -#define GTAGS_UNIQUE 1 /* compress duplicate lines */ -#define GTAGS_EXTRACTMETHOD 2 /* extract method from class definition */ -/* gtagsfirst() */ -#define GTOP_KEY 1 /* read key part */ -#define GTOP_PREFIX 2 /* prefixed read */ - -typedef struct { - DBOP *dbop; /* descripter of DBOP */ - int format_version; /* format version */ - int format; /* GTAGS_STANDARD, GTAGS_COMPACT */ - int mode; /* mode */ - int db; /* 0:GTAGS, 1:GRTAGS, 2:GSYMS */ - int flags; /* flags */ - char root[MAXPATHLEN+1]; /* root directory of source tree */ - /* - * Stuff for compact format - */ - int opened; /* wether or not file opened */ - char *line; /* current record */ - char tag[IDENTLEN+1]; /* current tag */ - char prev_tag[IDENTLEN+1]; /* previous tag */ - char path[MAXPATHLEN+1]; /* current path */ - char prev_path[MAXPATHLEN+1];/* previous path */ - STRBUF *sb; /* string buffer */ - FILE *fp; /* descriptor of 'path' */ - char *lnop; /* current line number */ - int lno; /* integer value of 'lnop' */ -} GTOP; - -#ifndef __P -#if defined(__STDC__) -#define __P(protos) protos -#else -#define __P(protos) () -#endif -#endif - -const char *dbname __P((int)); -void makecommand __P((char *, char *, STRBUF *)); -int formatcheck __P((char *, int)); -GTOP *gtagsopen __P((char *, char *, int, int, int)); -void gtagsput __P((GTOP *, char *, char *)); -char *gtagsget __P((GTOP *, char *)); -void gtagsadd __P((GTOP *, char *, char *, int)); -void gtagsdelete __P((GTOP *, char *)); -char *gtagsfirst __P((GTOP *, char *, int)); -char *gtagsnext __P((GTOP *)); -void gtagsclose __P((GTOP *)); - -#endif /* ! _GTOP_H_ */ diff --git a/contrib/global/lib/strbuf.c b/contrib/global/lib/gtagsopen.c index 3df14c9ee370b..90f0481603f5b 100644 --- a/contrib/global/lib/strbuf.c +++ b/contrib/global/lib/gtagsopen.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,110 +28,73 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * strbuf.c 5-Jul-98 + * gtagsopen.c 20-Oct-97 * */ +#include <sys/param.h> + +#include <ctype.h> +#include <db.h> +#include <fcntl.h> #include <stdlib.h> -#include <string.h> +#include "dbio.h" +#include "dbname.h" #include "die.h" -#include "strbuf.h" +#include "gtagsopen.h" +#include "makepath.h" -/* - * usage: string buffer - * - * sb = stropen(); - * for (s = string; *s; s++) - * strputc(sb, *s); - * s = strvalue(sb); - * strstart(sb); - * strputs(sb, "hello"); - * s = strvalue(sb); - * strclose(sb); - */ -/* - * expandbuf: expand buffer so that afford to the length data at least. - * - * i) sb STRBUF structure - * i) length required room - */ -void -expandbuf(sb, length) -STRBUF *sb; -int length; -{ - int count = sb->curp - sb->sbuf; +#define VERSIONKEY " __.VERSION" +static int support_version = 1; /* accept this format version */ - sb->sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE; - if (!(sb->sbuf = (char *)realloc(sb->sbuf, sb->sbufsize + 1))) - die("short of memory."); - sb->curp = sb->sbuf + count; - sb->endp = sb->sbuf + sb->sbufsize; -} /* - * stropen: open string buffer. + * gtagsopen: open global database. * - * r) sb STRBUF structure - */ -STRBUF * -stropen(void) -{ - STRBUF *sb = (STRBUF *)calloc(sizeof(STRBUF), 1); - - if (sb == NULL) - die("short of memory."); - sb->sbufsize = INITIALSIZE; - if (!(sb->sbuf = (char *)malloc(sb->sbufsize + 1))) - die("short of memory."); - sb->curp = sb->sbuf; - sb->endp = sb->sbuf + sb->sbufsize; - - return sb; -} -/* - * strstart: reset string buffer for new string. + * i) dbpath dbpath directory + * i) db GTAGS, GRTAGS, GSYMS + * i) mode 0: read only + * 1: write only + * 2: read and write + * r) DB structure * - * i) sb STRBUF structure + * when error occurred, gtagopen doesn't return. */ -void -strstart(sb) -STRBUF *sb; +DBIO * +gtagsopen(dbpath, db, mode) +char *dbpath; +int db; +int mode; { - sb->curp = sb->sbuf; -} -/* - * strbuflen: return the length of string buffer. - * - * i) sb STRBUF structure - */ -int -strbuflen(sb) -STRBUF *sb; -{ - return sb->curp - sb->sbuf; -} -/* - * strvalue: return the content of string buffer. - * - * i) sb STRBUF structure - * r) string - */ -char * -strvalue(sb) -STRBUF *sb; -{ - *sb->curp = 0; - return sb->sbuf; -} -/* - * strclose: close string buffer. - * - * i) sb STRBUF structure - */ -void -strclose(sb) -STRBUF *sb; -{ - (void)free(sb->sbuf); - (void)free(sb); + DBIO *dbio; + int version_number; + char *p; + + /* + * allow duplicate records. + */ + dbio = db_open(makepath(dbpath, dbname(db)), mode, 0644, DBIO_DUP); + if (dbio == NULL) { + if (mode == 1) + die1("cannot make database (%s).", makepath(dbpath, dbname(db))); + die1("database not found (%s).", makepath(dbpath, dbname(db))); + } + if (mode == 1) { + /* nothing to do now */ + } else { + /* + * recognize format version of GTAGS. 'format version record' + * is saved as a META record in GTAGS and GRTAGS. + * if 'format version record' is not found, it's assumed + * version 1. + */ + if ((p = db_get(dbio, VERSIONKEY)) != NULL) { + for (p += strlen(VERSIONKEY); *p && isspace(*p); p++) + ; + version_number = atoi(p); + } else + version_number = 1; + if (version_number > support_version) + die("GTAGS seems new format. Please install the latest GLOBAL."); + } + return dbio; } diff --git a/contrib/global/lib/gtagsopen.h b/contrib/global/lib/gtagsopen.h new file mode 100644 index 0000000000000..2afb2ab568928 --- /dev/null +++ b/contrib/global/lib/gtagsopen.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Shigio Yamaguchi. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * gtagsopen.h 16-Oct-97 + * + */ + +#ifndef _GTAGSOPEN_H_ +#define _GTAGSOPEN_H_ +#include "dbio.h" + +DBIO *gtagsopen __P((char *, int, int)); + +#endif /* ! _GTAGSOPEN_H_ */ diff --git a/contrib/global/lib/locatestring.c b/contrib/global/lib/locatestring.c index 76285994befb9..230ccce5149a2 100644 --- a/contrib/global/lib/locatestring.c +++ b/contrib/global/lib/locatestring.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * locatestring.c 25-Jul-98 + * locatestring.c 20-Oct-97 * */ #include <string.h> @@ -40,36 +40,35 @@ * * i) string string * i) pattern pattern - * i) flag MATCH_FIRST: match first - * MATCH_AT_FIRST: match only at first column - * MATCH_LAST: match last - * MATCH_AT_LAST: match only at last column + * i) flag 0: match first + * 1: match only at first column + * 2: match last + * 3: match only at last column * r) pointer or NULL * * This function is made to avoid compatibility problems. */ char * locatestring(string, pattern, flag) -const char *string; -const char *pattern; +char *string; +char *pattern; int flag; { int c = *pattern; - int slen, plen; - const char *p = NULL; + char *p = (char *)0; - plen = strlen(pattern); - if (flag == MATCH_AT_LAST && (slen = strlen(string)) > plen) - string += (slen - plen); + if (flag == 3 && strlen(string) > strlen(pattern)) { + string += strlen(string) - strlen(pattern); + } for (; *string; string++) { if (*string == c) - if (!strncmp(string, pattern, plen)) { + if (!strncmp(string, pattern, strlen(pattern))) { p = string; - if (flag == MATCH_FIRST) + if (flag == 0) break; } - if (flag == MATCH_AT_FIRST || flag == MATCH_AT_LAST) + if (flag == 1 || flag == 3) break; } - return (char *)p; + return p; } diff --git a/contrib/global/lib/locatestring.h b/contrib/global/lib/locatestring.h index 2b881c6f447e0..cdaeedb1e5b0a 100644 --- a/contrib/global/lib/locatestring.h +++ b/contrib/global/lib/locatestring.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,18 +28,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * locatestring.h 25-Jul-98 + * locatestring.h 16-Oct-97 * */ #ifndef _LOCATESTRING_H_ #define _LOCATESTRING_H_ -#define MATCH_FIRST 0 -#define MATCH_AT_FIRST 1 -#define MATCH_LAST 2 -#define MATCH_AT_LAST 3 - #ifndef __P #if defined(__STDC__) #define __P(protos) protos @@ -48,6 +43,6 @@ #endif #endif -char *locatestring __P((const char *, const char *, int)); +char *locatestring __P((char *, char *, int)); #endif /* ! _LOCATESTRING_H_ */ diff --git a/contrib/global/lib/lookup.c b/contrib/global/lib/lookup.c new file mode 100644 index 0000000000000..d317ba6f34347 --- /dev/null +++ b/contrib/global/lib/lookup.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Shigio Yamaguchi. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * lookup.c 20-Oct-97 + * + */ +#include "gtagsopen.h" +#include "lookup.h" +#include "dbio.h" +#include "die.h" +#include "dbname.h" + +static DBIO *dbio; +static int opened; + +void +lookupopen(dbpath) +char *dbpath; +{ + if (opened) + die("nested call to lookupopen."); + opened = 1; + dbio = gtagsopen(dbpath, GTAGS, 0); +} +int +lookup(name) +char *name; +{ + char *p = db_get(dbio, name); + return (p) ? 1 : 0; +} +void +lookupclose(void) +{ + db_close(dbio); + opened = 0; +} diff --git a/contrib/global/lib/strmake.h b/contrib/global/lib/lookup.h index 3558c55149722..037102f53600b 100644 --- a/contrib/global/lib/strmake.h +++ b/contrib/global/lib/lookup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,12 +28,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * strmake.h 17-Apr-98 + * lookup.h 16-Oct-97 * */ -#ifndef _STRMAKE_H_ -#define _STRMAKE_H_ +#ifndef _LOOKUP_H_ +#define _LOOKUP_H_ #ifndef __P #if defined(__STDC__) @@ -43,6 +43,8 @@ #endif #endif -char *strmake __P((const char *, const char *)); +void lookupopen __P((char *)); +int lookup __P((char *)); +void lookupclose __P((void)); -#endif /* ! _STRMAKE_H_ */ +#endif /* ! _LOOKUP_H_ */ diff --git a/contrib/global/lib/makepath.c b/contrib/global/lib/makepath.c index 26de06532454d..7efba18dd293b 100644 --- a/contrib/global/lib/makepath.c +++ b/contrib/global/lib/makepath.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,16 +28,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * makepath.c 15-May-98 + * makepath.c 20-Oct-97 * */ #include <string.h> #include <sys/param.h> -#include "die.h" #include "makepath.h" -#include "strbuf.h" - -static STRBUF *sb; /* * makepath: make path from directory and file. * @@ -47,21 +43,16 @@ static STRBUF *sb; */ char * makepath(dir, file) -const char *dir; -const char *file; +char *dir; +char *file; { - int length; + static char path[MAXPATHLEN+1]; + char *p; - if (sb == NULL) - sb = stropen(); - strstart(sb); - if ((length = strlen(dir)) > MAXPATHLEN) - die1("path name too long. '%s'\n", dir); - strputs(sb, dir); - strunputc(sb, '/'); - strputc(sb, '/'); - strputs(sb, file); - if ((length = strlen(strvalue(sb))) > MAXPATHLEN) - die1("path name too long. '%s'\n", dir); - return strvalue(sb); + strcpy(path, dir); + p = path + strlen(path); + if (*(p - 1) != '/') + *p++ = '/'; + strcpy(p, file); + return path; } diff --git a/contrib/global/lib/makepath.h b/contrib/global/lib/makepath.h index 74b1c16f76209..47d292d482dc3 100644 --- a/contrib/global/lib/makepath.h +++ b/contrib/global/lib/makepath.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,6 @@ #endif #endif -char *makepath __P((const char *, const char *)); +char *makepath __P((char *, char *)); #endif /* ! _MAKEPATH_H_ */ diff --git a/contrib/global/lib/mgets.c b/contrib/global/lib/mgets.c index 6b9bb731f70c4..b30cae643936b 100644 --- a/contrib/global/lib/mgets.c +++ b/contrib/global/lib/mgets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,20 +28,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * mgets.c 29-Aug-98 + * mgets.c 8-Nov-97 * */ -#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "die.h" #include "mgets.h" +#include "die.h" -#define EXPANDSIZE 127 -#define MINSIZE 16 - +#define EXPANDSIZE 512 static int mbufsize = EXPANDSIZE; static char *mbuf; @@ -49,21 +46,20 @@ static char *mbuf; * mgets: read whole record into allocated buffer * * i) ip input stream - * o) length record length * i) flags flags - * MGETS_CONT \\ + \n -> '' + * MGETS_CONT \\ + \n -> \n * MGETS_SKIPCOM skip line which start with '#'. - * MGETS_TAILCUT remove following blanks + * o) length length of record * r) record buffer (NULL at end of file) * * Returned buffer has whole record. * The buffer end with '\0' and doesn't include '\r' and '\n'. */ char * -mgets(ip, length, flags) +mgets(ip, flags, length) FILE *ip; -int *length; int flags; +int *length; { char *p; @@ -77,33 +73,27 @@ int flags; * read whole record. */ if (!fgets(mbuf, mbufsize, ip)) - return NULL; + return (char *)0; if (flags & MGETS_SKIPCOM) while (*mbuf == '#') if (!fgets(mbuf, mbufsize, ip)) - return NULL; + return (char *)0; p = mbuf + strlen(mbuf); - for (;;) { /* * get a line. */ while (*(p - 1) != '\n') { /* - * expand buffer and read additionally. + * expand and read additionally. */ int count = p - mbuf; - - if (mbufsize - count < MINSIZE) { - mbufsize += EXPANDSIZE; - if (!(mbuf = (char *)realloc(mbuf, mbufsize + 1))) - die("short of memory."); - p = mbuf + count; - } - if (!fgets(p, mbufsize - count, ip)) { - *p++ = '\n'; - break; - } + mbufsize += EXPANDSIZE; + if (!(mbuf = (char *)realloc(mbuf, mbufsize + 1))) + die("short of memory."); + p = mbuf + count; + if (!fgets(p, mbufsize - count, ip)) + die("illegal end of file."); p += strlen(p); } /* @@ -120,17 +110,6 @@ int flags; else break; } -/* - if (flags & MGETS_SKIPCOM) - for (p = mbuf; *p; p++) - if (*p == '#') { - *p = 0; - break; - } -*/ - if (flags & MGETS_TAILCUT) - while (isspace(*(--p))) - *p = 0; if (length) *length = p - mbuf; return mbuf; diff --git a/contrib/global/lib/mgets.h b/contrib/global/lib/mgets.h index 75b5e831268f2..ea3aef2fa8d82 100644 --- a/contrib/global/lib/mgets.h +++ b/contrib/global/lib/mgets.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redilogibution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,7 +37,6 @@ #include <stdio.h> #define MGETS_CONT 1 #define MGETS_SKIPCOM 2 -#define MGETS_TAILCUT 4 #ifndef __P #if defined(__STDC__) @@ -47,6 +46,6 @@ #endif #endif -char *mgets __P((FILE *, int *, int)); +char *mgets __P((FILE *, int, int *)); #endif /* ! _MGETS_H_ */ diff --git a/contrib/global/lib/pathop.c b/contrib/global/lib/pathop.c deleted file mode 100644 index 2eb9e6982675a..0000000000000 --- a/contrib/global/lib/pathop.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * pathop.c 12-Nov-98 - * - */ -#include <assert.h> -#include <stdlib.h> -#include <string.h> - -#include "die.h" -#include "dbop.h" -#include "makepath.h" -#include "pathop.h" - -static DBOP *dbop; -static const char *gpath = "GPATH"; -static int _nextkey; -static int _mode; -static int opened; -static int created; - -/* - * pathopen: open path dictionary tag. - * - * i) mode 0: read only - * 1: create - * 2: modify - * r) 0: normal - * -1: error - */ -int -pathopen(dbpath, mode) -char *dbpath; -int mode; -{ - char *p; - - assert(opened == 0); - /* - * We create GPATH just first time. - */ - _mode = mode; - if (mode == 1 && created) - mode = 0; - dbop = dbop_open(makepath(dbpath, gpath), mode, 0644, 0); - if (dbop == NULL) - return -1; - if (mode == 1) - _nextkey = 0; - else { - if (!(p = dbop_get(dbop, NEXTKEY))) - die("nextkey not found in GPATH."); - _nextkey = atoi(p); - } - opened = 1; - return 0; -} -void -pathput(path) -char *path; -{ - char buf[10]; - - assert(opened == 1); - if (_mode == 1 && created) - return; - if (dbop_get(dbop, path) != NULL) - return; - sprintf(buf, "%d", _nextkey++); - dbop_put(dbop, path, buf); - dbop_put(dbop, buf, path); -} -char * -pathget(key) -char *key; -{ - assert(opened == 1); - return dbop_get(dbop, key); -} -char * -pathiget(n) -int n; -{ - char key[80]; - assert(opened == 1); - sprintf(key, "%d", n); - return dbop_get(dbop, key); -} -void -pathdel(key) -char *key; -{ - char *d; - - assert(opened == 1); - assert(_mode == 2); - assert(key[0] == '.' && key[1] == '/'); - d = dbop_get(dbop, key); - if (d == NULL) - return; - dbop_del(dbop, d); - dbop_del(dbop, key); -} -int -nextkey(void) -{ - assert(_mode != 1); - return _nextkey; -} -void -pathclose(void) -{ - char buf[10]; - - assert(opened == 1); - opened = 0; - if (_mode == 1 && created) { - dbop_close(dbop); - return; - } - sprintf(buf, "%d", _nextkey); - if (_mode == 1 || _mode == 2) - dbop_put(dbop, NEXTKEY, buf); - dbop_close(dbop); - if (_mode == 1) - created = 1; -} diff --git a/contrib/global/lib/pathop.h b/contrib/global/lib/pathop.h deleted file mode 100644 index 5bfef5dbaf55c..0000000000000 --- a/contrib/global/lib/pathop.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * pathop.h 14-May-98 - * - */ - -#ifndef _PATHOP_H_ -#define _PATHOP_H_ -#include <stdio.h> -#include "dbop.h" -#include "gparam.h" - -#define NEXTKEY " __.NEXTKEY" - -#ifndef __P -#if defined(__STDC__) -#define __P(protos) protos -#else -#define __P(protos) () -#endif -#endif - -int pathopen __P((char *, int)); -char *pathget __P((char *)); -char *pathiget __P((int)); -void pathput __P((char *)); -void pathdel __P((char *)); -void pathclose __P((void)); -int nextkey __P((void)); - -#endif /* ! _PATHOP_H_ */ diff --git a/contrib/global/lib/strbuf.h b/contrib/global/lib/strbuf.h deleted file mode 100644 index e62c7ab3e0344..0000000000000 --- a/contrib/global/lib/strbuf.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * strbuf.h 5-Jul-98 - * - */ - -#ifndef _STRBUF_H -#define _STRBUF_H - -#include <string.h> -#define INITIALSIZE 80 -#define EXPANDSIZE 80 - -typedef struct { - char *sbuf; - char *endp; - char *curp; - int sbufsize; -} STRBUF; - -#define strputc(sb,c) do {\ - if (sb->curp + 1 > sb->endp)\ - expandbuf(sb, 0);\ - *sb->curp++ = c;\ -} while (0) -#define strunputc(sb,c) do {\ - if (sb->curp > sb->sbuf && *(sb->curp - 1) == c)\ - sb->curp--;\ -} while (0) -#define strnputs(sb, s, len) do {\ - unsigned int _length = len;\ - if (sb->curp + _length > sb->endp)\ - expandbuf(sb, _length);\ - strncpy(sb->curp, s, _length);\ - sb->curp += _length;\ -} while (0) -#define strputs(sb, s) strnputs(sb, s, strlen(s)) - -#ifndef __P -#if defined(__STDC__) -#define __P(protos) protos -#else -#define __P(protos) () -#endif -#endif - -void expandbuf __P((STRBUF *, int)); -STRBUF *stropen __P((void)); -void strstart __P((STRBUF *)); -int strbuflen __P((STRBUF *)); -char *strvalue __P((STRBUF *)); -void strclose __P((STRBUF *)); - -#endif /* ! _STRBUF_H */ diff --git a/contrib/global/lib/defined.c b/contrib/global/lib/strop.c index 1e72b46c05dd3..b024abca8371f 100644 --- a/contrib/global/lib/defined.c +++ b/contrib/global/lib/strop.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,39 +28,94 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * defined.c 12-Nov-98 + * strop.c 20-Oct-97 * */ #include <stdlib.h> +#include <string.h> #include "die.h" -#include "dbop.h" -#include "defined.h" -#include "makepath.h" - -static DBOP *dbop = NULL; +#include "strop.h" /* - * Tag command that supports referenced tag must call this function - * to decide whether or not the tag is defined. + * usage: string buffer + * + * stropen(); + * for (s = string; *s; s++) + * strputc(*s); + * s = strclose(); */ -int -defined(name) -const char *name; +#define EXPANDSIZE 80 +static char *sbuf; +static char *endp; +static char *curp; +static int sbufsize; +static int opened; + +void +stropen(void) +{ + if (opened) + die("nested call to stropen."); + opened = 1; + /* + * allocate initial buffer. + */ + if (!sbuf) + if (!(sbuf = (char *)malloc(sbufsize + 1))) + die("short of memory."); + curp = sbuf; + endp = sbuf + sbufsize; + *curp = 0; +} +void +strputs(s) +char *s; +{ + int length = strlen(s); + + strnputs(s, length); +} +void +strnputs(s, length) +char *s; +int length; { - if (dbop == NULL) { - const char *dbpath; + if (curp + length > endp) { + int count = curp - sbuf; - /* - * gtags(1) set GTAGSDBPATH to the path GTAGS exist. - */ - if (!(dbpath = getenv("GTAGSDBPATH"))) - dbpath = "."; - dbop = dbop_open(makepath(dbpath, "GTAGS"), 0, 0, 0); - if (dbop == NULL) - die1("GTAGS not found. (%s)", makepath(dbpath, "GTAGS")); + sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE; + if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1))) + die("short of memory."); + curp = sbuf + count; + endp = sbuf + sbufsize; } - if (dbop_get(dbop, name)) - return 1; - return 0; + strncpy(curp, s, length); + curp += length; + *curp = 0; +} +void +strputc(c) +int c; +{ + if (curp + 1 > endp) { + int count = curp - sbuf; + + sbufsize += EXPANDSIZE; + if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1))) + die("short of memory."); + curp = sbuf + count; + endp = sbuf + sbufsize; + } + *curp++ = c; + *curp = 0; +} +char * +strclose(void) +{ + opened = 0; + /* + * doesn't free area in current implementation. + */ + return sbuf; } diff --git a/contrib/global/lib/conf.h b/contrib/global/lib/strop.h index 9317d9ff8726b..9289566d00973 100644 --- a/contrib/global/lib/conf.h +++ b/contrib/global/lib/strop.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,14 +28,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * conf.h 16-Oct-97 + * strop.h 16-Oct-97 * */ -#ifndef _CONF_H_ -#define _CONF_H_ +#ifndef _STROP_H_ +#define _STROP_H_ -#include "strbuf.h" #ifndef __P #if defined(__STDC__) #define __P(protos) protos @@ -44,11 +43,10 @@ #endif #endif -char *configpath __P((void)); -void openconf __P((void)); -int getconfn __P((const char *, int *)); -int getconfs __P((const char *, STRBUF *)); -int getconfb __P((const char *)); -void closeconf __P((void)); +void stropen __P((void)); +void strputs __P((char *)); +void strnputs __P((char *, int)); +void strputc __P((int)); +char *strclose __P((void)); -#endif /* ! _CONF_H_ */ +#endif /* ! _STROP_H_ */ diff --git a/contrib/global/lib/tab.c b/contrib/global/lib/tab.c index 1a9896ff8b26a..d309386a2d411 100644 --- a/contrib/global/lib/tab.c +++ b/contrib/global/lib/tab.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,29 +28,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * tab.c 8-Oct-98 + * tab.c 20-Oct-97 * */ #include <stdio.h> #include "tab.h" -static int tabs = 8; - -#define TABPOS(i) ((i)%tabs == 0) -/* - * settabs: set default tab stop - * - * i) n tab stop - */ -void -settabs(n) -int n; -{ - if (n < 1 || n > 32) - return; - tabs = n; -} +#define TABPOS(i) ((i)%8 == 0) /* * detab: convert tabs into spaces and print * @@ -99,8 +84,7 @@ char *buf; blanks++; /* count blanks */ continue; } - /* don't convert single blank into tab */ - buf[dst++] = (blanks == 0) ? ' ' : '\t'; + buf[dst++] = '\t'; } else if (c == '\t') { while (!TABPOS(++pos)) ; @@ -113,8 +97,5 @@ char *buf; } blanks = 0; } - if (blanks > 0) - while (blanks--) - buf[dst++] = ' '; buf[dst] = 0; } diff --git a/contrib/global/lib/tab.h b/contrib/global/lib/tab.h index 6153ff186c31f..c2b5079695062 100644 --- a/contrib/global/lib/tab.h +++ b/contrib/global/lib/tab.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * tab.h 8-Oct-98 + * tab.h 16-Oct-97 * */ @@ -43,7 +43,6 @@ #endif #endif -void settabs __P((int)); void detab __P((FILE *, char *)); void entab __P((char *)); diff --git a/contrib/global/lib/usable.c b/contrib/global/lib/tag.c index af8dd0ab0fbb5..e80d634c27081 100644 --- a/contrib/global/lib/usable.c +++ b/contrib/global/lib/tag.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,43 +28,58 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * usable.c 22-Jun-98 + * tag.c 20-Oct-97 * */ -#include <assert.h> -#include <stdlib.h> +#include <ctype.h> #include <string.h> +#include "dbio.h" +#include "die.h" +#include "gtagsopen.h" #include "locatestring.h" -#include "gparam.h" -#include "makepath.h" -#include "test.h" -#include "usable.h" +#include "tab.h" +#include "tag.h" -/* - * usable: check executable or not about the command. - * - * i) command - * r) 1: executable - * 0: non executable - */ -int -usable(command) -char *command; -{ - char buf[MAXENVLEN+1], *p, *dir; - if (*command == '/' || locatestring(command, "./", MATCH_AT_FIRST) || locatestring(command, "../", MATCH_AT_FIRST)) - return test("fx", command); +static DBIO *dbio; +static int opened; + +void +tagopen(dbpath, db, mode) +char *dbpath; +int db; +int mode; +{ + if (opened) + die("nested call to tagopen."); + opened = 1; + dbio = gtagsopen(dbpath, db, mode); +} +void +tagput(entry, record) +char *entry; +char *record; +{ + entab(record); + db_put(dbio, entry, record); +} +void +tagdelete(path) +char *path; +{ + char *p; + int length = strlen(path); - strcpy(buf, getenv("PATH")); - p = buf; - while (p) { - dir = p; - if ((p = locatestring(p, ":", MATCH_FIRST)) != NULL) - *p++ = 0; - if (test("fx", makepath(dir, command))) - return 1; + for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio)) { + p = locatestring(p, "./", 0); + if (!strncmp(p, path, length) && isspace(*(p + length))) + db_del(dbio, NULL); } - return 0; +} +void +tagclose(void) +{ + db_close(dbio); + opened = 0; } diff --git a/contrib/global/lib/usable.h b/contrib/global/lib/tag.h index 647769d7ac4a1..8bac2ac2f9b64 100644 --- a/contrib/global/lib/usable.h +++ b/contrib/global/lib/tag.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,12 +28,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * usable.h 22-Jul-98 + * tag.h 16-Oct-97 * */ -#ifndef _USABLE_H_ -#define _USABLE_H_ +#ifndef _TAG_H_ +#define _TAG_H_ #ifndef __P #if defined(__STDC__) @@ -43,6 +43,9 @@ #endif #endif -int usable __P((char *)); +void tagopen __P((char *, int, int)); +void tagput __P((char *, char *)); +void tagdelete __P((char *)); +void tagclose __P((void)); -#endif /* ! _USABLE_H_ */ +#endif /* ! _TAG_H_ */ diff --git a/contrib/global/lib/test.c b/contrib/global/lib/test.c index d5c940ea294cb..a3b5966e26a44 100644 --- a/contrib/global/lib/test.c +++ b/contrib/global/lib/test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,8 +31,8 @@ * test.c 12-Dec-97 * */ -#include <sys/types.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> @@ -50,23 +50,21 @@ * "x" [ -x path ] * * i) path path - * if NULL then previous path. * r) 0: no, 1: ok * * You can specify more than one character. It assumed 'and' test. */ int test(flags, path) -const char *flags; -const char *path; +char *flags; +char *path; { - static struct stat sb; + struct stat sb; int c; - if (path != NULL) - if (stat(path, &sb) < 0) - return 0; - while ((c = *flags++) != 0) { + if (stat(path, &sb) < 0) + return 0; + while ((c = *flags++) != NULL) { switch (c) { case 'f': if (!S_ISREG(sb.st_mode)) diff --git a/contrib/global/lib/test.h b/contrib/global/lib/test.h index c44ee48bb340f..edadbdaafd7ac 100644 --- a/contrib/global/lib/test.h +++ b/contrib/global/lib/test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved. + * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,6 @@ #endif #endif -int test __P((const char *, const char *)); +int test __P((char *, char *)); #endif /* ! _TEST_H_ */ diff --git a/contrib/global/lib/token.c b/contrib/global/lib/token.c deleted file mode 100644 index 27dbe4226eefd..0000000000000 --- a/contrib/global/lib/token.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * token.c 14-Aug-98 - */ - -#include <ctype.h> -#include <stdio.h> -#include <string.h> -#include <sys/param.h> - -#include "mgets.h" -#include "token.h" - -/* - * File input method. - */ -int lineno; -char *sp, *cp, *lp; -int crflag; /* 1: return '\n', 0: doesn't return */ -int cmode; /* allow token which start with '#' */ -int ymode; /* allow token which start with '%' */ -char token[MAXTOKEN]; -char curfile[MAXPATHLEN]; - -static char ptok[MAXTOKEN]; -static int lasttok; -static FILE *ip; - -static void pushbackchar __P((void)); - -/* - * opentoken: - */ -int -opentoken(file) - char *file; -{ - if ((ip = fopen(file, "r")) == NULL) - return 0; - strcpy(curfile, file); - sp = cp = lp = NULL; lineno = 0; - return 1; -} -/* - * closetoken: - */ -void -closetoken() -{ - fclose(ip); -} - -/* - * nexttoken: get next token - * - * i) interested interested special charactor - * if NULL then all charactor. - * i) reserved converter from token to token number - * if this is specified, nexttoken() return - * word number, else return symbol. - * r) EOF(-1) end of file - * ==0 symbol ('tok' has the value.) - * > 255 reserved word - * <=255 interested special charactor - * - * nexttoken() doesn't return followings. - * - * o comment - * o space (' ', '\t', '\f') - * o quoted string ("...", '.') - */ - -int -nexttoken(interested, reserved) - const char *interested; - int (*reserved)(char *); -{ - int c; - char *p; - int sharp = 0; - int percent = 0; - - /* check push back buffer */ - if (ptok[0]) { - strcpy(token, ptok); - ptok[0] = 0; - return lasttok; - } - - for (;;) { - /* skip spaces */ - if (!crflag) - while ((c = nextchar()) != EOF && isspace(c)) - ; - else - while ((c = nextchar()) != EOF && (c == ' ' || c == '\t' || c == '\f')) - ; - if (c == EOF || c == '\n') - break; - - if (c == '"' || c == '\'') { /* quoted string */ - int quote = c; - - while ((c = nextchar()) != EOF) { - if (c == quote) - break; - if (quote == '\'' && c == '\n') - break; - if (c == '\\' && (c = nextchar()) == EOF) - break; - } - } else if (c == '/') { /* comment */ - if ((c = nextchar()) == '/') { - while ((c = nextchar()) != EOF) - if (c == '\n') - break; - } else if (c == '*') { - while ((c = nextchar()) != EOF) { - if (c == '*') { - if ((c = nextchar()) == '/') - break; - pushbackchar(); - } - } - } else - pushbackchar(); - } else if (c == '\\') { - (void)nextchar(); - } else if (isdigit(c)) { /* digit */ - while ((c = nextchar()) != EOF && (c == '.' || isdigit(c) || isalpha(c))) - ; - pushbackchar(); - } else if (c == '#' && cmode) { - /* recognize '##' as a token if it is reserved word. */ - if (peekc(1) == '#') { - p = token; - *p++ = c; - *p++ = nextchar(); - *p = 0; - if (reserved && (c = (*reserved)(token)) == 0) - break; - } else if (atfirst_exceptspace()) { - sharp = 1; - continue; - } - } else if (c == '%' && ymode) { - /* recognize '%%' as a token if it is reserved word. */ - if (atfirst) { - p = token; - *p++ = c; - if ((c = peekc(1)) == '%' || c == '{' || c == '}') { - *p++ = nextchar(); - *p = 0; - if (reserved && (c = (*reserved)(token)) != 0) - break; - } else if (!isspace(c)) { - percent = 1; - continue; - } - } - } else if (c & 0x80 || isalpha(c) || c == '_') {/* symbol */ - p = token; - if (sharp) { - sharp = 0; - *p++ = '#'; - } else if (percent) { - percent = 0; - *p++ = '%'; - } - for (*p++ = c; (c = nextchar()) != EOF && (c & 0x80 || isalnum(c) || c == '_'); *p++ = c) - ; - *p = 0; - if (c != EOF) - pushbackchar(); - /* convert token string into token number */ - if (reserved) - c = (*reserved)(token); - break; - } else { /* special char */ - if (interested == NULL || strchr(interested, c)) - break; - /* otherwise ignore it */ - } - sharp = percent = 0; - } - return lasttok = c; -} -/* - * pushbacktoken: push back token - * - * following nexttoken() return same token again. - */ -void -pushbacktoken() -{ - strcpy(ptok, token); -} -/* - * peekc: peek next char - * - * i) immediate 0: ignore blank, 1: include blank - * - * Peekc() read ahead following blanks but doesn't chage line. - */ -int -peekc(immediate) - int immediate; -{ - int c; - long pos; - - if (cp != NULL) { - if (immediate) - c = nextchar(); - else - while ((c = nextchar()) != EOF && c != '\n' && isspace(c)) - ; - if (c != EOF) - pushbackchar(); - if (c != '\n' || immediate) - return c; - } - pos = ftell(ip); - if (immediate) - c = getc(ip); - else - while ((c = getc(ip)) != EOF && isspace(c)) - ; - (void)fseek(ip, pos, SEEK_SET); - - return c; -} -/* - * atfirst_exceptspace: return if current position is the first column - * except for space. - * | 1 0 - * | v v - * | # define - */ -int -atfirst_exceptspace() -{ - char *start = sp; - char *end = cp ? cp - 1 : lp; - - while (start < end && *start && isspace(*start)) - start++; - return (start == end) ? 1 : 0; -} -/* - * pushbackchar: push back charactor. - * - * following nextchar() return same charactor again. - * - */ -static void -pushbackchar() -{ - if (sp == NULL) - return; /* nothing to do */ - if (cp == NULL) - cp = lp; - else - --cp; -} diff --git a/contrib/global/lib/token.h b/contrib/global/lib/token.h deleted file mode 100644 index 571b8505c88dd..0000000000000 --- a/contrib/global/lib/token.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Shigio Yamaguchi. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * token.h 14-Aug-98 - */ - -#ifndef _TOKEN_H_ -#define _TOKEN_H_ - -#include <sys/param.h> -#include "mgets.h" -#define MAXTOKEN 512 -#define SYMBOL 0 - -extern char *sp, *cp, *lp; -extern int lineno; -extern int crflag; -extern int cmode; -extern int ymode; -extern char token[MAXTOKEN]; -extern char curfile[MAXPATHLEN]; - -#define nextchar() \ - (cp == NULL ? \ - ((sp = cp = mgets(ip, NULL, 0)) == NULL ? \ - EOF : \ - (lineno++, *cp == 0 ? \ - lp = cp, cp = NULL, '\n' : \ - *cp++)) : \ - (*cp == 0 ? (lp = cp, cp = NULL, '\n') : *cp++)) -#define atfirst (sp && sp == (cp ? cp - 1 : lp)) - -#ifndef __P -#if defined(__STDC__) -#define __P(protos) protos -#else -#define __P(protos) () -#endif -#endif - -int opentoken __P((char *)); -void closetoken __P((void)); -int nexttoken __P((const char *, int (*)(char *))); -void pushbacktoken __P((void)); -int peekc __P((int)); -int atfirst_exceptspace __P((void)); - -#endif /* ! _TOKEN_H_ */ |