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