Codebase list global / 3af3166
git-debimport global_3.54.orig.tar.gz Ron 16 years ago
147 changed file(s) with 7913 addition(s) and 1397 deletion(s). Raw diff Collapse all Expand all
1313 This software is covered by the followings:
1414
1515 Copyright (c) 1996, 1997, 1998, 1999
16 Shigio Yamaguchi. All rights reserved.
17
16 Shigio Yamaguchi. All rights reserved.
17 Copyright (c) 1999
18 Tama Communications Corporation. All rights reserved.
19
1820 Redistribution and use in source and binary forms, with or without
1921 modification, are permitted provided that the following conditions
2022 are met:
2527 documentation and/or other materials provided with the distribution.
2628 3. All advertising materials mentioning features or use of this software
2729 must display the following acknowledgement:
28 This product includes software developed by Shigio Yamaguchi.
30 This product includes software developed by Tama Communications
31 Corporation and its contributors.
2932 4. Neither the name of the author nor the names of any co-contributors
3033 may be used to endorse or promote products derived from this software
3134 without specific prior written permission.
5659 ware for any purpose. It is provided "as is" without express or implied
5760 warranty.
5861
62 -------------------------------------------------------------------------
5963 Copyright 1991 by Andreas Stolcke
6064 Copyright 1990 by Solbourne Computer Inc.
6165 Longmont, Colorado
114118 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
115119 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
116120 SUCH DAMAGE.
121
122 REGEX library:
123
124 Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
125 This software is not subject to any license of the American Telephone
126 and Telegraph Company or of the Regents of the University of California.
127
128 Permission is granted to anyone to use this software for any purpose on
129 any computer system, and to alter it and redistribute it, subject
130 to the following restrictions:
131
132 1. The author is not responsible for the consequences of use of this
133 software, no matter how awful, even if they arise from flaws in it.
134
135 2. The origin of this software must not be misrepresented, either by
136 explicit claim or by omission. Since few users ever read sources,
137 credits must appear in the documentation.
138
139 3. Altered versions must be plainly marked as such, and must not be
140 misrepresented as being the original software. Since few users
141 ever read sources, credits must appear in the documentation.
142
143 4. This notice may not be removed or altered.
144
145 -------------------------------------------------------------------------
146 Copyright (c) 1992, 1993, 1994 Henry Spencer.
147 Copyright (c) 1992, 1993, 1994
148 The Regents of the University of California. All rights reserved.
149
150 This code is derived from software contributed to Berkeley by
151 Henry Spencer.
152
153 Redistribution and use in source and binary forms, with or without
154 modification, are permitted provided that the following conditions
155 are met:
156 1. Redistributions of source code must retain the above copyright
157 notice, this list of conditions and the following disclaimer.
158 2. Redistributions in binary form must reproduce the above copyright
159 notice, this list of conditions and the following disclaimer in the
160 documentation and/or other materials provided with the distribution.
161 3. All advertising materials mentioning features or use of this software
162 must display the following acknowledgement:
163 This product includes software developed by the University of
164 California, Berkeley and its contributors.
165 4. Neither the name of the University nor the names of its contributors
166 may be used to endorse or promote products derived from this software
167 without specific prior written permission.
168
169 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
170 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
173 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
174 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
175 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
176 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
177 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
178 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
179 SUCH DAMAGE.
+20
-0
FAQ less more
5757 GRTAGS tag file with it. With the result that you cannot use htags and
5858 global's -r option.
5959 ----------------------------------------------------------------------------
60 Q4. Everything seems to be ok except the man page, the man program on my
61 machine does not understand the manual files in GLOBAL
62
63 A4. Online manuals in GLOBAL are written with 'mandoc' macro which is a part
64 of GNU groff package. You can format these manuals by following command
65 line manually.
66
67 % groff -Wall -Tascii -mandoc global.1
68
69 If you replace your system's nroff(1) with GNU's one(nroff.sh) then
70 you can use man(1) to see GLOBAL's online manuals.
71
72 ----------------------------------------------------------------------------
73 Q5. I have built GLOBAL in WIN32 environment. But gtags(1) failed by sort
74 command error.
75
76 A5. It seems that MS sort is executed. Please set your path so that unix
77 sort will be executed.
78
79 ----------------------------------------------------------------------------
513513
514514 Thanks to Bert Gijsbers for his investigation.
515515
516 ---
516517 Extended ctags has been completely replaced with new gctags.
517518 Thanks to Ken Arnold and the other people who developped BSD ctags(1).
518519 Without it, GLOBAL had never been here.
611612 global.conf
612613 - fullpath parameter added. (for htags)
613614 - normal_suffix parameter added. (for htags)
614 libdb/ - db(3) 1.85 imported to keep machine and platform independency
615 in generic make. 'dbpatches' already has been applied.
615 libdb/ - db(3) 1.85 was imported to keep machine and platform
616 independency in generic make. 'dbpatches' already has been
617 applied.
616618 gctags - NENTRY() in asemmbler source code supported. (for NetBSD)
617619 htags - --action=url, --id=id and --nocgi options added to realize
618620 a safe cgi script.
619621
620622 Thanks to Ron Lee for his design and implementation of
621 a safe cgi mechanism.
623 'a safe cgi mechanism'.
624
625 version 3.5 Support of C++, XEmacs and WIN32 ready. [23-Aug-99]
626
627 [fixed]
628 gozilla - coudn't treat old style hypertext tree.
629 gtags - corrupted database when interrupted.
630 global - -Pl '^pattern' in subdirectory didn't work.
631 libutil - mgets destroyed memory.
632
633 Thanks to IWAMURO Motonori for his bug report and fix patch.
634
635 - getdirs doesn't work when undefined USEFIND.
636
637 Thanks to Dan Fandrich for his bug report and fix patch.
638
639 gctags - core dumped on some .C or .h files.
640
641 Thanks to Yann Dirson for his bug report.
642
643 - couldn't pick up macro definition with no argment.
644
645 [added]
646 gtags, global, htags, gozilla, gtags.el
647 - C++ support added.
648 gtags, gctags, global, htags, btreeop
649 - WIN32 Borland C++ (4.5 or 5.0) support added.
650
651 Thanks to Dan Fandrich for his port.
652
653 gtags.el
654 - XEmacs support added.
655
656 Thanks to
657 Klaus Borchers
658 okabe katsuyuki
659 Toshiyasu KOJIMA
660 MORIOKA Tomohiko
661 for their advice about xemacs.
662
663 - gtags-find-file(ESC-l) command added.
664 htags - symbol search support was added with -f option.
665 global.conf
666 - quoted char '\' became available. You can use it like this.
667 '...:GTAGS=c\:/usr/bin/specialtag.exe:...'
668 - sort and sed command became parameterized.
669 gozilla - https, ftp, nntp, mailto and about protocols were added.
670 All files
671 - copyright notice of Tama Communications Corporation.
672 gctags/C.c
673 - recognize #ident and #warning.
674 gctags/assembler.c
675 - recognize C_LABEL(x) and SYMBOL_NAME(x)
676 libregex/ - regex(3) imported.
677
678 [changed]
679 systags.sh
680 - parameter for gtags was changed from -owv to -wv.
681 global - -s option allowed with -c and -f command.
682 All files
683 - statement of license agreement 3.
684 Shigio Yamaguchi ->
685 Tama Communications Corporation and its contributors.
686 - My mail address
687 - delete #include <sys/param.h> for compatibility.
688 - delete __P() macro. It was for K&R C compiler.
689 VERSION - version number was moved to libutil/version.h.
690 some files
691 - some statements have been changed for generic UNIX.
692
693 Thanks to Marco Corvi for his information about
694 Digital Unix 4.0C.
695
696 Thnaks to Koen Hufkens for his information about
697 HP-UX 10.x.
698
699 libdb/db.h, gozilla/Imakefile
700 - slightly chagned for Debian GNU/Linux + powerpc.
701
702 Thanks to Ron Lee and Debian's porters for their patch.
703
704 libutil/find.c
705 - USEFIND undefined by default.
706 gozilla - specify -raise option.
707 htags - rewrite header #!/usr/bin/perl -> #!/usr/bin/env perl
708 ---
709 Dan Fandrich ported Global-3.44 into WIN32 environment.
710 I have included his codes into this version (3.5) and altered them
711 for some (mainly licensing) reasons, so any bugs in this area
712 are therefore my fault, not Dan's.
713
714 version 3.51 Support of Cygwin32. [26-Aug-99]
715
716 [added]
717 gtags, gctags, global, htags, btreeop
718 - Cygwin tools environment support added.
719
720 Thanks to David Aspinwall for his port.
721
722 ---
723 David Aspinwall ported Global-3.44 into cygwin32 environment.
724 I have merged his codes and Dan Fandrich's WIN32 code into this
725 version (3.51). So any bugs in this area are therefore my fault,
726 not David's.
727
728 version 3.52 Support of gozilla in WIN32 environment [29-Aug-99]
729
730 [fixed]
731 gctags - hanged when reading unix style text file in WIN32 environment.
732 (In Borland C, lseek() doesn't work to text file.)
733 htags - quotation error in global.cgi.
734
735 [added]
736 WIN32 support of gozilla
737 - Only for Borland C compiler.
738
739 version 3.53 Improved gtags.el and slightly modified [17-Sep-99]
740
741 [added]
742 compat.h- Macro for Solaris added.
743
744 Thanks to
745 Paul Lew
746 Dirk Schultheis
747 Yoshinori TOMITA
748 for thier advice.
749
750 gtags, htags, gctags
751 - --version option added.
752
753 Thanks to Marty Leisner for his advice.
754
755 FAQ - new faq added.
756
757 [changed]
758 gtags.el- ESC-t and ESC-r use current token as a default tag.
759 - ESC-t and ESC-r use mini-buffer history.
760
761 Thanks to Jun Obama for his patch.
762
763 Makefile.bsd, Makefile.inc
764 - description about libregex.a was deleted because BSD
765 has it in libc.
766
767 version 3.54 a couple of bugs fixed [3-Nov-99]
768
769 [fixed]
770 gctags - gctags - couldn't treat comment (/* ... */) that
771 include multi-byte character.
772 htags - index wasn't generated for large project.
00
11 Installation of GLOBAL
22
3 18-Mar-1999 Shigio Yamaguchi
3 17-Sep-1999 Shigio Yamaguchi
44 ---------------------------------------------------------------------------
55 Guide line (C style)
66 ---------------------------------------------------------------------------
99 You are lucky!
1010 You need not to do procedure "1. Preparation for generic UNIX".
1111
12 switch (version) {
13 case 2.0.5R:
14 case 2.1.0R:
15 case 2.1.5R:
16 case 2.1.6R:
17 case 2.1.7R:
18 case 2.2.1R:
12 if (version >= 2.2.2) {
13 Your system already includes GLOBAL.
14 You can overwrite it with this package.
15 } else {
1916 There is no problem.
20 break;
21 case 2.2.2R:
22 case 2.2.5R:
23 case 2.2.6R:
24 case 2.2.7R:
25 case 2.2.8R:
26 Your system includes GLOBAL 1.9 or 2.24.
17 }
18 } else if (Your system == NetBSD) {
19 You are lucky!
20 You need not to do procedure "1. Preparation for generic UNIX".
21
22 if (version >= 1.4) {
23 Your system already includes GLOBAL in your packages.
2724 You can overwrite it with this package.
28 break;
29 default:
30 I don't know. But it seems to be little problem.
31 }
32 } else if (Your system == NetBSD 1.3.2) {
25 } else if (version == 1.3.2) {
26 These is no problem.
27 You can use nvi-1.66.diff for native nvi.
28 } else {
29 I don't know but it seems no problem.
30 }
31 } else if (Your system == Debian GNU linux) {
3332 You are lucky!
34 You need not to do procedure "1. Preparation for generic UNIX"
35 and you can use nvi-1.66.diff for native nvi.
36 } else if (Your system == Debian GNU linux 1.3.1) {
37 You are lucky!
38
3933 You can skip most of "1. Preparation for generic UNIX" except for
4034 "a) Generic makefile".(It's very easy.)
35
36 if (version >= potato) {
37 Your system already includes GLOBAL in your packages.
38 You can overwrite it with this package.
39 } else if (version == 1.3.1) {
40 There is no problem.
41 } else {
42 I don't know but it seems no problem.
43 }
44 } else if (Your system == WIN32 (Windows95, WindowsNT 4.0)) {
45 if (You have Borland C++ compiler) {
46 Please go to win32/ directory and read README.
47 } else if (You are willing to use cygwin tools) {
48 There is no problem but some notice. I wrote cygwin specific
49 issure below.
50 } else {
51 I don't know but files in win32/ directory will be good
52 sample for you.
53 }
4154 } else {
4255 You may some error messages to make GLOBAL.
4356 But it seems not so difficult to clear it. If you make a patch for it,
6073
6174 1. Preparation for generic UNIX
6275
63 If you are a user of FreeBSD (all version) or NetBSD 1.3.2 then
64 nothing to do here. Please go to "2. GLOBAL basic".
76 If you are a user of FreeBSD or NetBSD then nothing to do here.
77 Please go to "2. GLOBAL basic". Else if you are a user of Borland
78 compiler, then goto win32/ directory and read README.
6579
6680 Otherwise, you must check following items before you install GLOBAL.
81
82 If you are willing to use cygwin tools in WIN32 environment then you must
83 install it at first and set path so that cygwin tool will be executed.
84 You can get it at:
85
86 http://sourceware.cygnus.com/
6787
6888 a) Generic makefile (necessary)
6989
7292 % make -f Makefile.generic gen
7393 % vi Makefile <- check variables DESTDIR, LIB...
7494
95 If you use cygwin tools then you must append --unix option like this.
96
97 % make --unix -f Makefile.generic gen
98
7599 b) Some UNIX tools (necessary)
76100
77 Find(1), sed(1), sort(1), uniq(1) are needed.
101 sed(1), sort(1) and env(1) are needed.
78102 If your environment is UNIX, you have them. You can confirm it like this.
79103
80 % which find
81 /usr/bin/find
104 [csh]
105 % which sed
106 /usr/bin/sed
82107 %
83108
84 c) POSIX regular expression (extension) library (necessary)
85
86 If you don't have it, you can use GNU's regex library (regex-0.12.tar.gz).
87 See following site.
88
89 http://www.gnu.org/order/ftp.html
90
91 d) PERL version 4 or later (needed for htags)
109 [bash]
110 $ type sed
111 sed is /usr/bin/sed
112 $
113
114 c) PERL version 4 or later (needed for htags)
92115
93116 If you don't have it, you can fetch it from this site.
94117
95 ftp://ftp.cis.ufl.edu/pub/perl/CPAN/src/5.0/latest.tar.gz
96
97 e) Rewrite some files (needed for htags)
118 http://www.perl.com/CPAN/
119
120 If you use cygwin tools then you can get it at:
121
122 http://www.activestate.com/
123
124 d) Rewrite some files (needed for htags)
98125
99126 If you install GLOBAL into other than /usr/bin, you need rewrite
100127 hard coded path in a program. You can find the place by this command.
101128
102129 % grep '/usr/bin/' */*.pl
103130
104 If you install perl to other than /usr/bin, please rewrite hard coded
105 path in some programs. You can find the places by this command.
106
107 % grep '/usr/bin/perl' */*.pl
108
109 f) Groff (needed for formatting online manuals)
131 If your env(1) command's path isn't '/usr/bin/env' then you must
132 rewrite perl script or copy env to /usr/bin. You can find the place by
133 this command.
134
135 % grep '/usr/bin/env' */*.pl
136
137 e) Groff (needed for formatting online manuals)
110138
111139 Online manuals in GLOBAL are written with 'mandoc' macro which is a part
112140 of GNU groff package. See following site:
125153 % make
126154 # make install
127155
156 If you use cygwin tools then use --unix option and cygwin_install.
157
158 $ make --unix
159 $ make --unix cygwin_install
160
161 If some errors occured in libdb/ or libregex/ then you had better to
162 modify 'machine/compat.h' and retry.
163
128164 3. Extended nvi (OPTIONAL)
129165
130 If you use FreeBSD 2.2.2R or later, your nvi is already extended nvi.
166 If you use FreeBSD 2.2.2R(or later) or NetBSD 1.4(or later), your nvi is
167 already extended nvi.
131168 Otherwise, please get nvi-1.79 at:
132169
133 ftp://ftp.cs.berkeley.edu/ucb/4bsd/nvi-1.79.tar.gz
170 http://www.bostic.com/vi/
134171
135172 and do the followings.
136173
146183
147184 4. Extended emacs (OPTIONAL)
148185
149 The version of Emacs supported by GLOBAL is GNU Emacs 19.28, 19.34 or
150 Mule 2.3 (= Emacs 19.28). Other emacs version seems to work well,
151 but I don't confirm it.
152
153 You can get it at:
154
155 Emacs 19.34b:
156 ftp://prep.ai.mit.edu/pub/gnu/emacs-19.34b.tar.gz
157 Mule 2.3:
158 ftp://ftp.cs.buffalo.edu/pub/mule/mule-2.3.tar.gz
159
160 If you are a FreeBSD user, install it from 'package' (see pkg_add(1)).
186 Global supports GNU Emacs and XEmacs. If you meet trouble, please tell me.
187
188 You can get them at:
189
190 GNU emacs:
191 http://www.gnu.org
192 XEmacs:
193 http://www.xemacs.org
161194
162195 If you have installed it then copy gtags.el in this package to the emacs
163196 lisp library directory or place the file in a directory
170203
171204 You need Elvis 2.1 or later. You can get it at:
172205
173 ftp://ftp.cs.pdx.edu/pub/elvis/elvis-2.1.tar.gz
206 http://www.fh-wedel.de/elvis/
174207
175208 You need not any patch for it.
176209
178211 6. Gozilla (OPTIONAL)
179212
180213 You need X(1) to install gozilla.
181
182 % (cd libdb; make)
214 After building basic GLOBAL then
215
183216 % cd gozilla
184217 % xmkmf
185218 % make
212245 | :tc=ctags-emacs:tc=htags:
213246
214247 Good luck!
248 ---------------------------------------------------------------------------
249 Additional comment for mainly BSD system.
250 ---------------------------------------------------------------------------
251 If your system is *BSD then you have db(3) and regex(3) in libc.
252 So you need not make libdb/ and libregex/.
253
254 The following modifications will suppress making them and make executables
255 smaller because they use libc.so instead of libdb and libregex.
256
257 [Makefile]
258
259 SUBDIR= libdb libutil global gtags gctags btreeop htags
260 |
261 v
262 SUBDIR= libutil global gtags gctags btreeop htags
263
264 [Makefile.inc]
265
266 LDADD= -lgloutil -lglodb
267 |
268 v
269 LDADD= -lgloutil
270
271 And you can do this.
272
273 % rm -rf libdb libregex
274 % make
66 Makefile.inc A part of Makefile for BSD.
77 Makefile.generic Makefile for generic UNIX(including BSD).
88 README Readme (introduction and usage).
9 VERSION Version number.
109 btreeop/ Btreeop command directory.
1110 gctags/ Extended ctags command directory.
1211 global/ Global command directory.
1615 gzshrc Gzsh start up file.
1716 htags/ Htags command directory.
1817 libdb/ DB(3) 1.85 library.
18 libregex/ REGEX(3) library.
1919 libutil/ Utility library.
2020 systags/ Script for kernel.
2121 gtags.el Gtags mode for Emacs.
2222 nvi-1.66.diff Patch for nvi 1.66.
2323 nvi-1.79.diff Patch for nvi 1.79.
24 VERSION Version number.
25 win32/ Items for WIN32 build.
0 SUBDIR= libdb libutil global gtags gctags btreeop htags
1
2 .include <bsd.subdir.mk>
0 SUBDIR = libdb libutil global gtags gctags btreeop htags
1
20 ##### EDIT THESE PARAMETERS ###############################################
31 CC = gcc
4 LIBS = -L../libutil -lgloutil -L../libdb -lglodb
5 CFLAGS = -O -I../libutil -I../libdb
62 DESTDIR = /usr
73 BINDIR = $(DESTDIR)/bin
84 MANDIR = $(DESTDIR)/man
95 ###########################################################################
10 # -DGTAGSCPP # alpha test for C++ support.
6
7 SUBDIR = libregex libdb libutil global gtags gctags btreeop htags
8 LIBS = ../libutil/libgloutil.a ../libdb/libglodb.a ../libregex/libgloregex.a
9 CFLAGS = -O -I../libutil -I../libdb -I../libregex -I../machine
1110
1211 all:
1312 @for d in $(SUBDIR); do \
1817 @for d in $(SUBDIR); do \
1918 set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS) BINDIR=$(BINDIR) MANDIR=$(MANDIR) install) ;\
2019 done
20 cygwin_install:
21 @for d in $(SUBDIR); do \
22 set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS) BINDIR=$(BINDIR) MANDIR=$(MANDIR) cygwin_install) ;\
23 done
2124 gen:
2225 @if [ ! -f Makefile.generic ]; then \
2326 echo "Error: generic makefile not found."; exit 1; \
2427 fi
25 mv Makefile Makefile.bsd && mv Makefile.generic Makefile
26 for d in $(SUBDIR); do \
27 (cd $$d && mv Makefile Makefile.bsd && mv Makefile.generic Makefile) ;\
28 cp Makefile.generic Makefile
29 for d in $(SUBDIR) systags; do \
30 (cd $$d && cp Makefile.generic Makefile) ;\
2831 done
2932 bsd:
3033 @if [ ! -f Makefile.bsd ]; then \
3134 echo "Error: BSD style makefile not found."; exit 1; \
3235 fi
33 mv Makefile Makefile.generic; mv Makefile.bsd Makefile
34 for d in $(SUBDIR); do \
35 (cd $$d && mv Makefile Makefile.generic && mv Makefile.bsd Makefile) ;\
36 cp Makefile.bsd Makefile
37 for d in $(SUBDIR) systags; do \
38 (cd $$d && cp Makefile.bsd Makefile) ;\
3639 done
3740 clean:
3841 @for d in $(SUBDIR); do \
11
22 GLOBAL_MAKEFILE_INC_BEEN_HERE=yes
33 BINDIR?= /usr/bin
4 LDDESTDIR= -L${.OBJDIR}/../libutil -L${.OBJDIR}/../libdb
4 LDDESTDIR= -L${.OBJDIR}/../libutil \
5 -L${.OBJDIR}/../libdb
56 LDADD= -lgloutil -lglodb
6 DPADD= ${.OBJDIR}/../libutil/libgloutil.a ${.OBJDIR}/../libdb/libglodb.a
7 CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../libutil -I${.CURDIR}/../libdb -O
7 DPADD= ${.OBJDIR}/../libutil/libgloutil.a \
8 ${.OBJDIR}/../libdb/libglodb.a
9 CFLAGS+= -I${.CURDIR} \
10 -I${.CURDIR}/../libutil \
11 -I${.CURDIR}/../libdb \
12 -I${.CURDIR}/../machine \
13 -O
814 # -Wall -Wwrite-strings -Wmissing-prototypes
9 # -DGTAGSCPP # alpha test for C++ support.
1015
1116 .endif
88 @=))) @=))@=)))@=))) @=)@=)))@=@=)))@=))@=)))
99 @@@@@@@@=)))@@@@=)@@@@@=)@@@@@@=@@@=)@@@@=)@@@@@@=)))
1010
11 Shigio Yamaguchi 20-Mar-99
12
13 Copyright 1996, 1997, 1998, 1999
14 Shigio Yamaguchi All right resereved.
11 Shigio Yamaguchi 24-Aug-99
12
13 Copyright (c) 1996, 1997, 1998, 1999
14 Shigio Yamaguchi. All rights reserved.
15 Copyright (c) 1999
16 Tama Communications Corporation. All rights reserved.
1517
1618 GLOBAL is a source code tag system that works the same way across diverse
17 environments. It supports C, Yacc and Java source code.
19 environments. It supports C, C++, Yacc and Java source code.
1820
1921 It brings benefits to all hackers. Enjoy!
2022
7880 o Web browser(see '4. Hypertext generator')
7981 o Elvis editor(see '5. Elvis using global')
8082
81 Supported languages are C, Yacc and Java.
83 Supported languages are C, C++, Yacc and Java.
8284 You can locate a specified function in the source files and move there easily.
8385 It is useful for hacking a large project containing many subdirectories,
8486 many '#ifdef' and many main() functions, like MH, X or BSD kernel.
124126 % cd /usr/src/usr.bin/vi
125127 % gtags
126128
127 Gtags traverse subdirectories and makes
128 three databases at the root of the source tree.
129 Gtags traverse subdirectories and makes four databases at the root of
130 the source tree.
129131
130132 % ls G*
131133 GPATH GRTAGS GSYMS GTAGS
140142
141143 Consider the following source tree:
142144
143 ROOT/ <- the root of source tree (GTAGS,GRTAGS)
145 ROOT/ <- the root of source tree (GTAGS,GRTAGS,...)
144146 |
145147 |- DIR1/
146148 | |
229231 You can make multiple tag files.
230232 For example, you can execute gtags at ROOT/, version1.0/ and version2.0/.
231233
232 ROOT/ <- the root of source tree (GTAGS,GRTAGS)
233 |
234 |- version1.0/ <- the root of version1.0 (GTAGS,GRTAGS)
234 ROOT/ <- the root of source tree (GTAGS,...)
235 |
236 |- version1.0/ <- the root of version1.0 (GTAGS,...)
235237 | |
236238 | |- file.c ..... +---------------+
237239 | |func1(){ i++; }|
238240 | +---------------+
239241 |
240 |- version2.0/ <- the root of version2.0 (GTAGS,GRTAGS)
242 |- version2.0/ <- the root of version2.0 (GTAGS,...)
241243 |
242244 |- file.c ..... +---------------+
243245 |func1(){ i--; }|
625627 o Mouse command is avalable.
626628
627629 If you use X version emacs, try the following
628 (but it doesn't work well in xemacs; I don't know why).
629630
630631 Move the mouse cursor to a function name and click the middle button.
631632 You will then go to the function's definition, or to its references,
638639
639640 4.1. Features
640641
641 o Htags makes hypertext from C, Yacc and Java source files.
642 o Htags makes hypertext from C, C++, Yacc and Java source files.
642643 o Once the hypertext is generated, you need nothing other than a WWW browser.
643644 o You can move the hypertext to anywhere. It is independent of the source code.
644645 o You can use all of your browser's functions, such as search,
963964
964965 Please see GLOBAL home page.
965966
966 <http://wafu.netgate.net/tama/unix/global.html>
967 <http://www.tamacom.com/global/>
967968
968969 Thank you for your reading.
969970 And of course, I'm also grateful to all excellent tools (vi, ctags, emacs,
970971 perl, C, db, mozilla ...) and its authors.
971972 ----------------------------------------------------------------------------
972 E-Mail: <shigio@wafu.netgate.net>
973 WWW: <http://wafu.netgate.net/tama/unix/indexe.html>
973 E-Mail: <shigio@tamacom.com>
974 WWW: <http://www.tamacom.com/global/>
974975 (You can find the latest version here.)
975976 ----------------------------------------------------------------------------
0 3.44
0 See libutil/version.h
0 PROG= btreeop
1
2 .include <bsd.prog.mk>
00 PROG = btreeop
11 CC = gcc
2 LIBS = -L../libutil -lgloutil -L../libdb -lglodb
3 CFLAGS = -O -I../lib
4 DEPLIBS= ../libutil/libgloutil.a
2 LIBS = ../libutil/libgloutil.a ../libdb/libglodb.a ../libregex/libgloregex.a
3 CFLAGS = -O -I../libutil -I../libdb -I../libregex -I../machine
54 OBJS = btreeop.o
65 BINDIR = /usr/bin
76 MANDIR = /usr/man
87
98 all: $(PROG)
109
11 $(PROG): $(OBJS) $(DEPLIBS)
10 $(PROG): $(OBJS) $(LIBS)
1211 $(CC) -o $(PROG) $(OBJS) $(LIBS)
1312 install:
1413 cp $(PROG) $(BINDIR)
1514 chmod 755 $(BINDIR)/$(PROG)
1615 cp $(PROG).1 $(MANDIR)/man1
1716 chmod 644 $(MANDIR)/man1/$(PROG).1
17 cygwin_install:
18 cp $(PROG).exe $(BINDIR)
19 chmod 755 $(BINDIR)/$(PROG).exe
20 cp $(PROG).1 $(MANDIR)/man1
21 chmod 644 $(MANDIR)/man1/$(PROG).1
1822 clean:
1923 rm -f $(PROG) $(OBJS)
0 PROG = btreeop.exe
1 CC = bcc32
2 LIBS = ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = btreeop.obj
5 WILDOBJ = /bc5/lib/32bit/wildargs.obj
6 BINDIR = \usr\bin
7 MANDIR = \usr\man
8
9 all: $(PROG)
10
11 $(PROG): $(OBJS) $(LIBS)
12 $(CC) -e$(PROG) $(OBJS) $(WILDOBJ) @..\win32\libs
13 install:
14 copy $(PROG) $(BINDIR)
15 copy $(PROG).1 $(MANDIR)/man1
16 clean:
17 del $(PROG)
18 del $(OBJS)
00 .\"
1 .\" Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
1 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
25 .\"
36 .\" Redistribution and use in source and binary forms, with or without
47 .\" modification, are permitted provided that the following conditions
1013 .\" documentation and/or other materials provided with the distribution.
1114 .\" 3. All advertising materials mentioning features or use of this software
1215 .\" must display the following acknowledgement:
13 .\" This product includes software developed by Shigio Yamaguchi.
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
1418 .\" 4. Neither the name of the author nor the names of any co-contributors
1519 .\" may be used to endorse or promote products derived from this software
1620 .\" without specific prior written permission.
17 .\"
21 .\"
1822 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
164168 .Sh SEE ALSO
165169 .Xr btree 3
166170 .Sh AUTHOR
167 Shigio Yamaguchi (shigio@wafu.netgate.net)
171 Shigio Yamaguchi (shigio@tamacom.com)
168172 .Sh HISTORY
169173 The
170174 .Nm
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * btreeop.c 12-Nov-98
34 * btreeop.c 5-Aug-99
3135 *
3236 */
3337 #include <sys/types.h>
3539
3640 #include <ctype.h>
3741 #include <signal.h>
42 #include <stdio.h>
3843 #include <stdlib.h>
3944 #include <string.h>
4045
41 #include "global.h"
46 #include "gparam.h"
47 #include "die.h"
48 #include "dbop.h"
49 #include "mgets.h"
50 #include "tab.h"
4251
4352 const char *dbdefault = "btree"; /* default database name */
4453 const char *progname = "btreeop"; /* command name */
4554
46 static void usage __P((void));
47 void signal_setup __P((void));
48 void onintr __P((int));
49 int main __P((int, char **));
50 void dbwrite __P((DBOP *));
51 void dbkey __P((DBOP *, char *, int));
52 void dbscan __P((DBOP *, char *, int));
53 void dbdel __P((DBOP *, char *, int));
54 void dbbysecondkey __P((DBOP *, int, char *, int));
55 static void usage(void);
56 void signal_setup(void);
57 void onintr(int);
58 int main(int, char **);
59 void dbwrite(DBOP *);
60 void dbkey(DBOP *, char *, int);
61 void dbscan(DBOP *, char *, int);
62 void dbdel(DBOP *, char *, int);
63 void dbbysecondkey(DBOP *, int, char *, int);
5564
5665 #define F_KEY 0
5766 #define F_DEL 1
7988 void
8089 signal_setup()
8190 {
91 signal(SIGINT, onintr);
92 signal(SIGTERM, onintr);
93 #ifdef SIGHUP
8294 signal(SIGHUP, onintr);
83 signal(SIGINT, onintr);
95 #endif
96 #ifdef SIGQUIT
8497 signal(SIGQUIT, onintr);
85 signal(SIGTERM, onintr);
98 #endif
8699 }
87100
88101 int
131144 break;
132145 default:
133146 usage();
147 break;
134148 }
135149 }
136150 db_name = (i < argc) ? argv[i] : dbdefault;
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * C.c 12-Sep-98
34 * C.c 10-Aug-99
3135 */
3236
3337 #include <ctype.h>
4044 #include "gctags.h"
4145 #include "defined.h"
4246 #include "die.h"
43 #include "locatestring.h"
4447 #include "strbuf.h"
4548 #include "token.h"
4649
47 static int function_definition __P((int));
48 static void condition_macro __P((int));
49 static int reserved __P((char *));
50 static int function_definition(int);
51 static void condition_macro(int);
52 static int reserved(char *);
5053
5154 /*
5255 * #ifdef stack.
5356 */
57 #define MAXPIFSTACK 100
58
5459 static struct {
5560 short start; /* level when #if block started */
5661 short end; /* level when #if block end */
209214 PUT(token, lineno, sp);
210215 if (c == '\n')
211216 pushbacktoken();
217 } else {
218 if (target == SYM)
219 PUT(token, lineno, sp);
212220 }
213221 break;
214222 case CP_INCLUDE:
215223 case CP_ERROR:
216224 case CP_LINE:
217225 case CP_PRAGMA:
226 case CP_WARNING:
227 case CP_IDENT:
218228 while ((c = nexttoken(interested, reserved)) != EOF && c != '\n')
219229 ;
220230 break;
227237 case CP_UNDEF:
228238 condition_macro(cc);
229239 while ((c = nexttoken(interested, reserved)) != EOF && c != '\n') {
230 if (!((cc == CP_IF || cc == CP_ELIF) && !strcmp(token, "defined")))
240 if (!strcmp(token, "defined"))
231241 continue;
232242 if (c == SYMBOL && target == SYM)
233243 PUT(token, lineno, sp);
289299 fprintf(stderr, "Warning: Out of function. %8s [+%d %s]\n", token, lineno, curfile);
290300 break;
291301 default:
302 break;
292303 }
293304 }
294305 strclose(sb);
323334 case CP_UNDEF:
324335 condition_macro(c);
325336 continue;
337 default:
338 break;
326339 }
327340 if (c == '('/* ) */)
328341 brace_level++;
347360 case CP_UNDEF:
348361 condition_macro(c);
349362 continue;
363 default:
364 break;
350365 }
351366 if (c == SYMBOL || IS_RESERVED(c))
352367 isdefine = 1;
416431 {"#else", CP_ELSE},
417432 {"#endif", CP_ENDIF},
418433 {"#error", CP_ERROR},
434 {"#ident", CP_IDENT},
419435 {"#if", CP_IF},
420436 {"#ifdef", CP_IFDEF},
421437 {"#ifndef", CP_IFNDEF},
423439 {"#line", CP_LINE},
424440 {"#pragma", CP_PRAGMA},
425441 {"#undef", CP_UNDEF},
442 {"#warning", CP_WARNING},
426443 {"%%", YACC_SEP},
427444 {"%left", YACC_LEFT},
428445 {"%nonassoc", YACC_NONASSOC},
429446 {"%right", YACC_RIGHT},
430447 {"%start", YACC_START},
448 {"%term", YACC_TERM},
431449 {"%token", YACC_TOKEN},
432450 {"%type", YACC_TYPE},
451 {"%union", YACC_UNION},
433452 {"%{", YACC_BEGIN},
434453 {"%}", YACC_END},
435454 {"__P", C___P},
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * C.h 20-Aug-98
34 * C.h 26-Jun-99
3135 */
3236 #define DECLARATIONS 0
3337 #define RULES 1
7882 #define CP_UNDEF 2011
7983 #define CP_ENDIF 2012
8084 #define CP_LINE 2013
85 #define CP_WARNING 2014
86 #define CP_IDENT 2015
8187 #define YACC_SEP 3001
8288 #define YACC_BEGIN 3002
8389 #define YACC_END 3003
8793 #define YACC_START 3007
8894 #define YACC_TOKEN 3008
8995 #define YACC_TYPE 3009
96 #define YACC_UNION 3010
97 #define YACC_TERM 3011
9098
9199 #define IS_CTOKEN(c) (c > 1000 && c < 2001)
92100 #define IS_CPTOKEN(c) (c > 2000 && c < 3001)
93101 #define IS_YACCTOKEN(c) (c > 3000 && c < 4001)
94 #define MAXPIFSTACK 100
00 /*
1 * Copyright (c) 1998, 1999 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * Cpp.c 18-Mar-99
34 * Cpp.c 18-Aug-99
3135 */
3236
3337 #include <ctype.h>
4448 #include "strbuf.h"
4549 #include "token.h"
4650
47 static int function_definition __P((int));
48 static void condition_macro __P((int));
49 static int reserved __P((char *));
51 static int function_definition(int);
52 static void condition_macro(int);
53 static int reserved(char *);
5054
5155 /*
5256 * #ifdef stack.
5357 */
58 #define MAXPIFSTACK 100
59
5460 static struct {
5561 short start; /* level when #if block started */
5662 short end; /* level when #if block end */
8187 const char *interested = "{}=;~";
8288 STRBUF *sb = stropen();
8389
90 *classname = *completename = 0;
91 stack[0].classname = completename;
8492 stack[0].terminate = completename;
8593 stack[0].level = 0;
8694 level = classlevel = piflevel = 0;
119127 strstart(sb);
120128 strnputs(sb, sp, strlen(sp) + 1);
121129 saveline = strvalue(sb);
122 if (function_definition(target))
130 if (function_definition(target)) {
123131 /* ignore constructor */
124132 if (target == DEF && strcmp(stack[classlevel].classname, savetok))
125133 PUT(savetok, savelineno, saveline);
134 }
126135 }
127136 } else {
128137 if (target == SYM)
212221 PUT(token, lineno, sp);
213222 if (c == '\n')
214223 pushbacktoken();
224 } else {
225 if (target == SYM)
226 PUT(token, lineno, sp);
215227 }
216228 break;
217229 case CP_INCLUDE:
218230 case CP_ERROR:
219231 case CP_LINE:
220232 case CP_PRAGMA:
233 case CP_WARNING:
234 case CP_IDENT:
221235 while ((c = nexttoken(interested, reserved)) != EOF && c != '\n')
222236 ;
223237 break;
230244 case CP_UNDEF:
231245 condition_macro(cc);
232246 while ((c = nexttoken(interested, reserved)) != EOF && c != '\n') {
233 if (!((cc == CP_IF || cc == CP_ELIF) && !strcmp(token, "defined")))
247 if (!strcmp(token, "defined"))
234248 continue;
235249 if (c == SYMBOL && target == SYM)
236250 PUT(token, lineno, sp);
336350 fprintf(stderr, "Warning: Out of function. %8s [+%d %s]\n", token, lineno, curfile);
337351 break;
338352 default:
353 break;
339354 }
340355 destruct = 0;
341356 }
371386 case CP_UNDEF:
372387 condition_macro(c);
373388 continue;
389 default:
390 break;
374391 }
375392 if (c == '('/* ) */)
376393 brace_level++;
399416 case CP_UNDEF:
400417 condition_macro(c);
401418 continue;
419 default:
420 break;
402421 }
403422 if (c == SYMBOL || IS_RESERVED(c))
404423 isdefine = 1;
468487 {"#else", CP_ELSE},
469488 {"#endif", CP_ENDIF},
470489 {"#error", CP_ERROR},
490 {"#ident", CP_IDENT},
471491 {"#if", CP_IF},
472492 {"#ifdef", CP_IFDEF},
473493 {"#ifndef", CP_IFNDEF},
475495 {"#line", CP_LINE},
476496 {"#pragma", CP_PRAGMA},
477497 {"#undef", CP_UNDEF},
498 {"#warning", CP_WARNING},
478499 {"::", CPP_SEP},
479500 {"__P", CPP___P},
480501 {"asm", CPP_ASM},
00 /*
1 * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * Cpp.h 19-Dec-98
34 * Cpp.h 26-Jun-99
3135 */
3236 #define CPP___P 1001
3337 #define CPP_ASM 1002
9397 #define CP_UNDEF 2011
9498 #define CP_ENDIF 2012
9599 #define CP_LINE 2013
100 #define CP_WARNING 2014
101 #define CP_IDENT 2015
96102
97103 #define IS_CPPTOKEN(c) (c > 1000 && c < 2001)
98104 #define IS_CPTOKEN(c) (c > 2000 && c < 3001)
99 #define MAXPIFSTACK 100
100105 #define MAXCOMPLETENAME 1024 /* max size of complete name of class */
101106 #define MAXCLASSSTACK 10 /* max size of class stack */
0 PROG= gctags
1 SRCS= C.c Cpp.c assembler.c gctags.c java.c
2
3 .include <bsd.prog.mk>
00 PROG = gctags
11 CC = gcc
2 LIBS = -L../libutil -lgloutil -L../libdb -lglodb
3 CFLAGS = -O -I../libutil
4 DEPLIBS= ../libutil/libgloutil.a
2 LIBS = ../libutil/libgloutil.a ../libdb/libglodb.a ../libregex/libgloregex.a
3 CFLAGS = -O -I../libutil -I../libdb -I../libregex -I../machine
54 OBJS = java.o gctags.o assembler.o C.o Cpp.o
65 BINDIR = /usr/bin
76 MANDIR = /usr/man
87
98 all: $(PROG)
109
11 $(PROG): $(OBJS) $(DEPLIBS)
10 $(PROG): $(OBJS) $(LIBS)
1211 $(CC) -o $(PROG) $(OBJS) $(LIBS)
1312 install:
1413 cp $(PROG) $(BINDIR)
1514 chmod 755 $(BINDIR)/$(PROG)
1615 cp $(PROG).1 $(MANDIR)/man1
1716 chmod 644 $(MANDIR)/man1/$(PROG).1
17 cygwin_install:
18 cp $(PROG).exe $(BINDIR)
19 chmod 755 $(BINDIR)/$(PROG).exe
20 cp $(PROG).1 $(MANDIR)/man1
21 chmod 644 $(MANDIR)/man1/$(PROG).1
1822 clean:
1923 rm -f $(PROG) $(OBJS)
0 PROG = gctags.exe
1 CC = bcc32
2 LIBS = ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = java.obj gctags.obj assembler.obj C.obj Cpp.obj
5 WILDOBJ = /bc5/lib/32bit/wildargs.obj
6 BINDIR = \usr\bin
7 MANDIR = \usr\man
8
9 all: $(PROG)
10
11 $(PROG): $(OBJS) $(LIBS)
12 $(CC) -e$(PROG) $(OBJS) $(WILDOBJ) @../win32/libs
13 install:
14 copy $(PROG) $(BINDIR)
15 copy $(PROG).1 $(MANDIR)/man1
16 clean:
17 del $(PROG)
18 del $(OBJS)
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * assembler.c 20-Feb-99
34 * assembler.c 12-Aug-99
3135 */
3236
3337 #include <ctype.h>
3842 #include "defined.h"
3943 #include "token.h"
4044
41 static int reserved __P((char *));
45 static int reserved(char *);
4246
4347 #define A_CALL 1001
4448 #define A_DEFINE 1002
4650 #define A_EXT 1004
4751 #define A_ALTENTRY 1005
4852 #define A_NENTRY 1006
53 #define A_SYMBOL_NAME 1007
54 #define A_C_LABEL 1008
4955
5056 void
5157 assembler()
7379 case A_CALL:
7480 if (!startline || target != REF)
7581 break;
76 if ((c = nexttoken(interested, reserved)) == A_EXT) {
82 if ((c = nexttoken(interested, reserved)) == A_EXT || c == A_SYMBOL_NAME || c == A_C_LABEL) {
7783 if ((c = nexttoken(interested, reserved)) == '('/* ) */)
7884 if ((c = nexttoken(interested, reserved)) == SYMBOL)
7985 if (defined(token))
106112 }
107113 }
108114 default:
115 break;
109116 }
110117 startline = 0;
111118 }
123130 if (!strcmp(word, "ALTENTRY"))
124131 return A_ALTENTRY;
125132 break;
133 case 'C':
134 if (!strcmp(word, "C_LABEL"))
135 return A_C_LABEL;
136 break;
126137 case 'E':
127138 if (!strcmp(word, "ENTRY"))
128139 return A_ENTRY;
133144 if (!strcmp(word, "NENTRY"))
134145 return A_NENTRY;
135146 break;
147 case 'S':
148 if (!strcmp(word, "SYMBOL_NAME"))
149 return A_SYMBOL_NAME;
150 break;
136151 case 'c':
137152 if (!strcmp(word, "call"))
138153 return A_CALL;
139154 break;
155 default:
156 break;
140157 }
141158 return SYMBOL;
142159 }
00 .\"
1 .\" Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
25 .\"
36 .\" Redistribution and use in source and binary forms, with or without
47 .\" modification, are permitted provided that the following conditions
1013 .\" documentation and/or other materials provided with the distribution.
1114 .\" 3. All advertising materials mentioning features or use of this software
1215 .\" must display the following acknowledgement:
13 .\" This product includes software developed by Shigio Yamaguchi.
14 .\" 4. Neither the name of the University nor the names of its contributors
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
18 .\" 4. Neither the name of the author nor the names of any co-contributors
1519 .\" may be used to endorse or promote products derived from this software
1620 .\" without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\"
22 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2226 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2327 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2428 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2731 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 .\" SUCH DAMAGE.
2933 .\"
30 .\"
31 .Dd Aug 19, 1998
34 .Dd Aug 27, 1999
3235 .Dt GCTAGS 1
3336 .Os BSD 4
3437 .Sh NAME
4851 print cross reference list for
4952 .Xr gtags 1
5053 from the specified C,
54 .Tn C++ ,
5155 .Tn YACC ,
5256 .Tn JAVA ,
5357 and assembler source to standard output.
7478 option.
7579 .It Fl r
7680 locate function references instead of function definitions. GTAGS file is
77 needed at the current directory. (C and Java source only)
81 needed at the current directory. (C, C++ and Java source only)
7882 By default, locate function definitions.
7983 .It Fl s
8084 collect symbols other than functions. By default, locate function definitions.
9498 .Nm \&.h
9599 are assumed to be C
96100 source files and are searched for C style routine and macro definitions.
101 Files whose names end in
102 .Nm \&.c++
103 .Nm \&.cc
104 .Nm \&.cpp
105 .Nm \&.cxx
106 .Nm \&.hxx
107 .Nm \&.C
108 .Nm \&.H
109 are assumed to be C++
110 source files.
97111 Files whose names end in
98112 .Nm \&.y
99113 are assumed to be
135149 and ALTENTRY() from source file. Probably valid only for FreeBSD and Linux
136150 kernel source.
137151 .Sh AUTHORS
138 Shigio Yamaguchi (shigio@wafu.netgate.net)
152 Shigio Yamaguchi (shigio@tamacom.com)
139153 .Sh HISTORY
140154 The
141155 .Nm
00 /*
1 * Copyright (c) 1998, 1999 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * gctags.c 18-Mar-99
34 * gctags.c 17-Aug-99
3135 */
3236
3337 #include <limits.h>
5155 const char *progname = "gctags"; /* program name */
5256 char *notfunction;
5357
54 int main __P((int, char **));
55 static void usage __P((void));
58 int main(int, char **);
59 static void usage(void);
5660
5761 struct words *words;
5862 static int tablesize;
9397 break;
9498 default:
9599 usage();
100 /* NOTREACHED */
96101 }
97102 }
98103 }
123128 for (; argc > 0; argv++, argc--) {
124129 if (!opentoken(argv[0]))
125130 die1("'%s' cannot open.", argv[0]);
131 #ifdef _WIN32
132 /* Lower case the file name since names are case insensitive */
133 strlwr(argv[0]);
134 #endif
126135 /*
127136 * yacc
128137 */
139148 */
140149 else if (locatestring(argv[0], ".java", MATCH_AT_LAST))
141150 java();
142 #ifdef GTAGSCPP
143151 /*
144152 * C++
145153 */
151159 locatestring(argv[0], ".C", MATCH_AT_LAST) ||
152160 locatestring(argv[0], ".H", MATCH_AT_LAST))
153161 Cpp();
154 #endif
155162 /*
156163 * C
157164 */
161168 * C or C++
162169 */
163170 else if (locatestring(argv[0], ".h", MATCH_AT_LAST)) {
164 #ifdef GTAGSCPP
165171 if (isCpp())
166172 Cpp();
167173 else
168 #endif
169174 C(0);
170175 }
171176 closetoken();
00 /*
1 * Copyright (c) 1998, 1999 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2933 *
3034 * gctags.h 8-Jan-99
3135 */
32 #include <sys/param.h>
3336 #include "token.h"
3437 /*
3538 * target type.
6972
7073 #define IS_RESERVED(a) ((a) > 255)
7174
72 #ifndef __P
73 #ifdef __STDC__
74 #define __P(protos) protos
75 #else
76 #define __P(protos) ()
77 #endif
78 #endif
79
8075 #define DBG_PRINT(level, a) dbg_print(level, a)
8176
82 void dbg_print __P((int, const char *));
83 int isnotfunction __P((char *));
84 int cmp __P((const void *, const void *));
85 void C __P((int));
86 void Cpp __P((void));
87 int isCpp __P((void));
88 void assembler __P((void));
89 void java __P((void));
77 void dbg_print(int, const char *);
78 int isnotfunction(char *);
79 int cmp(const void *, const void *);
80 void C(int);
81 void Cpp(void);
82 int isCpp(void);
83 void assembler(void);
84 void java(void);
00 /*
1 * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * java.c 2-Sep-98
34 * java.c 12-Jul-99
3135 */
3236
3337 #include <ctype.h>
4145 #include "java.h"
4246 #include "token.h"
4347
44 static int reserved __P((char *));
48 static int reserved(char *);
4549
4650 /*
4751 * java: read java file and pickup tag entries.
166170 pushbacktoken();
167171 break;
168172 default:
173 break;
169174 }
170175 }
171176 }
00 /*
1 * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0 PROG= global
1
2 .include <bsd.prog.mk>
00 PROG = global
11 CC = gcc
2 LIBS = -L../libutil -lgloutil -L../libdb -lglodb
3 CFLAGS = -O -I../libutil
4 DEPLIBS= ../libutil/libgloutil.a
2 LIBS = ../libutil/libgloutil.a ../libdb/libglodb.a ../libregex/libgloregex.a
3 CFLAGS = -O -I../libutil -I../libdb -I../libregex -I../machine
54 OBJS = global.o
65 BINDIR = /usr/bin
76 MANDIR = /usr/man
87
98 all: $(PROG)
109
11 $(PROG): $(OBJS) $(DEPLIBS)
10 $(PROG): $(OBJS) $(LIBS)
1211 $(CC) -o $(PROG) $(OBJS) $(LIBS)
1312 install:
1413 cp $(PROG) $(BINDIR)
1514 chmod 755 $(BINDIR)/$(PROG)
1615 cp $(PROG).1 $(MANDIR)/man1
1716 chmod 644 $(MANDIR)/man1/$(PROG).1
17 cygwin_install:
18 cp $(PROG).exe $(BINDIR)
19 chmod 755 $(BINDIR)/$(PROG).exe
20 cp $(PROG).1 $(MANDIR)/man1
21 chmod 644 $(MANDIR)/man1/$(PROG).1
1822 clean:
1923 rm -f $(PROG) $(OBJS)
0 PROG = global.exe
1 CC = bcc32
2 LIBS = ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = global.obj
5 WILDOBJ = /bc5/lib/32bit/wildargs.obj
6 BINDIR = \usr\bin
7 MANDIR = \usr\man
8
9 all: $(PROG)
10
11 $(PROG): $(OBJS) $(LIBS)
12 $(CC) -e$(PROG) $(OBJS) $(WILDOBJ) @../win32/libs
13 install:
14 copy $(PROG) $(BINDIR)
15 copy $(PROG).1 $(MANDIR)/man1
16 clean:
17 del $(PROG)
18 del $(OBJS)
00 .\"
11 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
35 .\"
46 .\" Redistribution and use in source and binary forms, with or without
57 .\" modification, are permitted provided that the following conditions
1113 .\" documentation and/or other materials provided with the distribution.
1214 .\" 3. All advertising materials mentioning features or use of this software
1315 .\" must display the following acknowledgement:
14 .\" This product includes software developed by Shigio Yamaguchi.
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
1518 .\" 4. Neither the name of the author nor the names of any co-contributors
1619 .\" may be used to endorse or promote products derived from this software
1720 .\" without specific prior written permission.
18 .\"
21 .\"
1922 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2023 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2124 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2831 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2932 .\" SUCH DAMAGE.
3033 .\"
31 .Dd Mar 19, 1999
34 .Dd Aug 27, 1999
3235 .Dt GLOBAL 1
3336 .Os BSD 4
3437 .Sh NAME
3639 .Nd print the locations of specified object.
3740 .Sh SYNOPSIS
3841 .Nm global
39 .Op Fl alnrtvx
42 .Op Fl alnrstvx
4043 .Ar pattern
4144 .Nm global -c
4245 .Op Ar prefix
4346 .Nm global
44 .Fl f[anrtx]
47 .Fl f[anrstx]
4548 .Ar files
4649 .Nm global
4750 .Fl g[alntvx]
5154 .Nm global
5255 .Fl p
5356 .Nm global
54 .Fl P[alnt]
57 .Fl P[alntx]
5558 .Op Ar pattern
56 .Nm global
57 .Fl s[alntvx]
58 .Ar pattern
5959 .Sh DESCRIPTION
6060 .Nm Global
61 find the locations of specified object in C, Yacc and Java source files.
61 find the locations of specified object in C, C++, Yacc, Java and assembler
62 source files.
6263 .Nm Global
6364 can treat a source tree, that is, a directory that has subdirectories and
6465 source files.
119120 .It Fl r
120121 print the locations of object references. By default, print object
121122 definitions.
123 .It Fl s
124 print the locations of specified symbol other than function names.
125 You need GSYMS tags file. See gtags(1).
122126 .It Fl t
123127 print with standard ctags format.
124128 .It Fl x
157161 .Xr htags 1 ,
158162 .Xr vi 1 .
159163 .Sh AUTHORS
160 Shigio Yamaguchi (shigio@wafu.netgate.net)
164 Shigio Yamaguchi (shigio@tamacom.com)
161165 .Sh HISTORY
162166 The
163167 .Nm
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * global.c 8-Dec-98
34 * global.c 18-Aug-99
3135 *
3236 */
3337
3539 #include <sys/stat.h>
3640
3741 #include <ctype.h>
38 #include <regex.h>
3942 #include <stdio.h>
4043 #include <stdlib.h>
4144 #include <string.h>
4245 #include <unistd.h>
4346
4447 #include "global.h"
48 #include "regex.h"
4549
4650 const char *progname = "global"; /* command name */
4751
48 static void usage __P((void));
49 static void setcom __P((int));
50 int main __P((int, char **));
51 void makefilter __P((char *));
52 FILE *openfilter __P((void));
53 void closefilter __P((FILE *));
54 void completelist __P((char *, char *, char *));
55 void relative_filter __P((STRBUF *, char *, char *));
56 void grep __P((char *));
57 void pathlist __P((char *, char *));
58 void parsefile __P((int, char **, char *, char *, char *, int));
59 void printtag __P((FILE *, char *));
60 int notnamechar __P((char *));
61 int search __P((char *, char *, char *, char *, int));
62 int includepath __P((char *, char *));
63
64 char sortfilter[MAXFILLEN+1]; /* sort filter */
65 char pathfilter[MAXFILLEN+1]; /* path convert filter */
52 static void usage(void);
53 static void setcom(int);
54 int main(int, char **);
55 void makefilter(char *);
56 FILE *openfilter(void);
57 void closefilter(FILE *);
58 void completelist(char *, char *, char *);
59 void relative_filter(STRBUF *, char *, char *);
60 void grep(char *);
61 void pathlist(char *, char *);
62 void parsefile(int, char **, char *, char *, char *, int);
63 void printtag(FILE *, char *);
64 int notnamechar(char *);
65 int search(char *, char *, char *, int);
66 int includepath(char *, char *);
67
68 char sort_command[MAXFILLEN+1]; /* sort command */
69 char sed_command[MAXFILLEN+1]; /* sed command */
70 STRBUF *sortfilter; /* sort filter */
71 STRBUF *pathfilter; /* path convert filter */
6672 char *localprefix; /* local prefix */
6773 int aflag; /* [option] */
6874 int cflag; /* command */
7480 int pflag; /* command */
7581 int Pflag; /* command */
7682 int rflag; /* [option] */
77 int sflag; /* command */
83 int sflag; /* [option] */
7884 int tflag; /* [option] */
7985 int vflag; /* [option] */
8086 int xflag; /* [option] */
8389 static void
8490 usage()
8591 {
86 fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
87 "global [-alnrtvx] pattern",
88 "global -c [prefix]",
89 "global -f[alnrtx] files",
92 fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
93 "global [-alnrstvx] pattern",
94 "global -c[s] [prefix]",
95 "global -f[alnrstx] files",
9096 "global -g[alntvx] pattern",
9197 "global -i[v]",
9298 "global -p[v]",
93 "global -P[alnt] [pattern]",
94 "global -s[alntvx] pattern");
99 "global -P[alntx] [pattern]");
95100 exit(1);
96101 }
97102
123128 if (!strcmp(argv[0], "--filter")) {
124129 pfilter++;
125130 continue;
131 } else if (!strcmp(argv[0], "--version")) {
132 fprintf(stdout, "%s\n", VERSION);
133 exit(0);
126134 }
127135 for (p = argv[0] + 1; *p; p++) {
128136 switch (*p) {
165173 break;
166174 case 's':
167175 sflag++;
168 setcom(*p);
169176 break;
170177 case 't':
171178 tflag++;
178185 break;
179186 default:
180187 usage();
188 break;
181189 }
182190 }
183191 }
184192 av = (argc > 0) ? *argv : NULL;
193 /*
194 * invalid options.
195 */
196 if (sflag && rflag)
197 die("both of -s and -r are not allowed.");
185198 /*
186199 * only -c, -i, -P and -p allows no argment.
187200 */
194207 break;
195208 default:
196209 usage();
197 }
198 }
199 /*
200 * invalid options are just ignored.
201 */
210 break;
211 }
212 }
213 /*
214 * -i and -p cannot have any arguments.
215 */
216 if (av) {
217 switch (command) {
218 case 'i':
219 case 'p':
220 usage();
221 default:
222 break;
223 }
224 }
202225 /*
203226 * remove leading blanks.
204227 */
254277 exit(0);
255278 }
256279 /*
280 * get command name of sort and sed.
281 */
282 {
283 STRBUF *sb = stropen();
284 if (!getconfs("sort_command", sb))
285 die("cannot get sort command name.");
286 strcpy(sort_command, strvalue(sb));
287 strstart(sb);
288 if (!getconfs("sed_command", sb))
289 die("cannot get sed command name.");
290 strcpy(sed_command, strvalue(sb));
291 strclose(sb);
292 }
293 /*
257294 * make sort filter.
258295 */
259 if (sflag && xflag)
260 strcpy(sortfilter, "");
261 else if (tflag) /* ctags format */
262 strcpy(sortfilter, "sort +0 -1 +1 -2 +2n -3");
263 else if (fflag)
264 strcpy(sortfilter, "sort +2 -3 +1n -2");
265 else if (xflag) /* print details */
266 strcpy(sortfilter, "sort +0 -1 +2 -3 +1n -2");
267 else /* print just file name */
268 strcpy(sortfilter, "sort | uniq");
296 sortfilter = stropen();
297 if (!(sflag && xflag)) {
298 strputs(sortfilter, sort_command);
299 strputc(sortfilter, ' ');
300 if (tflag) /* ctags format */
301 strputs(sortfilter, "+0 -1 +1 -2 +2n -3");
302 else if (fflag)
303 strputs(sortfilter, "+2 -3 +1n -2");
304 else if (xflag) /* print details */
305 strputs(sortfilter, "+0 -1 +2 -3 +1n -2");
306 else /* print just file name */
307 strputs(sortfilter, "-u");
308 }
269309 /*
270310 * make path filter.
271311 */
272 if (aflag) /* absolute path name */
273 sprintf(pathfilter, "sed -e 's!\\.!%s!'", root);
274 else { /* relative path name */
275 STRBUF *sb = stropen();
276
277 relative_filter(sb, root, cwd);
278 strcpy(pathfilter, strvalue(sb));
279 strclose(sb);
312 pathfilter = stropen();
313 if (aflag) { /* absolute path name */
314 strputs(pathfilter, sed_command);
315 strputc(pathfilter, ' ');
316 strputs(pathfilter, "-e \"s@\\.@");
317 strputs(pathfilter, root);
318 strputs(pathfilter, "@\"");
319 } else { /* relative path name */
320 relative_filter(pathfilter, root, cwd);
280321 }
281322 /*
282323 * make local prefix.
313354 if (gflag) {
314355 if (!lflag)
315356 chdir(root);
316 else if (!aflag)
317 sprintf(pathfilter, "sed -e 's!\\./!!'");
357 else if (!aflag) {
358 strstart(pathfilter);
359 strputs(pathfilter, sed_command);
360 strputc(pathfilter, ' ');
361 strputs(pathfilter, "-e \"s@\\./@@\"");
362 }
318363 grep(av);
319364 exit(0);
320365 }
336381 /*
337382 * search in current source tree.
338383 */
339 count = search(av, cwd, root, dbpath, db);
384 count = search(av, root, dbpath, db);
340385 /*
341386 * search in library path.
342387 */
349394 p = buf;
350395 while (p) {
351396 lib = p;
352 if ((p = locatestring(p, ":", MATCH_FIRST)) != NULL)
397 if ((p = locatestring(p, PATHSEP, MATCH_FIRST)) != NULL)
353398 *p++ = 0;
354399 if (!gtagsexist(lib, libdbpath))
355400 continue;
356401 if (!strcmp(dbpath, libdbpath))
357402 continue;
358 if (aflag) /* absolute path name */
359 sprintf(pathfilter, "sed -e 's!\\.!%s!'", lib);
360 else {
361 STRBUF *sb = stropen();
362 relative_filter(sb, lib, cwd);
363 strcpy(pathfilter, strvalue(sb));
364 strclose(sb);
403 if (aflag) { /* absolute path name */
404 strstart(pathfilter);
405 strputs(pathfilter, sed_command);
406 strputc(pathfilter, ' ');
407 strputs(pathfilter, "-e \"s@\\.@");
408 strputs(pathfilter, lib);
409 strputs(pathfilter, "@\"");
410 } else {
411 strstart(pathfilter);
412 relative_filter(pathfilter, lib, cwd);
365413 }
366 count = search(av, cwd, lib, libdbpath, db);
414 count = search(av, lib, libdbpath, db);
367415 if (count > 0) {
368416 strcpy(dbpath, libdbpath);
369417 break;
376424 fprintf(stderr, "%d object located", count);
377425 if (count > 1)
378426 fprintf(stderr, "%d objects located", count);
379 fprintf(stderr, " (using '%s').\n", makepath(dbpath, dbname(db)));
427 fprintf(stderr, " (using '%s').\n", makepath(dbpath, dbname(db), NULL));
380428 } else {
381429 fprintf(stderr, "'%s' not found.\n", av);
382430 }
386434 /*
387435 * makefilter: make filter string.
388436 *
389 * io) filter buffer
437 * o) filter buffer
390438 */
391439 void
392440 makefilter(filter)
394442 {
395443 if (nflag)
396444 filter[0] = 0;
397 else if (sortfilter[0] == 0 && pathfilter[0] == 0)
445 else if (!strbuflen(sortfilter) && !strbuflen(pathfilter))
398446 filter[0] = 0;
399 else if (sortfilter[0] && pathfilter[0])
400 sprintf(filter, "%s | %s", sortfilter, pathfilter);
401 else if (sortfilter[0])
402 strcpy(filter, sortfilter);
447 else if (strbuflen(sortfilter) && strbuflen(pathfilter))
448 sprintf(filter, "%s | %s", strvalue(sortfilter), strvalue(pathfilter));
449 else if (strbuflen(sortfilter))
450 strcpy(filter, strvalue(sortfilter));
403451 else
404 strcpy(filter, pathfilter);
452 strcpy(filter, strvalue(pathfilter));
405453 }
406454 /*
407455 * openfilter: open output filter.
408456 *
409457 * gi) pathfilter
410458 * gi) sortfilter
411 * r) output filter
459 * r) file pointer for output filter
412460 */
413461 FILE *
414462 openfilter(void)
446494 char *p;
447495 int flags = GTOP_KEY;
448496 GTOP *gtop;
497 int db;
449498
450499 if (prefix && *prefix == 0) /* In the case global -c '' */
451500 prefix = NULL;
452501 if (prefix)
453502 flags |= GTOP_PREFIX;
454 gtop = gtagsopen(dbpath, root, GTAGS, GTAGS_READ, 0);
503 db = (sflag) ? GSYMS : GTAGS;
504 gtop = gtagsopen(dbpath, root, db, GTAGS_READ, 0);
455505 for (p = gtagsfirst(gtop, prefix, flags); p; p = gtagsnext(gtop))
456506 (void)fprintf(stdout, "%s\n", p);
457507 gtagsclose(gtop);
459509 /*
460510 * relative_filter: make relative path filter
461511 *
462 * i) sb string buffer
512 * o) sb buffer for the result
463513 * i) root the root directory of source tree
464514 * i) cwd current directory
465 * r) relative path filter
466515 */
467516 void
468517 relative_filter(sb, root, cwd)
484533 /*
485534 * forward to root.
486535 */
487 strputs(sb, "sed -e 's!\\./!");
536 strputs(sb, sed_command);
537 strputc(sb, ' ');
538 strputs(sb, "-e \"s@\\./@");
488539 for (c = branch; *c; c++)
489540 if (*c == '/')
490541 strputs(sb, "../");
497548 strputs(sb, p);
498549 strputc(sb, '/');
499550 }
500 strputs(sb, "!'");
551 strputs(sb, "@\"");
501552 /*
502553 * remove redundancy.
503554 */
508559 for (c = branch + 1; ; c++) {
509560 if (*c == 0 || *c == '/') {
510561 *p = 0;
511 strputs(sb, " -e 's!\\.\\./");
562 strputs(sb, " -e \"s@\\.\\./");
512563 strputs(sb, unit);
513 strputs(sb, "/!!'");
564 strputs(sb, "/@@\"");
514565 if (*c == 0)
515566 break;
516567 p = unit;
610661 {
611662 char *p, *e = edit;
612663 for (p = pattern; *p; p++) {
613 if (*p == '%' || *p == ' ' || *p == '\t') {
664 if (*p == '%' || *p == ' ' || *p == '\t' || *p == '.') {
614665 sprintf(e, "%%%02x", *p);
615666 e += 3;
616667 } else
671722 char *av;
672723 {
673724 FILE *op;
674 const char *tag = av;
675 char key[10], *path;
725 char key[10], *path, *p;
676726 regex_t preg;
677727 int i, lim;
678728
679729 if (av) {
680730 if (regcomp(&preg, av, REG_EXTENDED) != 0)
681731 die("illegal regular expression.");
682 } else
683 tag = "file";
732 }
684733 if (!(op = openfilter()))
685734 die("cannot open output filter.");
686735 if (pathopen(dbpath, 0) < 0)
692741 continue;
693742 if (lflag && !locatestring(path, localprefix, MATCH_AT_FIRST))
694743 continue;
695 if (av && regexec(&preg, path + 2, 0, 0, 0) != 0)
744 /*
745 * skip './' and localprefix because end-user doesn't see it.
746 */
747 p = (lflag) ? path + strlen(localprefix) : path + 2;
748 if (av && regexec(&preg, p, 0, 0, 0) != 0)
696749 continue;
697 if (tflag)
698 fprintf(op, "%s\t%s\t1\n", tag, path);
750 if (xflag)
751 fprintf(op, "path\t1 %s \n", path);
752 else if (tflag)
753 fprintf(op, "path\t%s\t1\n", path);
699754 else
700755 fprintf(op, "%s\n", path);
701756 }
754809 * convert path into relative from root directory of source tree.
755810 */
756811 path = realpath(av, buf);
757 if (*path != '/')
812 if (!isabspath(path))
758813 die("realpath(3) is not compatible with BSD version.");
759814 if (strncmp(path, root, strlen(root))) {
760815 fprintf(stderr, "'%s' is out of source tree.\n", path);
790845 * search: search specified function
791846 *
792847 * i) pattern search pattern
793 * i) cwd current directory
794848 * i) root root of source tree
795849 * i) dbpath database directory
796850 * i) db GTAGS,GRTAGS,GSYMS
797851 * r) count of output lines
798852 */
799853 int
800 search(pattern, cwd, root, dbpath, db)
854 search(pattern, root, dbpath, db)
801855 char *pattern;
802 char *cwd;
803856 char *root;
804857 char *dbpath;
805858 int db;
00 #
1 # Copyright (c) 1998, 1999 Shigio Yamaguchi. All rights reserved.
1 # Copyright (c) 1996, 1997, 1998, 1999
2 # Shigio Yamaguchi. All rights reserved.
3 # Copyright (c) 1999
4 # Tama Communications Corporation. All rights reserved.
25 #
36 # Redistribution and use in source and binary forms, with or without
47 # modification, are permitted provided that the following conditions
1013 # documentation and/or other materials provided with the distribution.
1114 # 3. All advertising materials mentioning features or use of this software
1215 # must display the following acknowledgement:
13 # This product includes software developed by Shigio Yamaguchi.
16 # This product includes software developed by Tama Communications
17 # Corporation and its contributors.
1418 # 4. Neither the name of the author nor the names of any co-contributors
1519 # may be used to endorse or promote products derived from this software
1620 # without specific prior written permission.
17 #
21 #
1822 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4549 # Select 'standard' or 'compact'. By default, it assumes 'standard'.
4650 # suffixes:
4751 # Suffixes of target source file. By default, it assumes
48 # 'c,h,y,s,S,java'.
52 # 'c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java'
4953 # skip:
5054 # Skip files among the target files. If the name ends with '/',
5155 # gtags skips all files under the directory.
6973 # [gctags]
7074 #
7175 # This command is distributed as part of GLOBAL.
72 # (It's pre-alpha.)
73 # :suffixes=c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java:\
76 #
7477 gctags|tag command for GLOBAL:\
7578 :tc=common:\
76 :suffixes=c,h,y,s,S,java:\
79 :suffixes=c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java:\
80 :sort_command=sort:\
81 :sed_command=sed:\
7782 :GTAGS=gctags %s:\
7883 :GRTAGS=gctags -r %s:\
7984 :GSYMS=gctags -s %s:
85 gctags.exe|tag command for GLOBAL WIN32:\
86 :tc=common:\
87 :suffixes=c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java:\
88 :sort_command=sort.exe:\
89 :sed_command=sed.exe:\
90 :GTAGS=gctags.exe %s:\
91 :GRTAGS=gctags.exe -r %s:\
92 :GSYMS=gctags.exe -s %s:
8093 #
8194 # [Emacs's ctags]
8295 #
11 XCOMM Imakefile for gozilla
22 XCOMM
33
4 INC = ../libutil
5 LOCAL_LIBRARIES = XawClientLibs -L../libdb -lglodb
6 DEPLIBS = XawClientDepLibs ../libdb/libglodb.a
7 DEFINES = -DSTANDALONE -DGLOBAL -I$(INC)
4 LOCAL_LIBRARIES = XawClientLibs -L../libdb -lglodb -L../libutil -lgloutil
5 DEPLIBS = XawClientDepLibs ../libdb/libglodb.a ../libutil/libgloutil.a
6 DEFINES = -DSTANDALONE -DGLOBAL -I../libdb -I../libutil -I../machine
87
9 SRCS = gozilla.c remote.c test.c getdbpath.c strbuf.c conf.c \
10 mgets.c locatestring.c makepath.c strmake.c pathop.c dbop.c
11 OBJS = gozilla.o remote.o test.o getdbpath.o strbuf.o conf.o \
12 mgets.o locatestring.o makepath.o strmake.o pathop.o dbop.o
13
14 LinkSourceFile(test.c,$(INC))
15 LinkSourceFile(getdbpath.c,$(INC))
16 LinkSourceFile(strbuf.c,$(INC))
17 LinkSourceFile(conf.c,$(INC))
18 LinkSourceFile(mgets.c,$(INC))
19 LinkSourceFile(locatestring.c,$(INC))
20 LinkSourceFile(makepath.c,$(INC))
21 LinkSourceFile(strmake.c,$(INC))
22 LinkSourceFile(pathop.c,$(INC))
23 LinkSourceFile(dbop.c,$(INC))
24
25 ../libdb/libglodb.a:
26 (cd ../libdb; make)
8 SRCS = gozilla.c remote.c
9 OBJS = gozilla.o remote.o
2710
2811 ComplexProgramTarget(gozilla)
0 PROG = gozilla.exe
1 CC = bcc32
2 LIBS = ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = gozilla.obj
5 WILDOBJ = /bc5/lib/32bit/wildargs.obj
6 BINDIR = \usr\bin
7 MANDIR = \usr\man
8
9 all: $(PROG)
10
11 $(PROG): $(OBJS) $(LIBS)
12 $(CC) -e$(PROG) $(OBJS) $(WILDOBJ) @../win32/libs
13 install:
14 copy $(PROG) $(BINDIR)
15 copy $(PROG).man $(MANDIR)\man1\$(PROG).1
16 clean:
17 del $(PROG)
18 del $(OBJS)
00 /*
11 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
35 *
46 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
1113 * documentation and/or other materials provided with the distribution.
1214 * 3. All advertising materials mentioning features or use of this software
1315 * must display the following acknowledgement:
14 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1518 * 4. Neither the name of the author nor the names of any co-contributors
1619 * may be used to endorse or promote products derived from this software
1720 * without specific prior written permission.
18 *
21 *
1922 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2124 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2831 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2932 * SUCH DAMAGE.
3033 *
31 * gozilla.c 10-Feb-99
34 * gozilla.c 29-Aug-99
3235 *
3336 */
3437 #include <stdio.h>
3538 #include <stdlib.h>
3639 #include <string.h>
40 #include <ctype.h>
41 #ifdef _WIN32
42 #include <windows.h>
43 #endif
44
3745 #include "global.h"
3846
3947 const char *progname = "gozilla"; /* command name */
4048
41 static void usage __P((void));
42
43 int main __P((int, char **));
44 int issource __P((char *));
45 int convertpath __P((char *, char *, char *, STRBUF *));
46 int sendcommand __P((char *));
49 static void usage(void);
50
51 int main(int, char **);
52 int isprotocol(char *);
53 int issource(char *);
54 int convertpath(char *, char *, char *, STRBUF *);
55 void loadmozilla(char *);
56 int sendmozilla(char *, int);
57 #ifndef _WIN32
58 int sendcommand(char *);
59 #endif
4760
4861 int bflag;
4962 int pflag;
5063 int Cflag;
64 int linenumber = 0;
5165
5266 static void
5367 usage()
6680 char c, *p, *q;
6781 char *browser = NULL;
6882 char *command = NULL;
69 char *arg = NULL;
7083 char URL[MAXPATHLEN+1];
7184 char com[MAXFILLEN+1];
72 int linenumber = 0;
85 int isfile = 1;
7386 int status;
7487
7588 while (--argc > 0 && (c = (++argv)[0][0]) == '-' || c == '+') {
99112 if (command) {
100113 if (browser)
101114 die("-C option is valid only for mozilla.");
115 #ifndef _WIN32
102116 if (sendcommand(command) == -1)
103117 die("mozilla not found.");
118 #else
119 die("-C option isn't supported in WIN32 environment.");
120 #endif
104121 exit(0);
105122 }
106123 if (argc == 0)
107124 usage();
108 if (locatestring(argv[0], "http:", MATCH_AT_FIRST) ||
109 locatestring(argv[0], "ftp:", MATCH_AT_FIRST) ||
110 locatestring(argv[0], "news:", MATCH_AT_FIRST) ||
111 locatestring(argv[0], "mail:", MATCH_AT_FIRST) ||
112 locatestring(argv[0], "file:", MATCH_AT_FIRST))
125
126 if (isprotocol(argv[0])) {
127 isfile = 0;
113128 strcpy(URL, argv[0]);
114 else {
129 } else {
115130 char *abspath;
116131 char buf[MAXPATHLEN+1];
117132
119134 die1("path '%s' not found.", argv[0]);
120135 if (!(abspath = realpath(argv[0], buf)))
121136 die1("cannot make absolute path name. realpath(%s) failed.", argv[0]);
122 if (*abspath != '/')
137 if (!isabspath(abspath))
123138 die("realpath(3) is not compatible with BSD version.");
124139 if (issource(abspath)) {
125140 char cwd[MAXPATHLEN+1];
132147 * if GTAGS not found, getdbpath doesn't return.
133148 */
134149 getdbpath(cwd, root, dbpath);
135 if (test("d", makepath(dbpath, "HTML")))
136 strcpy(htmldir, makepath(dbpath, "HTML"));
137 else if (test("d", makepath(root, "HTML")))
138 strcpy(htmldir, makepath(root, "HTML"));
150 if (test("d", makepath(dbpath, "HTML", NULL)))
151 strcpy(htmldir, makepath(dbpath, "HTML", NULL));
152 else if (test("d", makepath(root, "HTML", NULL)))
153 strcpy(htmldir, makepath(root, "HTML", NULL));
139154 else
140155 die("hypertext not found. See htags(1).");
141156 /*
145160 if (convertpath(dbpath, htmldir, p, sb) == -1)
146161 die("cannot find the hypertext.");
147162 if (linenumber)
148 sprintf(URL, "file:%s#%d", strvalue(sb), linenumber);
163 sprintf(URL, "%s#%d", strvalue(sb), linenumber);
149164 else
150 sprintf(URL, "file:%s", strvalue(sb));
165 strcpy(URL, strvalue(sb));
151166 } else {
152 sprintf(URL, "file:%s", abspath);
167 strcpy(URL, abspath);
153168 }
154169 }
155170 if (pflag) {
167182 /*
168183 * send a command to mozilla.
169184 */
170 sprintf(com, "openURL(%s)", URL);
171 status = sendcommand(com);
185 status = sendmozilla(URL, isfile);
172186 /*
173187 * load mozilla if not found.
174188 */
175189 if (status != 0) {
176 int pid;
177
178 if ((pid = fork()) < 0) {
179 die("cannot execute netscape (fork).");
180 } else if (pid == 0) {
181 execlp("netscape", "netscape", URL, NULL);
182 die("loading mozilla failed.");
183 }
190 loadmozilla(URL);
184191 exit(0);
185192 }
186193 exit(status);
187194 }
195 /*
196 * isprotocol: return 1 if url has a procotol.
197 *
198 * i) url URL
199 * r) 1: protocol, 0: file
200 */
201 int
202 isprotocol(url)
203 char *url;
204 {
205 char *p;
206 /*
207 * protocol's style is like http://xxx.
208 */
209 for (p = url; *p && *p != ':'; p++)
210 if (!isalnum(*p))
211 return 0;
212 if (!*p)
213 return 0;
214 if (*p++ == ':' && *p++ == '/' && *p == '/')
215 return 1;
216 return 0;
217 }
218 /*
219 * issource: return 1 if path is a source file.
220 *
221 * i) path path
222 * r) 1: source file, 0: not source file
223 */
188224 int
189225 issource(path)
190226 char *path;
213249 return retval;
214250
215251 }
252 /*
253 * convertpath: convert source file into hypertext path.
254 *
255 * i) dbpath dbpath
256 * i) htmldir HTML directory made by htags(1)
257 * i) path source file path
258 * o) sb string buffer
259 * r) 0: normal, -1: error
260 */
216261 int
217262 convertpath(dbpath, htmldir, path, sb)
218263 char *dbpath;
220265 char *path;
221266 STRBUF *sb;
222267 {
223 char buf[MAXPATHLEN+1], *q = buf;
268 static const char *suffix[] = {".html", ".htm"};
269 static const char *gz = ".gz";
270 int i, lim = sizeof(suffix)/sizeof(char *);
224271 char *p;
225272
226 /*
227 * new style.
228 */
229273 strstart(sb);
230 strcpy(buf, "./");
231 strcat(buf, path + 1);
232 if (pathopen(dbpath, 0))
233 return -1;
234 p = pathget(buf);
235 pathclose();
236 if (p == NULL)
237 return -1;
238274 strputs(sb, htmldir);
239275 strputs(sb, "/S/");
240 strputs(sb, p);
241 strputs(sb, ".html");
242 if (test("f", strvalue(sb)))
243 return 0;
244 strpushback(sb, strlen(".html"));
245 strputs(sb, ".htm");
246 if (test("f", strvalue(sb)))
247 return 0;
276 /*
277 * new style.
278 */
279 if (pathopen(dbpath, 0) == 0) {
280 char key[MAXPATHLEN+1];
281
282 strcpy(key, "./");
283 strcat(key, path + 1);
284 p = pathget(key);
285 if (p == NULL) {
286 pathclose();
287 return -1;
288 }
289 strcpy(key, p);
290 pathclose();
291 strputs(sb, key);
292 for (i = 0; i < lim; i++) {
293 strputs(sb, suffix[i]);
294 if (test("f", strvalue(sb)))
295 return 0;
296 strputs(sb, gz);
297 if (test("f", strvalue(sb)))
298 return 0;
299 strpushback(sb, strlen(gz));
300 strpushback(sb, strlen(suffix[i]));
301 }
302 strpushback(sb, strlen(key));
303 }
248304 /*
249305 * old style.
250306 */
251 strputs(sb, htmldir);
252 strputs(sb, "/S/");
253307 for (p = path + 1; *p; p++)
254308 strputc(sb, (*p == '/') ? ' ' : *p);
255 strputs(sb, ".html");
256 if (test("f", strvalue(sb)))
257 return 0;
258 strpushback(sb, strlen(".html"));
259 strputs(sb, ".htm");
260 if (test("f", strvalue(sb)))
261 return 0;
262
309 for (i = 0; i < lim; i++) {
310 strputs(sb, suffix[i]);
311 if (test("f", strvalue(sb)))
312 return 0;
313 strputs(sb, gz);
314 if (test("f", strvalue(sb)))
315 return 0;
316 strpushback(sb, strlen(gz));
317 strpushback(sb, strlen(suffix[i]));
318 }
263319 return -1;
264320 }
321 /*
322 * sendmozilla: send URL to mozilla.
323 *
324 * i) url url or path
325 * i) isfile 1: file, 0: not file (protocol)
326 * r) -1: error, 0: normal
327 *
328 * Imprementation is based on
329 * [UNIX: X-property]
330 * See http://home.netscape.com/newsref/std/x-remote.html
331 * [WIN32: DDE]
332 * See http://developer.netscape.com/docs/manuals/communicator/DDE/abtdde.htm
333 */
334 #ifdef _WIN32
335 HDDEDATA CALLBACK DdemlCallback(hwnd, umsg, wparam, lparam)
336 HWND hwnd;
337 UINT umsg;
338 WPARAM wparam;
339 LPARAM lparam;
340 {
341 return(NULL);
342 }
343
344 int
345 sendmozilla(url, isfile)
346 char *url;
347 int isfile;
348 {
349 char com[MAXFILLEN+1];
350 int status;
351 DWORD dde = 0;
352 HSZ topic = NULL;
353 HSZ service = NULL;
354 HSZ command = NULL;
355 HCONV hconv = NULL;
356
357 /* load and initialize DDEML */
358 if (DdeInitialize(&dde, (PFNCALLBACK)MakeProcInstance((FARPROC)DdemlCallback, dde),
359 APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0) != 0)
360 die("Could not initialize DDEML.");
361
362 /* setup strings */
363 service = DdeCreateStringHandle(dde, "Netscape", CP_WINANSI);
364 topic = DdeCreateStringHandle(dde, "WWW_OpenURL", CP_WINANSI);
365
366 /* connect to server */
367 hconv = DdeConnect(dde, service, topic, NULL);
368 if (!hconv)
369 /* Could not connect to mozilla. We need to load mozilla. */
370 return -1;
371
372 if (isfile)
373 sprintf(com, "%s,,0xFFFFFFFF", url);
374 else
375 sprintf(com, "%s,,0xFFFFFFFF,0x4", url);
376 command = DdeCreateStringHandle(dde, com, CP_WINANSI);
377 /* send message to server */
378 if (!DdeClientTransaction((LPVOID)NULL, 0L, hconv, command,
379 CF_TEXT, XTYP_REQUEST, 1000L, NULL))
380 die1("Could not execute transaction(errorno = 0x%04x)\n", DdeGetLastError(dde));
381
382 DdeFreeStringHandle(dde, service);
383 DdeFreeStringHandle(dde, topic);
384 DdeFreeStringHandle(dde, command);
385
386 /* close connection */
387 DdeDisconnect(hconv);
388 DdeUninitialize(dde);
389
390 return 0;
391 }
392 #else
393 int
394 sendmozilla(url, isfile)
395 char *url;
396 int isfile;
397 {
398 char com[MAXFILLEN+1];
399
400 if (isfile)
401 sprintf(com, "openFile(%s)", url);
402 else
403 sprintf(com, "openURL(%s)", url);
404
405 return sendcommand(com);
406 }
265407 int
266408 sendcommand(com)
267 char *com;
268 {
409 char *com;
410 {
411 char *argv[5];
269412 int argc = 3;
270 char *argv[4];
271413
272414 argv[0] = "netscape-remote";
273 argv[1] = "-remote";
274 argv[2] = com;
275 argv[3] = NULL;
415 argv[1] = "-raise";
416 argv[2] = "-remote";
417 argv[3] = com;
418 argv[4] = NULL;
276419
277420 return netscape_remote(argc, argv);
278421 }
422 #endif
423 /*
424 * loadmozilla: load mozilla
425 *
426 * i) url URL
427 *
428 */
429 #ifdef _WIN32
430 void
431 loadmozilla(url)
432 char *url;
433 {
434 char com[1024], *path;
435 STARTUPINFO si;
436 PROCESS_INFORMATION pi;
437
438 if (!(path = usable("netscape")))
439 die("netscape not found in your path.");
440
441 ZeroMemory(&si, sizeof(STARTUPINFO));
442 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
443 si.cb = sizeof(STARTUPINFO);
444 si.dwFlags = STARTF_USESHOWWINDOW;
445 si.wShowWindow = SW_SHOWNORMAL;
446 sprintf(com, "netscape %s", url);
447 if (!CreateProcess(path, com, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
448 die1("Cannot load mozilla.(error = 0x%04x)\n", GetLastError());
449 exit(0);
450 }
451 #else
452 void
453 loadmozilla(url)
454 char *url;
455 {
456 int pid;
457
458 if ((pid = fork()) < 0) {
459 die("cannot load mozilla (fork).");
460 } else if (pid == 0) {
461 execlp("netscape", "netscape", url, NULL);
462 die("cannot load mozilla (execlp).");
463 }
464 }
465 #endif
00 .\"
1 .\" Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
1 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
25 .\"
36 .\" Redistribution and use in source and binary forms, with or without
47 .\" modification, are permitted provided that the following conditions
1013 .\" documentation and/or other materials provided with the distribution.
1114 .\" 3. All advertising materials mentioning features or use of this software
1215 .\" must display the following acknowledgement:
13 .\" This product includes software developed by Shigio Yamaguchi.
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
1418 .\" 4. Neither the name of the author nor the names of any co-contributors
1519 .\" may be used to endorse or promote products derived from this software
1620 .\" without specific prior written permission.
17 .\"
21 .\"
1822 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
137141 can treat not only source file but also normal file, directory, HTML file
138142 and even URL, because it is omnivorous.
139143 .Sh AUTHORS
140 Shigio Yamaguchi (shigio@wafu.netgate.net)
144 Shigio Yamaguchi (shigio@tamacom.com)
141145 .Sh HISTORY
142146 The
143147 .Nm
0 PROG= gtags
1
2 .include <bsd.prog.mk>
00 PROG = gtags
11 CC = gcc
2 LIBS = -L../libutil -lgloutil -L../libdb -lglodb
3 CFLAGS = -O -I../libutil
4 DEPLIBS= ../libutil/libgloutil.a
2 LIBS = ../libutil/libgloutil.a ../libdb/libglodb.a ../libregex/libgloregex.a
3 CFLAGS = -O -I../libutil -I../libdb -I../libregex -I../machine
54 OBJS = gtags.o
65 BINDIR = /usr/bin
76 MANDIR = /usr/man
87
98 all: $(PROG)
109
11 $(PROG): $(OBJS) $(DEPLIBS)
10 $(PROG): $(OBJS) $(LIBS)
1211 $(CC) -o $(PROG) $(OBJS) $(LIBS)
1312 install:
1413 cp $(PROG) $(BINDIR)
1514 chmod 755 $(BINDIR)/$(PROG)
1615 cp $(PROG).1 $(MANDIR)/man1
1716 chmod 644 $(MANDIR)/man1/$(PROG).1
17 cygwin_install:
18 cp $(PROG).exe $(BINDIR)
19 chmod 755 $(BINDIR)/$(PROG).exe
20 cp $(PROG).1 $(MANDIR)/man1
21 chmod 644 $(MANDIR)/man1/$(PROG).1
1822 clean:
1923 rm -f $(PROG) $(OBJS)
0 PROG = gtags.exe
1 CC = bcc32
2 LIBS = ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = gtags.obj
5 BINDIR = \usr\bin
6 MANDIR = \usr\man
7
8 all: $(PROG)
9
10 $(PROG): $(OBJS) $(LIBS)
11 $(CC) -e$(PROG) $(OBJS) @../win32/libs
12 install:
13 copy $(PROG) $(BINDIR)
14 copy $(PROG).1 $(MANDIR)/man1
15 clean:
16 del $(PROG)
17 del *.obj
00 .\"
11 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
35 .\"
46 .\" Redistribution and use in source and binary forms, with or without
57 .\" modification, are permitted provided that the following conditions
1113 .\" documentation and/or other materials provided with the distribution.
1214 .\" 3. All advertising materials mentioning features or use of this software
1315 .\" must display the following acknowledgement:
14 .\" This product includes software developed by Shigio Yamaguchi.
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
1518 .\" 4. Neither the name of the author nor the names of any co-contributors
1619 .\" may be used to endorse or promote products derived from this software
1720 .\" without specific prior written permission.
18 .\"
21 .\"
1922 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2023 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2124 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2831 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2932 .\" SUCH DAMAGE.
3033 .\"
31 .Dd Mar 19, 1999
34 .Dd Aug 27, 1999
3235 .Dt GTAGS 1
3336 .Os BSD 4
3437 .Sh NAME
4952 .Nm Gtags
5053 trace subdirectories, read source files,
5154 locate symbols and save the information into tag files.
52 C, yacc, java and assembler source files are supported.
55 C, C++, yacc, java and assembler source files are supported.
5356 You should execute this command at the root of the source tree.
5457 .Pp
5558 If your source directory is on a read only device like CDROM, specify
6972 print warning messages.
7073 .It Fl v
7174 verbose mode.
75 .El
76 .Pp
77 Files whose names end in
78 .Nm \&.c
79 or
80 .Nm \&.h
81 are assumed to be C
82 source files and are searched for C style routine and macro definitions.
83 Files whose names end in
84 .Nm \&.c++
85 .Nm \&.cc
86 .Nm \&.cpp
87 .Nm \&.cxx
88 .Nm \&.hxx
89 .Nm \&.C
90 .Nm \&.H
91 are assumed to be C++
92 source files.
93 Files whose names end in
94 .Nm \&.y
95 are assumed to be
96 .Tn YACC
97 source files.
98 Files whose names end in
99 .Nm \&.java
100 are assumed to be Java source files.
101 Files whose names end in
102 .Nm \&.s
103 or
104 .Nm \&.S
105 are assumed to be Assembler
106 source files. Other files are searched for C style definitions.
72107 .Sh FILES
73108 .Bl -tag -width tags -compact
74109 .It Pa GTAGS
85120 exits with a non 0 value if an error occurred, 0 otherwise.
86121 .Sh SEE ALSO
87122 .Xr btreeop 1 ,
123 .Xr gctags 1 ,
88124 .Xr global 1 ,
89125 .Xr htags 1 ,
90126 .Xr vi 1 .
98134 .br
99135 There is no concurrency control about tag files.
100136 .Sh AUTHORS
101 Shigio Yamaguchi (shigio@wafu.netgate.net)
137 Shigio Yamaguchi (shigio@tamacom.com)
102138 .Sh HISTORY
103139 The
104140 .Nm
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * gtags.c 8-Oct-98
34 * gtags.c 17-Aug-99
3135 *
3236 */
3337 #include <sys/types.h>
3438 #include <sys/stat.h>
3539
3640 #include <ctype.h>
41 #include <signal.h>
3742 #include <stdio.h>
3843 #include <stdlib.h>
3944 #include <string.h>
4449
4550 const char *progname = "gtags"; /* command name */
4651
47 static void usage __P((void));
48 int main __P((int, char **));
49 int incremental __P((char *, char *));
50 void updatetags __P((char *, char *, char *, int));
51 void createtags __P((char *, char *, int));
52 int printconf __P((char *));
53 char *now __P((void));
52 static void usage(void);
53 void signal_setup(void);
54 void onintr(int);
55 int main(int, char **);
56 int incremental(char *, char *);
57 void updatetags(char *, char *, char *, int);
58 void createtags(char *, char *, int);
59 int printconf(char *);
60 char *now(void);
5461
5562 int cflag; /* compact format */
63 int dflag; /* DEBUG */
5664 int iflag; /* incremental update */
5765 int oflag; /* suppress making GSYMS */
5866 int wflag; /* warning message */
6573 {
6674 fprintf(stderr, "usage:\t%s [-c][-i][-l][-o][-w][-v][dbpath]\n", progname);
6775 exit(1);
76 }
77 /*
78 * Gtags catch signal even if the parent ignore it.
79 */
80 int exitflag = 0;
81
82 void
83 onintr(signo)
84 int signo;
85 {
86 exitflag = 1;
87 }
88
89 void
90 signal_setup()
91 {
92 signal(SIGINT, onintr);
93 signal(SIGTERM, onintr);
94 #ifdef SIGHUP
95 signal(SIGHUP, onintr);
96 #endif
97 #ifdef SIGQUIT
98 signal(SIGQUIT, onintr);
99 #endif
68100 }
69101
70102 int
110142 while ((p = mgets(ip, NULL, 0)) != NULL)
111143 detab(stdout, p);
112144 exit(0);
145 } else if (!strcmp(argv[0], "--debug")) {
146 dflag = 1;
147 continue;
148 } else if (!strcmp(argv[0], "--version")) {
149 fprintf(stdout, "%s\n", VERSION);
150 exit(0);
113151 }
114152
115153 for (p = argv[0] + 1; *p; p++) {
135173 break;
136174 default:
137175 usage();
176 break;
138177 }
139178 }
140179 }
141180 if (!getcwd(cwd, MAXPATHLEN))
142181 die("cannot get current directory.");
182 canonpath(cwd);
143183 if (argc > 0)
144184 realpath(*argv,dbpath) ;
145185 else
146186 strcpy(dbpath, cwd);
187 #ifndef _WIN32
147188 if (!strcmp(dbpath, "/"))
148189 die("It's root directory! What are you doing?");
190 #endif
149191 if (!test("d", dbpath))
150192 die1("directory '%s' not found.", dbpath);
151193 if (vflag)
171213 /*
172214 * incremental update.
173215 */
174 if (iflag && test("f", makepath(dbpath, dbname(GTAGS))) &&
175 test("f", makepath(dbpath, dbname(GRTAGS))))
216 if (iflag && test("f", makepath(dbpath, dbname(GTAGS), NULL)) &&
217 test("f", makepath(dbpath, dbname(GRTAGS), NULL)))
176218 {
177219 /* open for version check */
178220 GTOP *gtop = gtagsopen(dbpath, cwd, GTAGS, GTAGS_MODIFY, 0);
179221 gtagsclose(gtop);
180 if (!test("f", makepath(dbpath, "GPATH")))
222 if (!test("f", makepath(dbpath, "GPATH", NULL)))
181223 die("Old version tag file found. Please remake it.");
182224 (void)incremental(dbpath, cwd);
183225 exit(0);
187229 /*
188230 * create GTAGS, GRTAGS and GSYMS
189231 */
232 signal_setup();
190233 for (db = GTAGS; db < GTAGLIM; db++) {
191234
192235 if (oflag && db == GSYMS)
199242 if (vflag)
200243 fprintf(stderr, "[%s] Creating '%s'.\n", now(), dbname(db));
201244 createtags(dbpath, cwd, db);
202 }
203
245 if (exitflag)
246 exit(1);
247 }
204248 if (vflag)
205249 fprintf(stderr, "[%s] Done.\n", now());
206250 closeconf();
233277 /*
234278 * get modified time of GTAGS.
235279 */
236 path = makepath(dbpath, dbname(GTAGS));
280 path = makepath(dbpath, dbname(GTAGS), NULL);
237281 if (stat(path, &statp) < 0)
238282 die1("stat failed '%s'.", path);
239283 gtags_mtime = statp.st_mtime;
273317 /*
274318 * execute updating.
275319 */
320 signal_setup();
276321 if (strbuflen(updatelist) > 0) {
277322 char *start = strvalue(updatelist);
278323 char *end = start + strbuflen(updatelist);
279324 char *p;
280325
281 for (p = start; p < end; p += strlen(p) + 1)
326 for (p = start; p < end; p += strlen(p) + 1) {
282327 updatetags(dbpath, root, p, 0);
328 if (exitflag)
329 exit(1);
330 }
283331 updated = 1;
284332 }
285333 if (strbuflen(addlist) > 0) {
287335 char *end = start + strbuflen(addlist);
288336 char *p;
289337
290 for (p = start; p < end; p += strlen(p) + 1)
338 for (p = start; p < end; p += strlen(p) + 1) {
291339 updatetags(dbpath, root, p, 1);
340 if (exitflag)
341 exit(1);
342 }
292343 updated = 1;
293344 }
294345 if (strbuflen(deletelist) > 0) {
296347 char *end = start + strbuflen(deletelist);
297348 char *p;
298349
299 for (p = start; p < end; p += strlen(p) + 1)
350 for (p = start; p < end; p += strlen(p) + 1) {
300351 updatetags(dbpath, root, p, 2);
352 if (exitflag)
353 exit(1);
354 }
301355
302356 pathopen(dbpath, 2);
303 for (p = start; p < end; p += strlen(p) + 1)
357 for (p = start; p < end; p += strlen(p) + 1) {
358 if (exitflag)
359 break;
304360 pathdel(p);
361 }
305362 pathclose();
306363 updated = 1;
307364 }
365 if (exitflag)
366 exit(1);
308367 if (vflag) {
309368 if (updated)
310369 fprintf(stderr, " Global databases have been modified.\n");
345404 if (vflag)
346405 fprintf(stderr, " %s tags of '%s' ...", msg, path + 2);
347406 for (db = GTAGS; db < GTAGLIM; db++) {
348 int flags = 0;
349
350 if (db == GSYMS && !test("f", makepath(dbpath, dbname(db))))
407 int gflags = 0;
408
409 if (exitflag)
410 break;
411 if (db == GSYMS && !test("f", makepath(dbpath, dbname(db), NULL)))
351412 continue;
352413 if (vflag)
353414 fprintf(stderr, "%s", dbname(db));
361422 /*
362423 * GTAGS needed to make GRTAGS.
363424 */
364 if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS")))
425 if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS", NULL)))
365426 die("GTAGS needed to create GRTAGS.");
366427 if (type != 1)
367428 gtagsdelete(gtop, path);
369430 fprintf(stderr, "..");
370431 if (type != 2) {
371432 if (db == GSYMS)
372 flags |= GTAGS_UNIQUE;
433 gflags |= GTAGS_UNIQUE;
373434 if (extractmethod)
374 flags |= GTAGS_EXTRACTMETHOD;
375 gtagsadd(gtop, strvalue(sb), path, flags);
435 gflags |= GTAGS_EXTRACTMETHOD;
436 if (dflag)
437 gflags |= GTAGS_DEBUG;
438 gtagsadd(gtop, strvalue(sb), path, gflags);
376439 }
377440 gtagsclose(gtop);
378441 }
442 strclose(sb);
443 if (exitflag)
444 return;
379445 if (vflag)
380446 fprintf(stderr, " Done.\n");
381 strclose(sb);
382447 }
383448 /*
384449 * createtags: create tags file
410475 /*
411476 * GTAGS needed to make GRTAGS.
412477 */
413 if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS")))
478 if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS", NULL)))
414479 die("GTAGS needed to create GRTAGS.");
415480 flags = 0;
416481 strstart(sb);
424489 gtop = gtagsopen(dbpath, root, db, GTAGS_CREATE, flags);
425490 for (findopen(); (path = findread(NULL)) != NULL; ) {
426491 int gflags = 0;
492
493 if (exitflag)
494 break;
427495 /*
428496 * GSYMS doesn't treat asembler.
429497 */
439507 gflags |= GTAGS_UNIQUE;
440508 if (extractmethod)
441509 gflags |= GTAGS_EXTRACTMETHOD;
510 if (dflag)
511 gflags |= GTAGS_DEBUG;
442512 gtagsadd(gtop, comline, path, gflags);
443513 }
444514 findclose();
00 ;;; gtags.el --- gtags facility for Emacs
11
22 ;;
3 ;; Copyright (c) 1997, 1998, 1999 Shigio Yamaguchi. All rights reserved.
3 ;; Copyright (c) 1996, 1997, 1998, 1999
4 ;; Shigio Yamaguchi. All rights reserved.
5 ;; Copyright (c) 1999
6 ;; Tama Communications Corporation. All rights reserved.
47 ;;
58 ;; Redistribution and use in source and binary forms, with or without
69 ;; modification, are permitted provided that the following conditions
1215 ;; documentation and/or other materials provided with the distribution.
1316 ;; 3. All advertising materials mentioning features or use of this software
1417 ;; must display the following acknowledgement:
15 ;; This product includes software developed by Shigio Yamaguchi.
18 ;; This product includes software developed by Tama Communications
19 ;; Corporation and its contributors.
1620 ;; 4. Neither the name of the author nor the names of any co-contributors
1721 ;; may be used to endorse or promote products derived from this software
1822 ;; without specific prior written permission.
19 ;;
23 ;;
2024 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2125 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2226 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2933 ;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3034 ;; SUCH DAMAGE.
3135 ;;
32 ;; gtags.el 10-Jan-99
36 ;; gtags.el 17-Sep-99
3337 ;;
3438
3539 ;; This file is part of GLOBAL.
36 ;; Author: Shigio Yamaguchi <shigio@wafu.netgate.net>
37 ;; Version: 1.51
40 ;; GLOBAL home page is at: http://www.tamacom.com/global/
41 ;; Author: Shigio Yamaguchi <shigio@tamacom.com>
42 ;; Version: 1.53
3843 ;; Keywords: tools
3944
4045 ;;; Code
4550 "Stack for tag browsing.")
4651 (defvar gtags-complete-list nil
4752 "Gtags complete list.")
53 (defvar gtags-history-list nil
54 "Gtags history list.")
4855 (defconst symbol-regexp "[A-Za-z_][A-Za-z_0-9]*"
4956 "Regexp matching tag name.")
5057 (defconst definition-regexp "#[ \t]*define[ \t]+\\|ENTRY(\\|ALTENTRY("
5360 "Gtags read only mode")
5461 (defvar gtags-mode-map (make-sparse-keymap)
5562 "Keymap used in gtags mode.")
63 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
64 "Whether we are running XEmacs/Lucid Emacs")
5665 (define-key gtags-mode-map "\et" 'gtags-find-tag)
5766 (define-key gtags-mode-map "\er" 'gtags-find-rtag)
5867 (define-key gtags-mode-map "\es" 'gtags-find-symbol)
5968 (define-key gtags-mode-map "\eg" 'gtags-find-pattern)
69 (define-key gtags-mode-map "\el" 'gtags-find-file)
6070 (define-key gtags-mode-map "\ec" 'gtags-make-complete-list)
6171 (define-key gtags-mode-map "\C-]" 'gtags-find-tag-from-here)
6272 (define-key gtags-mode-map "\eh" 'gtags-display-browser)
6373 (define-key gtags-mode-map "\C-t" 'gtags-pop-stack)
6474 (define-key gtags-mode-map "\e." 'etags-style-find-tag)
65 (define-key gtags-mode-map [mouse-2] 'gtags-find-tag-by-event)
66 (define-key gtags-mode-map [mouse-3] 'gtags-pop-stack)
75 (if (not running-xemacs) nil
76 (define-key gtags-mode-map 'button2 'gtags-find-tag-by-event)
77 (define-key gtags-mode-map 'button3 'gtags-pop-stack))
78 (if running-xemacs nil
79 (define-key gtags-mode-map [mouse-2] 'gtags-find-tag-by-event)
80 (define-key gtags-mode-map [mouse-3] 'gtags-pop-stack))
6781
6882 (defvar gtags-select-mode-map (make-sparse-keymap)
6983 "Keymap used in gtags select mode.")
7892 (define-key gtags-select-mode-map "p" 'previous-line)
7993 (define-key gtags-select-mode-map "j" 'next-line)
8094 (define-key gtags-select-mode-map "k" 'previous-line)
81 (define-key gtags-select-mode-map [mouse-2] 'gtags-select-tag-by-event)
82 (define-key gtags-select-mode-map [mouse-3] 'gtags-pop-stack)
95 (if (not running-xemacs) nil
96 (define-key gtags-select-mode-map 'button2 'gtags-select-tag-by-event)
97 (define-key gtags-select-mode-map 'button3 'gtags-pop-stack))
98 (if running-xemacs nil
99 (define-key gtags-select-mode-map [mouse-2] 'gtags-select-tag-by-event)
100 (define-key gtags-select-mode-map [mouse-3] 'gtags-pop-stack))
83101
84102 ;;
85103 ;; utility
154172 (defun gtags-find-tag ()
155173 "Input tag name and move to the definition."
156174 (interactive)
157 (let (tagname)
158 (setq tagname (completing-read ":tag " gtags-complete-list))
175 (let (tagname prompt input)
176 (setq tagname (gtags-current-token))
177 (if tagname
178 (setq prompt (concat ":tag (default " tagname ") "))
179 (setq prompt ":tag "))
180 (setq input (completing-read prompt gtags-complete-list
181 nil nil nil gtags-history-list))
182 (if (not (equal "" input))
183 (setq tagname input))
159184 (push-context)
160185 (gtags-goto-tag tagname "")))
161186
198223 (push-context)
199224 (gtags-goto-tag tagname "g")))
200225
226 (defun gtags-find-file ()
227 "Input pattern and move to the top of the file."
228 (interactive)
229 (let (tagname prompt input)
230 (setq prompt "Find files: ")
231 (setq input (read-string prompt))
232 (if (not (equal "" input)) (setq tagname input))
233 (push-context)
234 (gtags-goto-tag tagname "P")))
235
201236 (defun gtags-find-rtag ()
202237 "Input tag name and move to the referenced point."
203238 (interactive)
204 (let (tagname)
205 (setq tagname (completing-read ":rtag " gtags-complete-list))
239 (let (tagname prompt input)
240 (setq tagname (gtags-current-token))
241 (if tagname
242 (setq prompt (concat ":rtag (default " tagname ") "))
243 (setq prompt ":rtag "))
244 (setq input (completing-read prompt gtags-complete-list
245 nil nil nil gtags-history-list))
246 (if (not (equal "" input))
247 (setq tagname input))
206248 (push-context)
207249 (gtags-goto-tag tagname "r")))
208250
223265 "Display current screen on hypertext browser."
224266 (interactive)
225267 (let (lno)
268 (if (= 0 (count-lines (point-min) (point-max))) nil
226269 (save-excursion
227270 (end-of-line)
228271 (if (equal (point-min) (point))
229272 (setq lno 1)
230273 (setq lno (count-lines (point-min) (point)))))
231 (message (number-to-string lno))
232 (call-process "gozilla" nil t nil (concat "+" (number-to-string lno)) buffer-file-name)))
274 ; (message (number-to-string lno))
275 (call-process "gozilla" nil t nil (concat "+" (number-to-string lno)) buffer-file-name))))
233276
234277 (defun gtags-find-tag-by-event (event)
235278 "Get the expression as a tagname around here and move there."
236279 (interactive "e")
237 (select-window (posn-window (event-end event)))
238 (set-buffer (window-buffer (posn-window (event-end event))))
239 (goto-char (posn-point (event-end event)))
240280 (let (tagname flag)
241281 (if (= 0 (count-lines (point-min) (point-max)))
242282 (progn (setq tagname "main") (setq flag ""))
283 (if running-xemacs (goto-char (event-point event))
284 (select-window (posn-window (event-end event)))
285 (set-buffer (window-buffer (posn-window (event-end event))))
286 (goto-char (posn-point (event-end event))))
243287 (setq tagname (gtags-current-token))
244288 (if (is-function)
245289 (if (is-definition) (setq flag "r") (setq flag ""))
258302 (defun gtags-select-tag-by-event (event)
259303 "Select a tagname in [GTAGS SELECT MODE] and move there."
260304 (interactive "e")
261 (select-window (posn-window (event-end event)))
262 (set-buffer (window-buffer (posn-window (event-end event))))
263 (goto-char (posn-point (event-end event)))
305 (if running-xemacs (goto-char (event-point event))
306 (select-window (posn-window (event-end event)))
307 (set-buffer (window-buffer (posn-window (event-end event))))
308 (goto-char (posn-point (event-end event))))
264309 (push-context)
265310 (gtags-select-it nil))
266311
287332 (let (save prefix buffer lines)
288333 (setq save (current-buffer))
289334 (cond
335 ((equal flag "P")
336 (setq prefix "(P)"))
290337 ((equal flag "g")
291338 (setq prefix "(G)"))
292339 ((equal flag "s")
297344 ;; load tag
298345 (setq buffer (generate-new-buffer (generate-new-buffer-name (concat prefix tagname))))
299346 (set-buffer buffer)
347 (if (equal flag "g") (message "Searching...%s" tagname))
300348 (if (not (= 0 (call-process "global" nil t nil (concat "-ax" flag) tagname)))
301349 (progn (message (buffer-substring (point-min)(1- (point-max))))
302350 (pop-context))
304352 (setq lines (count-lines (point-min) (point-max)))
305353 (cond
306354 ((= 0 lines)
307 (message "%s: tag not found" tagname)
355 (cond
356 ((equal flag "P")
357 (message "%s: path not found" tagname))
358 ((equal flag "g")
359 (message "%s: pattern not found" tagname))
360 ((equal flag "s")
361 (message "%s: symbol not found" tagname))
362 (t
363 (message "%s: tag not found" tagname)))
308364 (pop-context)
309365 (kill-buffer buffer)
310366 (set-buffer save))
0 MAN1= htags.1
1
2 beforeinstall:
3 ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
4 ${.CURDIR}/htags.pl ${DESTDIR}${BINDIR}/htags
5
6 .include <bsd.prog.mk>
77 chmod 755 $(BINDIR)/$(PROG)
88 cp $(PROG).1 $(MANDIR)/man1
99 chmod 644 $(MANDIR)/man1/$(PROG).1
10 cygwin_install: install
1011 clean:
0 PROG = htags.pl
1 CC = bcc32
2 BINDIR = \usr\bin
3 MANDIR = \usr\man
4
5 all: $(PROG)
6
7 $(PROG):
8 @echo -n
9 install:
10 copy $(PROG) $(BINDIR)
11 copy $(PROG).1 $(MANDIR)/man1
12 clean:
13 @echo -n
00 .\"
1 .\" Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 .\" Copyright (c) 1996, 1997, 1998, 1999
2 .\" Shigio Yamaguchi. All rights reserved.
3 .\" Copyright (c) 1999
4 .\" Tama Communications Corporation. All rights reserved.
25 .\"
36 .\" Redistribution and use in source and binary forms, with or without
47 .\" modification, are permitted provided that the following conditions
1013 .\" documentation and/or other materials provided with the distribution.
1114 .\" 3. All advertising materials mentioning features or use of this software
1215 .\" must display the following acknowledgement:
13 .\" This product includes software developed by Shigio Yamaguchi.
16 .\" This product includes software developed by Tama Communications
17 .\" Corporation and its contributors.
1418 .\" 4. Neither the name of the author nor the names of any co-contributors
1519 .\" may be used to endorse or promote products derived from this software
1620 .\" without specific prior written permission.
17 .\"
21 .\"
1822 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 .\" SUCH DAMAGE.
2933 .\"
30 .Dd Oct 11, 1998
34 .Dd Aug 27, 1999
3135 .Dt HTAGS 1
3236 .Os BSD 4
3337 .Sh NAME
3438 .Nm htags
35 .Nd generate hypertext from C, Yacc and Java source code
39 .Nd generate hypertext from C, C++, Yacc, Java and assembler source code
3640 .Sh SYNOPSIS
3741 .Nm htags
3842 .Op Fl a
8286 .It Fl l
8387 Make a name tag(<A NAME=line number>) for each line, so that other hypertext
8488 can link to any line of this hypertext.
85 By default, htags makes it only for lines that are referred to by an object.
89 By default, htags makes it only for lines that are referred to.
8690 .It Fl n
8791 Print the line numbers. By default, doesn't print that.
8892 .It Fl v
9397 Specifies the directory in which GTAGS and GRTAGS exist. The default is the
9498 current directory.
9599 .It Fl t Ar title
96 The title of this hypertext. Defaults to the last component of the current
97 path.
100 The title of this hypertext. The default is the last component of the
101 current directory.
98102 .It Ar dir
99103 The directory in which hypertext is generated. The default is the current
100104 directory.
101105 .Sh EXAMPLES
102106 % cd /usr/src/sys
103 # gtags -o
107 # gtags
104108 # htags -fnvat 'Welcom to FreeBSD kernel source tour!'
105109 % lynx HTML/index.html
106110 .Sh FILES
129133 .Sh BUG
130134 Generated hypertext is VERY LARGE. In advance, check the space of your disk.
131135 .Sh AUTHORS
132 Shigio Yamaguchi (shigio@wafu.netgate.net)
136 Shigio Yamaguchi (shigio@tamacom.com)
133137 .Sh HISTORY
134138 The
135139 .Nm
0 #!/usr/bin/perl
0 #!/usr/bin/env perl
11 #
22 # Copyright (c) 1996, 1997, 1998, 1999
3 # Shigio Yamaguchi. All rights reserved.
3 # Shigio Yamaguchi. All rights reserved.
4 # Copyright (c) 1999
5 # Tama Communications Corporation. All rights reserved.
46 #
57 # Redistribution and use in source and binary forms, with or without
68 # modification, are permitted provided that the following conditions
1214 # documentation and/or other materials provided with the distribution.
1315 # 3. All advertising materials mentioning features or use of this software
1416 # must display the following acknowledgement:
15 # This product includes software developed by Shigio Yamaguchi.
17 # This product includes software developed by Tama Communications
18 # Corporation and its contributors.
1619 # 4. Neither the name of the author nor the names of any co-contributors
1720 # may be used to endorse or promote products derived from this software
1821 # without specific prior written permission.
19 #
22 #
2023 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2124 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2225 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2932 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3033 # SUCH DAMAGE.
3134 #
32 # htags.pl 29-Mar-99
35 # htags.pl 3-Nov-99
3336 #
3437 $com = $0;
3538 $com =~ s/.*\///;
36 $usage = "usage: $com [-a][-c][-f][-h][-l][-n][-v][-w][-t title][-d tagdir][--action=url][--id=id][dir]\n";
39 $usage = "usage: $com [-a][-c][-f][-h][-l][-n][-v][-w][-t title][-d tagdir][dir]\n";
40 $'win32 = ($^O =~ /^ms(dos|win(32|nt))/i) ? 1 : 0;
41 $'pathsep = ($'win32) ? ';' : ':';
3742 #-------------------------------------------------------------------------
3843 # COMMAND EXISTENCE CHECK
3944 #-------------------------------------------------------------------------
4954 $'tmp = '/tmp';
5055 if (defined($ENV{'TMPDIR'}) && -d $ENV{'TMPDIR'}) {
5156 $tmp = $ENV{'TMPDIR'};
57 }
58 if (! -d $tmp || ! -w $tmp) {
59 &'error("temporary directory '$tmp' not exist or not writable.");
5260 }
5361 $'ncol = 4; # columns of line number
5462 $'tabs = 8; # tab skip
159167 $'begin_html = "<HTML>";
160168 $'end_html = "</HTML>";
161169 $'meta_robots = "<META NAME='ROBOTS' CONTENT='NOINDEX,NOFOLLOW'>";
170 $'meta_generator = "<META NAME='GENERATOR' CONTENT='GLOBAL'>";
162171 $'begin_body = '<BODY';
163172 $'begin_body .= " BGCOLOR=$body_bgcolor" if ($body_bgcolor);
164173 $'begin_body .= " TEXT=$body_text" if ($body_text);
203212 "}\n";
204213 sub set_header {
205214 local($display, $title, $script) = @_;
206 local($head) = "<HEAD><TITLE>$title</TITLE>\n$'meta_robots";
215 local($head) = "<HEAD><TITLE>$title</TITLE>\n$'meta_robots\n$'meta_generator";
207216 if ($script || ($'hflag && $display)) {
208217 $head .= "\n";
209218 $head .= $'begin_script;
227236 # UTILITIES
228237 #-------------------------------------------------------------------------
229238 sub getcwd {
230 local($dir) = `/bin/pwd`;
239 local($dir) = `pwd`;
231240 chop($dir);
232241 $dir;
233242 }
259268 }
260269 sub usable {
261270 local($command) = @_;
262 foreach (split(/:/, $ENV{'PATH'})) {
263 return 1 if (-x "$_/$command");
271 foreach (split(/$'pathsep/, $ENV{'PATH'})) {
272 if ($win32) {
273 return 1 if (-f "$_/$command.com");
274 return 1 if (-f "$_/$command.exe");
275 } else {
276 return 1 if (-x "$_/$command");
277 }
264278 }
265279 return 0;
266280 }
267281 sub copy {
268282 local($from, $to) = @_;
269 local($ret) = system("cp $from $to");
270 $ret = $ret / 256;
271 $ret = ($ret == 0) ? 1 : 0;
272 $ret;
283 open(FROM, $from) || return 0;
284 open(TO, ">$to") || return 0;
285 print TO <FROM>;
286 close(TO);
287 close(FROM);
288 return 1;
273289 }
274290 sub getconf {
275291 local($name) = @_;
301317 $'id = $1;
302318 } elsif ($opt =~ /^--nocgi$/) {
303319 $'cgi = 0;
320 } elsif ($opt =~ /^--version$/) {
321 system("gtags --version");
322 exit 0;
304323 } elsif ($opt =~ /[^-acfhlnvwtd]/) {
305324 print STDERR $usage;
306325 exit 1;
336355 unless (-r "$dbpath/GTAGS" && -r "$dbpath/GRTAGS") {
337356 &'error("GTAGS and GRTAGS not found. Please make them.");
338357 }
358 if ($'fflag && ! -r "$dbpath/GSYMS") {
359 &'error("-f option needs GSYMS. Please make it.");
360 }
339361 $dbpath = &'realpath($dbpath);
340362 #
341363 # for global(1)
380402 # HTML/cgi-bin/ghtml.cgi ... unzip script (1)
381403 # HTML/.htaccess.skel ... skelton of .htaccess (1)
382404 # HTML/help.html ... help file (2)
383 # HTML/$REFS/* ... referencies (3)
405 # HTML/$REFS/* ... references (3)
384406 # HTML/$DEFS/* ... definitions (3)
385407 # HTML/funcs.html ... function index (4)
386408 # HTML/funcs/* ... function index (4)
412434 print STDERR "[", &'date, "] ", "(1) making CGI program ...\n" if ($'vflag);
413435 &makeprogram("$dist/cgi-bin/global.cgi") || &'error("cannot make CGI program.");
414436 chmod(0755, "$dist/cgi-bin/global.cgi") || &'error("cannot chmod CGI program.");
415 unlink("$dist/cgi-bin/GTAGS", "$dist/cgi-bin/GRTAGS", "$dist/cgi-bin/GPATH");
437 unlink("$dist/cgi-bin/GTAGS", "$dist/cgi-bin/GRTAGS", "$dist/cgi-bin/GSYMS", "$dist/cgi-bin/GPATH");
416438 link("$dbpath/GTAGS", "$dist/cgi-bin/GTAGS") || &'copy("$dbpath/GTAGS", "$dist/cgi-bin/GTAGS") || &'error("cannot copy GTAGS.");
417439 link("$dbpath/GRTAGS", "$dist/cgi-bin/GRTAGS") || &'copy("$dbpath/GRTAGS", "$dist/cgi-bin/GRTAGS") || &'error("cannot copy GRTAGS.");
440 link("$dbpath/GSYMS", "$dist/cgi-bin/GSYMS") || &'copy("$dbpath/GSYMS", "$dist/cgi-bin/GSYMS") || &'error("cannot copy GSYMS.");
418441 link("$dbpath/GPATH", "$dist/cgi-bin/GPATH") || &'copy("$dbpath/GPATH", "$dist/cgi-bin/GPATH") || &'error("cannot copy GPATH.");
419442 }
420443 if ($'cgi && $'cflag) {
454477 $SIG{'INT'} = 'suddenly';
455478 $SIG{'QUIT'} = 'suddenly';
456479 $SIG{'TERM'} = 'suddenly';
457 &cache'open(100000);
480 &cache'open();
458481 $func_total = &makedupindex($dist);
459482 print STDERR "Total $func_total functions.\n" if ($'vflag);
460483 #
506529 print STDERR "[Information]\n";
507530 print STDERR "\n";
508531 if ($'cflag) {
509 print STDERR " You need to setup http server so that '*.$'gzipped_suffix' are treated\n";
510 print STDERR " as gzipped files. Please see 'HTML/.htaccess.skel'.\n";
532 print STDERR " Your system may need to be setup to decompress *.$'gzipped_suffix files.\n";
533 print STDERR " This can be done by having your browser compiled with the relevant\n";
534 print STDERR " options, or by configuring your http server to treat these as\n";
535 print STDERR " gzipped files. (Please see 'HTML/.htaccess.skel')\n";
511536 print STDERR "\n";
512537 }
513538 if ($'fflag) {
549574 }
550575 if (\$form{'pattern'} eq '') {
551576 print "<H3>Pattern not specified. <A HREF=../mains.$'normal_suffix>[return]</A></H3>\\n";
552 print "$'end_body$'end_html";
577 print "$'end_body$'end_html\n";
553578 exit 0;
554579 }
555580 \$pattern = \$form{'pattern'};
556 \$flag = (\$form{'type'} eq 'definition') ? '' : 'r';
557 \$words = (\$form{'type'} eq 'definition') ? 'definitions' : 'referencies';
581 \$flag = '';
582 \$words = 'definitions';
583 if (\$form{'type'} eq 'reference') {
584 \$flag = 'r';
585 \$words = 'references';
586 } elsif (\$form{'type'} eq 'symbol') {
587 \$flag = 's';
588 \$words = 'symbols';
589 }
558590 print "<H1><FONT COLOR=#cc0000>\" . \$pattern . \"</FONT></H1>\\n";
559591 print "Following \$words are matched to above pattern.<HR>\\n";
560592 \$pattern =~ s/'//g; # to shut security hole
561 unless (open(PIPE, "/usr/bin/global -x\$flag '\$pattern' |")) {
593 unless (open(PIPE, "/usr/bin/global -x\$flag \\"\$pattern\\" |")) {
562594 print "<H3>Cannot execute global. <A HREF=../mains.$'normal_suffix>[return]</A></H3>\\n";
563 print "$'end_body$'end_html";
595 print "$'end_body$'end_html\n";
564596 exit 0;
565597 }
566598 \$cnt = 0;
578610 if (\$cnt == 0) {
579611 print "<H3>Pattern not found. <A HREF=../mains.$'normal_suffix>[return]</A></H3>\\n";
580612 }
581 print "$'end_body$'end_html";
613 print "$'end_body$'end_html\n";
582614 exit 0;
583615 #------------------------------------------------------------------
584616 # SORRY TO HAVE SURPRISED YOU!
618650 # Skelton file for .htaccess -- This file was generated by htags(1).
619651 #
620652 # Htags have made gzipped hypertext because you specified -c option.
621 # You need to setup http server so that these hypertext can be treated
622 # as gzipped files.
653 # If your browser doesn't decompress gzipped hypertext, you will need to
654 # setup your http server to treat this hypertext as gzipped files first.
623655 # There are many way to do it, but one of the method is to put .htaccess
624656 # file in 'HTML' directory.
625657 #
656688 print HELP "</DL>\n";
657689 print HELP $'end_body;
658690 print HELP $'end_html;
691 print HELP "\n";
659692 close(HELP);
660693 }
661694 #
685718 local($writing) = 0;
686719
687720 $count = 0;
688 local($command) = "global -nx$option '.*' | sort +0 -1 +2 -3 +1n -2";
721 local($command) = "global -nx$option \".*\" | sort +0 -1 +2 -3 +1n -2";
689722 open(LIST, "$command |") || &'error("cannot fork.");
690723 while (<LIST>) {
691724 chop;
697730 print FILE "</PRE>\n";
698731 print FILE $'end_body;
699732 print FILE $'end_html;
733 print FILE "\n";
700734 close(FILE);
701735 $writing = 0;
702736 }
735769 print FILE "</PRE>\n";
736770 print FILE $'end_body;
737771 print FILE $'end_html;
772 print FILE "\n";
738773 close(FILE);
739774 }
740775 if ($first_line) {
780815 print ALPHA "$'begin_script$'rewrite_href_funcs$'end_script";
781816 print ALPHA $'end_body;
782817 print ALPHA $'end_html;
818 print ALPHA "\n";
783819 close(ALPHA);
784820 }
785821 # for multi-byte code
829865 print ALPHA "$'begin_script$'rewrite_href_funcs$'end_script";
830866 print ALPHA $'end_body;
831867 print ALPHA $'end_html;
868 print ALPHA "\n";
832869 close(ALPHA);
833870
834871 print FUNCTIONS @funcs;
836873 print FUNCTIONS "</OL>\n" if (!$'aflag);
837874 print FUNCTIONS $'end_body;
838875 print FUNCTIONS $'end_html;
876 print FUNCTIONS "\n";
839877 close(FUNCTIONS);
840878 $count;
841879 }
853891 local($count) = 0;
854892 local($indexlink) = "../mains.$'normal_suffix";
855893 local(@dirstack, @fdstack);
856 local($command) = "gtags --find | sort";
894 local($command) = "$'findcom | sort";
857895 open(FIND, "$command |") || &'error("cannot fork.");
858896 open(FILES, ">$file") || &'error("cannot make file '$file'.");
859897 print FILES $'begin_html;
886924 print "$'begin_script$'rewrite_href_files$'end_script" if (@dirstack == 0);
887925 print $'end_body;
888926 print $'end_html;
927 print "\n";
889928 $path = pop(@fdstack);
890929 close($path);
891930 select($fdstack[$#fdstack]) if (@fdstack);
907946 print $li;
908947 }
909948 if ($'cflag) {
910 open($cur, "| gzip -c >'$cur'") || &'error("cannot make directory index.");
949 open($cur, "| gzip -c >\"$cur\"") || &'error("cannot make directory index.");
911950 } else {
912951 open($cur, ">$cur") || &'error("cannot make directory index.");
913952 }
952991 print "$'begin_script$'rewrite_href_files$'end_script" if (@dirstack == 0);
953992 print $'end_body;
954993 print $'end_html;
994 print "\n";
955995 $path = pop(@fdstack);
956996 close($path);
957997 select($fdstack[$#fdstack]) if (@fdstack);
9601000 print FILES "</OL>\n";
9611001 print FILES $'end_body;
9621002 print FILES $'end_html;
1003 print FILES "\n";
9631004 close(FILES);
9641005
9651006 select($org);
9831024 print INCLUDE "</PRE>\n";
9841025 print INCLUDE $'end_body;
9851026 print INCLUDE $'end_html;
1027 print INCLUDE "\n";
9861028 close(INCLUDE);
9871029 # '' means that information already written to file.
9881030 $includes{$last} = $no;
10031045 $index .= "<H1>$'title_begin$'title$'title_end</H1>\n";
10041046 $index .= "<P ALIGN=right>";
10051047 $index .= "Last updated " . &'date . "<BR>\n";
1006 $index .= "This hypertext was generated by <A HREF=http://wafu.netgate.net/tama/unix/global.html TARGET=_top>GLOBAL</A>.<BR>\n";
1048 $index .= "This hypertext was generated by <A HREF=http://www.tamacom.com/global/ TARGET=_top>GLOBAL</A>.<BR>\n";
10071049 $index .= $'begin_script;
10081050 $index .= "if (parent.frames.length && parent.mains == self)\n";
10091051 $index .= " document.write($'langle+'A HREF=mains.$'normal_suffix TARGET=_top'+$'rangle+'[No frame version is here.]'+$'langle+'/A'+$'rangle)\n";
10101052 $index .= $'end_script;
10111053 $index .= "</P>\n<HR>\n";
10121054 if ($'fflag) {
1013 $index .= "<H2>FUNCTION SEARCH</H2>\n";
1055 $index .= "<H2>OBJECT SEARCH</H2>\n";
10141056 $index .= "Please input function name and select [Search]. POSIX's regular expression is allowed.<P>\n";
10151057 $index .= "<FORM METHOD=GET ACTION=$'action>\n";
10161058 $index .= "<INPUT NAME=pattern>\n";
10191061 $index .= "<INPUT TYPE=reset VALUE=Reset><BR>\n";
10201062 $index .= "<INPUT TYPE=radio NAME=type VALUE=definition CHECKED>Definition\n";
10211063 $index .= "<INPUT TYPE=radio NAME=type VALUE=reference>Reference\n";
1064 $index .= "<INPUT TYPE=radio NAME=type VALUE=symbol>Other symbol\n";
10221065 $index .= "</FORM>\n<HR>\n";
10231066 }
10241067 $index .= "<H2>MAINS</H2>\n";
10631106
10641107 open(FRAME, ">$file") || &'error("cannot open file '$file'.");
10651108 print FRAME $'begin_html;
1066 print FRAME "<HEAD><TITLE>$title</TITLE>$'meta_robots</HEAD>\n";
1109 print FRAME "<HEAD><TITLE>$title</TITLE>$'meta_robots\n$'meta_generator</HEAD>\n";
10671110 print FRAME "<FRAMESET COLS='200,*'>\n";
10681111 print FRAME "<FRAMESET ROWS='50%,50%'>\n";
10691112 print FRAME "<FRAME NAME=funcs SRC=funcs.$'normal_suffix>\n";
10801123 print FRAME "<NOFRAMES>\n$index</NOFRAMES>\n";
10811124 print FRAME "</FRAMESET>\n";
10821125 print FRAME $'end_html;
1126 print FRAME "\n";
10831127 close(FRAME);
10841128 }
10851129 #
10981142 print INDEX $index;
10991143 print INDEX $'end_body;
11001144 print INDEX $'end_html;
1145 print INDEX "\n";
11011146 close(INDEX);
11021147 }
11031148 #
11091154 local($file) = @_;
11101155
11111156 open(NULL, ">$file") || &'error("cannot create file '$file'.");
1112 print NULL "$'begin_html$'begin_body$'end_body$'end_html";
1157 print NULL "$'begin_html$'begin_body$'end_body$'end_html\n";
11131158 close(NULL);
11141159 }
11151160 #
11511196 local($ncol) = $'ncol;
11521197 local($tabs) = $'tabs;
11531198 local(%ctab) = ('&', '&amp;', '<', '&lt;', '>', '&gt;');
1154 local($expand) = &'usable('expand') ? 'expand' : 'gtags --expand';
11551199 local($isjava) = ($file =~ /\.java$/) ? 1 : 0;
11561200 local($iscpp) = ($file =~ /\.(h|c\+\+|cc|cpp|cxx|hxx|C|H)$/) ? 1 : 0;
11571201
11581202 if ($'cflag) {
1159 open(HTML, "| gzip -c >'$hfile'") || &'error("cannot create file '$hfile'.");
1203 open(HTML, "| gzip -c >\"$hfile\"") || &'error("cannot create file '$hfile'.");
11601204 } else {
11611205 open(HTML, ">$hfile") || &'error("cannot create file '$hfile'.");
11621206 }
11651209 # load tags belonging to this file.
11661210 #
11671211 &anchor'load($file);
1168 open(SRC, "$expand -$tabs '$file' |") || &'error("cannot fork.");
1212 open(SRC, "gtags --expand -$tabs \"$file\" |") || &'error("cannot fork.");
11691213 #
11701214 # print the header
11711215 #
13041348 print "\n";
13051349 print $'end_body;
13061350 print $'end_html;
1351 print "\n";
13071352 close(SRC);
13081353 if ($?) { &'error("cannot open file '$file'."); }
13091354 close(HTML);
14371482 foreach $db ('GTAGS', 'GRTAGS') {
14381483 local($type) = ($db eq 'GTAGS') ? 'D' : 'R';
14391484 local($option) = ($db eq 'GTAGS') ? '' : 'r';
1440 local($command) = "global -nx$option '.*'";
1485 local($command) = "global -nx$option \".*\"";
14411486 open(PIPE, "$command |") || &'error("cannot fork.");
14421487 while (<PIPE>) {
14431488 local($tag, $lno, $filename) = split;
16111656 # other: sized cache
16121657 #
16131658 sub open {
1614 ($cachesize) = @_;
1615
1616 if ($cachesize == -1) {
1617 return;
1618 }
1619 undef %CACH if defined(%CACH);
1620 $cachecount = 0;
1659 $CACH = "$'tmp/CACH$$";
1660 dbmopen(%CACH, $CACH, 0600) || &'error("cannot make cache database.");
16211661 }
16221662 #
16231663 # put: put tag into cache
16301670 local($db, $tag, $line) = @_;
16311671 local($label) = ($db eq 'GTAGS') ? 'D' : 'R';
16321672
1633 $cachecount++;
1634 if ($cachesize >= 0 && $cachecount > $cachesize) {
1635 $CACH = "$'tmp/CACH$$";
1636 dbmopen(%CACH, $CACH, 0600) || &'error("make cache database.");
1637 $cachesize = -1;
1638 }
16391673 $CACH{$label.$tag} = $line;
16401674 }
16411675 #
16551689 # close: close cache
16561690 #
16571691 sub close {
1658 #dbmclose(%CACH);
1659 unlink("$CACH.db") if (defined($CACH));
1660 }
1692 local($dbm);
1693
1694 dbmclose(%CACH);
1695 chop($dbm = `echo $CACH*`);
1696 unlink($dbm);
1697 }
0 LIB= glodb
1 SRCS= bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c \
2 bt_open.c bt_overflow.c bt_page.c bt_put.c bt_search.c \
3 bt_seq.c bt_split.c bt_utils.c mpool.c db.c
4
5 NOPROFILE= noprofile
6 INTERNALLIB= true
7 INTERNALSTATICLIB= true
8
9 .include <bsd.lib.mk>
00 LIB = libglodb.a
11 CC = gcc
22 AR = ar
3 CFLAGS = -O
3 CFLAGS = -O -I../machine
44
55 OBJS= bt_close.o bt_conv.o bt_debug.o bt_delete.o bt_get.o \
66 bt_open.o bt_overflow.o bt_page.o bt_put.o bt_search.o \
99 all: $(LIB)
1010
1111 $(LIB): $(OBJS)
12 $(AR) cq $(LIB) $(OBJS)
12 $(AR) cr $(LIB) $(OBJS)
1313 install:
14 @echo -n
15 cygwin_install:
1416 @echo -n
1517 clean:
1618 rm -f $(LIB) $(OBJS)
0 LIB = libglodb.lib
1 CC = bcc32
2 AR = tlib
3 CFLAGS = -I../machine -I../win32
4
5 OBJS= bt_close.obj bt_conv.obj bt_debug.obj bt_delete.obj bt_get.obj \
6 bt_open.obj bt_overflow.obj bt_page.obj bt_put.obj bt_search.obj \
7 bt_seq.obj bt_split.obj bt_utils.obj mpool.obj db.obj
8
9 all: $(LIB)
10
11 $(LIB): $(OBJS)
12 $(AR) $(LIB) @..\win32\dbobjs
13 install:
14 @echo -n
15 clean:
16 del *.lib
17 del *.obj
00 Btree library derived from db(3) 1.85 with patch 2, 3, 4 applied.
1 Modified not to use system's db.h and btree.h.
1 Some code was modified for compatibility.
3737 static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94";
3838 #endif /* LIBC_SCCS and not lint */
3939
40 #include <sys/param.h>
41
4240 #include <errno.h>
4341 #include <stdio.h>
4442 #include <stdlib.h>
4846 #include "db.h"
4947 #include "btree.h"
5048
51 static int bt_meta __P((BTREE *));
49 static int bt_meta(BTREE *);
5250
5351 /*
5452 * BT_CLOSE -- Close a btree.
3737 static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94";
3838 #endif /* LIBC_SCCS and not lint */
3939
40 #include <sys/param.h>
41
4240 #include <stdio.h>
4341
4442 #include "db.h"
4543 #include "btree.h"
4644
47 static void mswap __P((PAGE *));
45 static void mswap(PAGE *);
4846
4947 /*
5048 * __BT_BPGIN, __BT_BPGOUT --
216214 P_32_SWAP(p); /* nrecs */
217215 p += sizeof(u_int32_t);
218216 P_32_SWAP(p); /* flags */
219 p += sizeof(u_int32_t);
217 #if 0 /* To satisfy compiler */
218 p += sizeof(u_int32_t);
219 #endif
220220 }
3636 #if defined(LIBC_SCCS) && !defined(lint)
3737 static char sccsid[] = "@(#)bt_debug.c 8.5 (Berkeley) 8/17/94";
3838 #endif /* LIBC_SCCS and not lint */
39
40 #include <sys/param.h>
4139
4240 #include <stdio.h>
4341 #include <stdlib.h>
4646 #include "db.h"
4747 #include "btree.h"
4848
49 static int __bt_bdelete __P((BTREE *, const DBT *));
50 static int __bt_curdel __P((BTREE *, const DBT *, PAGE *, u_int));
51 static int __bt_pdelete __P((BTREE *, PAGE *));
52 static int __bt_relink __P((BTREE *, PAGE *));
53 static int __bt_stkacq __P((BTREE *, PAGE **, CURSOR *));
49 static int __bt_bdelete(BTREE *, const DBT *);
50 static int __bt_curdel(BTREE *, const DBT *, PAGE *, u_int);
51 static int __bt_pdelete(BTREE *, PAGE *);
52 static int __bt_relink(BTREE *, PAGE *);
53 static int __bt_stkacq(BTREE *, PAGE **, CURSOR *);
5454
5555 /*
5656 * __bt_delete
149149 EPG *e;
150150 EPGNO *parent;
151151 PAGE *h;
152 indx_t index;
152 indx_t index = 0;
153153 pgno_t pgno;
154154 recno_t nextpg, prevpg;
155155 int exact, level;
4545 * is wholly independent of the Postgres code.
4646 */
4747
48 #include <sys/param.h>
4948 #include <sys/stat.h>
5049
5150 #include <errno.h>
6564 #define MINPSIZE 128
6665 #endif
6766
68 static int byteorder __P((void));
69 static int nroot __P((BTREE *));
70 static int tmp __P((void));
67 static int byteorder(void);
68 static int nroot(BTREE *);
69 static int tmp(void);
7170
7271 /*
7372 * __BT_OPEN -- Open a btree.
211210 F_SET(t, B_INMEM);
212211 }
213212
213 #ifndef _WIN32
214214 if (fcntl(t->bt_fd, F_SETFD, 1) == -1)
215215 goto err;
216 #endif
216217
217218 if (fstat(t->bt_fd, &sb))
218219 goto err;
258259 * Don't overflow the page offset type.
259260 */
260261 if (b.psize == 0) {
262 #ifndef _WIN32
261263 b.psize = sb.st_blksize;
262264 if (b.psize < MINPSIZE)
263265 b.psize = MINPSIZE;
264266 if (b.psize > MAX_PAGE_OFFSET + 1)
265267 b.psize = MAX_PAGE_OFFSET + 1;
268 #else
269 b.psize = MINPSIZE;
270 #endif
266271 }
267272
268273 /* Set flag if duplicates permitted. */
388393 sigset_t set, oset;
389394 int fd;
390395 char *envtmp;
391 char path[MAXPATHLEN];
396 #define MAXTEMPLEN 128
397 char path[MAXTEMPLEN];
392398
393399 envtmp = getenv("TMPDIR");
394 (void)snprintf(path,
395 sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : "/tmp");
396
400 if (envtmp && strlen(envtmp) + strlen("/bt.XXXXXX") >= MAXTEMPLEN)
401 return -1;
402 (void)sprintf(path, "%s/bt.XXXXXX", envtmp ? envtmp : "/tmp");
403
404 #ifndef _WIN32
397405 (void)sigfillset(&set);
398406 (void)sigprocmask(SIG_BLOCK, &set, &oset);
407 #endif
399408 if ((fd = mkstemp(path)) != -1)
400409 (void)unlink(path);
410 #ifndef _WIN32
401411 (void)sigprocmask(SIG_SETMASK, &oset, NULL);
412 #endif
402413 return(fd);
403414 }
404415
3737 static char sccsid[] = "@(#)bt_overflow.c 8.5 (Berkeley) 7/16/94";
3838 #endif /* LIBC_SCCS and not lint */
3939
40 #include <sys/param.h>
41
4240 #include <stdio.h>
4341 #include <stdlib.h>
4442 #include <string.h>
4747 #include "db.h"
4848 #include "btree.h"
4949
50 static EPG *bt_fast __P((BTREE *, const DBT *, const DBT *, int *));
50 static EPG *bt_fast(BTREE *, const DBT *, const DBT *, int *);
5151
5252 /*
5353 * __BT_PUT -- Add a btree item to the tree.
4444 #include "db.h"
4545 #include "btree.h"
4646
47 static int __bt_snext __P((BTREE *, PAGE *, const DBT *, int *));
48 static int __bt_sprev __P((BTREE *, PAGE *, const DBT *, int *));
47 static int __bt_snext(BTREE *, PAGE *, const DBT *, int *);
48 static int __bt_sprev(BTREE *, PAGE *, const DBT *, int *);
4949
5050 /*
5151 * __bt_search --
4747 #include "db.h"
4848 #include "btree.h"
4949
50 static int __bt_first __P((BTREE *, const DBT *, EPG *, int *));
51 static int __bt_seqadv __P((BTREE *, EPG *, int));
52 static int __bt_seqset __P((BTREE *, EPG *, DBT *, int));
50 static int __bt_first(BTREE *, const DBT *, EPG *, int *);
51 static int __bt_seqadv(BTREE *, EPG *, int);
52 static int __bt_seqset(BTREE *, EPG *, DBT *, int);
5353
5454 /*
5555 * Sequential scan support.
4747 #include "db.h"
4848 #include "btree.h"
4949
50 static int bt_broot __P((BTREE *, PAGE *, PAGE *, PAGE *));
51 static PAGE *bt_page
52 __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t));
53 static int bt_preserve __P((BTREE *, pgno_t));
54 static PAGE *bt_psplit
55 __P((BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t));
56 static PAGE *bt_root
57 __P((BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t));
58 static int bt_rroot __P((BTREE *, PAGE *, PAGE *, PAGE *));
59 static recno_t rec_total __P((PAGE *));
50 static int bt_broot(BTREE *, PAGE *, PAGE *, PAGE *);
51 static PAGE *bt_page(BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t);
52 static int bt_preserve(BTREE *, pgno_t);
53 static PAGE *bt_psplit(BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t);
54 static PAGE *bt_root(BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t);
55 static int bt_rroot(BTREE *, PAGE *, PAGE *, PAGE *);
56 static recno_t rec_total(PAGE *);
6057
6158 #ifdef STATISTICS
6259 u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved;
3737 static char sccsid[] = "@(#)bt_utils.c 8.8 (Berkeley) 7/20/94";
3838 #endif /* LIBC_SCCS and not lint */
3939
40 #include <sys/param.h>
41
4240 #include <stdio.h>
4341 #include <stdlib.h>
4442 #include <string.h>
334334 EPGNO bt_last; /* last insert */
335335
336336 /* B: key comparison function */
337 int (*bt_cmp) __P((const DBT *, const DBT *));
337 int (*bt_cmp)(const DBT *, const DBT *);
338338 /* B: prefix comparison function */
339 size_t (*bt_pfx) __P((const DBT *, const DBT *));
339 size_t (*bt_pfx)(const DBT *, const DBT *);
340340 /* R: recno input function */
341 int (*bt_irec) __P((struct _btree *, recno_t));
341 int (*bt_irec)(struct _btree *, recno_t);
342342
343343 FILE *bt_rfp; /* R: record FILE pointer */
344344 int bt_rfd; /* R: record file descriptor */
+0
-231
libdb/compat.h less more
0 /*-
1 * Copyright (c) 1991, 1993
2 * The Regents of the University of California. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by the University of
15 * California, Berkeley and its contributors.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)compat.h 8.13 (Berkeley) 2/21/94
33 */
34
35 #ifndef _COMPAT_H_
36 #define _COMPAT_H_
37
38 #include <sys/types.h>
39
40 /*
41 * If your system doesn't typedef u_long, u_short, or u_char, change
42 * the 0 to a 1.
43 */
44 #if 0
45 typedef unsigned char u_char; /* 4.[34]BSD names. */
46 typedef unsigned int u_int;
47 typedef unsigned long u_long;
48 typedef unsigned short u_short;
49 #endif
50
51 /* If your system doesn't typedef size_t, change the 0 to a 1. */
52 #if 0
53 typedef unsigned int size_t; /* POSIX, 4.[34]BSD names. */
54 #endif
55
56 /* If your system doesn't typedef ssize_t, change the 0 to a 1. */
57 #if 0
58 typedef int ssize_t; /* POSIX names. */
59 #endif
60
61 /*
62 * If your system doesn't have the POSIX type for a signal mask,
63 * change the 0 to a 1.
64 */
65 #if 0 /* POSIX 1003.1 signal mask type. */
66 typedef unsigned int sigset_t;
67 #endif
68
69 /*
70 * If your system's vsprintf returns a char *, not an int,
71 * change the 0 to a 1.
72 */
73 #if 0
74 #define VSPRINTF_CHARSTAR
75 #endif
76
77 /*
78 * If you don't have POSIX 1003.1 signals, the signal code surrounding the
79 * temporary file creation is intended to block all of the possible signals
80 * long enough to create the file and unlink it. All of this stuff is
81 * intended to use old-style BSD calls to fake POSIX 1003.1 calls.
82 */
83 #ifdef NO_POSIX_SIGNALS
84 #define sigemptyset(set) (*(set) = 0)
85 #define sigfillset(set) (*(set) = ~(sigset_t)0, 0)
86 #define sigaddset(set,signo) (*(set) |= sigmask(signo), 0)
87 #define sigdelset(set,signo) (*(set) &= ~sigmask(signo), 0)
88 #define sigismember(set,signo) ((*(set) & sigmask(signo)) != 0)
89
90 #define SIG_BLOCK 1
91 #define SIG_UNBLOCK 2
92 #define SIG_SETMASK 3
93
94 static int __sigtemp; /* For the use of sigprocmask */
95
96 /* Repeated test of oset != NULL is to avoid "*0". */
97 #define sigprocmask(how, set, oset) \
98 ((__sigtemp = \
99 (((how) == SIG_BLOCK) ? \
100 sigblock(0) | *(set) : \
101 (((how) == SIG_UNBLOCK) ? \
102 sigblock(0) & ~(*(set)) : \
103 ((how) == SIG_SETMASK ? \
104 *(set) : sigblock(0))))), \
105 ((oset) ? (*(oset ? oset : set) = sigsetmask(__sigtemp)) : \
106 sigsetmask(__sigtemp)), 0)
107 #endif
108
109 /*
110 * If your system doesn't have an include file with the appropriate
111 * byte order set, make sure you specify the correct one.
112 */
113 #ifndef BYTE_ORDER
114 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
115 #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
116 #define BYTE_ORDER LITTLE_ENDIAN /* Set for your system. */
117 #endif
118
119 #if defined(SYSV) || defined(SYSTEM5)
120 #define index(a, b) strchr(a, b)
121 #define rindex(a, b) strrchr(a, b)
122 #define bzero(a, b) memset(a, 0, b)
123 #define bcmp(a, b, n) memcmp(a, b, n)
124 #define bcopy(a, b, n) memmove(b, a, n)
125 #endif
126
127 #if defined(BSD) || defined(BSD4_3)
128 #define strchr(a, b) index(a, b)
129 #define strrchr(a, b) rindex(a, b)
130 #define memcmp(a, b, n) bcmp(a, b, n)
131 #define memmove(a, b, n) bcopy(b, a, n)
132 #endif
133
134 /*
135 * 32-bit machine. The db routines are theoretically independent of
136 * the size of u_shorts and u_longs, but I don't know that anyone has
137 * ever actually tried it. At a minimum, change the following #define's
138 * if you are trying to compile on a different type of system.
139 */
140 #ifndef USHRT_MAX
141 #define USHRT_MAX 0xFFFF
142 #define ULONG_MAX 0xFFFFFFFF
143 #endif
144
145 #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */
146 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
147 #endif
148
149 #ifndef _POSIX2_RE_DUP_MAX /* POSIX 1003.2 RE limit. */
150 #define _POSIX2_RE_DUP_MAX 255
151 #endif
152
153 /*
154 * If you can't provide lock values in the open(2) call. Note, this
155 * allows races to happen.
156 */
157 #ifndef O_EXLOCK /* 4.4BSD extension. */
158 #define O_EXLOCK 0
159 #endif
160
161 #ifndef O_SHLOCK /* 4.4BSD extension. */
162 #define O_SHLOCK 0
163 #endif
164
165 #ifndef EFTYPE
166 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
167 #endif
168
169 #ifndef WCOREDUMP /* 4.4BSD extension */
170 #define WCOREDUMP(a) 0
171 #endif
172
173 #ifndef STDERR_FILENO
174 #define STDIN_FILENO 0 /* ANSI C #defines */
175 #define STDOUT_FILENO 1
176 #define STDERR_FILENO 2
177 #endif
178
179 #ifndef SEEK_END
180 #define SEEK_SET 0 /* POSIX 1003.1 seek values */
181 #define SEEK_CUR 1
182 #define SEEK_END 2
183 #endif
184
185 #ifndef _POSIX_VDISABLE /* POSIX 1003.1 disabling char. */
186 #define _POSIX_VDISABLE 0 /* Some systems used 0. */
187 #endif
188
189 #ifndef TCSASOFT /* 4.4BSD extension. */
190 #define TCSASOFT 0
191 #endif
192
193 #ifndef _POSIX2_RE_DUP_MAX /* POSIX 1003.2 values. */
194 #define _POSIX2_RE_DUP_MAX 255
195 #endif
196
197 #ifndef NULL /* ANSI C #defines NULL everywhere. */
198 #define NULL 0
199 #endif
200
201 #ifndef MAX /* Usually found in <sys/param.h>. */
202 #define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
203 #endif
204 #ifndef MIN /* Usually found in <sys/param.h>. */
205 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
206 #endif
207
208 /* Default file permissions. */
209 #ifndef DEFFILEMODE /* 4.4BSD extension. */
210 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
211 #endif
212
213 #ifndef S_ISDIR /* POSIX 1003.1 file type tests. */
214 #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */
215 #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */
216 #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */
217 #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */
218 #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */
219 #endif
220 #ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */
221 #define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */
222 #define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */
223 #endif
224
225 /* The type of a va_list. */
226 #ifndef _BSD_VA_LIST_ /* 4.4BSD #define. */
227 #define _BSD_VA_LIST_ char *
228 #endif
229
230 #endif /* !_COMPAT_H_ */
5959 if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0)
6060 switch (type) {
6161 case DB_BTREE:
62 return (__bt_open(fname, flags & USE_OPEN_FLAGS,
62 return (__bt_open(fname, (flags & USE_OPEN_FLAGS) | O_BINARY,
6363 mode, openinfo, flags & DB_FLAGS));
6464 /*
6565 case DB_HASH:
66 return (__hash_open(fname, flags & USE_OPEN_FLAGS,
66 return (__hash_open(fname, (flags & USE_OPEN_FLAGS) | O_BINARY,
6767 mode, openinfo, flags & DB_FLAGS));
6868 case DB_RECNO:
69 return (__rec_open(fname, flags & USE_OPEN_FLAGS,
69 return (__rec_open(fname, (flags & USE_OPEN_FLAGS) | O_BINARY,
7070 mode, openinfo, flags & DB_FLAGS));
7171 */
7272 }
4545 #define RET_SUCCESS 0
4646 #define RET_SPECIAL 1
4747
48 /*
49 #ifndef __BIT_TYPES_DEFINED__
50 #define __BIT_TYPES_DEFINED__
51 typedef __signed char int8_t;
52 typedef unsigned char u_int8_t;
53 typedef short int16_t;
54 typedef unsigned short u_int16_t;
55 typedef int int32_t;
56 typedef unsigned int u_int32_t;
57 #ifdef WE_DONT_NEED_QUADS
58 typedef long long int64_t;
59 typedef unsigned long long u_int64_t;
60 #endif
61 #endif
62 */
63
6448 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
6549 typedef u_int32_t pgno_t;
6650 #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
11599 /* Access method description structure. */
116100 typedef struct __db {
117101 DBTYPE type; /* Underlying db type. */
118 int (*close) __P((struct __db *));
119 int (*del) __P((const struct __db *, const DBT *, u_int));
120 int (*get) __P((const struct __db *, const DBT *, DBT *, u_int));
121 int (*put) __P((const struct __db *, DBT *, const DBT *, u_int));
122 int (*seq) __P((const struct __db *, DBT *, DBT *, u_int));
123 int (*sync) __P((const struct __db *, u_int));
102 int (*close) (struct __db *);
103 int (*del) (const struct __db *, const DBT *, u_int);
104 int (*get) (const struct __db *, const DBT *, DBT *, u_int);
105 int (*put) (const struct __db *, DBT *, const DBT *, u_int);
106 int (*seq) (const struct __db *, DBT *, DBT *, u_int);
107 int (*sync) (const struct __db *, u_int);
124108 void *internal; /* Access method private. */
125 int (*fd) __P((const struct __db *));
109 int (*fd) (const struct __db *);
126110 } DB;
127111
128112 #define BTREEMAGIC 0x053162
129113 #define BTREEVERSION 3
114 #define R_DUP 0x01 /* duplicate keys */
130115
131116 /* Structure used to pass parameters to the btree routines. */
132117 typedef struct {
133 #define R_DUP 0x01 /* duplicate keys */
134118 u_long flags;
135119 u_int cachesize; /* bytes to cache */
136120 int maxkeypage; /* maximum keys per page */
137121 int minkeypage; /* minimum keys per page */
138122 u_int psize; /* page size */
139123 int (*compare) /* comparison function */
140 __P((const DBT *, const DBT *));
124 (const DBT *, const DBT *);
141125 size_t (*prefix) /* prefix function */
142 __P((const DBT *, const DBT *));
126 (const DBT *, const DBT *);
143127 int lorder; /* byte order */
144128 } BTREEINFO;
145129
153137 u_int nelem; /* number of elements */
154138 u_int cachesize; /* bytes to cache */
155139 u_int32_t /* hash function */
156 (*hash) __P((const void *, size_t));
140 (*hash)(const void *, size_t);
157141 int lorder; /* byte order */
158142 } HASHINFO;
159143
160 /* Structure used to pass parameters to the record routines. */
161 typedef struct {
162144 #define R_FIXEDLEN 0x01 /* fixed-length records */
163145 #define R_NOKEY 0x02 /* key not required */
164146 #define R_SNAPSHOT 0x04 /* snapshot the input */
147
148 /* Structure used to pass parameters to the record routines. */
149 typedef struct {
165150 u_long flags;
166151 u_int cachesize; /* bytes to cache */
167152 u_int psize; /* page size */
219204 ((char *)&(b))[1] = ((char *)&(a))[0]; \
220205 }
221206
222 __BEGIN_DECLS
223 DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
224
225 DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
226 DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
227 DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
228 void __dbpanic __P((DB *dbp));
229 __END_DECLS
207 DB *dbopen(const char *, int, int, DBTYPE, const void *);
208
209 DB *__bt_open(const char *, int, int, const BTREEINFO *, int);
210 DB *__hash_open(const char *, int, int, const HASHINFO *, int);
211 DB *__rec_open(const char *, int, int, const RECNOINFO *, int);
212 void __dbpanic(DB *dbp);
230213 #endif /* !_DB_H_ */
3232 * @(#)extern.h 8.10 (Berkeley) 7/20/94
3333 */
3434
35 int __bt_close __P((DB *));
36 int __bt_cmp __P((BTREE *, const DBT *, EPG *));
37 int __bt_crsrdel __P((BTREE *, EPGNO *));
38 int __bt_defcmp __P((const DBT *, const DBT *));
39 size_t __bt_defpfx __P((const DBT *, const DBT *));
40 int __bt_delete __P((const DB *, const DBT *, u_int));
41 int __bt_dleaf __P((BTREE *, const DBT *, PAGE *, u_int));
42 int __bt_fd __P((const DB *));
43 int __bt_free __P((BTREE *, PAGE *));
44 int __bt_get __P((const DB *, const DBT *, DBT *, u_int));
45 PAGE *__bt_new __P((BTREE *, pgno_t *));
46 void __bt_pgin __P((void *, pgno_t, void *));
47 void __bt_pgout __P((void *, pgno_t, void *));
48 int __bt_push __P((BTREE *, pgno_t, int));
49 int __bt_put __P((const DB *dbp, DBT *, const DBT *, u_int));
50 int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int));
51 EPG *__bt_search __P((BTREE *, const DBT *, int *));
52 int __bt_seq __P((const DB *, DBT *, DBT *, u_int));
53 void __bt_setcur __P((BTREE *, pgno_t, u_int));
54 int __bt_split __P((BTREE *, PAGE *,
55 const DBT *, const DBT *, int, size_t, u_int32_t));
56 int __bt_sync __P((const DB *, u_int));
35 int __bt_close(DB *);
36 int __bt_cmp(BTREE *, const DBT *, EPG *);
37 int __bt_crsrdel(BTREE *, EPGNO *);
38 int __bt_defcmp(const DBT *, const DBT *);
39 size_t __bt_defpfx(const DBT *, const DBT *);
40 int __bt_delete(const DB *, const DBT *, u_int);
41 int __bt_dleaf(BTREE *, const DBT *, PAGE *, u_int);
42 int __bt_fd(const DB *);
43 int __bt_free(BTREE *, PAGE *);
44 int __bt_get(const DB *, const DBT *, DBT *, u_int);
45 PAGE *__bt_new(BTREE *, pgno_t *);
46 void __bt_pgin(void *, pgno_t, void *);
47 void __bt_pgout(void *, pgno_t, void *);
48 int __bt_push(BTREE *, pgno_t, int);
49 int __bt_put(const DB *dbp, DBT *, const DBT *, u_int);
50 int __bt_ret(BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int);
51 EPG *__bt_search(BTREE *, const DBT *, int *);
52 int __bt_seq(const DB *, DBT *, DBT *, u_int);
53 void __bt_setcur(BTREE *, pgno_t, u_int);
54 int __bt_split(BTREE *, PAGE *,
55 const DBT *, const DBT *, int, size_t, u_int32_t);
56 int __bt_sync(const DB *, u_int);
5757
58 int __ovfl_delete __P((BTREE *, void *));
59 int __ovfl_get __P((BTREE *, void *, size_t *, void **, size_t *));
60 int __ovfl_put __P((BTREE *, const DBT *, pgno_t *));
58 int __ovfl_delete(BTREE *, void *);
59 int __ovfl_get(BTREE *, void *, size_t *, void **, size_t *);
60 int __ovfl_put(BTREE *, const DBT *, pgno_t *);
6161
6262 #ifdef DEBUG
63 void __bt_dnpage __P((DB *, pgno_t));
64 void __bt_dpage __P((PAGE *));
65 void __bt_dump __P((DB *));
63 void __bt_dnpage(DB *, pgno_t);
64 void __bt_dpage(PAGE *);
65 void __bt_dump(DB *);
6666 #endif
6767 #ifdef STATISTICS
68 void __bt_stat __P((DB *));
68 void __bt_stat(DB *);
6969 #endif
3434 static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94";
3535 #endif /* LIBC_SCCS and not lint */
3636
37 #include <sys/param.h>
3837 #include <sys/stat.h>
3938
4039 #include <errno.h>
4948 #define __MPOOLINTERFACE_PRIVATE
5049 #include "mpool.h"
5150
52 static BKT *mpool_bkt __P((MPOOL *));
53 static BKT *mpool_look __P((MPOOL *, pgno_t));
54 static int mpool_write __P((MPOOL *, BKT *));
51 static BKT *mpool_bkt(MPOOL *);
52 static BKT *mpool_look(MPOOL *, pgno_t);
53 static int mpool_write(MPOOL *, BKT *);
5554
5655 /*
5756 * mpool_open --
10099 void
101100 mpool_filter(mp, pgin, pgout, pgcookie)
102101 MPOOL *mp;
103 void (*pgin) __P((void *, pgno_t, void *));
104 void (*pgout) __P((void *, pgno_t, void *));
102 void (*pgin)(void *, pgno_t, void *);
103 void (*pgout)(void *, pgno_t, void *);
105104 void *pgcookie;
106105 {
107106 mp->pgin = pgin;
6666 u_long pagesize; /* file page size */
6767 int fd; /* file descriptor */
6868 /* page in conversion routine */
69 void (*pgin) __P((void *, pgno_t, void *));
69 void (*pgin)(void *, pgno_t, void *);
7070 /* page out conversion routine */
71 void (*pgout) __P((void *, pgno_t, void *));
71 void (*pgout)(void *, pgno_t, void *);
7272 void *pgcookie; /* cookie for page in/out routines */
7373 #ifdef STATISTICS
7474 u_long cachehit;
8383 #endif
8484 } MPOOL;
8585
86 __BEGIN_DECLS
87 MPOOL *mpool_open __P((void *, int, pgno_t, pgno_t));
88 void mpool_filter __P((MPOOL *, void (*)(void *, pgno_t, void *),
89 void (*)(void *, pgno_t, void *), void *));
90 void *mpool_new __P((MPOOL *, pgno_t *));
91 void *mpool_get __P((MPOOL *, pgno_t, u_int));
92 int mpool_put __P((MPOOL *, void *, u_int));
93 int mpool_sync __P((MPOOL *));
94 int mpool_close __P((MPOOL *));
86 MPOOL *mpool_open(void *, int, pgno_t, pgno_t);
87 void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
88 void (*)(void *, pgno_t, void *), void *);
89 void *mpool_new(MPOOL *, pgno_t *);
90 void *mpool_get(MPOOL *, pgno_t, u_int);
91 int mpool_put(MPOOL *, void *, u_int);
92 int mpool_sync(MPOOL *);
93 int mpool_close(MPOOL *);
9594 #ifdef STATISTICS
96 void mpool_stat __P((MPOOL *));
95 void mpool_stat(MPOOL *);
9796 #endif
98 __END_DECLS
432432
433433 #else /* !__GNUC__ */
434434
435 void insque __P((void *a, void *b));
436 void remque __P((void *a));
435 void insque(void *a, void *b);
436 void remque(void *a);
437437
438438 #endif /* __GNUC__ */
439439
0 Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
1 This software is not subject to any license of the American Telephone
2 and Telegraph Company or of the Regents of the University of California.
3
4 Permission is granted to anyone to use this software for any purpose on
5 any computer system, and to alter it and redistribute it, subject
6 to the following restrictions:
7
8 1. The author is not responsible for the consequences of use of this
9 software, no matter how awful, even if they arise from flaws in it.
10
11 2. The origin of this software must not be misrepresented, either by
12 explicit claim or by omission. Since few users ever read sources,
13 credits must appear in the documentation.
14
15 3. Altered versions must be plainly marked as such, and must not be
16 misrepresented as being the original software. Since few users
17 ever read sources, credits must appear in the documentation.
18
19 4. This notice may not be removed or altered.
20
21 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 /*-
23 * Copyright (c) 1994
24 * The Regents of the University of California. All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 *
54 * @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
55 */
0 LIB= gloregex
1 SRCS= regcomp.c regerror.c regexec.c regfree.c
2
3 NOPROFILE= noprofile
4 INTERNALLIB= true
5 INTERNALSTATICLIB= true
6
7 .include <bsd.lib.mk>
0 LIB= gloregex
1 SRCS= regcomp.c regerror.c regexec.c regfree.c
2
3 NOPROFILE= noprofile
4 INTERNALLIB= true
5 INTERNALSTATICLIB= true
6
7 .include <bsd.lib.mk>
0 LIB = libgloregex.a
1 CC = gcc
2 AR = ar
3 CFLAGS = -O -I../machine
4 OBJS = regcomp.o regerror.o regexec.o regfree.o
5
6 all: $(LIB)
7
8 $(LIB): $(OBJS)
9 $(AR) cr $(LIB) $(OBJS)
10 install:
11 @echo -n
12 cygwin_install:
13 @echo -n
14 clean:
15 rm -f $(LIB) $(OBJS)
0 LIB = libgloregex.lib
1 CC = bcc32
2 AR = tlib
3 CFLAGS = -I../libdb -I../machine -I../win32
4 OBJS = regcomp.obj regerror.obj regexec.obj regfree.obj
5
6 all: $(LIB)
7
8 $(LIB): $(OBJS)
9 $(AR) $(LIB) @..\win32\regexobjs
10 install:
11 @echo -n
12 clean:
13 del *.lib
14 del *.obj
0 Regex library derived from FreeBSD-2.2.5R.
1
2 I have modified like follows.
3
4 All files:
5 #include <regex.h> -> #include "regex.h"
6 delete __P()
7 regcomp.c:
8 following code added.
9
10 #ifndef BSD4_4
11 int __collate_range_cmp (c1, c2)
12 int c1;
13 int c2;
14 {
15 return c1 - c2;
16 }
17 #ifndef isblank
18 #define isblank(c) ((c) == ' ' || (c) == '\t')
19 #endif
20 #endif
0 # @(#)WHATSNEW 8.3 (Berkeley) 3/18/94
1
2 New in alpha3.4: The complex bug alluded to below has been fixed (in a
3 slightly kludgey temporary way that may hurt efficiency a bit; this is
4 another "get it out the door for 4.4" release). The tests at the end of
5 the tests file have accordingly been uncommented. The primary sign of
6 the bug was that something like a?b matching ab matched b rather than ab.
7 (The bug was essentially specific to this exact situation, else it would
8 have shown up earlier.)
9
10 New in alpha3.3: The definition of word boundaries has been altered
11 slightly, to more closely match the usual programming notion that "_"
12 is an alphabetic. Stuff used for pre-ANSI systems is now in a subdir,
13 and the makefile no longer alludes to it in mysterious ways. The
14 makefile has generally been cleaned up some. Fixes have been made
15 (again!) so that the regression test will run without -DREDEBUG, at
16 the cost of weaker checking. A workaround for a bug in some folks'
17 <assert.h> has been added. And some more things have been added to
18 tests, including a couple right at the end which are commented out
19 because the code currently flunks them (complex bug; fix coming).
20 Plus the usual minor cleanup.
21
22 New in alpha3.2: Assorted bits of cleanup and portability improvement
23 (the development base is now a BSDI system using GCC instead of an ancient
24 Sun system, and the newer compiler exposed some glitches). Fix for a
25 serious bug that affected REs using many [] (including REG_ICASE REs
26 because of the way they are implemented), *sometimes*, depending on
27 memory-allocation patterns. The header-file prototypes no longer name
28 the parameters, avoiding possible name conflicts. The possibility that
29 some clot has defined CHAR_MIN as (say) `-128' instead of `(-128)' is
30 now handled gracefully. "uchar" is no longer used as an internal type
31 name (too many people have the same idea). Still the same old lousy
32 performance, alas.
33
34 New in alpha3.1: Basically nothing, this release is just a bookkeeping
35 convenience. Stay tuned.
36
37 New in alpha3.0: Performance is no better, alas, but some fixes have been
38 made and some functionality has been added. (This is basically the "get
39 it out the door in time for 4.4" release.) One bug fix: regfree() didn't
40 free the main internal structure (how embarrassing). It is now possible
41 to put NULs in either the RE or the target string, using (resp.) a new
42 REG_PEND flag and the old REG_STARTEND flag. The REG_NOSPEC flag to
43 regcomp() makes all characters ordinary, so you can match a literal
44 string easily (this will become more useful when performance improves!).
45 There are now primitives to match beginnings and ends of words, although
46 the syntax is disgusting and so is the implementation. The REG_ATOI
47 debugging interface has changed a bit. And there has been considerable
48 internal cleanup of various kinds.
49
50 New in alpha2.3: Split change list out of README, and moved flags notes
51 into Makefile. Macro-ized the name of regex(7) in regex(3), since it has
52 to change for 4.4BSD. Cleanup work in engine.c, and some new regression
53 tests to catch tricky cases thereof.
54
55 New in alpha2.2: Out-of-date manpages updated. Regerror() acquires two
56 small extensions -- REG_ITOA and REG_ATOI -- which avoid debugging kludges
57 in my own test program and might be useful to others for similar purposes.
58 The regression test will now compile (and run) without REDEBUG. The
59 BRE \$ bug is fixed. Most uses of "uchar" are gone; it's all chars now.
60 Char/uchar parameters are now written int/unsigned, to avoid possible
61 portability problems with unpromoted parameters. Some unsigned casts have
62 been introduced to minimize portability problems with shifting into sign
63 bits.
64
65 New in alpha2.1: Lots of little stuff, cleanup and fixes. The one big
66 thing is that regex.h is now generated, using mkh, rather than being
67 supplied in the distribution; due to circularities in dependencies,
68 you have to build regex.h explicitly by "make h". The two known bugs
69 have been fixed (and the regression test now checks for them), as has a
70 problem with assertions not being suppressed in the absence of REDEBUG.
71 No performance work yet.
72
73 New in alpha2: Backslash-anything is an ordinary character, not an
74 error (except, of course, for the handful of backslashed metacharacters
75 in BREs), which should reduce script breakage. The regression test
76 checks *where* null strings are supposed to match, and has generally
77 been tightened up somewhat. Small bug fixes in parameter passing (not
78 harmful, but technically errors) and some other areas. Debugging
79 invoked by defining REDEBUG rather than not defining NDEBUG.
80
81 New in alpha+3: full prototyping for internal routines, using a little
82 helper program, mkh, which extracts prototypes given in stylized comments.
83 More minor cleanup. Buglet fix: it's CHAR_BIT, not CHAR_BITS. Simple
84 pre-screening of input when a literal string is known to be part of the
85 RE; this does wonders for performance.
86
87 New in alpha+2: minor bits of cleanup. Notably, the number "32" for the
88 word width isn't hardwired into regexec.c any more, the public header
89 file prototypes the functions if __STDC__ is defined, and some small typos
90 in the manpages have been fixed.
91
92 New in alpha+1: improvements to the manual pages, and an important
93 extension, the REG_STARTEND option to regexec().
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)cclass.h 8.3 (Berkeley) 3/20/94
37 */
38
39
40 typedef enum {CALNUM, CALPHA, CBLANK, CCNTRL, CDIGIT, CGRAPH,
41 CLOWER, CPRINT, CPUNCT, CSPACE, CUPPER, CXDIGIT} citype;
42
43 /* character-class table */
44 static struct cclass {
45 char *name;
46 citype fidx;
47 } cclasses[] = {
48 {"alnum", CALNUM},
49 {"alpha", CALPHA},
50 {"blank", CBLANK},
51 {"cntrl", CCNTRL},
52 {"digit", CDIGIT},
53 {"graph", CGRAPH},
54 {"lower", CLOWER},
55 {"print", CPRINT},
56 {"punct", CPUNCT},
57 {"space", CSPACE},
58 {"upper", CUPPER},
59 {"xdigit", CXDIGIT},
60 {NULL, }
61 };
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)cname.h 8.3 (Berkeley) 3/20/94
37 */
38
39 /* character-name table */
40 static struct cname {
41 char *name;
42 char code;
43 } cnames[] = {
44 {"NUL", '\0'},
45 {"SOH", '\001'},
46 {"STX", '\002'},
47 {"ETX", '\003'},
48 {"EOT", '\004'},
49 {"ENQ", '\005'},
50 {"ACK", '\006'},
51 {"BEL", '\007'},
52 {"alert", '\007'},
53 {"BS", '\010'},
54 {"backspace", '\b'},
55 {"HT", '\011'},
56 {"tab", '\t'},
57 {"LF", '\012'},
58 {"newline", '\n'},
59 {"VT", '\013'},
60 {"vertical-tab", '\v'},
61 {"FF", '\014'},
62 {"form-feed", '\f'},
63 {"CR", '\015'},
64 {"carriage-return", '\r'},
65 {"SO", '\016'},
66 {"SI", '\017'},
67 {"DLE", '\020'},
68 {"DC1", '\021'},
69 {"DC2", '\022'},
70 {"DC3", '\023'},
71 {"DC4", '\024'},
72 {"NAK", '\025'},
73 {"SYN", '\026'},
74 {"ETB", '\027'},
75 {"CAN", '\030'},
76 {"EM", '\031'},
77 {"SUB", '\032'},
78 {"ESC", '\033'},
79 {"IS4", '\034'},
80 {"FS", '\034'},
81 {"IS3", '\035'},
82 {"GS", '\035'},
83 {"IS2", '\036'},
84 {"RS", '\036'},
85 {"IS1", '\037'},
86 {"US", '\037'},
87 {"space", ' '},
88 {"exclamation-mark", '!'},
89 {"quotation-mark", '"'},
90 {"number-sign", '#'},
91 {"dollar-sign", '$'},
92 {"percent-sign", '%'},
93 {"ampersand", '&'},
94 {"apostrophe", '\''},
95 {"left-parenthesis", '('},
96 {"right-parenthesis", ')'},
97 {"asterisk", '*'},
98 {"plus-sign", '+'},
99 {"comma", ','},
100 {"hyphen", '-'},
101 {"hyphen-minus", '-'},
102 {"period", '.'},
103 {"full-stop", '.'},
104 {"slash", '/'},
105 {"solidus", '/'},
106 {"zero", '0'},
107 {"one", '1'},
108 {"two", '2'},
109 {"three", '3'},
110 {"four", '4'},
111 {"five", '5'},
112 {"six", '6'},
113 {"seven", '7'},
114 {"eight", '8'},
115 {"nine", '9'},
116 {"colon", ':'},
117 {"semicolon", ';'},
118 {"less-than-sign", '<'},
119 {"equals-sign", '='},
120 {"greater-than-sign", '>'},
121 {"question-mark", '?'},
122 {"commercial-at", '@'},
123 {"left-square-bracket", '['},
124 {"backslash", '\\'},
125 {"reverse-solidus", '\\'},
126 {"right-square-bracket",']'},
127 {"circumflex", '^'},
128 {"circumflex-accent", '^'},
129 {"underscore", '_'},
130 {"low-line", '_'},
131 {"grave-accent", '`'},
132 {"left-brace", '{'},
133 {"left-curly-bracket", '{'},
134 {"vertical-line", '|'},
135 {"right-brace", '}'},
136 {"right-curly-bracket", '}'},
137 {"tilde", '~'},
138 {"DEL", '\177'},
139 {NULL, 0}
140 };
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)engine.c 8.5 (Berkeley) 3/20/94
37 */
38
39 /*
40 * The matching engine and friends. This file is #included by regexec.c
41 * after suitable #defines of a variety of macros used herein, so that
42 * different state representations can be used without duplicating masses
43 * of code.
44 */
45
46 #ifdef SNAMES
47 #define matcher smatcher
48 #define fast sfast
49 #define slow sslow
50 #define dissect sdissect
51 #define backref sbackref
52 #define step sstep
53 #define print sprint
54 #define at sat
55 #define match smat
56 #endif
57 #ifdef LNAMES
58 #define matcher lmatcher
59 #define fast lfast
60 #define slow lslow
61 #define dissect ldissect
62 #define backref lbackref
63 #define step lstep
64 #define print lprint
65 #define at lat
66 #define match lmat
67 #endif
68
69 /* another structure passed up and down to avoid zillions of parameters */
70 struct match {
71 struct re_guts *g;
72 int eflags;
73 regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
74 char *offp; /* offsets work from here */
75 char *beginp; /* start of string -- virtual NUL precedes */
76 char *endp; /* end of string -- virtual NUL here */
77 char *coldp; /* can be no match starting before here */
78 char **lastpos; /* [nplus+1] */
79 STATEVARS;
80 states st; /* current states */
81 states fresh; /* states for a fresh start */
82 states tmp; /* temporary */
83 states empty; /* empty set of states */
84 };
85
86 /* ========= begin header generated by ./mkh ========= */
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90
91 /* === engine.c === */
92 static int matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
93 static char *dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
94 static char *backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
95 static char *fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
96 static char *slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
97 static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft);
98 #define BOL (OUT+1)
99 #define EOL (BOL+1)
100 #define BOLEOL (BOL+2)
101 #define NOTHING (BOL+3)
102 #define BOW (BOL+4)
103 #define EOW (BOL+5)
104 #define CODEMAX (BOL+5) /* highest code used */
105 #define NONCHAR(c) ((c) > CHAR_MAX)
106 #define NNONCHAR (CODEMAX-CHAR_MAX)
107 #ifdef REDEBUG
108 static void print(struct match *m, char *caption, states st, int ch, FILE *d);
109 #endif
110 #ifdef REDEBUG
111 static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
112 #endif
113 #ifdef REDEBUG
114 static char *pchar(int ch);
115 #endif
116
117 #ifdef __cplusplus
118 }
119 #endif
120 /* ========= end header generated by ./mkh ========= */
121
122 #ifdef REDEBUG
123 #define SP(t, s, c) print(m, t, s, c, stdout)
124 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
125 #define NOTE(str) { if (m->eflags&REG_TRACE) printf("=%s\n", (str)); }
126 #else
127 #define SP(t, s, c) /* nothing */
128 #define AT(t, p1, p2, s1, s2) /* nothing */
129 #define NOTE(s) /* nothing */
130 #endif
131
132 /*
133 - matcher - the actual matching engine
134 == static int matcher(register struct re_guts *g, char *string, \
135 == size_t nmatch, regmatch_t pmatch[], int eflags);
136 */
137 static int /* 0 success, REG_NOMATCH failure */
138 matcher(g, string, nmatch, pmatch, eflags)
139 register struct re_guts *g;
140 char *string;
141 size_t nmatch;
142 regmatch_t pmatch[];
143 int eflags;
144 {
145 register char *endp;
146 register int i;
147 struct match mv;
148 register struct match *m = &mv;
149 register char *dp;
150 register const sopno gf = g->firststate+1; /* +1 for OEND */
151 register const sopno gl = g->laststate;
152 char *start;
153 char *stop;
154
155 /* simplify the situation where possible */
156 if (g->cflags&REG_NOSUB)
157 nmatch = 0;
158 if (eflags&REG_STARTEND) {
159 start = string + pmatch[0].rm_so;
160 stop = string + pmatch[0].rm_eo;
161 } else {
162 start = string;
163 stop = start + strlen(start);
164 }
165 if (stop < start)
166 return(REG_INVARG);
167
168 /* prescreening; this does wonders for this rather slow code */
169 if (g->must != NULL) {
170 for (dp = start; dp < stop; dp++)
171 if (*dp == g->must[0] && stop - dp >= g->mlen &&
172 memcmp(dp, g->must, (size_t)g->mlen) == 0)
173 break;
174 if (dp == stop) /* we didn't find g->must */
175 return(REG_NOMATCH);
176 }
177
178 /* match struct setup */
179 m->g = g;
180 m->eflags = eflags;
181 m->pmatch = NULL;
182 m->lastpos = NULL;
183 m->offp = string;
184 m->beginp = start;
185 m->endp = stop;
186 STATESETUP(m, 4);
187 SETUP(m->st);
188 SETUP(m->fresh);
189 SETUP(m->tmp);
190 SETUP(m->empty);
191 CLEAR(m->empty);
192
193 /* this loop does only one repetition except for backrefs */
194 for (;;) {
195 endp = fast(m, start, stop, gf, gl);
196 if (endp == NULL) { /* a miss */
197 STATETEARDOWN(m);
198 return(REG_NOMATCH);
199 }
200 if (nmatch == 0 && !g->backrefs)
201 break; /* no further info needed */
202
203 /* where? */
204 assert(m->coldp != NULL);
205 for (;;) {
206 NOTE("finding start");
207 endp = slow(m, m->coldp, stop, gf, gl);
208 if (endp != NULL)
209 break;
210 assert(m->coldp < m->endp);
211 m->coldp++;
212 }
213 if (nmatch == 1 && !g->backrefs)
214 break; /* no further info needed */
215
216 /* oh my, he wants the subexpressions... */
217 if (m->pmatch == NULL)
218 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
219 sizeof(regmatch_t));
220 if (m->pmatch == NULL) {
221 STATETEARDOWN(m);
222 return(REG_ESPACE);
223 }
224 for (i = 1; i <= m->g->nsub; i++)
225 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
226 if (!g->backrefs && !(m->eflags&REG_BACKR)) {
227 NOTE("dissecting");
228 dp = dissect(m, m->coldp, endp, gf, gl);
229 } else {
230 if (g->nplus > 0 && m->lastpos == NULL)
231 m->lastpos = (char **)malloc((g->nplus+1) *
232 sizeof(char *));
233 if (g->nplus > 0 && m->lastpos == NULL) {
234 free(m->pmatch);
235 STATETEARDOWN(m);
236 return(REG_ESPACE);
237 }
238 NOTE("backref dissect");
239 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
240 }
241 if (dp != NULL)
242 break;
243
244 /* uh-oh... we couldn't find a subexpression-level match */
245 assert(g->backrefs); /* must be back references doing it */
246 assert(g->nplus == 0 || m->lastpos != NULL);
247 for (;;) {
248 if (dp != NULL || endp <= m->coldp)
249 break; /* defeat */
250 NOTE("backoff");
251 endp = slow(m, m->coldp, endp-1, gf, gl);
252 if (endp == NULL)
253 break; /* defeat */
254 /* try it on a shorter possibility */
255 #ifndef NDEBUG
256 for (i = 1; i <= m->g->nsub; i++) {
257 assert(m->pmatch[i].rm_so == -1);
258 assert(m->pmatch[i].rm_eo == -1);
259 }
260 #endif
261 NOTE("backoff dissect");
262 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
263 }
264 assert(dp == NULL || dp == endp);
265 if (dp != NULL) /* found a shorter one */
266 break;
267
268 /* despite initial appearances, there is no match here */
269 NOTE("false alarm");
270 start = m->coldp + 1; /* recycle starting later */
271 assert(start <= stop);
272 }
273
274 /* fill in the details if requested */
275 if (nmatch > 0) {
276 pmatch[0].rm_so = m->coldp - m->offp;
277 pmatch[0].rm_eo = endp - m->offp;
278 }
279 if (nmatch > 1) {
280 assert(m->pmatch != NULL);
281 for (i = 1; i < nmatch; i++)
282 if (i <= m->g->nsub)
283 pmatch[i] = m->pmatch[i];
284 else {
285 pmatch[i].rm_so = -1;
286 pmatch[i].rm_eo = -1;
287 }
288 }
289
290 if (m->pmatch != NULL)
291 free((char *)m->pmatch);
292 if (m->lastpos != NULL)
293 free((char *)m->lastpos);
294 STATETEARDOWN(m);
295 return(0);
296 }
297
298 /*
299 - dissect - figure out what matched what, no back references
300 == static char *dissect(register struct match *m, char *start, \
301 == char *stop, sopno startst, sopno stopst);
302 */
303 static char * /* == stop (success) always */
304 dissect(m, start, stop, startst, stopst)
305 register struct match *m;
306 char *start;
307 char *stop;
308 sopno startst;
309 sopno stopst;
310 {
311 register int i;
312 register sopno ss; /* start sop of current subRE */
313 register sopno es; /* end sop of current subRE */
314 register char *sp; /* start of string matched by it */
315 register char *stp; /* string matched by it cannot pass here */
316 register char *rest; /* start of rest of string */
317 register char *tail; /* string unmatched by rest of RE */
318 register sopno ssub; /* start sop of subsubRE */
319 register sopno esub; /* end sop of subsubRE */
320 register char *ssp; /* start of string matched by subsubRE */
321 register char *sep; /* end of string matched by subsubRE */
322 register char *oldssp; /* previous ssp */
323 register char *dp;
324
325 AT("diss", start, stop, startst, stopst);
326 sp = start;
327 for (ss = startst; ss < stopst; ss = es) {
328 /* identify end of subRE */
329 es = ss;
330 switch (OP(m->g->strip[es])) {
331 case OPLUS_:
332 case OQUEST_:
333 es += OPND(m->g->strip[es]);
334 break;
335 case OCH_:
336 while (OP(m->g->strip[es]) != O_CH)
337 es += OPND(m->g->strip[es]);
338 break;
339 }
340 es++;
341
342 /* figure out what it matched */
343 switch (OP(m->g->strip[ss])) {
344 case OEND:
345 assert(nope);
346 break;
347 case OCHAR:
348 sp++;
349 break;
350 case OBOL:
351 case OEOL:
352 case OBOW:
353 case OEOW:
354 break;
355 case OANY:
356 case OANYOF:
357 sp++;
358 break;
359 case OBACK_:
360 case O_BACK:
361 assert(nope);
362 break;
363 /* cases where length of match is hard to find */
364 case OQUEST_:
365 stp = stop;
366 for (;;) {
367 /* how long could this one be? */
368 rest = slow(m, sp, stp, ss, es);
369 assert(rest != NULL); /* it did match */
370 /* could the rest match the rest? */
371 tail = slow(m, rest, stop, es, stopst);
372 if (tail == stop)
373 break; /* yes! */
374 /* no -- try a shorter match for this one */
375 stp = rest - 1;
376 assert(stp >= sp); /* it did work */
377 }
378 ssub = ss + 1;
379 esub = es - 1;
380 /* did innards match? */
381 if (slow(m, sp, rest, ssub, esub) != NULL) {
382 dp = dissect(m, sp, rest, ssub, esub);
383 assert(dp == rest);
384 } else /* no */
385 assert(sp == rest);
386 sp = rest;
387 break;
388 case OPLUS_:
389 stp = stop;
390 for (;;) {
391 /* how long could this one be? */
392 rest = slow(m, sp, stp, ss, es);
393 assert(rest != NULL); /* it did match */
394 /* could the rest match the rest? */
395 tail = slow(m, rest, stop, es, stopst);
396 if (tail == stop)
397 break; /* yes! */
398 /* no -- try a shorter match for this one */
399 stp = rest - 1;
400 assert(stp >= sp); /* it did work */
401 }
402 ssub = ss + 1;
403 esub = es - 1;
404 ssp = sp;
405 oldssp = ssp;
406 for (;;) { /* find last match of innards */
407 sep = slow(m, ssp, rest, ssub, esub);
408 if (sep == NULL || sep == ssp)
409 break; /* failed or matched null */
410 oldssp = ssp; /* on to next try */
411 ssp = sep;
412 }
413 if (sep == NULL) {
414 /* last successful match */
415 sep = ssp;
416 ssp = oldssp;
417 }
418 assert(sep == rest); /* must exhaust substring */
419 assert(slow(m, ssp, sep, ssub, esub) == rest);
420 dp = dissect(m, ssp, sep, ssub, esub);
421 assert(dp == sep);
422 sp = rest;
423 break;
424 case OCH_:
425 stp = stop;
426 for (;;) {
427 /* how long could this one be? */
428 rest = slow(m, sp, stp, ss, es);
429 assert(rest != NULL); /* it did match */
430 /* could the rest match the rest? */
431 tail = slow(m, rest, stop, es, stopst);
432 if (tail == stop)
433 break; /* yes! */
434 /* no -- try a shorter match for this one */
435 stp = rest - 1;
436 assert(stp >= sp); /* it did work */
437 }
438 ssub = ss + 1;
439 esub = ss + OPND(m->g->strip[ss]) - 1;
440 assert(OP(m->g->strip[esub]) == OOR1);
441 for (;;) { /* find first matching branch */
442 if (slow(m, sp, rest, ssub, esub) == rest)
443 break; /* it matched all of it */
444 /* that one missed, try next one */
445 assert(OP(m->g->strip[esub]) == OOR1);
446 esub++;
447 assert(OP(m->g->strip[esub]) == OOR2);
448 ssub = esub + 1;
449 esub += OPND(m->g->strip[esub]);
450 if (OP(m->g->strip[esub]) == OOR2)
451 esub--;
452 else
453 assert(OP(m->g->strip[esub]) == O_CH);
454 }
455 dp = dissect(m, sp, rest, ssub, esub);
456 assert(dp == rest);
457 sp = rest;
458 break;
459 case O_PLUS:
460 case O_QUEST:
461 case OOR1:
462 case OOR2:
463 case O_CH:
464 assert(nope);
465 break;
466 case OLPAREN:
467 i = OPND(m->g->strip[ss]);
468 assert(0 < i && i <= m->g->nsub);
469 m->pmatch[i].rm_so = sp - m->offp;
470 break;
471 case ORPAREN:
472 i = OPND(m->g->strip[ss]);
473 assert(0 < i && i <= m->g->nsub);
474 m->pmatch[i].rm_eo = sp - m->offp;
475 break;
476 default: /* uh oh */
477 assert(nope);
478 break;
479 }
480 }
481
482 assert(sp == stop);
483 return(sp);
484 }
485
486 /*
487 - backref - figure out what matched what, figuring in back references
488 == static char *backref(register struct match *m, char *start, \
489 == char *stop, sopno startst, sopno stopst, sopno lev);
490 */
491 static char * /* == stop (success) or NULL (failure) */
492 backref(m, start, stop, startst, stopst, lev)
493 register struct match *m;
494 char *start;
495 char *stop;
496 sopno startst;
497 sopno stopst;
498 sopno lev; /* PLUS nesting level */
499 {
500 register int i;
501 register sopno ss; /* start sop of current subRE */
502 register char *sp; /* start of string matched by it */
503 register sopno ssub; /* start sop of subsubRE */
504 register sopno esub; /* end sop of subsubRE */
505 register char *ssp; /* start of string matched by subsubRE */
506 register char *dp;
507 register size_t len;
508 register int hard;
509 register sop s;
510 register regoff_t offsave;
511 register cset *cs;
512
513 AT("back", start, stop, startst, stopst);
514 sp = start;
515
516 /* get as far as we can with easy stuff */
517 hard = 0;
518 for (ss = startst; !hard && ss < stopst; ss++)
519 switch (OP(s = m->g->strip[ss])) {
520 case OCHAR:
521 if (sp == stop || *sp++ != (char)OPND(s))
522 return(NULL);
523 break;
524 case OANY:
525 if (sp == stop)
526 return(NULL);
527 sp++;
528 break;
529 case OANYOF:
530 cs = &m->g->sets[OPND(s)];
531 if (sp == stop || !CHIN(cs, *sp++))
532 return(NULL);
533 break;
534 case OBOL:
535 if ( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
536 (sp < m->endp && *(sp-1) == '\n' &&
537 (m->g->cflags&REG_NEWLINE)) )
538 { /* yes */ }
539 else
540 return(NULL);
541 break;
542 case OEOL:
543 if ( (sp == m->endp && !(m->eflags&REG_NOTEOL)) ||
544 (sp < m->endp && *sp == '\n' &&
545 (m->g->cflags&REG_NEWLINE)) )
546 { /* yes */ }
547 else
548 return(NULL);
549 break;
550 case OBOW:
551 if (( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
552 (sp < m->endp && *(sp-1) == '\n' &&
553 (m->g->cflags&REG_NEWLINE)) ||
554 (sp > m->beginp &&
555 !ISWORD(*(sp-1))) ) &&
556 (sp < m->endp && ISWORD(*sp)) )
557 { /* yes */ }
558 else
559 return(NULL);
560 break;
561 case OEOW:
562 if (( (sp == m->endp && !(m->eflags&REG_NOTEOL)) ||
563 (sp < m->endp && *sp == '\n' &&
564 (m->g->cflags&REG_NEWLINE)) ||
565 (sp < m->endp && !ISWORD(*sp)) ) &&
566 (sp > m->beginp && ISWORD(*(sp-1))) )
567 { /* yes */ }
568 else
569 return(NULL);
570 break;
571 case O_QUEST:
572 break;
573 case OOR1: /* matches null but needs to skip */
574 ss++;
575 s = m->g->strip[ss];
576 do {
577 assert(OP(s) == OOR2);
578 ss += OPND(s);
579 } while (OP(s = m->g->strip[ss]) != O_CH);
580 /* note that the ss++ gets us past the O_CH */
581 break;
582 default: /* have to make a choice */
583 hard = 1;
584 break;
585 }
586 if (!hard) { /* that was it! */
587 if (sp != stop)
588 return(NULL);
589 return(sp);
590 }
591 ss--; /* adjust for the for's final increment */
592
593 /* the hard stuff */
594 AT("hard", sp, stop, ss, stopst);
595 s = m->g->strip[ss];
596 switch (OP(s)) {
597 case OBACK_: /* the vilest depths */
598 i = OPND(s);
599 assert(0 < i && i <= m->g->nsub);
600 if (m->pmatch[i].rm_eo == -1)
601 return(NULL);
602 assert(m->pmatch[i].rm_so != -1);
603 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
604 assert(stop - m->beginp >= len);
605 if (sp > stop - len)
606 return(NULL); /* not enough left to match */
607 ssp = m->offp + m->pmatch[i].rm_so;
608 if (memcmp(sp, ssp, len) != 0)
609 return(NULL);
610 while (m->g->strip[ss] != SOP(O_BACK, i))
611 ss++;
612 return(backref(m, sp+len, stop, ss+1, stopst, lev));
613 break;
614 case OQUEST_: /* to null or not */
615 dp = backref(m, sp, stop, ss+1, stopst, lev);
616 if (dp != NULL)
617 return(dp); /* not */
618 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev));
619 break;
620 case OPLUS_:
621 assert(m->lastpos != NULL);
622 assert(lev+1 <= m->g->nplus);
623 m->lastpos[lev+1] = sp;
624 return(backref(m, sp, stop, ss+1, stopst, lev+1));
625 break;
626 case O_PLUS:
627 if (sp == m->lastpos[lev]) /* last pass matched null */
628 return(backref(m, sp, stop, ss+1, stopst, lev-1));
629 /* try another pass */
630 m->lastpos[lev] = sp;
631 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev);
632 if (dp == NULL)
633 return(backref(m, sp, stop, ss+1, stopst, lev-1));
634 else
635 return(dp);
636 break;
637 case OCH_: /* find the right one, if any */
638 ssub = ss + 1;
639 esub = ss + OPND(s) - 1;
640 assert(OP(m->g->strip[esub]) == OOR1);
641 for (;;) { /* find first matching branch */
642 dp = backref(m, sp, stop, ssub, esub, lev);
643 if (dp != NULL)
644 return(dp);
645 /* that one missed, try next one */
646 if (OP(m->g->strip[esub]) == O_CH)
647 return(NULL); /* there is none */
648 esub++;
649 assert(OP(m->g->strip[esub]) == OOR2);
650 ssub = esub + 1;
651 esub += OPND(m->g->strip[esub]);
652 if (OP(m->g->strip[esub]) == OOR2)
653 esub--;
654 else
655 assert(OP(m->g->strip[esub]) == O_CH);
656 }
657 break;
658 case OLPAREN: /* must undo assignment if rest fails */
659 i = OPND(s);
660 assert(0 < i && i <= m->g->nsub);
661 offsave = m->pmatch[i].rm_so;
662 m->pmatch[i].rm_so = sp - m->offp;
663 dp = backref(m, sp, stop, ss+1, stopst, lev);
664 if (dp != NULL)
665 return(dp);
666 m->pmatch[i].rm_so = offsave;
667 return(NULL);
668 break;
669 case ORPAREN: /* must undo assignment if rest fails */
670 i = OPND(s);
671 assert(0 < i && i <= m->g->nsub);
672 offsave = m->pmatch[i].rm_eo;
673 m->pmatch[i].rm_eo = sp - m->offp;
674 dp = backref(m, sp, stop, ss+1, stopst, lev);
675 if (dp != NULL)
676 return(dp);
677 m->pmatch[i].rm_eo = offsave;
678 return(NULL);
679 break;
680 default: /* uh oh */
681 assert(nope);
682 break;
683 }
684
685 /* "can't happen" */
686 assert(nope);
687 /* NOTREACHED */
688 return "shut up gcc";
689 }
690
691 /*
692 - fast - step through the string at top speed
693 == static char *fast(register struct match *m, char *start, \
694 == char *stop, sopno startst, sopno stopst);
695 */
696 static char * /* where tentative match ended, or NULL */
697 fast(m, start, stop, startst, stopst)
698 register struct match *m;
699 char *start;
700 char *stop;
701 sopno startst;
702 sopno stopst;
703 {
704 register states st = m->st;
705 register states fresh = m->fresh;
706 register states tmp = m->tmp;
707 register char *p = start;
708 register int c = (start == m->beginp) ? OUT : *(start-1);
709 register int lastc; /* previous c */
710 register int flagch;
711 register int i;
712 register char *coldp; /* last p after which no match was underway */
713
714 CLEAR(st);
715 SET1(st, startst);
716 st = step(m->g, startst, stopst, st, NOTHING, st);
717 ASSIGN(fresh, st);
718 SP("start", st, *p);
719 coldp = NULL;
720 for (;;) {
721 /* next character */
722 lastc = c;
723 c = (p == m->endp) ? OUT : *p;
724 if (EQ(st, fresh))
725 coldp = p;
726
727 /* is there an EOL and/or BOL between lastc and c? */
728 flagch = '\0';
729 i = 0;
730 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
731 (lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
732 flagch = BOL;
733 i = m->g->nbol;
734 }
735 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
736 (c == OUT && !(m->eflags&REG_NOTEOL)) ) {
737 flagch = (flagch == BOL) ? BOLEOL : EOL;
738 i += m->g->neol;
739 }
740 if (i != 0) {
741 for (; i > 0; i--)
742 st = step(m->g, startst, stopst, st, flagch, st);
743 SP("boleol", st, c);
744 }
745
746 /* how about a word boundary? */
747 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
748 (c != OUT && ISWORD(c)) ) {
749 flagch = BOW;
750 }
751 if ( (lastc != OUT && ISWORD(lastc)) &&
752 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
753 flagch = EOW;
754 }
755 if (flagch == BOW || flagch == EOW) {
756 st = step(m->g, startst, stopst, st, flagch, st);
757 SP("boweow", st, c);
758 }
759
760 /* are we done? */
761 if (ISSET(st, stopst) || p == stop)
762 break; /* NOTE BREAK OUT */
763
764 /* no, we must deal with this character */
765 ASSIGN(tmp, st);
766 ASSIGN(st, fresh);
767 assert(c != OUT);
768 st = step(m->g, startst, stopst, tmp, c, st);
769 SP("aft", st, c);
770 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
771 p++;
772 }
773
774 assert(coldp != NULL);
775 m->coldp = coldp;
776 if (ISSET(st, stopst))
777 return(p+1);
778 else
779 return(NULL);
780 }
781
782 /*
783 - slow - step through the string more deliberately
784 == static char *slow(register struct match *m, char *start, \
785 == char *stop, sopno startst, sopno stopst);
786 */
787 static char * /* where it ended */
788 slow(m, start, stop, startst, stopst)
789 register struct match *m;
790 char *start;
791 char *stop;
792 sopno startst;
793 sopno stopst;
794 {
795 register states st = m->st;
796 register states empty = m->empty;
797 register states tmp = m->tmp;
798 register char *p = start;
799 register int c = (start == m->beginp) ? OUT : *(start-1);
800 register int lastc; /* previous c */
801 register int flagch;
802 register int i;
803 register char *matchp; /* last p at which a match ended */
804
805 AT("slow", start, stop, startst, stopst);
806 CLEAR(st);
807 SET1(st, startst);
808 SP("sstart", st, *p);
809 st = step(m->g, startst, stopst, st, NOTHING, st);
810 matchp = NULL;
811 for (;;) {
812 /* next character */
813 lastc = c;
814 c = (p == m->endp) ? OUT : *p;
815
816 /* is there an EOL and/or BOL between lastc and c? */
817 flagch = '\0';
818 i = 0;
819 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
820 (lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
821 flagch = BOL;
822 i = m->g->nbol;
823 }
824 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
825 (c == OUT && !(m->eflags&REG_NOTEOL)) ) {
826 flagch = (flagch == BOL) ? BOLEOL : EOL;
827 i += m->g->neol;
828 }
829 if (i != 0) {
830 for (; i > 0; i--)
831 st = step(m->g, startst, stopst, st, flagch, st);
832 SP("sboleol", st, c);
833 }
834
835 /* how about a word boundary? */
836 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
837 (c != OUT && ISWORD(c)) ) {
838 flagch = BOW;
839 }
840 if ( (lastc != OUT && ISWORD(lastc)) &&
841 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
842 flagch = EOW;
843 }
844 if (flagch == BOW || flagch == EOW) {
845 st = step(m->g, startst, stopst, st, flagch, st);
846 SP("sboweow", st, c);
847 }
848
849 /* are we done? */
850 if (ISSET(st, stopst))
851 matchp = p;
852 if (EQ(st, empty) || p == stop)
853 break; /* NOTE BREAK OUT */
854
855 /* no, we must deal with this character */
856 ASSIGN(tmp, st);
857 ASSIGN(st, empty);
858 assert(c != OUT);
859 st = step(m->g, startst, stopst, tmp, c, st);
860 SP("saft", st, c);
861 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
862 p++;
863 }
864
865 return(matchp);
866 }
867
868
869 /*
870 - step - map set of states reachable before char to set reachable after
871 == static states step(register struct re_guts *g, sopno start, sopno stop, \
872 == register states bef, int ch, register states aft);
873 == #define BOL (OUT+1)
874 == #define EOL (BOL+1)
875 == #define BOLEOL (BOL+2)
876 == #define NOTHING (BOL+3)
877 == #define BOW (BOL+4)
878 == #define EOW (BOL+5)
879 == #define CODEMAX (BOL+5) // highest code used
880 == #define NONCHAR(c) ((c) > CHAR_MAX)
881 == #define NNONCHAR (CODEMAX-CHAR_MAX)
882 */
883 static states
884 step(g, start, stop, bef, ch, aft)
885 register struct re_guts *g;
886 sopno start; /* start state within strip */
887 sopno stop; /* state after stop state within strip */
888 register states bef; /* states reachable before */
889 int ch; /* character or NONCHAR code */
890 register states aft; /* states already known reachable after */
891 {
892 register cset *cs;
893 register sop s;
894 register sopno pc;
895 register onestate here; /* note, macros know this name */
896 register sopno look;
897 register int i;
898
899 for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
900 s = g->strip[pc];
901 switch (OP(s)) {
902 case OEND:
903 assert(pc == stop-1);
904 break;
905 case OCHAR:
906 /* only characters can match */
907 assert(!NONCHAR(ch) || ch != (char)OPND(s));
908 if (ch == (char)OPND(s))
909 FWD(aft, bef, 1);
910 break;
911 case OBOL:
912 if (ch == BOL || ch == BOLEOL)
913 FWD(aft, bef, 1);
914 break;
915 case OEOL:
916 if (ch == EOL || ch == BOLEOL)
917 FWD(aft, bef, 1);
918 break;
919 case OBOW:
920 if (ch == BOW)
921 FWD(aft, bef, 1);
922 break;
923 case OEOW:
924 if (ch == EOW)
925 FWD(aft, bef, 1);
926 break;
927 case OANY:
928 if (!NONCHAR(ch))
929 FWD(aft, bef, 1);
930 break;
931 case OANYOF:
932 cs = &g->sets[OPND(s)];
933 if (!NONCHAR(ch) && CHIN(cs, ch))
934 FWD(aft, bef, 1);
935 break;
936 case OBACK_: /* ignored here */
937 case O_BACK:
938 FWD(aft, aft, 1);
939 break;
940 case OPLUS_: /* forward, this is just an empty */
941 FWD(aft, aft, 1);
942 break;
943 case O_PLUS: /* both forward and back */
944 FWD(aft, aft, 1);
945 i = ISSETBACK(aft, OPND(s));
946 BACK(aft, aft, OPND(s));
947 if (!i && ISSETBACK(aft, OPND(s))) {
948 /* oho, must reconsider loop body */
949 pc -= OPND(s) + 1;
950 INIT(here, pc);
951 }
952 break;
953 case OQUEST_: /* two branches, both forward */
954 FWD(aft, aft, 1);
955 FWD(aft, aft, OPND(s));
956 break;
957 case O_QUEST: /* just an empty */
958 FWD(aft, aft, 1);
959 break;
960 case OLPAREN: /* not significant here */
961 case ORPAREN:
962 FWD(aft, aft, 1);
963 break;
964 case OCH_: /* mark the first two branches */
965 FWD(aft, aft, 1);
966 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
967 FWD(aft, aft, OPND(s));
968 break;
969 case OOR1: /* done a branch, find the O_CH */
970 if (ISSTATEIN(aft, here)) {
971 for (look = 1;
972 OP(s = g->strip[pc+look]) != O_CH;
973 look += OPND(s))
974 assert(OP(s) == OOR2);
975 FWD(aft, aft, look);
976 }
977 break;
978 case OOR2: /* propagate OCH_'s marking */
979 FWD(aft, aft, 1);
980 if (OP(g->strip[pc+OPND(s)]) != O_CH) {
981 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
982 FWD(aft, aft, OPND(s));
983 }
984 break;
985 case O_CH: /* just empty */
986 FWD(aft, aft, 1);
987 break;
988 default: /* ooooops... */
989 assert(nope);
990 break;
991 }
992 }
993
994 return(aft);
995 }
996
997 #ifdef REDEBUG
998 /*
999 - print - print a set of states
1000 == #ifdef REDEBUG
1001 == static void print(struct match *m, char *caption, states st, \
1002 == int ch, FILE *d);
1003 == #endif
1004 */
1005 static void
1006 print(m, caption, st, ch, d)
1007 struct match *m;
1008 char *caption;
1009 states st;
1010 int ch;
1011 FILE *d;
1012 {
1013 register struct re_guts *g = m->g;
1014 register int i;
1015 register int first = 1;
1016
1017 if (!(m->eflags&REG_TRACE))
1018 return;
1019
1020 fprintf(d, "%s", caption);
1021 if (ch != '\0')
1022 fprintf(d, " %s", pchar(ch));
1023 for (i = 0; i < g->nstates; i++)
1024 if (ISSET(st, i)) {
1025 fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1026 first = 0;
1027 }
1028 fprintf(d, "\n");
1029 }
1030
1031 /*
1032 - at - print current situation
1033 == #ifdef REDEBUG
1034 == static void at(struct match *m, char *title, char *start, char *stop, \
1035 == sopno startst, sopno stopst);
1036 == #endif
1037 */
1038 static void
1039 at(m, title, start, stop, startst, stopst)
1040 struct match *m;
1041 char *title;
1042 char *start;
1043 char *stop;
1044 sopno startst;
1045 sopno stopst;
1046 {
1047 if (!(m->eflags&REG_TRACE))
1048 return;
1049
1050 printf("%s %s-", title, pchar(*start));
1051 printf("%s ", pchar(*stop));
1052 printf("%ld-%ld\n", (long)startst, (long)stopst);
1053 }
1054
1055 #ifndef PCHARDONE
1056 #define PCHARDONE /* never again */
1057 /*
1058 - pchar - make a character printable
1059 == #ifdef REDEBUG
1060 == static char *pchar(int ch);
1061 == #endif
1062 *
1063 * Is this identical to regchar() over in debug.c? Well, yes. But a
1064 * duplicate here avoids having a debugging-capable regexec.o tied to
1065 * a matching debug.o, and this is convenient. It all disappears in
1066 * the non-debug compilation anyway, so it doesn't matter much.
1067 */
1068 static char * /* -> representation */
1069 pchar(ch)
1070 int ch;
1071 {
1072 static char pbuf[10];
1073
1074 if (isprint((uch)ch) || ch == ' ')
1075 sprintf(pbuf, "%c", ch);
1076 else
1077 sprintf(pbuf, "\\%o", ch);
1078 return(pbuf);
1079 }
1080 #endif
1081 #endif
1082
1083 #undef matcher
1084 #undef fast
1085 #undef slow
1086 #undef dissect
1087 #undef backref
1088 #undef step
1089 #undef print
1090 #undef at
1091 #undef match
0 .\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
1 .\" Copyright (c) 1992, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Henry Spencer.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\" @(#)re_format.7 8.3 (Berkeley) 3/20/94
36 .\"
37 .TH RE_FORMAT 7 "March 20, 1994"
38 .SH NAME
39 re_format \- POSIX 1003.2 regular expressions
40 .SH DESCRIPTION
41 Regular expressions (``RE''s),
42 as defined in POSIX 1003.2, come in two forms:
43 modern REs (roughly those of
44 .IR egrep ;
45 1003.2 calls these ``extended'' REs)
46 and obsolete REs (roughly those of
47 .IR ed ;
48 1003.2 ``basic'' REs).
49 Obsolete REs mostly exist for backward compatibility in some old programs;
50 they will be discussed at the end.
51 1003.2 leaves some aspects of RE syntax and semantics open;
52 `\(dg' marks decisions on these aspects that
53 may not be fully portable to other 1003.2 implementations.
54 .PP
55 A (modern) RE is one\(dg or more non-empty\(dg \fIbranches\fR,
56 separated by `|'.
57 It matches anything that matches one of the branches.
58 .PP
59 A branch is one\(dg or more \fIpieces\fR, concatenated.
60 It matches a match for the first, followed by a match for the second, etc.
61 .PP
62 A piece is an \fIatom\fR possibly followed
63 by a single\(dg `*', `+', `?', or \fIbound\fR.
64 An atom followed by `*' matches a sequence of 0 or more matches of the atom.
65 An atom followed by `+' matches a sequence of 1 or more matches of the atom.
66 An atom followed by `?' matches a sequence of 0 or 1 matches of the atom.
67 .PP
68 A \fIbound\fR is `{' followed by an unsigned decimal integer,
69 possibly followed by `,'
70 possibly followed by another unsigned decimal integer,
71 always followed by `}'.
72 The integers must lie between 0 and RE_DUP_MAX (255\(dg) inclusive,
73 and if there are two of them, the first may not exceed the second.
74 An atom followed by a bound containing one integer \fIi\fR
75 and no comma matches
76 a sequence of exactly \fIi\fR matches of the atom.
77 An atom followed by a bound
78 containing one integer \fIi\fR and a comma matches
79 a sequence of \fIi\fR or more matches of the atom.
80 An atom followed by a bound
81 containing two integers \fIi\fR and \fIj\fR matches
82 a sequence of \fIi\fR through \fIj\fR (inclusive) matches of the atom.
83 .PP
84 An atom is a regular expression enclosed in `()' (matching a match for the
85 regular expression),
86 an empty set of `()' (matching the null string)\(dg,
87 a \fIbracket expression\fR (see below), `.'
88 (matching any single character), `^' (matching the null string at the
89 beginning of a line), `$' (matching the null string at the
90 end of a line), a `\e' followed by one of the characters
91 `^.[$()|*+?{\e'
92 (matching that character taken as an ordinary character),
93 a `\e' followed by any other character\(dg
94 (matching that character taken as an ordinary character,
95 as if the `\e' had not been present\(dg),
96 or a single character with no other significance (matching that character).
97 A `{' followed by a character other than a digit is an ordinary
98 character, not the beginning of a bound\(dg.
99 It is illegal to end an RE with `\e'.
100 .PP
101 A \fIbracket expression\fR is a list of characters enclosed in `[]'.
102 It normally matches any single character from the list (but see below).
103 If the list begins with `^',
104 it matches any single character
105 (but see below) \fInot\fR from the rest of the list.
106 If two characters in the list are separated by `\-', this is shorthand
107 for the full \fIrange\fR of characters between those two (inclusive) in the
108 collating sequence,
109 e.g. `[0-9]' in ASCII matches any decimal digit.
110 It is illegal\(dg for two ranges to share an
111 endpoint, e.g. `a-c-e'.
112 Ranges are very collating-sequence-dependent,
113 and portable programs should avoid relying on them.
114 .PP
115 To include a literal `]' in the list, make it the first character
116 (following a possible `^').
117 To include a literal `\-', make it the first or last character,
118 or the second endpoint of a range.
119 To use a literal `\-' as the first endpoint of a range,
120 enclose it in `[.' and `.]' to make it a collating element (see below).
121 With the exception of these and some combinations using `[' (see next
122 paragraphs), all other special characters, including `\e', lose their
123 special significance within a bracket expression.
124 .PP
125 Within a bracket expression, a collating element (a character,
126 a multi-character sequence that collates as if it were a single character,
127 or a collating-sequence name for either)
128 enclosed in `[.' and `.]' stands for the
129 sequence of characters of that collating element.
130 The sequence is a single element of the bracket expression's list.
131 A bracket expression containing a multi-character collating element
132 can thus match more than one character,
133 e.g. if the collating sequence includes a `ch' collating element,
134 then the RE `[[.ch.]]*c' matches the first five characters
135 of `chchcc'.
136 .PP
137 Within a bracket expression, a collating element enclosed in `[=' and
138 `=]' is an equivalence class, standing for the sequences of characters
139 of all collating elements equivalent to that one, including itself.
140 (If there are no other equivalent collating elements,
141 the treatment is as if the enclosing delimiters were `[.' and `.]'.)
142 For example, if o and \o'o^' are the members of an equivalence class,
143 then `[[=o=]]', `[[=\o'o^'=]]', and `[o\o'o^']' are all synonymous.
144 An equivalence class may not\(dg be an endpoint
145 of a range.
146 .PP
147 Within a bracket expression, the name of a \fIcharacter class\fR enclosed
148 in `[:' and `:]' stands for the list of all characters belonging to that
149 class.
150 Standard character class names are:
151 .PP
152 .RS
153 .nf
154 .ta 3c 6c 9c
155 alnum digit punct
156 alpha graph space
157 blank lower upper
158 cntrl print xdigit
159 .fi
160 .RE
161 .PP
162 These stand for the character classes defined in
163 .IR ctype (3).
164 A locale may provide others.
165 A character class may not be used as an endpoint of a range.
166 .PP
167 There are two special cases\(dg of bracket expressions:
168 the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at
169 the beginning and end of a word respectively.
170 A word is defined as a sequence of
171 word characters
172 which is neither preceded nor followed by
173 word characters.
174 A word character is an
175 .I alnum
176 character (as defined by
177 .IR ctype (3))
178 or an underscore.
179 This is an extension,
180 compatible with but not specified by POSIX 1003.2,
181 and should be used with
182 caution in software intended to be portable to other systems.
183 .PP
184 In the event that an RE could match more than one substring of a given
185 string,
186 the RE matches the one starting earliest in the string.
187 If the RE could match more than one substring starting at that point,
188 it matches the longest.
189 Subexpressions also match the longest possible substrings, subject to
190 the constraint that the whole match be as long as possible,
191 with subexpressions starting earlier in the RE taking priority over
192 ones starting later.
193 Note that higher-level subexpressions thus take priority over
194 their lower-level component subexpressions.
195 .PP
196 Match lengths are measured in characters, not collating elements.
197 A null string is considered longer than no match at all.
198 For example,
199 `bb*' matches the three middle characters of `abbbc',
200 `(wee|week)(knights|nights)' matches all ten characters of `weeknights',
201 when `(.*).*' is matched against `abc' the parenthesized subexpression
202 matches all three characters, and
203 when `(a*)*' is matched against `bc' both the whole RE and the parenthesized
204 subexpression match the null string.
205 .PP
206 If case-independent matching is specified,
207 the effect is much as if all case distinctions had vanished from the
208 alphabet.
209 When an alphabetic that exists in multiple cases appears as an
210 ordinary character outside a bracket expression, it is effectively
211 transformed into a bracket expression containing both cases,
212 e.g. `x' becomes `[xX]'.
213 When it appears inside a bracket expression, all case counterparts
214 of it are added to the bracket expression, so that (e.g.) `[x]'
215 becomes `[xX]' and `[^x]' becomes `[^xX]'.
216 .PP
217 No particular limit is imposed on the length of REs\(dg.
218 Programs intended to be portable should not employ REs longer
219 than 256 bytes,
220 as an implementation can refuse to accept such REs and remain
221 POSIX-compliant.
222 .PP
223 Obsolete (``basic'') regular expressions differ in several respects.
224 `|', `+', and `?' are ordinary characters and there is no equivalent
225 for their functionality.
226 The delimiters for bounds are `\e{' and `\e}',
227 with `{' and `}' by themselves ordinary characters.
228 The parentheses for nested subexpressions are `\e(' and `\e)',
229 with `(' and `)' by themselves ordinary characters.
230 `^' is an ordinary character except at the beginning of the
231 RE or\(dg the beginning of a parenthesized subexpression,
232 `$' is an ordinary character except at the end of the
233 RE or\(dg the end of a parenthesized subexpression,
234 and `*' is an ordinary character if it appears at the beginning of the
235 RE or the beginning of a parenthesized subexpression
236 (after a possible leading `^').
237 Finally, there is one new type of atom, a \fIback reference\fR:
238 `\e' followed by a non-zero decimal digit \fId\fR
239 matches the same sequence of characters
240 matched by the \fId\fRth parenthesized subexpression
241 (numbering subexpressions by the positions of their opening parentheses,
242 left to right),
243 so that (e.g.) `\e([bc]\e)\e1' matches `bb' or `cc' but not `bc'.
244 .SH SEE ALSO
245 regex(3)
246 .PP
247 POSIX 1003.2, section 2.8 (Regular Expression Notation).
248 .SH BUGS
249 Having two kinds of REs is a botch.
250 .PP
251 The current 1003.2 spec says that `)' is an ordinary character in
252 the absence of an unmatched `(';
253 this was an unintentional result of a wording error,
254 and change is likely.
255 Avoid relying on it.
256 .PP
257 Back references are a dreadful botch,
258 posing major problems for efficient implementations.
259 They are also somewhat vaguely defined
260 (does
261 `a\e(\e(b\e)*\e2\e)*d' match `abbbd'?).
262 Avoid using them.
263 .PP
264 1003.2's specification of case-independent matching is vague.
265 The ``one case implies all cases'' definition given above
266 is current consensus among implementors as to the right interpretation.
267 .PP
268 The syntax for word boundaries is incredibly ugly.
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
37 */
38
39 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
41 #endif /* LIBC_SCCS and not lint */
42
43 #include <sys/types.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <ctype.h>
47 #include <limits.h>
48 #include <stdlib.h>
49
50 #include "regex.h"
51 #include "utils.h"
52 #include "regex2.h"
53
54 #include "cclass.h"
55 #include "cname.h"
56
57 /*
58 * parse structure, passed up and down to avoid global variables and
59 * other clumsinesses
60 */
61 struct parse {
62 char *next; /* next character in RE */
63 char *end; /* end of string (-> NUL normally) */
64 int error; /* has an error been seen? */
65 sop *strip; /* malloced strip */
66 sopno ssize; /* malloced strip size (allocated) */
67 sopno slen; /* malloced strip length (used) */
68 int ncsalloc; /* number of csets allocated */
69 struct re_guts *g;
70 # define NPAREN 10 /* we need to remember () 1-9 for back refs */
71 sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
72 sopno pend[NPAREN]; /* -> ) ([0] unused) */
73 };
74
75 /* ========= begin header generated by ./mkh ========= */
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
80 /* === regcomp.c === */
81 static void p_ere(struct parse *p, int stop);
82 static void p_ere_exp(struct parse *p);
83 static void p_str(struct parse *p);
84 static void p_bre(struct parse *p, int end1, int end2);
85 static int p_simp_re(struct parse *p, int starordinary);
86 static int p_count(struct parse *p);
87 static void p_bracket(struct parse *p);
88 static void p_b_term(struct parse *p, cset *cs);
89 static void p_b_cclass(struct parse *p, cset *cs);
90 static void p_b_eclass(struct parse *p, cset *cs);
91 static char p_b_symbol(struct parse *p);
92 static char p_b_coll_elem(struct parse *p, int endc);
93 static char othercase(int ch);
94 static void bothcases(struct parse *p, int ch);
95 static void ordinary(struct parse *p, int ch);
96 static void nonnewline(struct parse *p);
97 static void repeat(struct parse *p, sopno start, int from, int to);
98 static int seterr(struct parse *p, int e);
99 static cset *allocset(struct parse *p);
100 static void freeset(struct parse *p, cset *cs);
101 static int freezeset(struct parse *p, cset *cs);
102 static int firstch(struct parse *p, cset *cs);
103 static int nch(struct parse *p, cset *cs);
104 static void mcadd(struct parse *p, cset *cs, char *cp);
105 #if used
106 static void mcsub(cset *cs, char *cp);
107 static int mcin(cset *cs, char *cp);
108 static char *mcfind(cset *cs, char *cp);
109 #endif
110 static void mcinvert(struct parse *p, cset *cs);
111 static void mccase(struct parse *p, cset *cs);
112 static int isinsets(struct re_guts *g, int c);
113 static int samesets(struct re_guts *g, int c1, int c2);
114 static void categorize(struct parse *p, struct re_guts *g);
115 static sopno dupl(struct parse *p, sopno start, sopno finish);
116 static void doemit(struct parse *p, sop op, size_t opnd);
117 static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos);
118 static void dofwd(struct parse *p, sopno pos, sop value);
119 static void enlarge(struct parse *p, sopno size);
120 static void stripsnug(struct parse *p, struct re_guts *g);
121 static void findmust(struct parse *p, struct re_guts *g);
122 static sopno pluscount(struct parse *p, struct re_guts *g);
123
124 #ifdef __cplusplus
125 }
126 #endif
127 /* ========= end header generated by ./mkh ========= */
128
129 static char nuls[10]; /* place to point scanner in event of error */
130
131 /*
132 * macros for use with parse structure
133 * BEWARE: these know that the parse structure is named `p' !!!
134 */
135 #define PEEK() (*p->next)
136 #define PEEK2() (*(p->next+1))
137 #define MORE() (p->next < p->end)
138 #define MORE2() (p->next+1 < p->end)
139 #define SEE(c) (MORE() && PEEK() == (c))
140 #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
141 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
142 #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
143 #define NEXT() (p->next++)
144 #define NEXT2() (p->next += 2)
145 #define NEXTn(n) (p->next += (n))
146 #define GETNEXT() (*p->next++)
147 #define SETERROR(e) seterr(p, (e))
148 #define REQUIRE(co, e) ((co) || SETERROR(e))
149 #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
150 #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
151 #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
152 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
153 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
154 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
155 #define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
156 #define HERE() (p->slen)
157 #define THERE() (p->slen - 1)
158 #define THERETHERE() (p->slen - 2)
159 #define DROP(n) (p->slen -= (n))
160
161 #ifndef NDEBUG
162 static int never = 0; /* for use in asserts; shuts lint up */
163 #else
164 #define never 0 /* some <assert.h>s have bugs too */
165 #endif
166
167 #ifndef BSD4_4
168 int __collate_range_cmp (c1, c2)
169 int c1;
170 int c2;
171 {
172 return c1 - c2;
173 }
174 #ifndef isblank
175 #define isblank(c) ((c) == ' ' || (c) == '\t')
176 #endif
177 #endif
178 /*
179 - regcomp - interface for parser and compilation
180 = extern int regcomp(regex_t *, const char *, int);
181 = #define REG_BASIC 0000
182 = #define REG_EXTENDED 0001
183 = #define REG_ICASE 0002
184 = #define REG_NOSUB 0004
185 = #define REG_NEWLINE 0010
186 = #define REG_NOSPEC 0020
187 = #define REG_PEND 0040
188 = #define REG_DUMP 0200
189 */
190 int /* 0 success, otherwise REG_something */
191 regcomp(preg, pattern, cflags)
192 regex_t *preg;
193 const char *pattern;
194 int cflags;
195 {
196 struct parse pa;
197 register struct re_guts *g;
198 register struct parse *p = &pa;
199 register int i;
200 register size_t len;
201 #ifdef REDEBUG
202 # define GOODFLAGS(f) (f)
203 #else
204 # define GOODFLAGS(f) ((f)&~REG_DUMP)
205 #endif
206
207 cflags = GOODFLAGS(cflags);
208 if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
209 return(REG_INVARG);
210
211 if (cflags&REG_PEND) {
212 if (preg->re_endp < pattern)
213 return(REG_INVARG);
214 len = preg->re_endp - pattern;
215 } else
216 len = strlen((char *)pattern);
217
218 /* do the mallocs early so failure handling is easy */
219 g = (struct re_guts *)malloc(sizeof(struct re_guts) +
220 (NC-1)*sizeof(cat_t));
221 if (g == NULL)
222 return(REG_ESPACE);
223 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
224 p->strip = (sop *)malloc(p->ssize * sizeof(sop));
225 p->slen = 0;
226 if (p->strip == NULL) {
227 free((char *)g);
228 return(REG_ESPACE);
229 }
230
231 /* set things up */
232 p->g = g;
233 p->next = (char *)pattern; /* convenience; we do not modify it */
234 p->end = p->next + len;
235 p->error = 0;
236 p->ncsalloc = 0;
237 for (i = 0; i < NPAREN; i++) {
238 p->pbegin[i] = 0;
239 p->pend[i] = 0;
240 }
241 g->csetsize = NC;
242 g->sets = NULL;
243 g->setbits = NULL;
244 g->ncsets = 0;
245 g->cflags = cflags;
246 g->iflags = 0;
247 g->nbol = 0;
248 g->neol = 0;
249 g->must = NULL;
250 g->mlen = 0;
251 g->nsub = 0;
252 g->ncategories = 1; /* category 0 is "everything else" */
253 g->categories = &g->catspace[-(CHAR_MIN)];
254 (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t));
255 g->backrefs = 0;
256
257 /* do it */
258 EMIT(OEND, 0);
259 g->firststate = THERE();
260 if (cflags&REG_EXTENDED)
261 p_ere(p, OUT);
262 else if (cflags&REG_NOSPEC)
263 p_str(p);
264 else
265 p_bre(p, OUT, OUT);
266 EMIT(OEND, 0);
267 g->laststate = THERE();
268
269 /* tidy up loose ends and fill things in */
270 categorize(p, g);
271 stripsnug(p, g);
272 findmust(p, g);
273 g->nplus = pluscount(p, g);
274 g->magic = MAGIC2;
275 preg->re_nsub = g->nsub;
276 preg->re_g = g;
277 preg->re_magic = MAGIC1;
278 #ifndef REDEBUG
279 /* not debugging, so can't rely on the assert() in regexec() */
280 if (g->iflags&BAD)
281 SETERROR(REG_ASSERT);
282 #endif
283
284 /* win or lose, we're done */
285 if (p->error != 0) /* lose */
286 regfree(preg);
287 return(p->error);
288 }
289
290 /*
291 - p_ere - ERE parser top level, concatenation and alternation
292 == static void p_ere(register struct parse *p, int stop);
293 */
294 static void
295 p_ere(p, stop)
296 register struct parse *p;
297 int stop; /* character this ERE should end at */
298 {
299 register char c;
300 register sopno prevback;
301 register sopno prevfwd;
302 register sopno conc;
303 register int first = 1; /* is this the first alternative? */
304
305 for (;;) {
306 /* do a bunch of concatenated expressions */
307 conc = HERE();
308 while (MORE() && (c = PEEK()) != '|' && c != stop)
309 p_ere_exp(p);
310 (void)REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
311
312 if (!EAT('|'))
313 break; /* NOTE BREAK OUT */
314
315 if (first) {
316 INSERT(OCH_, conc); /* offset is wrong */
317 prevfwd = conc;
318 prevback = conc;
319 first = 0;
320 }
321 ASTERN(OOR1, prevback);
322 prevback = THERE();
323 AHEAD(prevfwd); /* fix previous offset */
324 prevfwd = HERE();
325 EMIT(OOR2, 0); /* offset is very wrong */
326 }
327
328 if (!first) { /* tail-end fixups */
329 AHEAD(prevfwd);
330 ASTERN(O_CH, prevback);
331 }
332
333 assert(!MORE() || SEE(stop));
334 }
335
336 /*
337 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
338 == static void p_ere_exp(register struct parse *p);
339 */
340 static void
341 p_ere_exp(p)
342 register struct parse *p;
343 {
344 register char c;
345 register sopno pos;
346 register int count;
347 register int count2;
348 register sopno subno;
349 int wascaret = 0;
350
351 assert(MORE()); /* caller should have ensured this */
352 c = GETNEXT();
353
354 pos = HERE();
355 switch (c) {
356 case '(':
357 (void)REQUIRE(MORE(), REG_EPAREN);
358 p->g->nsub++;
359 subno = p->g->nsub;
360 if (subno < NPAREN)
361 p->pbegin[subno] = HERE();
362 EMIT(OLPAREN, subno);
363 if (!SEE(')'))
364 p_ere(p, ')');
365 if (subno < NPAREN) {
366 p->pend[subno] = HERE();
367 assert(p->pend[subno] != 0);
368 }
369 EMIT(ORPAREN, subno);
370 (void)MUSTEAT(')', REG_EPAREN);
371 break;
372 #ifndef POSIX_MISTAKE
373 case ')': /* happens only if no current unmatched ( */
374 /*
375 * You may ask, why the ifndef? Because I didn't notice
376 * this until slightly too late for 1003.2, and none of the
377 * other 1003.2 regular-expression reviewers noticed it at
378 * all. So an unmatched ) is legal POSIX, at least until
379 * we can get it fixed.
380 */
381 SETERROR(REG_EPAREN);
382 break;
383 #endif
384 case '^':
385 EMIT(OBOL, 0);
386 p->g->iflags |= USEBOL;
387 p->g->nbol++;
388 wascaret = 1;
389 break;
390 case '$':
391 EMIT(OEOL, 0);
392 p->g->iflags |= USEEOL;
393 p->g->neol++;
394 break;
395 case '|':
396 SETERROR(REG_EMPTY);
397 break;
398 case '*':
399 case '+':
400 case '?':
401 SETERROR(REG_BADRPT);
402 break;
403 case '.':
404 if (p->g->cflags&REG_NEWLINE)
405 nonnewline(p);
406 else
407 EMIT(OANY, 0);
408 break;
409 case '[':
410 p_bracket(p);
411 break;
412 case '\\':
413 (void)REQUIRE(MORE(), REG_EESCAPE);
414 c = GETNEXT();
415 ordinary(p, c);
416 break;
417 case '{': /* okay as ordinary except if digit follows */
418 (void)REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
419 /* FALLTHROUGH */
420 default:
421 ordinary(p, c);
422 break;
423 }
424
425 if (!MORE())
426 return;
427 c = PEEK();
428 /* we call { a repetition if followed by a digit */
429 if (!( c == '*' || c == '+' || c == '?' ||
430 (c == '{' && MORE2() && isdigit(PEEK2())) ))
431 return; /* no repetition, we're done */
432 NEXT();
433
434 (void)REQUIRE(!wascaret, REG_BADRPT);
435 switch (c) {
436 case '*': /* implemented as +? */
437 /* this case does not require the (y|) trick, noKLUDGE */
438 INSERT(OPLUS_, pos);
439 ASTERN(O_PLUS, pos);
440 INSERT(OQUEST_, pos);
441 ASTERN(O_QUEST, pos);
442 break;
443 case '+':
444 INSERT(OPLUS_, pos);
445 ASTERN(O_PLUS, pos);
446 break;
447 case '?':
448 /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
449 INSERT(OCH_, pos); /* offset slightly wrong */
450 ASTERN(OOR1, pos); /* this one's right */
451 AHEAD(pos); /* fix the OCH_ */
452 EMIT(OOR2, 0); /* offset very wrong... */
453 AHEAD(THERE()); /* ...so fix it */
454 ASTERN(O_CH, THERETHERE());
455 break;
456 case '{':
457 count = p_count(p);
458 if (EAT(',')) {
459 if (isdigit(PEEK())) {
460 count2 = p_count(p);
461 (void)REQUIRE(count <= count2, REG_BADBR);
462 } else /* single number with comma */
463 count2 = INFINITY;
464 } else /* just a single number */
465 count2 = count;
466 repeat(p, pos, count, count2);
467 if (!EAT('}')) { /* error heuristics */
468 while (MORE() && PEEK() != '}')
469 NEXT();
470 (void)REQUIRE(MORE(), REG_EBRACE);
471 SETERROR(REG_BADBR);
472 }
473 break;
474 }
475
476 if (!MORE())
477 return;
478 c = PEEK();
479 if (!( c == '*' || c == '+' || c == '?' ||
480 (c == '{' && MORE2() && isdigit(PEEK2())) ) )
481 return;
482 SETERROR(REG_BADRPT);
483 }
484
485 /*
486 - p_str - string (no metacharacters) "parser"
487 == static void p_str(register struct parse *p);
488 */
489 static void
490 p_str(p)
491 register struct parse *p;
492 {
493 (void)REQUIRE(MORE(), REG_EMPTY);
494 while (MORE())
495 ordinary(p, GETNEXT());
496 }
497
498 /*
499 - p_bre - BRE parser top level, anchoring and concatenation
500 == static void p_bre(register struct parse *p, register int end1, \
501 == register int end2);
502 * Giving end1 as OUT essentially eliminates the end1/end2 check.
503 *
504 * This implementation is a bit of a kludge, in that a trailing $ is first
505 * taken as an ordinary character and then revised to be an anchor. The
506 * only undesirable side effect is that '$' gets included as a character
507 * category in such cases. This is fairly harmless; not worth fixing.
508 * The amount of lookahead needed to avoid this kludge is excessive.
509 */
510 static void
511 p_bre(p, end1, end2)
512 register struct parse *p;
513 register int end1; /* first terminating character */
514 register int end2; /* second terminating character */
515 {
516 register sopno start = HERE();
517 register int first = 1; /* first subexpression? */
518 register int wasdollar = 0;
519
520 if (EAT('^')) {
521 EMIT(OBOL, 0);
522 p->g->iflags |= USEBOL;
523 p->g->nbol++;
524 }
525 while (MORE() && !SEETWO(end1, end2)) {
526 wasdollar = p_simp_re(p, first);
527 first = 0;
528 }
529 if (wasdollar) { /* oops, that was a trailing anchor */
530 DROP(1);
531 EMIT(OEOL, 0);
532 p->g->iflags |= USEEOL;
533 p->g->neol++;
534 }
535
536 (void)REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
537 }
538
539 /*
540 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
541 == static int p_simp_re(register struct parse *p, int starordinary);
542 */
543 static int /* was the simple RE an unbackslashed $? */
544 p_simp_re(p, starordinary)
545 register struct parse *p;
546 int starordinary; /* is a leading * an ordinary character? */
547 {
548 register int c;
549 register int count;
550 register int count2;
551 register sopno pos;
552 register int i;
553 register sopno subno;
554 # define BACKSL (1<<CHAR_BIT)
555
556 pos = HERE(); /* repetion op, if any, covers from here */
557
558 assert(MORE()); /* caller should have ensured this */
559 c = GETNEXT();
560 if (c == '\\') {
561 (void)REQUIRE(MORE(), REG_EESCAPE);
562 c = BACKSL | (unsigned char)GETNEXT();
563 }
564 switch (c) {
565 case '.':
566 if (p->g->cflags&REG_NEWLINE)
567 nonnewline(p);
568 else
569 EMIT(OANY, 0);
570 break;
571 case '[':
572 p_bracket(p);
573 break;
574 case BACKSL|'{':
575 SETERROR(REG_BADRPT);
576 break;
577 case BACKSL|'(':
578 p->g->nsub++;
579 subno = p->g->nsub;
580 if (subno < NPAREN)
581 p->pbegin[subno] = HERE();
582 EMIT(OLPAREN, subno);
583 /* the MORE here is an error heuristic */
584 if (MORE() && !SEETWO('\\', ')'))
585 p_bre(p, '\\', ')');
586 if (subno < NPAREN) {
587 p->pend[subno] = HERE();
588 assert(p->pend[subno] != 0);
589 }
590 EMIT(ORPAREN, subno);
591 (void)REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
592 break;
593 case BACKSL|')': /* should not get here -- must be user */
594 case BACKSL|'}':
595 SETERROR(REG_EPAREN);
596 break;
597 case BACKSL|'1':
598 case BACKSL|'2':
599 case BACKSL|'3':
600 case BACKSL|'4':
601 case BACKSL|'5':
602 case BACKSL|'6':
603 case BACKSL|'7':
604 case BACKSL|'8':
605 case BACKSL|'9':
606 i = (c&~BACKSL) - '0';
607 assert(i < NPAREN);
608 if (p->pend[i] != 0) {
609 assert(i <= p->g->nsub);
610 EMIT(OBACK_, i);
611 assert(p->pbegin[i] != 0);
612 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
613 assert(OP(p->strip[p->pend[i]]) == ORPAREN);
614 (void) dupl(p, p->pbegin[i]+1, p->pend[i]);
615 EMIT(O_BACK, i);
616 } else
617 SETERROR(REG_ESUBREG);
618 p->g->backrefs = 1;
619 break;
620 case '*':
621 (void)REQUIRE(starordinary, REG_BADRPT);
622 /* FALLTHROUGH */
623 default:
624 ordinary(p, c &~ BACKSL);
625 break;
626 }
627
628 if (EAT('*')) { /* implemented as +? */
629 /* this case does not require the (y|) trick, noKLUDGE */
630 INSERT(OPLUS_, pos);
631 ASTERN(O_PLUS, pos);
632 INSERT(OQUEST_, pos);
633 ASTERN(O_QUEST, pos);
634 } else if (EATTWO('\\', '{')) {
635 count = p_count(p);
636 if (EAT(',')) {
637 if (MORE() && isdigit(PEEK())) {
638 count2 = p_count(p);
639 (void)REQUIRE(count <= count2, REG_BADBR);
640 } else /* single number with comma */
641 count2 = INFINITY;
642 } else /* just a single number */
643 count2 = count;
644 repeat(p, pos, count, count2);
645 if (!EATTWO('\\', '}')) { /* error heuristics */
646 while (MORE() && !SEETWO('\\', '}'))
647 NEXT();
648 (void)REQUIRE(MORE(), REG_EBRACE);
649 SETERROR(REG_BADBR);
650 }
651 } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */
652 return(1);
653
654 return(0);
655 }
656
657 /*
658 - p_count - parse a repetition count
659 == static int p_count(register struct parse *p);
660 */
661 static int /* the value */
662 p_count(p)
663 register struct parse *p;
664 {
665 register int count = 0;
666 register int ndigits = 0;
667
668 while (MORE() && isdigit(PEEK()) && count <= DUPMAX) {
669 count = count*10 + (GETNEXT() - '0');
670 ndigits++;
671 }
672
673 (void)REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
674 return(count);
675 }
676
677 /*
678 - p_bracket - parse a bracketed character list
679 == static void p_bracket(register struct parse *p);
680 *
681 * Note a significant property of this code: if the allocset() did SETERROR,
682 * no set operations are done.
683 */
684 static void
685 p_bracket(p)
686 register struct parse *p;
687 {
688 register cset *cs = allocset(p);
689 register int invert = 0;
690
691 /* Dept of Truly Sickening Special-Case Kludges */
692 if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
693 EMIT(OBOW, 0);
694 NEXTn(6);
695 return;
696 }
697 if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
698 EMIT(OEOW, 0);
699 NEXTn(6);
700 return;
701 }
702
703 if (EAT('^'))
704 invert++; /* make note to invert set at end */
705 if (EAT(']'))
706 CHadd(cs, ']');
707 else if (EAT('-'))
708 CHadd(cs, '-');
709 while (MORE() && PEEK() != ']' && !SEETWO('-', ']'))
710 p_b_term(p, cs);
711 if (EAT('-'))
712 CHadd(cs, '-');
713 (void)MUSTEAT(']', REG_EBRACK);
714
715 if (p->error != 0) /* don't mess things up further */
716 return;
717
718 if (p->g->cflags&REG_ICASE) {
719 register int i;
720 register int ci;
721
722 for (i = p->g->csetsize - 1; i >= 0; i--)
723 if (CHIN(cs, i) && isalpha(i)) {
724 ci = othercase(i);
725 if (ci != i)
726 CHadd(cs, ci);
727 }
728 if (cs->multis != NULL)
729 mccase(p, cs);
730 }
731 if (invert) {
732 register int i;
733
734 for (i = p->g->csetsize - 1; i >= 0; i--)
735 if (CHIN(cs, i))
736 CHsub(cs, i);
737 else
738 CHadd(cs, i);
739 if (p->g->cflags&REG_NEWLINE)
740 CHsub(cs, '\n');
741 if (cs->multis != NULL)
742 mcinvert(p, cs);
743 }
744
745 assert(cs->multis == NULL); /* xxx */
746
747 if (nch(p, cs) == 1) { /* optimize singleton sets */
748 ordinary(p, firstch(p, cs));
749 freeset(p, cs);
750 } else
751 EMIT(OANYOF, freezeset(p, cs));
752 }
753
754 /*
755 - p_b_term - parse one term of a bracketed character list
756 == static void p_b_term(register struct parse *p, register cset *cs);
757 */
758 static void
759 p_b_term(p, cs)
760 register struct parse *p;
761 register cset *cs;
762 {
763 register char c;
764 register char start, finish;
765 register int i;
766
767 /* classify what we've got */
768 switch ((MORE()) ? PEEK() : '\0') {
769 case '[':
770 c = (MORE2()) ? PEEK2() : '\0';
771 break;
772 case '-':
773 SETERROR(REG_ERANGE);
774 return; /* NOTE RETURN */
775 break;
776 default:
777 c = '\0';
778 break;
779 }
780
781 switch (c) {
782 case ':': /* character class */
783 NEXT2();
784 (void)REQUIRE(MORE(), REG_EBRACK);
785 c = PEEK();
786 (void)REQUIRE(c != '-' && c != ']', REG_ECTYPE);
787 p_b_cclass(p, cs);
788 (void)REQUIRE(MORE(), REG_EBRACK);
789 (void)REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
790 break;
791 case '=': /* equivalence class */
792 NEXT2();
793 (void)REQUIRE(MORE(), REG_EBRACK);
794 c = PEEK();
795 (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
796 p_b_eclass(p, cs);
797 (void)REQUIRE(MORE(), REG_EBRACK);
798 (void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
799 break;
800 default: /* symbol, ordinary character, or range */
801 /* xxx revision needed for multichar stuff */
802 start = p_b_symbol(p);
803 if (SEE('-') && MORE2() && PEEK2() != ']') {
804 /* range */
805 NEXT();
806 if (EAT('-'))
807 finish = '-';
808 else
809 finish = p_b_symbol(p);
810 } else
811 finish = start;
812 if (start == finish)
813 CHadd(cs, start);
814 else {
815 (void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE);
816 for (i = CHAR_MIN; i <= CHAR_MAX; i++) {
817 if ( __collate_range_cmp(start, i) <= 0
818 && __collate_range_cmp(i, finish) <= 0
819 )
820 CHadd(cs, i);
821 }
822 }
823 break;
824 }
825 }
826
827 /*
828 - p_b_cclass - parse a character-class name and deal with it
829 == static void p_b_cclass(register struct parse *p, register cset *cs);
830 */
831 static void
832 p_b_cclass(p, cs)
833 register struct parse *p;
834 register cset *cs;
835 {
836 register int c;
837 register char *sp = p->next;
838 register struct cclass *cp;
839 register size_t len;
840
841 while (MORE() && isalpha((uch)PEEK()))
842 NEXT();
843 len = p->next - sp;
844 for (cp = cclasses; cp->name != NULL; cp++)
845 if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
846 break;
847 if (cp->name == NULL) {
848 /* oops, didn't find it */
849 SETERROR(REG_ECTYPE);
850 return;
851 }
852
853 switch (cp->fidx) {
854 case CALNUM:
855 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
856 if (isalnum((uch)c))
857 CHadd(cs, c);
858 break;
859 case CALPHA:
860 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
861 if (isalpha((uch)c))
862 CHadd(cs, c);
863 break;
864 case CBLANK:
865 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
866 if (isblank((uch)c))
867 CHadd(cs, c);
868 break;
869 case CCNTRL:
870 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
871 if (iscntrl((uch)c))
872 CHadd(cs, c);
873 break;
874 case CDIGIT:
875 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
876 if (isdigit((uch)c))
877 CHadd(cs, c);
878 break;
879 case CGRAPH:
880 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
881 if (isgraph((uch)c))
882 CHadd(cs, c);
883 break;
884 case CLOWER:
885 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
886 if (islower((uch)c))
887 CHadd(cs, c);
888 break;
889 case CPRINT:
890 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
891 if (isprint((uch)c))
892 CHadd(cs, c);
893 break;
894 case CPUNCT:
895 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
896 if (ispunct((uch)c))
897 CHadd(cs, c);
898 break;
899 case CSPACE:
900 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
901 if (isspace((uch)c))
902 CHadd(cs, c);
903 break;
904 case CUPPER:
905 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
906 if (isupper((uch)c))
907 CHadd(cs, c);
908 break;
909 case CXDIGIT:
910 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
911 if (isxdigit((uch)c))
912 CHadd(cs, c);
913 break;
914 }
915 #if 0
916 for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
917 MCadd(p, cs, u);
918 #endif
919 }
920
921 /*
922 - p_b_eclass - parse an equivalence-class name and deal with it
923 == static void p_b_eclass(register struct parse *p, register cset *cs);
924 *
925 * This implementation is incomplete. xxx
926 */
927 static void
928 p_b_eclass(p, cs)
929 register struct parse *p;
930 register cset *cs;
931 {
932 register char c;
933
934 c = p_b_coll_elem(p, '=');
935 CHadd(cs, c);
936 }
937
938 /*
939 - p_b_symbol - parse a character or [..]ed multicharacter collating symbol
940 == static char p_b_symbol(register struct parse *p);
941 */
942 static char /* value of symbol */
943 p_b_symbol(p)
944 register struct parse *p;
945 {
946 register char value;
947
948 (void)REQUIRE(MORE(), REG_EBRACK);
949 if (!EATTWO('[', '.'))
950 return(GETNEXT());
951
952 /* collating symbol */
953 value = p_b_coll_elem(p, '.');
954 (void)REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
955 return(value);
956 }
957
958 /*
959 - p_b_coll_elem - parse a collating-element name and look it up
960 == static char p_b_coll_elem(register struct parse *p, int endc);
961 */
962 static char /* value of collating element */
963 p_b_coll_elem(p, endc)
964 register struct parse *p;
965 int endc; /* name ended by endc,']' */
966 {
967 register char *sp = p->next;
968 register struct cname *cp;
969 register int len;
970
971 while (MORE() && !SEETWO(endc, ']'))
972 NEXT();
973 if (!MORE()) {
974 SETERROR(REG_EBRACK);
975 return(0);
976 }
977 len = p->next - sp;
978 for (cp = cnames; cp->name != NULL; cp++)
979 if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
980 return(cp->code); /* known name */
981 if (len == 1)
982 return(*sp); /* single character */
983 SETERROR(REG_ECOLLATE); /* neither */
984 return(0);
985 }
986
987 /*
988 - othercase - return the case counterpart of an alphabetic
989 == static char othercase(int ch);
990 */
991 static char /* if no counterpart, return ch */
992 othercase(ch)
993 int ch;
994 {
995 ch = (unsigned char)ch;
996 assert(isalpha(ch));
997 if (isupper(ch))
998 return(tolower(ch));
999 else if (islower(ch))
1000 return(toupper(ch));
1001 else /* peculiar, but could happen */
1002 return(ch);
1003 }
1004
1005 /*
1006 - bothcases - emit a dualcase version of a two-case character
1007 == static void bothcases(register struct parse *p, int ch);
1008 *
1009 * Boy, is this implementation ever a kludge...
1010 */
1011 static void
1012 bothcases(p, ch)
1013 register struct parse *p;
1014 int ch;
1015 {
1016 register char *oldnext = p->next;
1017 register char *oldend = p->end;
1018 char bracket[3];
1019
1020 ch = (unsigned char)ch;
1021 assert(othercase(ch) != ch); /* p_bracket() would recurse */
1022 p->next = bracket;
1023 p->end = bracket+2;
1024 bracket[0] = ch;
1025 bracket[1] = ']';
1026 bracket[2] = '\0';
1027 p_bracket(p);
1028 assert(p->next == bracket+2);
1029 p->next = oldnext;
1030 p->end = oldend;
1031 }
1032
1033 /*
1034 - ordinary - emit an ordinary character
1035 == static void ordinary(register struct parse *p, register int ch);
1036 */
1037 static void
1038 ordinary(p, ch)
1039 register struct parse *p;
1040 register int ch;
1041 {
1042 register cat_t *cap = p->g->categories;
1043
1044 if ((p->g->cflags&REG_ICASE) && isalpha((unsigned char)ch) && othercase(ch) != ch)
1045 bothcases(p, ch);
1046 else {
1047 EMIT(OCHAR, (unsigned char)ch);
1048 if (cap[ch] == 0)
1049 cap[ch] = p->g->ncategories++;
1050 }
1051 }
1052
1053 /*
1054 - nonnewline - emit REG_NEWLINE version of OANY
1055 == static void nonnewline(register struct parse *p);
1056 *
1057 * Boy, is this implementation ever a kludge...
1058 */
1059 static void
1060 nonnewline(p)
1061 register struct parse *p;
1062 {
1063 register char *oldnext = p->next;
1064 register char *oldend = p->end;
1065 char bracket[4];
1066
1067 p->next = bracket;
1068 p->end = bracket+3;
1069 bracket[0] = '^';
1070 bracket[1] = '\n';
1071 bracket[2] = ']';
1072 bracket[3] = '\0';
1073 p_bracket(p);
1074 assert(p->next == bracket+3);
1075 p->next = oldnext;
1076 p->end = oldend;
1077 }
1078
1079 /*
1080 - repeat - generate code for a bounded repetition, recursively if needed
1081 == static void repeat(register struct parse *p, sopno start, int from, int to);
1082 */
1083 static void
1084 repeat(p, start, from, to)
1085 register struct parse *p;
1086 sopno start; /* operand from here to end of strip */
1087 int from; /* repeated from this number */
1088 int to; /* to this number of times (maybe INFINITY) */
1089 {
1090 register sopno finish = HERE();
1091 # define N 2
1092 # define INF 3
1093 # define REP(f, t) ((f)*8 + (t))
1094 # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
1095 register sopno copy;
1096
1097 if (p->error != 0) /* head off possible runaway recursion */
1098 return;
1099
1100 assert(from <= to);
1101
1102 switch (REP(MAP(from), MAP(to))) {
1103 case REP(0, 0): /* must be user doing this */
1104 DROP(finish-start); /* drop the operand */
1105 break;
1106 case REP(0, 1): /* as x{1,1}? */
1107 case REP(0, N): /* as x{1,n}? */
1108 case REP(0, INF): /* as x{1,}? */
1109 /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
1110 INSERT(OCH_, start); /* offset is wrong... */
1111 repeat(p, start+1, 1, to);
1112 ASTERN(OOR1, start);
1113 AHEAD(start); /* ... fix it */
1114 EMIT(OOR2, 0);
1115 AHEAD(THERE());
1116 ASTERN(O_CH, THERETHERE());
1117 break;
1118 case REP(1, 1): /* trivial case */
1119 /* done */
1120 break;
1121 case REP(1, N): /* as x?x{1,n-1} */
1122 /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
1123 INSERT(OCH_, start);
1124 ASTERN(OOR1, start);
1125 AHEAD(start);
1126 EMIT(OOR2, 0); /* offset very wrong... */
1127 AHEAD(THERE()); /* ...so fix it */
1128 ASTERN(O_CH, THERETHERE());
1129 copy = dupl(p, start+1, finish+1);
1130 assert(copy == finish+4);
1131 repeat(p, copy, 1, to-1);
1132 break;
1133 case REP(1, INF): /* as x+ */
1134 INSERT(OPLUS_, start);
1135 ASTERN(O_PLUS, start);
1136 break;
1137 case REP(N, N): /* as xx{m-1,n-1} */
1138 copy = dupl(p, start, finish);
1139 repeat(p, copy, from-1, to-1);
1140 break;
1141 case REP(N, INF): /* as xx{n-1,INF} */
1142 copy = dupl(p, start, finish);
1143 repeat(p, copy, from-1, to);
1144 break;
1145 default: /* "can't happen" */
1146 SETERROR(REG_ASSERT); /* just in case */
1147 break;
1148 }
1149 }
1150
1151 /*
1152 - seterr - set an error condition
1153 == static int seterr(register struct parse *p, int e);
1154 */
1155 static int /* useless but makes type checking happy */
1156 seterr(p, e)
1157 register struct parse *p;
1158 int e;
1159 {
1160 if (p->error == 0) /* keep earliest error condition */
1161 p->error = e;
1162 p->next = nuls; /* try to bring things to a halt */
1163 p->end = nuls;
1164 return(0); /* make the return value well-defined */
1165 }
1166
1167 /*
1168 - allocset - allocate a set of characters for []
1169 == static cset *allocset(register struct parse *p);
1170 */
1171 static cset *
1172 allocset(p)
1173 register struct parse *p;
1174 {
1175 register int no = p->g->ncsets++;
1176 register size_t nc;
1177 register size_t nbytes;
1178 register cset *cs;
1179 register size_t css = (size_t)p->g->csetsize;
1180 register int i;
1181
1182 if (no >= p->ncsalloc) { /* need another column of space */
1183 p->ncsalloc += CHAR_BIT;
1184 nc = p->ncsalloc;
1185 assert(nc % CHAR_BIT == 0);
1186 nbytes = nc / CHAR_BIT * css;
1187 if (p->g->sets == NULL)
1188 p->g->sets = (cset *)malloc(nc * sizeof(cset));
1189 else
1190 p->g->sets = (cset *)realloc((char *)p->g->sets,
1191 nc * sizeof(cset));
1192 if (p->g->setbits == NULL)
1193 p->g->setbits = (uch *)malloc(nbytes);
1194 else {
1195 p->g->setbits = (uch *)realloc((char *)p->g->setbits,
1196 nbytes);
1197 /* xxx this isn't right if setbits is now NULL */
1198 for (i = 0; i < no; i++)
1199 p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
1200 }
1201 if (p->g->sets != NULL && p->g->setbits != NULL)
1202 (void) memset((char *)p->g->setbits + (nbytes - css),
1203 0, css);
1204 else {
1205 no = 0;
1206 SETERROR(REG_ESPACE);
1207 /* caller's responsibility not to do set ops */
1208 }
1209 }
1210
1211 assert(p->g->sets != NULL); /* xxx */
1212 cs = &p->g->sets[no];
1213 cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
1214 cs->mask = 1 << ((no) % CHAR_BIT);
1215 cs->hash = 0;
1216 cs->smultis = 0;
1217 cs->multis = NULL;
1218
1219 return(cs);
1220 }
1221
1222 /*
1223 - freeset - free a now-unused set
1224 == static void freeset(register struct parse *p, register cset *cs);
1225 */
1226 static void
1227 freeset(p, cs)
1228 register struct parse *p;
1229 register cset *cs;
1230 {
1231 register int i;
1232 register cset *top = &p->g->sets[p->g->ncsets];
1233 register size_t css = (size_t)p->g->csetsize;
1234
1235 for (i = 0; i < css; i++)
1236 CHsub(cs, i);
1237 if (cs == top-1) /* recover only the easy case */
1238 p->g->ncsets--;
1239 }
1240
1241 /*
1242 - freezeset - final processing on a set of characters
1243 == static int freezeset(register struct parse *p, register cset *cs);
1244 *
1245 * The main task here is merging identical sets. This is usually a waste
1246 * of time (although the hash code minimizes the overhead), but can win
1247 * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash
1248 * is done using addition rather than xor -- all ASCII [aA] sets xor to
1249 * the same value!
1250 */
1251 static int /* set number */
1252 freezeset(p, cs)
1253 register struct parse *p;
1254 register cset *cs;
1255 {
1256 register short h = cs->hash;
1257 register int i;
1258 register cset *top = &p->g->sets[p->g->ncsets];
1259 register cset *cs2;
1260 register size_t css = (size_t)p->g->csetsize;
1261
1262 /* look for an earlier one which is the same */
1263 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
1264 if (cs2->hash == h && cs2 != cs) {
1265 /* maybe */
1266 for (i = 0; i < css; i++)
1267 if (!!CHIN(cs2, i) != !!CHIN(cs, i))
1268 break; /* no */
1269 if (i == css)
1270 break; /* yes */
1271 }
1272
1273 if (cs2 < top) { /* found one */
1274 freeset(p, cs);
1275 cs = cs2;
1276 }
1277
1278 return((int)(cs - p->g->sets));
1279 }
1280
1281 /*
1282 - firstch - return first character in a set (which must have at least one)
1283 == static int firstch(register struct parse *p, register cset *cs);
1284 */
1285 static int /* character; there is no "none" value */
1286 firstch(p, cs)
1287 register struct parse *p;
1288 register cset *cs;
1289 {
1290 register int i;
1291 register size_t css = (size_t)p->g->csetsize;
1292
1293 for (i = 0; i < css; i++)
1294 if (CHIN(cs, i))
1295 return((unsigned char)i);
1296 assert(never);
1297 return(0); /* arbitrary */
1298 }
1299
1300 /*
1301 - nch - number of characters in a set
1302 == static int nch(register struct parse *p, register cset *cs);
1303 */
1304 static int
1305 nch(p, cs)
1306 register struct parse *p;
1307 register cset *cs;
1308 {
1309 register int i;
1310 register size_t css = (size_t)p->g->csetsize;
1311 register int n = 0;
1312
1313 for (i = 0; i < css; i++)
1314 if (CHIN(cs, i))
1315 n++;
1316 return(n);
1317 }
1318
1319 /*
1320 - mcadd - add a collating element to a cset
1321 == static void mcadd(register struct parse *p, register cset *cs, \
1322 == register char *cp);
1323 */
1324 static void
1325 mcadd(p, cs, cp)
1326 register struct parse *p;
1327 register cset *cs;
1328 register char *cp;
1329 {
1330 register size_t oldend = cs->smultis;
1331
1332 cs->smultis += strlen(cp) + 1;
1333 if (cs->multis == NULL)
1334 cs->multis = malloc(cs->smultis);
1335 else
1336 cs->multis = realloc(cs->multis, cs->smultis);
1337 if (cs->multis == NULL) {
1338 SETERROR(REG_ESPACE);
1339 return;
1340 }
1341
1342 (void) strcpy(cs->multis + oldend - 1, cp);
1343 cs->multis[cs->smultis - 1] = '\0';
1344 }
1345
1346 #if used
1347 /*
1348 - mcsub - subtract a collating element from a cset
1349 == static void mcsub(register cset *cs, register char *cp);
1350 */
1351 static void
1352 mcsub(cs, cp)
1353 register cset *cs;
1354 register char *cp;
1355 {
1356 register char *fp = mcfind(cs, cp);
1357 register size_t len = strlen(fp);
1358
1359 assert(fp != NULL);
1360 (void) memmove(fp, fp + len + 1,
1361 cs->smultis - (fp + len + 1 - cs->multis));
1362 cs->smultis -= len;
1363
1364 if (cs->smultis == 0) {
1365 free(cs->multis);
1366 cs->multis = NULL;
1367 return;
1368 }
1369
1370 cs->multis = realloc(cs->multis, cs->smultis);
1371 assert(cs->multis != NULL);
1372 }
1373
1374 /*
1375 - mcin - is a collating element in a cset?
1376 == static int mcin(register cset *cs, register char *cp);
1377 */
1378 static int
1379 mcin(cs, cp)
1380 register cset *cs;
1381 register char *cp;
1382 {
1383 return(mcfind(cs, cp) != NULL);
1384 }
1385
1386 /*
1387 - mcfind - find a collating element in a cset
1388 == static char *mcfind(register cset *cs, register char *cp);
1389 */
1390 static char *
1391 mcfind(cs, cp)
1392 register cset *cs;
1393 register char *cp;
1394 {
1395 register char *p;
1396
1397 if (cs->multis == NULL)
1398 return(NULL);
1399 for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
1400 if (strcmp(cp, p) == 0)
1401 return(p);
1402 return(NULL);
1403 }
1404 #endif
1405
1406 /*
1407 - mcinvert - invert the list of collating elements in a cset
1408 == static void mcinvert(register struct parse *p, register cset *cs);
1409 *
1410 * This would have to know the set of possibilities. Implementation
1411 * is deferred.
1412 */
1413 static void
1414 mcinvert(p, cs)
1415 register struct parse *p;
1416 register cset *cs;
1417 {
1418 assert(cs->multis == NULL); /* xxx */
1419 }
1420
1421 /*
1422 - mccase - add case counterparts of the list of collating elements in a cset
1423 == static void mccase(register struct parse *p, register cset *cs);
1424 *
1425 * This would have to know the set of possibilities. Implementation
1426 * is deferred.
1427 */
1428 static void
1429 mccase(p, cs)
1430 register struct parse *p;
1431 register cset *cs;
1432 {
1433 assert(cs->multis == NULL); /* xxx */
1434 }
1435
1436 /*
1437 - isinsets - is this character in any sets?
1438 == static int isinsets(register struct re_guts *g, int c);
1439 */
1440 static int /* predicate */
1441 isinsets(g, c)
1442 register struct re_guts *g;
1443 int c;
1444 {
1445 register uch *col;
1446 register int i;
1447 register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1448 register unsigned uc = (unsigned char)c;
1449
1450 for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
1451 if (col[uc] != 0)
1452 return(1);
1453 return(0);
1454 }
1455
1456 /*
1457 - samesets - are these two characters in exactly the same sets?
1458 == static int samesets(register struct re_guts *g, int c1, int c2);
1459 */
1460 static int /* predicate */
1461 samesets(g, c1, c2)
1462 register struct re_guts *g;
1463 int c1;
1464 int c2;
1465 {
1466 register uch *col;
1467 register int i;
1468 register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1469 register unsigned uc1 = (unsigned char)c1;
1470 register unsigned uc2 = (unsigned char)c2;
1471
1472 for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
1473 if (col[uc1] != col[uc2])
1474 return(0);
1475 return(1);
1476 }
1477
1478 /*
1479 - categorize - sort out character categories
1480 == static void categorize(struct parse *p, register struct re_guts *g);
1481 */
1482 static void
1483 categorize(p, g)
1484 struct parse *p;
1485 register struct re_guts *g;
1486 {
1487 register cat_t *cats = g->categories;
1488 register int c;
1489 register int c2;
1490 register cat_t cat;
1491
1492 /* avoid making error situations worse */
1493 if (p->error != 0)
1494 return;
1495
1496 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
1497 if (cats[c] == 0 && isinsets(g, c)) {
1498 cat = g->ncategories++;
1499 cats[c] = cat;
1500 for (c2 = c+1; c2 <= CHAR_MAX; c2++)
1501 if (cats[c2] == 0 && samesets(g, c, c2))
1502 cats[c2] = cat;
1503 }
1504 }
1505
1506 /*
1507 - dupl - emit a duplicate of a bunch of sops
1508 == static sopno dupl(register struct parse *p, sopno start, sopno finish);
1509 */
1510 static sopno /* start of duplicate */
1511 dupl(p, start, finish)
1512 register struct parse *p;
1513 sopno start; /* from here */
1514 sopno finish; /* to this less one */
1515 {
1516 register sopno ret = HERE();
1517 register sopno len = finish - start;
1518
1519 assert(finish >= start);
1520 if (len == 0)
1521 return(ret);
1522 enlarge(p, p->ssize + len); /* this many unexpected additions */
1523 assert(p->ssize >= p->slen + len);
1524 (void) memcpy((char *)(p->strip + p->slen),
1525 (char *)(p->strip + start), (size_t)len*sizeof(sop));
1526 p->slen += len;
1527 return(ret);
1528 }
1529
1530 /*
1531 - doemit - emit a strip operator
1532 == static void doemit(register struct parse *p, sop op, size_t opnd);
1533 *
1534 * It might seem better to implement this as a macro with a function as
1535 * hard-case backup, but it's just too big and messy unless there are
1536 * some changes to the data structures. Maybe later.
1537 */
1538 static void
1539 doemit(p, op, opnd)
1540 register struct parse *p;
1541 sop op;
1542 size_t opnd;
1543 {
1544 /* avoid making error situations worse */
1545 if (p->error != 0)
1546 return;
1547
1548 /* deal with oversize operands ("can't happen", more or less) */
1549 assert(opnd < 1<<OPSHIFT);
1550
1551 /* deal with undersized strip */
1552 if (p->slen >= p->ssize)
1553 enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */
1554 assert(p->slen < p->ssize);
1555
1556 /* finally, it's all reduced to the easy case */
1557 p->strip[p->slen++] = SOP(op, opnd);
1558 }
1559
1560 /*
1561 - doinsert - insert a sop into the strip
1562 == static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos);
1563 */
1564 static void
1565 doinsert(p, op, opnd, pos)
1566 register struct parse *p;
1567 sop op;
1568 size_t opnd;
1569 sopno pos;
1570 {
1571 register sopno sn;
1572 register sop s;
1573 register int i;
1574
1575 /* avoid making error situations worse */
1576 if (p->error != 0)
1577 return;
1578
1579 sn = HERE();
1580 EMIT(op, opnd); /* do checks, ensure space */
1581 assert(HERE() == sn+1);
1582 s = p->strip[sn];
1583
1584 /* adjust paren pointers */
1585 assert(pos > 0);
1586 for (i = 1; i < NPAREN; i++) {
1587 if (p->pbegin[i] >= pos) {
1588 p->pbegin[i]++;
1589 }
1590 if (p->pend[i] >= pos) {
1591 p->pend[i]++;
1592 }
1593 }
1594
1595 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1596 (HERE()-pos-1)*sizeof(sop));
1597 p->strip[pos] = s;
1598 }
1599
1600 /*
1601 - dofwd - complete a forward reference
1602 == static void dofwd(register struct parse *p, sopno pos, sop value);
1603 */
1604 static void
1605 dofwd(p, pos, value)
1606 register struct parse *p;
1607 register sopno pos;
1608 sop value;
1609 {
1610 /* avoid making error situations worse */
1611 if (p->error != 0)
1612 return;
1613
1614 assert(value < 1<<OPSHIFT);
1615 p->strip[pos] = OP(p->strip[pos]) | value;
1616 }
1617
1618 /*
1619 - enlarge - enlarge the strip
1620 == static void enlarge(register struct parse *p, sopno size);
1621 */
1622 static void
1623 enlarge(p, size)
1624 register struct parse *p;
1625 register sopno size;
1626 {
1627 register sop *sp;
1628
1629 if (p->ssize >= size)
1630 return;
1631
1632 sp = (sop *)realloc(p->strip, size*sizeof(sop));
1633 if (sp == NULL) {
1634 SETERROR(REG_ESPACE);
1635 return;
1636 }
1637 p->strip = sp;
1638 p->ssize = size;
1639 }
1640
1641 /*
1642 - stripsnug - compact the strip
1643 == static void stripsnug(register struct parse *p, register struct re_guts *g);
1644 */
1645 static void
1646 stripsnug(p, g)
1647 register struct parse *p;
1648 register struct re_guts *g;
1649 {
1650 g->nstates = p->slen;
1651 g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
1652 if (g->strip == NULL) {
1653 SETERROR(REG_ESPACE);
1654 g->strip = p->strip;
1655 }
1656 }
1657
1658 /*
1659 - findmust - fill in must and mlen with longest mandatory literal string
1660 == static void findmust(register struct parse *p, register struct re_guts *g);
1661 *
1662 * This algorithm could do fancy things like analyzing the operands of |
1663 * for common subsequences. Someday. This code is simple and finds most
1664 * of the interesting cases.
1665 *
1666 * Note that must and mlen got initialized during setup.
1667 */
1668 static void
1669 findmust(p, g)
1670 struct parse *p;
1671 register struct re_guts *g;
1672 {
1673 register sop *scan;
1674 sop *start;
1675 register sop *newstart;
1676 register sopno newlen;
1677 register sop s;
1678 register char *cp;
1679 register sopno i;
1680
1681 /* avoid making error situations worse */
1682 if (p->error != 0)
1683 return;
1684
1685 /* find the longest OCHAR sequence in strip */
1686 newlen = 0;
1687 scan = g->strip + 1;
1688 do {
1689 s = *scan++;
1690 switch (OP(s)) {
1691 case OCHAR: /* sequence member */
1692 if (newlen == 0) /* new sequence */
1693 newstart = scan - 1;
1694 newlen++;
1695 break;
1696 case OPLUS_: /* things that don't break one */
1697 case OLPAREN:
1698 case ORPAREN:
1699 break;
1700 case OQUEST_: /* things that must be skipped */
1701 case OCH_:
1702 scan--;
1703 do {
1704 scan += OPND(s);
1705 s = *scan;
1706 /* assert() interferes w debug printouts */
1707 if (OP(s) != O_QUEST && OP(s) != O_CH &&
1708 OP(s) != OOR2) {
1709 g->iflags |= BAD;
1710 return;
1711 }
1712 } while (OP(s) != O_QUEST && OP(s) != O_CH);
1713 /* fallthrough */
1714 default: /* things that break a sequence */
1715 if (newlen > g->mlen) { /* ends one */
1716 start = newstart;
1717 g->mlen = newlen;
1718 }
1719 newlen = 0;
1720 break;
1721 }
1722 } while (OP(s) != OEND);
1723
1724 if (g->mlen == 0) /* there isn't one */
1725 return;
1726
1727 /* turn it into a character string */
1728 g->must = malloc((size_t)g->mlen + 1);
1729 if (g->must == NULL) { /* argh; just forget it */
1730 g->mlen = 0;
1731 return;
1732 }
1733 cp = g->must;
1734 scan = start;
1735 for (i = g->mlen; i > 0; i--) {
1736 while (OP(s = *scan++) != OCHAR)
1737 continue;
1738 assert(cp < g->must + g->mlen);
1739 *cp++ = (char)OPND(s);
1740 }
1741 assert(cp == g->must + g->mlen);
1742 *cp++ = '\0'; /* just on general principles */
1743 }
1744
1745 /*
1746 - pluscount - count + nesting
1747 == static sopno pluscount(register struct parse *p, register struct re_guts *g);
1748 */
1749 static sopno /* nesting depth */
1750 pluscount(p, g)
1751 struct parse *p;
1752 register struct re_guts *g;
1753 {
1754 register sop *scan;
1755 register sop s;
1756 register sopno plusnest = 0;
1757 register sopno maxnest = 0;
1758
1759 if (p->error != 0)
1760 return(0); /* there may not be an OEND */
1761
1762 scan = g->strip + 1;
1763 do {
1764 s = *scan++;
1765 switch (OP(s)) {
1766 case OPLUS_:
1767 plusnest++;
1768 break;
1769 case O_PLUS:
1770 if (plusnest > maxnest)
1771 maxnest = plusnest;
1772 plusnest--;
1773 break;
1774 }
1775 } while (OP(s) != OEND);
1776 if (plusnest != 0)
1777 g->iflags |= BAD;
1778 return(maxnest);
1779 }
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
37 */
38
39 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
41 #endif /* LIBC_SCCS and not lint */
42
43 #include <sys/types.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <ctype.h>
47 #include <limits.h>
48 #include <stdlib.h>
49
50 #include "regex.h"
51 #include "utils.h"
52
53 /* ========= begin header generated by ./mkh ========= */
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /* === regerror.c === */
59 static char *regatoi(const regex_t *preg, char *localbuf);
60
61 #ifdef __cplusplus
62 }
63 #endif
64 /* ========= end header generated by ./mkh ========= */
65 /*
66 = #define REG_NOMATCH 1
67 = #define REG_BADPAT 2
68 = #define REG_ECOLLATE 3
69 = #define REG_ECTYPE 4
70 = #define REG_EESCAPE 5
71 = #define REG_ESUBREG 6
72 = #define REG_EBRACK 7
73 = #define REG_EPAREN 8
74 = #define REG_EBRACE 9
75 = #define REG_BADBR 10
76 = #define REG_ERANGE 11
77 = #define REG_ESPACE 12
78 = #define REG_BADRPT 13
79 = #define REG_EMPTY 14
80 = #define REG_ASSERT 15
81 = #define REG_INVARG 16
82 = #define REG_ATOI 255 // convert name to number (!)
83 = #define REG_ITOA 0400 // convert number to name (!)
84 */
85 static struct rerr {
86 int code;
87 char *name;
88 char *explain;
89 } rerrs[] = {
90 {REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match"},
91 {REG_BADPAT, "REG_BADPAT", "invalid regular expression"},
92 {REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"},
93 {REG_ECTYPE, "REG_ECTYPE", "invalid character class"},
94 {REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)"},
95 {REG_ESUBREG, "REG_ESUBREG", "invalid backreference number"},
96 {REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced"},
97 {REG_EPAREN, "REG_EPAREN", "parentheses not balanced"},
98 {REG_EBRACE, "REG_EBRACE", "braces not balanced"},
99 {REG_BADBR, "REG_BADBR", "invalid repetition count(s)"},
100 {REG_ERANGE, "REG_ERANGE", "invalid character range"},
101 {REG_ESPACE, "REG_ESPACE", "out of memory"},
102 {REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid"},
103 {REG_EMPTY, "REG_EMPTY", "empty (sub)expression"},
104 {REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug"},
105 {REG_INVARG, "REG_INVARG", "invalid argument to regex routine"},
106 {0, "", "*** unknown regexp error code ***"}
107 };
108
109 /*
110 - regerror - the interface to error numbers
111 = extern size_t regerror(int, const regex_t *, char *, size_t);
112 */
113 /* ARGSUSED */
114 size_t
115 regerror(errcode, preg, errbuf, errbuf_size)
116 int errcode;
117 const regex_t *preg;
118 char *errbuf;
119 size_t errbuf_size;
120 {
121 register struct rerr *r;
122 register size_t len;
123 register int target = errcode &~ REG_ITOA;
124 register char *s;
125 char convbuf[50];
126
127 if (errcode == REG_ATOI)
128 s = regatoi(preg, convbuf);
129 else {
130 for (r = rerrs; r->code != 0; r++)
131 if (r->code == target)
132 break;
133
134 if (errcode&REG_ITOA) {
135 if (r->code != 0)
136 (void) strcpy(convbuf, r->name);
137 else
138 sprintf(convbuf, "REG_0x%x", target);
139 assert(strlen(convbuf) < sizeof(convbuf));
140 s = convbuf;
141 } else
142 s = r->explain;
143 }
144
145 len = strlen(s) + 1;
146 if (errbuf_size > 0) {
147 if (errbuf_size > len)
148 (void) strcpy(errbuf, s);
149 else {
150 (void) strncpy(errbuf, s, errbuf_size-1);
151 errbuf[errbuf_size-1] = '\0';
152 }
153 }
154
155 return(len);
156 }
157
158 /*
159 - regatoi - internal routine to implement REG_ATOI
160 == static char *regatoi(const regex_t *preg, char *localbuf);
161 */
162 static char *
163 regatoi(preg, localbuf)
164 const regex_t *preg;
165 char *localbuf;
166 {
167 register struct rerr *r;
168
169 for (r = rerrs; r->code != 0; r++)
170 if (strcmp(r->name, preg->re_endp) == 0)
171 break;
172 if (r->code == 0)
173 return("0");
174
175 sprintf(localbuf, "%d", r->code);
176 return(localbuf);
177 }
0 .\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
1 .\" Copyright (c) 1992, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Henry Spencer.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\" @(#)regex.3 8.4 (Berkeley) 3/20/94
36 .\"
37 .TH REGEX 3 "March 20, 1994"
38 .de ZR
39 .\" one other place knows this name: the SEE ALSO section
40 .IR re_format (7) \\$1
41 ..
42 .SH NAME
43 regcomp, regexec, regerror, regfree \- regular-expression library
44 .SH SYNOPSIS
45 .ft B
46 .\".na
47 #include <sys/types.h>
48 .br
49 #include <regex.h>
50 .HP 10
51 int regcomp(regex_t\ *preg, const\ char\ *pattern, int\ cflags);
52 .HP
53 int\ regexec(const\ regex_t\ *preg, const\ char\ *string,
54 size_t\ nmatch, regmatch_t\ pmatch[], int\ eflags);
55 .HP
56 size_t\ regerror(int\ errcode, const\ regex_t\ *preg,
57 char\ *errbuf, size_t\ errbuf_size);
58 .HP
59 void\ regfree(regex_t\ *preg);
60 .\".ad
61 .ft
62 .SH DESCRIPTION
63 These routines implement POSIX 1003.2 regular expressions (``RE''s);
64 see
65 .ZR .
66 .I Regcomp
67 compiles an RE written as a string into an internal form,
68 .I regexec
69 matches that internal form against a string and reports results,
70 .I regerror
71 transforms error codes from either into human-readable messages,
72 and
73 .I regfree
74 frees any dynamically-allocated storage used by the internal form
75 of an RE.
76 .PP
77 The header
78 .I <regex.h>
79 declares two structure types,
80 .I regex_t
81 and
82 .IR regmatch_t ,
83 the former for compiled internal forms and the latter for match reporting.
84 It also declares the four functions,
85 a type
86 .IR regoff_t ,
87 and a number of constants with names starting with ``REG_''.
88 .PP
89 .I Regcomp
90 compiles the regular expression contained in the
91 .I pattern
92 string,
93 subject to the flags in
94 .IR cflags ,
95 and places the results in the
96 .I regex_t
97 structure pointed to by
98 .IR preg .
99 .I Cflags
100 is the bitwise OR of zero or more of the following flags:
101 .IP REG_EXTENDED \w'REG_EXTENDED'u+2n
102 Compile modern (``extended'') REs,
103 rather than the obsolete (``basic'') REs that
104 are the default.
105 .IP REG_BASIC
106 This is a synonym for 0,
107 provided as a counterpart to REG_EXTENDED to improve readability.
108 .IP REG_NOSPEC
109 Compile with recognition of all special characters turned off.
110 All characters are thus considered ordinary,
111 so the ``RE'' is a literal string.
112 This is an extension,
113 compatible with but not specified by POSIX 1003.2,
114 and should be used with
115 caution in software intended to be portable to other systems.
116 REG_EXTENDED and REG_NOSPEC may not be used
117 in the same call to
118 .IR regcomp .
119 .IP REG_ICASE
120 Compile for matching that ignores upper/lower case distinctions.
121 See
122 .ZR .
123 .IP REG_NOSUB
124 Compile for matching that need only report success or failure,
125 not what was matched.
126 .IP REG_NEWLINE
127 Compile for newline-sensitive matching.
128 By default, newline is a completely ordinary character with no special
129 meaning in either REs or strings.
130 With this flag,
131 `[^' bracket expressions and `.' never match newline,
132 a `^' anchor matches the null string after any newline in the string
133 in addition to its normal function,
134 and the `$' anchor matches the null string before any newline in the
135 string in addition to its normal function.
136 .IP REG_PEND
137 The regular expression ends,
138 not at the first NUL,
139 but just before the character pointed to by the
140 .I re_endp
141 member of the structure pointed to by
142 .IR preg .
143 The
144 .I re_endp
145 member is of type
146 .IR const\ char\ * .
147 This flag permits inclusion of NULs in the RE;
148 they are considered ordinary characters.
149 This is an extension,
150 compatible with but not specified by POSIX 1003.2,
151 and should be used with
152 caution in software intended to be portable to other systems.
153 .PP
154 When successful,
155 .I regcomp
156 returns 0 and fills in the structure pointed to by
157 .IR preg .
158 One member of that structure
159 (other than
160 .IR re_endp )
161 is publicized:
162 .IR re_nsub ,
163 of type
164 .IR size_t ,
165 contains the number of parenthesized subexpressions within the RE
166 (except that the value of this member is undefined if the
167 REG_NOSUB flag was used).
168 If
169 .I regcomp
170 fails, it returns a non-zero error code;
171 see DIAGNOSTICS.
172 .PP
173 .I Regexec
174 matches the compiled RE pointed to by
175 .I preg
176 against the
177 .IR string ,
178 subject to the flags in
179 .IR eflags ,
180 and reports results using
181 .IR nmatch ,
182 .IR pmatch ,
183 and the returned value.
184 The RE must have been compiled by a previous invocation of
185 .IR regcomp .
186 The compiled form is not altered during execution of
187 .IR regexec ,
188 so a single compiled RE can be used simultaneously by multiple threads.
189 .PP
190 By default,
191 the NUL-terminated string pointed to by
192 .I string
193 is considered to be the text of an entire line, minus any terminating
194 newline.
195 The
196 .I eflags
197 argument is the bitwise OR of zero or more of the following flags:
198 .IP REG_NOTBOL \w'REG_STARTEND'u+2n
199 The first character of
200 the string
201 is not the beginning of a line, so the `^' anchor should not match before it.
202 This does not affect the behavior of newlines under REG_NEWLINE.
203 .IP REG_NOTEOL
204 The NUL terminating
205 the string
206 does not end a line, so the `$' anchor should not match before it.
207 This does not affect the behavior of newlines under REG_NEWLINE.
208 .IP REG_STARTEND
209 The string is considered to start at
210 \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_so\fR
211 and to have a terminating NUL located at
212 \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_eo\fR
213 (there need not actually be a NUL at that location),
214 regardless of the value of
215 .IR nmatch .
216 See below for the definition of
217 .IR pmatch
218 and
219 .IR nmatch .
220 This is an extension,
221 compatible with but not specified by POSIX 1003.2,
222 and should be used with
223 caution in software intended to be portable to other systems.
224 Note that a non-zero \fIrm_so\fR does not imply REG_NOTBOL;
225 REG_STARTEND affects only the location of the string,
226 not how it is matched.
227 .PP
228 See
229 .ZR
230 for a discussion of what is matched in situations where an RE or a
231 portion thereof could match any of several substrings of
232 .IR string .
233 .PP
234 Normally,
235 .I regexec
236 returns 0 for success and the non-zero code REG_NOMATCH for failure.
237 Other non-zero error codes may be returned in exceptional situations;
238 see DIAGNOSTICS.
239 .PP
240 If REG_NOSUB was specified in the compilation of the RE,
241 or if
242 .I nmatch
243 is 0,
244 .I regexec
245 ignores the
246 .I pmatch
247 argument (but see below for the case where REG_STARTEND is specified).
248 Otherwise,
249 .I pmatch
250 points to an array of
251 .I nmatch
252 structures of type
253 .IR regmatch_t .
254 Such a structure has at least the members
255 .I rm_so
256 and
257 .IR rm_eo ,
258 both of type
259 .I regoff_t
260 (a signed arithmetic type at least as large as an
261 .I off_t
262 and a
263 .IR ssize_t ),
264 containing respectively the offset of the first character of a substring
265 and the offset of the first character after the end of the substring.
266 Offsets are measured from the beginning of the
267 .I string
268 argument given to
269 .IR regexec .
270 An empty substring is denoted by equal offsets,
271 both indicating the character following the empty substring.
272 .PP
273 The 0th member of the
274 .I pmatch
275 array is filled in to indicate what substring of
276 .I string
277 was matched by the entire RE.
278 Remaining members report what substring was matched by parenthesized
279 subexpressions within the RE;
280 member
281 .I i
282 reports subexpression
283 .IR i ,
284 with subexpressions counted (starting at 1) by the order of their opening
285 parentheses in the RE, left to right.
286 Unused entries in the array\(emcorresponding either to subexpressions that
287 did not participate in the match at all, or to subexpressions that do not
288 exist in the RE (that is, \fIi\fR\ > \fIpreg\fR\->\fIre_nsub\fR)\(emhave both
289 .I rm_so
290 and
291 .I rm_eo
292 set to \-1.
293 If a subexpression participated in the match several times,
294 the reported substring is the last one it matched.
295 (Note, as an example in particular, that when the RE `(b*)+' matches `bbb',
296 the parenthesized subexpression matches each of the three `b's and then
297 an infinite number of empty strings following the last `b',
298 so the reported substring is one of the empties.)
299 .PP
300 If REG_STARTEND is specified,
301 .I pmatch
302 must point to at least one
303 .I regmatch_t
304 (even if
305 .I nmatch
306 is 0 or REG_NOSUB was specified),
307 to hold the input offsets for REG_STARTEND.
308 Use for output is still entirely controlled by
309 .IR nmatch ;
310 if
311 .I nmatch
312 is 0 or REG_NOSUB was specified,
313 the value of
314 .IR pmatch [0]
315 will not be changed by a successful
316 .IR regexec .
317 .PP
318 .I Regerror
319 maps a non-zero
320 .I errcode
321 from either
322 .I regcomp
323 or
324 .I regexec
325 to a human-readable, printable message.
326 If
327 .I preg
328 is non-NULL,
329 the error code should have arisen from use of
330 the
331 .I regex_t
332 pointed to by
333 .IR preg ,
334 and if the error code came from
335 .IR regcomp ,
336 it should have been the result from the most recent
337 .I regcomp
338 using that
339 .IR regex_t .
340 .RI ( Regerror
341 may be able to supply a more detailed message using information
342 from the
343 .IR regex_t .)
344 .I Regerror
345 places the NUL-terminated message into the buffer pointed to by
346 .IR errbuf ,
347 limiting the length (including the NUL) to at most
348 .I errbuf_size
349 bytes.
350 If the whole message won't fit,
351 as much of it as will fit before the terminating NUL is supplied.
352 In any case,
353 the returned value is the size of buffer needed to hold the whole
354 message (including terminating NUL).
355 If
356 .I errbuf_size
357 is 0,
358 .I errbuf
359 is ignored but the return value is still correct.
360 .PP
361 If the
362 .I errcode
363 given to
364 .I regerror
365 is first ORed with REG_ITOA,
366 the ``message'' that results is the printable name of the error code,
367 e.g. ``REG_NOMATCH'',
368 rather than an explanation thereof.
369 If
370 .I errcode
371 is REG_ATOI,
372 then
373 .I preg
374 shall be non-NULL and the
375 .I re_endp
376 member of the structure it points to
377 must point to the printable name of an error code;
378 in this case, the result in
379 .I errbuf
380 is the decimal digits of
381 the numeric value of the error code
382 (0 if the name is not recognized).
383 REG_ITOA and REG_ATOI are intended primarily as debugging facilities;
384 they are extensions,
385 compatible with but not specified by POSIX 1003.2,
386 and should be used with
387 caution in software intended to be portable to other systems.
388 Be warned also that they are considered experimental and changes are possible.
389 .PP
390 .I Regfree
391 frees any dynamically-allocated storage associated with the compiled RE
392 pointed to by
393 .IR preg .
394 The remaining
395 .I regex_t
396 is no longer a valid compiled RE
397 and the effect of supplying it to
398 .I regexec
399 or
400 .I regerror
401 is undefined.
402 .PP
403 None of these functions references global variables except for tables
404 of constants;
405 all are safe for use from multiple threads if the arguments are safe.
406 .SH IMPLEMENTATION CHOICES
407 There are a number of decisions that 1003.2 leaves up to the implementor,
408 either by explicitly saying ``undefined'' or by virtue of them being
409 forbidden by the RE grammar.
410 This implementation treats them as follows.
411 .PP
412 See
413 .ZR
414 for a discussion of the definition of case-independent matching.
415 .PP
416 There is no particular limit on the length of REs,
417 except insofar as memory is limited.
418 Memory usage is approximately linear in RE size, and largely insensitive
419 to RE complexity, except for bounded repetitions.
420 See BUGS for one short RE using them
421 that will run almost any system out of memory.
422 .PP
423 A backslashed character other than one specifically given a magic meaning
424 by 1003.2 (such magic meanings occur only in obsolete [``basic''] REs)
425 is taken as an ordinary character.
426 .PP
427 Any unmatched [ is a REG_EBRACK error.
428 .PP
429 Equivalence classes cannot begin or end bracket-expression ranges.
430 The endpoint of one range cannot begin another.
431 .PP
432 RE_DUP_MAX, the limit on repetition counts in bounded repetitions, is 255.
433 .PP
434 A repetition operator (?, *, +, or bounds) cannot follow another
435 repetition operator.
436 A repetition operator cannot begin an expression or subexpression
437 or follow `^' or `|'.
438 .PP
439 `|' cannot appear first or last in a (sub)expression or after another `|',
440 i.e. an operand of `|' cannot be an empty subexpression.
441 An empty parenthesized subexpression, `()', is legal and matches an
442 empty (sub)string.
443 An empty string is not a legal RE.
444 .PP
445 A `{' followed by a digit is considered the beginning of bounds for a
446 bounded repetition, which must then follow the syntax for bounds.
447 A `{' \fInot\fR followed by a digit is considered an ordinary character.
448 .PP
449 `^' and `$' beginning and ending subexpressions in obsolete (``basic'')
450 REs are anchors, not ordinary characters.
451 .SH SEE ALSO
452 grep(1), re_format(7)
453 .PP
454 POSIX 1003.2, sections 2.8 (Regular Expression Notation)
455 and
456 B.5 (C Binding for Regular Expression Matching).
457 .SH DIAGNOSTICS
458 Non-zero error codes from
459 .I regcomp
460 and
461 .I regexec
462 include the following:
463 .PP
464 .nf
465 .ta \w'REG_ECOLLATE'u+3n
466 REG_NOMATCH regexec() failed to match
467 REG_BADPAT invalid regular expression
468 REG_ECOLLATE invalid collating element
469 REG_ECTYPE invalid character class
470 REG_EESCAPE \e applied to unescapable character
471 REG_ESUBREG invalid backreference number
472 REG_EBRACK brackets [ ] not balanced
473 REG_EPAREN parentheses ( ) not balanced
474 REG_EBRACE braces { } not balanced
475 REG_BADBR invalid repetition count(s) in { }
476 REG_ERANGE invalid character range in [ ]
477 REG_ESPACE ran out of memory
478 REG_BADRPT ?, *, or + operand invalid
479 REG_EMPTY empty (sub)expression
480 REG_ASSERT ``can't happen''\(emyou found a bug
481 REG_INVARG invalid argument, e.g. negative-length string
482 .fi
483 .SH HISTORY
484 Originally written by Henry Spencer.
485 Altered for inclusion in the
486 .Bx 4.4
487 distribution.
488 .SH BUGS
489 This is an alpha release with known defects.
490 Please report problems.
491 .PP
492 There is one known functionality bug.
493 The implementation of internationalization is incomplete:
494 the locale is always assumed to be the default one of 1003.2,
495 and only the collating elements etc. of that locale are available.
496 .PP
497 The back-reference code is subtle and doubts linger about its correctness
498 in complex cases.
499 .PP
500 .I Regexec
501 performance is poor.
502 This will improve with later releases.
503 .I Nmatch
504 exceeding 0 is expensive;
505 .I nmatch
506 exceeding 1 is worse.
507 .I Regexec
508 is largely insensitive to RE complexity \fIexcept\fR that back
509 references are massively expensive.
510 RE length does matter; in particular, there is a strong speed bonus
511 for keeping RE length under about 30 characters,
512 with most special characters counting roughly double.
513 .PP
514 .I Regcomp
515 implements bounded repetitions by macro expansion,
516 which is costly in time and space if counts are large
517 or bounded repetitions are nested.
518 An RE like, say,
519 `((((a{1,100}){1,100}){1,100}){1,100}){1,100}'
520 will (eventually) run almost any existing machine out of swap space.
521 .PP
522 There are suspected problems with response to obscure error conditions.
523 Notably,
524 certain kinds of internal overflow,
525 produced only by truly enormous REs or by multiply nested bounded repetitions,
526 are probably not handled well.
527 .PP
528 Due to a mistake in 1003.2, things like `a)b' are legal REs because `)' is
529 a special character only in the presence of a previous unmatched `('.
530 This can't be fixed until the spec is fixed.
531 .PP
532 The standard's definition of back references is vague.
533 For example, does
534 `a\e(\e(b\e)*\e2\e)*d' match `abbbd'?
535 Until the standard is clarified,
536 behavior in such cases should not be relied on.
537 .PP
538 The implementation of word-boundary matching is a bit of a kludge,
539 and bugs may lurk in combinations of word-boundary matching and anchoring.
0 /*-
1 * Copyright (c) 1992 Henry Spencer.
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer of the University of Toronto.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regex.h 8.2 (Berkeley) 1/3/94
37 */
38
39 #ifndef _REGEX_H_
40 #define _REGEX_H_
41
42 #include "compat.h"
43
44 /* types */
45 typedef off_t regoff_t;
46
47 typedef struct {
48 int re_magic;
49 size_t re_nsub; /* number of parenthesized subexpressions */
50 const char *re_endp; /* end pointer for REG_PEND */
51 struct re_guts *re_g; /* none of your business :-) */
52 } regex_t;
53
54 typedef struct {
55 regoff_t rm_so; /* start of match */
56 regoff_t rm_eo; /* end of match */
57 } regmatch_t;
58
59 /* regcomp() flags */
60 #define REG_BASIC 0000
61 #define REG_EXTENDED 0001
62 #define REG_ICASE 0002
63 #define REG_NOSUB 0004
64 #define REG_NEWLINE 0010
65 #define REG_NOSPEC 0020
66 #define REG_PEND 0040
67 #define REG_DUMP 0200
68
69 /* regerror() flags */
70 #define REG_NOMATCH 1
71 #define REG_BADPAT 2
72 #define REG_ECOLLATE 3
73 #define REG_ECTYPE 4
74 #define REG_EESCAPE 5
75 #define REG_ESUBREG 6
76 #define REG_EBRACK 7
77 #define REG_EPAREN 8
78 #define REG_EBRACE 9
79 #define REG_BADBR 10
80 #define REG_ERANGE 11
81 #define REG_ESPACE 12
82 #define REG_BADRPT 13
83 #define REG_EMPTY 14
84 #define REG_ASSERT 15
85 #define REG_INVARG 16
86 #define REG_ATOI 255 /* convert name to number (!) */
87 #define REG_ITOA 0400 /* convert number to name (!) */
88
89 /* regexec() flags */
90 #define REG_NOTBOL 00001
91 #define REG_NOTEOL 00002
92 #define REG_STARTEND 00004
93 #define REG_TRACE 00400 /* tracing of execution */
94 #define REG_LARGE 01000 /* force large representation */
95 #define REG_BACKR 02000 /* force use of backref code */
96
97 int regcomp(regex_t *, const char *, int);
98 size_t regerror(int, const regex_t *, char *, size_t);
99 int regexec(const regex_t *, const char *, size_t, regmatch_t [], int);
100 void regfree(regex_t *);
101
102 #endif /* !_REGEX_H_ */
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regex2.h 8.4 (Berkeley) 3/20/94
37 */
38
39 /*
40 * First, the stuff that ends up in the outside-world include file
41 = typedef off_t regoff_t;
42 = typedef struct {
43 = int re_magic;
44 = size_t re_nsub; // number of parenthesized subexpressions
45 = const char *re_endp; // end pointer for REG_PEND
46 = struct re_guts *re_g; // none of your business :-)
47 = } regex_t;
48 = typedef struct {
49 = regoff_t rm_so; // start of match
50 = regoff_t rm_eo; // end of match
51 = } regmatch_t;
52 */
53 /*
54 * internals of regex_t
55 */
56 #define MAGIC1 ((('r'^0200)<<8) | 'e')
57
58 /*
59 * The internal representation is a *strip*, a sequence of
60 * operators ending with an endmarker. (Some terminology etc. is a
61 * historical relic of earlier versions which used multiple strips.)
62 * Certain oddities in the representation are there to permit running
63 * the machinery backwards; in particular, any deviation from sequential
64 * flow must be marked at both its source and its destination. Some
65 * fine points:
66 *
67 * - OPLUS_ and O_PLUS are *inside* the loop they create.
68 * - OQUEST_ and O_QUEST are *outside* the bypass they create.
69 * - OCH_ and O_CH are *outside* the multi-way branch they create, while
70 * OOR1 and OOR2 are respectively the end and the beginning of one of
71 * the branches. Note that there is an implicit OOR2 following OCH_
72 * and an implicit OOR1 preceding O_CH.
73 *
74 * In state representations, an operator's bit is on to signify a state
75 * immediately *preceding* "execution" of that operator.
76 */
77 typedef unsigned long sop; /* strip operator */
78 typedef long sopno;
79 #define OPRMASK 0xf8000000
80 #define OPDMASK 0x07ffffff
81 #define OPSHIFT ((unsigned)27)
82 #define OP(n) ((n)&OPRMASK)
83 #define OPND(n) ((n)&OPDMASK)
84 #define SOP(op, opnd) ((op)|(opnd))
85 /* operators meaning operand */
86 /* (back, fwd are offsets) */
87 #define OEND (1<<OPSHIFT) /* endmarker - */
88 #define OCHAR (2<<OPSHIFT) /* character unsigned char */
89 #define OBOL (3<<OPSHIFT) /* left anchor - */
90 #define OEOL (4<<OPSHIFT) /* right anchor - */
91 #define OANY (5<<OPSHIFT) /* . - */
92 #define OANYOF (6<<OPSHIFT) /* [...] set number */
93 #define OBACK_ (7<<OPSHIFT) /* begin \d paren number */
94 #define O_BACK (8<<OPSHIFT) /* end \d paren number */
95 #define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */
96 #define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */
97 #define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */
98 #define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */
99 #define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */
100 #define ORPAREN (14<<OPSHIFT) /* ) back to ( */
101 #define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */
102 #define OOR1 (16<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
103 #define OOR2 (17<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
104 #define O_CH (18<<OPSHIFT) /* end choice back to OOR1 */
105 #define OBOW (19<<OPSHIFT) /* begin word - */
106 #define OEOW (20<<OPSHIFT) /* end word - */
107
108 /*
109 * Structure for [] character-set representation. Character sets are
110 * done as bit vectors, grouped 8 to a byte vector for compactness.
111 * The individual set therefore has both a pointer to the byte vector
112 * and a mask to pick out the relevant bit of each byte. A hash code
113 * simplifies testing whether two sets could be identical.
114 *
115 * This will get trickier for multicharacter collating elements. As
116 * preliminary hooks for dealing with such things, we also carry along
117 * a string of multi-character elements, and decide the size of the
118 * vectors at run time.
119 */
120 typedef struct {
121 uch *ptr; /* -> uch [csetsize] */
122 uch mask; /* bit within array */
123 short hash; /* hash code */
124 size_t smultis;
125 char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
126 } cset;
127 /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
128 #define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c))
129 #define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c))
130 #define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
131 #define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
132 #define MCsub(p, cs, cp) mcsub(p, cs, cp)
133 #define MCin(p, cs, cp) mcin(p, cs, cp)
134
135 /* stuff for character categories */
136 typedef unsigned char cat_t;
137
138 /*
139 * main compiled-expression structure
140 */
141 struct re_guts {
142 int magic;
143 # define MAGIC2 ((('R'^0200)<<8)|'E')
144 sop *strip; /* malloced area for strip */
145 int csetsize; /* number of bits in a cset vector */
146 int ncsets; /* number of csets in use */
147 cset *sets; /* -> cset [ncsets] */
148 uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
149 int cflags; /* copy of regcomp() cflags argument */
150 sopno nstates; /* = number of sops */
151 sopno firststate; /* the initial OEND (normally 0) */
152 sopno laststate; /* the final OEND */
153 int iflags; /* internal flags */
154 # define USEBOL 01 /* used ^ */
155 # define USEEOL 02 /* used $ */
156 # define BAD 04 /* something wrong */
157 int nbol; /* number of ^ used */
158 int neol; /* number of $ used */
159 int ncategories; /* how many character categories */
160 cat_t *categories; /* ->catspace[-CHAR_MIN] */
161 char *must; /* match must contain this string */
162 int mlen; /* length of must */
163 size_t nsub; /* copy of re_nsub */
164 int backrefs; /* does it use back references? */
165 sopno nplus; /* how deep does it nest +s? */
166 /* catspace must be last */
167 cat_t catspace[1]; /* actually [NC] */
168 };
169
170 /* misc utilities */
171 #define OUT (CHAR_MAX+1) /* a non-character value */
172 #define ISWORD(c) (isalnum((uch)(c)) || (c) == '_')
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
37 */
38
39 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
41 #endif /* LIBC_SCCS and not lint */
42
43 /*
44 * the outer shell of regexec()
45 *
46 * This file includes engine.c *twice*, after muchos fiddling with the
47 * macros that code uses. This lets the same code operate on two different
48 * representations for state sets.
49 */
50 #include <sys/types.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <limits.h>
55 #include <ctype.h>
56
57 #include "regex.h"
58 #include "utils.h"
59 #include "regex2.h"
60
61 static int nope = 0; /* for use in asserts; shuts lint up */
62
63 /* macros for manipulating states, small version */
64 #define states long
65 #define states1 states /* for later use in regexec() decision */
66 #define CLEAR(v) ((v) = 0)
67 #define SET0(v, n) ((v) &= ~(1 << (n)))
68 #define SET1(v, n) ((v) |= 1 << (n))
69 #define ISSET(v, n) ((v) & (1 << (n)))
70 #define ASSIGN(d, s) ((d) = (s))
71 #define EQ(a, b) ((a) == (b))
72 #define STATEVARS int dummy /* dummy version */
73 #define STATESETUP(m, n) /* nothing */
74 #define STATETEARDOWN(m) /* nothing */
75 #define SETUP(v) ((v) = 0)
76 #define onestate int
77 #define INIT(o, n) ((o) = (unsigned)1 << (n))
78 #define INC(o) ((o) <<= 1)
79 #define ISSTATEIN(v, o) ((v) & (o))
80 /* some abbreviations; note that some of these know variable names! */
81 /* do "if I'm here, I can also be there" etc without branches */
82 #define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n))
83 #define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
84 #define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
85 /* function names */
86 #define SNAMES /* engine.c looks after details */
87
88 #include "engine.c"
89
90 /* now undo things */
91 #undef states
92 #undef CLEAR
93 #undef SET0
94 #undef SET1
95 #undef ISSET
96 #undef ASSIGN
97 #undef EQ
98 #undef STATEVARS
99 #undef STATESETUP
100 #undef STATETEARDOWN
101 #undef SETUP
102 #undef onestate
103 #undef INIT
104 #undef INC
105 #undef ISSTATEIN
106 #undef FWD
107 #undef BACK
108 #undef ISSETBACK
109 #undef SNAMES
110
111 /* macros for manipulating states, large version */
112 #define states char *
113 #define CLEAR(v) memset(v, 0, m->g->nstates)
114 #define SET0(v, n) ((v)[n] = 0)
115 #define SET1(v, n) ((v)[n] = 1)
116 #define ISSET(v, n) ((v)[n])
117 #define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
118 #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
119 #define STATEVARS int vn; char *space
120 #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
121 if ((m)->space == NULL) return(REG_ESPACE); \
122 (m)->vn = 0; }
123 #define STATETEARDOWN(m) { free((m)->space); }
124 #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
125 #define onestate int
126 #define INIT(o, n) ((o) = (n))
127 #define INC(o) ((o)++)
128 #define ISSTATEIN(v, o) ((v)[o])
129 /* some abbreviations; note that some of these know variable names! */
130 /* do "if I'm here, I can also be there" etc without branches */
131 #define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
132 #define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
133 #define ISSETBACK(v, n) ((v)[here - (n)])
134 /* function names */
135 #define LNAMES /* flag */
136
137 #include "engine.c"
138
139 /*
140 - regexec - interface for matching
141 = extern int regexec(const regex_t *, const char *, size_t, \
142 = regmatch_t [], int);
143 = #define REG_NOTBOL 00001
144 = #define REG_NOTEOL 00002
145 = #define REG_STARTEND 00004
146 = #define REG_TRACE 00400 // tracing of execution
147 = #define REG_LARGE 01000 // force large representation
148 = #define REG_BACKR 02000 // force use of backref code
149 *
150 * We put this here so we can exploit knowledge of the state representation
151 * when choosing which matcher to call. Also, by this point the matchers
152 * have been prototyped.
153 */
154 int /* 0 success, REG_NOMATCH failure */
155 regexec(preg, string, nmatch, pmatch, eflags)
156 const regex_t *preg;
157 const char *string;
158 size_t nmatch;
159 regmatch_t pmatch[];
160 int eflags;
161 {
162 register struct re_guts *g = preg->re_g;
163 #ifdef REDEBUG
164 # define GOODFLAGS(f) (f)
165 #else
166 # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
167 #endif
168
169 if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
170 return(REG_BADPAT);
171 assert(!(g->iflags&BAD));
172 if (g->iflags&BAD) /* backstop for no-debug case */
173 return(REG_BADPAT);
174 eflags = GOODFLAGS(eflags);
175
176 if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
177 return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
178 else
179 return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
180 }
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
37 */
38
39 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
41 #endif /* LIBC_SCCS and not lint */
42
43 #include <sys/types.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46
47 #include "regex.h"
48 #include "utils.h"
49 #include "regex2.h"
50
51 /*
52 - regfree - free everything
53 = extern void regfree(regex_t *);
54 */
55 void
56 regfree(preg)
57 regex_t *preg;
58 {
59 register struct re_guts *g;
60
61 if (preg->re_magic != MAGIC1) /* oops */
62 return; /* nice to complain, but hard */
63
64 g = preg->re_g;
65 if (g == NULL || g->magic != MAGIC2) /* oops again */
66 return;
67 preg->re_magic = 0; /* mark it invalid */
68 g->magic = 0; /* mark it invalid */
69
70 if (g->strip != NULL)
71 free((char *)g->strip);
72 if (g->sets != NULL)
73 free((char *)g->sets);
74 if (g->setbits != NULL)
75 free((char *)g->setbits);
76 if (g->must != NULL)
77 free(g->must);
78 free((char *)g);
79 }
0 /*-
1 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Henry Spencer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)utils.h 8.3 (Berkeley) 3/20/94
37 */
38
39 /* utility definitions */
40 #define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */
41 #define INFINITY (DUPMAX + 1)
42 #define NC (CHAR_MAX - CHAR_MIN + 1)
43 typedef unsigned char uch;
44
45 /* switch off assertions (if not already off) if no REDEBUG */
46 #ifndef REDEBUG
47 #ifndef NDEBUG
48 #define NDEBUG /* no assertions please */
49 #endif
50 #endif
51 #include <assert.h>
52
53 /* for old systems with bcopy() but no memmove() */
54 #ifdef USEBCOPY
55 #define memmove(d, s, c) bcopy(s, d, c)
56 #endif
00 LIB= gloutil
11 SRCS= gtagsop.c tab.c strbuf.c mgets.c defined.c getdbpath.c \
22 find.c dbop.c test.c makepath.c locatestring.c pathop.c \
3 conf.c strmake.c usable.c token.c
3 conf.c strmake.c usable.c token.c path.c
44 NOPROFILE= noprofile
55 INTERNALLIB= true
66 INTERNALSTATICLIB= true
0 LIB= gloutil
1 SRCS= gtagsop.c tab.c strbuf.c mgets.c defined.c getdbpath.c \
2 find.c dbop.c test.c makepath.c locatestring.c pathop.c \
3 conf.c strmake.c usable.c token.c path.c
4 NOPROFILE= noprofile
5 INTERNALLIB= true
6 INTERNALSTATICLIB= true
7
8 .include <bsd.lib.mk>
00 LIB = libgloutil.a
11 CC = gcc
22 AR = ar
3 CFLAGS = -O -I../libdb
4 OBJS = usable.o gtagsop.o getdbpath.o find.o defined.o conf.o tab.o strmake.o \
5 pathop.o mgets.o makepath.o locatestring.o dbop.o test.o token.o strbuf.o
3 CFLAGS = -O -I../libdb -I../libregex -I../machine
4 OBJS = usable.o gtagsop.o getdbpath.o find.o defined.o conf.o tab.o \
5 strmake.o pathop.o mgets.o makepath.o locatestring.o dbop.o \
6 test.o token.o strbuf.o path.o
67
78 all: $(LIB)
89
910 $(LIB): $(OBJS)
10 $(AR) cq $(LIB) $(OBJS)
11 $(AR) cr $(LIB) $(OBJS)
1112 install:
13 @echo -n
14 cygwin_install:
1215 @echo -n
1316 clean:
1417 rm -f $(LIB) $(OBJS)
0 LIB = libgloutil.lib
1 CC = bcc32
2 AR = tlib
3 CFLAGS = -I../libutil -I../libdb -I../libregex -I../machine -I../win32
4 OBJS = usable.obj gtagsop.obj getdbpath.obj find.obj defined.obj \
5 conf.obj tab.obj strmake.obj pathop.obj mgets.obj makepath.obj \
6 locatestring.obj dbop.obj test.obj token.obj strbuf.obj path.obj
7
8 all: $(LIB)
9
10 $(LIB): $(OBJS)
11 $(AR) $(LIB) @..\win32\utilobjs
12 install:
13 @echo -n
14 clean:
15 del *.lib
16 del *.obj
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * conf.c 23-Mar-99
31 *
32 */
33 #include <sys/param.h>
34 * conf.c 25-Aug-99
35 *
36 */
3437 #include <assert.h>
3538 #include <ctype.h>
3639 #include <stdlib.h>
3740 #include <string.h>
3841
42 #include "gparam.h"
3943 #include "conf.h"
4044 #include "die.h"
41 #include "gparam.h"
4245 #include "locatestring.h"
4346 #include "makepath.h"
4447 #include "mgets.h"
4548 #include "strbuf.h"
4649 #include "strmake.h"
4750 #include "test.h"
48 /*
49 * Access library for global.conf (.globalrc).
50 * File format is a subset of XXXcap (termcap, printcap) file.
51 */
52 #define GTAGSCONF "/etc/global.conf"
53 #define DEBIANCONF "/etc/gtags/global.conf"
54 #define GTAGSRC ".globalrc"
55 #define DEFAULTLABEL "default"
56 #ifdef GTAGSCPP
57 #define DEFAULTSUFFIXES "c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java"
58 #else
59 #define DEFAULTSUFFIXES "c,h,y,s,S,java"
60 #endif
61 #define DEFAULTSKIP "y.tab.c,y.tab.h,SCCS/,RCS/,CVS/"
6251
6352 static FILE *fp;
6453 static char *line;
6554 static int allowed_nest_level = 8;
6655 static int opened;
6756
68 static void trim __P((char *));
69 static char *readrecord __P((const char *));
70 static void includelabel __P((STRBUF *, const char *, int));
57 static void trim(char *);
58 static char *readrecord(const char *);
59 static void includelabel(STRBUF *, const char *, int);
7160
7261 static void
7362 trim(l)
155144 config[0] = 0;
156145 else
157146 strcpy(config, p);
158 } else if ((p = getenv("HOME")) && test("r", makepath(p, GTAGSRC)))
159 strcpy(config, makepath(p, GTAGSRC));
147 } else if ((p = getenv("HOME")) && test("r", makepath(p, GTAGSRC, NULL)))
148 strcpy(config, makepath(p, GTAGSRC, NULL));
160149 else if (test("r", GTAGSCONF))
161150 strcpy(config, GTAGSCONF);
162151 else if (test("r", DEBIANCONF))
194183 strputc(sb, ':');
195184 strputs(sb, "format=standard:");
196185 strputs(sb, "extractmethod:");
186 #ifdef _WIN32
187 strputs(sb, "GTAGS=gctags.exe %s:");
188 strputs(sb, "GRTAGS=gctags.exe -r %s:");
189 strputs(sb, "GSYMS=gctags.exe -s %s:");
190 strputs(sb, "sort_command=sort.exe:");
191 strputs(sb, "sed_command=sed.exe:");
192 #else
197193 strputs(sb, "GTAGS=gctags %s:");
198194 strputs(sb, "GRTAGS=gctags -r %s:");
199195 strputs(sb, "GSYMS=gctags -s %s:");
196 strputs(sb, "sort_command=sort:");
197 strputs(sb, "sed_command=sed:");
198 #endif /* _WIN32 */
200199 line = strdup(strvalue(sb));
201200 if (!line)
202201 die("short of memory.");
269268 if (exist && sb)
270269 strputc(sb, ',');
271270 exist = 1;
272 for (p += strlen(buf); *p && *p != ':'; p++)
271 for (p += strlen(buf); *p && *p != ':'; p++) {
272 if (*p == '\\') /* quoted charactor */
273 p++;
273274 if (sb)
274275 strputc(sb, *p);
276 }
275277 if (!all)
276278 break;
277279 }
287289 } else if (!strcmp(name, "skip")) {
288290 if (sb)
289291 strputs(sb, DEFAULTSKIP);
292 } else if (!strcmp(name, "sort_command")) {
293 if (sb)
294 #ifdef _WIN32
295 strputs(sb, "sort.exe");
296 #else
297 strputs(sb, "sort");
298 #endif
299 } else if (!strcmp(name, "sed_command")) {
300 if (sb)
301 #ifdef _WIN32
302 strputs(sb, "sed.exe");
303 #else
304 strputs(sb, "sed");
305 #endif
290306 } else
291307 exist = 0;
292308 }
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * conf.h 16-Oct-97
34 * conf.h 25-Aug-99
3135 *
3236 */
3337
3539 #define _CONF_H_
3640
3741 #include "strbuf.h"
38 #ifndef __P
39 #if defined(__STDC__)
40 #define __P(protos) protos
41 #else
42 #define __P(protos) ()
43 #endif
44 #endif
42 /*
43 * Access library for global.conf (.globalrc).
44 * File format is a subset of XXXcap (termcap, printcap) file.
45 */
46 #define GTAGSCONF "/etc/global.conf"
47 #define DEBIANCONF "/etc/gtags/global.conf"
48 #define GTAGSRC ".globalrc"
49 #define DEFAULTLABEL "default"
50 #define DEFAULTSUFFIXES "c,h,y,c++,cc,cpp,cxx,hxx,C,H,s,S,java"
51 #define DEFAULTSKIP "y.tab.c,y.tab.h,SCCS/,RCS/,CVS/"
4552
46 char *configpath __P((void));
47 void openconf __P((void));
48 int getconfn __P((const char *, int *));
49 int getconfs __P((const char *, STRBUF *));
50 int getconfb __P((const char *));
51 void closeconf __P((void));
53 char *configpath(void);
54 void openconf(void);
55 int getconfn(const char *, int *);
56 int getconfs(const char *, STRBUF *);
57 int getconfb(const char *);
58 void closeconf(void);
5259
5360 #endif /* ! _CONF_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
2 *
3 * Redilogibution and use in source and binary forms, with or without
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
58 * are met:
6 * 1. Redilogibutions of source code must retain the above copyright
9 * 1. Redistributions of source code must retain the above copyright
710 * notice, this list of conditions and the following disclaimer.
8 * 2. Redilogibutions in binary form must reproduce the above copyright
11 * 2. Redistributions in binary form must reproduce the above copyright
912 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the dilogibution.
13 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
3 * Redilogibution and use in source and binary forms, with or without
6 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
58 * are met:
6 * 1. Redilogibutions of source code must retain the above copyright
9 * 1. Redistributions of source code must retain the above copyright
710 * notice, this list of conditions and the following disclaimer.
8 * 2. Redilogibutions in binary form must reproduce the above copyright
11 * 2. Redistributions in binary form must reproduce the above copyright
912 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the dilogibution.
13 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * dbop.h 12-Nov-98
34 * dbop.h 12-Jul-99
3135 *
3236 */
3337 #ifndef _DBOP_H_
3438 #define _DBOP_H_
3539
36 #include <sys/param.h>
40 #include "gparam.h"
3741 #include "db.h"
3842
3943 #ifndef LITTLE_ENDIAN
4246 #ifndef BIG_ENDIAN
4347 #define BIG_ENDIAN 4321
4448 #endif
45
46 #define MAXKEYLEN 300
4749
4850 typedef struct {
4951 DB *db; /* descripter of DB */
6971 #define DBOP_KEY 1 /* read key part */
7072 #define DBOP_PREFIX 2 /* prefixed read */
7173
72 #ifndef __P
73 #if defined(__STDC__)
74 #define __P(protos) protos
75 #else
76 #define __P(protos) ()
77 #endif
78 #endif
79
80 DBOP *dbop_open __P((const char *, int, int, int));
81 char *dbop_get __P((DBOP *, const char *));
82 void dbop_put __P((DBOP *, const char *, const char *));
83 void dbop_del __P((DBOP *, const char *));
84 char *dbop_first __P((DBOP *, const char *, int));
85 char *dbop_next __P((DBOP *));
86 void dbop_close __P((DBOP *));
74 DBOP *dbop_open(const char *, int, int, int);
75 char *dbop_get(DBOP *, const char *);
76 void dbop_put(DBOP *, const char *, const char *);
77 void dbop_del(DBOP *, const char *);
78 char *dbop_first(DBOP *, const char *, int);
79 char *dbop_next(DBOP *);
80 void dbop_close(DBOP *);
8781 #endif /* _DBOP_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * defined.c 12-Nov-98
34 * defined.c 3-Aug-99
3135 *
3236 */
3337 #include <stdlib.h>
5559 */
5660 if (!(dbpath = getenv("GTAGSDBPATH")))
5761 dbpath = ".";
58 dbop = dbop_open(makepath(dbpath, "GTAGS"), 0, 0, 0);
62 dbop = dbop_open(makepath(dbpath, "GTAGS", NULL), 0, 0, 0);
5963 if (dbop == NULL)
60 die1("GTAGS not found. (%s)", makepath(dbpath, "GTAGS"));
64 die1("GTAGS not found. (%s)", makepath(dbpath, "GTAGS", NULL));
6165 }
6266 if (dbop_get(dbop, name))
6367 return 1;
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * defined.h 2-May-98
34 * defined.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _DEFINED_H_
3539 #define _DEFINED_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 int defined __P((const char *));
41 int defined(const char *);
4642
4743 #endif /* ! _DEFINED_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * find.c 1-May-98
34 * find.c 18-Aug-99
3135 *
3236 */
3337 /*
3438 * USEFIND use find(1) to traverse directory tree.
3539 * Otherwise, use dirent(3) library.
3640 */
37 #define USEFIND
38
39 #include <sys/param.h>
40
41 /* #define USEFIND */
4142 #include <assert.h>
4243 #include <ctype.h>
4344 #ifndef USEFIND
45 #include <sys/types.h>
4446 #include <dirent.h>
45 #ifndef BSD4_4
47 #ifndef BSD4_4 /* BSD's dirent(3) need not stat(2) */
4648 #include <sys/stat.h>
4749 #endif
4850 #endif
4951 #include <stdio.h>
5052 #include <stdlib.h>
51 #include <strings.h>
52 #include <regex.h>
53
53 #include <string.h>
54 #include <unistd.h>
55
56 #include "gparam.h"
57 #include "regex.h"
5458 #include "conf.h"
5559 #include "die.h"
5660 #include "find.h"
57 #include "gparam.h"
5861 #include "locatestring.h"
5962 #include "makepath.h"
6063 #include "strbuf.h"
7275 static regex_t skip_area;
7376 static regex_t *skip = &skip_area;
7477 static int opened;
75
76 static void trim __P((char *));
78 static int retval;
79
80 static void trim(char *);
7781
7882 /*
7983 * trim: remove blanks and '\'.
167171 /*
168172 * compile regular expression.
169173 */
170 if (regcomp(skip, reg, REG_EXTENDED|REG_NEWLINE) != 0)
174 retval = regcomp(skip, reg, REG_EXTENDED|REG_NEWLINE);
175 if (retval != 0)
171176 die("cannot compile regular expression.");
172177 strclose(sbb);
173178 } else {
242247 while ((dp = readdir(dirp)) != NULL) {
243248 #ifdef BSD4_4
244249 if (dp->d_namlen == 1 && dp->d_name[0] == '.')
250 #else
251 if (!strcmp(dp->d_name, "."))
252 #endif
245253 continue;
254 #ifdef BSD4_4
246255 if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
256 #else
257 if (!strcmp(dp->d_name, ".."))
258 #endif
247259 continue;
260 #ifdef BSD4_4
248261 if (dp->d_type == DT_DIR)
249262 strputc(sb, 'd');
250263 else if (dp->d_type == DT_REG)
255268 strputc(sb, ' ');
256269 strnputs(sb, dp->d_name, (int)dp->d_namlen);
257270 #else
258 if (stat(path, &st) < 0) {
259 fprintf(stderr, "cannot stat '%s'. (Ignored)\n", path);
271 #ifdef _WIN32
272 if (stat(makepath(dir, dp->d_name, NULL), &st) < 0) {
273 fprintf(stderr, "cannot stat '%s'. (Ignored)\n", dp->d_name);
260274 continue;
261275 }
276 #else
277 if (lstat(makepath(dir, dp->d_name, NULL), &st) < 0) {
278 fprintf(stderr, "cannot lstat '%s'. (Ignored)\n", dp->d_name);
279 continue;
280 }
281 #endif /* _WIN32 */
262282 if (S_ISDIR(st.st_mode))
263283 strputc(sb, 'd');
264284 else if (S_ISREG(st.st_mode))
316336 trim(skiplist);
317337 }
318338 {
319 char *p;
339 char *suffp;
320340
321341 strstart(sb);
322 strputc(sb, '('); /* ) */
323 for (p = sufflist; p; ) {
324 char *suffp = p;
325 if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
326 *p++ = 0;
327 strputs(sb, "\\.");
328 strputs(sb, suffp);
329 strputc(sb, '$');
330 if (p)
331 strputc(sb, '|');
332 }
333 strputc(sb, ')');
342 strputs(sb, "\\.("); /* ) */
343 for (suffp = sufflist; suffp; ) {
344 char *p;
345
346 for (p = suffp; *p && *p != ','; p++) {
347 strputc(sb, '\\');
348 strputc(sb, *p);
349 }
350 if (!*p)
351 break;
352 assert(*p == ',');
353 strputc(sb, '|');
354 suffp = ++p;
355 }
356 strputs(sb, ")$");
334357 /*
335358 * compile regular expression.
336359 */
337 if (regcomp(suff, strvalue(sb), REG_EXTENDED) != 0)
360 retval = regcomp(suff, strvalue(sb), REG_EXTENDED);
361 if (retval != 0)
338362 die("cannot compile regular expression.");
339363 }
340364 if (skiplist) {
363387 /*
364388 * compile regular expression.
365389 */
366 if (regcomp(skip, strvalue(sb), REG_EXTENDED) != 0)
390 retval = regcomp(skip, strvalue(sb), REG_EXTENDED);
391 if (retval != 0)
367392 die("cannot compile regular expression.");
368393 } else {
369394 skip = (regex_t *)0;
387412
388413 curp->p += strlen(curp->p) + 1;
389414 if (type == 'f' || type == 'l') {
390 char *path = makepath(dir, unit);
415 char *path = makepath(dir, unit, NULL);
391416 if (regexec(suff, path, 0, 0, 0) != 0)
392417 continue;
393418 if (skip && regexec(skip, path, 0, 0, 0) == 0)
394419 continue;
395420 strcpy(val, path);
421 if (length)
422 *length = strlen(val);
396423 return val;
397424 }
398425 if (type == 'd') {
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * find.h 16-Oct-97
34 * find.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _FIND_H_
3539 #define _FIND_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 int issource __P((char *));
46 void findopen __P((void));
47 char *findread __P((int *));
48 void findclose __P((void));
41 int issource(char *);
42 void findopen(void);
43 char *findread(int *);
44 void findclose(void);
4945
5046 #endif /* ! _FIND_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * getdbpath.c 20-Oct-97
34 * getdbpath.c 19-Aug-99
3135 *
3236 */
33 #include <sys/param.h>
3437 #include <sys/types.h>
3538 #include <sys/stat.h>
3639
40 #include <stdlib.h>
41 #include <string.h>
3742 #include <unistd.h>
38 #include <stdlib.h>
3943
44 #include "gparam.h"
4045 #include "die.h"
4146 #include "getdbpath.h"
47 #include "makepath.h"
48 #include "path.h"
4249 #include "test.h"
4350
4451 static const char *makeobjdirprefix; /* obj partition */
98105
99106 if (!getcwd(cwd, MAXPATHLEN))
100107 die("cannot get current directory.");
108 canonpath(cwd);
109 #ifndef _WIN32
101110 /*
102111 * GLOBAL never think '/' is the root of source tree.
103112 */
104113 if (!strcmp(cwd, "/"))
105114 die("It's root directory! What are you doing?");
106
115 #endif
107116 if ((p = getenv("MAKEOBJDIRPREFIX")) != NULL)
108117 makeobjdirprefix = p;
109118 else
114123 makeobjdir = "obj";
115124
116125 if ((p = getenv("GTAGSROOT")) != NULL) {
117 if (*p != '/')
126 if (!isabspath(p))
118127 die("GTAGSROOT must be an absolute path.");
119128 if (stat(p, &sb) || !S_ISDIR(sb.st_mode))
120129 die1("directory '%s' not found.", p);
124133 * GTAGSDBPATH is meaningful only when GTAGSROOT exist.
125134 */
126135 if ((p = getenv("GTAGSDBPATH")) != NULL) {
127 if (*p != '/')
136 if (!isabspath(p))
128137 die("GTAGSDBPATH must be an absolute path.");
129138 if (stat(p, &sb) || !S_ISDIR(sb.st_mode))
130139 die1("directory '%s' not found.", p);
140149 strcpy(root, cwd);
141150 p = root + strlen(root);
142151 while (!gtagsexist(root, dbpath)) {
143 while (*--p != '/')
152 while (*--p != '/' && p > root)
144153 ;
145154 *p = 0;
146155 if (root == p) /* reached root directory */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * getdbpath.h 16-Oct-97
34 * getdbpath.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _GETDBPATH_H_
3539 #define _GETDBPATH_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 int gtagsexist __P((char *, char *));
46 void getdbpath __P((char *, char *, char *));
41 int gtagsexist(char *, char *);
42 void getdbpath(char *, char *, char *);
4743
4844 #endif /* ! _GETDBPATH_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * global.h 2-May-98
34 * global.h 19-Aug-99
3135 *
3236 */
3337
3438 #ifndef _GLOBAL_H_
3539 #define _GLOBAL_H_
3640
41 #include "gparam.h"
3742 #include "conf.h"
3843 #include "dbop.h"
3944 #include "defined.h"
4045 #include "die.h"
4146 #include "find.h"
4247 #include "getdbpath.h"
43 #include "gparam.h"
4448 #include "gtagsop.h"
4549 #include "locatestring.h"
4650 #include "makepath.h"
4751 #include "mgets.h"
52 #include "path.h"
4853 #include "pathop.h"
4954 #include "strbuf.h"
5055 #include "strmake.h"
5257 #include "test.h"
5358 #include "token.h"
5459 #include "usable.h"
60 #include "version.h"
5561
5662 #endif /* ! _GLOBAL_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * gparam.h 16-Jul-98
34 * gparam.h 26-Aug-99
3135 *
3236 */
3337 #ifndef _GPARAM_H_
3438 #define _GPARAM_H_
39 #ifndef __BORLANDC__
40 #include <sys/param.h>
41 #endif
3542
3643 #define MAXFILLEN 1024 /* max length of filter */
3744 #define IDENTLEN 512 /* max length of ident */
3946 #define MAXBUFLEN 1024 /* max length of buffer */
4047 #define MAXPROPLEN 1024 /* max length of property */
4148 #define MAXARGLEN 512 /* max length of argment */
49 #define MAXKEYLEN 300 /* max length of record key */
50 #define MAXTOKEN 512 /* max length of token */
51 #ifndef MAXPATHLEN
52 #define MAXPATHLEN 1024 /* max length of path */
53 #endif
4254
4355 #endif /* ! _GPARAM_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * gtagsop.c 12-Nov-98
34 * gtagsop.c 19-Aug-99
3135 *
3236 */
3337 #include <assert.h>
3539 #include <stdio.h>
3640 #include <stdlib.h>
3741 #include <string.h>
38
42 #include <unistd.h>
43
44 #include "conf.h"
45 #include "gparam.h"
3946 #include "dbop.h"
4047 #include "die.h"
4148 #include "gtagsop.h"
4249 #include "locatestring.h"
4350 #include "makepath.h"
4451 #include "mgets.h"
52 #include "path.h"
4553 #include "pathop.h"
4654 #include "strbuf.h"
4755 #include "strmake.h"
4856 #include "tab.h"
4957
50 static char *genrecord __P((GTOP *));
51 static int belongto __P((GTOP *, char *, char *));
58 static char *genrecord(GTOP *);
59 static int belongto(GTOP *, char *, char *);
5260
5361 static int support_version = 2; /* acceptable format version */
5462 static const char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"};
198206 /*
199207 * allow duplicate records.
200208 */
201 gtop->dbop = dbop_open(makepath(dbpath, dbname(db)), dbmode, 0644, DBOP_DUP);
209 gtop->dbop = dbop_open(makepath(dbpath, dbname(db), NULL), dbmode, 0644, DBOP_DUP);
202210 if (gtop->dbop == NULL) {
203211 if (dbmode == 1)
204212 die1("cannot make %s.", dbname(db));
339347 * i) gtop descripter of GTOP
340348 * i) comline tag command line
341349 * i) path source file
342 * i) flags GTAGS_UNIQUE, GTAGS_EXTRACTMETHOD
350 * i) flags GTAGS_UNIQUE, GTAGS_EXTRACTMETHOD, GTAGS_DEBUG
343351 */
344352 void
345353 gtagsadd(gtop, comline, path, flags)
351359 char *tagline;
352360 FILE *ip;
353361 STRBUF *sb = stropen();
354
362 char sort_command[MAXFILLEN+1];
363 char sed_command[MAXFILLEN+1];
364
365 /*
366 * get command name of sort and sed.
367 */
368 if (!getconfs("sort_command", sb))
369 die("cannot get sort command name.");
370 strcpy(sort_command, strvalue(sb));
371 strstart(sb);
372 if (!getconfs("sed_command", sb))
373 die("cannot get sed command name.");
374 strcpy(sed_command, strvalue(sb));
355375 /*
356376 * add path index if not yet.
357377 */
359379 /*
360380 * make command line.
361381 */
382 strstart(sb);
362383 makecommand(comline, path, sb);
363384 /*
364385 * Compact format.
368389
369390 if ((pno = pathget(path)) == NULL)
370391 die1("GPATH is corrupted.('%s' not found)", path);
371 strputs(sb, "| sed 's!");
392 strputs(sb, "| ");
393 strputs(sb, sed_command);
394 strputc(sb, ' ');
395 strputs(sb, "\"s@");
372396 strputs(sb, path);
373 strputs(sb, "!");
397 strputs(sb, "@");
374398 strputs(sb, pno);
375 strputs(sb, "!'");
376 }
377 if (gtop->format & GTAGS_COMPACT)
378 strputs(sb, "| sort +0 -1 +1n -2");
399 strputs(sb, "@\"");
400 }
401 if (gtop->format & GTAGS_COMPACT) {
402 strputs(sb, "| ");
403 strputs(sb, sort_command);
404 strputc(sb, ' ');
405 strputs(sb, "+0 -1 +1n -2");
406 }
379407 if (flags & GTAGS_UNIQUE)
380 strputs(sb, "| uniq");
408 strputs(sb, " -u");
409 if (flags & GTAGS_DEBUG)
410 fprintf(stderr, "[DBG] executing '%s'\n", strvalue(sb));
381411 if (!(ip = popen(strvalue(sb), "r")))
382412 die1("cannot execute '%s'.", strvalue(sb));
383413 while ((tagline = mgets(ip, NULL, MGETS_TAILCUT)) != NULL) {
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * gtagsop.h 23-Dec-97
34 * gtagsop.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _GTOP_H_
3539 #define _GTOP_H_
3640 #include <stdio.h>
41
42 #include "gparam.h"
3743 #include "dbop.h"
38 #include "gparam.h"
3944 #include "strbuf.h"
4045
4146 #define VERSIONKEY " __.VERSION"
5863 /* gtagsadd() */
5964 #define GTAGS_UNIQUE 1 /* compress duplicate lines */
6065 #define GTAGS_EXTRACTMETHOD 2 /* extract method from class definition */
66 #define GTAGS_DEBUG 4 /* print information for debug */
6167 /* gtagsfirst() */
6268 #define GTOP_KEY 1 /* read key part */
6369 #define GTOP_PREFIX 2 /* prefixed read */
8591 int lno; /* integer value of 'lnop' */
8692 } GTOP;
8793
88 #ifndef __P
89 #if defined(__STDC__)
90 #define __P(protos) protos
91 #else
92 #define __P(protos) ()
93 #endif
94 #endif
95
96 const char *dbname __P((int));
97 void makecommand __P((char *, char *, STRBUF *));
98 int formatcheck __P((char *, int));
99 GTOP *gtagsopen __P((char *, char *, int, int, int));
100 void gtagsput __P((GTOP *, char *, char *));
101 char *gtagsget __P((GTOP *, char *));
102 void gtagsadd __P((GTOP *, char *, char *, int));
103 void gtagsdelete __P((GTOP *, char *));
104 char *gtagsfirst __P((GTOP *, char *, int));
105 char *gtagsnext __P((GTOP *));
106 void gtagsclose __P((GTOP *));
94 const char *dbname(int);
95 void makecommand(char *, char *, STRBUF *);
96 int formatcheck(char *, int);
97 GTOP *gtagsopen(char *, char *, int, int, int);
98 void gtagsput(GTOP *, char *, char *);
99 char *gtagsget(GTOP *, char *);
100 void gtagsadd(GTOP *, char *, char *, int);
101 void gtagsdelete(GTOP *, char *);
102 char *gtagsfirst(GTOP *, char *, int);
103 char *gtagsnext(GTOP *);
104 void gtagsclose(GTOP *);
107105
108106 #endif /* ! _GTOP_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * locatestring.c 25-Jul-98
34 * locatestring.c 3-Aug-99
3135 *
3236 */
3337 #include <string.h>
38 #include <ctype.h>
3439
3540 #include "locatestring.h"
41
42 /*
43 * strincmp: strncmp with ignoring case.
44 *
45 * Interface is same with strncmp.
46 */
47 static int
48 strincmp(string, pattern, len)
49 const char *string;
50 const char *pattern;
51 size_t len;
52 {
53 unsigned char s, p;
54
55 while (len--) {
56 s = tolower(*string++);
57 p = tolower(*pattern++);
58 if (s != p)
59 return s - p;
60 if (s == 0)
61 break;
62 }
63 return 0;
64 }
3665
3766 /*
3867 * locatestring: locate pattern from string
4372 * MATCH_AT_FIRST: match only at first column
4473 * MATCH_LAST: match last
4574 * MATCH_AT_LAST: match only at last column
75 * IGNORE_CASE: Ignore case
4676 * r) pointer or NULL
4777 *
4878 * This function is made to avoid compatibility problems.
5484 int flag;
5585 {
5686 int c = *pattern;
57 int slen, plen;
87 int plen = strlen(pattern);
5888 const char *p = NULL;
89 int slen;
90 int (*cmpfunc) ();
5991
60 plen = strlen(pattern);
92 cmpfunc = (flag & IGNORE_CASE) ? strincmp : strncmp;
93 flag &= ~IGNORE_CASE;
94
6195 if (flag == MATCH_AT_LAST && (slen = strlen(string)) > plen)
6296 string += (slen - plen);
6397 for (; *string; string++) {
6498 if (*string == c)
65 if (!strncmp(string, pattern, plen)) {
99 if (!(*cmpfunc)(string, pattern, plen)) {
66100 p = string;
67101 if (flag == MATCH_FIRST)
68102 break;
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * locatestring.h 25-Jul-98
34 * locatestring.h 3-Aug-99
3135 *
3236 */
3337
3842 #define MATCH_AT_FIRST 1
3943 #define MATCH_LAST 2
4044 #define MATCH_AT_LAST 3
45 #define IGNORE_CASE 8
4146
42 #ifndef __P
43 #if defined(__STDC__)
44 #define __P(protos) protos
45 #else
46 #define __P(protos) ()
47 #endif
48 #endif
49
50 char *locatestring __P((const char *, const char *, int));
47 char *locatestring(const char *, const char *, int);
5148
5249 #endif /* ! _LOCATESTRING_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * makepath.c 15-May-98
34 * makepath.c 3-Aug-99
3135 *
3236 */
33 #include <sys/param.h>
37 #include <string.h>
38
39 #include "gparam.h"
3440 #include "die.h"
3541 #include "makepath.h"
3642 #include "strbuf.h"
4147 *
4248 * i) dir directory
4349 * i) file file
50 * i) suffix suffix(optional)
4451 * r) path
4552 */
4653 char *
47 makepath(dir, file)
54 makepath(dir, file, suffix)
4855 const char *dir;
4956 const char *file;
57 const char *suffix;
5058 {
5159 int length;
5260
5967 strunputc(sb, '/');
6068 strputc(sb, '/');
6169 strputs(sb, file);
70 if (suffix) {
71 if (*suffix != '.')
72 strputc(sb, '.');
73 strputs(sb, suffix);
74 }
6275 if ((length = strlen(strvalue(sb))) > MAXPATHLEN)
63 die1("path name too long. '%s'\n", dir);
76 die1("path name too long. '%s'\n", strvalue(sb));
6477 return strvalue(sb);
6578 }
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * makepath.h 16-Oct-97
34 * makepath.h 19-Aug-99
3135 *
3236 */
3337
3438 #ifndef _MAKEPATH_H_
3539 #define _MAKEPATH_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 char *makepath __P((const char *, const char *));
41 char *makepath(const char *, const char *, const char *);
4642
4743 #endif /* ! _MAKEPATH_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * mgets.c 29-Aug-98
34 * mgets.c 29-May-99
3135 *
3236 */
3337 #include <ctype.h>
127131 }
128132 */
129133 if (flags & MGETS_TAILCUT)
130 while (isspace(*(--p)))
134 while (p > mbuf && isspace(*(--p)))
131135 *p = 0;
132136 if (length)
133137 *length = p - mbuf;
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
3 * Redilogibution and use in source and binary forms, with or without
6 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
58 * are met:
6 * 1. Redilogibutions of source code must retain the above copyright
9 * 1. Redistributions of source code must retain the above copyright
710 * notice, this list of conditions and the following disclaimer.
8 * 2. Redilogibutions in binary form must reproduce the above copyright
11 * 2. Redistributions in binary form must reproduce the above copyright
912 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the dilogibution.
13 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * mgets.h 20-Oct-97
34 * mgets.h 12-Jul-99
3135 *
3236 */
3337 #ifndef _MGETS_H_
3842 #define MGETS_SKIPCOM 2
3943 #define MGETS_TAILCUT 4
4044
41 #ifndef __P
42 #if defined(__STDC__)
43 #define __P(protos) protos
44 #else
45 #define __P(protos) ()
46 #endif
47 #endif
48
49 char *mgets __P((FILE *, int *, int));
45 char *mgets(FILE *, int *, int);
5046
5147 #endif /* ! _MGETS_H_ */
0 /*
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * path.c 24-Aug-99
35 *
36 */
37 #include <string.h>
38
39 #include "path.h"
40
41 /*
42 * isabspath: wether absolute path or not
43 *
44 * i) path path
45 * r) 1: absolute, 0: not absolute
46 */
47 int
48 isabspath(p)
49 char *p;
50 {
51 if (p[0] == '/')
52 return 1;
53 #ifdef _WIN32
54 if (p[0] == '\\')
55 return 1;
56 if (isdrivechar(p[0]) && p[1] == ':' && (p[2] == '\\' || p[2] == '/'))
57 return 1;
58 #endif
59 return 0;
60 }
61
62 /*
63 * canonpath: make canonical path name.
64 *
65 * io) path path
66 * r) path
67 *
68 * Note: canonpath rewrite argument buffer.
69 */
70 char *
71 canonpath(path)
72 char *path;
73 {
74 char *p, *s;
75 #ifdef _WIN32
76 p = path;
77 /*
78 * Change \ to / in a path (for DOS/Windows paths)
79 */
80 while ((p = strchr(p, '\\')) != NULL)
81 *p = '/';
82 #endif
83 #ifdef __CYGWIN__
84 /*
85 * On NT with CYGWIN, getcwd can return something like
86 * "//c/tmp", which isn't usable. We change that to "c:/tmp".
87 */
88 p = path;
89 if (p[0] == '/' && p[1] == '/' && isdrivechar(p[2]) && p[3] == '/') {
90 s = &p[2]; /* point drive char */
91 *p++ = *s++;
92 *p++ = ':';
93 while (*p++ = *s++)
94 ;
95 }
96 #endif
97 return path;
98 }
0 /*
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * path.h 26-Aug-99
35 *
36 */
37
38 #ifndef _PATH_H_
39 #define _PATH_H_
40
41 #if defined(_WIN32) && !defined(__CYGWIN__)
42 #include <unistd.h>
43 #endif
44
45 /*
46 * PATHSEP - Define OS-specific directory and path seperators
47 * isabspath(p) - Returns true when the given path is absolute
48 */
49 #if defined(_WIN32) && !defined(__CYGWIN__)
50 #define PATHSEP ";"
51 #else
52 #define PATHSEP ":"
53 #endif
54
55 #define isdrivechar(x) (((x) >= 'A' && (x) <= 'Z') || ((x) >= 'a' && (x) <= 'z'))
56
57 int isabspath(char *);
58 char *canonpath(char *);
59
60 #endif /* ! _PATH_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * pathop.c 12-Nov-98
34 * pathop.c 3-Aug-99
3135 *
3236 */
3337 #include <assert.h>
6973 _mode = mode;
7074 if (mode == 1 && created)
7175 mode = 0;
72 dbop = dbop_open(makepath(dbpath, gpath), mode, 0644, 0);
76 dbop = dbop_open(makepath(dbpath, gpath, NULL), mode, 0644, 0);
7377 if (dbop == NULL)
7478 return -1;
7579 if (mode == 1)
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * pathop.h 14-May-98
34 * pathop.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _PATHOP_H_
3539 #define _PATHOP_H_
3640 #include <stdio.h>
41
42 #include "gparam.h"
3743 #include "dbop.h"
38 #include "gparam.h"
3944
4045 #define NEXTKEY " __.NEXTKEY"
4146
42 #ifndef __P
43 #if defined(__STDC__)
44 #define __P(protos) protos
45 #else
46 #define __P(protos) ()
47 #endif
48 #endif
49
50 int pathopen __P((const char *, int));
51 char *pathget __P((const char *));
52 char *pathiget __P((int));
53 void pathput __P((const char *));
54 void pathdel __P((const char *));
55 void pathclose __P((void));
56 int nextkey __P((void));
47 int pathopen(const char *, int);
48 char *pathget(const char *);
49 char *pathiget(int);
50 void pathput(const char *);
51 void pathdel(const char *);
52 void pathclose(void);
53 int nextkey(void);
5754
5855 #endif /* ! _PATHOP_H_ */
00 /*
11 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
35 *
46 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
1113 * documentation and/or other materials provided with the distribution.
1214 * 3. All advertising materials mentioning features or use of this software
1315 * must display the following acknowledgement:
14 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1518 * 4. Neither the name of the author nor the names of any co-contributors
1619 * may be used to endorse or promote products derived from this software
1720 * without specific prior written permission.
18 *
21 *
1922 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2124 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00 /*
11 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
35 *
46 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
1113 * documentation and/or other materials provided with the distribution.
1214 * 3. All advertising materials mentioning features or use of this software
1315 * must display the following acknowledgement:
14 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1518 * 4. Neither the name of the author nor the names of any co-contributors
1619 * may be used to endorse or promote products derived from this software
1720 * without specific prior written permission.
18 *
21 *
1922 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2124 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2831 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2932 * SUCH DAMAGE.
3033 *
31 * strbuf.h 20-Jan-99
34 * strbuf.h 12-Jul-99
3235 *
3336 */
3437
6467 } while (0)
6568 #define strputs(sb, s) strnputs(sb, s, strlen(s))
6669
67 #ifndef __P
68 #if defined(__STDC__)
69 #define __P(protos) protos
70 #else
71 #define __P(protos) ()
72 #endif
73 #endif
74
75 void expandbuf __P((STRBUF *, int));
76 STRBUF *stropen __P((void));
77 void strstart __P((STRBUF *));
78 int strbuflen __P((STRBUF *));
79 char *strvalue __P((STRBUF *));
80 void strpushback __P((STRBUF *, int));
81 void strclose __P((STRBUF *));
70 void expandbuf(STRBUF *, int);
71 STRBUF *stropen(void);
72 void strstart(STRBUF *);
73 int strbuflen(STRBUF *);
74 char *strvalue(STRBUF *);
75 void strpushback(STRBUF *, int);
76 void strclose(STRBUF *);
8277
8378 #endif /* ! _STRBUF_H */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * strmake.h 17-Apr-98
34 * strmake.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _STRMAKE_H_
3539 #define _STRMAKE_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 char *strmake __P((const char *, const char *));
41 char *strmake(const char *, const char *);
4642
4743 #endif /* ! _STRMAKE_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * tab.h 8-Oct-98
34 * tab.h 12-Jul-99
3135 *
3236 */
3337
3438 #ifndef _TAB
3539 #define _TAB_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 void settabs __P((int));
46 void detab __P((FILE *, char *));
47 void entab __P((char *));
41 void settabs(int);
42 void detab(FILE *, char *);
43 void entab(char *);
4844
4945 #endif /* ! _TAB_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * test.c 12-Dec-97
34 * test.c 1-Aug-99
3135 *
3236 */
3337 #include <sys/types.h>
3438 #include <sys/stat.h>
35
39 #include <string.h>
3640 #include <unistd.h>
3741
42 #include "locatestring.h"
3843 #include "test.h"
3944
4045 /*
8489 return 0;
8590 break;
8691 case 'x':
92 #ifdef _WIN32
93 /* Look at file extension to determine executability */
94 if (strlen(path) < 5)
95 return 0;
96 if (!S_ISREG(sb.st_mode))
97 return 0;
98 if (!locatestring(path, ".exe", MATCH_AT_LAST|IGNORE_CASE) &&
99 !locatestring(path, ".com", MATCH_AT_LAST|IGNORE_CASE) &&
100 !locatestring(path, ".bat", MATCH_AT_LAST|IGNORE_CASE))
101 return 0;
102 #else
87103 if (access(path, X_OK) < 0)
88104 return 0;
105 #endif
89106 break;
90107 default:
91108 break;
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * test.h 16-Oct-97
34 * test.h 17-Aug-99
3135 *
3236 */
3337
3438 #ifndef _TEST_H_
3539 #define _TEST_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 int test __P((const char *, const char *));
41 int test(const char *, const char *);
4642
4743 #endif /* ! _TEST_H_ */
00 /*
1 * Copyright (c) 1998, 1999 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * token.c 2-Feb-99
34 * token.c 3-Nov-99
3135 */
3236
3337 #include <ctype.h>
3438 #include <stdio.h>
3539 #include <string.h>
36 #include <sys/param.h>
37
40
41 #include "gparam.h"
3842 #include "mgets.h"
3943 #include "token.h"
4044
4246 * File input method.
4347 */
4448 int lineno;
45 char *sp, *cp, *lp;
49 unsigned char *sp, *cp, *lp;
4650 int crflag; /* 1: return '\n', 0: doesn't return */
4751 int cmode; /* allow token which start with '#' */
4852 int cppmode; /* allow token '::' */
4953 int ymode; /* allow token which start with '%' */
50 char token[MAXTOKEN];
51 char curfile[MAXPATHLEN];
52
53 static char ptok[MAXTOKEN];
54 unsigned char token[MAXTOKEN];
55 unsigned char curfile[MAXPATHLEN];
56
57 static unsigned char ptok[MAXTOKEN];
5458 static int lasttok;
5559 static FILE *ip;
5660
57 static void pushbackchar __P((void));
61 static void pushbackchar(void);
5862
5963 /*
6064 * opentoken:
6367 opentoken(file)
6468 char *file;
6569 {
66 if ((ip = fopen(file, "r")) == NULL)
70 /*
71 * b flag is needed for WIN32 environment. Almost unix ignore it.
72 */
73 if ((ip = fopen(file, "rb")) == NULL)
6774 return 0;
6875 strcpy(curfile, file);
6976 sp = cp = lp = NULL; ptok[0] = 0; lineno = 0;
00 /*
1 * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
14 * 4. Neither the name of the author nor the names of its contributors
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * token.h 14-Aug-98
34 * token.h 12-Jul-99
3135 */
3236
3337 #ifndef _TOKEN_H_
3438 #define _TOKEN_H_
3539
36 #include <sys/param.h>
40 #include "gparam.h"
3741 #include "mgets.h"
38 #define MAXTOKEN 512
42
3943 #define SYMBOL 0
4044
41 extern char *sp, *cp, *lp;
45 extern unsigned char *sp, *cp, *lp;
4246 extern int lineno;
4347 extern int crflag;
4448 extern int cmode;
4549 extern int ymode;
4650 extern int cppmode;
47 extern char token[MAXTOKEN];
48 extern char curfile[MAXPATHLEN];
51 extern unsigned char token[MAXTOKEN];
52 extern unsigned char curfile[MAXPATHLEN];
4953
5054 #define nextchar() \
5155 (cp == NULL ? \
5761 (*cp == 0 ? (lp = cp, cp = NULL, '\n') : *cp++))
5862 #define atfirst (sp && sp == (cp ? cp - 1 : lp))
5963
60 #ifndef __P
61 #if defined(__STDC__)
62 #define __P(protos) protos
63 #else
64 #define __P(protos) ()
65 #endif
66 #endif
67
68 int opentoken __P((char *));
69 void rewindtoken __P((void));
70 void closetoken __P((void));
71 int nexttoken __P((const char *, int (*)(char *)));
72 void pushbacktoken __P((void));
73 int peekc __P((int));
74 int atfirst_exceptspace __P((void));
64 int opentoken(char *);
65 void rewindtoken(void);
66 void closetoken(void);
67 int nexttoken(const char *, int (*)(char *));
68 void pushbacktoken(void);
69 int peekc(int);
70 int atfirst_exceptspace(void);
7571
7672 #endif /* ! _TOKEN_H_ */
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * usable.c 22-Jun-98
34 * usable.c 26-Aug-99
3135 *
3236 */
3337 #include <assert.h>
3438 #include <stdlib.h>
3539 #include <string.h>
3640
41 #include "gparam.h"
3742 #include "locatestring.h"
38 #include "gparam.h"
3943 #include "makepath.h"
44 #include "path.h"
4045 #include "test.h"
4146 #include "usable.h"
4247
48 #ifdef _WIN32
49 static const char *suffix[] = {".exe", ".com", ".bat",};
50 #endif
51
4352 /*
44 * usable: check executable or not about the command.
53 * usable: check if command is executable or not.
4554 *
4655 * i) command
4756 * r) 1: executable
4857 * 0: non executable
4958 */
50 int
59 char *
5160 usable(command)
5261 char *command;
5362 {
5463 char buf[MAXENVLEN+1], *p, *dir;
64 static char path[MAXPATHLEN+1];
65 #ifdef _WIN32
66 int i, lim = sizeof(suffix)/sizeof(char *);
67 #endif
5568
56 if (*command == '/' || locatestring(command, "./", MATCH_AT_FIRST) || locatestring(command, "../", MATCH_AT_FIRST))
57 return test("fx", command);
58
69 if (isabspath(command) || locatestring(command, "./", MATCH_AT_FIRST)
70 || locatestring(command, "../", MATCH_AT_FIRST)) {
71 if (test("fx", command)) {
72 strcpy(path, command);
73 return path;
74 }
75 return NULL;
76 }
5977 strcpy(buf, getenv("PATH"));
6078 p = buf;
6179 while (p) {
6280 dir = p;
63 if ((p = locatestring(p, ":", MATCH_FIRST)) != NULL)
81 if ((p = locatestring(p, PATHSEP, MATCH_FIRST)) != NULL)
6482 *p++ = 0;
65 if (test("fx", makepath(dir, command)))
66 return 1;
83 if (test("fx", makepath(dir, command, NULL))) {
84 strcpy(path, makepath(dir, command, NULL));
85 return path;
86 }
87 #if defined(_WIN32)
88 for (i = 0; i < lim; i++)
89 if (test("f", makepath(dir, command, suffix[i]))) {
90 strcpy(path, makepath(dir, command, suffix[i]));
91 return path;
92 }
93 #endif
6794 }
68 return 0;
95 return NULL;
6996 }
00 /*
1 * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
25 *
36 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
1013 * documentation and/or other materials provided with the distribution.
1114 * 3. All advertising materials mentioning features or use of this software
1215 * must display the following acknowledgement:
13 * This product includes software developed by Shigio Yamaguchi.
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
1418 * 4. Neither the name of the author nor the names of any co-contributors
1519 * may be used to endorse or promote products derived from this software
1620 * without specific prior written permission.
17 *
21 *
1822 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1923 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2731 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2832 * SUCH DAMAGE.
2933 *
30 * usable.h 22-Jul-98
34 * usable.h 28-Aug-99
3135 *
3236 */
3337
3438 #ifndef _USABLE_H_
3539 #define _USABLE_H_
3640
37 #ifndef __P
38 #if defined(__STDC__)
39 #define __P(protos) protos
40 #else
41 #define __P(protos) ()
42 #endif
43 #endif
44
45 int usable __P((char *));
41 char *usable(char *);
4642
4743 #endif /* ! _USABLE_H_ */
0 /*
1 * Copyright (c) 1996, 1997, 1998, 1999
2 * Shigio Yamaguchi. All rights reserved.
3 * Copyright (c) 1999
4 * Tama Communications Corporation. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Tama Communications
17 * Corporation and its contributors.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * version.h 3-Nov-99
35 *
36 */
37
38 #ifndef _VERSION_H_
39 #define _VERSION_H_
40
41 #define VERSION "3.54"
42
43 #endif /* ! _VERSION_H_ */
0 /*-
1 * Copyright (c) 1991, 1993
2 * The Regents of the University of California. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by the University of
15 * California, Berkeley and its contributors.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #ifndef _COMPAT_H_
34 #define _COMPAT_H_
35
36 #include <sys/types.h>
37
38 /*
39 * For Borland C++ Compiler and VC++ Compiler.
40 */
41 #if defined(_WIN32) && !defined(__CYGWIN__)
42 typedef unsigned char u_char;
43 typedef unsigned int u_int;
44 typedef unsigned long u_long;
45 typedef unsigned short u_short;
46 typedef signed char int8_t;
47 typedef unsigned char u_int8_t;
48 typedef short int16_t;
49 typedef unsigned short u_int16_t;
50 typedef int int32_t;
51 typedef unsigned int u_int32_t;
52 #endif
53
54 /*
55 * For Solaris.
56 */
57 #if defined(sun) && defined(__SVR4)
58 typedef unsigned char u_int8_t;
59 typedef unsigned short u_int16_t;
60 typedef unsigned int u_int32_t;
61 #endif
62
63 /* If your system doesn't typedef size_t, change the 0 to a 1. */
64 #if 0
65 typedef unsigned int size_t; /* POSIX, 4.[34]BSD names. */
66 #endif
67
68 /* If your system doesn't typedef ssize_t, change the 0 to a 1. */
69 #if 0 || (defined(_WIN32) && !defined(__CYGWIN__))
70 typedef int ssize_t; /* POSIX names. */
71 typedef char * caddr_t;
72 #endif
73
74 /*
75 * If your system doesn't have the POSIX type for a signal mask,
76 * change the 0 to a 1.
77 */
78 #if 0 || (defined(_WIN32) && !defined(__CYGWIN__))
79 typedef unsigned int sigset_t;
80 #endif
81
82 /*
83 * If your system's vsprintf returns a char *, not an int,
84 * change the 0 to a 1.
85 */
86 #if 0
87 #define VSPRINTF_CHARSTAR
88 #endif
89
90 /*
91 * If you don't have POSIX 1003.1 signals, the signal code surrounding the
92 * temporary file creation is intended to block all of the possible signals
93 * long enough to create the file and unlink it. All of this stuff is
94 * intended to use old-style BSD calls to fake POSIX 1003.1 calls.
95 */
96 #if defined(_WIN32) && !defined(__CYGWIN__)
97 #define NO_POSIX_SIGNALS
98 #endif
99 #ifdef NO_POSIX_SIGNALS
100 #define sigemptyset(set) (*(set) = 0)
101 #define sigfillset(set) (*(set) = ~(sigset_t)0, 0)
102 #define sigaddset(set,signo) (*(set) |= sigmask(signo), 0)
103 #define sigdelset(set,signo) (*(set) &= ~sigmask(signo), 0)
104 #define sigismember(set,signo) ((*(set) & sigmask(signo)) != 0)
105
106 #define SIG_BLOCK 1
107 #define SIG_UNBLOCK 2
108 #define SIG_SETMASK 3
109
110 static int __sigtemp; /* For the use of sigprocmask */
111
112 /* Repeated test of oset != NULL is to avoid "*0". */
113 #define sigprocmask(how, set, oset) \
114 ((__sigtemp = \
115 (((how) == SIG_BLOCK) ? \
116 sigblock(0) | *(set) : \
117 (((how) == SIG_UNBLOCK) ? \
118 sigblock(0) & ~(*(set)) : \
119 ((how) == SIG_SETMASK ? \
120 *(set) : sigblock(0))))), \
121 ((oset) ? (*(oset ? oset : set) = sigsetmask(__sigtemp)) : \
122 sigsetmask(__sigtemp)), 0)
123 #endif
124
125 /*
126 * If your system doesn't have an include file with the appropriate
127 * byte order set, make sure you specify the correct one.
128 */
129 #ifndef BYTE_ORDER
130 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
131 #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
132 #define BYTE_ORDER LITTLE_ENDIAN /* Set for your system. */
133 #endif
134
135 #if defined(SYSV) || defined(SYSTEM5)
136 #define index(a, b) strchr(a, b)
137 #define rindex(a, b) strrchr(a, b)
138 #define bzero(a, b) memset(a, 0, b)
139 #define bcmp(a, b, n) memcmp(a, b, n)
140 #define bcopy(a, b, n) memmove(b, a, n)
141 #endif
142
143 #if defined(BSD) || defined(BSD4_3)
144 #define strchr(a, b) index(a, b)
145 #define strrchr(a, b) rindex(a, b)
146 #define memcmp(a, b, n) bcmp(a, b, n)
147 #define memmove(a, b, n) bcopy(b, a, n)
148 #endif
149
150 /*
151 * 32-bit machine. The db routines are theoretically independent of
152 * the size of u_shorts and u_longs, but I don't know that anyone has
153 * ever actually tried it. At a minimum, change the following #define's
154 * if you are trying to compile on a different type of system.
155 */
156 #ifndef USHRT_MAX
157 #define USHRT_MAX 0xFFFF
158 #define ULONG_MAX 0xFFFFFFFF
159 #endif
160
161 #ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */
162 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
163 #endif
164
165 #ifndef _POSIX2_RE_DUP_MAX /* POSIX 1003.2 RE limit. */
166 #define _POSIX2_RE_DUP_MAX 255
167 #endif
168
169 /*
170 * If you can't provide lock values in the open(2) call. Note, this
171 * allows races to happen.
172 */
173 #ifndef O_EXLOCK /* 4.4BSD extension. */
174 #define O_EXLOCK 0
175 #endif
176
177 #ifndef O_SHLOCK /* 4.4BSD extension. */
178 #define O_SHLOCK 0
179 #endif
180
181 #ifndef O_BINARY /* UNIX systems don't often have or need this */
182 #define O_BINARY 0
183 #endif
184
185 #ifndef O_NONBLOCK /* Win32 systems doesn't have or need this */
186 #define O_NONBLOCK 0
187 #endif
188
189 #ifndef EFTYPE
190 #define EFTYPE EINVAL /* POSIX 1003.1 format errno. */
191 #endif
192
193 #ifndef WCOREDUMP /* 4.4BSD extension */
194 #define WCOREDUMP(a) 0
195 #endif
196
197 #ifndef STDERR_FILENO
198 #define STDIN_FILENO 0 /* ANSI C #defines */
199 #define STDOUT_FILENO 1
200 #define STDERR_FILENO 2
201 #endif
202
203 #ifndef SEEK_END
204 #define SEEK_SET 0 /* POSIX 1003.1 seek values */
205 #define SEEK_CUR 1
206 #define SEEK_END 2
207 #endif
208
209 #ifndef _POSIX_VDISABLE /* POSIX 1003.1 disabling char. */
210 #define _POSIX_VDISABLE 0 /* Some systems used 0. */
211 #endif
212
213 #ifndef TCSASOFT /* 4.4BSD extension. */
214 #define TCSASOFT 0
215 #endif
216
217 #ifndef _POSIX2_RE_DUP_MAX /* POSIX 1003.2 values. */
218 #define _POSIX2_RE_DUP_MAX 255
219 #endif
220
221 #ifndef NULL /* ANSI C #defines NULL everywhere. */
222 #define NULL 0
223 #endif
224
225 #ifndef MAX /* Usually found in <sys/param.h>. */
226 #define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
227 #endif
228 #ifndef MIN /* Usually found in <sys/param.h>. */
229 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
230 #endif
231
232 /* Default file permissions. */
233 #ifndef DEFFILEMODE /* 4.4BSD extension. */
234 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
235 #endif
236
237 #ifndef S_ISDIR /* POSIX 1003.1 file type tests. */
238 #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */
239 #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */
240 #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */
241 #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */
242 #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */
243 #endif
244 #ifndef S_ISLNK /* BSD POSIX 1003.1 extensions */
245 #if defined(_WIN32) && !defined(__CYGWIN__)
246 #define S_ISLNK(m) (0)
247 #else
248 #define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */
249 #define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */
250 #endif
251 #endif
252
253 #endif /* !_COMPAT_H_ */
0 beforeinstall:
1 ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
2 ${.CURDIR}/systags.sh ${DESTDIR}${BINDIR}/systags
3
4 .include <bsd.prog.mk>
44 install:
55 cp $(PROG).sh $(BINDIR)/$(PROG)
66 chmod 755 $(BINDIR)/$(PROG)
7 cygwin_install: install
78 clean:
00 #!/bin/sh
11 #
2 # Copyright (c) 1997, 1998 Shigio Yamaguchi. All rights reserved.
2 # Copyright (c) 1996, 1997, 1998, 1999
3 # Shigio Yamaguchi. All rights reserved.
4 # Copyright (c) 1999
5 # Tama Communications Corporation. All rights reserved.
36 #
47 # Redistribution and use in source and binary forms, with or without
58 # modification, are permitted provided that the following conditions
1114 # documentation and/or other materials provided with the distribution.
1215 # 3. All advertising materials mentioning features or use of this software
1316 # must display the following acknowledgement:
14 # This product includes software developed by Shigio Yamaguchi.
17 # This product includes software developed by Tama Communications
18 # Corporation and its contributors.
1519 # 4. Neither the name of the author nor the names of any co-contributors
1620 # may be used to endorse or promote products derived from this software
1721 # without specific prior written permission.
18 #
22 #
1923 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2024 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2125 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
217221 #
218222 # make global database(GTAGS, GRTAGS).
219223 #
220 com="gtags -owv $dir > $dir/gtags.log 2>&1"
224 com="gtags -wv $dir > $dir/gtags.log 2>&1"
221225 case $nflag in
222226 n) echo $com;;
223227 *) eval $com;;
0 How to install in WIN32 environment.
1
2 You need Borland C++ compiler 5.0 in C:\bc5.
3
4 C:\global>win32\makeall[RET]
5 ~~~~~~~~~~~~~~~~~~
6 C:\global>win32\install[RET]
7 ~~~~~~~~~~~~~~~~~~
8 C:\global>mkdir \tmp[RET]
9 ~~~~~~~~~~~~~~~
10 C:\global>win32\clean[RET]
11 ~~~~~~~~~~~~~~~~
12 You need perl command when using htags.pl.
13 You can get win32-perl at Active STATE. See 'http://www.activestate.com/'.
14
15 Also, you need UNIX compatible sed and sort.
16 Please read win32.txt by Dan Fandrich for more information.
17
18 Global 3.5 has been tested under Windows NT 4.0 with Borland C++ 5.02.
0 cd libdb
1 copy Makefile.w32 Makefile
2 make clean
3 cd ..
4 cd libregex
5 copy Makefile.w32 Makefile
6 make clean
7 cd ..
8 cd libutil
9 copy Makefile.w32 Makefile
10 make clean
11 cd ..
12 cd btreeop
13 copy Makefile.w32 Makefile
14 make clean
15 cd ..
16 cd global
17 copy Makefile.w32 Makefile
18 make clean
19 cd ..
20 cd gtags
21 copy Makefile.w32 Makefile
22 make clean
23 cd ..
24 cd gctags
25 copy Makefile.w32 Makefile
26 make clean
27 cd ..
28 cd gozilla
29 copy Makefile.w32 Makefile
30 make clean
31 cd ..
0 -+bt_close.obj -+bt_conv.obj -+bt_debug.obj -+bt_delete.obj -+bt_get.obj -+bt_open.obj -+bt_overflow.obj -+bt_page.obj -+bt_put.obj -+bt_search.obj -+bt_seq.obj -+bt_split.obj -+bt_utils.obj -+mpool.obj -+db.obj
0 set bin=\bin
1 copy btreeop\btreeop.exe %bin%
2 copy global\global.exe %bin%
3 copy gtags\gtags.exe %bin%
4 copy gctags\gctags.exe %bin%
5 copy htags\htags.pl %bin%
6 copy gozilla\gozilla.exe %bin%
0 ../libutil/libgloutil.lib ../libdb/libglodb.lib ../libregex/libgloregex.lib
0 cd libdb
1 copy Makefile.w32 Makefile
2 make
3 cd ..
4 cd libregex
5 copy Makefile.w32 Makefile
6 make
7 cd ..
8 cd libutil
9 copy Makefile.w32 Makefile
10 make
11 cd ..
12 cd btreeop
13 copy Makefile.w32 Makefile
14 make
15 cd ..
16 cd global
17 copy Makefile.w32 Makefile
18 make
19 cd ..
20 cd gtags
21 copy Makefile.w32 Makefile
22 make
23 cd ..
24 cd gctags
25 copy Makefile.w32 Makefile
26 make
27 cd ..
28 cd gozilla
29 copy Makefile.w32 Makefile
30 make
31 cd ..
0 -+regcomp.obj -+regerror.obj -+regexec.obj -+regfree.obj
0 /*
1 * This file is placed into the public domain by the author,
2 * Dan Fandrich <dan@fch.wimsey.bc.ca>
3 */
4
5 /* Win32 header file to simulate some of the things Unix provides */
6
7 #ifndef _UNISTD_H_
8 #define _UNISTD_H_
9
10 #include <io.h>
11 #include <fcntl.h>
12 #include <dir.h>
13 #include <stddef.h>
14 #include <stdio.h> /* to avoid problems with db.h */
15
16 #ifdef __VISUALC__
17 /* Compatibility functions for Microsoft Visual C++ */
18 #define mkstemp(p) open(_mktemp(p), _O_CREAT | _O_SHORT_LIVED | _O_EXCL)
19
20 #ifndef S_ISREG
21 #define S_ISREG(m) ((m) & _S_IFREG)
22 #define S_ISDIR(m) ((m) & _S_IFDIR)
23 #define S_ISCHR(m) ((m) & S_IFCHR)
24 #define S_ISBLK(m) ((m) & S_IFBLK)
25 #define S_ISFIFO(m) ((m) & S_IFIFO)
26 #endif
27
28 #endif
29
30 #ifdef __BORLANDC__
31 #define mkstemp(p) open(mktemp(p), O_CREAT | O_EXCL)
32 #define realpath(a,b) _fullpath((b), (a), \
33 sizeof(b) == sizeof(char *) ? MAXPATHLEN : sizeof(b)), \
34 canonpath(b)
35 #endif
36
37 /* Compatibility for both Borland C++ and MS VC++ */
38 #define popen _popen
39 #define pclose _pclose
40 #define sigsetmask(x) (0)
41 #define sigblock(x) (0)
42 #define fsync(f) (0)
43
44 #ifndef R_OK
45 #define R_OK 4
46 #endif
47 #ifndef W_OK
48 #define W_OK 2
49 #endif
50 #ifndef X_OK
51 #define X_OK 1
52 #endif
53
54 #endif /* _UNISTD_H_ */
0 -+usable.obj -+gtagsop.obj -+getdbpath.obj -+find.obj -+defined.obj -+conf.obj -+tab.obj -+strmake.obj -+pathop.obj -+mgets.obj -+makepath.obj -+locatestring.obj -+dbop.obj -+test.obj -+token.obj -+strbuf.obj -+path.obj
0 Global under Windows
1
2 Global requires the GNU programs sed.exe, sort.exe, uniq.exe be the path.
3 Note that the sort that comes with Windows does not support multikey sorting
4 which is required by global. To avoid using that version of sort, the directory
5 containing the GNU version must be first in your PATH.
6
7 The GNU utilities listed above may be downloaded from:
8 <http://www.edv.agrar.tu-muenchen.de/~syring/win32/UnxUtils.html>
9
10 All paths are expected to use the UNIX directory separator '/' instead of
11 the DOS/Windows '\'. This includes the Global-specific environment variables
12 as well as paths given on command lines. However, the path separators
13 expected for the PATH and GTAGSLIBPATH environment variables are expected
14 to be the DOS-style ';' instead of the UNIX-style ':'.
15
16 The included file win32\global.conf must also be copied to a convenient
17 location and the GTAGSCONF environment variable must be set to its name
18 (e.g. set GTAGCONF=c:/global/global.conf)
19
20 To compile Global under Windows, manually change to each directory
21 in turn and in each type 'make -N -fmakefile.w32' (the libutil and libdb
22 directories must be done first). The result will be an executable file
23 or a library in each directory. Copy the executables into a directory on
24 yoru PATH.
25
26 Global 3.44 has been tested under Windows NT 4.0 with Borland C++ 4.5
27
28 Dan Fandrich <dan@fch.wimsey.bc.ca>
29 July 29, 1999