--- joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 10:45:02 1.13 +++ joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 11:44:57 1.14 @@ -5,7 +5,7 @@ * Uebung 4.4 */ -// $Id: bmp_fractal.c,v 1.13 2006/07/02 10:45:02 joko Exp $ +// $Id: bmp_fractal.c,v 1.14 2006/07/02 11:44:57 joko Exp $ #include #include @@ -156,23 +156,20 @@ } -BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) { +//BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) { +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); + strcpy(opt_value, opt_current_value); } return TRUE; } @@ -206,40 +203,44 @@ // command line stuff char arg_option[1024]; - char *arg_value[1024]; - //arg_value = malloc(1024); + char arg_value[1024]; + char *bmp_filename; + char *verbose_option = ""; - VERBOSE = FALSE; + + // parse command line arguments + if (argc < 2) { + fprintf(stderr, "Can not run without arguments!\nPlease specify '-t {number of threads}' or '-p {number of processes}' and an image filename.\n"); + exit(EXIT_FAILURE); + } - // "parse" command line arguments - /* - if (argc >= 2) { - if (strcmp(argv[1], "--worker") == 0) { - is_worker_process = TRUE; - } + if (scan_argv(argc, argv, "--verbose", arg_value)) { + VERBOSE = 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)) { + if (strlen(arg_value) == 0) { + fprintf(stderr, "Please specify number of processes!\n"); + exit(EXIT_FAILURE); + } use_processes = TRUE; is_worker_process = FALSE; workers = atoi(arg_value); } else if (scan_argv(argc, argv, "-t", arg_value)) { + if (strlen(arg_value) == 0) { + fprintf(stderr, "Please specify number of threads!\n"); + exit(EXIT_FAILURE); + } use_processes = FALSE; is_worker_process = FALSE; workers = atoi(arg_value); } - //printf("value: %s\n", arg_value); - //exit(0); if (VERBOSE && use_processes) { @@ -249,16 +250,23 @@ else fprintf(stdout, "MASTER-PROCESS\n"); } - - // create empty bmp-file (black background) - if (!is_worker_process) - write_blank_file("test.bmp"); - // master creates memory mapped file + + // master creates memory mapped file ("empty" image) if (!is_worker_process) { + if (argc < 4) { + fprintf(stderr, "Must give filename of image as third argument!\n"); + exit(EXIT_FAILURE); + } + + bmp_filename = argv[3]; + + // create empty bmp-file (black background) + write_blank_file(bmp_filename); + // open file for reading and writing - hFile = CreateFile("test.bmp", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + hFile = CreateFile(bmp_filename, GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) { err = GetLastError(); printErrorAndExit("Error at CreateFile",err); @@ -390,7 +398,9 @@ } else { - _snprintf(szCmdline, 1023, "%s %s %i %i", argv[0], "--worker", worker_startrow, worker_rows); + if (VERBOSE) + verbose_option = "--verbose"; + _snprintf(szCmdline, 1023, "%s %s %i %i %s", argv[0], "--worker", worker_startrow, worker_rows, verbose_option); if (VERBOSE) fprintf(stdout, "starting worker process: %s\n", szCmdline); ZeroMemory( &si, sizeof(si) );