├── .gitignore ├── 437.lst ├── 850.lst ├── 8859.lst ├── CHANGES ├── COPYRIGHT ├── Makefile ├── README.md ├── agrep.8859.lst ├── agrep.algorithms ├── agrep.c ├── agrep.chronicle ├── agrep.h ├── agrephlp.c ├── archive ├── 204 │ └── agrep-2.04.tgz ├── 333 │ ├── agrep333.zip │ └── agrepw32.zip ├── 335 │ ├── 333to335.dif │ ├── AgrepWin.dif │ ├── ag335src.zip │ ├── agrep.zip │ ├── agrep2.zip │ ├── agrep335.zip │ └── agrepdos.zip ├── 336 │ └── AGRPW336.ZIP ├── 337 │ ├── ag337src.zip │ ├── agrep337.zip │ └── agrepw32.zip ├── 340 │ └── agrep340.zip ├── 341 │ └── agrep-3.41.tgz ├── README.204 ├── agrep335.doc ├── agrepw32.doc ├── codepage.rexx └── readme.1st ├── asearch.c ├── asearch1.c ├── asplit.c ├── autoconf.h ├── bitap.c ├── bitap.c.orig ├── checkfil.c ├── checkfil.h ├── checkfile.c ├── checkfile.h ├── checksg.c ├── codepage.c ├── codepage.h ├── compat.c ├── config.h ├── contribution.list ├── defs.h ├── delim.c ├── docs ├── AGREP_A_FAST_ APPROXIMATE_PATTERN-MATCHING_TOOL_1992_agrep2.pdf ├── FAST_TEXT_ SEARCHING_WITH ERRORS_199106_ agrep1.pdf ├── GLIMPSE_A_Tool_to_Search_Through_Entire_File_Systems_199310_glimpse.pdf ├── README └── agrep-and-glimpse-docs.zip ├── dummyfil.c ├── dummyfilters.c ├── dummysyscalls.c ├── follow.c ├── installation ├── Agrep.mak ├── Makefile.NeXT ├── Makefile.alpha ├── Makefile.hp ├── Makefile.in ├── Makefile.linux.old ├── Makefile.os2 ├── Makefile.rs6000 ├── Makefile.sgi ├── Makefile.solaris ├── Makefile.sunos ├── README └── agrepgdb.mk ├── io.c ├── io.c.orig ├── main.c ├── maskgen.c ├── newmgrep.c ├── ntdirent.c ├── ntdirent.h ├── parse.c ├── preproce.c ├── preprocess.c ├── putils.c ├── re.h ├── recursiv.c ├── recursive.c ├── resources └── agrep.gif ├── sgrep.c ├── unistd.h ├── utilitie.c ├── utilities.c └── version.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /agrep 3 | *.exe 4 | *~ 5 | -------------------------------------------------------------------------------- /437.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/437.lst -------------------------------------------------------------------------------- /850.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/850.lst -------------------------------------------------------------------------------- /8859.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/8859.lst -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 20140918 new license see COPYRIGHT ("... Permission to use, copy, modify, and/or distribute ... for any purpose with or without fee is hereby granted ...") 2 | 3.411 20130216 TG small changes, help file, version, preparing for Github, makefile makefile.os2, CHANGES 3 | 3.41 20040531 TG The versions AGREP 3.41 for LINUX, AGREP 3.37 for Windows 95/NT, AGREP 3.35 for OS/2 and DOS 4 | are based on the AGREP program from GLIMPSE 3.0. 5 | Many bugs have been identified and I regard my version as the most tested and debugged version of all AGREP versions 6 | I found until 31.05.2004. However, the core from which I started is extremely diffcult to read (apart from understanding) 7 | and lacking descriptions. However, my port never crashed in all the last eight years. 8 | 3.0 Agrep version 3.0 as in GLIMPSE 3.0 9 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | As of Sept 18, 2014, Webglimpse, Glimpse and Agrep are available under 2 | the ISC open source license, thanks to the 3 | University of Arizona Office of Technology Transfer and all the developers, 4 | who were more than happy to release it. 5 | 6 | Sources: 7 | http://webglimpse.net/sublicensing/licensing.html 8 | http://opensource.org/licenses/ISC 9 | 10 | =============================================================================== 11 | 12 | Copyright 1996, Arizona Board of Regents 13 | on behalf of The University of Arizona. 14 | 15 | Permission to use, copy, modify, and/or distribute this software for any 16 | purpose with or without fee is hereby granted, provided that the above 17 | copyright notice and this permission notice appear in all copies. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 20 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS. 22 | 23 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, 24 | OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 25 | DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 26 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 27 | OF THIS SOFTWARE. 28 | 29 | =============================================================================== 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # agrep 3 | # 4 | # Makefile for the LINUX version of AGREP 5 | # 6 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 7 | # 8 | 9 | # CC = gcc -ansi -O3 10 | 11 | # for cross-compilation to Windows 12 | # see http://mxe.cc/#tutorial 13 | # 14 | # use 15 | # make CROSS=i686-pc-mingw32- 16 | 17 | CC=$(CROSS)gcc 18 | 19 | 20 | # --------------------------------------------------------------------- 21 | # Define HAVE_DIRENT_H to be 1 when you don't have 22 | # else define it to be 0 (in this case, one of the other 3 flags 23 | # may need to be defined to be 1). 24 | # --------------------------------------------------------------------- 25 | 26 | HAVE_DIRENT_H = 1 27 | HAVE_SYS_DIR_H = 0 28 | HAVE_SYS_NDIR_H = 0 29 | HAVE_NDIR_H = 0 30 | 31 | # --------------------------------------------------------------------- 32 | # Define UTIME to be 1 if you have the utime() routine on your system. 33 | # Else define it to be 0. 34 | # --------------------------------------------------------------------- 35 | 36 | UTIME = 1 37 | 38 | # --------------------------------------------------------------------- 39 | # Define codepage_SET to be 1 if you want to use the international 40 | # 8bit character set. Else define it to be 0. 41 | # --------------------------------------------------------------------- 42 | # This switch has not been introduced by me ! [TG] 05.10.96 43 | 44 | ISO_CHAR_SET = 1 45 | 46 | OPTIMIZEFLAGS = -O3 47 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) \ 48 | -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) \ 49 | -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) \ 50 | -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) \ 52 | -DISO_CHAR_SET=$(ISO_CHAR_SET) \ 53 | -DS_IFLNK=-1 \ 54 | -Dlstat=stat 55 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) 56 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 \ 57 | -DAGREP_POINTER=1 \ 58 | -DDOTCOMPRESSED=0 59 | 60 | # -Werror=no-unprototyped-calls 61 | 62 | CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) 63 | OTHERLIBS = 64 | 65 | PROG = agrep 66 | 67 | HDRS = agrep.h checkfil.h re.h defs.h config.h codepage.h version.h 68 | 69 | OBJS = follow.o \ 70 | asearch.o \ 71 | asearch1.o \ 72 | agrep.o \ 73 | bitap.o \ 74 | checkfil.o \ 75 | compat.o \ 76 | dummyfil.o \ 77 | main.o \ 78 | maskgen.o \ 79 | parse.o \ 80 | checksg.o \ 81 | preproce.o \ 82 | delim.o \ 83 | asplit.o \ 84 | recursiv.o \ 85 | sgrep.o \ 86 | newmgrep.o \ 87 | utilitie.o \ 88 | codepage.o \ 89 | agrephlp.o 90 | 91 | ifeq ($(CROSS),i686-pc-mingw32-) 92 | 93 | $(PROG).exe: $(OBJS) $(HDRS) 94 | $(CC) -o $(PROG).exe $(OBJS) 95 | 96 | else 97 | 98 | $(PROG): $(OBJS) $(HDRS) 99 | $(CC) -o $(PROG) $(OBJS) 100 | 101 | endif 102 | 103 | clean: 104 | rm -f *.o 105 | rm -f $(PROG) 106 | rm -f $(PROG).exe 107 | 108 | # The header file config.h should be visible in the whole source code 109 | # Apparently, it is not at the moment. [TG] 28.09.96 110 | 111 | compat.o: agrep.h defs.h config.h 112 | asearch.o: agrep.h defs.h config.h 113 | asearch1.o: agrep.h defs.h config.h 114 | bitap.o: agrep.h defs.h config.h codepage.h 115 | checkfil.o: agrep.h checkfil.h defs.h config.h 116 | follow.o: re.h agrep.h defs.h config.h 117 | main.o: agrep.h checkfil.h defs.h config.h 118 | agrep.o: agrep.h checkfil.h defs.h config.h version.h codepage.h 119 | agrephlp.o: version.h config.h 120 | newmgrep.o: agrep.h defs.h config.h codepage.h 121 | maskgen.o: agrep.h defs.h config.h codepage.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preproce.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfil.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h codepage.h 129 | abm.o: agrep.h defs.h config.h 130 | utilitie.o: re.h agrep.h defs.h config.h 131 | dummyfil.o: config.h 132 | codepage.o: codepage.h config.h agrep.h 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # This project is unmaintained since many years. The source code is kept for historical and archive reasons. Use at your own risk, do not use in production environments. 4 | 5 | 6 | AGREP - an approximate GREP. 7 | 8 | Fast searching files for a string or regular expression, with approximate matching capabilities and user-definable records. 9 | 10 | Developed 1989-1991 by Udi Manber, Sun Wu et al. at the University of Arizona. 11 | 12 | For Glimpse and WebGlimpse - AGREP is an essential part of them - see 13 | 14 | * https://github.com/gvelez17/glimpse 15 | * https://github.com/gvelez17/webglimpse 16 | 17 | 18 | Usage 19 | ===== 20 | 21 | Type 22 | 23 | agrep 24 | 25 | to get the six built-in help pages. 26 | 27 | ``` 28 | Approximate Pattern Matching GREP -- Get Regular Expression 29 | Usage: 30 | AGREP [-#cdehi[a|#]klnprstvwxyABDGIRS] [-f patternfile] [-H dir] pattern [files] 31 | -# find matches with at most # errors -A always output filenames 32 | -b print byte offset of match 33 | -c output the number of matched records -B find best match to the pattern 34 | -d define record delimiter -Dk deletion cost is k 35 | -e for use when pattern begins with - -G output the files with a match 36 | -f name of file containing patterns -Ik insertion cost is k 37 | -h do not display file names -Sk substitution cost is k 38 | -i case-insensitive search; ISO <> ASCII -ia ISO chars mapped to lower ASCII 39 | -i# digits-match-digits, letters-letters -i0 case-sensitive search 40 | -k treat pattern literally - no meta-characters 41 | -l output the names of files that contain a match 42 | -n print line numbers of matches -q print buffer byte offsets 43 | -p supersequence search -CP 850|437 set codepage 44 | -r recurse subdirectories (UNIX style) -s silent 45 | -t for use when delimiter is at the end of records 46 | -v output those records without matches -V[012345V] version / verbose more 47 | -w pattern has to match as a word: "win" will not match "wind" 48 | -u unterdruecke record output -x pattern must match a whole line 49 | -y suppresses the prompt when used with -B best match option 50 | @listfile use the filenames in listfile <1>23456Q 51 | ``` 52 | 53 | Branches 54 | ======== 55 | 56 | The present repository contains three different branches: 57 | 58 | * **master**: agrep based on agrep 3.0, ported to OS/2, DOS and Windows in the 90ies, and backported to LINUX (the present version you are visiting) 59 | * **agrep3.0-as-found-in-glimpse4.18.6-20130216**: agrep 3.0 as it was found in the glimpse software 60 | * **agrep2.04**: the first published and original agrep version 61 | 62 | 63 | Installation 64 | ============ 65 | 66 | ``` 67 | git clone git@github.com:Wikinaut/agrep.git 68 | cd agrep 69 | make 70 | ``` 71 | 72 | 73 | Algorithms 74 | ========== 75 | 76 | * [Wu, S., Manber, U.: "Agrep - A Fast Approximate Pattern-Matching Tool", 1992.](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.8488) 77 | * [Wu, S., Manber, U.: "Fast Text Searching With Errors", 1991.](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.20.8854) 78 | * see [agrep.algorithms](https://github.com/Wikinaut/agrep/blob/master/agrep.algorithms) 79 | * see [docs](https://github.com/Wikinaut/agrep/blob/master/docs) 80 | * see [readme](https://github.com/Wikinaut/agrep/blob/master/docs/README) 81 | 82 | 83 | COPYRIGHT 84 | ========= 85 | 86 | * see [COPYRIGHT](https://github.com/Wikinaut/agrep/blob/master/COPYRIGHT) 87 | 88 | 89 | As of Sept 18, 2014, Webglimpse, Glimpse and Agrep are available under 90 | the ISC open source license, thanks to the 91 | University of Arizona Office of Technology Transfer and all the developers, 92 | who were more than happy to release it. 93 | 94 | Sources: 95 | http://webglimpse.net/sublicensing/licensing.html 96 | http://opensource.org/licenses/ISC 97 | 98 | Anyone distributing the AGREP code should include the following license 99 | which is applicable since September 2014: 100 | 101 | Copyright 1996, Arizona Board of Regents 102 | on behalf of The University of Arizona. 103 | 104 | Permission to use, copy, modify, and/or distribute this software for any 105 | purpose with or without fee is hereby granted, provided that the above 106 | copyright notice and this permission notice appear in all copies. 107 | 108 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 109 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 110 | MERCHANTABILITY AND FITNESS. 111 | 112 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, 113 | OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 114 | DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 115 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 116 | OF THIS SOFTWARE. 117 | 118 | 119 | Contributors 120 | ============ 121 | 122 | * see [contribution.list](https://github.com/Wikinaut/agrep/blob/master/contribution.list) 123 | 124 | 125 | History 126 | ======= 127 | 128 | * see [agrep.chronicle](https://github.com/Wikinaut/agrep/blob/master/agrep.chronicle) 129 | 130 | 131 | Alternatives to AGREP 132 | ===================== 133 | 134 | [Alternatives](http://www.tgries.de/agrep): 135 | * TRE is a lightweight, robust, and efficient POSIX compliant regexp matching library with some exciting features such as approximate (fuzzy) matching. 136 | * AGREPY: Python port of agrep string matching with errors 137 | * The bitap library , another new and fresh implementation of the bitap algorithm. Windows - C - Cygwin 138 | * PERL module String:Approx. Perl extension for approximate matching (fuzzy matching) by Jarkko Hietaniemi, Finland 139 | * ugrep https://github.com/Genivia/ugrep 140 | 141 | Further stuff with the same name (agrep) 142 | ======================================== 143 | 144 | * [aGrep](https://play.google.com/store/apps/details?id=jp.sblo.pandora.aGrep&hl=de), published in 2012, is an Android implementation of ```grep``` (but not ```agrep```). 145 | 146 | 147 | Homepage and references 148 | ======================= 149 | 150 | * http://www.tgries.de/agrep 151 | * http://webglimpse.net 152 | * https://en.wikipedia.org/wiki/Agrep 153 | * [Wu, S., Manber, U.: "Agrep - A Fast Approximate Pattern-Matching Tool", 1992.](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.8488) 154 | * [Wu, S., Manber, U.: "Fast Text Searching With Errors", 1991.](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.20.8854) 155 | -------------------------------------------------------------------------------- /agrep.8859.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/agrep.8859.lst -------------------------------------------------------------------------------- /agrep.algorithms: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | The implementation of agrep includes the following algorithms. 3 | Except for exact matching of simple patterns, for which we use 4 | a simple variation of the Boyer-Moore algorithm, 5 | all the algorithms (listed below) were designed by Sun Wu and Udi Manber. 6 | 7 | 1. bitap: The most general algorithm inside agrep. 8 | It supports many extensions such as approximate regular expression 9 | pattern matching, non-uniform costs, simultaneous matching of 10 | multiple patterns, mixed exact/approximate matching, etc. 11 | The algorithm is described in agrep.ps.1. 12 | 13 | 2. mgrep: A sub-linear expect-time algorithm for matching a set of patterns. 14 | It assumes that the set of patterns contains k patterns, and that 15 | the shortest pattern is of size m. 16 | See agrep.ps.2 for a brief description of the algorithm. 17 | 18 | 3. amonkey: a Boyer-Moore style algorithm for approximate pattern matching. 19 | let b = log_c (2*m), where c is the size of alphabet set. 20 | In the preprocessing, a table is built to determine whether 21 | a given substring of size b is in the pattern. 22 | Suppose we are looking for matches with at most k errors. 23 | The search is done in two passes. 24 | In the first pass (the filtering pass), the areas in the text 25 | that have a possibility to contain the matches are marked. 26 | The second pass finds the matches in those marked areas. 27 | The search in the first pass is done in the following way. 28 | Suppose the end position of the pattern is currently aligned with 29 | position tx in the text. 30 | The algorithm scans backward from tx until either (k+1) blocks 31 | that do not occur in the pattern have been scanned, or 32 | the scan has passed position (tx-m+k). 33 | In the former case, pattern is shifted forward to align 34 | the beginning position of the pattern with one character after 35 | the position in the text where the scan was stopped. 36 | In the latter case, we marked tx-m to tx+m as a candidate area. 37 | 38 | 4. mmonkey: Combining the mgrep algorithm with a partition technique, we 39 | have an algorithm with the same time complexity as amonkey. 40 | For ASCII text and pattern, this algorithm is faster than amonkey. 41 | The principle of the partition technique is as follows. 42 | Let A and B be two strings of size m. 43 | If we partition A into (k+1) blocks, then the distance between 44 | A and B is > k if none of the blocks of A occur in B. 45 | This implies that to match A with no more than k errors, 46 | B has to contain a substring that matches exactly one block of A. 47 | A brief description can be found in agrep.ps.2. 48 | 49 | -------------------------------------------------------------------------------- /agrep.chronicle: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | Started in Feb 1991. 3 | This chronicle briefly describes the progress of agrep. 4 | 5 | Feb/91: The approximate pattern matching algorithm called 'bitap' 6 | (bit-parallel approximate pattern matching) is designed. 7 | The algorithm is a generalization of Baeza-Yates' "shift-or" 8 | algorithm for exact matching. 9 | 10 | Mar/91: Many extensions of the algorithm 'bitap' are found, especially 11 | for approximate regular expression pattern matching. Preliminary 12 | implementation of the algorithm showed a strong promise for 13 | a general-purpose fast approximate pattern-matching tool. 14 | 15 | Apr/91: Approximate regular expression pattern matching was implemented. 16 | The result is even better than expected. 17 | The design of the software tool is pinned down. 18 | (For example, record oriented, multi-pattern, AND/OR logic queries.) 19 | A partition technique for approximate pattern matching is used. 20 | 21 | May/91: The prototype of "agrep" is completed. 22 | A lot of debugging/optimization in this month. 23 | 24 | Jun/91: The first version of agrep is released. 25 | agrep 1.0 was announced and made available by anonymous ftp 26 | from cs.arizona.edu. 27 | 28 | Jul/91: A sub-linear expected-time algorithm, called "amonkey" for 29 | approximate pattern matching (for simple pattern) is designed. 30 | The algorithm has the same time complexity as that of 31 | Chang&Lawler but is much much faster in practice. 32 | The algorithm is based on a variation of Boyer-Moore technique, 33 | which we call "block-shifting." 34 | A sub-linear expected-time algorithm, called "mgrep" for 35 | matching a set of patterns is designed based on the "block-shifting" 36 | technique with a hashing technique. 37 | 38 | Aug/91: "amonkey" is implemented and incorporated into agrep. 39 | It is very fast for long patterns like DNA patterns. 40 | (But roughly the same for matching English words as the bitap 41 | algorithm using the partition technique.) 42 | Prototype of "mgrep" is implemented. 43 | 44 | Sep/91: "mgrep" is incorporated into agrep to support the -f option. 45 | An algorithm for approximate pattern matching that combines the 46 | 'partition' technique with the sub-linear expected-time algorithm 47 | for multi-patterns is designed. 48 | Implementation shows it to be the fastest for ASCII text (and pattern). 49 | Boyer-moore technique for exact matching is incorporated. 50 | 51 | Nov/91: The final paper of "agrep" that is to appear in USENIX 52 | conference (Jan 1992) is finished. 53 | 54 | Jan/92: Some new options are added, such as find best matches (-B), 55 | and file outputs (-G). 56 | The man pages are revised. 57 | agrep version 2.0 is released. 58 | Fixed the following bugs and change the version to be 2.01. 59 | 1. -G option doesn't work correctly. 60 | 2. multiple definition of some global variables. 61 | 3. -# with -w forced the first character of the pattern to be matched 62 | 63 | Mar/92: Fixed the following bugs and change the version to be 2.02. 64 | 1. agrep sometimes misses some matches for pipeline input. 65 | 2. the word delimiter was not defined consistantly. 66 | 67 | ------------------------------------------------------------------------------ 68 | bgopal: The following changes were made to the original agrep during 1993-94: 69 | 70 | 1. Modifications to make main() take multiple options from the same '-' group: 71 | - the only modifications were in main.c. 72 | 73 | 2. Now, to make agrep take input from a buffer so that it can be used as a 74 | procedure from another program. Places where changes have to be done: 75 | 76 | - asearch.c/fill_buf(), bitap.c/fill_buf() 77 | - main.c/read() statements 78 | - mgrep.c/read() statements 79 | - sgrep.c/read() statements 80 | - probably don't have to change scanf in main.c where a y/n is asked. 81 | - probably don't have to change readdir in recursive.c. 82 | 83 | I have used fill_buf everywhere for reading things from a file. I have to 84 | verify whether this is actually used to take input in which it has to search 85 | for patterns or to read things REALLY from a file (-f option, file_out, etc.). 86 | If former, then I can simply modify fill_buf to read from an fd or from 87 | an input string. How to specify that string / area of memory is a separate 88 | issue to be resolved during the weekend. 89 | 90 | I have resolved it. I've also made a library interface for agrep. So 2 is done. 91 | 92 | 3. Make errno = exit code whenever you return -1 instead of exiting. 93 | 94 | 4. See if there is a way to avoid copying of memory bytes in agrep 95 | by using pointer manipulation instead of fill_buf: a part of making agrep 96 | a callable routine. Important to make it really fast, that's why do this. 97 | 98 | Solution: 99 | --------- 100 | I think I've solved the problem: but there is a restriction for within the 101 | memory pattern matching: THE SEARCHBUFFER HAS TO BEGIN WITH A NEWLINE -- 102 | otherwise we cannot avoid the copying. This fact can be checked in the 103 | library interface. 104 | 105 | There are some more problems whose solution I'm not sure of: ask Udi. 106 | The problem is: 107 | a. In asearch(), asearch0() and asearch1(), some data is copied after 108 | the data read in the buffer. Is that crucial? The same thing can be 109 | seen in bitap(). This is done when num_read < BlockSize -- why? 110 | b. In sgrep(), the whole buffer is filled with pat[m-1] so that bm() 111 | does not enter an infinite-loop. Is that crucial if there is an 112 | equivalent of a single iteration of the while-fill_buf-loop. 113 | 114 | I have not modified prepf() to read the multi-pattern from memory, not a 115 | file. I have to modify it later (including agrep.c). Function fill_buf now 116 | simply reads from the fd given: it does not bother about pointer 117 | manipulation. Note: wherever there is a while(i lots of 165 | problems! *). 166 | **** These were completed and added into glimpse/glimpseindex in Spring 1994. 167 | 168 | 7. One other problems with agrep as a callable routine: the variable names used 169 | by agrep can clash with user defined variable names. Making agrep variables 170 | static is not going to help since they are accessed throughout agrep code. 171 | Making code reentrant is not the issue (it is almost impossible!). 172 | 173 | -------------------------------------------------------------------------------- /agrep.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* see also agrephlp.c and agrep.c for a more precise history of changes. 4 | 5 | 3.11 [new] option -i0 [TG] 23.09.96 6 | 3.10 [chg] in AGREP.H, ISO_CHAR.H, AGREP.C [TG] 22.09.96 7 | handling of meta symbols 8 | 3.09 [fix] in BITAP.C (type CHAR) [TG] 22.09.96 9 | [new] in AGREP.C (Grand Total) 10 | 3.08 un-commenting code defined in OUTPUT_OVERFLOW [TG] 16.09.96 11 | */ 12 | 13 | #ifndef _AGREP_H_ 14 | #define _AGREP_H_ 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "re.h" 20 | #include "defs.h" 21 | #include "config.h" 22 | #include 23 | #ifndef _WIN32 24 | #include 25 | #endif 26 | #include 27 | 28 | #define AGREP_ENV_OPTS "AGREPOPTS" /* name of the environment variable 29 | holding default options for AGREP */ 30 | 31 | #define MAXNUM_PAT 16 /* 32 parts of a pattern = width of expression-tree */ 32 | #define CHAR unsigned char 33 | #define MAXPAT 256 34 | #define MAXPATT 256 35 | #define MAXDELIM 8 /* Max size of a delimiter pattern */ 36 | #define SHORTREG 15 37 | #define MAXREG 30 38 | #define MAXNAME 256 39 | #define Max_Pats 12 /* max num of patterns */ 40 | #define Max_Keys 12 /* max num of keywords */ 41 | #define Max_Psize 128 /* max size of a pattern counting all the characters */ 42 | #define Max_Keyword 31 /* the max size of a keyword */ 43 | #define WORD 32 /* the size of a word */ 44 | #define MaxError 8 /* the max number of errors allowed */ 45 | #define MaxRerror 4 /* the max number of erros for regular expression */ 46 | #define MaxDelimit 16 /* the max raw length of a user defined delimiter */ 47 | 48 | #define BlockSize 49152 49 | #define Max_record 49152 50 | 51 | #define SIZE 16384 /* BlockSize in sgrep */ 52 | #define MAXLINE 1024 /* maxline in sgrep */ 53 | #define MAX_LINE_LEN 1024 54 | #define Maxline 1024 55 | #define RBLOCK 8192 56 | #define RMAXLINE 1024 57 | #define MaxNext 66000 58 | #define ON 1 59 | #define OFF 0 60 | #define Compl 1 61 | #define Maxresult 10000 62 | #define MaxCan 2500 63 | 64 | #if ( ! (defined(__EMX__) && defined(ISO_CHAR_SET))) 65 | 66 | #define MAXSYM 256 /* ASCII */ 67 | #define WORDB 133 /* -w option */ 68 | #define LPARENT 134 /* ( */ 69 | #define RPARENT 135 /* ) */ 70 | #define LRANGE 136 /* [ */ 71 | #define RRANGE 137 /* ] */ 72 | #define LANGLE 138 /* < */ 73 | #define RANGLE 139 /* > */ 74 | #define NOTSYM 140 /* ^ */ 75 | #define WILDCD 141 /* wildcard */ 76 | #define ORSYM 142 /* | */ 77 | #define ORPAT 143 /* , */ 78 | #define ANDPAT 144 /* ; */ 79 | #define STAR 145 /* closure */ 80 | #define HYPHEN 129 /* - */ 81 | #define NOCARE 130 /* . */ 82 | #define NNLINE 131 /* special symbol for newline in begin of pattern*/ 83 | /* matches '\n' and NNLINE */ 84 | #define USERRANGE_MIN 128 /* min char in pattern of user: give warning */ 85 | #define USERRANGE_MAX 145 /* max char in pattern of user: give warning */ 86 | 87 | #else 88 | 89 | /* The following characters cannot be searched, because they are used 90 | as meta symbols. We need 16 meta symbols. 91 | 92 | The table is optimised for codepage 850; only some code of graphical 93 | characters are now used as meta symbols and cannot be searched therefore. 94 | 95 | These meta symbols are also flagged as such in table UL850 (module ISO_CHAR.H). 96 | (is_metasymbol == 1) 97 | 98 | [TG] 22.09.96 99 | 100 | */ 101 | 102 | #define MAXSYM 256 /* ASCII */ 103 | extern unsigned char metasymb[16]; 104 | 105 | #define WORDB metasymb[0] /* -w option */ 106 | #define LPARENT metasymb[1] /* ( */ 107 | #define RPARENT metasymb[2] /* ) */ 108 | #define LRANGE metasymb[3] /* [ */ 109 | #define RRANGE metasymb[4] /* ] */ 110 | #define LANGLE metasymb[5] /* < */ 111 | #define RANGLE metasymb[6] /* > */ 112 | #define NOTSYM metasymb[7] /* ^ */ 113 | #define WILDCD metasymb[8] /* # wildcard */ 114 | #define ORSYM metasymb[9] /* | */ 115 | #define ORPAT metasymb[10] /* , */ 116 | #define ANDPAT metasymb[11] /* ; */ 117 | #define STAR metasymb[12] /* * closure */ 118 | #define HYPHEN metasymb[13] /* - */ 119 | #define NOCARE metasymb[14] /* . */ 120 | #define NNLINE metasymb[15] /* special symbol for newline in begin of pattern*/ 121 | /* matches '\n' and NNLINE */ 122 | 123 | /* not used anymore: [TG] */ 124 | #define USERRANGE_MIN 0 /* min char in pattern of user: give warning */ 125 | #define USERRANGE_MAX 0 /* max char in pattern of user: give warning */ 126 | 127 | #endif 128 | 129 | /* not a comment anylonger [TG] 16.09.96 */ 130 | #define OUTPUT_OVERFLOW fprintf(stderr, "Output buffer overflow after %d bytes @ %s:%d !!\n", agrep_outpointer, __FILE__, __LINE__) 131 | 132 | extern int exists_delimiter(unsigned char *begin, unsigned char *end, unsigned char *delim, int len); 133 | extern void preprocess_delimiter(unsigned char *src, int srclen, unsigned char *dest, int *pdestlen); 134 | extern unsigned char * backward_delimiter(unsigned char *end, unsigned char *begin, unsigned char *delim, int len, int outtail); 135 | extern unsigned char * forward_delimiter(unsigned char *begin, unsigned char *end, unsigned char *delim, int len, int outtail); 136 | 137 | int exists_tcompressed_word(); 138 | unsigned char * forward_tcompressed_word(), *backward_tcompressed_word(); 139 | extern void alloc_buf(int fd, unsigned char **sbuf, int size); 140 | extern void free_buf(int fd, char *sbuf); 141 | 142 | 143 | /* To parse patterns in asplit.c */ 144 | #define AND_EXP 0x1 /* boolean ; -- remains set throughout */ 145 | #define OR_EXP 0x2 /* boolean , -- remains set throughout */ 146 | #define ATTR_EXP 0x4 /* set when = is next non-alpha char, remains set until next , or ; --> never used in agrep */ 147 | #define VAL_EXP 0x8 /* set all the time except when = is seen for first time --> never used in agrep */ 148 | #define ENDSUB_EXP 0x10 /* set when , or ; is seen: must unset ATTR_EXP now --> never used in agrep */ 149 | 150 | #define INTERNAL 1 151 | #define LEAF 2 152 | #define NOTPAT 0x1000 153 | #define OPMASK 0x00ff 154 | 155 | typedef struct _ParseTree { 156 | short op; 157 | char type; 158 | char terminalindex; 159 | union { 160 | struct { 161 | struct _ParseTree *left, *right; 162 | } internal; 163 | struct { 164 | unsigned char *attribute; /* never used in agrep */ 165 | unsigned char *value; 166 | } leaf; 167 | } data; 168 | } ParseTree; 169 | 170 | #define unget_token_bool(bufptr, tokenlen) (*(bufptr)) -= (tokenlen) 171 | 172 | #define dd(a,b) 1 173 | #define AGREP_ERROR 123 /* errno = 123 means that glimpse should quit searching files: used for errors glimpse itself cannot detect but agrep can */ 174 | 175 | #if ISO_CHAR_SET /* From Henrik.Martin@eua.ericsson.se (Henrik Martin) */ 176 | #define IS_LOCALE_CHAR(c) ((isalnum((c)) || isxdigit((c)) || \ 177 | isspace((c)) || ispunct((c)) || iscntrl((c))) ? 1 : 0) 178 | #define ISASCII(c) IS_LOCALE_CHAR(c) 179 | #else 180 | #define ISASCII(c) isascii(c) 181 | #endif 182 | #endif /* _AGREP_H_ */ 183 | 184 | -------------------------------------------------------------------------------- /archive/204/agrep-2.04.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/204/agrep-2.04.tgz -------------------------------------------------------------------------------- /archive/333/agrep333.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/333/agrep333.zip -------------------------------------------------------------------------------- /archive/333/agrepw32.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/333/agrepw32.zip -------------------------------------------------------------------------------- /archive/335/333to335.dif: -------------------------------------------------------------------------------- 1 | diff -u -r --new-file agrep.333/agrep.c agrep.335/agrep.c 2 | --- agrep.333/agrep.c Tue Apr 08 00:50:01 1997 3 | +++ agrep.335/agrep.c Thu Dec 11 02:22:17 1997 4 | @@ -1,9 +1,13 @@ 5 | /* 6 | AGREP APPROXIMATE PATTERN - GREP. 7 | 8 | - Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. 9 | + Copyright (c) 1994-1997 Sun Wu, Udi Manber, Burra Gopal, Tom Gries (for OS/2) 10 | All Rights Reserved. 11 | 12 | +[fix] 3.35 TG 11.12.97 agrep.c: -f function did not work because of a simple 13 | + problem in the commandline parser: the patternfile preprocessing 14 | + prepf() was done before definition of the codepage. Oops. 15 | +[fix] 3.34 newmgrep.c: input buffer was used before its start address 16 | [chg] 3.33 TG 02.03.97 when no target filename(s) were given: 17 | AGREP displays an error message now 18 | instead of reading from stdin. 19 | @@ -2418,16 +2422,23 @@ 20 | PRINT(printf("file=%s\n", argv[0]); 21 | ) 22 | strcpy(PAT_FILE_NAME, argv[0]); 23 | - if (prepf(multifd, NULL, 0) <= -1) { 24 | - close(multifd); 25 | - PAT_FILE = OFF; 26 | - fprintf(stderr, "%s: error in processing pattern file: %s\n", Progname, argv[0]); 27 | - if (!EXITONERROR) { 28 | - errno = AGREP_ERROR; 29 | - return -1; 30 | - } 31 | - else exit(2); 32 | - } 33 | + 34 | +/* TG 11.12.97 [fix] 3.35 35 | + * Postpone the pattern file preprocessing until the codepage has been set up outside the loop ! 36 | + * Code is simply moved below (after codepage loading). 37 | + * 38 | + * if (prepf(multifd, NULL, 0) <= -1) { 39 | + * close(multifd); 40 | + * PAT_FILE = OFF; 41 | + * fprintf(stderr, "%s: error in processing pattern file: %s\n", Progname, argv[0]); 42 | + * if (!EXITONERROR) { 43 | + * errno = AGREP_ERROR; 44 | + * return -1; 45 | + * } 46 | + * else exit(2); 47 | + * } 48 | + */ 49 | + 50 | quitwhile = ON; 51 | break; 52 | 53 | @@ -2805,6 +2816,24 @@ 54 | 55 | } 56 | } 57 | + 58 | + 59 | + /* pattern file handling TG 11.12.97 [fix] 3.35 60 | + Simply moved from above, commandline parsing of -f option. */ 61 | + 62 | + if (PAT_FILE) { 63 | + if (prepf(multifd, NULL, 0) <= -1) { 64 | + close(multifd); 65 | + PAT_FILE = OFF; 66 | + fprintf(stderr, "%s: error in processing pattern file: %s\n", Progname, argv[0]); 67 | + if (!EXITONERROR) { 68 | + errno = AGREP_ERROR; 69 | + return -1; 70 | + } 71 | + else exit(2); 72 | + } 73 | + } 74 | + 75 | 76 | if (NOOUTTAIL == ON) OUTTAIL = OFF; 77 | 78 | diff -u -r --new-file agrep.333/agrepgdb.mk agrep.335/agrepgdb.mk 79 | --- agrep.333/agrepgdb.mk Wed Dec 31 19:00:00 1969 80 | +++ agrep.335/agrepgdb.mk Wed Oct 22 01:49:55 1997 81 | @@ -0,0 +1,164 @@ 82 | +# 83 | +# agrepos2.mk 84 | +# Makefile for the OS/2-only version of AGREP 85 | +# 86 | +# creates AGREP2.EXE for OS/2 87 | +# does not need any other EXE or DLL 88 | +# 89 | +# Operatingsystem | OS/2 | DOS | Win 3.x | 90 | +# |------------------------|--------------|-----------------------| 91 | +# | native | DOS-Box | native | DOS-Box | GUI | 92 | +# | AGREP2.EXE | - | - | - | - | 93 | +# 94 | +# If you are running DOS or Windows, 95 | +# and/or if you want to run AGREP in a DOS-Window of OS/2, 96 | +# compile and link with 97 | +# 98 | +# agrepdos.mk 99 | +# 100 | +# to create an executable 101 | +# 102 | +# AGREP.EXE 103 | +# 104 | +# which DOES need RSX.EXE (see table) when running under a 105 | +# DPMI server (himem.sys+emm386, 386max, or qemm386) 106 | +# 107 | +# | | | | | | 108 | +# | AGREP.EXE | AGREP.EXE | AGREP.EXE | AGREP.EXE | not impl.| | 109 | +# prerequisites: | | + RSX.EXE | | + RSX.EXE | | 110 | +# | | (note 1) | | 111 | +# 112 | +# NOTE: 113 | +# 114 | +# The AGREP.EXE tries to locate RSX.EXE via the environment variable RSX. 115 | +# When you have put the RSX.EXE into the subdirectory c:\rsx\bin\rsx.exe then use 116 | +# 117 | +# SET RSX=C:\RSX\BIN\RSX.EXE 118 | +# 119 | +# in your AUTOEXEC.BAT. 120 | +# 121 | +# 122 | +# Adapted for the emx compiler by Tom Gries 123 | +# 02.03.97 124 | +# 125 | +# on the basis of an original: 126 | +# Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 127 | +# 128 | + 129 | +# The switches -Zomf and -Zsys are sufficient to create an 130 | +# OS/2-only stand-alone executable, which does not need EMX.DLL 131 | +# 132 | +# This is the PURE-OS/2 solution. 133 | +# 134 | +#CC = gcc -Zomf -Zsys -ansi -O3 135 | + 136 | +CC = gcc -ansi 137 | + 138 | +# 139 | +#CC = gcc -ansi -O3 140 | +# 141 | + 142 | +# --------------------------------------------------------------------- 143 | +# Define HAVE_DIRENT_H to be 1 when you don't have 144 | +# else define it to be 0 (in this case, one of the other 3 flags 145 | +# may need to be defined to be 1). 146 | +# --------------------------------------------------------------------- 147 | + 148 | +HAVE_DIRENT_H = 1 149 | +HAVE_SYS_DIR_H = 0 150 | +HAVE_SYS_NDIR_H = 0 151 | +HAVE_NDIR_H = 0 152 | + 153 | +# --------------------------------------------------------------------- 154 | +# Define UTIME to be 1 if you have the utime() routine on your system. 155 | +# Else define it to be 0. 156 | +# --------------------------------------------------------------------- 157 | + 158 | +UTIME = 1 159 | + 160 | +# --------------------------------------------------------------------- 161 | +# Define codepage_SET to be 1 if you want to use the international 162 | +# 8bit character set. Else define it to be 0. 163 | +# --------------------------------------------------------------------- 164 | +# This switch has not been introduced by me ! [TG] 05.10.96 165 | + 166 | +ISO_CHAR_SET = 1 167 | + 168 | +###### OPTIMIZEFLAGS = -O3 169 | + 170 | +DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) \ 171 | + -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) \ 172 | + -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) \ 173 | + -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 174 | + -DUTIME=$(UTIME) \ 175 | + -DISO_CHAR_SET=$(ISO_CHAR_SET) \ 176 | + -DS_IFLNK=-1 \ 177 | + -Dlstat=stat 178 | +SUBDIRCFLAGS = -g -c -fbounds-checking $(DEFINEFLAGS) $(OPTIMIZEFLAGS) 179 | +MYDEFINEFLAGS = -DMEASURE_TIMES=0 \ 180 | + -DAGREP_POINTER=1 \ 181 | + -DDOTCOMPRESSED=0 \ 182 | + -D__OS2=1 183 | +CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) 184 | +OTHERLIBS = 185 | + 186 | +PROG = agrep2 187 | + 188 | +HDRS = agrep.h checkfil.h re.h defs.h config.h codepage.h version.h 189 | + 190 | +OBJS = follow.o \ 191 | + asearch.o \ 192 | + asearch1.o \ 193 | + agrep.o \ 194 | + bitap.o \ 195 | + checkfil.o \ 196 | + compat.o \ 197 | + dummyfil.o \ 198 | + main.o \ 199 | + maskgen.o \ 200 | + parse.o \ 201 | + checksg.o \ 202 | + preproce.o \ 203 | + delim.o \ 204 | + asplit.o \ 205 | + recursiv.o \ 206 | + sgrep.o \ 207 | + newmgrep.o \ 208 | + utilitie.o \ 209 | + codepage.o \ 210 | + agrephlp.o 211 | + 212 | +# not use any longer io.o 213 | + 214 | +$(PROG).EXE: $(OBJS) 215 | + $(CC) -fbounds-checking -o $(PROG).EXE $(OBJS) 216 | + 217 | +clean: 218 | + -del *.o 219 | + -del $(PROG).EXE 220 | + 221 | +# The header file config.h should be visible in the whole source code 222 | +# Apparently, it is not at the moment. [TG] 28.09.96 223 | + 224 | +compat.o: agrep.h defs.h config.h 225 | +asearch.o: agrep.h defs.h config.h 226 | +asearch1.o: agrep.h defs.h config.h 227 | +bitap.o: agrep.h defs.h config.h codepage.h 228 | +checkfil.o: agrep.h checkfil.h defs.h config.h 229 | +follow.o: re.h agrep.h defs.h config.h 230 | +main.o: agrep.h checkfil.h defs.h config.h 231 | +agrep.o: agrep.h checkfil.h defs.h config.h version.h codepage.h 232 | +agrephlp.o: version.h config.h 233 | +newmgrep.o: agrep.h defs.h config.h codepage.h 234 | +maskgen.o: agrep.h defs.h config.h codepage.h 235 | +next.o: agrep.h defs.h config.h 236 | +parse.o: re.h agrep.h defs.h config.h 237 | +preproce.o: agrep.h defs.h config.h 238 | +checksg.o: agrep.h checkfil.h defs.h config.h 239 | +delim.o: agrep.h defs.h config.h 240 | +asplit.o: agrep.h defs.h config.h 241 | +sgrep.o: agrep.h defs.h config.h codepage.h 242 | +# not used any longer io.o: agrep.h defs.h config.h 243 | +utilitie.o: re.h agrep.h defs.h config.h 244 | +dummyfil.o: config.h 245 | +codepage.o: codepage.h config.h agrep.h 246 | diff -u -r --new-file agrep.333/newmgrep.c agrep.335/newmgrep.c 247 | --- agrep.333/newmgrep.c Tue Apr 08 00:50:01 1997 248 | +++ agrep.335/newmgrep.c Wed Oct 22 22:13:19 1997 249 | @@ -1,7 +1,10 @@ 250 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 251 | 252 | /* 253 | -[chg] 21.08.96 now uses ISO_CHAR.H /TG 254 | + 255 | +[fix] TG 22.10.97 3.34 in mgrep(): check bounds before memcpy-ing 256 | +[chg] TG 21.08.96 now uses ISO_CHAR.H 257 | + 258 | */ 259 | 260 | /* multipattern matcher */ 261 | @@ -479,7 +482,15 @@ 262 | newbuf = backward_delimiter(newbuf, text+MAXLINE, D_pattern, D_length, OUTTAIL); /* see agrep.c/'d' */ 263 | if (newbuf < text+MAXLINE+D_length) newbuf = text + end + 1; 264 | end = newbuf - text - 1; 265 | - memcpy(text+start-D_length, D_pattern, D_length); 266 | + 267 | +/* TG 22.10.97 Check bounds before memcpy-ing */ 268 | +/* printf("text %x start %i D_length %i D_pattern %i residue %i\n",text,start,D_length,D_pattern,residue); */ 269 | + 270 | + if (start > D_length) memcpy(text+start-D_length, D_pattern, D_length); 271 | + memcpy(text+start+residue, D_pattern, D_length); 272 | + 273 | +/* original code was: memcpy(text+start-D_length, D_pattern, D_length); */ 274 | + 275 | } 276 | residue = buf_end - end + 1 ; 277 | if(INVERSE && COUNT) countline(text+MAXLINE, num_read); 278 | diff -u -r --new-file agrep.333/target agrep.335/target 279 | --- agrep.333/target Wed Dec 31 19:00:00 1969 280 | +++ agrep.335/target Mon Dec 08 22:22:07 1997 281 | @@ -0,0 +1,9 @@ 282 | +cepas 283 | +wombat 284 | +nail 285 | +beavis 286 | +coat 287 | +teletubbies 288 | +coat nail 289 | +happy xmas 290 | + 291 | \ No newline at end of file 292 | diff -u -r --new-file agrep.333/version.h agrep.335/version.h 293 | --- agrep.333/version.h Tue Apr 08 00:50:01 1997 294 | +++ agrep.335/version.h Thu Dec 11 01:55:57 1997 295 | @@ -1,4 +1,8 @@ 296 | /* 297 | +[fix] 3.35 TG 11.12.97 in agrep(): -f now working again 298 | + prepf() for multi-pattern was called 299 | + before the codepage LUT was prepared 300 | +[fix] 3.34 TG 22.10.97 in mgrep(): check bounds before memcpy() 301 | [chg] 3.33 TG 07.04.97 when no target filename(s) were given: 302 | AGREP displays an error message now 303 | instead of reading from stdin. 304 | @@ -35,7 +39,7 @@ 305 | 306 | */ 307 | 308 | -#define AGREP_VERSION "3.33" 309 | +#define AGREP_VERSION "3.35" 310 | 311 | #ifdef __DOS 312 | #define AGREP_OS "DOS" 313 | -------------------------------------------------------------------------------- /archive/335/ag335src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/335/ag335src.zip -------------------------------------------------------------------------------- /archive/335/agrep.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/335/agrep.zip -------------------------------------------------------------------------------- /archive/335/agrep2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/335/agrep2.zip -------------------------------------------------------------------------------- /archive/335/agrep335.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/335/agrep335.zip -------------------------------------------------------------------------------- /archive/335/agrepdos.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/335/agrepdos.zip -------------------------------------------------------------------------------- /archive/336/AGRPW336.ZIP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/336/AGRPW336.ZIP -------------------------------------------------------------------------------- /archive/337/ag337src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/337/ag337src.zip -------------------------------------------------------------------------------- /archive/337/agrep337.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/337/agrep337.zip -------------------------------------------------------------------------------- /archive/337/agrepw32.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/337/agrepw32.zip -------------------------------------------------------------------------------- /archive/340/agrep340.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/340/agrep340.zip -------------------------------------------------------------------------------- /archive/341/agrep-3.41.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/341/agrep-3.41.tgz -------------------------------------------------------------------------------- /archive/README.204: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | This is version 2.04 of agrep - a new tool for fast 3 | text searching allowing errors. 4 | agrep is similar to egrep (or grep or fgrep), but it is much more general 5 | (and usually faster). 6 | The main changes from version 1.1 are 1) incorporating Boyer-Moore 7 | type filtering to speed up search considerably, 2) allowing multi patterns 8 | via the -f option; this is similar to fgrep, but from our experience 9 | agrep is much faster, 3) searching for "best match" without having to 10 | specify the number of errors allowed, and 4) ascii is no longer required. 11 | Several more options were added. 12 | 13 | To compile, simply run make in the agrep directory after untar'ing 14 | the tar file (tar -xf agrep-2.04.tar will do it). 15 | 16 | The three most significant features of agrep that are not supported by 17 | the grep family are 18 | 1) the ability to search for approximate patterns; 19 | for example, "agrep -2 homogenos foo" will find homogeneous as well 20 | as any other word that can be obtained from homogenos with at most 21 | 2 substitutions, insertions, or deletions. 22 | "agrep -B homogenos foo" will generate a message of the form 23 | best match has 2 errors, there are 5 matches, output them? (y/n) 24 | 2) agrep is record oriented rather than just line oriented; a record 25 | is by default a line, but it can be user defined; 26 | for example, "agrep -d '^From ' 'pizza' mbox" 27 | outputs all mail messages that contain the keyword "pizza". 28 | Another example: "agrep -d '$$' pattern foo" will output all 29 | paragraphs (separated by an empty line) that contain pattern. 30 | 3) multiple patterns with AND (or OR) logic queries. 31 | For example, "agrep -d '^From ' 'burger,pizza' mbox" 32 | outputs all mail messages containing at least one of the 33 | two keywords (, stands for OR). 34 | "agrep -d '^From ' 'good;pizza' mbox" outputs all mail messages 35 | containing both keywords. 36 | 37 | Putting these options together one can ask queries like 38 | 39 | agrep -d '$$' -2 ';TheAuthor;Curriculum;<198[5-9]>' bib 40 | 41 | which outputs all paragraphs referencing articles in CACM between 42 | 1985 and 1989 by TheAuthor dealing with curriculum. 43 | Two errors are allowed, but they cannot be in either CACM or the year 44 | (the <> brackets forbid errors in the pattern between them). 45 | 46 | Other features include searching for regular expressions (with or 47 | without errors), unlimited wild cards, limiting the errors to only 48 | insertions or only substitutions or any combination, 49 | allowing each deletion, for example, to be counted as, say, 50 | 2 substitutions or 3 insertions, restricting parts of the query 51 | to be exact and parts to be approximate, and many more. 52 | 53 | agrep is available by anonymous ftp from cs.arizona.edu (IP 192.12.69.5) 54 | as agrep/agrep-2.04.tar.Z (or in uncompressed form as agrep/agrep-2.04.tar). 55 | The tar file contains the source code (in C), man pages (agrep.1), 56 | and two additional files, agrep.algorithms and agrep.chronicle, 57 | giving more information. 58 | The agrep directory also includes two postscript files: 59 | agrep.ps.1 is a technical report from June 1991 60 | describing the design and implementation of agrep; 61 | agrep.ps.2 is a copy of the paper as appeared in the 1992 62 | Winter USENIX conference. 63 | 64 | Please mail bug reports (or any other comments) 65 | to sw@cs.arizona.edu or to udi@cs.arizona.edu. 66 | 67 | We would appreciate if users notify us (at the address above) 68 | of any extensions, improvements, or interesting uses of this software. 69 | 70 | January 17, 1992 71 | 72 | 73 | BUGS_fixed/option_update 74 | 75 | 1. remove multiple definitions of some global variables. 76 | 2. fix a bug in -G option. 77 | 3. fix a bug in -w option. 78 | January 23, 1992 79 | 80 | 4. fix a bug in pipeline input. 81 | 5. make the definition of word-delimiter consistant. 82 | March 16, 1992 83 | 84 | 6. add option '-y' which, if specified with -B option, will always 85 | output the best-matches without a prompt. 86 | April 10, 1992 87 | 88 | 7. fix a bug regarding exit status. 89 | April 15, 1992 90 | 91 | ------------------------------------------------------------------------------- 92 | REVISIONS TO AGREP, FALL '93 93 | 94 | 8. Options can now be specified in a single group of characters after one '-'. 95 | - Sept 3rd 1993 96 | 97 | 9. Made agrep callable as a library routine from a separate function. The 98 | interface is: memagrep(argc, argv, searchbufferlen, searchbuffer), 99 | the pattern to be searched for and the options being specified EXACTLY as 100 | if they are being specified on the command line. The only difference is 101 | that instead of the file-names to look at, the user should specify a buffer 102 | and its length. Sample user programs are in ../user directory. 103 | 104 | In memagrep(), there are TWO peculiarities: 105 | 1. Peculiarity #1 -- at the end of the buffer, the user must have N bytes 106 | of valid virtual memory, where N is the length of the pattern to be 107 | searched. This space is used by agrep to speed up the checking of the 108 | termination condition. Its contents are restored before memagrep() 109 | returns -- however, some space must be there... else you'll get SIGSEGV. 110 | I might trap segv and do a longjmp, but that'll be in a new version! 111 | 2. The search buffer must begin with a newline so that it is easy for 112 | agrep to output matched lines. This also avoids some copying. 113 | Ofcourse, if we copied the user's search buffer into another buffer which 114 | meets both the above conditions, memagrep() will no longer be fast -- and 115 | speed is the primary goal. 116 | 117 | - Sept 27th 1993 118 | 119 | 10. Added some filter-programs to make agrep search thru compressed files. 120 | Also added some features in the Makefile which allows the user to build 121 | an agrep with a dummyfilter so that agrep remains independent of tcompress. 122 | The definitions needed in agrep to interface with tcompress are in defs.h 123 | 124 | - Nov 10th 1993 125 | 126 | 11. Added a library interface for searching thru a specified set of files, 127 | fileagrep(), which is similar to memagrep(). This is used by glimpse. 128 | Had to modify some other things and fix some bugs (see CHANGES). 129 | 130 | - Dec 1993 (coding), Jan 1993 (debugging). 131 | ------------------------------------------------------------------------------- 132 | 133 | CODING NOTE: sgrep.c and newmgrep.c use a similar while(fill_buf) loop 134 | with start and end, while others use loops with an internal variable i. 135 | -------------------------------------------------------------------------------- /archive/agrep335.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/agrep335.doc -------------------------------------------------------------------------------- /archive/agrepw32.doc: -------------------------------------------------------------------------------- 1 | To: "'gries@ibm.net'" 2 | Subject: Port of agrep to Win95/WinNT 3 | Date: Wed, 31 Dec 1997 10:25:46 -0500 4 | 5 | Hi, 6 | 7 | I recently had need of a version of agrep that ran on Windows NT and I 8 | didn't want to install emx and/or rsx. So I took the source code and 9 | did a quick port to Windows. It now runs natively at the command line 10 | under Windows 95 (very little testing) and Windows NT (NT 4.0 SP3 where 11 | I did the work). I compiled the code using Microsoft VC 5.0. My 12 | changes were minor with the biggest changes being the addition of two 13 | new files (public domain code) that handle the dirent.h type functions 14 | (I called them ntdirent.c and ntdirent.h). I also added function 15 | prototypes to reduce the number of warning messages so I could see the 16 | real problems but I didn't do anything with the numerous signed/unsigned 17 | comparison warnings. I also linked with the Microsoft globbing object 18 | code so file globbing is now taken care of automatically without 19 | resorting to response files. For completeness sake I'll tell you that I 20 | didn't touch the codepage stuff (except to get it to compile) because I 21 | don't need it. 22 | 23 | I'm attaching a zip file of the modified source code. It contains an 24 | agrep executable (compiled without debugging), a makefile (agrep.mak), 25 | and the output of the differences between my version and version 3.33. 26 | 27 | The diff command used to get the diff file was: diff -u -r -new-file 28 | agrep.org agrep.win 29 | The patch command to apply the changes to the original is: patch -N < 30 | agrep.dif 31 | To compile the sources I used: nmake -f agrep.mak (by default this 32 | creates the release version) 33 | 34 | Do with what you will with the changes; I have what I need and don't 35 | have the time to support the code. I'm hoping that you can find some 36 | use from my day's work. 37 | 38 | Good Luck, 39 | David 40 | 41 | 42 | To: "'Tom Gries'" 43 | Subject: RE: Port of agrep to Win95/WinNT 44 | Date: Fri, 2 Jan 1998 17:02:49 -0500 45 | 46 | Tom, 47 | 48 | Attached to this email is my update to your 3.35 sources of agrep. The 49 | changes you made were small so it didn't take too long. 50 | 51 | Included in the zip file is: 52 | (1) a diff of the 3.33 to 3.35 changes (333to335.dif) 53 | (2) a diff of my changes to 3.35 (AgrepWin.dif) 54 | (3) a makefile for Microsoft VC 5.0 (Agrep.mak) 55 | (4) an executable compiled without debugging (Agrep.exe) 56 | 57 | For your information I did a quick compile and some testing using 58 | BoundsChecker from NuMega Software. The only problem it found was on 59 | line 723 of sgrep.c. BoundsChecker complains about an uninitialized 60 | memory access. In the agrep source directory I was using the command: 61 | agrep -r "main" *.* . I don't have time to track it down completely 62 | but I do know that the problem happens during the processing of 63 | codepage.c, It seems to have something to do with a character very high 64 | (or out of) the SHIFT table. Sorry I don't have time right now to look 65 | any further. The good news is that nothing else was found as being a 66 | problem. 67 | 68 | Good Luck, 69 | Dave 70 |  -------------------------------------------------------------------------------- /archive/codepage.rexx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/archive/codepage.rexx -------------------------------------------------------------------------------- /archive/readme.1st: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | README.1ST of AGREP 3.35 for OS/2 and DOS January 4, 1998 3 | ------------------------------------------------------------------------------- 4 | 5 | For the impatient user: 6 | 7 | There are four different executables 8 | 9 | 1. AGREP2.EXE stand-alone executable for OS/2 10 | 11 | You do not need any other files to run AGREP2.EXE 12 | under OS/2. 13 | 14 | 2. AGREPDOS.EXE stand-alone executable for native DOS 15 | 16 | You do not need any other files to run AGREPDOS.EXE 17 | under native DOS. 18 | 19 | For OS/2 users: 20 | AGREPDOS.EXE will also run under OS/2 21 | when it can find EMX.DLL . 22 | 23 | 3. AGREPW32.EXE executable for Windows 95 and Windows NT 24 | 25 | compiled by Dave using Microsoft VC 5.0 26 | 27 | 4. AGREP.EXE executable for DOS, Win-DOS box, OS/2, OS/2-DOS box, 28 | 29 | AGREP.EXE needs additional files depending on 30 | the actual operating system / environment: 31 | 32 | under native DOS ---> it needs EMX.EXE ! 33 | in a DOS box of Win 3.x ---> it needs RSX.EXE ! 34 | under OS/2 ---> it needs EMX.DLL ! 35 | in a DOS box of OS/2 ---> it needs RSX.EXE ! 36 | 37 | Suggested locations for these files: 38 | 39 | EMX.EXE -> c:\emx\bin 40 | RSX.EXE -> c:\rsx\bin 41 | 42 | For OS/2 users: 43 | you can copy EMX.DLL to the system DLLs' location 44 | or to another subdirectory pointed to by LIBPATH. 45 | 46 | Example: 47 | EMX.DLL -> c:\os2\dll (OS/2 system DLLs) 48 | 49 | Make sure, that AGREP*.* can find these pre- 50 | requisites; it tries to find these files via the 51 | PATH and/or using environment variables EMX amd RSX 52 | 53 | SET EMX=c:\emx\bin\emx.exe (full path to emx.exe) 54 | SET RSX=c:\rsx\bin\rsx.exe (full path to rsx.exe) 55 | 56 | ------------------------------------------------------------------------------- 57 | For this compilation for AGREP for OS/2 and DOS and Win95/NT: 58 | ------------------------------------------------------------------------------- 59 | 60 | Mail to: gries@ibm.net Tom Gries 61 | 62 | The Homepage for AGREP for OS/2 and DOS is: 63 | 64 | http://www.geocities.com/SiliconValley/Lakes/4889/agrep.html 65 | 66 | The Homepage for AGREP and GLIMPSE in general is: 67 | 68 | http://glimpse.cs.arizona.edu 69 | 70 | ------------------------------------------------------------------------------- 71 | LEGAL STUFF of AGREP, EMX, RSX 72 | ------------------------------------------------------------------------------- 73 | 74 | In addition to the AGREP executables and source, please note 75 | that the private use is only allowed by respecting the contents 76 | of the following readme files and license/copyright conditions, 77 | under which AGREP is published: 78 | 79 | copying.agrep AGREP copyright notice by Udi Manber and Sun Wu, 80 | University of Arizona 81 | 82 | readme.emx GNU compiler emx 0.9c by Eberhard Mattes 83 | copying.emx 84 | 85 | readme.rsx RSX, the DPMI DOS-extender for EMX programs by Rainer Schnitker 86 | copying.rsx 87 | 88 | copying GNU General Publice License 89 | 90 | =============================================================================== 91 | 92 | ------------------------------------------------------------------------------- 93 | Excerpt README.EMX from emx 0.9c (see file README.EMX for further information) 94 | ------------------------------------------------------------------------------- 95 | 96 | Legal stuff 97 | ----------- 98 | 99 | emx is free software; you can redistribute it and/or modify it 100 | under the terms of the GNU General Public License as published by 101 | the Free Software Foundation; either version 2, or (at your option) 102 | any later version. 103 | 104 | emx is distributed in the hope that it will be useful, 105 | but WITHOUT ANY WARRANTY; without even the implied warranty of 106 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 107 | GNU General Public License for more details. 108 | 109 | You should have received a copy of the GNU General Public License 110 | along with emx; see the file COPYING. If not, write to 111 | the Free Software Foundation, 59 Temple Place - Suite 330, 112 | Boston, MA 02111-1307, USA. 113 | 114 | See \emx\doc\COPYING.EMX and \emx\doc\COPYING for details. 115 | 116 | Instead of a list: All the trademarks used in this document and all 117 | the other emx documents are registered to whoever it is that owns 118 | them. 119 | 120 | 121 | Where to get emx 122 | ---------------- 123 | 124 | emx is available for anonymous ftp on 125 | 126 | ftp.leo.org: /pub/comp/os/os2/leo/gnu/emx+gcc 127 | ftp-os2.cdrom.com: /pub/os2/lang/emx09c 128 | ftp-os2.nmsu.edu: /os2/unix/emx09c 129 | src.doc.ic.ac.uk: /packages/os2/unix/emx09c 130 | 131 | WWW page: 132 | 133 | http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc 134 | 135 | =============================================================================== 136 | 137 | ------------------------------------------------------------------------------- 138 | README.RSX Release: RSX 5.10 (c) Rainer Schnitker Dec 1996 139 | ------------------------------------------------------------------------------- 140 | This program is free software; you can redistribute it and/or modify 141 | it under the terms of the GNU General Public License version 2 as 142 | published by the Free Software Foundation. 143 | ------------------------------------------------------------------------------- 144 | 145 | This is RSX, the DPMI DOS-extender for EMX programs. 146 | 147 | RSX can run the GCC programs under DPMI-servers like MS-Windows 3.x, OS/2 148 | and DOS memory managers like QDPMI or 386Max. Also RSX simulates a missing 149 | 387/487 coprocessor. This version can also run Win32 console programs that 150 | are build with rsxnt. 151 | 152 | RSX510RT.ZIP: rsx 5.10 - runtime binaries and help file 153 | RSX510S.ZIP: rsx 5.10 - source files without binaries 154 | 155 | ------------------------------------------------------------------------------- 156 | 157 | Mail to: rainer@mathematik.uni-bielefeld.de 158 | 159 | Home FTP-server: 160 | ftp: ftp.uni-bielefeld.de 161 | ftp: hermes.hrz.uni-bielefeld.de 162 | dir: /pub/systems/msdos/misc 163 | 164 | ------------------------------------------------------------------------------- 165 | end of README.1ST for AGREP 166 | ------------------------------------------------------------------------------- 167 |  -------------------------------------------------------------------------------- /autoconf.h: -------------------------------------------------------------------------------- 1 | # 2 | -------------------------------------------------------------------------------- /checkfil.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* 4 | * checkfile.c 5 | * takes a file name and checks to see if a file is a regular ascii file 6 | * 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #ifdef __APPLE__ 14 | #include 15 | #endif 16 | #include 17 | #include "checkfil.h" 18 | 19 | #ifdef _WIN32 20 | #include 21 | #include "config.h" 22 | #endif 23 | 24 | #ifndef S_ISREG 25 | #define S_ISREG(mode) (0100000&(mode)) 26 | #endif 27 | 28 | #ifndef S_ISDIR 29 | #define S_ISDIR(mode) (0040000&(mode)) 30 | #endif 31 | 32 | #define MAXLINE 512 33 | 34 | extern char Progname[]; 35 | extern int errno; 36 | 37 | unsigned char ibuf[MAXLINE]; 38 | 39 | /************************************************************************** 40 | * 41 | * check_file 42 | * input: filename or path (null-terminated character string) 43 | * returns: int (0 if file is a regular file, non-0 if not) 44 | * 45 | * uses stat(2) to see if a file is a regular file. 46 | * 47 | ***************************************************************************/ 48 | 49 | int check_file(fname) 50 | char *fname; 51 | 52 | { 53 | struct stat buf; 54 | 55 | if (stat(fname, &buf) != 0) { 56 | if (errno == ENOENT) 57 | return NOSUCHFILE; 58 | else 59 | return STATFAILED; 60 | } 61 | else { 62 | /* 63 | int ftype; 64 | if (S_ISREG(buf.st_mode)) { 65 | if ((ftype = samplefile(fname)) == ISASCIIFILE) { 66 | return ISASCIIFILE; 67 | } else if (ftype == ISBINARYFILE) { 68 | return ISBINARYFILE; 69 | } else if (ftype == OPENFAILED) { 70 | return OPENFAILED; 71 | } 72 | } 73 | if (S_ISDIR(buf.st_mode)) { 74 | return ISDIRECTORY; 75 | } 76 | if (S_ISBLK(buf.st_mode)) { 77 | return ISBLOCKFILE; 78 | } 79 | if (S_ISSOCK(buf.st_mode)) { 80 | return ISSOCKET; 81 | } 82 | */ 83 | return 0; 84 | } 85 | } 86 | 87 | /*************************************************************************** 88 | * 89 | * samplefile 90 | * reads in the first part of a file, and checks to see that it is 91 | * all ascii. 92 | * 93 | ***************************************************************************/ 94 | /* 95 | int samplefile(fname) 96 | char *fname; 97 | { 98 | char *p; 99 | int numread; 100 | int fd; 101 | 102 | if ((fd = open(fname, O_RDONLY)) == -1) { 103 | fprintf(stderr, "open failed on filename %s\n", fname); 104 | return OPENFAILED; 105 | } 106 | 107 | -comment- No need to use alloc_buf and free_buf here since always read from non-ve fd -tnemmoc- 108 | 109 | if (numread = fill_buf(fd, ibuf, MAXLINE)) { 110 | close(fd); 111 | p = ibuf; 112 | while (ISASCII(*p++) && --numread); 113 | if (!numread) { 114 | return(ISASCIIFILE); 115 | } else { 116 | return(ISBINARYFILE); 117 | } 118 | } else { 119 | close(fd); 120 | return(ISASCIIFILE); 121 | } 122 | } 123 | */ 124 | 125 | -------------------------------------------------------------------------------- /checkfil.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | #define NOSUCHFILE -3 3 | #define OPENFAILED -2 4 | #define STATFAILED -1 5 | #define ISASCIIFILE 0 6 | #define ISDIRECTORY 1 7 | #define ISBLOCKFILE 2 8 | #define ISSOCKET 3 9 | #define ISBINARYFILE 4 10 | -------------------------------------------------------------------------------- /checkfile.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* 3 | * checkfile.c 4 | * takes a file name and checks to see if a file is a regular ascii file 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "checkfile.h" 15 | 16 | #ifndef S_ISREG 17 | #define S_ISREG(mode) (0100000&(mode)) 18 | #endif 19 | 20 | #ifndef S_ISDIR 21 | #define S_ISDIR(mode) (0040000&(mode)) 22 | #endif 23 | 24 | #define MAXLINE 512 25 | 26 | extern char Progname[]; 27 | extern int errno; 28 | 29 | unsigned char ibuf[MAXLINE]; 30 | 31 | /************************************************************************** 32 | * 33 | * check_file 34 | * input: filename or path (null-terminated character string) 35 | * returns: int (0 if file is a regular file, non-0 if not) 36 | * 37 | * uses stat(2) to see if a file is a regular file. 38 | * 39 | ***************************************************************************/ 40 | 41 | int check_file(fname) 42 | char *fname; 43 | 44 | { 45 | struct stat buf; 46 | 47 | if (my_stat(fname, &buf) != 0) { 48 | if (errno == ENOENT) 49 | return NOSUCHFILE; 50 | else 51 | return STATFAILED; 52 | } 53 | else { 54 | /* 55 | int ftype; 56 | if (S_ISREG(buf.st_mode)) { 57 | if ((ftype = samplefile(fname)) == ISASCIIFILE) { 58 | return ISASCIIFILE; 59 | } else if (ftype == ISBINARYFILE) { 60 | return ISBINARYFILE; 61 | } else if (ftype == OPENFAILED) { 62 | return OPENFAILED; 63 | } 64 | } 65 | if (S_ISDIR(buf.st_mode)) { 66 | return ISDIRECTORY; 67 | } 68 | if (S_ISBLK(buf.st_mode)) { 69 | return ISBLOCKFILE; 70 | } 71 | if (S_ISSOCK(buf.st_mode)) { 72 | return ISSOCKET; 73 | } 74 | */ 75 | return 0; 76 | } 77 | } 78 | 79 | /*************************************************************************** 80 | * 81 | * samplefile 82 | * reads in the first part of a file, and checks to see that it is 83 | * all ascii. 84 | * 85 | ***************************************************************************/ 86 | /* 87 | int samplefile(fname) 88 | char *fname; 89 | { 90 | char *p; 91 | int numread; 92 | int fd; 93 | 94 | if ((fd = open(fname, O_RDONLY)) == -1) { 95 | fprintf(stderr, "open failed on filename %s\n", fname); 96 | return OPENFAILED; 97 | } 98 | 99 | -comment- No need to use alloc_buf and free_buf here since always read from non-ve fd -tnemmoc- 100 | if (numread = fill_buf(fd, ibuf, MAXLINE)) { 101 | close(fd); 102 | p = ibuf; 103 | while (ISASCII(*p++) && --numread); 104 | if (!numread) { 105 | return(ISASCIIFILE); 106 | } else { 107 | return(ISBINARYFILE); 108 | } 109 | } else { 110 | close(fd); 111 | return(ISASCIIFILE); 112 | } 113 | } 114 | */ 115 | -------------------------------------------------------------------------------- /checkfile.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | #define NOSUCHFILE -3 3 | #define OPENFAILED -2 4 | #define STATFAILED -1 5 | #define ISASCIIFILE 0 6 | #define ISDIRECTORY 1 7 | #define ISBLOCKFILE 2 8 | #define ISSOCKET 3 9 | #define ISBINARYFILE 4 10 | -------------------------------------------------------------------------------- /checksg.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | #include "agrep.h" 4 | #include "checkfil.h" 5 | 6 | /* TG 29.04.04 */ 7 | #include 8 | 9 | extern int errno; 10 | extern CHAR Progname[MAXNAME]; 11 | extern int SGREP, PAT_FILE, PAT_BUFFER, EXITONERROR, SIMPLEPATTERN, 12 | CONSTANT, D, NOUPPER, JUMP, I, LINENUM, INVERSE, WORDBOUND, WHOLELINE, 13 | SILENT, DNA, BESTMATCH; 14 | 15 | /* Make it an interface routine that tells you whether mgrep can be used 16 | for the pattern or not: must sneak and access global variable D though... */ 17 | 18 | int 19 | checksg(Pattern, D, set) 20 | 21 | CHAR *Pattern; 22 | int D; 23 | int set; /* should I set flags SGREP and DNA? not if called from glimpse via library */ 24 | { 25 | char c; 26 | int i, m; 27 | int NOTSGREP = 0; 28 | 29 | if (set) SGREP = OFF; 30 | m = strlen(Pattern); 31 | #if DEBUG 32 | fprintf(stderr, "checksg: len=%d, pat=%s, pat[len]=%d\n", m, Pattern, Pattern[m]); 33 | #endif 34 | if(!(PAT_FILE || PAT_BUFFER) && (m <= D)) { 35 | fprintf(stderr, "%s: size of pattern '%s' must be > #of errors %d\n", Progname, Pattern, D); 36 | if (!EXITONERROR) { 37 | errno = AGREP_ERROR; 38 | return -1; 39 | } 40 | else exit(2); 41 | } 42 | SIMPLEPATTERN = ON; 43 | for (i=0; i < m; i++) 44 | { 45 | switch(Pattern[i]) 46 | { 47 | case ';' : 48 | SIMPLEPATTERN = OFF; 49 | goto outoffor; 50 | case ',' : 51 | SIMPLEPATTERN = OFF; 52 | goto outoffor; 53 | case '.' : 54 | SIMPLEPATTERN = OFF; 55 | goto outoffor; 56 | case '*' : 57 | SIMPLEPATTERN = OFF; 58 | goto outoffor; 59 | case '-' : 60 | SIMPLEPATTERN = OFF; 61 | goto outoffor; 62 | case '[' : 63 | SIMPLEPATTERN = OFF; 64 | goto outoffor; 65 | case ']' : 66 | SIMPLEPATTERN = OFF; 67 | goto outoffor; 68 | case '(' : 69 | SIMPLEPATTERN = OFF; 70 | goto outoffor; 71 | case ')' : 72 | SIMPLEPATTERN = OFF; 73 | goto outoffor; 74 | case '<' : 75 | SIMPLEPATTERN = OFF; 76 | goto outoffor; 77 | case '>' : 78 | SIMPLEPATTERN = OFF; 79 | goto outoffor; 80 | case '^' : 81 | NOTSGREP = 1; 82 | if(D > 0) SIMPLEPATTERN = OFF; 83 | goto outoffor; 84 | case '$' : 85 | NOTSGREP = 1; 86 | if(D > 0) SIMPLEPATTERN = OFF; 87 | goto outoffor; 88 | case '|' : 89 | SIMPLEPATTERN = OFF; 90 | goto outoffor; 91 | case '#' : 92 | SIMPLEPATTERN = OFF; 93 | goto outoffor; 94 | case '{': 95 | SIMPLEPATTERN = OFF; 96 | goto outoffor; 97 | case '}': 98 | SIMPLEPATTERN = OFF; 99 | goto outoffor; 100 | case '~': 101 | SIMPLEPATTERN = OFF; 102 | goto outoffor; 103 | case '\\' : 104 | { /* Should I DO the left shift Pattern including Pattern[m] which is '\0', or just ignore the next character after '\\'????? */ 105 | 106 | if (set) { /* preprocess and maskgen figure out what to do */ 107 | i++; /* in addition to for loop ++ */ 108 | } 109 | else { /* maskgen won't be called if we can help it, so shift it to make it verbatim */ 110 | /* 111 | int j; 112 | for (j=i; j0)) return 0; /* errors, not simple */ 129 | if (NOUPPER && (D>0)) return 0; /* errors, not simple */ 130 | if (JUMP == ON) return 0; /* I, S, D costs, not simple */ 131 | if (I == 0) return 0; /* I has 0 cost not 1, not simple */ 132 | if (LINENUM) return 0; /* can't use mgrep, so not simple */ 133 | if (WORDBOUND && (D > 0)) return 0; /* errors, not simple */ 134 | if (WHOLELINE && (D > 0)) return 0; /* errors, not simple */ 135 | if (SILENT) return 1; /* dont care output, so dont care pat */ 136 | 137 | if (set) { 138 | if (!NOTSGREP || CONSTANT) SGREP = ON; 139 | if (m >= 16) DNA = ON; 140 | for(i=0; i set MUST be on */ 150 | for (i=0; i < m; i++) 151 | { 152 | switch(Pattern[i]) 153 | { 154 | case '\\' : 155 | for (j=i; j 11 | [ini] Mike Thomas 12 | 13 | *******************************************************/ 14 | 15 | #define CODEPGNR 256 /* array index of codepage identification number */ 16 | #define CPSIZE 257 /* 0..255 characters, one codepage identifier */ 17 | #define CODEPAGES 3 /* number of implemented codepages: 437, 850, ISO-8859-1 */ 18 | 19 | struct CODEPAGE_struct 20 | { 21 | 22 | unsigned char lower_1; /* output 1: lowercase characters 23 | - still accented 24 | - still "umlauted" */ 25 | 26 | unsigned char lower_2; /* output 2: lowercase characters 27 | - mapped to the closest 28 | ASCII lowercase character */ 29 | 30 | unsigned char lower_3; /* output 3: type indicator: 31 | 32 | for the control characters < ' ': 33 | 34 | - preserve the code; 35 | for example, CR remains CR 36 | 37 | for characters >= ' ': 38 | 39 | - 'a': all letters are mapped to 'a' 40 | - '1': all digits or what looks like: '1' 41 | - '#': otherwise */ 42 | 43 | int metasymb; /* output 3: 44 | - >0 : character is used as metasymbol 45 | - metasymb[UL850[c].metasymb]=c; 46 | - is not allowed in search pattern 47 | - AGREP.C shows a warning message */ 48 | }; 49 | -------------------------------------------------------------------------------- /compat.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* test the conflicts between options */ 3 | #include 4 | #include "agrep.h" 5 | 6 | /* TG 29.04.04 */ 7 | #include 8 | 9 | extern int D; 10 | extern int FILENAMEONLY, APPROX, PAT_FILE, PAT_BUFFER, MULTI_OUTPUT, COUNT, INVERSE, BESTMATCH; 11 | extern FILEOUT; 12 | extern REGEX; 13 | extern DELIMITER; 14 | extern WHOLELINE; 15 | extern LINENUM; 16 | extern I, S, DD; 17 | extern JUMP; 18 | extern char Progname[32]; 19 | extern int agrep_initialfd; 20 | extern int EXITONERROR; 21 | extern int errno; 22 | 23 | int 24 | compat() 25 | { 26 | if(BESTMATCH) if(COUNT || FILENAMEONLY || APPROX || PAT_FILE) { 27 | BESTMATCH = 0; 28 | fprintf(stderr, "%s: -B option ignored when -c, -l, -f, or -# is on\n", Progname); 29 | } 30 | if (COUNT && LINENUM) { 31 | LINENUM = 0; 32 | fprintf(stderr, "%s: -n option ignored with -c\n", Progname); 33 | } 34 | if(PAT_FILE || PAT_BUFFER) { 35 | if(APPROX && (D > 0)) { 36 | fprintf(stderr, "%s: approximate matching is not supported with -f option\n", Progname); 37 | } 38 | /* 39 | if(INVERSE) { 40 | fprintf(stderr, "%s: -f and -v are not compatible\n", Progname); 41 | if (!EXITONERROR) { 42 | errno = AGREP_ERROR; 43 | return -1; 44 | } 45 | else exit(2); 46 | } 47 | */ 48 | if(LINENUM) { 49 | fprintf(stderr, "%s: -f and -n are not compatible\n", Progname); 50 | if (!EXITONERROR) { 51 | errno = AGREP_ERROR; 52 | return -1; 53 | } 54 | else exit(2); 55 | } 56 | /* 57 | if(DELIMITER) { 58 | fprintf(stderr, "%s: -f and -d are not compatible\n", Progname); 59 | if (!EXITONERROR) { 60 | errno = AGREP_ERROR; 61 | return -1; 62 | } 63 | else exit(2); 64 | } 65 | */ 66 | } 67 | if (MULTI_OUTPUT && LINENUM) { 68 | fprintf(stderr, "%s: -M and -n are not compatible\n", Progname); 69 | if (!EXITONERROR) { 70 | errno = AGREP_ERROR; 71 | return -1; 72 | } 73 | else exit(2); 74 | } 75 | if(JUMP) { 76 | if(REGEX) { 77 | fprintf(stderr, "%s: -D#, -I#, or -S# option is ignored for regular expression pattern\n", Progname); 78 | JUMP = 0; 79 | } 80 | if(I == 0 || S == 0 || DD == 0) { 81 | fprintf(stderr, "%s: the error cost cannot be 0\n", Progname); 82 | if (!EXITONERROR) { 83 | errno = AGREP_ERROR; 84 | return -1; 85 | } 86 | else exit(2); 87 | } 88 | } 89 | if(DELIMITER) { 90 | if(WHOLELINE) { 91 | fprintf(stderr, "%s: -d and -x are not compatible\n", Progname); 92 | if (!EXITONERROR) { 93 | errno = AGREP_ERROR; 94 | return -1; 95 | } 96 | else exit(2); 97 | } 98 | } 99 | if (INVERSE && (PAT_FILE || PAT_BUFFER) && MULTI_OUTPUT) { 100 | fprintf(stderr, "%s: -v and -M are not compatible\n", Progname); 101 | if (!EXITONERROR) { 102 | errno = AGREP_ERROR; 103 | return -1; 104 | } 105 | else exit(2); 106 | } 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* 4 | * Definitions in this file will be visible throughout glimpse source code. 5 | * Any global flags or macros can should be defined here. 6 | */ 7 | 8 | #if defined(__NeXT__) 9 | #define getcwd(buf,size) getwd(buf) /* NB: unchecked target size--could overflow; BG: Ok since buffers are usually >= 256B */ 10 | #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG)) 11 | #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) 12 | #endif 13 | 14 | #ifdef _WIN32 15 | 16 | #ifndef S_ISDIR 17 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 18 | #endif 19 | 20 | #ifndef S_ISREG 21 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 22 | #endif 23 | 24 | #else 25 | 26 | #ifndef S_ISREG 27 | #define S_ISREG(mode) (0100000&(mode)) 28 | #endif 29 | 30 | #ifndef S_ISDIR 31 | #define S_ISDIR(mode) (0040000&(mode)) 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /contribution.list: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | List of people (other than authors) who have contributed to agrep: 3 | 4 | Chunghwa H. Rao 5 | Gene Myers 6 | Ricardo Baeza-Yates 7 | Cliff Hathaway 8 | Ric Anderson 9 | Su-Ing Tsuei 10 | Raphael Finkel 11 | Andrew Hume 12 | David W. Sanderson 13 | William I. Chang 14 | Jack Kirman 15 | Dave Lutz 16 | Tony Plate 17 | Ken Lalonde 18 | Mark Christopher 19 | Dieter Becker 20 | Ian Young 21 | James M. Winget 22 | John F. Stoffel 23 | Thomas Gries 24 | Mike Thomas 25 | crd@hplb.hpl.hp.com 26 | ew@senate.be 27 | Henrik Martin 28 | -------------------------------------------------------------------------------- /defs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* Must be the same as those defined in compress/defs.h */ 3 | #define SIGNATURE_LEN 16 4 | #define TC_LITTLE_ENDIAN 1 5 | #define TC_BIG_ENDIAN 0 6 | #define TC_EASYSEARCH 0x1 7 | #define TC_UNTILNEWLINE 0x2 8 | #define TC_REMOVE 0x4 9 | #define TC_OVERWRITE 0x8 10 | #define TC_RECURSIVE 0x10 11 | #define TC_ERRORMSGS 0x20 12 | #define TC_SILENT 0x40 13 | #define TC_NOPROMPT 0x80 14 | #define TC_FILENAMESONSTDIN 0x100 15 | #define COMP_SUFFIX ".CZ" 16 | #define DEF_FREQ_FILE ".glimpse_quick" 17 | #define DEF_HASH_FILE ".glimpse_compress" 18 | #define DEF_STRING_FILE ".glimpse_uncompress" 19 | -------------------------------------------------------------------------------- /delim.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Burra Gopal, Udi Manber. All Rights Reserved. */ 2 | 3 | #include "agrep.h" 4 | extern int EASYSEARCH, TCOMPRESSED; 5 | 6 | /* Accesses src completely before dest, so that dest can be = src */ 7 | void 8 | preprocess_delimiter(src, srclen, dest, pdestlen) 9 | unsigned char *src, *dest; 10 | int srclen, *pdestlen; 11 | { 12 | CHAR temp[Maxline]; 13 | int i, j; 14 | 15 | strcpy(temp, src); 16 | temp[srclen] = '\0'; 17 | for (i=0, j=0; i end) return -1; 39 | if (TCOMPRESSED == ON) return (exists_tcompressed_word(delim, len, begin, end - begin, EASYSEARCH)); 40 | for (curbegin = begin; curbegin + len <= end; curbegin ++) { 41 | for (curbuf = curbegin, curdelim = delim; curbuf < curbegin + len; curbuf ++, curdelim++) 42 | if (*curbuf != *curdelim) break; 43 | if (curbuf >= curbegin + len) return (curbegin - begin); 44 | } 45 | return -1; 46 | } 47 | 48 | /* return where delimiter begins or ends (=outtail): range = [begin, end) */ 49 | unsigned char * 50 | forward_delimiter(begin, end, delim, len, outtail) 51 | unsigned char *begin, *end, *delim; 52 | int len, outtail; 53 | { 54 | register unsigned char *curbegin, *curbuf, *curdelim; 55 | 56 | if (begin + len > end) return end + 1; 57 | if ((len == 1) && (*delim == '\n')) { 58 | begin ++; 59 | while ((begin < end) && (*begin != '\n')) begin ++; 60 | if (outtail && (*begin == '\n')) begin++; 61 | return begin; 62 | } 63 | if (TCOMPRESSED == ON) return forward_tcompressed_word(begin, end, delim, len, outtail, EASYSEARCH); 64 | for (curbegin = begin; curbegin + len <= end; curbegin ++) { 65 | for (curbuf = curbegin, curdelim = delim; curbuf < curbegin + len; curbuf ++, curdelim++) 66 | if (*curbuf != *curdelim) break; 67 | if (curbuf >= curbegin + len) break; 68 | } 69 | if (!outtail) return (curbegin <= end - len ? curbegin: end + 1); 70 | else return (curbegin <= end - len ? curbegin + len : end + 1); 71 | } 72 | 73 | /* return where the delimiter begins or ends (=outtail): range = [begin, end) */ 74 | unsigned char * 75 | backward_delimiter(end, begin, delim, len, outtail) 76 | unsigned char *end, *begin, *delim; 77 | int len, outtail; 78 | { 79 | register unsigned char *curbegin, *curbuf, *curdelim; 80 | 81 | if (end - len < begin) return begin; 82 | if ((len == 1) && (*delim == '\n')) { 83 | end --; 84 | while ((end > begin) && (*end != '\n')) end --; 85 | if (outtail && (*end == '\n')) end++; 86 | return end; 87 | } 88 | if (TCOMPRESSED == ON) return backward_tcompressed_word(end, begin, delim, len, outtail, EASYSEARCH); 89 | for (curbegin = end-len; curbegin >= begin; curbegin --) { 90 | for (curbuf = curbegin, curdelim = delim; curbuf < curbegin + len; curbuf ++, curdelim++) 91 | if (*curbuf != *curdelim) break; 92 | if (curbuf >= curbegin + len) break; 93 | } 94 | if (!outtail) return (curbegin >= begin ? curbegin : begin); 95 | else return (curbegin >= begin ? curbegin + len : begin); 96 | } 97 | -------------------------------------------------------------------------------- /docs/AGREP_A_FAST_ APPROXIMATE_PATTERN-MATCHING_TOOL_1992_agrep2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/docs/AGREP_A_FAST_ APPROXIMATE_PATTERN-MATCHING_TOOL_1992_agrep2.pdf -------------------------------------------------------------------------------- /docs/FAST_TEXT_ SEARCHING_WITH ERRORS_199106_ agrep1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/docs/FAST_TEXT_ SEARCHING_WITH ERRORS_199106_ agrep1.pdf -------------------------------------------------------------------------------- /docs/GLIMPSE_A_Tool_to_Search_Through_Entire_File_Systems_199310_glimpse.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/docs/GLIMPSE_A_Tool_to_Search_Through_Entire_File_Systems_199310_glimpse.pdf -------------------------------------------------------------------------------- /docs/README: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | This is version 2.04 of agrep - a new tool for fast 3 | text searching allowing errors. 4 | agrep is similar to egrep (or grep or fgrep), but it is much more general 5 | (and usually faster). 6 | The main changes from version 1.1 are 1) incorporating Boyer-Moore 7 | type filtering to speed up search considerably, 2) allowing multi patterns 8 | via the -f option; this is similar to fgrep, but from our experience 9 | agrep is much faster, 3) searching for "best match" without having to 10 | specify the number of errors allowed, and 4) ascii is no longer required. 11 | Several more options were added. 12 | 13 | To compile, simply run make in the agrep directory after untar'ing 14 | the tar file (tar -xf agrep-2.04.tar will do it). 15 | 16 | The three most significant features of agrep that are not supported by 17 | the grep family are 18 | 1) the ability to search for approximate patterns; 19 | for example, "agrep -2 homogenos foo" will find homogeneous as well 20 | as any other word that can be obtained from homogenos with at most 21 | 2 substitutions, insertions, or deletions. 22 | "agrep -B homogenos foo" will generate a message of the form 23 | best match has 2 errors, there are 5 matches, output them? (y/n) 24 | 2) agrep is record oriented rather than just line oriented; a record 25 | is by default a line, but it can be user defined; 26 | for example, "agrep -d '^From ' 'pizza' mbox" 27 | outputs all mail messages that contain the keyword "pizza". 28 | Another example: "agrep -d '$$' pattern foo" will output all 29 | paragraphs (separated by an empty line) that contain pattern. 30 | 3) multiple patterns with AND (or OR) logic queries. 31 | For example, "agrep -d '^From ' 'burger,pizza' mbox" 32 | outputs all mail messages containing at least one of the 33 | two keywords (, stands for OR). 34 | "agrep -d '^From ' 'good;pizza' mbox" outputs all mail messages 35 | containing both keywords. 36 | 37 | Putting these options together one can ask queries like 38 | 39 | agrep -d '$$' -2 ';TheAuthor;Curriculum;<198[5-9]>' bib 40 | 41 | which outputs all paragraphs referencing articles in CACM between 42 | 1985 and 1989 by TheAuthor dealing with curriculum. 43 | Two errors are allowed, but they cannot be in either CACM or the year 44 | (the <> brackets forbid errors in the pattern between them). 45 | 46 | Other features include searching for regular expressions (with or 47 | without errors), unlimited wild cards, limiting the errors to only 48 | insertions or only substitutions or any combination, 49 | allowing each deletion, for example, to be counted as, say, 50 | 2 substitutions or 3 insertions, restricting parts of the query 51 | to be exact and parts to be approximate, and many more. 52 | 53 | agrep is available by anonymous ftp from cs.arizona.edu (IP 192.12.69.5) 54 | as agrep/agrep-2.04.tar.Z (or in uncompressed form as agrep/agrep-2.04.tar). 55 | The tar file contains the source code (in C), man pages (agrep.1), 56 | and two additional files, agrep.algorithms and agrep.chronicle, 57 | giving more information. 58 | The agrep directory also includes two postscript files: 59 | agrep.ps.1 is a technical report from June 1991 60 | describing the design and implementation of agrep; 61 | agrep.ps.2 is a copy of the paper as appeared in the 1992 62 | Winter USENIX conference. 63 | 64 | Please mail bug reports (or any other comments) 65 | to sw@cs.arizona.edu or to udi@cs.arizona.edu. 66 | 67 | We would appreciate if users notify us (at the address above) 68 | of any extensions, improvements, or interesting uses of this software. 69 | 70 | January 17, 1992 71 | 72 | 73 | BUGS_fixed/option_update 74 | 75 | 1. remove multiple definitions of some global variables. 76 | 2. fix a bug in -G option. 77 | 3. fix a bug in -w option. 78 | January 23, 1992 79 | 80 | 4. fix a bug in pipeline input. 81 | 5. make the definition of word-delimiter consistant. 82 | March 16, 1992 83 | 84 | 6. add option '-y' which, if specified with -B option, will always 85 | output the best-matches without a prompt. 86 | April 10, 1992 87 | 88 | 7. fix a bug regarding exit status. 89 | April 15, 1992 90 | 91 | ------------------------------------------------------------------------------- 92 | REVISIONS TO AGREP, FALL '93 93 | 94 | 8. Options can now be specified in a single group of characters after one '-'. 95 | - Sept 3rd 1993 96 | 97 | 9. Made agrep callable as a library routine from a separate function. The 98 | interface is: memagrep(argc, argv, searchbufferlen, searchbuffer), 99 | the pattern to be searched for and the options being specified EXACTLY as 100 | if they are being specified on the command line. The only difference is 101 | that instead of the file-names to look at, the user should specify a buffer 102 | and its length. Sample user programs are in ../user directory. 103 | 104 | In memagrep(), there are TWO peculiarities: 105 | 1. Peculiarity #1 -- at the end of the buffer, the user must have N bytes 106 | of valid virtual memory, where N is the length of the pattern to be 107 | searched. This space is used by agrep to speed up the checking of the 108 | termination condition. Its contents are restored before memagrep() 109 | returns -- however, some space must be there... else you'll get SIGSEGV. 110 | I might trap segv and do a longjmp, but that'll be in a new version! 111 | 2. The search buffer must begin with a newline so that it is easy for 112 | agrep to output matched lines. This also avoids some copying. 113 | Ofcourse, if we copied the user's search buffer into another buffer which 114 | meets both the above conditions, memagrep() will no longer be fast -- and 115 | speed is the primary goal. 116 | 117 | - Sept 27th 1993 118 | 119 | 10. Added some filter-programs to make agrep search thru compressed files. 120 | Also added some features in the Makefile which allows the user to build 121 | an agrep with a dummyfilter so that agrep remains independent of tcompress. 122 | The definitions needed in agrep to interface with tcompress are in defs.h 123 | 124 | - Nov 10th 1993 125 | 126 | 11. Added a library interface for searching thru a specified set of files, 127 | fileagrep(), which is similar to memagrep(). This is used by glimpse. 128 | Had to modify some other things and fix some bugs (see CHANGES). 129 | 130 | - Dec 1993 (coding), Jan 1993 (debugging). 131 | ------------------------------------------------------------------------------- 132 | 133 | CODING NOTE: sgrep.c and newmgrep.c use a similar while(fill_buf) loop 134 | with start and end, while others use loops with an internal variable i. 135 | -------------------------------------------------------------------------------- /docs/agrep-and-glimpse-docs.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/docs/agrep-and-glimpse-docs.zip -------------------------------------------------------------------------------- /dummyfil.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Burra Gopal, Udi Manber. All Rights Reserved. */ 2 | 3 | /* bgopal: used if search in compressed text files is not being performed */ 4 | /* Always say could not be compressed */ 5 | int 6 | quick_tcompress() 7 | { 8 | return 0; 9 | } 10 | 11 | /* Always say could not be uncompressed */ 12 | int 13 | quick_tuncompress() 14 | { 15 | return 0; 16 | } 17 | 18 | /* Always return uncompressible */ 19 | int 20 | tuncompressible() 21 | { 22 | return 0; 23 | } 24 | 25 | /* Always return uncompressible */ 26 | int 27 | tuncompressible_filename() 28 | { 29 | return 0; 30 | } 31 | 32 | /* Always return uncompressible */ 33 | int 34 | tuncompressible_file() 35 | { 36 | return 0; 37 | } 38 | 39 | /* Always return uncompressible */ 40 | int 41 | tuncompressible_fp() 42 | { 43 | return 0; 44 | } 45 | 46 | int 47 | exists_tcompressed_word() 48 | { 49 | return -1; 50 | } 51 | 52 | unsigned char * 53 | forward_tcompressed_word(begin, end, delim, len, outtail, flags) 54 | unsigned char *begin, *end, *delim; 55 | int len, outtail, flags; 56 | { 57 | return begin; 58 | } 59 | 60 | unsigned char * 61 | backward_tcompressed_word(end, begin, delim, len, outtail, flags) 62 | unsigned char *begin, *end, *delim; 63 | int len, outtail, flags; 64 | { 65 | return end; 66 | } 67 | 68 | int 69 | tcompress_file() 70 | { 71 | return 0; 72 | } 73 | 74 | int 75 | tuncompress_file() 76 | { 77 | return 0; 78 | } 79 | 80 | int 81 | initialize_tcompress() 82 | { 83 | return 0; 84 | } 85 | 86 | int 87 | initialize_tuncompress() 88 | { 89 | return 0; 90 | } 91 | 92 | int 93 | initialize_common() 94 | { 95 | return 0; 96 | } 97 | 98 | int 99 | uninitialize_tuncompress() 100 | { 101 | return 0; 102 | } 103 | 104 | int 105 | compute_dictionary() 106 | { 107 | return 0; 108 | } 109 | 110 | int 111 | uninitialize_common() 112 | { 113 | return 0; 114 | } 115 | 116 | int 117 | uninitialize_tcompress() 118 | { 119 | return 0; 120 | } 121 | 122 | int usemalloc = 0; 123 | 124 | int 125 | set_usemalloc() 126 | { 127 | return 0; 128 | } 129 | 130 | int 131 | unset_usemalloc() 132 | { 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /dummyfilters.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Burra Gopal, Udi Manber. All Rights Reserved. */ 2 | 3 | /* bgopal: used if search in compressed text files is not being performed */ 4 | /* Always say could not be compressed */ 5 | int 6 | quick_tcompress() 7 | { 8 | return 0; 9 | } 10 | 11 | /* Always say could not be uncompressed */ 12 | int 13 | quick_tuncompress() 14 | { 15 | return 0; 16 | } 17 | 18 | /* Always return uncompressible */ 19 | int 20 | tuncompressible() 21 | { 22 | return 0; 23 | } 24 | 25 | /* Always return uncompressible */ 26 | int 27 | tuncompressible_filename() 28 | { 29 | return 0; 30 | } 31 | 32 | /* Always return uncompressible */ 33 | int 34 | tuncompressible_file() 35 | { 36 | return 0; 37 | } 38 | 39 | /* Always return uncompressible */ 40 | int 41 | tuncompressible_fp() 42 | { 43 | return 0; 44 | } 45 | 46 | int 47 | exists_tcompressed_word() 48 | { 49 | return -1; 50 | } 51 | 52 | unsigned char * 53 | forward_tcompressed_word(begin, end, delim, len, outtail, flags) 54 | unsigned char *begin, *end, *delim; 55 | int len, outtail, flags; 56 | { 57 | return begin; 58 | } 59 | 60 | unsigned char * 61 | backward_tcompressed_word(end, begin, delim, len, outtail, flags) 62 | unsigned char *begin, *end, *delim; 63 | int len, outtail, flags; 64 | { 65 | return end; 66 | } 67 | 68 | int 69 | tcompress_file() 70 | { 71 | return 0; 72 | } 73 | 74 | int 75 | tuncompress_file() 76 | { 77 | return 0; 78 | } 79 | 80 | int 81 | initialize_tcompress() 82 | { 83 | return 0; 84 | } 85 | 86 | int 87 | initialize_tuncompress() 88 | { 89 | return 0; 90 | } 91 | 92 | int 93 | initialize_common() 94 | { 95 | return 0; 96 | } 97 | 98 | int 99 | uninitialize_tuncompress() 100 | { 101 | return 0; 102 | } 103 | 104 | int 105 | compute_dictionary() 106 | { 107 | return 0; 108 | } 109 | 110 | int 111 | uninitialize_common() 112 | { 113 | return 0; 114 | } 115 | 116 | int 117 | uninitialize_tcompress() 118 | { 119 | return 0; 120 | } 121 | 122 | int usemalloc = 0; 123 | 124 | int 125 | set_usemalloc() 126 | { 127 | return 0; 128 | } 129 | 130 | int 131 | unset_usemalloc() 132 | { 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /dummysyscalls.c: -------------------------------------------------------------------------------- 1 | 2 | /* These functions have been added here so that agrep/cast binaries will work independent of glimpse */ 3 | 4 | int 5 | my_open(name, flags, mode) 6 | char *name; 7 | int flags, mode; 8 | { 9 | return open(name, flags, mode); 10 | } 11 | 12 | FILE * 13 | my_fopen(name, flags) 14 | char *name; 15 | char *flags; 16 | { 17 | return fopen(name, flags); 18 | } 19 | 20 | int 21 | my_lstat(name, buf) 22 | char *name; 23 | struct stat *buf; 24 | { 25 | return lstat(name, buf); 26 | } 27 | 28 | int 29 | my_stat(name, buf) 30 | char *name; 31 | struct stat *buf; 32 | { 33 | return stat(name, buf); 34 | } 35 | 36 | int 37 | special_get_name(name, len, temp) 38 | char *name; 39 | int len; 40 | char *temp; 41 | { 42 | strcpy(temp, name); 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /follow.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* comments changed by TG 09.09.96 */ 4 | 5 | /* the functions in this file take a syntax tree for a regular 6 | expression and produce a DFA using the McNaughton-Yamada 7 | construction. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #ifndef _WIN32 13 | #include 14 | #endif 15 | #include "re.h" 16 | 17 | #define TRUE 1 18 | 19 | extern Pset pset_union(Pset s1, Pset s2, int dontreplicate); 20 | extern int pos_cnt; 21 | extern Re_node parse(char *s); 22 | 23 | Re_lit_array lpos; 24 | 25 | 26 | /* extend_re() extends the RE by adding a ".*(" at the front and a ")" 27 | at the back. */ 28 | 29 | char *extend_re(s) 30 | char *s; 31 | { 32 | char *s1; 33 | 34 | s1 = malloc((unsigned) strlen(s)+4+1); 35 | return strcat(strcat(strcpy(s1, ".*("), s), ")"); 36 | } 37 | 38 | void free_pos(fpos, pos_cnt) 39 | Pset_array fpos; 40 | int pos_cnt; 41 | { 42 | Pset tpos, pos; 43 | int i; 44 | 45 | if ((fpos == NULL) || (*fpos == NULL)) return; 46 | for (i=0; inextpos; 51 | free(tpos); 52 | } 53 | } 54 | free(fpos); 55 | } 56 | 57 | /* Function to clear out a Ch_Set */ 58 | void free_cset(cset) 59 | Ch_Set cset; 60 | { 61 | Ch_Set tset; 62 | 63 | while (cset != NULL) { 64 | tset = cset; 65 | cset = cset->rest; 66 | free(tset->elt); 67 | free(tset); 68 | } 69 | } 70 | 71 | /* Function to clear out the tree of re-nodes */ 72 | void free_re(e) 73 | Re_node e; 74 | { 75 | if (e == NULL) return; 76 | 77 | /* 78 | * Was creating "reading freed memory", "freeing unallocated/freed memory" 79 | * errors. So abandoned it. Leaks are now up by 60B/call to 80B/call 80 | * -bg 81 | * 82 | { 83 | Pset tpos, pos; 84 | int tofree = 0; 85 | 86 | if ((Lastpos(e)) != (Firstpos(e))) tofree = 1; 87 | pos = Lastpos(e); 88 | while (pos != NULL) { 89 | tpos = pos; 90 | pos = pos->nextpos; 91 | free(tpos); 92 | } 93 | Lastpos(e) = NULL; 94 | 95 | if (tofree) { 96 | pos = Firstpos(e); 97 | while (pos != NULL) { 98 | tpos = pos; 99 | pos = pos->nextpos; 100 | free(tpos); 101 | } 102 | Firstpos(e) = NULL; 103 | } 104 | } 105 | */ 106 | 107 | switch (Op(e)) { 108 | case EOS: 109 | if (lit_type(Lit(e)) == C_SET) free_cset(lit_cset(Lit(e))); 110 | free(Lit(e)); 111 | break; 112 | case OPSTAR: 113 | free_re(Child(e)); 114 | break; 115 | case OPCAT: 116 | free_re(Lchild(e)); 117 | free_re(Rchild(e)); 118 | break; 119 | case OPOPT: 120 | free_re(Child(e)); 121 | break; 122 | case OPALT: 123 | free_re(Lchild(e)); 124 | free_re(Rchild(e)); 125 | break; 126 | case LITERAL: 127 | if (lit_type(Lit(e)) == C_SET) free_cset(lit_cset(Lit(e))); 128 | free(Lit(e)); 129 | break; 130 | default: 131 | fprintf(stderr, "free_re: unknown node type %d\n", Op(e)); 132 | } 133 | free(e); 134 | return; 135 | } 136 | 137 | 138 | /* mk_followpos() takes a syntax tree for a regular expression and 139 | traverses it once, computing the followpos function at each node 140 | and returns a pointer to an array whose ith element is a pointer 141 | to a list of position nodes, representing the positions in 142 | followpos(i). */ 143 | 144 | void mk_followpos_1(e, fpos) 145 | Re_node e; 146 | Pset_array fpos; 147 | { 148 | Pset pos; 149 | int i; 150 | 151 | switch (Op(e)) { 152 | case EOS: 153 | break; 154 | case OPSTAR: 155 | pos = Lastpos(e); 156 | while (pos != NULL) { 157 | i = pos->posnum; 158 | (*fpos)[i] = pset_union(Firstpos(e), (*fpos)[i], 0); 159 | pos = pos->nextpos; 160 | } 161 | mk_followpos_1(Child(e), fpos); 162 | break; 163 | case OPCAT: 164 | pos = Lastpos(Lchild(e)); 165 | while (pos != NULL) { 166 | i = pos->posnum; 167 | (*fpos)[i] = pset_union(Firstpos(Rchild(e)), (*fpos)[i], 0); 168 | pos = pos->nextpos; 169 | } 170 | mk_followpos_1(Lchild(e), fpos); 171 | mk_followpos_1(Rchild(e), fpos); 172 | break; 173 | case OPOPT: 174 | mk_followpos_1(Child(e), fpos); 175 | break; 176 | case OPALT: 177 | mk_followpos_1(Lchild(e), fpos); 178 | mk_followpos_1(Rchild(e), fpos); 179 | break; 180 | case LITERAL: 181 | break; 182 | default: 183 | fprintf(stderr, "mk_followpos: unknown node type %d\n", Op(e)); 184 | } 185 | return; 186 | } 187 | 188 | Pset_array mk_followpos(tree, npos) 189 | Re_node tree; 190 | int npos; 191 | { 192 | int i; 193 | Pset_array fpos; 194 | 195 | if (tree == NULL || npos < 0) return NULL; 196 | fpos = (Pset_array) malloc((unsigned) (npos+1)*sizeof(Pset)); 197 | if (fpos == NULL) return NULL; 198 | for (i = 0; i <= npos; i++) (*fpos)[i] = NULL; 199 | mk_followpos_1(tree, fpos); 200 | return fpos; 201 | } 202 | 203 | /* mk_poslist() sets a static array whose i_th element is a pointer to 204 | the RE-literal at position i. It returns 1 if everything is OK, 0 205 | otherwise. */ 206 | 207 | /* init performs initialization actions; it returns -1 in case of error, 208 | 0 if everything goes OK. */ 209 | 210 | int init(s, table) 211 | char *s; 212 | int table[32][32]; 213 | { 214 | Pset_array fpos; 215 | Re_node e; 216 | Pset l; 217 | int i, j; 218 | char *s1; 219 | 220 | if ((s1 = extend_re(s)) == NULL) return -1; 221 | 222 | if ((e = parse(s1)) == NULL) { 223 | free(s1); 224 | return -1; 225 | } 226 | 227 | free(s1); 228 | if ((fpos = mk_followpos(e, pos_cnt)) == NULL) { 229 | free_re(e); 230 | return -1; 231 | } 232 | for (i = 0; i <= pos_cnt; i += 1) { 233 | #ifdef Debug 234 | printf("followpos[%d] = ", i); 235 | #endif 236 | l = (*fpos)[i]; 237 | j = 0; 238 | for ( ; l != NULL; l = l->nextpos) { 239 | #ifdef Debug 240 | printf("%d ", l->posnum); 241 | #endif 242 | table[i][j] = l->posnum; 243 | j++; 244 | } 245 | #ifdef Debug 246 | printf("\n"); 247 | #endif 248 | } 249 | #ifdef Debug 250 | for (i=0; i <= pos_cnt; i += 1) { 251 | j = 0; 252 | while (table[i][j] != 0) { 253 | printf(" %d ", table[i][j]); 254 | j++; 255 | } 256 | printf("\n"); 257 | } 258 | #endif 259 | free_pos(fpos, pos_cnt); 260 | free_re(e); 261 | return (pos_cnt); 262 | } 263 | -------------------------------------------------------------------------------- /installation/Makefile.NeXT: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On IRIX, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = /bin/ar 7 | RANLIB = /bin/ranlib 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 0 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = gcc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.NeXT CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.alpha: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On Solaris, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = ar #/usr/ccs/bin/ar #for Solaris 7 | RANLIB = ranlib #true #for Solaris 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = cc #gcc -traditional #cc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O -Olimit 3000 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.alpha CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.hp: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On Solaris, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = ar #/usr/ccs/bin/ar #for Solaris 7 | RANLIB = : 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 0 11 | HAVE_SYS_DIR_H = 1 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = cc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.hp CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | srcdir = @srcdir@ 4 | VPATH = @srcdir@ 5 | SHELL = /bin/sh 6 | CC = @CC@ 7 | AR = @AR@ 8 | RANLIB = @RANLIB@ 9 | CP = @CP@ 10 | STRIP = @STRIP@ 11 | INSTALL = @INSTALL@ 12 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 13 | INSTALL_DATA = @INSTALL_DATA@ 14 | INSTALL_MAN = ${INSTALL} -m 444 15 | DEFS = 16 | 17 | prefix = @prefix@ 18 | exec_prefix = @exec_prefix@ 19 | binprefix = 20 | manprefix = 21 | 22 | bindir = $(exec_prefix)/bin 23 | libdir = $(exec_prefix)/lib 24 | mandir = $(prefix)/man/man1 25 | manext = 1 26 | 27 | MAN1 = agrep.1 28 | 29 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 30 | 31 | # The binaries will be made in ../bin/. and the agrep library in ../lib 32 | # You normally don't have to change them. 33 | BINDIR = ../bin 34 | LIBDIR = ../lib 35 | TCOMP = cast 36 | TCOMPDIR = ../compress 37 | AGREPDIR = ../agrep 38 | TEMPLATEDIR = ../libtemplate 39 | 40 | # You can change the target to use the "cast" (compression) library by changing: 41 | # all: $(NOTCPROG) 42 | # to: 43 | # all: $(PROG) 44 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 45 | 46 | DOTCOMPRESSED = 0 47 | 48 | OPTIMIZEFLAGS = -O2 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | 51 | # AGREP_POINTER is defined in autoconf.h 52 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 53 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(DEFS) 54 | LDFLAGS = 55 | OTHERLIBS = 56 | 57 | PROG = agrep 58 | NOTCPROG = notc$(PROG) 59 | LIB = $(LIBDIR)/lib$(PROG).a 60 | 61 | all: $(LIB) $(NOTCPROG) 62 | 63 | install: all install-man 64 | $(INSTALL) $(PROG) $(bindir) 65 | 66 | install-man: $(MAN1) 67 | $(INSTALL_MAN) $(MAN1) $(mandir) 68 | 69 | clean: 70 | rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 71 | 72 | distclean: clean 73 | rm -f Makefile 74 | 75 | HDRS = agrep.h checkfile.h re.h defs.h config.h 76 | TCOMPLIBOBJ = \ 77 | $(TCOMPDIR)/hash.o \ 78 | $(TCOMPDIR)/string.o \ 79 | $(TCOMPDIR)/misc.o \ 80 | $(TCOMPDIR)/quick.o \ 81 | $(TCOMPDIR)/cast.o \ 82 | $(TCOMPDIR)/uncast.o \ 83 | $(TCOMPDIR)/tsimpletest.o \ 84 | $(TCOMPDIR)/tbuild.o\ 85 | $(TCOMPDIR)/tmemlook.o 86 | OBJS = \ 87 | follow.o \ 88 | asearch.o \ 89 | asearch1.o \ 90 | agrep.o \ 91 | bitap.o \ 92 | checkfile.o \ 93 | compat.o \ 94 | maskgen.o \ 95 | parse.o \ 96 | checksg.o \ 97 | preprocess.o \ 98 | delim.o \ 99 | asplit.o \ 100 | recursive.o \ 101 | sgrep.o \ 102 | newmgrep.o \ 103 | utilities.o 104 | 105 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 106 | $(CC) -L$(LIBDIR) $(LDFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 107 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 108 | $(RANLIB) $(LIB) 109 | 110 | $(LIBDIR)/lib$(TCOMP).a: 111 | cd $(TCOMPDIR) ; $(MAKE) 112 | 113 | $(LIB): $(OBJS) dummyfilters.o 114 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 115 | $(RANLIB) $(LIB) 116 | 117 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 118 | $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 119 | 120 | compat.o: agrep.h defs.h config.h 121 | asearch.o: agrep.h defs.h config.h 122 | asearch1.o: agrep.h defs.h config.h 123 | bitap.o: agrep.h defs.h config.h 124 | checkfile.o: agrep.h checkfile.h defs.h config.h 125 | follow.o: re.h agrep.h defs.h config.h 126 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 127 | agrep.o: agrep.h checkfile.h defs.h config.h 128 | newmgrep.o: agrep.h defs.h config.h 129 | maskgen.o: agrep.h defs.h config.h 130 | next.o: agrep.h defs.h config.h 131 | parse.o: re.h agrep.h defs.h config.h 132 | preprocess.o: agrep.h defs.h config.h 133 | checksg.o: agrep.h checkfile.h defs.h config.h 134 | delim.o: agrep.h defs.h config.h 135 | asplit.o: agrep.h defs.h config.h 136 | sgrep.o: agrep.h defs.h config.h 137 | abm.o: agrep.h defs.h config.h 138 | utilities.o: re.h agrep.h defs.h config.h 139 | dummyfilters.o: dummyfilters.c 140 | -------------------------------------------------------------------------------- /installation/Makefile.linux.old: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On Solaris, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = ar #/usr/ccs/bin/ar #for Solaris 7 | RANLIB = ranlib #true #for Solaris 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = gcc -m486 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O2 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.linux CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.os2: -------------------------------------------------------------------------------- 1 | # 2 | # agrepos2.mk 3 | # Makefile for the OS/2-only version of AGREP 4 | # 5 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 6 | # 7 | 8 | # The switches -Zomf and -Zsys are sufficient to create an 9 | # OS/2-only stand-alone executable, which does not need EMX.DLL 10 | # 11 | # This is the PURE-OS/2 solution. 12 | # 13 | CC = gcc -ansi -O3 14 | 15 | # --------------------------------------------------------------------- 16 | # Define HAVE_DIRENT_H to be 1 when you don't have 17 | # else define it to be 0 (in this case, one of the other 3 flags 18 | # may need to be defined to be 1). 19 | # --------------------------------------------------------------------- 20 | 21 | HAVE_DIRENT_H = 1 22 | HAVE_SYS_DIR_H = 0 23 | HAVE_SYS_NDIR_H = 0 24 | HAVE_NDIR_H = 0 25 | 26 | # --------------------------------------------------------------------- 27 | # Define UTIME to be 1 if you have the utime() routine on your system. 28 | # Else define it to be 0. 29 | # --------------------------------------------------------------------- 30 | 31 | UTIME = 1 32 | 33 | # --------------------------------------------------------------------- 34 | # Define codepage_SET to be 1 if you want to use the international 35 | # 8bit character set. Else define it to be 0. 36 | # --------------------------------------------------------------------- 37 | # This switch has not been introduced by me ! [TG] 05.10.96 38 | 39 | ISO_CHAR_SET = 1 40 | 41 | OPTIMIZEFLAGS = -O3 42 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) \ 43 | -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) \ 44 | -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) \ 45 | -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 46 | -DUTIME=$(UTIME) \ 47 | -DISO_CHAR_SET=$(ISO_CHAR_SET) \ 48 | -DS_IFLNK=-1 \ 49 | -Dlstat=stat 50 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) 51 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 \ 52 | -DAGREP_POINTER=1 \ 53 | -DDOTCOMPRESSED=0 \ 54 | -D__OS2=1 55 | CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) 56 | OTHERLIBS = 57 | 58 | PROG = agrep 59 | 60 | HDRS = agrep.h checkfil.h re.h defs.h config.h codepage.h version.h 61 | 62 | OBJS = follow.o \ 63 | asearch.o \ 64 | asearch1.o \ 65 | agrep.o \ 66 | bitap.o \ 67 | checkfil.o \ 68 | compat.o \ 69 | dummyfil.o \ 70 | main.o \ 71 | maskgen.o \ 72 | parse.o \ 73 | checksg.o \ 74 | preproce.o \ 75 | delim.o \ 76 | asplit.o \ 77 | recursiv.o \ 78 | sgrep.o \ 79 | newmgrep.o \ 80 | utilitie.o \ 81 | codepage.o \ 82 | agrephlp.o 83 | 84 | $(PROG): $(OBJS) $(HDRS) 85 | $(CC) -o $(PROG) $(OBJS) 86 | 87 | clean: 88 | -del *.o 89 | -del $(PROG) 90 | 91 | # The header file config.h should be visible in the whole source code 92 | # Apparently, it is not at the moment. [TG] 28.09.96 93 | 94 | compat.o: agrep.h defs.h config.h 95 | asearch.o: agrep.h defs.h config.h 96 | asearch1.o: agrep.h defs.h config.h 97 | bitap.o: agrep.h defs.h config.h codepage.h 98 | checkfil.o: agrep.h checkfil.h defs.h config.h 99 | follow.o: re.h agrep.h defs.h config.h 100 | main.o: agrep.h checkfil.h defs.h config.h 101 | agrep.o: agrep.h checkfil.h defs.h config.h version.h codepage.h 102 | agrephlp.o: version.h config.h 103 | newmgrep.o: agrep.h defs.h config.h codepage.h 104 | maskgen.o: agrep.h defs.h config.h codepage.h 105 | next.o: agrep.h defs.h config.h 106 | parse.o: re.h agrep.h defs.h config.h 107 | preproce.o: agrep.h defs.h config.h 108 | checksg.o: agrep.h checkfil.h defs.h config.h 109 | delim.o: agrep.h defs.h config.h 110 | asplit.o: agrep.h defs.h config.h 111 | sgrep.o: agrep.h defs.h config.h codepage.h 112 | abm.o: agrep.h defs.h config.h 113 | utilitie.o: re.h agrep.h defs.h config.h 114 | dummyfil.o: config.h 115 | codepage.o: codepage.h config.h agrep.h 116 | -------------------------------------------------------------------------------- /installation/Makefile.rs6000: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On IRIX, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = /usr/bin/ar 7 | RANLIB = true #for IRIX 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = cc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.rs6000 CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.sgi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On IRIX, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = /usr/bin/ar 7 | RANLIB = true #for IRIX 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = cc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.sgi CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.solaris: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On Solaris, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = /usr/ccs/bin/ar #for Solaris 7 | RANLIB = true #for Solaris 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = gcc -traditional #cc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.solaris CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/Makefile.sunos: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 2 | 3 | # You might have to change these depending on your machine configuration. 4 | # AR and RANLIB are the library-archive programs. On Solaris, RANLIB is not 5 | # required (define it to true) and AR is in /usr/ccs/bin/ar (on our machine!). 6 | AR = ar #/usr/ccs/bin/ar #for Solaris 7 | RANLIB = ranlib #true #for Solaris 8 | 9 | # Define HAVE_DIRENT_H to be 1 when you don't have else define it to be 0 (in this case, one of the other 3 flags may need to be defined to be 1). 10 | HAVE_DIRENT_H = 1 11 | HAVE_SYS_DIR_H = 0 12 | HAVE_SYS_NDIR_H = 0 13 | HAVE_NDIR_H = 0 14 | 15 | # Define UTIME to be 1 if you have the utime() routine on your system. Else define it to be 0. 16 | UTIME = 1 17 | 18 | # Define ISO_CHAR_SET to be 1 if you want to use the international 8bit character set. Else define it to be 0. 19 | ISO_CHAR_SET = 0 20 | 21 | # You might have to change this depending on your machine configuration. 22 | CC = gcc 23 | 24 | SHELL = /bin/sh 25 | 26 | # YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE 27 | 28 | # The binaries will be made in ../bin/. and the agrep library in ../lib 29 | # You normally don't have to change them. 30 | BINDIR = ../bin 31 | LIBDIR = ../lib 32 | TCOMP = cast 33 | TCOMPDIR = ../compress 34 | AGREPDIR = ../agrep 35 | TEMPLATEDIR = ../libtemplate 36 | 37 | # You can change the target to use the "cast" (compression) library by changing: 38 | # all: $(NOTCPROG) 39 | # to: 40 | # all: $(PROG) 41 | # You must also define DOTCOMPRESSED below to be 1 instead of 0. 42 | 43 | DOTCOMPRESSED = 0 44 | 45 | # Include flags is not a part of CLFAGS and LINKFLAGS since path names from subdirs can be different 46 | OPTIMIZEFLAGS = -O 47 | #PROFILEFLAGS = -p 48 | #DEBUGFLAGS = -g -DBG_DEBUG=1 -DDEBUG=1 49 | INCLUDEFLAGS = -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 50 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 51 | -DUTIME=$(UTIME) -DISO_CHAR_SET=$(ISO_CHAR_SET) 52 | SUBDIRCFLAGS = -c $(DEFINEFLAGS) $(OPTIMIZEFLAGS) $(PROFILEFLAGS) $(DEBUGFLAGS) 53 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 -DAGREP_POINTER=1 -DDOTCOMPRESSED=$(DOTCOMPRESSED) 54 | CFLAGS = $(MYDEFINEFLAGS) $(INCLUDEFLAGS) $(SUBDIRCFLAGS) 55 | SUBDIRLINKFLAGS = $(PROFILEFLAGS) 56 | LINKFLAGS = $(INCLUDEFLAGS) $(SUBDIRLINKFLAGS) 57 | OTHERLIBS = 58 | 59 | PROG = agrep 60 | NOTCPROG = notc$(PROG) 61 | 62 | all: $(NOTCPROG) 63 | cp $(PROG) $(BINDIR)/. 64 | 65 | LIB = $(LIBDIR)/lib$(PROG).a 66 | HDRS = agrep.h checkfile.h re.h defs.h config.h 67 | TCOMPLIBOBJ = \ 68 | $(TCOMPDIR)/hash.o \ 69 | $(TCOMPDIR)/string.o \ 70 | $(TCOMPDIR)/misc.o \ 71 | $(TCOMPDIR)/quick.o \ 72 | $(TCOMPDIR)/cast.o \ 73 | $(TCOMPDIR)/uncast.o \ 74 | $(TCOMPDIR)/tsimpletest.o \ 75 | $(TCOMPDIR)/tbuild.o\ 76 | $(TCOMPDIR)/tmemlook.o 77 | OBJS = \ 78 | follow.o \ 79 | asearch.o \ 80 | asearch1.o \ 81 | agrep.o \ 82 | bitap.o \ 83 | checkfile.o \ 84 | compat.o \ 85 | maskgen.o \ 86 | parse.o \ 87 | checksg.o \ 88 | preprocess.o \ 89 | delim.o \ 90 | asplit.o \ 91 | recursive.o \ 92 | sgrep.o \ 93 | newmgrep.o \ 94 | utilities.o 95 | 96 | $(PROG): $(OBJS) main.o $(LIBDIR)/lib$(TCOMP).a 97 | $(CC) -L$(LIBDIR) $(LINKFLAGS) -o $@ $(OBJS) main.o -l$(TCOMP) $(OTHERLIBS) 98 | $(AR) rcv $(LIB) $(OBJS) $(TCOMPLIBOBJ) 99 | $(RANLIB) $(LIB) 100 | 101 | $(LIBDIR)/lib$(TCOMP).a: 102 | cd $(TCOMPDIR) ; $(MAKE) -f Makefile.sunos CC="$(CC)" SUBDIRCFLAGS="$(SUBDIRCFLAGS)" SUBDIRLINKFLAGS="$(SUBDIRLINKFLAGS)" SHELL="$(SHELL)" HAVE_DIRENT_H="$(HAVE_DIRENT_H)" HAVE_SYS_DIR_H="$(HAVE_SYS_DIR_H)" HAVE_SYS_NDIR_H="$(HAVE_SYS_NDIR_H)" HAVE_NDIR_H="$(HAVE_NDIR_H)" UTIME="$(UTIME)" STRUCTURED_QUERIES="$(STRUCTURED_QUERIES)" ISO_CHAR_SET="$(ISO_CHAR_SET)" SFS_COMPAT="$(SFS_COMPAT)" 103 | 104 | $(NOTCPROG): $(OBJS) dummyfilters.o main.o 105 | $(CC) $(LINKFLAGS) -o $(PROG) $(OBJS) dummyfilters.o main.o $(OTHERLIBS) 106 | $(AR) rcv $(LIB) $(OBJS) dummyfilters.o 107 | $(RANLIB) $(LIB) 108 | 109 | clean: 110 | -rm -f $(LIB) $(OBJS) dummyfilters.o main.o core a.out $(PROG) 111 | 112 | compat.o: agrep.h defs.h config.h 113 | asearch.o: agrep.h defs.h config.h 114 | asearch1.o: agrep.h defs.h config.h 115 | bitap.o: agrep.h defs.h config.h 116 | checkfile.o: agrep.h checkfile.h defs.h config.h 117 | follow.o: re.h agrep.h defs.h config.h 118 | main.o: agrep.h checkfile.h defs.h config.h dummysyscalls.c 119 | agrep.o: agrep.h checkfile.h defs.h config.h 120 | newmgrep.o: agrep.h defs.h config.h 121 | maskgen.o: agrep.h defs.h config.h 122 | next.o: agrep.h defs.h config.h 123 | parse.o: re.h agrep.h defs.h config.h 124 | preprocess.o: agrep.h defs.h config.h 125 | checksg.o: agrep.h checkfile.h defs.h config.h 126 | delim.o: agrep.h defs.h config.h 127 | asplit.o: agrep.h defs.h config.h 128 | sgrep.o: agrep.h defs.h config.h 129 | abm.o: agrep.h defs.h config.h 130 | utilities.o: re.h agrep.h defs.h config.h 131 | dummyfilters.o: dummyfilters.c 132 | -------------------------------------------------------------------------------- /installation/README: -------------------------------------------------------------------------------- 1 | Older makefiles not use and not maintained anymore 2 | T. Gries 20130217 3 | -------------------------------------------------------------------------------- /installation/agrepgdb.mk: -------------------------------------------------------------------------------- 1 | # 2 | # agrepos2.mk 3 | # Makefile for the OS/2-only version of AGREP 4 | # 5 | # creates AGREP2.EXE for OS/2 6 | # does not need any other EXE or DLL 7 | # 8 | # Operatingsystem | OS/2 | DOS | Win 3.x | 9 | # |------------------------|--------------|-----------------------| 10 | # | native | DOS-Box | native | DOS-Box | GUI | 11 | # | AGREP2.EXE | - | - | - | - | 12 | # 13 | # If you are running DOS or Windows, 14 | # and/or if you want to run AGREP in a DOS-Window of OS/2, 15 | # compile and link with 16 | # 17 | # agrepdos.mk 18 | # 19 | # to create an executable 20 | # 21 | # AGREP.EXE 22 | # 23 | # which DOES need RSX.EXE (see table) when running under a 24 | # DPMI server (himem.sys+emm386, 386max, or qemm386) 25 | # 26 | # | | | | | | 27 | # | AGREP.EXE | AGREP.EXE | AGREP.EXE | AGREP.EXE | not impl.| | 28 | # prerequisites: | | + RSX.EXE | | + RSX.EXE | | 29 | # | | (note 1) | | 30 | # 31 | # NOTE: 32 | # 33 | # The AGREP.EXE tries to locate RSX.EXE via the environment variable RSX. 34 | # When you have put the RSX.EXE into the subdirectory c:\rsx\bin\rsx.exe then use 35 | # 36 | # SET RSX=C:\RSX\BIN\RSX.EXE 37 | # 38 | # in your AUTOEXEC.BAT. 39 | # 40 | # 41 | # Adapted for the emx compiler by Tom Gries 42 | # 02.03.97 43 | # 44 | # on the basis of an original: 45 | # Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. 46 | # 47 | 48 | # The switches -Zomf and -Zsys are sufficient to create an 49 | # OS/2-only stand-alone executable, which does not need EMX.DLL 50 | # 51 | # This is the PURE-OS/2 solution. 52 | # 53 | #CC = gcc -Zomf -Zsys -ansi -O3 54 | 55 | CC = gcc -ansi 56 | 57 | # 58 | #CC = gcc -ansi -O3 59 | # 60 | 61 | # --------------------------------------------------------------------- 62 | # Define HAVE_DIRENT_H to be 1 when you don't have 63 | # else define it to be 0 (in this case, one of the other 3 flags 64 | # may need to be defined to be 1). 65 | # --------------------------------------------------------------------- 66 | 67 | HAVE_DIRENT_H = 1 68 | HAVE_SYS_DIR_H = 0 69 | HAVE_SYS_NDIR_H = 0 70 | HAVE_NDIR_H = 0 71 | 72 | # --------------------------------------------------------------------- 73 | # Define UTIME to be 1 if you have the utime() routine on your system. 74 | # Else define it to be 0. 75 | # --------------------------------------------------------------------- 76 | 77 | UTIME = 1 78 | 79 | # --------------------------------------------------------------------- 80 | # Define codepage_SET to be 1 if you want to use the international 81 | # 8bit character set. Else define it to be 0. 82 | # --------------------------------------------------------------------- 83 | # This switch has not been introduced by me ! [TG] 05.10.96 84 | 85 | ISO_CHAR_SET = 1 86 | 87 | ###### OPTIMIZEFLAGS = -O3 88 | 89 | DEFINEFLAGS = -DHAVE_DIRENT_H=$(HAVE_DIRENT_H) \ 90 | -DHAVE_SYS_DIR_H=$(HAVE_SYS_DIR_H) \ 91 | -DHAVE_SYS_NDIR_H=$(HAVE_SYS_NDIR_H) \ 92 | -DHAVE_NDIR_H=$(HAVE_NDIR_H) \ 93 | -DUTIME=$(UTIME) \ 94 | -DISO_CHAR_SET=$(ISO_CHAR_SET) \ 95 | -DS_IFLNK=-1 \ 96 | -Dlstat=stat 97 | SUBDIRCFLAGS = -g -c -fbounds-checking $(DEFINEFLAGS) $(OPTIMIZEFLAGS) 98 | MYDEFINEFLAGS = -DMEASURE_TIMES=0 \ 99 | -DAGREP_POINTER=1 \ 100 | -DDOTCOMPRESSED=0 \ 101 | -D__OS2=1 102 | CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) 103 | OTHERLIBS = 104 | 105 | PROG = agrep2 106 | 107 | HDRS = agrep.h checkfil.h re.h defs.h config.h codepage.h version.h 108 | 109 | OBJS = follow.o \ 110 | asearch.o \ 111 | asearch1.o \ 112 | agrep.o \ 113 | bitap.o \ 114 | checkfil.o \ 115 | compat.o \ 116 | dummyfil.o \ 117 | main.o \ 118 | maskgen.o \ 119 | parse.o \ 120 | checksg.o \ 121 | preproce.o \ 122 | delim.o \ 123 | asplit.o \ 124 | recursiv.o \ 125 | sgrep.o \ 126 | newmgrep.o \ 127 | utilitie.o \ 128 | codepage.o \ 129 | agrephlp.o 130 | 131 | # not use any longer io.o 132 | 133 | $(PROG).EXE: $(OBJS) 134 | $(CC) -fbounds-checking -o $(PROG).EXE $(OBJS) 135 | 136 | clean: 137 | -del *.o 138 | -del $(PROG).EXE 139 | 140 | # The header file config.h should be visible in the whole source code 141 | # Apparently, it is not at the moment. [TG] 28.09.96 142 | 143 | compat.o: agrep.h defs.h config.h 144 | asearch.o: agrep.h defs.h config.h 145 | asearch1.o: agrep.h defs.h config.h 146 | bitap.o: agrep.h defs.h config.h codepage.h 147 | checkfil.o: agrep.h checkfil.h defs.h config.h 148 | follow.o: re.h agrep.h defs.h config.h 149 | main.o: agrep.h checkfil.h defs.h config.h 150 | agrep.o: agrep.h checkfil.h defs.h config.h version.h codepage.h 151 | agrephlp.o: version.h config.h 152 | newmgrep.o: agrep.h defs.h config.h codepage.h 153 | maskgen.o: agrep.h defs.h config.h codepage.h 154 | next.o: agrep.h defs.h config.h 155 | parse.o: re.h agrep.h defs.h config.h 156 | preproce.o: agrep.h defs.h config.h 157 | checksg.o: agrep.h checkfil.h defs.h config.h 158 | delim.o: agrep.h defs.h config.h 159 | asplit.o: agrep.h defs.h config.h 160 | sgrep.o: agrep.h defs.h config.h codepage.h 161 | # not used any longer io.o: agrep.h defs.h config.h 162 | utilitie.o: re.h agrep.h defs.h config.h 163 | dummyfil.o: config.h 164 | codepage.o: codepage.h config.h agrep.h 165 | -------------------------------------------------------------------------------- /io.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | #include "agrep.h" 3 | 4 | /* AGREP_POINTER must be defined to be 1 always */ 5 | /* #define AGREP_POINTER 1 */ 6 | /* Removed since we now have a -DAGREP_POINTER=1 option in the Makefile */ 7 | 8 | fill_buf(fd, buf, record_size) 9 | int fd, record_size; 10 | unsigned char *buf; 11 | { 12 | int num_read=1; 13 | int total_read=0; 14 | 15 | if (fd >= 0) { 16 | while(total_read < record_size && num_read > 0) { 17 | num_read = read(fd, buf+total_read, record_size - total_read); 18 | total_read = total_read + num_read; 19 | } 20 | } 21 | #if AGREP_POINTER 22 | else return 0; /* should not call this function if buf is a pointer to a user-specified region! */ 23 | #else /*AGREP_POINTER*/ 24 | else { /* simulate a file */ 25 | total_read = (record_size > (agrep_inlen - agrep_inpointer)) ? (agrep_inlen - agrep_inpointer) : record_size; 26 | memcpy(buf, agrep_inbuffer + agrep_inpointer, total_read); 27 | agrep_inpointer += total_read; 28 | } 29 | #endif /*AGREP_POINTER*/ 30 | return(total_read); 31 | } 32 | 33 | /* 34 | * In these functions no allocs/copying is done when 35 | * fd == -1, i.e., agrep is called to search within memory. 36 | */ 37 | 38 | alloc_buf(fd, buf, size) 39 | int fd; 40 | char **buf; 41 | int size; 42 | { 43 | #if AGREP_POINTER 44 | if (fd != -1) 45 | #endif /*AGREP_POINTER*/ 46 | *buf = (char *)malloc(size); 47 | } 48 | 49 | free_buf(fd, buf) 50 | int fd; 51 | char *buf; 52 | { 53 | #if AGREP_POINTER 54 | if (fd != -1) 55 | #endif /*AGREP_POINTER*/ 56 | free(buf); 57 | } 58 | -------------------------------------------------------------------------------- /io.c.orig: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | #include "agrep.h" 3 | 4 | /* AGREP_POINTER must be defined to be 1 always */ 5 | /* #define AGREP_POINTER 1 */ 6 | /* Removed since we now have a -DAGREP_POINTER=1 option in the Makefile */ 7 | 8 | fill_buf(fd, buf, record_size) 9 | int fd, record_size; 10 | unsigned char *buf; 11 | { 12 | int num_read=1; 13 | int total_read=0; 14 | 15 | if (fd >= 0) { 16 | while(total_read < record_size && num_read > 0) { 17 | num_read = read(fd, buf+total_read, record_size - total_read); 18 | total_read = total_read + num_read; 19 | } 20 | } 21 | #if AGREP_POINTER 22 | else return 0; /* should not call this function if buf is a pointer to a user-specified region! */ 23 | #else /*AGREP_POINTER*/ 24 | else { /* simulate a file */ 25 | total_read = (record_size > (agrep_inlen - agrep_inpointer)) ? (agrep_len - agrep_inpointer) : record_size; 26 | memcpy(buf, agrep_inbuffer + agrep_inpointer, total_read); 27 | agrep_inpointer += total_read; 28 | } 29 | #endif /*AGREP_POINTER*/ 30 | return(total_read); 31 | } 32 | 33 | /* 34 | * In these functions no allocs/copying is done when 35 | * fd == -1, i.e., agrep is called to search within memory. 36 | */ 37 | 38 | alloc_buf(fd, buf, size) 39 | int fd; 40 | char **buf; 41 | int size; 42 | { 43 | #if AGREP_POINTER 44 | if (fd != -1) 45 | #endif /*AGREP_POINTER*/ 46 | *buf = (char *)malloc(size); 47 | } 48 | 49 | free_buf(fd, buf) 50 | int fd; 51 | char *buf; 52 | { 53 | #if AGREP_POINTER 54 | if (fd != -1) 55 | #endif /*AGREP_POINTER*/ 56 | free(buf); 57 | } 58 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* [TG] 3.29 14.10.96 */ 4 | 5 | #include 6 | #include "agrep.h" 7 | 8 | #if ISO_CHAR_SET 9 | #include /* support for 8bit character set: ew@senate.be */ 10 | #endif 11 | 12 | #if MEASURE_TIMES 13 | extern int INFILTER_ms, OUTFILTER_ms, FILTERALGO_ms; 14 | #endif /*MEASURE_TIMES*/ 15 | 16 | extern char Pattern[MAXPAT]; 17 | extern int EXITONERROR; 18 | 19 | #ifdef __EMX__ 20 | extern unsigned int _emx_env; /* this variable denotes the operating system DOS, OS/2 */ 21 | #endif 22 | 23 | #ifdef _WIN32 24 | int fileagrep(); /* agrep.c */ 25 | #endif 26 | 27 | #ifndef _WIN32 28 | int 29 | #else 30 | void 31 | #endif 32 | main(argc, argv) 33 | int argc; 34 | char *argv[]; 35 | { 36 | int ret; 37 | 38 | 39 | #ifdef __EMX__ 40 | 41 | /* The emx-compiler specific variable _emx_env describes the environment 42 | the program is running in. See also: the makefiles. 43 | 44 | values of _emx_env OS/2: OS/2 DOS box: DOS: Win DOS box: 45 | 46 | AGREP2.EXE 0x0220 - - - 47 | AGREPDOS.EXE +EMX.DLL=0x0A20 - 0x0803 - 48 | AGREP.EXE +EMX.DLL=0x0A20 +RSX.EXE=0x18A0 +EMX.EXE=0x0003 +RSX.EXE=0x18A0 49 | 50 | fprintf(stderr,"AGREP -- INFO: _emx_env = 0x%04lX\n",_emx_env); 51 | */ 52 | 53 | #ifdef __DOS /* check if compiled for DOS but running under OS/2 */ 54 | /* 55 | if ((_emx_env & 0x0A00)!=0x0800) { 56 | fprintf(stderr,"This program cannot be run in an OS/2 session.\nPlease use the OS/2 version."); 57 | 58 | ret = -1; 59 | goto ABORT; 60 | } 61 | */ 62 | #endif 63 | 64 | #ifdef __OS2 /* check if compiled for OS/2 but running under DOS or in a DOS session */ 65 | /* 66 | if ((_emx_env & 0x0A00)!=0x0200) { 67 | fprintf(stderr,"This program cannot be run in a DOS session.\nPlease use the DOS version.\n"); 68 | 69 | ret = -1; 70 | goto ABORT; 71 | } 72 | */ 73 | #endif 74 | 75 | 76 | #endif 77 | 78 | EXITONERROR = 1; /* the only place where it is set to 1 */ 79 | ret = fileagrep(argc, argv, 0, stdout); 80 | 81 | #if ISO_CHAR_SET 82 | setlocale(LC_ALL,""); /* support for 8bit character set: ew@senate.be, Henrik.Martin@eua.ericsson.se */ 83 | #endif 84 | 85 | #if MEASURE_TIMES 86 | fprintf(stderr, "ret = %d infilter = %d ms\toutfilter = %d ms\tfilteralgo = %d ms\n", ret, INFILTER_ms, OUTFILTER_ms, FILTERALGO_ms); 87 | #endif /*MEASURE_TIMES*/ 88 | 89 | /* The original return codes were: 90 | 91 | if(ret<0) exit(2); 92 | if(ret==0) exit(1); 93 | exit(0); 94 | */ 95 | 96 | ABORT: exit(ret); /* changed by [TG] 23.09.96 */ 97 | } 98 | -------------------------------------------------------------------------------- /maskgen.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* [chg] 22.09.96 UL850[].lower_1 -> UL850[].lower [TG] 4 | [chg] 21.08.96 now using ISO_CHAR.H and 5 | table look-up for upper-lower conversion. [TG] 6 | */ 7 | 8 | #include "agrep.h" 9 | #include "codepage.h" 10 | 11 | /* TG 29.04.04 */ 12 | #include 13 | 14 | extern unsigned char LUT[256]; 15 | extern int CODEPAGE; 16 | extern struct CODEPAGE_struct CP[CODEPAGES][CPSIZE]; 17 | 18 | extern unsigned D_endpos, endposition, Init1, wildmask; 19 | extern Mask[], Bit[], Init[], NO_ERR_MASK; 20 | extern int AND, REGEX, NOUPPER, D_length; 21 | extern unsigned char Progname[]; 22 | extern int agrep_initialfd; 23 | extern int EXITONERROR; 24 | extern int errno; 25 | 26 | int 27 | maskgen(Pattern, D) 28 | 29 | unsigned char *Pattern; 30 | int D; 31 | { 32 | struct term { 33 | int flag; 34 | unsigned char class[WORD]; 35 | } 36 | position[WORD+10]; 37 | unsigned char c, pp; 38 | 39 | int i, j, k, l, M, OR=0, EVEN = 0, base, No_error; 40 | 41 | #ifdef DEBUG 42 | fprintf(stderr, "maskgen: len=%d, pat=%s, D=%d\n", strlen(Pattern), Pattern, D); 43 | #endif 44 | for(i=0; i 0) printf("%d %c = metasymb[%d]\n",CP[CODEPAGE][i].upper,CP[CODEPAGE][i].upper,CP[CODEPAGE][i].metasymb); 63 | for(i=0; i' (use \\<, \\> to search for <, >)\n", Progname); 89 | if (!EXITONERROR) { 90 | errno = AGREP_ERROR; 91 | return -1; 92 | } 93 | else exit(2); 94 | } 95 | } 96 | else if (pp==LRANGE) { 97 | if (No_error == ON) NO_ERR_MASK = NO_ERR_MASK | Bit[j]; 98 | i=i+1; 99 | if (Pattern[i] == NOTSYM) { 100 | position[j].flag = Compl; 101 | i++; 102 | } 103 | k=0; 104 | while ((Pattern[i] != RRANGE) && i < M) 105 | { 106 | if(Pattern[i] == HYPHEN) 107 | { 108 | position[j].class[k-1] = Pattern[i+1]; 109 | i=i+2; 110 | } 111 | else { 112 | position[j].class[k] = position[j].class[k+1] = Pattern[i]; 113 | k = k+2; 114 | i++; 115 | } 116 | } 117 | if(i == M) { 118 | fprintf(stderr, "%s: unmatched '[', ']' (use \\[, \\] to search for [, ])\n", Progname); 119 | if (!EXITONERROR) { 120 | errno = AGREP_ERROR; 121 | return -1; 122 | } 123 | else exit(2); 124 | } 125 | position[j].class[k] = '\0'; 126 | j++; 127 | } 128 | else if (pp==RRANGE) { 129 | fprintf(stderr, "%s: unmatched '[', ']' (use \\[, \\] to search for [, ])\n", Progname); 130 | if (!EXITONERROR) { 131 | errno = AGREP_ERROR; 132 | return -1; 133 | } 134 | else exit(2); 135 | } 136 | else if (pp==ORPAT) { 137 | if(REGEX == ON || AND == ON) { 138 | fprintf(stderr, "illegal pattern: cannot handle OR (',') and AND (';')/regular-expressions simultaneously\n"); 139 | if (!EXITONERROR) { 140 | errno = AGREP_ERROR; 141 | return -1; 142 | } 143 | else exit(2); 144 | } 145 | OR = ON; 146 | position[j].flag = 2; 147 | position[j].class[0] = '\0'; 148 | endposition = endposition | Bit[j++]; 149 | } 150 | else if (pp==ANDPAT) { 151 | position[j].flag = 2; 152 | position[j].class[0] = '\0'; 153 | if(j > D_length) AND = ON; 154 | if(OR || (REGEX == ON && j>D_length)) { 155 | fprintf(stderr, "illegal pattern: cannot handle AND (';') and OR (',')/regular-expressions simultaneously\n"); 156 | if (!EXITONERROR) { 157 | errno = AGREP_ERROR; 158 | return -1; 159 | } 160 | else exit(2); 161 | } 162 | endposition = endposition | Bit[j++]; 163 | } 164 | /* 165 | case ' ' : if (Pattern[i-1] == ORPAT || Pattern[i-1] == ANDPAT) break; 166 | if(No_error == ON) NO_ERR_MASK = NO_ERR_MASK | Bit[j]; 167 | position[j].flag = 0; 168 | position[j].class[0] = position[j].class[1] = Pattern[i]; 169 | position[j++].class[2] = '\0'; break; 170 | */ 171 | else if (pp=='\n') { 172 | NO_ERR_MASK = NO_ERR_MASK | Bit[j]; 173 | position[j].class[0] = position[j].class[1] = '\n'; 174 | position[j++].class[2] = '\0'; 175 | } 176 | else if (pp==WORDB) { 177 | NO_ERR_MASK = NO_ERR_MASK | Bit[j]; 178 | position[j].class[0] = 1; 179 | position[j].class[1] = 47; 180 | position[j].class[2] = 58; 181 | position[j].class[3] = 64; 182 | position[j].class[4] = 91; 183 | position[j].class[5] = 96; 184 | position[j].class[6] = 123; 185 | position[j].class[7] = 127; 186 | position[j++].class[8] = '\0'; 187 | } 188 | else if (pp==NNLINE) { 189 | NO_ERR_MASK |= Bit[j]; 190 | position[j].class[0] = position[j].class[1] = '\n'; 191 | position[j].class[2] = position[j].class[3] = NNLINE; 192 | position[j++].class[4] = '\0'; 193 | } 194 | else if ((pp != STAR) & (pp != ORSYM) & (pp != LPARENT) & (pp != RPARENT)) { 195 | if(No_error == ON) NO_ERR_MASK = NO_ERR_MASK | Bit[j]; 196 | position[j].flag = 0; 197 | position[j].class[0] = position[j].class[1] = Pattern[i]; 198 | position[j++].class[2] = '\0'; 199 | }; 200 | 201 | if(j > WORD) { 202 | fprintf(stderr, "%s: pattern too long (has > %d chars)\n", Progname, WORD); 203 | if (!EXITONERROR) { 204 | errno = AGREP_ERROR; 205 | return -1; 206 | } 207 | else exit(2); 208 | } 209 | } 210 | if (EVEN != 0) { 211 | fprintf(stderr, "%s: unmatched '<', '>' (use \\<, \\> to search for <, >)\n", Progname); 212 | if (!EXITONERROR) { 213 | errno = AGREP_ERROR; 214 | return -1; 215 | } 216 | else exit(2); 217 | } 218 | M = j - 1; 219 | base = WORD - M; 220 | wildmask = (wildmask >> base); 221 | endposition = (endposition >> base); 222 | NO_ERR_MASK = (NO_ERR_MASK >> 1) & (~Bit[1]); 223 | NO_ERR_MASK = ~NO_ERR_MASK >> (base-1); 224 | for (i=1; i<= WORD - M ; i++) Init[0] = Init[0] | Bit[i]; 225 | Init[0] = Init[0] | endposition; 226 | 227 | /* not necessary for INit[i], i>0, */ 228 | /* but at every begining of the matching process append one 229 | no-match character to initialize the error vectors */ 230 | 231 | endposition = ( endposition << 1 ) + 1; 232 | Init1 = (Init[0] | wildmask | endposition) ; 233 | D_endpos = ( endposition >> ( M - D_length ) ) << ( M - D_length); 234 | endposition = endposition ^ D_endpos; 235 | #ifdef DEBUG 236 | printf("endposition: %o\n", endposition); 237 | printf("no_err_mask: %o\n", NO_ERR_MASK); 238 | #endif 239 | for(c=0, i=0; i < MAXSYM; c++, i++) 240 | { 241 | for (k=1, l=0; k<=M ; k++, l=0) { 242 | while (position[k].class[l] != '\0') { 243 | if ((position[k].class[l] == NOCARE) && ((c != '\n') || REGEX) ) 244 | { 245 | Mask[c] = Mask[c] | Bit[base + k]; 246 | break; 247 | } 248 | if (c >= position[k].class[l] && c <= position[k].class[l+1]) 249 | { 250 | Mask[c] = Mask[c] | Bit[base + k]; 251 | break; 252 | } 253 | l = l + 2; 254 | } 255 | if (position[k].flag == Compl) Mask[c] = Mask[c] ^ Bit[base+k]; 256 | } 257 | } 258 | 259 | if(NOUPPER) for(i=0; i, June/87 3 | */ 4 | 5 | /* #ifdef WIN32 */ 6 | /* 7 | * @(#)dir.c 1.4 87/11/06 Public Domain. 8 | * 9 | * A public domain implementation of BSD directory routines for 10 | * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield), 11 | * August 1897 12 | * Ported to OS/2 by Kai Uwe Rommel 13 | * December 1989, February 1990 14 | * Ported to Windows NT 22 May 91 15 | * other mods Summer '92 brianmo@microsoft.com 16 | * opendirx() was horribly written, very inefficient, and did not take care 17 | * of all cases. It is still not too clean, but it is far more efficient. 18 | * Changes made by Gordon Chaffee (chaffee@bugs-bunny.cs.berkeley.edu) 19 | */ 20 | 21 | 22 | /*Includes: 23 | * crt 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "ntdirent.h" 31 | 32 | #define stat _stat 33 | 34 | /* 35 | * NT specific 36 | */ 37 | #include 38 | 39 | /* 40 | * random typedefs 41 | */ 42 | #define HDIR HANDLE 43 | #define HFILE HANDLE 44 | #define PHFILE PHANDLE 45 | 46 | /* 47 | * local functions 48 | */ 49 | static char *getdirent(char *); 50 | static void free_dircontents(struct _dircontents *); 51 | 52 | static HDIR FindHandle; 53 | static WIN32_FIND_DATA FileFindData; 54 | 55 | static struct dirent dp; 56 | 57 | DIR *opendirx(char *name, char *pattern) 58 | { 59 | struct stat statb; 60 | DIR *dirp; 61 | char c; 62 | char *s; 63 | struct _dircontents *dp; 64 | int len; 65 | int unc; 66 | char path[ OFS_MAXPATHNAME ]; 67 | register char *ip, *op; 68 | 69 | for (ip = name, op = path; ; op++, ip++) { 70 | *op = *ip; 71 | if (*ip == '\0') { 72 | break; 73 | } 74 | } 75 | len = ip - name; 76 | if (len > 0) { 77 | unc = ((path[0] == '\\' || path[0] == '/') && 78 | (path[1] == '\\' || path[1] == '/')); 79 | c = path[len - 1]; 80 | if (unc) { 81 | if (c != '\\' && c != '/') { 82 | path[len] = '/'; 83 | len++; 84 | path[len] ='\0'; 85 | } 86 | } else { 87 | if ((c == '\\' || c == '/') && (len > 1)) { 88 | len--; 89 | path[len] = '\0'; 90 | 91 | if (path[len - 1] == ':' ) { 92 | path[len] = '/'; len++; 93 | path[len] = '.'; len++; 94 | path[len] = '\0'; 95 | } 96 | } else if (c == ':' ) { 97 | path[len] = '.'; 98 | len++; 99 | path[len] ='\0'; 100 | } 101 | } 102 | } else { 103 | unc = 0; 104 | path[0] = '.'; 105 | path[1] = '\0'; 106 | len = 1; 107 | } 108 | 109 | if (stat(path, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR) { 110 | return NULL; 111 | } 112 | 113 | dirp = malloc(sizeof(DIR)); 114 | if (dirp == NULL) { 115 | return dirp; 116 | } 117 | 118 | c = path[len - 1]; 119 | if (c == '.' ) { 120 | if (len == 1) { 121 | len--; 122 | } else { 123 | c = path[len - 2]; 124 | if (c == '\\' || c == ':') { 125 | len--; 126 | } else { 127 | path[len] = '/'; 128 | len++; 129 | } 130 | } 131 | } else if (!unc && ((len != 1) || (c != '\\' && c != '/'))) { 132 | path[len] = '/'; 133 | len++; 134 | } 135 | strcpy(path + len, pattern); 136 | 137 | dirp -> dd_loc = 0; 138 | dirp -> dd_contents = dirp -> dd_cp = NULL; 139 | 140 | if ((s = getdirent(path)) == NULL) { 141 | return dirp; 142 | } 143 | 144 | do 145 | { 146 | if (((dp = malloc(sizeof(struct _dircontents))) == NULL) || 147 | ((dp -> _d_entry = malloc(strlen(s) + 1)) == NULL) ) 148 | { 149 | if (dp) 150 | free(dp); 151 | free_dircontents(dirp -> dd_contents); 152 | 153 | return NULL; 154 | } 155 | 156 | if (dirp -> dd_contents) 157 | dirp -> dd_cp = dirp -> dd_cp -> _d_next = dp; 158 | else 159 | dirp -> dd_contents = dirp -> dd_cp = dp; 160 | 161 | strcpy(dp -> _d_entry, s); 162 | dp -> _d_next = NULL; 163 | 164 | } 165 | while ((s = getdirent(NULL)) != NULL); 166 | 167 | dirp -> dd_cp = dirp -> dd_contents; 168 | return dirp; 169 | } 170 | 171 | DIR *opendir(char *name) 172 | { 173 | return opendirx(name, "*"); 174 | } 175 | 176 | void closedir(DIR * dirp) 177 | { 178 | free_dircontents(dirp -> dd_contents); 179 | free(dirp); 180 | } 181 | 182 | struct dirent *readdir(DIR * dirp) 183 | { 184 | /* static struct dirent dp; */ 185 | if (dirp -> dd_cp == NULL) 186 | return NULL; 187 | 188 | /*strcpy(dp.d_name,dirp->dd_cp->_d_entry); */ 189 | 190 | dp.d_name = dirp->dd_cp->_d_entry; 191 | 192 | dp.d_namlen = dp.d_reclen = 193 | strlen(dp.d_name); 194 | 195 | dp.d_ino = dirp->dd_loc+1; /* fake the inode */ 196 | 197 | dirp -> dd_cp = dirp -> dd_cp -> _d_next; 198 | dirp -> dd_loc++; 199 | 200 | 201 | return &dp; 202 | } 203 | 204 | void seekdir(DIR * dirp, long off) 205 | { 206 | long i = off; 207 | struct _dircontents *dp; 208 | 209 | if (off >= 0) 210 | { 211 | for (dp = dirp -> dd_contents; --i >= 0 && dp; dp = dp -> _d_next); 212 | 213 | dirp -> dd_loc = off - (i + 1); 214 | dirp -> dd_cp = dp; 215 | } 216 | } 217 | 218 | 219 | long telldir(DIR * dirp) 220 | { 221 | return dirp -> dd_loc; 222 | } 223 | 224 | static void free_dircontents(struct _dircontents * dp) 225 | { 226 | struct _dircontents *odp; 227 | 228 | while (dp) 229 | { 230 | if (dp -> _d_entry) 231 | free(dp -> _d_entry); 232 | 233 | dp = (odp = dp) -> _d_next; 234 | free(odp); 235 | } 236 | } 237 | /* end of "free_dircontents" */ 238 | 239 | static char *getdirent(char *dir) 240 | { 241 | int got_dirent; 242 | 243 | if (dir != NULL) 244 | { /* get first entry */ 245 | if ((FindHandle = FindFirstFile( dir, &FileFindData )) 246 | == (HDIR)0xffffffff) 247 | { 248 | return NULL; 249 | } 250 | got_dirent = 1; 251 | } 252 | else /* get next entry */ 253 | got_dirent = FindNextFile( FindHandle, &FileFindData ); 254 | 255 | if (got_dirent) 256 | return FileFindData.cFileName; 257 | else 258 | { 259 | FindClose(FindHandle); 260 | return NULL; 261 | } 262 | } 263 | /* end of getdirent() */ 264 | 265 | struct passwd * _cdecl 266 | getpwnam(char *name) 267 | { 268 | return NULL; 269 | } 270 | 271 | struct passwd * _cdecl 272 | getpwuid(int uid) 273 | { 274 | return NULL; 275 | } 276 | 277 | int 278 | getuid() 279 | { 280 | return 0; 281 | } 282 | 283 | void _cdecl 284 | endpwent(void) 285 | { 286 | } 287 | 288 | /* #endif */ 289 | -------------------------------------------------------------------------------- /ntdirent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @(#) dirent.h 2.0 17 Jun 91 Public Domain. 3 | * 4 | * A public domain implementation of BSD directory routines for 5 | * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield), 6 | * August 1987 7 | * 8 | * Enhanced and ported to OS/2 by Kai Uwe Rommel; added scandir() prototype 9 | * December 1989, February 1990 10 | * Change of MAXPATHLEN for HPFS, October 1990 11 | * 12 | * Unenhanced and ported to Windows NT by Bill Gallagher 13 | * 17 Jun 91 14 | * changed d_name to char * instead of array, removed non-std extensions 15 | * 16 | * Cleanup, other hackery, Summer '92, Brian Moran , brianmo@microsoft.com 17 | */ 18 | 19 | #ifndef _DIRENT 20 | #define _DIRENT 21 | 22 | #include 23 | 24 | struct dirent 25 | { 26 | ino_t d_ino; /* a bit of a farce */ 27 | short d_reclen; /* more farce */ 28 | short d_namlen; /* length of d_name */ 29 | char *d_name; 30 | }; 31 | 32 | struct _dircontents 33 | { 34 | char *_d_entry; 35 | struct _dircontents *_d_next; 36 | }; 37 | 38 | typedef struct _dirdesc 39 | { 40 | int dd_id; /* uniquely identify each open directory*/ 41 | long dd_loc; /* where we are in directory entry */ 42 | struct _dircontents *dd_contents; /* pointer to contents of dir */ 43 | struct _dircontents *dd_cp; /* pointer to current position */ 44 | } 45 | DIR; 46 | 47 | extern DIR *opendir(char *); 48 | extern struct dirent *readdir(DIR *); 49 | extern void seekdir(DIR *, long); 50 | extern long telldir(DIR *); 51 | extern void closedir(DIR *); 52 | #define rewinddir(dirp) seekdir(dirp, 0L) 53 | 54 | #endif /* _DIRENT */ 55 | 56 | /* end of dirent.h */ 57 | -------------------------------------------------------------------------------- /preprocess.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* substitute metachar with special symbol */ 3 | /* if regularr expression, then set flag REGEX */ 4 | /* if REGEX and MULTIPAT then report error message, */ 5 | /* -w only for single word pattern. If WORDBOUND & MULTIWORD error */ 6 | /* process start of line, endof line symbol, */ 7 | /* process -w WORDBOUND option, append special symbol at begin&end of */ 8 | /* process -d option before this routine */ 9 | /* the delimiter pattern is in D_pattern (need to end with '; ') */ 10 | /* if '-t' (suggestion: how about -B) the pattern is passed to sgrep */ 11 | /* and doesn't go here */ 12 | /* in that case, -d is ignored? or not necessary */ 13 | /* upon return, Pattern contains the pattern to be processed by maskgen */ 14 | /* D_pattern contains transformed D_pattern */ 15 | 16 | #include "agrep.h" 17 | #include 18 | 19 | extern int PAT_FILE, PAT_BUFFER; 20 | extern ParseTree *AParse; 21 | extern int WHOLELINE, REGEX, FASTREGEX, RE_ERR, DELIMITER, TAIL, WORDBOUND; 22 | extern int HEAD; 23 | extern CHAR Progname[]; 24 | extern int D_length, tc_D_length; 25 | extern CHAR tc_D_pattern[MaxDelimit * 2]; 26 | extern int table[WORD][WORD]; 27 | extern int agrep_initialfd; 28 | extern int EXITONERROR; 29 | extern int errno; 30 | 31 | extern int multifd; 32 | extern char *multibuf; 33 | extern int multilen; 34 | extern int anum_terminals; 35 | extern ParseTree aterminals[MAXNUM_PAT]; 36 | extern char FREQ_FILE[MAX_LINE_LEN], HASH_FILE[MAX_LINE_LEN], STRING_FILE[MAX_LINE_LEN]; /* interfacing with tcompress */ 37 | extern int AComplexBoolean; 38 | 39 | int 40 | preprocess(D_pattern, Pattern) /* need two parameters */ 41 | CHAR D_pattern[], Pattern[]; 42 | { 43 | CHAR temp[Maxline], *r_pat, *old_pat; /* r_pat for r.e. */ 44 | CHAR old_D_pat[MaxDelimit*2]; 45 | int i, j=0, rp=0, m, t=0, num_pos, ANDON = 0; 46 | int d_end ; 47 | int IN_RANGE=0; 48 | int ret1, ret2; 49 | 50 | #if DEBUG 51 | fprintf(stderr, "preprocess: m=%d, pat=%s, PAT_FILE=%d, PAT_BUFFER=%d\n", strlen(Pattern), Pattern, PAT_FILE, PAT_BUFFER); 52 | #endif 53 | if ((m = strlen(Pattern)) <= 0) return 0; 54 | if (PAT_FILE || PAT_BUFFER) return 0; 55 | REGEX = OFF; 56 | FASTREGEX = OFF; 57 | old_pat = Pattern; /* to remember the starting position */ 58 | 59 | /* Check if pattern is a concatenation of ands OR ors of simple patterns */ 60 | multibuf = (char *)malloc(m * 2 + 2); /* worst case: a,a,a,a,a,a */ 61 | if (multibuf == NULL) goto normal_processing; 62 | /* if (WORDBOUND) goto normal_processing; */ 63 | 64 | multilen = 0; 65 | AParse = 0; 66 | ret1 = ret2 = 0; 67 | if (((ret1 = asplit_pattern(Pattern, m, aterminals, &anum_terminals, &AParse)) <= 0) || /* can change the pattern if simple boolean with {} */ 68 | ((ret2 = asplit_terminal(0, anum_terminals, multibuf, &multilen)) <= 0) || 69 | ((ret2 == 1) && !(aterminals[0].op & NOTPAT))) { /* must do normal processing */ 70 | if (AComplexBoolean && (AParse != NULL)) destroy_tree(AParse); /* so that direct exec invocations don't use AParse by mistake! */ 71 | #if DEBUG 72 | fprintf(stderr, "preprocess: split_pat = %d, split_term = %d, #terms = %d\n", ret1, ret2, anum_terminals); 73 | #endif /*DEBUG*/ 74 | /* 75 | if (ret2 == 1) { 76 | strcpy(Pattern, aterminals[0].data.leaf.value); 77 | m = strlen(Pattern); 78 | } 79 | */ 80 | m = strlen(Pattern); 81 | AParse = 0; 82 | free(multibuf); 83 | multibuf = NULL; 84 | multilen = 0; 85 | goto normal_processing; 86 | } 87 | 88 | /* This is quick processing */ 89 | if (AParse != 0) { /* successfully converted to ANDPAT/ORPAT */ 90 | PAT_BUFFER = 1; 91 | /* printf("preprocess(): converted= %d, patterns= %s", AParse, multibuf); */ 92 | /* Now I have to process the delimiter if any */ 93 | if (DELIMITER) { 94 | /* D_pattern is "; ", D_length is 1 + length of string PAT: see agrep.c/'d' */ 95 | preprocess_delimiter(D_pattern+1, D_length - 1, D_pattern, &D_length); 96 | /* D_pattern is the exact stuff we want to match, D_length is its strlen */ 97 | if ((tc_D_length = quick_tcompress(FREQ_FILE, HASH_FILE, D_pattern, D_length, tc_D_pattern, MaxDelimit*2, TC_EASYSEARCH)) <= 0) { 98 | strcpy(tc_D_pattern, D_pattern); 99 | tc_D_length = D_length; 100 | } 101 | /* printf("mgrep's delim=%s,%d tc_delim=%s,%d\n", D_pattern, D_length, tc_D_pattern, tc_D_length); */ 102 | } 103 | return 0; 104 | } 105 | /* else either unknown character, one simple pattern or none at all */ 106 | 107 | normal_processing: 108 | for(i=0; i< m; i++) { 109 | if(Pattern[i] == '\\') i++; 110 | else if(Pattern[i] == '|' || Pattern[i] == '*') REGEX = ON; 111 | } 112 | 113 | r_pat = (CHAR *) malloc(strlen(Pattern)+2*strlen(D_pattern) + 8); /* bug-report, From: Chris Dalton */ 114 | strcpy(temp, D_pattern); 115 | d_end = t = strlen(temp); /* size of D_pattern, including '; ' */ 116 | if (WHOLELINE) { 117 | temp[t++] = LANGLE; 118 | temp[t++] = NNLINE; 119 | temp[t++] = RANGLE; 120 | temp[t] = '\0'; 121 | strcat(temp, Pattern); 122 | m = strlen(temp); 123 | temp[m++] = LANGLE; 124 | temp[m++] = '\n'; 125 | temp[m++] = RANGLE; 126 | temp[m] = '\0'; 127 | } 128 | else { 129 | if (WORDBOUND) { 130 | temp[t++] = LANGLE; 131 | temp[t++] = WORDB; 132 | temp[t++] = RANGLE; 133 | temp[t] = '\0'; 134 | } 135 | strcat(temp, Pattern); 136 | m = strlen(temp); 137 | if (WORDBOUND) { 138 | temp[m++] = LANGLE; 139 | temp[m++] = WORDB; 140 | temp[m++] = RANGLE; 141 | } 142 | temp[m] = '\0'; 143 | } 144 | /* now temp contains augmented pattern , m it's size */ 145 | D_length = 0; 146 | for (i=0, j=0; i< d_end-2; i++) { 147 | switch(temp[i]) 148 | { 149 | case '\\' : 150 | i++; 151 | Pattern[j++] = temp[i]; 152 | old_D_pat[D_length++] = temp[i]; 153 | break; 154 | case '<' : 155 | Pattern[j++] = LANGLE; 156 | break; 157 | case '>' : 158 | Pattern[j++] = RANGLE; 159 | break; 160 | case '^' : 161 | Pattern[j++] = '\n'; 162 | old_D_pat[D_length++] = temp[i]; 163 | break; 164 | case '$' : 165 | Pattern[j++] = '\n'; 166 | old_D_pat[D_length++] = temp[i]; 167 | break; 168 | default : 169 | Pattern[j++] = temp[i]; 170 | old_D_pat[D_length++] = temp[i]; 171 | break; 172 | } 173 | } 174 | if(D_length > MAXDELIM) { 175 | fprintf(stderr, "%s: delimiter pattern too long (has > %d chars)\n", Progname, MAXDELIM); 176 | free(r_pat); 177 | if (!EXITONERROR) { 178 | errno = AGREP_ERROR; 179 | return -1; 180 | } 181 | else exit(2); 182 | } 183 | 184 | Pattern[j++] = ANDPAT; 185 | old_D_pat[D_length] = '\0'; 186 | strcpy(D_pattern, old_D_pat); 187 | D_length++; 188 | /* 189 | Pattern[j++] = ' '; 190 | */ 191 | Pattern[j] = '\0'; 192 | rp = 0; 193 | if(REGEX) { 194 | r_pat[rp++] = '.'; /* if REGEX: always append '.' in front */ 195 | r_pat[rp++] = '('; 196 | Pattern[j++] = NOCARE; 197 | HEAD = ON; 198 | } 199 | for (i=d_end; i < m ; i++) 200 | { 201 | switch(temp[i]) 202 | { 203 | case '\\': 204 | i++; 205 | Pattern[j++] = temp[i]; 206 | r_pat[rp++] = 'o'; /* the symbol doesn't matter */ 207 | break; 208 | case '#': 209 | FASTREGEX = ON; 210 | if(REGEX) { 211 | Pattern[j++] = NOCARE; 212 | r_pat[rp++] = '.'; 213 | r_pat[rp++] = '*'; 214 | break; 215 | } 216 | Pattern[j++] = WILDCD; 217 | break; 218 | case '(': 219 | Pattern[j++] = LPARENT; 220 | r_pat[rp++] = '('; 221 | break; 222 | case ')': 223 | Pattern[j++] = RPARENT; 224 | r_pat[rp++] = ')'; 225 | break; 226 | case '[': 227 | Pattern[j++] = LRANGE; 228 | r_pat[rp++] = '['; 229 | IN_RANGE = ON; 230 | break; 231 | case ']': 232 | Pattern[j++] = RRANGE; 233 | r_pat[rp++] = ']'; 234 | IN_RANGE = OFF; 235 | break; 236 | case '<': 237 | Pattern[j++] = LANGLE; 238 | break; 239 | case '>': 240 | Pattern[j++] = RANGLE; 241 | break; 242 | case '^': 243 | if (temp[i-1] == '[') Pattern[j++] = NOTSYM; 244 | else Pattern[j++] = '\n'; 245 | r_pat[rp++] = '^'; 246 | break; 247 | case '$': 248 | Pattern[j++] = '\n'; 249 | r_pat[rp++] = '$'; 250 | break; 251 | case '.': 252 | Pattern[j++] = NOCARE; 253 | r_pat[rp++] = '.'; 254 | break; 255 | case '*': 256 | Pattern[j++] = STAR; 257 | r_pat[rp++] = '*'; 258 | break; 259 | case '|': 260 | Pattern[j++] = ORSYM; 261 | r_pat[rp++] = '|'; 262 | break; 263 | case ',': 264 | Pattern[j++] = ORPAT; 265 | RE_ERR = ON; 266 | break; 267 | case ';': 268 | if(ANDON) RE_ERR = ON; 269 | Pattern[j++] = ANDPAT; 270 | ANDON = ON; 271 | break; 272 | case '-': 273 | if(IN_RANGE) { 274 | Pattern[j++] = HYPHEN; 275 | r_pat[rp++] = '-'; 276 | } 277 | else { 278 | Pattern[j++] = temp[i]; 279 | r_pat[rp++] = temp[i]; 280 | } 281 | break; 282 | case NNLINE : 283 | Pattern[j++] = temp[i]; 284 | r_pat[rp++] = 'N'; 285 | break; 286 | default: 287 | Pattern[j++] = temp[i]; 288 | r_pat[rp++] = temp[i]; 289 | break; 290 | } 291 | } 292 | if(REGEX) { /* append ').' at end of regular expression */ 293 | r_pat[rp++] = ')'; 294 | r_pat[rp++] = '.'; 295 | Pattern[j++] = NOCARE; 296 | TAIL = ON; 297 | } 298 | Pattern[j] = '\0'; 299 | m = j; 300 | r_pat[rp] = '\0'; 301 | if(REGEX) 302 | { 303 | if(DELIMITER || WORDBOUND) { 304 | fprintf(stderr, "%s: -d or -w option is not supported for this pattern\n", Progname); 305 | free(r_pat); 306 | if (!EXITONERROR) { 307 | errno = AGREP_ERROR; 308 | return -1; 309 | } 310 | else exit(2); 311 | } 312 | if(RE_ERR) { 313 | fprintf(stderr, "%s: illegal regular expression\n", Progname); 314 | free(r_pat); 315 | if (!EXITONERROR) { 316 | errno = AGREP_ERROR; 317 | return -1; 318 | } 319 | else exit(2); 320 | } 321 | while(*Pattern != NOCARE && m-- > 0) Pattern++; /* poit to . */ 322 | num_pos = init(r_pat, table); 323 | if(num_pos <= 0) { 324 | fprintf(stderr, "%s: illegal regular expression\n", Progname); 325 | free(r_pat); 326 | if (!EXITONERROR) { 327 | errno = AGREP_ERROR; 328 | return -1; 329 | } 330 | else exit(2); 331 | } 332 | if(num_pos > MAXREG) { 333 | fprintf(stderr, "%s: regular expression too long, max is %d\n", Progname,MAXREG); 334 | free(r_pat); 335 | if (!EXITONERROR) { 336 | errno = AGREP_ERROR; 337 | return -1; 338 | } 339 | else exit(2); 340 | } 341 | strcpy(old_pat, Pattern); /* do real change to the Pattern to be returned */ 342 | free(r_pat); 343 | return 0; 344 | } /* if regex */ 345 | 346 | free(r_pat); 347 | return 0; 348 | } 349 | 350 | -------------------------------------------------------------------------------- /putils.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Burra Gopal, Udi Manber. All Rights Reserved. */ 2 | 3 | #include "agrep.h" 4 | 5 | int 6 | is_complex_boolean(buffer, len) 7 | CHAR *buffer; 8 | int len; 9 | { 10 | int i = 0; 11 | CHAR cur = '\0'; 12 | 13 | while (i < len) { 14 | if (buffer[i] == '\\') i+=2; 15 | else if (buffer[i] == ',') { 16 | if ((cur == ';') || (cur == '~')) return 1; 17 | else cur = ','; 18 | i++; 19 | } 20 | else if (buffer[i] == ';') { 21 | if ((cur == ',') || (cur == '~')) return 1; 22 | else cur = ';'; 23 | i++; 24 | } 25 | /* else if ((buffer[i] == '~') || (buffer[i] == '{') || (buffer[i] == '}')) { */ 26 | else if (buffer[i] == '~') { 27 | /* even if pattern has just ~s... user must use -v option for single NOT */ 28 | return 1; 29 | } 30 | else i++; 31 | } 32 | return 0; 33 | } 34 | 35 | /* The possible tokens are: ; , a e ~ { } */ 36 | int 37 | get_token_bool(buffer, len, ptr, tokenbuf, tokenlen) 38 | CHAR *buffer, *tokenbuf; 39 | int len, *ptr, *tokenlen; 40 | { 41 | if ((*ptr>=len) || (buffer[*ptr] == '\n') || (buffer[*ptr] == '\0')) return 'e'; 42 | while ((*ptr=len) || (buffer[*ptr] == '\n') || (buffer[*ptr] == '\0')) return 'e'; 44 | if ((buffer[*ptr] == ',') || (buffer[*ptr] == ';') || (buffer[*ptr] == '~') || (buffer[*ptr] == '{') || (buffer[*ptr] == '}')) { 45 | tokenbuf[0] = buffer[*ptr]; 46 | *tokenlen = 1; 47 | return buffer[(*ptr)++]; 48 | } 49 | *tokenlen = 0; 50 | if (buffer[*ptr] == '\\') { 51 | tokenbuf[(*tokenlen)++] = buffer[(*ptr)++]; 52 | tokenbuf[(*tokenlen)++] = buffer[(*ptr)++]; 53 | } 54 | else tokenbuf[(*tokenlen)++] = buffer[(*ptr)++]; 55 | while ( (*ptr= len) */ 66 | } 67 | 68 | void 69 | print_tree(t, level) 70 | ParseTree *t; 71 | { 72 | int i; 73 | 74 | if (t == NULL) printf("NULL"); 75 | else if (t->type == LEAF) { 76 | for (i=0; iop, t->terminalindex, t->data.leaf.value); 78 | } 79 | else if (t->type == INTERNAL) { 80 | if (t->data.internal.left != NULL) print_tree(t->data.internal.left, level + 1); 81 | for (i=0; iop); 83 | if (t->data.internal.right != NULL) print_tree(t->data.internal.right, level + 1); 84 | } 85 | } 86 | 87 | void 88 | destroy_tree(t) 89 | ParseTree *t; 90 | { 91 | if (t == NULL) return; 92 | if (t->type == LEAF) { 93 | free(t->data.leaf.value); /* t itself should not be freed: static allocation */ 94 | } 95 | else if (t->type == INTERNAL) { 96 | if (t->data.internal.left != NULL) destroy_tree(t->data.internal.left); 97 | if (t->data.internal.right != NULL) destroy_tree(t->data.internal.right); 98 | free(t); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /re.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* 09.09.96 T.Gries new definition of ASCII_MAX 4 | allows the fully ISO-Charset. 5 | */ 6 | 7 | /************************************************************* 8 | * * 9 | * Macros defining special characters. * 10 | * * 11 | *************************************************************/ 12 | 13 | #define NUL '\0' 14 | #define ASCII_MIN '\001' 15 | #define ASCII_MAX '\377' /* changed by TG. Orginal value was \177 */ 16 | 17 | /************************************************************* 18 | * * 19 | * Macros defining lexical categories. * 20 | * * 21 | *************************************************************/ 22 | 23 | #define C_LIT 0 /* individual character literal */ 24 | #define C_SET 1 /* character set literal */ 25 | 26 | #define EOS 0 /* end-of-string */ 27 | #define LITERAL 1 28 | #define OPSTAR 2 29 | #define OPALT 3 30 | #define OPOPT 4 31 | #define OPCAT 5 32 | #define LPAREN 6 33 | #define RPAREN 7 34 | 35 | /************************************************************* 36 | * * 37 | * Macros for manipulating syntax tree nodes. * 38 | * * 39 | *************************************************************/ 40 | 41 | #define lit_type(x) (x->l_type) 42 | #define lit_pos(x) (x->pos) 43 | #define lit_char(x) ((x->val).c) 44 | #define lit_cset(x) ((x->val).cset) 45 | 46 | #define tok_type(x) (x->type) 47 | #define tok_val(x) (x->val) 48 | #define tok_op(x) (x->val->op) 49 | #define tok_lit(x) ((x->val->refs).lit) 50 | 51 | #define Op(x) (x->op) 52 | #define Lit(x) ((x->refs).lit) 53 | #define Child(x) ((x->refs).child) 54 | #define Lchild(x) ((x->refs).children.l_child) 55 | #define Rchild(x) ((x->refs).children.r_child) 56 | #define Nullable(x) (x->nullable) 57 | #define Firstpos(x) (x->firstposn) 58 | #define Lastpos(x) (x->lastposn) 59 | 60 | /************************************************************* 61 | * * 62 | * Macros for manipulating DFA states and sets of states. * 63 | * * 64 | *************************************************************/ 65 | 66 | #define Positions(x) (x->posns) 67 | #define Final_St(x) (x->final) 68 | #define Goto(x, c) ((x->trans)[c]) 69 | #define Next_State(x) ((x)->next_state) 70 | 71 | /*************************************************************/ 72 | 73 | #define new_node(type, l, x) \ 74 | {\ 75 | extern void *malloc();\ 76 | \ 77 | (l) = (type) malloc(sizeof(*(x)));\ 78 | if ((l) == NULL) {\ 79 | fprintf(stderr, "malloc failure in new_node\n");\ 80 | exit(2);\ 81 | }\ 82 | memset((l), '\0', sizeof(*(x)));\ 83 | } 84 | 85 | typedef struct { /* character range literals */ 86 | char low_bd, hi_bd; 87 | } *Ch_Range; 88 | 89 | typedef struct ch_set { /* character set literals */ 90 | Ch_Range elt; /* rep. as list of ranges */ 91 | struct ch_set *rest; 92 | } *Ch_Set; 93 | 94 | typedef struct { /* regular expression literal */ 95 | int pos; /* position in syntax tree */ 96 | short l_type; /* type of literal */ 97 | union { 98 | char c; /* for character literals */ 99 | Ch_Set cset; /* for character sets */ 100 | } val; 101 | } *Re_Lit, *(*Re_lit_array)[]; 102 | 103 | typedef struct pnode { 104 | int posnum; 105 | struct pnode *nextpos; 106 | } *Pset, *(*Pset_array)[]; 107 | 108 | typedef struct rnode { /* regular expression node */ 109 | short op; /* operator at that node */ 110 | union { 111 | Re_Lit lit; /* child is a leaf node */ 112 | struct rnode *child; /* child of unary op */ 113 | struct { 114 | struct rnode *l_child; 115 | struct rnode *r_child; 116 | } children; /* children of binary op */ 117 | } refs; 118 | short nullable; 119 | Pset firstposn, lastposn; 120 | } *Re_node; 121 | 122 | typedef struct { /* token node */ 123 | short type; 124 | Re_node val; 125 | } *Tok_node; 126 | 127 | 128 | typedef struct snode { 129 | Re_node val; 130 | int size; 131 | struct snode *next; 132 | } *Stack; 133 | 134 | typedef struct dfa_st { 135 | Pset posns; 136 | int final; /* 1 if the state is a final state, 0 o/w */ 137 | struct dfa_st *trans[128]; 138 | } *Dfa_state; 139 | 140 | typedef struct dfa_stset { 141 | Dfa_state st; 142 | struct dfa_stset *next_state; 143 | } *Dfa_state_set; 144 | 145 | -------------------------------------------------------------------------------- /recursiv.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | 3 | /* Burra Gopal: 4 | 5 | The function of the program is to traverse the 6 | 7 | This program is derived from the C-programming language book 8 | 9 | Originally, the program opens a directory file as a regular file. 10 | But it won't work. 11 | 12 | We have to open a directory file using opendir() system call, 13 | and use readdir() to read each entry of the directory. 14 | 15 | 16 | [chg] T.Gries 11.08.96 17 | 18 | */ 19 | 20 | /* #define REC_DIAG */ 21 | 22 | #include "autoconf.h" /* ../libtemplate/include */ 23 | #include 24 | #include 25 | 26 | #if ISO_CHAR_SET 27 | #include 28 | #endif 29 | 30 | #if HAVE_DIRENT_H 31 | 32 | #ifndef _WIN32 33 | # include 34 | #else 35 | # include "ntdirent.h" 36 | #endif 37 | # define NAMLEN(dirent) strlen((dirent)->d_name) 38 | #else 39 | # define dirent direct 40 | # define NAMLEN(dirent) (dirent)->d_namlen 41 | 42 | # if HAVE_SYS_NDIR_H 43 | # include 44 | # endif 45 | 46 | # if HAVE_SYS_DIR_H 47 | # include 48 | # endif 49 | 50 | # if HAVE_NDIR_H 51 | # include 52 | # endif 53 | 54 | #endif 55 | 56 | #ifdef __APPLE__ 57 | #include 58 | #endif 59 | 60 | #ifdef _WIN32 61 | #include "config.h" 62 | #include 63 | #include 64 | #include 65 | #include 66 | int exec(); /* agrep.c */ 67 | #endif 68 | 69 | /* 70 | * #include 71 | */ 72 | #include 73 | #define BUFSIZE 256 74 | #define DIRSIZE 14 75 | #define max_list 10 76 | 77 | #ifndef S_ISREG 78 | #define S_ISREG(mode) (0100000&(mode)) 79 | #endif 80 | 81 | #ifndef S_ISDIR 82 | #define S_ISDIR(mode) (0040000&(mode)) 83 | #endif 84 | 85 | /* TG 28.04.04 */ 86 | /* TG 2013032 */ 87 | #ifndef S_IFDIR 88 | #define S_IFDIR __S_IFDIR 89 | #endif 90 | 91 | #ifndef S_IFMT 92 | #define S_IFMT __S_IFMT 93 | #endif 94 | 95 | char *file_list[max_list*2]; 96 | int fdx=0; /* index of file_List */ 97 | extern int Numfiles; 98 | char name_buf[BUFSIZE]; 99 | 100 | void directory(); 101 | static void treewalk(); 102 | 103 | /* returns -1 if error, num of matches >= 0 otherwise */ 104 | 105 | int 106 | recursive(argc, argv) 107 | 108 | int argc; 109 | char **argv; 110 | { 111 | int i,j; 112 | int num = 0, ret; 113 | 114 | for(i=0; i< argc; i++) { 115 | 116 | /* printf("RECURSIVE: I= %d = %s\n",i,argv[i]); */ 117 | 118 | strcpy(name_buf, argv[i]); 119 | treewalk(name_buf); 120 | 121 | if(fdx > 0) { 122 | Numfiles = fdx; 123 | if ((ret = exec(3, file_list)) == -1) return -1; 124 | num += ret; 125 | for(j=0; j 0) { 151 | strcpy(buf, *++argv); 152 | treewalk(buf); 153 | } 154 | } 155 | */ 156 | 157 | static void 158 | treewalk(name) 159 | 160 | char *name; 161 | { 162 | struct stat stbuf; 163 | int i; 164 | extern void *malloc(); 165 | 166 | #ifdef REC_DIAG 167 | printf(" In treewalk. name= %s\n",name); 168 | #endif 169 | 170 | #ifndef _WIN32 171 | if(lstat(name, &stbuf) == -1) { 172 | #else 173 | if(stat(name, &stbuf) != 0) { 174 | #endif 175 | fprintf(stderr, "permission denied or non-existent: %s\n", name); 176 | return; 177 | } 178 | #ifndef _WIN32 179 | if ((stbuf.st_mode & S_IFMT) == S_IFLNK) { 180 | 181 | #ifdef REC_DIAG 182 | fprintf(stderr, "S_IFLNK %s",name); 183 | #endif 184 | 185 | return; 186 | } 187 | #endif 188 | if (( stbuf.st_mode & S_IFMT) == S_IFDIR) { 189 | 190 | #ifdef REC_DIAG 191 | fprintf(stderr, "S_IFDIR %s",name); 192 | #endif 193 | 194 | directory(name); 195 | } 196 | else { 197 | file_list[fdx] = (char *)malloc(BUFSIZE); 198 | strcpy(file_list[fdx++], name); 199 | 200 | #ifdef REC_DIAG 201 | printf(" %s\n", name); 202 | #endif 203 | if(fdx >= max_list) { 204 | Numfiles = fdx; 205 | exec(3, file_list); 206 | for(i=0; i= name+BUFSIZE ) /* name too long */ 227 | { 228 | fprintf(stderr, "name too long: %.32s...\n", name); 229 | return; 230 | } 231 | 232 | if((dirp = opendir(name)) == NULL) { 233 | fprintf(stderr, "permission denied: %s\n", name); 234 | return; 235 | } 236 | 237 | *nbp++ = '/'; 238 | *nbp = '\0'; 239 | for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { 240 | 241 | if (dp->d_name[0] == '\0' || strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..")==0) 242 | goto CONT; 243 | 244 | #ifdef REC_DIAG 245 | printf("dp->d_name = %s\n", dp->d_name); 246 | #endif 247 | 248 | strcpy(nbp, dp->d_name); 249 | treewalk(name); 250 | CONT: 251 | ; 252 | } 253 | closedir (dirp); 254 | *--nbp = '\0'; /* restore name */ 255 | } 256 | -------------------------------------------------------------------------------- /recursive.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* The function of the program is to traverse the 3 | direcctory tree and collect paath names. 4 | This program is derived from the C-programming language book 5 | Originally, the program open a directory file as a regular file. But 6 | it won't work. We have to open a directory file using 7 | opendir system call, and use readdir() to read each entry of the 8 | directory. 9 | */ 10 | 11 | #include "autoconf.h" /* ../libtemplate/include */ 12 | #include 13 | #include 14 | #if ISO_CHAR_SET 15 | #include 16 | #endif 17 | 18 | #if HAVE_DIRENT_H 19 | # include 20 | # define NAMLEN(dirent) strlen((dirent)->d_name) 21 | #else 22 | # define dirent direct 23 | # define NAMLEN(dirent) (dirent)->d_namlen 24 | # if HAVE_SYS_NDIR_H 25 | # include 26 | # endif 27 | # if HAVE_SYS_DIR_H 28 | # include 29 | # endif 30 | # if HAVE_NDIR_H 31 | # include 32 | # endif 33 | #endif 34 | 35 | #include 36 | #include 37 | #define BUFSIZE 256 38 | #define DIRSIZE 14 39 | #define max_list 10 40 | 41 | #ifndef S_ISREG 42 | #define S_ISREG(mode) (0100000&(mode)) 43 | #endif 44 | 45 | #ifndef S_ISDIR 46 | #define S_ISDIR(mode) (0040000&(mode)) 47 | #endif 48 | 49 | char *file_list[max_list*2]; 50 | int fdx=0; /* index of file_List */ 51 | extern int Numfiles; 52 | char name_buf[BUFSIZE]; 53 | 54 | void directory(); 55 | static void treewalk(); 56 | 57 | /* returns -1 if error, num of matches >= 0 otherwise */ 58 | int 59 | recursive(argc, argv) 60 | int argc; 61 | char **argv; 62 | { 63 | int i,j; 64 | int num = 0, ret; 65 | 66 | for(i=0; i< argc; i++) { 67 | strcpy(name_buf, argv[i]); 68 | treewalk(name_buf); 69 | if(fdx > 0) { 70 | Numfiles = fdx; 71 | if ((ret = exec(3, file_list)) == -1) return -1; 72 | num += ret; 73 | for(j=0; j 0) { 99 | strcpy(buf, *++argv); 100 | treewalk(buf); 101 | } 102 | } 103 | */ 104 | 105 | static void 106 | treewalk(name) 107 | char *name; 108 | { 109 | struct stat stbuf; 110 | int i; 111 | extern void *malloc(); 112 | 113 | /* printf(" In treewalk\n"); */ 114 | if(my_lstat(name, &stbuf) == -1) { 115 | fprintf(stderr, "permission denied or non-existent: %s\n", name); 116 | return; 117 | } 118 | if ((stbuf.st_mode & S_IFMT) == S_IFLNK) { 119 | return; 120 | } 121 | if (( stbuf.st_mode & S_IFMT) == S_IFDIR) 122 | directory(name); 123 | else { 124 | file_list[fdx] = (char *)malloc(BUFSIZE); 125 | strcpy(file_list[fdx++], name); 126 | /* printf(" %s\n", name); */ 127 | if(fdx >= max_list) { 128 | Numfiles = fdx; 129 | exec(3, file_list); 130 | for(i=0; i= name+BUFSIZE ) /* name too long */ 149 | { 150 | fprintf(stderr, "name too long: %.32s...\n", name); 151 | return; 152 | } 153 | if((dirp = opendir(name)) == NULL) { 154 | fprintf(stderr, "permission denied: %s\n", name); 155 | return; 156 | } 157 | *nbp++ = '/'; 158 | *nbp = '\0'; 159 | for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { 160 | if (dp->d_name[0] == '\0' || strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..")==0) 161 | goto CONT; 162 | /* 163 | printf("dp->d_name = %s\n", dp->d_name); 164 | */ 165 | strcpy(nbp, dp->d_name); 166 | treewalk(name); 167 | CONT: 168 | ; 169 | } 170 | closedir (dirp); 171 | *--nbp = '\0'; /* restore name */ 172 | } 173 | -------------------------------------------------------------------------------- /resources/agrep.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Wikinaut/agrep/6394ed8a8cb5f0996cf277f03e62f62de070c947/resources/agrep.gif -------------------------------------------------------------------------------- /unistd.h: -------------------------------------------------------------------------------- 1 | /* unistd.h (emx+gcc) */ 2 | 3 | #if !defined (_UNISTD_H) 4 | #define _UNISTD_H 5 | 6 | #if defined (__cplusplus) 7 | extern "C" { 8 | #endif 9 | 10 | #if defined (_POSIX_C_SOURCE) && !defined (_POSIX_SOURCE) 11 | #define _POSIX_SOURCE 12 | #endif 13 | 14 | #if !defined (_SIZE_T) 15 | #define _SIZE_T 16 | typedef unsigned long size_t; 17 | #endif 18 | 19 | #if !defined (_SSIZE_T) 20 | #define _SSIZE_T 21 | typedef int ssize_t; 22 | #endif 23 | 24 | #if !defined (NULL) 25 | #define NULL ((void *)0) 26 | #endif 27 | 28 | #if !defined (STDIN_FILENO) 29 | #define STDIN_FILENO 0 30 | #define STDOUT_FILENO 1 31 | #define STDERR_FILENO 2 32 | #endif 33 | 34 | #if !defined (F_OK) 35 | #define F_OK 0 36 | #define X_OK 1 37 | #define W_OK 2 38 | #define R_OK 4 39 | #endif 40 | 41 | #if !defined (SEEK_SET) 42 | #define SEEK_SET 0 43 | #define SEEK_CUR 1 44 | #define SEEK_END 2 45 | #endif 46 | 47 | #if !defined (_PC_LINK_MAX) 48 | #define _PC_LINK_MAX 1 49 | #define _PC_MAX_CANON 2 50 | #define _PC_MAX_INPUT 3 51 | #define _PC_NAME_MAX 4 52 | #define _PC_PATH_MAX 5 53 | #define _PC_PIPE_BUF 6 54 | #define _PC_CHOWN_RESTRICTED 7 55 | #define _PC_NO_TRUNC 8 56 | #define _PC_VDISABLE 9 57 | #endif 58 | 59 | #if !defined (_SC_ARG_MAX) 60 | #define _SC_ARG_MAX 1 61 | #define _SC_CHILD_MAX 2 62 | #define _SC_CLK_TCK 3 63 | #define _SC_NGROUPS_MAX 4 64 | #define _SC_OPEN_MAX 5 65 | #define _SC_STREAM_MAX 6 66 | #define _SC_TZNAME_MAX 7 67 | #define _SC_JOB_CONTROL 8 68 | #define _SC_SAVED_IDS 9 69 | #define _SC_VERSION 10 70 | #endif 71 | 72 | #if !defined (_POSIX_VERSION) 73 | #define _POSIX_VERSION 199009L 74 | #endif 75 | 76 | 77 | int access (__const__ char *name, int mode); 78 | unsigned alarm (unsigned sec); 79 | int chdir (__const__ char *name); 80 | /* chown() */ 81 | int close (int handle); 82 | /* ctermid() */ 83 | char *cuserid (char *buffer); 84 | int dup (int handle); 85 | int dup2 (int handle1, int handle2); 86 | int execl (__const__ char *name, __const__ char *arg0, ...); 87 | int execle (__const__ char *name, __const__ char *arg0, ...); 88 | int execlp (__const__ char *name, __const__ char *arg0, ...); 89 | int execv (__const__ char *name, char * __const__ argv[]); 90 | int execve (__const__ char *name, char * __const__ argv[], 91 | char * __const__ envp[]); 92 | int execvp (__const__ char *name, char * __const__ argv[]); 93 | void _exit (int ret) __attribute__ ((__noreturn__)); 94 | int fork (void); 95 | long fpathconf (int handle, int name); 96 | char *getcwd (char *buffer, size_t size); 97 | int getegid (void); /* gid_t getegid (void); */ 98 | int geteuid (void); /* uid_t geteuid (void); */ 99 | int getgid (void); /* gid_t getgid (void); */ 100 | /* int getgroups (int gidsetsize, gid_t grouplist[]); */ 101 | int getgroups (int gidsetsize, int grouplist[]); 102 | char *getlogin (void); 103 | int getpgrp (void); /* pid_t getpgrp (void); */ 104 | int getpid (void); /* pid_t getpid (void); */ 105 | int getppid (void); /* pid_t getppid (void); */ 106 | int getuid (void); /* uid_t getuid (void); */ 107 | int isatty (int handle); 108 | /* link() */ 109 | long lseek (int handle, long offset, int origin); 110 | long pathconf (__const__ char *path, int name); 111 | int pause (void); 112 | int pipe (int *two_handles); 113 | int read (int handle, void *buf, size_t nbyte); 114 | int rmdir (__const__ char *name); 115 | int setgid (int gid); /* int setsid (gid_t gid); */ 116 | int setpgid (int pid, int pgid); /* int setpgid (gid_t pid, gid_t pgid); */ 117 | int setsid (void); /* pid_t setsid (void); */ 118 | int setuid (int uid); /* setuid (uid_t uid); */ 119 | unsigned sleep (unsigned sec); 120 | long sysconf (int name); 121 | int tcgetpgrp (int fd); /* pid_t tcgetpgrp (int fd); */ 122 | int tcsetpgrp (int fd, int pgrp); /* int tcsetpgrp (int fd, pid_t pgrp) */ 123 | /* ttyname() */ 124 | int unlink (__const__ char *name); 125 | int write (int handle, __const__ void *buf, size_t nbyte); 126 | 127 | 128 | #if !defined (_POSIX_SOURCE) 129 | 130 | char *getpass (__const__ char *prompt); 131 | char *_getpass1 (__const__ char *prompt); 132 | char *_getpass2 (__const__ char *prompt, int kbd); 133 | 134 | #endif 135 | 136 | 137 | #if !defined (_POSIX_SOURCE) || _POSIX_C_SOURCE >= 2 138 | 139 | extern char *optarg; 140 | extern int optind; 141 | extern int opterr; 142 | extern int optopt; 143 | 144 | /* Note: `argv' is not const as GETOPT_ANY reorders argv[]. */ 145 | 146 | int getopt (int argc, char * argv[], __const__ char *opt_str); 147 | 148 | #endif 149 | 150 | #if defined (__cplusplus) 151 | } 152 | #endif 153 | 154 | #endif /* !defined (_UNISTD_H) */ 155 |  -------------------------------------------------------------------------------- /utilitie.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */ 2 | /* this file contains various utility functions for accessing 3 | and manipulating regular expression syntax trees. */ 4 | 5 | #include 6 | #include 7 | #include "re.h" 8 | 9 | #ifdef _WIN32 10 | #include 11 | #include 12 | #include 13 | #endif 14 | 15 | /************************************************************************/ 16 | /* */ 17 | /* the following routines implement an abstract data type "stack". */ 18 | /* */ 19 | /************************************************************************/ 20 | 21 | Stack Push(s, v) 22 | Stack *s; 23 | Re_node v; 24 | { 25 | Stack node; 26 | 27 | new_node(Stack, node, node); 28 | if (s == NULL || node == NULL) return NULL; /* can't allocate */ 29 | node->next = *s; 30 | node->val = v; 31 | if (*s == NULL) node->size = 1; 32 | else node->size = (*s)->size + 1; 33 | *s = node; 34 | return *s; 35 | } 36 | 37 | Re_node Pop(s) 38 | Stack *s; 39 | { 40 | Re_node node; 41 | Stack temp; 42 | 43 | if (s == NULL || *s == NULL) return NULL; 44 | else { 45 | temp = *s; 46 | node = (*s)->val; 47 | *s = (*s)->next; 48 | free(temp); 49 | return node; 50 | } 51 | } 52 | 53 | Re_node Top(s) 54 | Stack s; 55 | { 56 | if (s == NULL) return NULL; 57 | else return s->val; 58 | } 59 | 60 | int Size(s) 61 | Stack s; 62 | { 63 | if (s == NULL) return 0; 64 | else return s->size; 65 | } 66 | 67 | /************************************************************************/ 68 | /* */ 69 | /* the following routines manipulate sets of positions. */ 70 | /* */ 71 | /************************************************************************/ 72 | 73 | int occurs_in(n, p) 74 | int n; 75 | Pset p; 76 | { 77 | while (p != NULL) 78 | if (n == p->posnum) return 1; 79 | else p = p->nextpos; 80 | return 0; 81 | } 82 | 83 | /* pset_union() takes two position-sets and returns their union. */ 84 | 85 | Pset pset_union(s1, s2) 86 | Pset s1, s2; 87 | { 88 | Pset hd, curr, new = NULL; 89 | 90 | hd = NULL; 91 | curr = NULL; 92 | while (s1 != NULL) { 93 | if (!occurs_in(s1->posnum, s2)) { 94 | new_node(Pset, new, new); 95 | if (new == NULL) return NULL; 96 | new->posnum = s1->posnum; 97 | if (hd == NULL) hd = new; 98 | else curr->nextpos = new; 99 | } 100 | curr = new; 101 | s1 = s1->nextpos; 102 | } 103 | if (hd == NULL) hd = s2; 104 | else curr->nextpos = s2; 105 | return hd; 106 | } 107 | 108 | /* create_pos() creates a position node with the position value given, 109 | then returns a pointer to this node. */ 110 | 111 | Pset create_pos(n) 112 | int n; 113 | { 114 | Pset x; 115 | 116 | new_node(Pset, x, x); 117 | if (x == NULL) return NULL; 118 | x->posnum = n; 119 | x->nextpos = NULL; 120 | return x; 121 | } 122 | 123 | /* eq_pset() takes two position sets and checks to see if they are 124 | equal. It returns 1 if the sets are equal, 0 if they are not. */ 125 | int 126 | subset_pset(s1, s2) 127 | Pset s1, s2; 128 | { 129 | int subs = 1; 130 | 131 | while (s1 != NULL && subs != 0) { 132 | subs = 0; 133 | while (s2 != NULL && subs != 1) 134 | if (s1->posnum == s2->posnum) subs = 1; 135 | else s2 = s2->nextpos; 136 | s1 = s1->nextpos; 137 | } 138 | return subs; 139 | } 140 | 141 | int eq_pset(s1, s2) 142 | Pset s1, s2; 143 | { 144 | return subset_pset(s1, s2) && subset_pset(s2, s1); 145 | } 146 | 147 | int 148 | word_exists(word, wordlen, line, linelen) 149 | unsigned char *word, *line; 150 | int wordlen, linelen; 151 | { 152 | unsigned char oldchar, *lineend = line+linelen; 153 | int i; 154 | 155 | i = 0; 156 | while(line 6 | #include 7 | #include "re.h" 8 | 9 | /************************************************************************/ 10 | /* */ 11 | /* the following routines implement an abstract data type "stack". */ 12 | /* */ 13 | /************************************************************************/ 14 | 15 | Stack Push(s, v) 16 | Stack *s; 17 | Re_node v; 18 | { 19 | Stack node; 20 | 21 | new_node(Stack, node, node); 22 | if (s == NULL || node == NULL) return NULL; /* can't allocate */ 23 | node->next = *s; 24 | node->val = v; 25 | if (*s == NULL) node->size = 1; 26 | else node->size = (*s)->size + 1; 27 | *s = node; 28 | return *s; 29 | } 30 | 31 | Re_node Pop(s) 32 | Stack *s; 33 | { 34 | Re_node node; 35 | Stack temp; 36 | 37 | if (s == NULL || *s == NULL) return NULL; 38 | else { 39 | temp = *s; 40 | node = (*s)->val; 41 | *s = (*s)->next; 42 | free(temp); 43 | return node; 44 | } 45 | } 46 | 47 | Re_node Top(s) 48 | Stack s; 49 | { 50 | if (s == NULL) return NULL; 51 | else return s->val; 52 | } 53 | 54 | int Size(s) 55 | Stack s; 56 | { 57 | if (s == NULL) return 0; 58 | else return s->size; 59 | } 60 | 61 | /************************************************************************/ 62 | /* */ 63 | /* the following routines manipulate sets of positions. */ 64 | /* */ 65 | /************************************************************************/ 66 | 67 | int occurs_in(n, p) 68 | int n; 69 | Pset p; 70 | { 71 | while (p != NULL) 72 | if (n == p->posnum) return 1; 73 | else p = p->nextpos; 74 | return 0; 75 | } 76 | 77 | /* pset_union() takes two position-sets and returns their union. */ 78 | 79 | Pset pset_union(s1, s2, dontreplicate) 80 | Pset s1, s2; 81 | int dontreplicate; 82 | { 83 | Pset hd, curr, new = NULL; 84 | Pset replicas2 = NULL, temps2 = s2; /* code added: 26/Aug/96 */ 85 | 86 | /* Code added on 26/Aug/96 */ 87 | if (dontreplicate) replicas2 = s2; 88 | else while (temps2 != NULL) { 89 | new_node(Pset, new, new); 90 | if (new == NULL) return NULL; 91 | new->posnum = temps2->posnum; 92 | if (replicas2 == NULL) replicas2 = new; 93 | else curr->nextpos = new; 94 | curr = new; 95 | temps2 = temps2->nextpos; 96 | } 97 | 98 | hd = NULL; 99 | curr = NULL; 100 | while (s1 != NULL) { 101 | if (!occurs_in(s1->posnum, s2)) { 102 | new_node(Pset, new, new); 103 | if (new == NULL) return NULL; 104 | new->posnum = s1->posnum; 105 | if (hd == NULL) hd = new; 106 | else curr->nextpos = new; 107 | } 108 | curr = new; 109 | s1 = s1->nextpos; 110 | } 111 | if (hd == NULL) hd = replicas2; /* changed from s2: 26/Aug/96 */ 112 | else curr->nextpos = replicas2; /* changed from s2: 26/Aug/96 */ 113 | return hd; 114 | } 115 | 116 | /* create_pos() creates a position node with the position value given, 117 | then returns a pointer to this node. */ 118 | 119 | Pset create_pos(n) 120 | int n; 121 | { 122 | Pset x; 123 | 124 | new_node(Pset, x, x); 125 | if (x == NULL) return NULL; 126 | x->posnum = n; 127 | x->nextpos = NULL; 128 | return x; 129 | } 130 | 131 | /* eq_pset() takes two position sets and checks to see if they are 132 | equal. It returns 1 if the sets are equal, 0 if they are not. */ 133 | int 134 | subset_pset(s1, s2) 135 | Pset s1, s2; 136 | { 137 | int subs = 1; 138 | 139 | while (s1 != NULL && subs != 0) { 140 | subs = 0; 141 | while (s2 != NULL && subs != 1) 142 | if (s1->posnum == s2->posnum) subs = 1; 143 | else s2 = s2->nextpos; 144 | s1 = s1->nextpos; 145 | } 146 | return subs; 147 | } 148 | 149 | int eq_pset(s1, s2) 150 | Pset s1, s2; 151 | { 152 | return subset_pset(s1, s2) && subset_pset(s2, s1); 153 | } 154 | 155 | int 156 | word_exists(word, wordlen, line, linelen) 157 | unsigned char *word, *line; 158 | int wordlen, linelen; 159 | { 160 | unsigned char oldchar, *lineend = line+linelen; 161 | int i; 162 | 163 | i = 0; 164 | while(line *" and there are 17 | no files in that subdirectory, 18 | the 3.32 has waited for stdin (=haystack, target). 19 | [chg] compiled with emx 0.9c 20 | [new] using EMX.EXE or RSX.EXE allows to run AGREP in DOS boxes 21 | under Windows or OS/2 22 | 23 | [chg] 15.01.97 3.32 new links, helppage revised 24 | [new] 16.12.96 3.31 new subswitch -i0 25 | [chg] 16.10.96 3.30 constant unsigned _emx_env 26 | [chg] 14.10.96 3.29 nicer help pages; not running under DOS/OS2 messages 27 | [fix] 3.28 bug fixed with metasymb[0] 28 | [chg] 13.10.96 3.27 improved navigation through the help pages 29 | [new] 11.10.96 3.26 _read_kbd() while browsing through the help pages 30 | 'q' or 'Q' quitts immediately 31 | [fix] 10.10.96 3.25 sgrep.c: output problems at buffer end fixed 32 | (not at the end of file) 33 | [fix] 08.10.96 3.23 codepage detection when compiled for DOS returns -1 now 34 | [fix] 3.22 -w bug repaired (in since 3.17) 35 | [new] 07.10.96 3.21 verbose options -V[0123V] 36 | [new] 06.10.96 3.20 multi-codepage support 37 | [new] 05.10.96 3.19 using environment variable AGREPOPTS 38 | [chg] 04.10.96 3.17 major bugs fixed in Boyer-Moore bm() in sgrep.c 39 | [new] 23.09.96 3.11 option -i0 40 | [chg] 3.10 in AGREP.H, ISO_CHAR.H, AGREP.C 41 | handling of meta symbols 42 | [fix] 22.09.96 3.09 in BITAP.C (type CHAR) 43 | [new] in AGREP.C (Grand Total) 44 | [chg]TG 16.09.96 3.08 un-commenting code defined in OUTPUT_OVERFLOW 45 | 46 | */ 47 | 48 | #define AGREP_VERSION "3.41.5/TG" 49 | 50 | #ifdef __DOS 51 | #define AGREP_OS "DOS" 52 | #endif 53 | 54 | #ifdef __OS2 55 | #define AGREP_OS "OS/2" 56 | #endif 57 | 58 | #ifdef __RSX 59 | #define AGREP_OS "VPMI" 60 | #endif 61 | 62 | #ifdef _WIN32 63 | #define AGREP_OS "WIN32" 64 | #endif 65 | 66 | #ifndef AGREP_OS 67 | #define AGREP_OS "NATIVE LINUX" 68 | #endif 69 | 70 | 71 | #define AGREP_DATE __DATE__ 72 | 73 | #define AGREP_VERSION_STRING "AGREP "AGREP_VERSION" for "AGREP_OS" compiled with GCC "__VERSION__" ("__DATE__" "__TIME__"). Manber/Wu/Gries et al." 74 | --------------------------------------------------------------------------------