82
|
1 /* svn://svn.kuehne.cn/dstress/extract__.c
|
|
2 *
|
|
3 * extract compiler flags for DStress test cases
|
|
4 *
|
239
|
5 * Copyright (C) 2004, 2005 Thomas Kuehne
|
82
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include <stdio.h>
|
|
23 #include <stdlib.h>
|
|
24 #include <string.h>
|
|
25 #include <errno.h>
|
|
26
|
|
27 // @WARNING@ works only with ASCII / UTF-8 source files
|
|
28 int main(int argc, char* argv[]){
|
|
29 if(argc!=2){
|
|
30 printf("this stdin will be queried for the patter given as first argument\n");
|
|
31 return -1;
|
|
32 }
|
|
33
|
|
34 // the longest source line in the test is a bit over 1<<16 bytes long
|
|
35 size_t length = 1 << 17;
|
|
36 char* line = malloc(length);
|
|
37 char* buffer;
|
|
38 char* found;
|
|
39 char* pattern=argv[1];
|
|
40 size_t pattern_length=strlen(pattern);
|
|
41
|
|
42 errno=0;
|
|
43 while(buffer=fgets(line, length, stdin)){
|
|
44 found = strstr(buffer, pattern);
|
|
45
|
|
46 if(errno!=0){
|
|
47 break;
|
|
48 }else if(found!=NULL){
|
|
49 found+=pattern_length;
|
|
50 printf("%s", found);
|
|
51 break;
|
|
52 }
|
|
53 }
|
|
54
|
|
55 free(line);
|
|
56
|
|
57 return 0;
|
|
58 }
|