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 outputing save files that advent
7 * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
8 * Copyright (c) 2017 by Eric S. Raymond
9 * SPDX-License-Identifier: BSD-2-clause
15 #include <editline/readline.h>
18 int main(int argc, char *argv[])
21 char *savefilename = NULL;
25 // Initialize game variables
28 /* we're generating a saved game, so saved once by default,
29 * unless overridden with command-line options below.
34 const char* opts = "d:l:s:t:v:o:";
35 const char* usage = "Usage: %s [-d numdie] [-s numsaves] [-v version] -o savefilename \n"
36 " -d number of deaths. Signed integer.\n"
37 " -l lifetime of lamp in turns. Signed integer.\n"
38 " -s number of saves. Signed integer.\n"
39 " -t number of turns. Signed integer.\n"
40 " -v version number of save format.\n"
41 " -o required. File name of save game to write.\n";
43 while ((ch = getopt(argc, argv, opts)) != EOF) {
46 game.numdie = (turn_t)atoi(optarg);
47 printf("cheat: game.numdie = %d\n", game.numdie);
50 game.limit = (turn_t)atoi(optarg);
51 printf("cheat: game.limit = %d\n", game.limit);
54 game.saved = (int)atoi(optarg);
55 printf("cheat: game.saved = %d\n", game.saved);
58 game.turns = (turn_t)atoi(optarg);
59 printf("cheat: game.turns = %d\n", game.turns);
62 version = atoi(optarg);
63 printf("cheat: version = %d\n", version);
66 savefilename = optarg;
76 // Save filename required; the point of cheat is to generate save file
77 if (savefilename == NULL) {
81 "ERROR: filename required\n");
85 fp = fopen(savefilename, WRITE_MODE);
88 "Can't open file %s. Exiting.\n", savefilename);
92 savefile(fp, version);
96 printf("cheat: %s created.\n", savefilename);
102 * Ugh...unused, but required for linkage.
103 * See thje actually useful version of this in main.c
106 char *myreadline(const char *prompt)
108 return readline(prompt);