home *** CD-ROM | disk | FTP | other *** search
- TUG PDS CERT 1.01 (Documentation)
-
- ==========================================================================
-
- TUG PUBLIC DOMAIN SOFTWARE CERTIFICATION
-
- The Turbo User Group (TUG) is recognized by Borland International as the
- official support organization for Turbo languages. This file has been
- verified by the TUG library staff. We are reasonably certain that the
- information contained in this file is public domain material, but
- it is also subject to any restrictions applied by its author.
-
- This diskette contains information determined to be in the PUBLIC
- DOMAIN, provided as a service of TUG for the use of its members. The
- Turbo User Group will not be liable for any damages, including any lost
- profits, lost savings or other incidental or consequential damages arising
- out of the use of or inability to use the contents, even if TUG has been
- advised of the possibility of such damages, or for any claim by any
- other party.
-
- To the best of our knowledge, the information in this file is accurate.
-
- If you discover an error in this file, we would appreciate it if you would
- report it to us. To report bugs, or to request information on membership
- in TUG, please contact us at:
-
- Turbo User Group
- PO Box 1510
- Poulsbo, Washington USA 98370
-
- --------------------------------------------------------------------------
- F i l e I n f o r m a t i o n
-
- * DESCRIPTION
- Documentation file for SEARCHES.PAS.
-
- * ASSOCIATED FILES
- SEARCHES.PAS
- BOYER.DOC
- SEARCHES.DOC
-
- * CHECKED BY
- DRM - 08/14/88
-
- * KEYWORDS
- TURBO PASCAL V4.0 DOCUMENTATION SEARCH INLINE
-
- ==========================================================================
- }
- { SEARCHES -- A unit for rapidly searching a buffer for a string.
-
- Version 1.00 - 10/26/1987 - Initial release
-
- Scott Bussinger
- Professional Practice Systems
- 110 South 131st Street
- Tacoma, WA 98444
- (206)531-8944
- Compuserve 72247,2671
-
- This UNIT for Turbo Pascal version 4.0 provides contains high speed
- routines for searching buffers for strings. To include this unit in your
- program add SEARCHES to the USES clause in your main program.
- The unit actually has two routines which do the same thing in different
- ways. The first is BlockPos which takes three parameters; a buffer
- containing the data be searched, the size of the buffer and the string to be
- searched for. This routine is written in assembly language with inline code
- and is very fast since it takes advantage of special comparison instructions
- in the 8086 instruction set. Note the the buffer is assumed to be based from
- a lower index of 1. The result is the offset of the match within the buffer.
- A failure to match returns a 0. This routine was originally written by Randy
- Forgaard for use with Turbo Pascal 3.0.
- The second search routine is based on the Boyer-Moore search algorithm and
- is coded strictly in Pascal. It is MUCH, MUCH slower than BlockPos and is
- included only because I felt like converting it and it doesn't hurt anything
- to include it in the unit. Actually, the Boyer-Moore algorithm is quite a
- good search algorithm for some cases but doesn't do very well here because
- BlockPos is written in assembly language and BoyerMoore isn't. I don't expect
- anyone will use this routine, but for those who want to, there are two steps
- to using the BoyerMoore routines. The first is to process the search string
- into a special form for the actual search routine itself. This procedure is
- called MakeBoyerTable and converts a string into a special record type called
- a BoyerTable. This need only be done once for a given search string. The
- second procedure is the search procedure itself and is called BoyerMoore. For
- parameters, it takes the buffer containing data to be searched, the size of
- that buffer, the starting location in the buffer (in case you want to continue
- a previous search from where you left off), and the BoyerTable you created
- using MakeBoyerTable. Again, the Buffer is assumed to be based from 1 and the
- result is the offset where the match was found (0 indicating not found).
- These routines are based on some routines written by Van Hall for Turbo Pascal
- 3.0 and I've included his original description of the Boyer-Moore algorithm in
- a separate file called BOYER.DOC for those who are interested.
- Note that in general, the buffer can contain any data and the search string
- need not be text but rather any data in a string form. For example, to search
- for a CR/LF sequence use #13#10 as the search string.
- You can compile this file to create a test program using these routines. It
- allows you to enter a search string and looks in this documentation file for
- the chosen string. }
-
- program Test;
-
- uses Searches;
-
- var Buffer: array[1..maxint] of char;
- Size: word;
- Fyle: file;
- Str: string;
- Table: BoyerTable;
-
- begin
- assign(Fyle,'SEARCHES.DOC');
- reset(Fyle,1);
- blockread(Fyle,Buffer,maxint,Size);
- close(Fyle);
- repeat
- write('String to search for:');
- readln(Str);
-
- writeln(' BlockPos = ',BlockPos(Buffer,Size,Str));
-
- MakeBoyerTable(Str,Table);
- writeln(' BoyerMoore = ',BoyerMoore(Buffer,Size,1,Table))
-
- until Str = ''
- end.