--- joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 09:27:14 1.12 +++ joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 10:45:02 1.13 @@ -5,7 +5,7 @@ * Uebung 4.4 */ -// $Id: bmp_fractal.c,v 1.12 2006/07/02 09:27:14 joko Exp $ +// $Id: bmp_fractal.c,v 1.13 2006/07/02 10:45:02 joko Exp $ #include #include @@ -156,6 +156,30 @@ } +BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) { + int i; + char * opt_current_name; + char * opt_current_value; + + //printf("searching for: '%s'\n", opt_name); + + for (i = 1; i < argc; i++) { + opt_current_name = argv[i]; + if (strcmp(opt_current_name, opt_name) == 0) { + //printf("opt: %s\n", opt_current_name); + opt_current_value = argv[i+1]; + //printf("opt-current-value: %s\n", opt_current_value); + if (opt_current_value != NULL) { + //*opt_value = *argv[i+1]; + *opt_value = *opt_current_value; + //printf("opt-value: %s\n", opt_value); + } + return TRUE; + } + } + return FALSE; +} + int main(int argc, char *argv[]) { @@ -172,23 +196,51 @@ PWORKERARGS worker_args; // threads or processes? - BOOL use_processes = TRUE; + BOOL use_processes = FALSE; BOOL is_worker_process = FALSE; // information for creating processes STARTUPINFO si; PROCESS_INFORMATION pi; - char szCmdline[1024]; + char szCmdline[65536]; + // command line stuff + char arg_option[1024]; + char *arg_value[1024]; + //arg_value = malloc(1024); - VERBOSE = TRUE; + VERBOSE = FALSE; // "parse" command line arguments + /* if (argc >= 2) { if (strcmp(argv[1], "--worker") == 0) { is_worker_process = TRUE; } } + */ + + //scan_argv(argc, argv, "--worker", &arg_value); + //*arg_value = '\0'; + // parse command line arguments + if (scan_argv(argc, argv, "--worker", arg_value)) { + use_processes = TRUE; + is_worker_process = TRUE; + + } else if (scan_argv(argc, argv, "-p", arg_value)) { + use_processes = TRUE; + is_worker_process = FALSE; + workers = atoi(arg_value); + + } else if (scan_argv(argc, argv, "-t", arg_value)) { + use_processes = FALSE; + is_worker_process = FALSE; + workers = atoi(arg_value); + + } + //printf("value: %s\n", arg_value); + //exit(0); + if (VERBOSE && use_processes) { fprintf(stdout, "===================================================== "); @@ -268,7 +320,7 @@ if (!CloseHandle(hMap)) printErrorAndExit("Error at CloseHandle", GetLastError()); - return 0; + return 0; } /*