]> git.mxchange.org Git - simgear.git/blob - simgear/metar/Charcmp.cpp
Fixes for MSVC++.
[simgear.git] / simgear / metar / Charcmp.cpp
1 #pragma comment (compiler)
2 //#pragma comment (date)
3 //#pragma comment (timestamp)
4 #pragma pagesize(80)
5  
6 #include "Local.h"     /* standard header file */
7  
8 #pragma subtitle(" ")
9 #pragma page(1)
10 #pragma subtitle("charcmp - characters compare with patterns  ")
11 /********************************************************************/
12 /*                                                                  */
13 /*  Title:         charcmp                                          */
14 /*  Organization:  W/OSO242 - GRAPHICS AND DISPLAY SECTION          */
15 /*  Date:          12 Dec 1995                                      */
16 /*  Programmer:    CINDY L. CHONG                                   */
17 /*  Language:      C/370                                            */
18 /*                                                                  */
19 /*  Abstract:      This function will compare each character in the */
20 /*                 string match with each character in the pattern  */
21 /*                 which is made up of characters.   The str can    */
22 /*                 be longer than the pattern.                      */
23 /*                                                                  */
24 /*  External Functions Called:                                      */
25 /*                 None.                                            */
26 /*                                                                  */
27 /*  Input:         str is a pointer to char                         */
28 /*                 pattern is a pointer to char                     */
29 /*                                                                  */
30 /*  Output:        Return true if str matches pattern,              */
31 /*                 otherwise, return false                          */
32 /*                                                                  */
33 /*  Modification History:                                           */
34 /*                 None.                                            */
35 /*                                                                  */
36 /********************************************************************/
37 #pragma page(1)
38  
39 bool charcmp(char *str, char *pattern)
40 {
41  
42  
43    /**********************************************************/
44    /* Loop while str and pattern is not equal to null, then  */
45    /* inscreases str and pattern by one                      */
46    /**********************************************************/
47  
48    for (; *pattern != '\0'; pattern++)
49    {
50       if (*str == '\0')
51          return FALSE;
52  
53       /************************************************************/
54       /* If pattern match str, then increase str and jump out the */
55       /* case and read next char of the str and pattern           */
56       /************************************************************/
57  
58       if ( isspace(*pattern) )
59          pattern = nxtalpha(pattern);
60  
61       switch( *pattern )
62       {
63          case 'c':
64             if ( !isalnum(*str++) )
65             {
66                return FALSE;
67             }
68             break;
69  
70          case 'a':
71             if ( !isalpha(*str) )
72             {
73                return FALSE;
74             }
75             str++;
76             break;
77  
78          case 'n':
79             if ( !iscntrl(*str++) )
80             {
81                return FALSE;
82             }
83             break;
84  
85          case 'd':
86             if ( !isdigit(*str) )
87             {
88                return FALSE;
89             }
90             str++;
91             break;
92  
93          case 'g':
94             if ( !isgraph(*str++) )
95             {
96                return FALSE;
97             }
98             break;
99  
100          case 'i':
101             if ( !islower(*str++) )
102             {
103                return FALSE;
104             }
105             break;
106  
107          case 'p':
108             if ( !isprint(*str++) )
109             {
110                return FALSE;
111             }
112             break;
113  
114          case 't':
115             if ( !ispunct(*str++) )
116             {
117                return FALSE;
118             }
119             break;
120  
121          case 'w':
122             if ( !isspace(*str++) )
123             {
124                return FALSE;
125             }
126             break;
127  
128          case 'u':
129             if ( !isupper(*str++) )
130             {
131                return FALSE;
132             }
133             break;
134  
135          case 's':
136             if (*str++ != ' ')
137             {
138                return FALSE;
139             }
140             break;
141  
142          case 'm':
143             if ( !isspace(*str) )
144             {
145                return FALSE;
146             }
147             else
148             {
149                while ( isspace(*str) )
150                   str++;
151             }
152             break;
153  
154          case '\'':
155             pattern++;
156             if (*pattern != *str)
157             {
158                return FALSE;
159             }
160             pattern++;
161             str++;
162             break;
163  
164          default:
165             return FALSE;
166  
167       } /* end switch */
168  
169    } /* end for */
170  
171    return (TRUE);
172 }