Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92603793
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-04-16 23:09:09

// mygrep.c

#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);
}

// (END)
阅读(333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~