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