static int processturn(const char *orders) { turn++; readorders(orders); processorders(); reports(); writesummary(); writegame(); return 0; }
int writereport() /* **------------------------------------------------------ ** Input: none ** Output: returns error code ** Purpose: writes formatted output report to file ** ** Calls strcomp() from the EPANET.C module. **------------------------------------------------------ */ { char tflag; FILE *tfile; int errcode = 0; /* If no secondary report file specified then */ /* write formatted output to primary report file. */ Fprinterr = FALSE; if (Rptflag && strlen(Rpt2Fname) == 0 && RptFile != NULL) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* A secondary report file was specified */ else if (strlen(Rpt2Fname) > 0) { /* If secondary report file has same name as either input */ /* or primary report file then use primary report file. */ if (strcomp(Rpt2Fname,InpFname) || strcomp(Rpt2Fname,Rpt1Fname)) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* Otherwise write report to secondary report file. */ else { /* Try to open file */ tfile = RptFile; tflag = Rptflag; if ((RptFile = fopen(Rpt2Fname,"wt")) == NULL) { RptFile = tfile; Rptflag = tflag; errcode = 303; } /* Write full formatted report to file */ else { Rptflag = 1; writecon(FMT17); writecon(Rpt2Fname); writelogo(); if (Summaryflag) writesummary(); if (Energyflag) writeenergy(); errcode = writeresults(); fclose(RptFile); RptFile = tfile; Rptflag = tflag; } } } /* Special error handler for write-to-file error */ if (Fprinterr) errmsg(309); return(errcode); } /* End of writereport */
int main(int argc, char **argv) { int i; char buf[12]; const char *arg, *orders = 0, *cfgfile = 0; rnd_seed((unsigned int) time(0)); puts("Atlantis v1.0 " __DATE__ "\n" "Copyright 1993 by Russell Wallace.\n" "Type ? for list of commands."); turn = -1; for (i = 1; i != argc; ++i) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'c': cfgfile = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; break; case 'i': ignore_password = 1; break; case 'p': /* process */ orders = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; break; case 't': /* turn */ arg = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; turn = atoi(arg); break; default: fprintf(stderr, "invalid argument %d: '%s'\n", i, argv[i]); return -1; } } } if (cfgfile) { FILE * F = fopen(cfgfile, "r"); if (F) { cJSON *json; char *data; size_t len; fseek(F, 0,SEEK_END); len = ftell(F); fseek(F,0,SEEK_SET); data = (char *)malloc(len+1); if (data) { fread(data,1,len,F); } json = cJSON_Parse(data); if (json) { read_config_json(json); cJSON_Delete(json); } else { fprintf(stderr, "could not parse configuration file '%s'\n", cfgfile); } free(data); } else { fprintf(stderr, "could not open configuration file '%s'\n", cfgfile); return errno ? errno : -1; } } initgame(); if (orders) { return processturn(orders); } for (;;) { printf("> "); fgets(buf, sizeof(buf), stdin); switch (tolower(buf[0])) { case 'm': writemap(stdout); break; case 'g': turn = 0; cleargame(false); autoworld("players"); writemap(stdout); break; case 'r': reports(); break; case 'f': fixme(); break; case 'w': writesummary(); writegame(); break; case 'p': printf("Name of orders file? "); fgets(buf, sizeof(buf), stdin); if (!buf[0]) return -1; return processturn(buf); case 'q': return 0; default: puts("C - Create New Continent.\n" "A - Add New Players.\n" "M - Draw Map.\n" "P - Process Game Turn.\n" "R - Write Reports.\n" "G - Generate New World.\n" "Q - Quit.\n" "W - Write Game.\n"); } } }