help
Rev | Line | |
---|
[25ae32e] | 1 | #include <stdio.h> |
---|
| 2 | #include <string.h> |
---|
| 3 | #include <regex.h> |
---|
| 4 | |
---|
| 5 | char buf[5001]; |
---|
| 6 | |
---|
| 7 | main(int argc, char **argv) |
---|
| 8 | { |
---|
| 9 | |
---|
| 10 | char *pattern; |
---|
| 11 | char eoln; |
---|
| 12 | regex_t re; |
---|
| 13 | |
---|
| 14 | int firstline=1; |
---|
| 15 | |
---|
| 16 | if(argc < 2) |
---|
| 17 | /* pattern="[ \t]*([0-9]+[ \t]+){2}EOS([ \t].*)?"; */ |
---|
| 18 | pattern="[ \t]*BOS([ \t].*)?"; |
---|
| 19 | else |
---|
| 20 | pattern=argv[1]; |
---|
| 21 | |
---|
| 22 | if(argc < 3) |
---|
| 23 | eoln='\f'; |
---|
| 24 | else |
---|
| 25 | eoln=atoi(argv[2]); |
---|
| 26 | |
---|
| 27 | if(regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) !=0) |
---|
| 28 | { |
---|
| 29 | fprintf(stderr,"Invalid pattern.\n"); |
---|
| 30 | exit(1); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | while(fgets(buf,5000,stdin)) |
---|
| 34 | { |
---|
| 35 | buf[strlen(buf)-1]='\0'; |
---|
| 36 | if(firstline) |
---|
| 37 | firstline=0; |
---|
| 38 | else |
---|
| 39 | if(regexec(&re, buf, (size_t)0, NULL, 0) == 0) |
---|
| 40 | putchar('\n'); |
---|
| 41 | else |
---|
| 42 | putchar(eoln); |
---|
| 43 | fputs(buf,stdout); |
---|
| 44 | } |
---|
| 45 | putchar('\n'); |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.