comparison urogue/main.c @ 259:096d3cfd9afd

UltraRogue: add the -n option.
author John "Elwin" Edwards
date Thu, 09 Feb 2017 16:29:45 -0500
parents c495a4f288c6
children 08057be02f47
comparison
equal deleted inserted replaced
258:2908dc47f9e2 259:096d3cfd9afd
21 #include <time.h> 21 #include <time.h>
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #include <string.h> 23 #include <string.h>
24 #include <signal.h> 24 #include <signal.h>
25 #include <stdlib.h> 25 #include <stdlib.h>
26 #include <errno.h>
26 #include "rogue.h" 27 #include "rogue.h"
28
29 #define SAVEDIR "."
27 30
28 FILE *fd_score = NULL; 31 FILE *fd_score = NULL;
29 32
30 /* Command line options */ 33 /* Command line options */
31 34
60 63
61 case 'r': 64 case 'r':
62 rflag = TRUE; 65 rflag = TRUE;
63 break; 66 break;
64 67
68 #ifdef SAVEDIR
69 case 'n':
70 if (x + 1 < argc) {
71 use_savedir = TRUE;
72 x++;
73 // Set rogue's name to the next argument
74 strncpy(whoami, argv[x], 2*LINELEN);
75 whoami[2*LINELEN - 1] = '\0';
76 // And set up the savefile name
77 snprintf(file_name, 2*LINELEN, "%s/%d-%.80s.ursav", SAVEDIR,
78 md_getuid(), whoami);
79 }
80 break;
81 #endif
82
65 default: 83 default:
66 fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]); 84 fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
67 exit(1); 85 exit(1);
68 } 86 }
69 } 87 }
84 fd_score = fopen(score_file, "a+"); 102 fd_score = fopen(score_file, "a+");
85 103
86 if ((env = getenv("OPTIONS")) != NULL) 104 if ((env = getenv("OPTIONS")) != NULL)
87 parse_opts(env); 105 parse_opts(env);
88 106
89 nm = getenv("USER"); 107 if (!use_savedir) {
90 108 nm = getenv("USER");
91 if (nm != NULL) 109
92 strcpy(whoami,nm); 110 if (nm != NULL)
93 else 111 strcpy(whoami,nm);
94 strcpy(whoami,"anonymous"); 112 else
113 strcpy(whoami,"anonymous");
114 }
95 115
96 lowtime = time(&now); 116 lowtime = time(&now);
97 117
98 dnum = (wizard && getenv("SEED") != NULL ? atoi( getenv("SEED")) : (int)lowtime); 118 dnum = (wizard && getenv("SEED") != NULL ? atoi( getenv("SEED")) : (int)lowtime);
99 119
166 186
167 cw = newwin(LINES, COLS, 0, 0); 187 cw = newwin(LINES, COLS, 0, 0);
168 mw = newwin(LINES, COLS, 0, 0); 188 mw = newwin(LINES, COLS, 0, 0);
169 hw = newwin(LINES, COLS, 0, 0); 189 hw = newwin(LINES, COLS, 0, 0);
170 190
171 if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1])) 191 if (use_savedir) {
192 if (!restore(file_name))
193 exit(1);
194 }
195 else if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
172 /* Note: restore returns on error only */ 196 /* Note: restore returns on error only */
173 exit(1); 197 exit(1);
174 198
175 waswizard = wizard; /* set wizard flags */ 199 waswizard = wizard; /* set wizard flags */
176 200