@@ -418,6 +418,43 @@ int reportCommand(int argc, char *argv[]) {
418
418
struct ship_data * ship , * ship2 , * alien_ship ;
419
419
struct sp_loc_data * locations_base , * my_loc , * its_loc ;
420
420
421
+ // consolidate logic for reporting and logging flags
422
+ // by default, log and report on all species
423
+ int logSpecies = 1 ;
424
+ int reportSpecies [MAX_SPECIES + 1 ];
425
+ for (j = 0 ; j <= MAX_SPECIES ; j ++ ) {
426
+ reportSpecies [j ] = 1 ;
427
+ }
428
+
429
+ // process the arguments and reset flags as needed
430
+ for (i = 1 ; i < argc ; i ++ ) {
431
+ if (strcmp (argv [i ], "--help" ) == 0 || strcmp (argv [i ], "-h" ) == 0 || strcmp (argv [i ], "-?" ) == 0 ) {
432
+ fprintf (stderr , "usage: report [--skip-log] [list-of-species]\n" );
433
+ fprintf (stderr , "\t--skip-log do not include prior turn results in report\n" );
434
+ fprintf (stderr , "\tlist-of-species you may specify individual species numbers to report on\n" );
435
+ return 2 ;
436
+ } else if (strcmp (argv [i ], "--skip-log" ) == 0 ) {
437
+ // turn off logging for all species
438
+ logSpecies = 0 ;
439
+ } else { // should be the species to report
440
+ int speciesNo = atoi (argv [i ]);
441
+ if (speciesNo < 1 || speciesNo > MAX_SPECIES ) {
442
+ fprintf (stderr , "error: unknown species '%s'\n" , argv [i ]);
443
+ return 2 ;
444
+ } else {
445
+ // ugly hack to reset the flags.
446
+ if (reportSpecies [0 ] == 1 ) {
447
+ // reset the flags because we're not reporting on all
448
+ for (j = 0 ; j <= MAX_SPECIES ; j ++ ) {
449
+ reportSpecies [j ] = 0 ;
450
+ }
451
+ }
452
+ // set the flag for this species
453
+ reportSpecies [speciesNo ] = 1 ;
454
+ }
455
+ }
456
+ }
457
+
421
458
/* Get all necessary data. */
422
459
printf ("fh: %s: loading galaxy file...\n" , cmdName );
423
460
get_galaxy_data ();
@@ -436,18 +473,8 @@ int reportCommand(int argc, char *argv[]) {
436
473
int alien_number = 0 ; /* Pointers to alien data not yet assigned. */
437
474
for (species_number = 1 ; species_number <= galaxy .num_species ; species_number ++ ) {
438
475
/* Check if we are doing all species, or just one or more specified ones. */
439
- if (argc > 1 ) {
440
- int do_this_species = FALSE;
441
- for (i = 1 ; i < argc ; i ++ ) {
442
- j = atoi (argv [i ]);
443
- if (species_number == j ) {
444
- do_this_species = TRUE;
445
- break ;
446
- }
447
- }
448
- if (!do_this_species ) {
449
- continue ;
450
- }
476
+ if (reportSpecies [species_number ] != 1 ) {
477
+ continue ;
451
478
}
452
479
453
480
/* Check if this species is still in the game. */
@@ -483,20 +510,22 @@ int reportCommand(int argc, char *argv[]) {
483
510
}
484
511
485
512
/* Copy log file, if any, to output file. */
486
- sprintf (filename , "sp%02d.log" , species_number );
487
- log_file = fopen (filename , "r" );
488
- if (log_file != NULL ) {
489
- if (turn_number > 1 ) {
490
- fprintf (report_file , "\n\n\t\t\tEVENT LOG FOR TURN %d\n" , turn_number - 1 );
491
- }
513
+ if (logSpecies == 1 ) {
514
+ sprintf (filename , "sp%02d.log" , species_number );
515
+ log_file = fopen (filename , "r" );
516
+ if (log_file != NULL ) {
517
+ if (turn_number > 1 ) {
518
+ fprintf (report_file , "\n\n\t\t\tEVENT LOG FOR TURN %d\n" , turn_number - 1 );
519
+ }
492
520
493
- while (readln (log_line , 256 , log_file ) != NULL ) {
494
- fputs (log_line , report_file );
495
- }
521
+ while (readln (log_line , 256 , log_file ) != NULL ) {
522
+ fputs (log_line , report_file );
523
+ }
496
524
497
- fprintf (report_file , "\n\n" );
525
+ fprintf (report_file , "\n\n" );
498
526
499
- fclose (log_file );
527
+ fclose (log_file );
528
+ }
500
529
}
501
530
502
531
/* Print header for status report. */
0 commit comments