6 void print_help(char name[])
9 printf("Simulates execution of an program. \n");
11 printf("Usage: %s \n", name);
12 printf("The default action of the program is to return with 0 (success) \n");
13 printf(" -eNN=MM Return with value NN with a probability of MM% \n");
18 void parse_argv(char argv[], int *retval, int *percentage)
20 if ( sscanf(argv,"-e %d = %d",retval,percentage)!=2 )
22 printf("Argument sytax error : %s \n", argv);
26 if ( *percentage <= 0 )
28 printf("Percentage argument must be > 0");
35 int main (int argc, char** argv)
37 int i, rand_value, sum;
41 if (argc==2 && strcmp("--help",argv[1])==0 )
48 for (i=1; i<argc; i++)
50 parse_argv(argv[i], retvals+i-1, percentages+i-1);
54 /* Get random number in interval [0,100) */
56 rand_value = rand() % 100;
58 /* See if we want to fire an "error" */
60 for (i=0; i<argc-1; i++)
62 sum += percentages[i];
63 if ( rand_value < sum )
65 printf("Simulated error : %d \n", retvals[i]);