-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddDirective_c.c
61 lines (53 loc) · 1.4 KB
/
addDirective_c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <ctype.h>
#define MAXCHAR 10000
// this function glance through Csmith's random test and find the for loop
// then add a loop name to it named LOOP_1
int add_Loop_Name(int num) {
FILE *fp;
char str[MAXCHAR];
char* filename = "test_modify_main.txt";
//char* filename = argv[1];
int line, i;
char add_name[MAXCHAR];
int find = 0;
int count = num;
char convert[MAXCHAR];
//int num = strtol(argv[2], NULL, 10);
fp = fopen(filename, "r");
if (fp == NULL){
printf("Could not open file %s",filename);
return 1;
}
while(fgets(str, MAXCHAR, fp) != NULL) {
find = 0;
if(strstr(str, "for (") != NULL && num > 0) {
strcpy(add_name, "\tLOOP_");
sprintf(convert, "%d:", num);
strcat(add_name, convert);
printf("%s", add_name);
printf("%s\n", str);
find = 1;
num--;
}
//don't need to print current line if find for and already modified in the
//above if block
if(find == 0) {
printf("%s", str);
}
line++;
}
//Close the file if still open.
if(fp) {
fclose(fp);
}
return 0;
}
int main(int argc, char* argv[])
{
int num = strtol(argv[1], NULL, 10);
add_Loop_Name(num);
return 0;
}