/[cvs]/joko/Uni/BSArch/04/bmp_fractal.c
ViewVC logotype

Diff of /joko/Uni/BSArch/04/bmp_fractal.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by joko, Sun Jul 2 09:27:14 2006 UTC revision 1.14 by joko, Sun Jul 2 11:44:57 2006 UTC
# Line 156  DWORD WINAPI fractal_create_segment (LPV Line 156  DWORD WINAPI fractal_create_segment (LPV
156    
157  }  }
158    
159    //BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) {
160    BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value) {
161      int i;
162      char * opt_current_name;
163      char * opt_current_value;
164    
165      //printf("searching for: '%s'\n", opt_name);
166      
167      for (i = 1; i < argc; i++) {
168        opt_current_name = argv[i];
169        if (strcmp(opt_current_name, opt_name) == 0) {
170          opt_current_value = argv[i+1];
171          if (opt_current_value != NULL) {
172            strcpy(opt_value, opt_current_value);
173          }
174          return TRUE;
175        }
176      }
177      return FALSE;
178    }
179    
180    
181  int main(int argc, char *argv[]) {  int main(int argc, char *argv[]) {
182    
# Line 172  int main(int argc, char *argv[]) { Line 193  int main(int argc, char *argv[]) {
193    PWORKERARGS worker_args;    PWORKERARGS worker_args;
194    
195    // threads or processes?    // threads or processes?
196    BOOL use_processes = TRUE;    BOOL use_processes = FALSE;
197    BOOL is_worker_process = FALSE;    BOOL is_worker_process = FALSE;
198        
199    // information for creating processes    // information for creating processes
200    STARTUPINFO si;    STARTUPINFO si;
201    PROCESS_INFORMATION pi;    PROCESS_INFORMATION pi;
202    char szCmdline[1024];    char szCmdline[65536];
203      
204      // command line stuff
205      char arg_option[1024];
206      char arg_value[1024];
207      char *bmp_filename;
208      char *verbose_option = "";
209        
210    
211      // parse command line arguments
212      if (argc < 2) {
213        fprintf(stderr, "Can not run without arguments!\nPlease specify '-t {number of threads}' or '-p {number of processes}' and an image filename.\n");
214        exit(EXIT_FAILURE);
215      }
216        
217    VERBOSE = TRUE;    if (scan_argv(argc, argv, "--verbose", arg_value)) {
218        VERBOSE = TRUE;
219      }
220        
221    // "parse" command line arguments    if (scan_argv(argc, argv, "--worker", arg_value)) {
222    if (argc >= 2) {      use_processes = TRUE;
223      if (strcmp(argv[1], "--worker") == 0) {      is_worker_process = TRUE;
224        is_worker_process = TRUE;    
225      } else if (scan_argv(argc, argv, "-p", arg_value)) {
226        if (strlen(arg_value) == 0) {
227          fprintf(stderr, "Please specify number of processes!\n");
228          exit(EXIT_FAILURE);
229        }
230        use_processes = TRUE;
231        is_worker_process = FALSE;
232        workers = atoi(arg_value);
233      
234      } else if (scan_argv(argc, argv, "-t", arg_value)) {
235        if (strlen(arg_value) == 0) {
236          fprintf(stderr, "Please specify number of threads!\n");
237          exit(EXIT_FAILURE);
238      }      }
239        use_processes = FALSE;
240        is_worker_process = FALSE;
241        workers = atoi(arg_value);
242        
243    }    }
244        
245      
246    if (VERBOSE && use_processes) {    if (VERBOSE && use_processes) {
247      fprintf(stdout, "===================================================== ");      fprintf(stdout, "===================================================== ");
248      if (is_worker_process)      if (is_worker_process)
# Line 197  int main(int argc, char *argv[]) { Line 250  int main(int argc, char *argv[]) {
250      else      else
251        fprintf(stdout, "MASTER-PROCESS\n");        fprintf(stdout, "MASTER-PROCESS\n");
252    }    }
     
   // create empty bmp-file (black background)  
   if (!is_worker_process)  
     write_blank_file("test.bmp");  
253    
254    // master creates memory mapped file    
255      // master creates memory mapped file ("empty" image)
256    if (!is_worker_process) {    if (!is_worker_process) {
257            
258        if (argc < 4) {
259          fprintf(stderr, "Must give filename of image as third argument!\n");
260          exit(EXIT_FAILURE);
261        }
262        
263        bmp_filename = argv[3];
264        
265        // create empty bmp-file (black background)
266        write_blank_file(bmp_filename);
267    
268      // open file for reading and writing      // open file for reading and writing
269      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);
270      if (INVALID_HANDLE_VALUE == hFile) {      if (INVALID_HANDLE_VALUE == hFile) {
271        err = GetLastError();        err = GetLastError();
272        printErrorAndExit("Error at CreateFile",err);        printErrorAndExit("Error at CreateFile",err);
# Line 268  int main(int argc, char *argv[]) { Line 328  int main(int argc, char *argv[]) {
328      if (!CloseHandle(hMap))      if (!CloseHandle(hMap))
329        printErrorAndExit("Error at CloseHandle", GetLastError());        printErrorAndExit("Error at CloseHandle", GetLastError());
330            
331      return 0;      return 0;
332    }    }
333        
334    /*    /*
# Line 338  int main(int argc, char *argv[]) { Line 398  int main(int argc, char *argv[]) {
398                
399      } else {      } else {
400    
401        _snprintf(szCmdline, 1023, "%s %s %i %i", argv[0], "--worker", worker_startrow, worker_rows);        if (VERBOSE)
402            verbose_option = "--verbose";
403          _snprintf(szCmdline, 1023, "%s %s %i %i %s", argv[0], "--worker", worker_startrow, worker_rows, verbose_option);
404        if (VERBOSE)        if (VERBOSE)
405          fprintf(stdout, "starting worker process: %s\n", szCmdline);          fprintf(stdout, "starting worker process: %s\n", szCmdline);
406        ZeroMemory( &si, sizeof(si) );        ZeroMemory( &si, sizeof(si) );

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.14

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed