55
66#include "my_regex.h"
77#include "main.ih"
8+ #include "tests_include.h"
89
910char * progname ;
1011int debug = 0 ;
@@ -65,14 +66,15 @@ char *argv[];
6566 size_t len ;
6667 int c ;
6768 int errflg = 0 ;
69+ int opt_inline = 0 ;
6870 register int i ;
6971 char * input_file_name = NULL ;
7072 extern int optind ;
7173 extern char * optarg ;
7274
7375 progname = argv [0 ];
7476
75- while ((c = getopt (argc , argv , "c:e:i:S:E:x " )) != EOF )
77+ while ((c = getopt (argc , argv , "c:e:i:S:E:xI " )) != EOF )
7678 switch (c ) {
7779 case 'c' : /* compile options */
7880 copts = options ('c' , optarg );
@@ -92,6 +94,9 @@ char *argv[];
9294 case 'x' : /* Debugging. */
9395 debug ++ ;
9496 break ;
97+ case 'I' : /* Inline. */
98+ opt_inline = 1 ;
99+ break ;
95100 case '?' :
96101 default :
97102 errflg ++ ;
@@ -100,10 +105,15 @@ char *argv[];
100105 if (errflg ) {
101106 fprintf (stderr , "usage: %s " , progname );
102107 fprintf (stderr ,
103- "[-c copt][-e eopt][-i filename][-S][-E][-x] [re]\n" );
108+ "[-c copt][-e eopt][-i filename][-S][-E][-x][-I] [re]\n" );
104109 exit (2 );
105110 }
106111
112+ if (opt_inline ) {
113+ regress (NULL );
114+ exit (status );
115+ }
116+
107117 if (optind >= argc && !input_file_name ) {
108118 regress (stdin );
109119 exit (status );
@@ -165,9 +175,24 @@ char *argv[];
165175 exit (status );
166176}
167177
178+ char *
179+ get_next_line (s , size , stream )
180+ char * s ;
181+ int size ;
182+ FILE * stream ;
183+ {
184+ if (stream )
185+ return fgets (s , size , stream );
186+ if (test_array [line ])
187+ return strncpy (s , test_array [line ], size );
188+ return NULL ;
189+ }
190+
168191/*
169192 - regress - main loop of regression test
170193 == void regress(FILE *in);
194+ Reads file, line-by-line.
195+ If in == NULL, we read data from test_array instead.
171196 */
172197void
173198regress (in )
@@ -185,13 +210,14 @@ FILE *in;
185210 const char * bpname = "MY_REG_BADPAT" ;
186211 my_regex_t re ;
187212
188- while (fgets (inbuf , sizeof (inbuf ), in ) != NULL ) {
213+ while (get_next_line (inbuf , sizeof (inbuf ), in ) != NULL ) {
189214 line ++ ;
190- if (inbuf [0 ] == '#' || inbuf [0 ] == '\n' )
215+ if (inbuf [0 ] == '#' || inbuf [0 ] == '\n' || inbuf [ 0 ] == '\0' )
191216 continue ; /* NOTE CONTINUE */
192- inbuf [strlen (inbuf )- 1 ] = '\0' ; /* get rid of stupid \n */
217+ if (inbuf [strlen (inbuf )- 1 ] == '\n' )
218+ inbuf [strlen (inbuf )- 1 ] = '\0' ; /* get rid of stupid \n */
193219 if (debug )
194- fprintf (stdout , "%d:\n" , line );
220+ fprintf (stdout , "%d: <%s> \n" , line , inbuf );
195221 nf = split (inbuf , f , MAXF , (char * ) "\t\t" );
196222 if (nf < 3 ) {
197223 fprintf (stderr , "bad input, line %d\n" , line );
0 commit comments