2 * 'cheat' is a tool for generating save game files to test states that ought
3 * not happen. It leverages chunks of advent, mostly initialize() and
4 * savefile(), so we know we're always outputting save files that advent
7 * SPDX-FileCopyrightText: (C) 1977, 2005 by Will Crowther and Don Woods
8 * SPDX-License-Identifier: BSD-2-Clause
11 #include <editline/readline.h>
17 int main(int argc, char *argv[]) {
19 char *savefilename = NULL;
22 // Initialize game variables
25 /* we're generating a saved game, so saved once by default,
26 * unless overridden with command-line options below.
31 const char *opts = "d:l:s:t:v:o:";
33 "Usage: %s [-d numdie] [-s numsaves] [-v version] -o savefilename "
35 " -d number of deaths. Signed integer.\n"
36 " -l lifetime of lamp in turns. Signed integer.\n"
37 " -s number of saves. Signed integer.\n"
38 " -t number of turns. Signed integer.\n"
39 " -v version number of save format.\n"
40 " -o required. File name of save game to write.\n";
42 while ((ch = getopt(argc, argv, opts)) != EOF) {
45 game.numdie = (turn_t)atoi(optarg);
46 printf("cheat: game.numdie = %d\n", game.numdie);
49 game.limit = (turn_t)atoi(optarg);
50 printf("cheat: game.limit = %d\n", game.limit);
53 game.saved = (int)atoi(optarg);
54 printf("cheat: game.saved = %d\n", game.saved);
57 game.turns = (turn_t)atoi(optarg);
58 printf("cheat: game.turns = %d\n", game.turns);
61 save.version = atoi(optarg);
62 printf("cheat: version = %d\n", save.version);
65 savefilename = optarg;
68 fprintf(stderr, usage, argv[0]);
74 // Save filename required; the point of cheat is to generate save file
75 if (savefilename == NULL) {
76 fprintf(stderr, usage, argv[0]);
77 fprintf(stderr, "ERROR: filename required\n");
81 fp = fopen(savefilename, WRITE_MODE);
83 fprintf(stderr, "Can't open file %s. Exiting.\n", savefilename);
91 printf("cheat: %s created.\n", savefilename);
98 * Ugh...unused, but required for linkage.
99 * See the actually useful version of this in main.c
102 char *myreadline(const char *prompt) { return readline(prompt); }