⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mygrep.c

📁 编写自己的grep命令
💻 C
字号:
// 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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -