home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / stringsearch / bmsource / no.fwd.inc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-06  |  1.7 KB  |  87 lines  |  [TEXT/MPS ]

  1. /*
  2.     search routine generated by gen.
  3.     skip=no, match=fwd, shift=inc
  4. */
  5. /*
  6.  * The authors of this software are Andrew Hume and Daniel Sunday.
  7.  * 
  8.  * Copyright (c) 1991 by AT&T and Daniel Sunday.
  9.  * 
  10.  * Permission to use, copy, modify, and distribute this software for any
  11.  * purpose without fee is hereby granted, provided that this entire notice
  12.  * is included in all copies of any software which is or includes a copy
  13.  * or modification of this software and in all copies of the supporting
  14.  * documentation for such software.
  15.  * 
  16.  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
  18.  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  19.  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef    CHARTYPE
  23. #define    CHARTYPE    unsigned char
  24. #endif
  25. #define    MAXPAT    256
  26.  
  27. #include    "stats.h"
  28.  
  29. #ifndef    TABTYPE
  30. #define    TABTYPE    long
  31. #endif
  32. typedef TABTYPE Tab;
  33.  
  34. static struct
  35. {
  36.     int patlen;
  37.     CHARTYPE pat[MAXPAT];
  38. } pat;
  39.  
  40. prep(base, m)
  41.     CHARTYPE *base;
  42.     register m;
  43. {
  44.     CHARTYPE *skipc;
  45.  
  46.     pat.patlen = m;
  47.     if(m > MAXPAT)
  48.         abort();
  49.     memcpy(pat.pat, base, m);
  50.     skipc = 0;
  51.     stats.len = m;
  52. }
  53.  
  54. exec(base, n)
  55.     CHARTYPE *base;
  56. {
  57.     int nmatch = 0;
  58.     register CHARTYPE *e, *s;
  59.     register int s_offset;
  60.     register CHARTYPE *p, *q;
  61.     register CHARTYPE *ep;
  62.  
  63.     s = base+pat.patlen-1;
  64.     e = base+n;
  65.     s_offset = 1-pat.patlen;
  66.     ep = pat.pat + pat.patlen;
  67.     while(s < e){
  68. #ifdef    STATS
  69.         stats.slow++;
  70. #endif
  71.         for(p = pat.pat, q = s+s_offset; p < ep; ){
  72. #ifdef    STATS
  73.             stats.cmp++;
  74. #endif
  75.             if(*q++ != *p++)
  76.                 goto mismatch;
  77.         }
  78.         nmatch++;
  79.     mismatch:
  80.         s++;
  81. #ifdef    STATS
  82.         stats.step[1]++;
  83. #endif
  84.     }
  85.     return(nmatch);
  86. }
  87.