@@ -80,37 +80,26 @@ struct match
80
80
pg_wchar * endp ;/* end of string -- virtual NUL here */
81
81
pg_wchar * coldp ;/* can be no match starting before here */
82
82
pg_wchar * * lastpos ;/* [nplus+1] */
83
- STATEVARS ;
83
+ STATEVARS ;
84
84
states st ;/* current states */
85
85
states fresh ;/* states for a fresh start */
86
86
states tmp ;/* temporary */
87
87
states empty ;/* empty set of states */
88
88
};
89
89
90
- /* ========= begin header generated by ./mkh ========= */
91
- #ifdef __cplusplus
92
- extern "C"
93
- {
94
- #endif
90
+ static int matcher (struct re_guts * g ,pg_wchar * string ,size_t nmatch ,
91
+ regmatch_t * pmatch ,int eflags );
92
+ static pg_wchar * dissect (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
93
+ sopno startst ,sopno stopst );
94
+ static pg_wchar * backref (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
95
+ sopno startst ,sopno stopst ,sopno lev );
96
+ static pg_wchar * fast (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
97
+ sopno startst ,sopno stopst );
98
+ static pg_wchar * slow (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
99
+ sopno startst ,sopno stopst );
100
+ static states step (struct re_guts * g ,sopno start ,
101
+ sopno stop ,states bef ,int ch ,states aft );
95
102
96
- /* === engine.c === */
97
- static int
98
- matcher (struct re_guts * g ,pg_wchar * string ,size_t nmatch ,
99
- regmatch_t * pmatch ,int eflags );
100
- static pg_wchar *
101
- dissect (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
102
- sopno startst ,sopno stopst );
103
- static pg_wchar *
104
- backref (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
105
- sopno startst ,sopno stopst ,sopno lev );
106
- static pg_wchar *
107
- fast (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
108
- sopno startst ,sopno stopst );
109
- static pg_wchar *
110
- slow (struct match * m ,pg_wchar * start ,pg_wchar * stop ,sopno startst ,sopno stopst );
111
- static states
112
- step (struct re_guts * g ,sopno start ,
113
- sopno stop ,states bef ,int ch ,states aft );
114
103
#define BOL (OUT+1)
115
104
#define EOL (BOL+1)
116
105
#define BOLEOL (BOL+2)
@@ -128,24 +117,13 @@ extern"C"
128
117
#endif
129
118
130
119
#ifdef REDEBUG
131
- static void
132
- print (struct match * m ,pg_wchar * caption ,states st ,int ch ,FILE * d );
133
- #endif
134
- #ifdef REDEBUG
135
- static void
136
- at (struct match * m ,pg_wchar * title ,pg_wchar * start ,pg_wchar * stop ,
137
- sopno startst ,sopno stopst );
138
- #endif
139
- #ifdef REDEBUG
140
- static pg_wchar *
141
- p_char (int ch );
142
- #endif
143
-
144
- #ifdef __cplusplus
145
- }
146
-
120
+ static void print (struct match * m ,pg_wchar * caption ,states st ,int ch ,
121
+ FILE * d );
122
+ static void at (struct match * m ,pg_wchar * title ,pg_wchar * start ,
123
+ pg_wchar * stop ,sopno startst ,sopno stopst );
124
+ static pg_wchar * pchar (int ch );
125
+ static int pg_isprint (int c );
147
126
#endif
148
- /* ========= end header generated by ./mkh ========= */
149
127
150
128
#ifdef REDEBUG
151
129
#define SP (t ,s ,c )print(m, t, s, c, stdout)
@@ -158,17 +136,11 @@ extern"C"
158
136
#endif
159
137
160
138
/*
161
- - matcher - the actual matching engine
162
- == static int matcher(struct re_guts *g, pg_wchar *string, \
163
- ==size_t nmatch, regmatch_t *pmatch, int eflags);
139
+ * matcher - the actual matching engine
164
140
*/
165
141
static int /* 0 success, REG_NOMATCH failure */
166
- matcher (g ,string ,nmatch ,pmatch ,eflags )
167
- struct re_guts * g ;
168
- pg_wchar * string ;
169
- size_t nmatch ;
170
- regmatch_t * pmatch ;
171
- int eflags ;
142
+ matcher (struct re_guts * g ,pg_wchar * string ,size_t nmatch ,
143
+ regmatch_t * pmatch ,int eflags )
172
144
{
173
145
pg_wchar * endp ;
174
146
int i ;
@@ -206,10 +178,11 @@ inteflags;
206
178
for (dp = start ;dp < stop ;dp ++ )
207
179
if (* dp == g -> must [0 ]&& stop - dp >=g -> mlen &&
208
180
#ifdef MULTIBYTE
209
- memcmp (dp ,g -> must , (size_t ) (g -> mlen * sizeof (pg_wchar )))== 0 )
181
+ memcmp (dp ,g -> must , (size_t ) (g -> mlen * sizeof (pg_wchar )))== 0
210
182
#else
211
- memcmp (dp ,g -> must , (size_t )g -> mlen )== 0 )
183
+ memcmp (dp ,g -> must , (size_t )g -> mlen )== 0
212
184
#endif
185
+ )
213
186
break ;
214
187
if (dp == stop )/* we didn't find g->must */
215
188
return REG_NOMATCH ;
@@ -349,17 +322,11 @@ inteflags;
349
322
}
350
323
351
324
/*
352
- - dissect - figure out what matched what, no back references
353
- == static char *dissect(struct match *m, char *start, \
354
- ==char *stop, sopno startst, sopno stopst);
325
+ * dissect - figure out what matched what, no back references
355
326
*/
356
327
static pg_wchar * /* == stop (success) always */
357
- dissect (m ,start ,stop ,startst ,stopst )
358
- struct match * m ;
359
- pg_wchar * start ;
360
- pg_wchar * stop ;
361
- sopno startst ;
362
- sopno stopst ;
328
+ dissect (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
329
+ sopno startst ,sopno stopst )
363
330
{
364
331
int i ;
365
332
sopno ss ;/* start sop of current subRE */
@@ -549,18 +516,13 @@ sopnostopst;
549
516
}
550
517
551
518
/*
552
- - backref - figure out what matched what, figuring in back references
553
- == static char *backref(struct match *m, char *start, \
554
- ==char *stop, sopno startst, sopno stopst, sopno lev);
519
+ * backref - figure out what matched what, figuring in back references
520
+ *
521
+ * lev is PLUS nesting level
555
522
*/
556
523
static pg_wchar * /* == stop (success) or NULL (failure) */
557
- backref (m ,start ,stop ,startst ,stopst ,lev )
558
- struct match * m ;
559
- pg_wchar * start ;
560
- pg_wchar * stop ;
561
- sopno startst ;
562
- sopno stopst ;
563
- sopno lev ;/* PLUS nesting level */
524
+ backref (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
525
+ sopno startst ,sopno stopst ,sopno lev )
564
526
{
565
527
int i ;
566
528
sopno ss ;/* start sop of current subRE */
@@ -763,17 +725,11 @@ sopnolev;/* PLUS nesting level */
763
725
}
764
726
765
727
/*
766
- - fast - step through the string at top speed
767
- == static char *fast(struct match *m, char *start, \
768
- ==char *stop, sopno startst, sopno stopst);
728
+ * fast - step through the string at top speed
769
729
*/
770
730
static pg_wchar * /* where tentative match ended, or NULL */
771
- fast (m ,start ,stop ,startst ,stopst )
772
- struct match * m ;
773
- pg_wchar * start ;
774
- pg_wchar * stop ;
775
- sopno startst ;
776
- sopno stopst ;
731
+ fast (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
732
+ sopno startst ,sopno stopst )
777
733
{
778
734
states st = m -> st ;
779
735
states fresh = m -> fresh ;
@@ -858,17 +814,11 @@ sopnostopst;
858
814
}
859
815
860
816
/*
861
- - slow - step through the string more deliberately
862
- == static char *slow(struct match *m, char *start, \
863
- ==char *stop, sopno startst, sopno stopst);
817
+ * slow - step through the string more deliberately
864
818
*/
865
819
static pg_wchar * /* where it ended */
866
- slow (m ,start ,stop ,startst ,stopst )
867
- struct match * m ;
868
- pg_wchar * start ;
869
- pg_wchar * stop ;
870
- sopno startst ;
871
- sopno stopst ;
820
+ slow (struct match * m ,pg_wchar * start ,pg_wchar * stop ,
821
+ sopno startst ,sopno stopst )
872
822
{
873
823
states st = m -> st ;
874
824
states empty = m -> empty ;
@@ -948,27 +898,15 @@ sopnostopst;
948
898
949
899
950
900
/*
951
- - step - map set of states reachable before char to set reachable after
952
- == static states step(struct re_guts *g, sopno start, sopno stop, \
953
- ==states bef, int ch, states aft);
954
- == #defineBOL(OUT+1)
955
- == #defineEOL(BOL+1)
956
- == #defineBOLEOL(BOL+2)
957
- == #defineNOTHING (BOL+3)
958
- == #defineBOW(BOL+4)
959
- == #defineEOW(BOL+5)
960
- == #defineCODEMAX (BOL+5)// highest code used
961
- == #defineNONCHAR(c)((c) > CHAR_MAX)
962
- == #defineNNONCHAR(CODEMAX-CHAR_MAX)
901
+ * step - map set of states reachable before char to set reachable after
963
902
*/
964
903
static states
965
- step (g ,start ,stop ,bef ,ch ,aft )
966
- struct re_guts * g ;
967
- sopno start ;/* start state within strip */
968
- sopno stop ;/* state after stop state within strip */
969
- states bef ;/* states reachable before */
970
- int ch ;/* character or NONCHAR code */
971
- states aft ;/* states already known reachable after */
904
+ step (struct re_guts * g ,
905
+ sopno start ,/* start state within strip */
906
+ sopno stop ,/* state after stop state within strip */
907
+ states bef ,/* states reachable before */
908
+ int ch ,/* character or NONCHAR code */
909
+ states aft )/* states already known reachable after */
972
910
{
973
911
cset * cs ;
974
912
sop s ;
@@ -1082,19 +1020,11 @@ statesaft;/* states already known reachable after */
1082
1020
1083
1021
#ifdef REDEBUG
1084
1022
/*
1085
- - print - print a set of states
1086
- == #ifdef REDEBUG
1087
- == static void print(struct match *m, char *caption, states st, \
1088
- ==int ch, FILE *d);
1089
- == #endif
1023
+ * print - print a set of states
1090
1024
*/
1091
1025
static void
1092
- print (m ,caption ,st ,ch ,d )
1093
- struct match * m ;
1094
- pg_wchar * caption ;
1095
- states st ;
1096
- int ch ;
1097
- FILE * d ;
1026
+ print (struct match * m ,pg_wchar * caption ,states st ,
1027
+ int ch ,FILE * d )
1098
1028
{
1099
1029
struct re_guts * g = m -> g ;
1100
1030
int i ;
@@ -1116,20 +1046,11 @@ FILE *d;
1116
1046
}
1117
1047
1118
1048
/*
1119
- - at - print current situation
1120
- == #ifdef REDEBUG
1121
- == static void at(struct match *m, pg_wchar *title, pg_wchar *start, pg_wchar *stop, \
1122
- ==sopno startst, sopno stopst);
1123
- == #endif
1049
+ * at - print current situation
1124
1050
*/
1125
1051
static void
1126
- at (m ,title ,start ,stop ,startst ,stopst )
1127
- struct match * m ;
1128
- pg_wchar * title ;
1129
- pg_wchar * start ;
1130
- pg_wchar * stop ;
1131
- sopno startst ;
1132
- sopno stopst ;
1052
+ at (struct match * m ,pg_wchar * title ,pg_wchar * start ,pg_wchar * stop ,
1053
+ sopno startst ,sopno stopst )
1133
1054
{
1134
1055
if (!(m -> eflags & REG_TRACE ))
1135
1056
return ;
@@ -1140,19 +1061,26 @@ sopnostopst;
1140
1061
}
1141
1062
1142
1063
#ifndef PCHARDONE
1143
- #define PCHARDONE /*never again */
1064
+ #define PCHARDONE /*only do this once */
1144
1065
/*
1145
- - pchar - make a character printable
1146
- == #ifdef REDEBUG
1147
- == static char *pchar(int ch);
1148
- == #endif
1066
+ * pchar - make a character printable
1149
1067
*
1150
1068
* Is this identical to regchar() over in debug.c?Well, yes.But a
1151
1069
* duplicate here avoids having a debugging-capable regexec.o tied to
1152
1070
* a matching debug.o, and this is convenient.It all disappears in
1153
1071
* the non-debug compilation anyway, so it doesn't matter much.
1154
1072
*/
1073
+ static pg_wchar * /* -> representation */
1074
+ pchar (int ch )
1075
+ {
1076
+ static pg_wchar pbuf [10 ];
1155
1077
1078
+ if (pg_isprint (ch )|| ch == ' ' )
1079
+ sprintf (pbuf ,"%c" ,ch );
1080
+ else
1081
+ sprintf (pbuf ,"\\%o" ,ch );
1082
+ return pbuf ;
1083
+ }
1156
1084
1157
1085
static int
1158
1086
pg_isprint (int c )
@@ -1164,19 +1092,6 @@ pg_isprint(int c)
1164
1092
#endif
1165
1093
}
1166
1094
1167
- static pg_wchar * /* -> representation */
1168
- pchar (ch )
1169
- int ch ;
1170
- {
1171
- static pg_wchar pbuf [10 ];
1172
-
1173
- if (pg_isprint (ch )|| ch == ' ' )
1174
- sprintf (pbuf ,"%c" ,ch );
1175
- else
1176
- sprintf (pbuf ,"\\%o" ,ch );
1177
- return pbuf ;
1178
- }
1179
-
1180
1095
#endif
1181
1096
#endif
1182
1097