diff options
Diffstat (limited to 'contrib/global/lib')
31 files changed, 2321 insertions, 0 deletions
diff --git a/contrib/global/lib/Makefile b/contrib/global/lib/Makefile new file mode 100644 index 0000000..99d49ef --- /dev/null +++ b/contrib/global/lib/Makefile @@ -0,0 +1,8 @@ +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/Makefile.generic b/contrib/global/lib/Makefile.generic new file mode 100644 index 0000000..2cd87fb --- /dev/null +++ b/contrib/global/lib/Makefile.generic @@ -0,0 +1,14 @@ +LIB = libutil.a +CC = gcc +AR = ar +CFLAGS = -O -I../lib -I/usr/include/db +OBJS = 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 +all: $(LIB) + +$(LIB): $(OBJS) + $(AR) cq $(LIB) $(OBJS) +install: + @echo -n +clean: + rm -f $(LIB) $(OBJS) diff --git a/contrib/global/lib/dbio.c b/contrib/global/lib/dbio.c new file mode 100644 index 0000000..c569782 --- /dev/null +++ b/contrib/global/lib/dbio.c @@ -0,0 +1,322 @@ +/* + * 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 <stdlib.h> +#include <fcntl.h> +#include "dbio.h" +#include "die.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/dbio.h b/contrib/global/lib/dbio.h new file mode 100644 index 0000000..bc0abf4 --- /dev/null +++ b/contrib/global/lib/dbio.h @@ -0,0 +1,89 @@ +/* + * 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.h 14-Dec-97 + * + */ +#ifndef _DBIO_H_ +#define _DBIO_H_ + +#include <db.h> +#include <sys/param.h> + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +#define MAXKEYLEN 300 + +typedef struct { + DB *db; /* descripter of DB */ + char dbname[MAXPATHLEN+1]; /* dbname */ + char key[MAXKEYLEN+1]; /* key */ + int keylen; /* key length */ + 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 db_open() */ + int ioflags; /* flags of db_first() */ + int perm; /* file permission */ +} DBIO; + +/* + * openflags + */ +#define DBIO_DUP 1 /* allow duplicate records */ +#define DBIO_REMOVE 2 /* remove file when closed */ +/* + * ioflags + */ +#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__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +DBIO *db_open __P((char *, int, int, int)); +char *db_get __P((DBIO *, char *)); +void db_put __P((DBIO *, char *, char *)); +void de_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/dbname.c b/contrib/global/lib/dbname.c new file mode 100644 index 0000000..1e68b3a --- /dev/null +++ b/contrib/global/lib/dbname.c @@ -0,0 +1,48 @@ +/* + * 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. + * + * dbname.c 20-Oct-97 + * + */ +#include "dbname.h" + +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; +{ + return tagslist[db]; +} diff --git a/contrib/global/lib/dbname.h b/contrib/global/lib/dbname.h new file mode 100644 index 0000000..17eba36 --- /dev/null +++ b/contrib/global/lib/dbname.h @@ -0,0 +1,53 @@ +/* + * 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. + * + * dbname.h 16-Oct-97 + * + */ + +#ifndef _DBNAME_H_ +#define _DBNAME_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +#define GTAGS 0 +#define GRTAGS 1 +#define GSYMS 2 +#define GTAGLIM 3 + +char *dbname __P((int)); + +#endif /* ! _DBNAME_H_ */ diff --git a/contrib/global/lib/die.h b/contrib/global/lib/die.h new file mode 100644 index 0000000..46813d4 --- /dev/null +++ b/contrib/global/lib/die.h @@ -0,0 +1,49 @@ +/* + * 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. + * + * die.h 16-Oct-97 + * + */ +#ifndef _DIE_H_ +#define _DIE_H_ +#include <stdio.h> + +extern char *progname; + +#define die(a) fprintf(stderr, "%s: ", progname),\ + fprintf(stderr, a),\ + fputs("\n", stderr),\ + exit(1) + +#define die1(a,b) fprintf(stderr, "%s: ", progname),\ + fprintf(stderr, a, b),\ + fputs("\n", stderr),\ + exit(1) +#endif /* ! _DIE_H_ */ diff --git a/contrib/global/lib/find.c b/contrib/global/lib/find.c new file mode 100644 index 0000000..fd3537c --- /dev/null +++ b/contrib/global/lib/find.c @@ -0,0 +1,165 @@ +/* + * 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. + * + * find.c 20-Oct-97 + * + */ +#include <stdio.h> +#include <sys/types.h> +#include <regex.h> +#include <sys/param.h> +#include "gparam.h" +#include "find.h" +#include "die.h" +#include "locatestring.h" + +/* + * usage of findxxx() + * + * 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; +static FILE *ip; +static int opened; + +int +issource(path) +char *path; +{ + char c, *p, *q; + + 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; + } + return 0; +} + +void +findopen() +{ + char edit[512], *p, *q; + int i, lim; + + if (opened) + die("nested call to findopen."); + opened = 1; + 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); + } + sprintf(p, " \\) -print"); + if (sizeof(skippath) != 0) { + int i, lim = sizeof(skippath)/sizeof(char *); + /* + * construct regular expression. + */ + p = edit; + *p++ = '('; + for (i = 0; i < lim; i++) { + *p++ = '/'; + for (q = skippath[i]; *q; q++) { + if (*q == '.') + *p++ = '\\'; + *p++ = *q; + } + if (*(q - 1) != '/') + *p++ = '$'; + *p++ = '|'; + } + *(p - 1) = ')'; + *p = 0; + /* + * compile regular expression. + */ + skip = &skip_area; + if (regcomp(skip, edit, REG_EXTENDED|REG_NEWLINE) != 0) + die("cannot compile regular expression."); + } else { + skip = (regex_t *)0; + } + if (!(ip = popen(findcom, "r"))) + die("cannot execute find."); +} +char * +findread(length) +int *length; +{ + static char path[MAXPATHLEN+1]; + char *p; + + while (fgets(path, MAXPATHLEN, ip)) { + if (!skip || regexec(skip, path, 0, 0, 0) != 0) { + p = path + strlen(path) - 1; + if (*p != '\n') + die("output of find(1) is wrong (findread)."); + *p = 0; + if (length) + *length = p - path; + return path; + } + } + return (char *)0; +} +void +findclose() +{ + pclose(ip); + opened = 0; +} diff --git a/contrib/global/lib/find.h b/contrib/global/lib/find.h new file mode 100644 index 0000000..c745a19 --- /dev/null +++ b/contrib/global/lib/find.h @@ -0,0 +1,51 @@ +/* + * 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. + * + * find.h 16-Oct-97 + * + */ + +#ifndef _FIND_H_ +#define _FIND_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +int issource __P((char *)); +void findopen __P(()); +char *findread __P((int *)); +void findclose __P(()); + +#endif /* ! _FIND_H_ */ diff --git a/contrib/global/lib/getdbpath.c b/contrib/global/lib/getdbpath.c new file mode 100644 index 0000000..9c689da --- /dev/null +++ b/contrib/global/lib/getdbpath.c @@ -0,0 +1,154 @@ +/* + * 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. + * + * getdbpath.c 20-Oct-97 + * + */ +#include <sys/param.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdlib.h> +#include "die.h" +#include "locatestring.h" + +static char *makeobjdirprefix; /* obj partition */ +static char *makeobjdir; /* obj directory */ +static int bsd; /* if BSD */ + +/* + * gtagsexist: test whether GTAGS's existence. + * + * i) candidate candidate root directory + * o) dbpath directory which GTAGS exist + * r) 0: not found, 1: found + */ +int +gtagsexist(candidate, dbpath) +char *candidate; +char *dbpath; +{ + char path[MAXPATHLEN+1]; + + sprintf(path, "%s/GTAGS", candidate); + if (test("fr", path)) { + strcpy(dbpath, 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; +} +/* + * getdbpath: get dbpath directory + * + * o) cwd current directory + * o) root root of source tree + * o) dbpath directory which GTAGS exist + * + * root and dbpath assumed as + * char cwd[MAXPATHLEN+1]; + * char root[MAXPATHLEN+1]; + * char dbpath[MAXPATHLEN+1]; + */ +void +getdbpath(cwd, root, dbpath) +char *cwd; +char *root; +char *dbpath; +{ + struct stat sb; + char *p; + + if (!getcwd(cwd, MAXPATHLEN)) + die("cannot get current directory."); + /* + * GLOBAL never think '/' is the root of source tree. + */ + if (!strcmp(cwd, "/")) + die("It's root directory! What are you doing?"); + + if (getenv("OSTYPE") && locatestring(getenv("OSTYPE"), "BSD", 0)) { + if (p = getenv("MAKEOBJDIRPREFIX")) + makeobjdirprefix = p; + else + makeobjdirprefix = "/usr/obj"; + if (p = getenv("MAKEOBJDIR")) + makeobjdir = p; + else + makeobjdir = "obj"; + bsd = 1; + } + + if (p = getenv("GTAGSROOT")) { + if (*p != '/') + die("GTAGSROOT must be an absolute path."); + if (stat(p, &sb) || !S_ISDIR(sb.st_mode)) + die1("directory '%s' not found.", p); + strcpy(root, p); + /* + * GTAGSDBPATH is meaningful only when GTAGSROOT exist. + */ + if (p = getenv("GTAGSDBPATH")) { + if (*p != '/') + die("GTAGSDBPATH must be an absolute path."); + if (stat(p, &sb) || !S_ISDIR(sb.st_mode)) + die1("directory '%s' not found.", p); + strcpy(dbpath, getenv("GTAGSDBPATH")); + } else { + if (!gtagsexist(root, dbpath)) + die("GTAGS not found."); + } + } else { + /* + * start from current directory to '/' directory. + */ + strcpy(root, cwd); + p = root + strlen(root); + while (!gtagsexist(root, dbpath)) { + while (*--p != '/') + ; + *p = 0; + if (root == p) /* reached root directory */ + break; + } + if (*root == 0) + die("GTAGS not found."); + } +} diff --git a/contrib/global/lib/getdbpath.h b/contrib/global/lib/getdbpath.h new file mode 100644 index 0000000..193dfff --- /dev/null +++ b/contrib/global/lib/getdbpath.h @@ -0,0 +1,49 @@ +/* + * 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. + * + * getdbpath.h 16-Oct-97 + * + */ + +#ifndef _GETDBPATH_H_ +#define _GETDBPATH_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +int gtagsexist __P((char *, char *)); +void getdbpath __P((char *, char *, char *)); + +#endif /* ! _GETDBPATH_H_ */ diff --git a/contrib/global/lib/global.h b/contrib/global/lib/global.h new file mode 100644 index 0000000..7fbc2b8 --- /dev/null +++ b/contrib/global/lib/global.h @@ -0,0 +1,54 @@ +/* + * 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. + * + * global.h 16-Oct-97 + * + */ + +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + +#include "gparam.h" +#include "dbname.h" +#include "makepath.h" +#include "dbio.h" +#include "locatestring.h" +#include "mgets.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" + +#endif /* ! _GLOBAL_H_ */ diff --git a/contrib/global/lib/gparam.h b/contrib/global/lib/gparam.h new file mode 100644 index 0000000..8a506c4 --- /dev/null +++ b/contrib/global/lib/gparam.h @@ -0,0 +1,42 @@ +/* + * 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. + * + * gparam.h 16-Oct-97 + * + */ +#ifndef _GPARAM_H_ +#define _GPARAM_H_ + +#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/gtagsopen.c b/contrib/global/lib/gtagsopen.c new file mode 100644 index 0000000..2331c4b --- /dev/null +++ b/contrib/global/lib/gtagsopen.c @@ -0,0 +1,95 @@ +/* + * 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.c 20-Oct-97 + * + */ +#include <sys/param.h> +#include <fcntl.h> +#include <db.h> +#include "dbio.h" +#include "die.h" +#include "makepath.h" +#include "dbname.h" + +#define VERSIONKEY " __.VERSION" +static int support_version = 1; /* accept this format version */ + +/* + * gtagsopen: open global database. + * + * i) dbpath dbpath directory + * i) db GTAGS, GRTAGS, GSYMS + * i) mode 0: read only + * 1: write only + * 2: read and write + * r) DB structure + * + * when error occurred, gtagopen doesn't return. + */ +DBIO * +gtagsopen(dbpath, db, mode) +char *dbpath; +int db; +int mode; +{ + 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)) { + 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 0000000..2afb2ab --- /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 new file mode 100644 index 0000000..f2aeecf --- /dev/null +++ b/contrib/global/lib/locatestring.c @@ -0,0 +1,70 @@ +/* + * 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. + * + * locatestring.c 20-Oct-97 + * + */ +/* + * locatestring: locate pattern from string + * + * i) string string + * i) pattern pattern + * 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) +char *string; +char *pattern; +int flag; +{ + int c = *pattern; + char *p = (char *)0; + + if (flag == 3 && strlen(string) > strlen(pattern)) { + string += strlen(string) - strlen(pattern); + } + for (; *string; string++) { + if (*string == c) + if (!strncmp(string, pattern, strlen(pattern))) { + p = string; + if (flag == 0) + break; + } + if (flag == 1 || flag == 3) + break; + } + return p; +} diff --git a/contrib/global/lib/locatestring.h b/contrib/global/lib/locatestring.h new file mode 100644 index 0000000..cdaeedb --- /dev/null +++ b/contrib/global/lib/locatestring.h @@ -0,0 +1,48 @@ +/* + * 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. + * + * locatestring.h 16-Oct-97 + * + */ + +#ifndef _LOCATESTRING_H_ +#define _LOCATESTRING_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +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 0000000..0583d6b --- /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() +{ + db_close(dbio); + opened = 0; +} diff --git a/contrib/global/lib/lookup.h b/contrib/global/lib/lookup.h new file mode 100644 index 0000000..cfe8c8e --- /dev/null +++ b/contrib/global/lib/lookup.h @@ -0,0 +1,50 @@ +/* + * 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.h 16-Oct-97 + * + */ + +#ifndef _LOOKUP_H_ +#define _LOOKUP_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +void lookupopen __P((char *)); +int lookup __P((char *)); +void lookupclose __P(()); + +#endif /* ! _LOOKUP_H_ */ diff --git a/contrib/global/lib/makepath.c b/contrib/global/lib/makepath.c new file mode 100644 index 0000000..ba00ecf --- /dev/null +++ b/contrib/global/lib/makepath.c @@ -0,0 +1,57 @@ +/* + * 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. + * + * makepath.c 20-Oct-97 + * + */ +#include <sys/param.h> +#include "makepath.h" +/* + * makepath: make path from directory and file. + * + * i) dir directory + * i) file file + * r) path + */ +char * +makepath(dir, file) +char *dir; +char *file; +{ + static char path[MAXPATHLEN+1]; + char *p; + + 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 new file mode 100644 index 0000000..47d292d --- /dev/null +++ b/contrib/global/lib/makepath.h @@ -0,0 +1,48 @@ +/* + * 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. + * + * makepath.h 16-Oct-97 + * + */ + +#ifndef _MAKEPATH_H_ +#define _MAKEPATH_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +char *makepath __P((char *, char *)); + +#endif /* ! _MAKEPATH_H_ */ diff --git a/contrib/global/lib/mgets.c b/contrib/global/lib/mgets.c new file mode 100644 index 0000000..880338e --- /dev/null +++ b/contrib/global/lib/mgets.c @@ -0,0 +1,113 @@ +/* + * 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. + * + * mgets.c 8-Nov-97 + * + */ +#include <stdio.h> +#include "mgets.h" +#include "die.h" + +#define EXPANDSIZE 512 +static int mbufsize = EXPANDSIZE; +static char *mbuf; + +/* + * mgets: read whole record into allocated buffer + * + * i) ip input stream + * i) flags flags + * MGETS_CONT \\ + \n -> \n + * MGETS_SKIPCOM skip line which start with '#'. + * 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, flags, length) +FILE *ip; +int flags; +int *length; +{ + char *p; + + /* + * allocate initial buffer. + */ + if (!mbuf) + if (!(mbuf = (char *)malloc(mbufsize + 1))) + die("short of memory."); + /* + * read whole record. + */ + if (!fgets(mbuf, mbufsize, ip)) + return (char *)0; + if (flags & MGETS_SKIPCOM) + while (*mbuf == '#') + if (!fgets(mbuf, mbufsize, ip)) + return (char *)0; + p = mbuf + strlen(mbuf); + for (;;) { + /* + * get a line. + */ + while (*(p - 1) != '\n') { + /* + * expand and read additionally. + */ + int count = p - mbuf; + 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); + } + /* + * chop(mbuf) + */ + *(--p) = 0; + if (*(p - 1) == '\r') + *(--p) = 0; + /* + * continue? + */ + if ((flags & MGETS_CONT) && *(p - 1) == '\\') + *(--p) = 0; + else + break; + } + if (length) + *length = p - mbuf; + return mbuf; +} diff --git a/contrib/global/lib/mgets.h b/contrib/global/lib/mgets.h new file mode 100644 index 0000000..ea3aef2 --- /dev/null +++ b/contrib/global/lib/mgets.h @@ -0,0 +1,51 @@ +/* + * 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. + * + * mgets.h 20-Oct-97 + * + */ +#ifndef _MGETS_H_ +#define _MGETS_H_ + +#include <stdio.h> +#define MGETS_CONT 1 +#define MGETS_SKIPCOM 2 + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +char *mgets __P((FILE *, int, int *)); + +#endif /* ! _MGETS_H_ */ diff --git a/contrib/global/lib/strop.c b/contrib/global/lib/strop.c new file mode 100644 index 0000000..e15db16 --- /dev/null +++ b/contrib/global/lib/strop.c @@ -0,0 +1,117 @@ +/* + * 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. + * + * strop.c 20-Oct-97 + * + */ +#include "strop.h" +#include "die.h" +/* + * usage: string buffer + * + * stropen(); + * for (s = string; *s; s++) + * strputc(*s); + * s = strclose(); + */ +#define EXPANDSIZE 80 +static char *sbuf; +static char *endp; +static char *curp; +static int sbufsize; +static int opened; + +void +stropen() +{ + 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 (curp + length > endp) { + int count = curp - sbuf; + + sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE; + if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1))) + die("short of memory."); + curp = sbuf + count; + endp = sbuf + sbufsize; + } + 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() +{ + opened = 0; + /* + * doesn't free area in current implementation. + */ + return sbuf; +} diff --git a/contrib/global/lib/strop.h b/contrib/global/lib/strop.h new file mode 100644 index 0000000..aa9fa68 --- /dev/null +++ b/contrib/global/lib/strop.h @@ -0,0 +1,52 @@ +/* + * 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. + * + * strop.h 16-Oct-97 + * + */ + +#ifndef _STROP_H_ +#define _STROP_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +void stropen __P(()); +void strputs __P((char *)); +void strnputs __P((char *, int)); +void strputc __P((int)); +char *strclose __P(()); + +#endif /* ! _STROP_H_ */ diff --git a/contrib/global/lib/tab.c b/contrib/global/lib/tab.c new file mode 100644 index 0000000..8f5adbf --- /dev/null +++ b/contrib/global/lib/tab.c @@ -0,0 +1,99 @@ +/* + * 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. + * + * tab.c 20-Oct-97 + * + */ +#include <stdio.h> + +#define TABPOS(i) ((i)%8 == 0) +/* + * detab: convert tabs into spaces and print + * + * i) op FILE * + * i) buf string including tabs + */ +void +detab(op, buf) +FILE *op; +char *buf; +{ + int src, dst; + char c; + + src = dst = 0; + while ((c = buf[src++]) != 0) { + if (c == '\t') { + do { + (void)putc(' ', op); + dst++; + } while (!TABPOS(dst)); + } else { + (void)putc(c, op); + dst++; + } + } + (void)putc('\n', op); +} +/* + * entab: convert spaces into tabs + * + * io) buf string buffer + */ +void +entab(buf) +char *buf; +{ + int blanks = 0; + int pos, src, dst; + char c; + + pos = src = dst = 0; + while ((c = buf[src++]) != 0) { + if (c == ' ') { + if (!TABPOS(++pos)) { + blanks++; /* count blanks */ + continue; + } + buf[dst++] = '\t'; + } else if (c == '\t') { + while (!TABPOS(++pos)) + ; + buf[dst++] = '\t'; + } else { + ++pos; + while (blanks--) + buf[dst++] = ' '; + buf[dst++] = c; + } + blanks = 0; + } + buf[dst] = 0; +} diff --git a/contrib/global/lib/tab.h b/contrib/global/lib/tab.h new file mode 100644 index 0000000..c2b5079 --- /dev/null +++ b/contrib/global/lib/tab.h @@ -0,0 +1,49 @@ +/* + * 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. + * + * tab.h 16-Oct-97 + * + */ + +#ifndef _TAB +#define _TAB_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +void detab __P((FILE *, char *)); +void entab __P((char *)); + +#endif /* ! _TAB_H_ */ diff --git a/contrib/global/lib/tag.c b/contrib/global/lib/tag.c new file mode 100644 index 0000000..81d9aae --- /dev/null +++ b/contrib/global/lib/tag.c @@ -0,0 +1,80 @@ +/* + * 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. + * + * tag.c 20-Oct-97 + * + */ +#include "dbio.h" +#include "die.h" +#include "gtagsopen.h" +#include "tag.h" +#include "locatestring.h" + +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); + + 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); + } +} +void +tagclose() +{ + db_close(dbio); + opened = 0; +} diff --git a/contrib/global/lib/tag.h b/contrib/global/lib/tag.h new file mode 100644 index 0000000..b12caaa --- /dev/null +++ b/contrib/global/lib/tag.h @@ -0,0 +1,51 @@ +/* + * 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. + * + * tag.h 16-Oct-97 + * + */ + +#ifndef _TAG_H_ +#define _TAG_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +void tagopen __P((char *, int, int)); +void tagput __P((char *, char *)); +void tagdelete __P((char *)); +void tagclose __P(()); + +#endif /* ! _TAG_H_ */ diff --git a/contrib/global/lib/test.c b/contrib/global/lib/test.c new file mode 100644 index 0000000..99aae9d --- /dev/null +++ b/contrib/global/lib/test.c @@ -0,0 +1,90 @@ +/* + * 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. + * + * test.c 12-Dec-97 + * + */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +/* + * test: + * + * i) flags file flags + * + * "f" [ -f path ] + * "d" [ -d path ] + * "r" [ -r path ] + * "w" [ -w path ] + * "x" [ -x path ] + * + * i) path path + * r) 0: no, 1: ok + * + * You can specify more than one character. It assumed 'and' test. + */ +int +test(flags, path) +char *flags; +char *path; +{ + struct stat sb; + int c; + + if (stat(path, &sb) < 0) + return 0; + while (c = *flags++) { + switch (c) { + case 'f': + if (!S_ISREG(sb.st_mode)) + return 0; + break; + case 'd': + if (!S_ISDIR(sb.st_mode)) + return 0; + break; + case 'r': + if (access(path, R_OK) < 0) + return 0; + break; + case 'w': + if (access(path, W_OK) < 0) + return 0; + break; + case 'x': + if (access(path, X_OK) < 0) + return 0; + break; + default: + break; + } + } + return 1; +} diff --git a/contrib/global/lib/test.h b/contrib/global/lib/test.h new file mode 100644 index 0000000..edadbda --- /dev/null +++ b/contrib/global/lib/test.h @@ -0,0 +1,48 @@ +/* + * 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. + * + * test.h 16-Oct-97 + * + */ + +#ifndef _TEST_H_ +#define _TEST_H_ + +#ifndef __P +#if defined(__STDC__) +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +int test __P((char *, char *)); + +#endif /* ! _TEST_H_ */ |