home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 277.lha / PatternLibrary / Pattern / test.d < prev    next >
Encoding:
Text File  |  1989-08-08  |  1.2 KB  |  53 lines

  1. #drinc:pattern.g
  2. #drinc:util.g
  3.  
  4. proc main()void:
  5.     [100] ulong comp, states;
  6.     [100] char pattern, subject;
  7.     register ulong i;
  8.     PatternState_t ps;
  9.     PatternCompileError_t err;
  10.  
  11.     if OpenPatternLibrary(0) ~= nil then
  12.     ps.ps_pattern := &pattern[0];
  13.     ps.ps_compiled := &comp[0];
  14.     ps.ps_activeStates := &states[0];
  15.     ps.ps_ignoreCase := true;
  16.     while
  17.         write("Pattern: ");
  18.         readln(&pattern[0]) and pattern[0] ~= '\e'
  19.     do
  20.         ps.ps_length := CharsLen(&pattern[0]);
  21.         Compile(&ps);
  22.         if ps.ps_error = pse_ok then
  23.         for i from 0 upto ps.ps_length do
  24.             write(comp[i], ' ');
  25.         od;
  26.         writeln();
  27.         while
  28.             write("Subject: ");
  29.             readln(&subject[0]) and subject[0] ~= '\e'
  30.         do
  31.             if Match(&ps, &subject[0], CharsLen(&subject[0])) then
  32.             writeln("Matched.");
  33.             else
  34.             writeln("Not matched.");
  35.             fi;
  36.         od;
  37.         else
  38.         case ps.ps_error
  39.         incase pse_missingPrimary:
  40.             writeln("Missing primary");
  41.         incase pse_unexpectedRightParen:
  42.             writeln("Unexpected right paren");
  43.         incase pse_unexpectedOr:
  44.             writeln("Unexecpted or");
  45.         incase pse_missingRightParen:
  46.             writeln("Missing right paren");
  47.         esac;
  48.         fi;
  49.     od;
  50.     ClosePatternLibrary();
  51.     fi;
  52. corp;
  53.