source: trunk/Softwares/MiBench/src/c/stringsearch-strsearch.c @ 117

Last change on this file since 117 was 117, checked in by rosiere, 15 years ago

1) Platforms : add new organization for test
2) Load_Store_Unit : add array to count nb_check in store_queue
3) Issue_queue and Core_Glue : rewrite the issue network
4) Special_Register_Unit : add reset value to register CID
5) Softwares : add multicontext test
6) Softwares : add SPECINT
7) Softwares : add MiBench?
7) Read_queue : inhib access for r0
8) Change Core_Glue (network) - dont yet support priority and load balancing scheme

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/* +++Date last modified: 05-Jul-1997 */
2
3/*
4**        A Pratt-Boyer-Moore string search, written by Jerry Coffin
5**  sometime or other in 1991.  Removed from original program, and
6**  (incorrectly) rewritten for separate, generic use in early 1992.
7**  Corrected with help from Thad Smith, late March and early
8**  April 1992...hopefully it's correct this time. Revised by Bob Stout.
9**
10**  This is hereby placed in the Public Domain by its author.
11**
12**  10/21/93 rdg  Fixed bug found by Jeff Dunlop
13*/
14
15#include "stringsearch-search.h"
16#include <stddef.h>
17#include <string.h>
18#include <limits.h>
19
20static size_t table[UCHAR_MAX + 1];
21static size_t len;
22static char *findme;
23
24/*
25**  Call this with the string to locate to initialize the table
26*/
27
28void init_search(const char *string)
29{
30      size_t i;
31
32      len = strlen(string);
33      for (i = 0; i <= UCHAR_MAX; i++)                      /* rdg 10/93 */
34            table[i] = len;
35      for (i = 0; i < len; i++)
36            table[(unsigned char)string[i]] = len - i - 1;
37      findme = (char *)string;
38}
39
40/*
41**  Call this with a buffer to search
42*/
43
44char *strsearch(const char *string)
45{
46      register size_t shift;
47      register size_t pos = len - 1;
48      char *here;
49      size_t limit=strlen(string);
50
51      while (pos < limit)
52      {
53            while( pos < limit &&
54                  (shift = table[(unsigned char)string[pos]]) > 0)
55            {
56                  pos += shift;
57            }
58            if (0 == shift)
59            {
60                  if (0 == strncmp(findme,
61                        here = (char *)&string[pos-len+1], len))
62                  {
63                        return(here);
64                  }
65                  else  pos++;
66            }
67      }
68      return NULL;
69}
Note: See TracBrowser for help on using the repository browser.