匿名用户
1级
2015-08-31 回答
/* 一组宏定义,不过此函数没有用 */
#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); /* 退出程序 */
}
/* 没见过compile函数 */
nextpos = compile(argv[1], ebuf, &ebuf[ESIZE],'\0');
if(nextpos)
for(i=2;i
{
if((fp=fopen(argv[i],"rb"))==NULL)
printf("%s: read failure.\n",argv[i]);
else
/* 没见过step函数 */
while(fgets(lbuf,sizeof(lbuf),fp))
if(step(lbuf,ebuf)) printf("%s: %s",argv[i],lbuf);
fclose(fp); /* 关闭文件 */
}
}
/* 向标准出错设备输出信息,即屏幕 */
int regerr(int c) /* 函数不完整,返回值没用 */
{
fprintf(stderr,"Error %d.\n", c);
}
grep的功能
grep从一个或多个文本文件中查找符合指定范本(正则表达式)的行,并把查找结果输出到指定设备(默认到屏幕)。
正则表达式?还要模式匹配?有点小复杂啊。。。