Well, there is PCRE.
Minimal grep implemented with pcre (note that the expression to search for is supplied on the command line at run time):
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "pcre.h"
#define OVECCOUNT 30 /* should be a multiple of 3 */
/* only needed if your libc doesn't include it! */
#include "getline.c"
int main(int argc, char**argv){
char *res;
char *fname;
const char *error;
int erroroffset;
pcre *re=NULL;
/* Grab the search expression from the first command line argument */
if (--argc) {
res=(++argv)[0];
re=pcre_compile(res,0,&error,&erroroffset,NULL);
if (re==NULL) /* compilation failed, bomb out */ exit(1);
}
/* All further command line arguments are files to grep in */
while (--argc) {
FILE*f=NULL;
fname=(++argv)[0];
if (f=fopen(fname,"r")) {
char *line=NULL;
size_t l=0;
while (-1 != getline(&line,&l,f)) {
int ovector[OVECCOUNT];
if ( pcre_exec(re,NULL,line,l,0,0,ovector,OVECCOUNT) > 0 ) {
printf("%s",line);
}
free(line);
line = NULL; l=0;
}
fclose(f);
}
}
free(re);
return 0;
}
Run it:
$ ./pcregrep char pcregrep.c
int main(int argc, char**argv){
char *res;
char *fname;
const char *error;
char *line=NULL;