Mapper
strpat.c
Go to the documentation of this file.
1 /* --------------------------------------------------------------------
2  FUNCTION
3  strpat
4 
5  PURPOSE
6  Search for string patterns, using template characters,
7  for numbers and/or alpha characters.
8 
9  VERSION and UPDATES
10  1.0 DEC 95 David G. Brandon
11  Original Version
12  *--------------------------------------------------------------------- */
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17 #include <dirent.h>
18 #include <unistd.h>
19 #include <string.h>
20 #include <math.h>
21 #include <sys/stat.h>
22 /*
23 #include <fcntl.h>
24 */
25 
26 /* *********************** */
27 /* pattern search function */
28 /* *********************** */
29 
30 strpat(char buffer[], char token[] , int numtemp, int chartemp )
31 {
32 
33 int token_len, buffer_len, cutoff_len;
34 int i,j,k;
35 
36  token_len = strlen(token);
37  buffer_len = strlen(buffer);
38  cutoff_len = buffer_len - token_len;
39 
40  i = 0;
41  while ( i < cutoff_len +1 )
42  {
43  j = 0;
44  k = i;
45 
46  while ( j < token_len )
47  {
48  if ( token[j] == numtemp )
49  {
50  if ( buffer[k] != '-' )
51  {
52  if ( buffer[k] != '.' )
53  {
54  if ( !isdigit(buffer[k]) )
55  {
56  if ( token[j] != buffer[k] )
57  break;
58  }
59  }
60  }
61  }
62  else if ( token[j] == chartemp )
63  {
64  if ( !isalpha(buffer[k]) )
65  {
66  if ( token[j] != buffer[k] )
67  break;
68  }
69 
70  }
71  else if ( token[j] != buffer[k] )
72  break;
73 
74  j++;
75  k++;
76 
77  if ( j == token_len )
78  return i;
79  }
80  i++;
81  }
82  return -1;
83 }
static char token[LEN_TOKEN+1]
static int i
int j
Definition: mapp2h.h:48
int k
Definition: mapp2h.h:48
strpat(char buffer[], char token[], int numtemp, int chartemp)
Definition: strpat.c:30