home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol237 / pilot-p.lbr / MATCH.PZ < prev    next >
Encoding:
Text File  |  1986-02-10  |  2.1 KB  |  77 lines

  1. PROCEDURE match( patterns : string255;    {these patterns           }
  2.          delim    : char;    {separated by this delimiter}
  3.          source   : string255;    {against this source string}
  4.            var status : boolean );    {returning this flag       }
  5. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6. LAST EDITED: 03/03/84 rep
  7.  
  8. RETURNS:
  9.     'status' true if any of the patterns appear in the source string.
  10.  
  11.  
  12. DECLARE:
  13.     TYPE  string0 = string 0;
  14.       string255 = string 255;
  15.  
  16.  CALL AS:
  17.     match ( 'YES!yes!NO!no', '!', ans,flag );
  18.     match ( $s, '!', ans,flag );
  19.  
  20.  Required:
  21.     function vlength();        from ASL.REL
  22.     procedure setlength();        Pascal/Z supplied extension.
  23.     function index();        Pascal/Z supplied extension.
  24. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  25. TYPE
  26.   nodeptr = ^node;
  27.   node    = record
  28.      data : STRING 18;    { MATCH MAXIMUM OF 18 CHARACTERS PER ARGUMENT }
  29.      next : nodeptr
  30.   end;
  31. VAR
  32.   i   : integer;
  33.   a,
  34.   root: nodeptr;
  35. {$C-,F-,R-,S-,M-}
  36. {
  37.     NAME    MATCH
  38.     ENTRY    MATCH
  39. }
  40. { setlength - forces the length of string 's' to length 'n' }
  41. PROCEDURE setlength ( VAR s: string0; n: integer ); external;
  42.  
  43. { vlength - returns length of ANY length string. super fast! }
  44. FUNCTION vlength ( VAR s: string0 ): integer; external;
  45.  
  46. { index - returns the position of pattern in source else 0 }
  47. FUNCTION index ( source,pattern: string255 ): integer; external;
  48. {
  49. MATCH:
  50. }
  51. BEGIN
  52.   root := NIL;
  53.   append(patterns,delim);
  54.   i := 0;
  55.   WHILE i<vlength(patterns) DO
  56.     BEGIN
  57.       new(a);            {allocate a new variable}
  58.       a^.next := root;        {ground it to the tree}
  59.       root := a;        {and run up the tree}
  60.       setlength(a^.data,0);    { data := '';    }
  61.       i := i+1;
  62.       WHILE NOT((i>vlength(patterns)) OR (patterns[i]=delim)) DO
  63.         BEGIN
  64.           append(a^.data,patterns[i]);
  65.           i := i+1
  66.         END
  67.     END;
  68.  
  69.   a := root;
  70.   status := false;
  71.   WHILE (a<>NIL) AND (status=false) DO
  72.     BEGIN
  73.       status := (index(source,a^.data)<>0);
  74.       a := a^.next
  75.     END
  76. END{match};
  77.