From: MÃ¥rten Dolk Date: Thu, 19 May 2005 13:30:24 +0000 (+0000) Subject: intital ci of simprog.c X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=commitdiff_plain;h=52feef3369ad80d5b7207620f37ae341ccd11b95 intital ci of simprog.c --- diff --git a/simprog.c b/simprog.c new file mode 100644 index 0000000..a713847 --- /dev/null +++ b/simprog.c @@ -0,0 +1,72 @@ +#include +#include +#include + + +void print_help(char name[]) +{ + printf("\n"); + printf("Simulates execution of an program. \n"); + printf("\n"); + printf("Usage: %s \n", name); + printf("The default action of the program is to return with 0 (success) \n"); + printf(" -eNN=MM Return with value NN with a probability of MM% \n"); + printf("\n"); +} + + +void parse_argv(char argv[], int *retval, int *percentage) +{ + if ( sscanf(argv,"-e %d = %d",retval,percentage)!=2 ) + { + printf("Argument sytax error : %s \n", argv); + exit(EXIT_FAILURE); + } + + if ( *percentage <= 0 ) + { + printf("Percentage argument must be > 0"); + exit(EXIT_FAILURE); + } +} + + + +int main (int argc, char** argv) +{ + int i, rand_value, sum; + int retvals[100]; + int percentages[100]; + + if (argc==2 && strcmp("--help",argv[1])==0 ) + { + print_help(argv[0]); + return 1; + } + + + for (i=1; i