69,371
社区成员
发帖
与我相关
我的任务
分享
#define ESIZE 1024
#define INIT register unsigned char *sp=instring;
#define GETC() (*sp++)
#define PEEKC() (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return c;
#define ERROR(c) { regerr(c); return(NULL); }
#include "stdio.h"
#include "string.h"
#include "regexp.h"
int i;
unsigned char *nextpos;
static unsigned char lbuf[512], ebuf[ESIZE];
FILE *fp;
int regerr();
main(argc,argv)
int argc;
unsigned char *argv[];
{
if (argc < 3)
{
fprintf(stderr,"Use: %s regular_expr files ..\n", argv[0]);
exit(-1);
}
if (nextpos=compile(argv[1], ebuf, &ebuf[ESIZE],'\0'))
for (i=2;i < argc;i++)
{
if ((fp=fopen(argv[i],"rb"))==NULL)
printf("%s: read failure.\n",argv[i]);
else while (fgets(lbuf,sizeof(lbuf),fp))
if (step(lbuf,ebuf)) printf("%s: %s",argv[i],lbuf);
fclose(fp);
}
}
int regerr(c)
int c;
{
fprintf(stderr,"Error %d.\n", c);
}
$ apt-get source grep
#define ESIZE 1024
#define INIT register unsigned char *sp=instring;
#define GETC() (*sp++)
#define PEEKC() (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return c;
#define ERROR(c) { regerr(c); return(NULL); }
#include "stdio.h"
#include "string.h"
#include "regexp.h"
int i;
unsigned char *nextpos;
static unsigned char lbuf[512], ebuf[ESIZE];
FILE *fp;
int regerr();
int main(int argc,char *argv[])
{,
if (argc < 3)
{
fprintf(stderr,"Use: %s regular_expr files ..\n", argv[0]);
exit(-1);
}
if (nextpos = compile(argv[1], ebuf, &ebuf[ESIZE],'\0'))
for (i=2;i < argc;i++)
{
if ((fp=fopen(argv[i],"rb"))==NULL)
printf("%s: read failure.\n",argv[i]);
else while (fgets(lbuf,sizeof(lbuf),fp))
if (step(lbuf,ebuf)) printf("%s: %s",argv[i],lbuf);
fclose(fp);
}
return 0;
}
int regerr(int c)
{
fprintf(stderr,"Error %d.\n", c);
}