/**
* grepdemo.c
*
* This file is a simple program that demonstrates the use of the
* functions contained in the grep libraries.  To compile and link
* this file, use the commands:
*
*	LC:lc -iINCLUDE: -iINCLUDE:lattice/ grepdemo.c
*	LINK:alink  FROM LIB:c.o+grepdemo.o  TO grepdemo  LIBRARY grep.lib +
*		LIB:lc.lib+ LIB:amiga.lib
*
* This assumes that you are using the Lattice C development system, along
* with the startup-sequence which initializes the logical name assignments
* used by Lattice C.  To assist you in this end, a duplicate of the startup-
* sequence file has been provided on the TMU distribution disk.
*
* Running the resulting executable (grepdemo) should result in the
* following lines being displayed (twice!):

	char *string2 = "int";
	main()
		printf("Can't open grepdemo.c\n");
		printf("Can't create pattern p\n");
			printf("%s",buf);
			printf("%s",buf);

*
**/

#include "stdio.h"
#include "pat.h"

char *string1 = "^[a-z]+(.*)";
char *string2 = "int";
char buf[256];
PATTERN re_gen();

main()
{
   FILE *fp;
   PATTERN p;

   if ( (fp = fopen("grepdemo.c","r")) == NULL ) {
	printf("Can't open grepdemo.c\n");
	exit(1);
   }

   if ( (p = re_gen(string1)) == NULL ) {
	printf("Can't create pattern p\n");
	exit(1);
   }

   while ( fgets(buf,256,fp) != NULL ) {
	if ( re_match(buf,p) >= 0 )
		printf("%s",buf);
	if ( re_smatch(string2,buf) >= 0 )
		printf("%s",buf);
   }
}
	   
