annotate extract__.c @ 239:c2a96b326f61

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