GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_ut_wild.c
Go to the documentation of this file.
1 // $Id: f_ut_wild.c 478 2009-10-29 12:26:09Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #define MATCH 0
19 #define NOMATCH -1
20 
21 INTS4 f_ut_wild(CHARS *pc_test, CHARS *pc_wild)
22 {
23 INTS4 l_wild,l_test,l_len;
24 CHARS c_wild[256],c_test[256];
25 CHARS *pc_h,*pc_n,*pc_w,*pc_s;
26 strcpy(c_wild,pc_wild);
27 strcpy(c_test,pc_test);
28 pc_w=(CHARS *)c_wild;
29 pc_s=(CHARS *)c_test;
30 l_test=strlen(pc_s);
31 while(1)
32 {
33  while(*pc_w=='*')
34  {
35  while(*pc_w=='*'){pc_w++; if(*pc_w==0)return MATCH;}
36  pc_h=pc_w;
37  while((*pc_h!='*')&(*pc_h!=0))pc_h++;
38  if(*pc_h==0)
39  {
40  /* match pc_w at end of test */
41  l_len=strlen(pc_w);
42  if(strlen(pc_s) < l_len) return NOMATCH;
43  pc_s=(CHARS *)&c_test[l_test-l_len];
44  }
45  if(*pc_h=='*')
46  {
47  /* match pc_w-pc_h somewhere in test */
48  *pc_h=0;
49  if((pc_n=(CHARS *)strstr(pc_s,pc_w))==NULL) return NOMATCH;
50  l_len=strlen(pc_w);
51  *pc_h='*';
52  pc_w=pc_h;
53  pc_s=pc_n+l_len;
54  }
55  }
56  if((*pc_w!='%') & (*pc_w!=*pc_s))return NOMATCH;
57  pc_s++;pc_w++;
58  if((*pc_s==0)&(*pc_w==0)) return MATCH;
59  if(*pc_s==0)
60  {
61  if((*pc_w=='*') & (*(pc_w+1)==0))return MATCH;
62  return NOMATCH;
63  }
64  if(*pc_w==0)return NOMATCH;
65 }
66 }
int INTS4
Definition: typedefs.h:28
INTS4 f_ut_wild(CHARS *pc_test, CHARS *pc_wild)
Definition: f_ut_wild.c:21
#define MATCH
Definition: f_ut_wild.c:18
#define NOMATCH
Definition: f_ut_wild.c:19
char CHARS
Definition: typedefs.h:21