split option processing into its own file
[IRC.git] / Robust / src / Runtime / option.c
1 #include "option.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include "runtime.h"
5
6 extern char *options;
7 extern int injectfailures;
8 extern float failurechance;
9 extern int debugtask;
10 extern int injectinstructionfailures;
11 extern int failurecount;
12 extern float instfailurechance;
13 extern int numfailures;
14 extern int instaccum;
15 extern char ** environ;
16
17 void processOptions() {
18   int i;
19   options=NULL;
20   for(i=0;environ[i]!=0;i++) {
21     if (strncmp(environ[i],"BRISTLECONE=",12)==0) {
22       options=environ[i]+12;
23       break;
24     }
25   }
26   
27   while(options!=NULL) {
28     if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) {
29       options=strchr(options,' ');
30       if (options!=NULL) options++;
31       if (options==NULL)
32         break;
33       sscanf(options, "%f", &failurechance);
34       injectfailures=1;
35       printf("Injecting errors with chance=%f\n",failurechance);
36       options=strchr(options,' ');
37       if (options!=NULL) options++;
38     } else if (strncmp(options,"-injectinstructionfailures",sizeof("-injectinstructionfailures")-1)==0) {
39       options=strchr(options,' ');
40       if (options!=NULL) options++;
41       if (options==NULL)
42         break;
43       sscanf(options, "%d", &failurecount);
44       options=strchr(options,' ');
45       if (options!=NULL) options++;
46       if (options==NULL)
47         break;
48
49       sscanf(options, "%f", &instfailurechance);
50       options=strchr(options,' ');
51       if (options!=NULL) options++;
52       if (options==NULL)
53         break;
54
55       sscanf(options, "%d", &numfailures);
56       options=strchr(options,' ');
57       if (options!=NULL) options++;
58
59       instaccum=failurecount;
60       instructioncount=failurecount;
61       injectinstructionfailures=1;
62       printf("Number of failures=%d\n",numfailures);
63       printf("Injecting errors with count=%d\n",failurecount);
64       printf("Injecting errors with chance=%f\n",instfailurechance);
65     } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) {
66       options=strchr(options,' ');
67       if (options!=NULL) options++;
68       debugtask=1;
69       printf("Debug task option on.\n");
70     } else if (strncmp(options, "-initializerandom", sizeof("-initializerandom")-1)==0) {
71       options=strchr(options,' ');
72       if (options!=NULL) options++;
73       printf("Initializing random number generator.\n");
74       srandomdev();
75     } else
76       break;
77   }
78 }