@@ -80,37 +80,26 @@ struct match
8080 pg_wchar * endp ; /* end of string -- virtual NUL here */
8181 pg_wchar * coldp ; /* can be no match starting before here */
8282 pg_wchar * * lastpos ; /* [nplus+1] */
83- STATEVARS ;
83+ STATEVARS ;
8484 states st ; /* current states */
8585 states fresh ; /* states for a fresh start */
8686 states tmp ; /* temporary */
8787 states empty ; /* empty set of states */
8888};
8989
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 );
95102
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 );
114103#define BOL (OUT+1)
115104#define EOL (BOL+1)
116105#define BOLEOL (BOL+2)
@@ -128,24 +117,13 @@ extern "C"
128117#endif
129118
130119#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 );
147126#endif
148- /* ========= end header generated by ./mkh ========= */
149127
150128#ifdef REDEBUG
151129#define SP (t , s , c ) print(m, t, s, c, stdout)
@@ -158,17 +136,11 @@ extern "C"
158136#endif
159137
160138/*
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
164140 */
165141static 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 )
172144{
173145 pg_wchar * endp ;
174146 int i ;
@@ -206,10 +178,11 @@ int eflags;
206178 for (dp = start ; dp < stop ; dp ++ )
207179 if (* dp == g -> must [0 ] && stop - dp >= g -> mlen &&
208180#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
210182#else
211- memcmp (dp , g -> must , (size_t ) g -> mlen ) == 0 )
183+ memcmp (dp , g -> must , (size_t ) g -> mlen ) == 0
212184#endif
185+ )
213186 break ;
214187 if (dp == stop ) /* we didn't find g->must */
215188 return REG_NOMATCH ;
@@ -349,17 +322,11 @@ int eflags;
349322}
350323
351324/*
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
355326 */
356327static 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 )
363330{
364331 int i ;
365332 sopno ss ; /* start sop of current subRE */
@@ -549,18 +516,13 @@ sopno stopst;
549516}
550517
551518/*
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
555522 */
556523static 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 )
564526{
565527 int i ;
566528 sopno ss ; /* start sop of current subRE */
@@ -763,17 +725,11 @@ sopno lev; /* PLUS nesting level */
763725}
764726
765727/*
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
769729 */
770730static 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 )
777733{
778734 states st = m -> st ;
779735 states fresh = m -> fresh ;
@@ -858,17 +814,11 @@ sopno stopst;
858814}
859815
860816/*
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
864818 */
865819static 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 )
872822{
873823 states st = m -> st ;
874824 states empty = m -> empty ;
@@ -948,27 +898,15 @@ sopno stopst;
948898
949899
950900/*
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- == #define BOL (OUT+1)
955- == #define EOL (BOL+1)
956- == #define BOLEOL (BOL+2)
957- == #define NOTHING (BOL+3)
958- == #define BOW (BOL+4)
959- == #define EOW (BOL+5)
960- == #define CODEMAX (BOL+5) // highest code used
961- == #define NONCHAR(c) ((c) > CHAR_MAX)
962- == #define NNONCHAR (CODEMAX-CHAR_MAX)
901+ * step - map set of states reachable before char to set reachable after
963902 */
964903static 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 */
972910{
973911 cset * cs ;
974912 sop s ;
@@ -1082,19 +1020,11 @@ states aft; /* states already known reachable after */
10821020
10831021#ifdef REDEBUG
10841022/*
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
10901024 */
10911025static 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 )
10981028{
10991029 struct re_guts * g = m -> g ;
11001030 int i ;
@@ -1116,20 +1046,11 @@ FILE *d;
11161046}
11171047
11181048/*
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
11241050 */
11251051static 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 )
11331054{
11341055 if (!(m -> eflags & REG_TRACE ))
11351056 return ;
@@ -1140,19 +1061,26 @@ sopno stopst;
11401061}
11411062
11421063#ifndef PCHARDONE
1143- #define PCHARDONE /* never again */
1064+ #define PCHARDONE /* only do this once */
11441065/*
1145- - pchar - make a character printable
1146- == #ifdef REDEBUG
1147- == static char *pchar(int ch);
1148- == #endif
1066+ * pchar - make a character printable
11491067 *
11501068 * Is this identical to regchar() over in debug.c? Well, yes. But a
11511069 * duplicate here avoids having a debugging-capable regexec.o tied to
11521070 * a matching debug.o, and this is convenient. It all disappears in
11531071 * the non-debug compilation anyway, so it doesn't matter much.
11541072 */
1073+ static pg_wchar * /* -> representation */
1074+ pchar (int ch )
1075+ {
1076+ static pg_wchar pbuf [10 ];
11551077
1078+ if (pg_isprint (ch ) || ch == ' ' )
1079+ sprintf (pbuf , "%c" , ch );
1080+ else
1081+ sprintf (pbuf , "\\%o" , ch );
1082+ return pbuf ;
1083+ }
11561084
11571085static int
11581086pg_isprint (int c )
@@ -1164,19 +1092,6 @@ pg_isprint(int c)
11641092#endif
11651093}
11661094
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-
11801095#endif
11811096#endif
11821097
0 commit comments