Skip to content

Commit 52d15ab

Browse files
committed
added skip-log to reports
and usage text
1 parent 5a3cf26 commit 52d15ab

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

src/report.c

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,43 @@ int reportCommand(int argc, char *argv[]) {
418418
struct ship_data *ship, *ship2, *alien_ship;
419419
struct sp_loc_data *locations_base, *my_loc, *its_loc;
420420

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+
421458
/* Get all necessary data. */
422459
printf("fh: %s: loading galaxy file...\n", cmdName);
423460
get_galaxy_data();
@@ -436,18 +473,8 @@ int reportCommand(int argc, char *argv[]) {
436473
int alien_number = 0; /* Pointers to alien data not yet assigned. */
437474
for (species_number = 1; species_number <= galaxy.num_species; species_number++) {
438475
/* 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;
451478
}
452479

453480
/* Check if this species is still in the game. */
@@ -483,20 +510,22 @@ int reportCommand(int argc, char *argv[]) {
483510
}
484511

485512
/* 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+
}
492520

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+
}
496524

497-
fprintf(report_file, "\n\n");
525+
fprintf(report_file, "\n\n");
498526

499-
fclose(log_file);
527+
fclose(log_file);
528+
}
500529
}
501530

502531
/* Print header for status report. */

0 commit comments

Comments
 (0)