Mercurial > hg > Members > shinya > pyrect
view pyrect/template/grep.cbc @ 41:ffbbdd33881d
modify cbcgrep, remove global variable to args(interface).
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Aug 2010 04:02:19 +0900 |
parents | 962ae4154724 |
children | d29d3470fde7 |
line wrap: on
line source
char linebuf[LINEBUFSIZE]; char readbuf[READBUFSIZE]; void grep(char* s, char *cur, char *buf, FILE *f, char* filename) { goto next_line(s, cur, buf, f, filename); return; } void grepmain(int argc, char* argv[]) { int i; char *buf = linebuf; char *cur = buf; char *s = cur; char *filename; FILE *f; if (argc < 2) { fprintf(stderr, "usage: grep regexp [file ...]"); exit(0); } if (argc == 2) { grep(s, cur, buf, stdin, NULL); } else { for (i = 2; i < argc; i++) { filename = argv[i]; f = fopen(filename, "r"); if (f == NULL) { fprintf(stderr, "can't open %s:", filename); continue; } if (READBUFSIZE > 0) setvbuf(f, readbuf, _IOFBF, READBUFSIZE); grep(s, cur, buf, f, filename); fclose(f); } } return; }