home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / stringsearch / bmsource / sfc.fwd.inc.c-A < prev    next >
Encoding:
Text File  |  1991-05-06  |  1.8 KB  |  99 lines  |  [TEXT/MPS ]

  1. /*
  2.     search routine generated by gen.
  3.     skip=sfc, match=fwd (using fwdl), 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.     skipc = &pat.pat[0];
  53. }
  54.  
  55. exec(base, n)
  56.     CHARTYPE *base;
  57. {
  58.     int nmatch = 0;
  59.     register CHARTYPE *e, *s;
  60.     register CHARTYPE ch;
  61.     register CHARTYPE *p, *q;
  62.     register CHARTYPE *ep;
  63.  
  64.     s = base;
  65.     e = base + n - pat.patlen;
  66.     ch = pat.pat[0];
  67.     base[n] = ch;
  68.     ep = pat.pat + pat.patlen;
  69.     while(s < e){
  70. #ifdef    STATS
  71.         while(ch != *s++)
  72.             stats.jump++;
  73.         stats.jump++;
  74. #else
  75.         while(ch != *s++)
  76.             ;
  77. #endif
  78.         if(s > e)
  79.             break;
  80. #ifdef    STATS
  81.         stats.slow++;
  82. #endif
  83.         for(p = pat.pat+1, q = s; p < ep; ){
  84. #ifdef    STATS
  85.             stats.cmp++;
  86. #endif
  87.             if(*q++ != *p++)
  88.                 goto mismatch;
  89.         }
  90.         nmatch++;
  91.     mismatch:
  92.         ;
  93. #ifdef    STATS
  94.         stats.step[1]++;
  95. #endif
  96.     }
  97.     return(nmatch);
  98. }
  99.