I cringed while writing this, looking at all those unsafe string calls.
I resisted the urge to go off on a tangent, correcting all of them.
Rather than do that now and forget what I should be doing, I'll get
directory restriction done and THEN tackle the string call problem.
#define FALSE 0
#endif
+#ifndef PATH_MAX
+# ifdef MAXPATHLEN /* defined in <sys/param.h> some systems */
+# define PATH_MAX MAXPATHLEN
+# else
+# if FILENAME_MAX > 255 /* used like PATH_MAX on some systems */
+# define PATH_MAX FILENAME_MAX
+# else
+# define PATH_MAX (FILNAMSIZ - 1)
+# endif
+# endif /* ?MAXPATHLEN */
+#endif /* !PATH_MAX */
+
+
+#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined (__CYGWIN__)
+#define PATH_SEPARATOR '\\'
+#else
+#define PATH_SEPARATOR '/'
+#endif
+
/* typedef unsigned short zbyte; */
typedef unsigned char zbyte;
typedef unsigned short zword;
char *aux_name;
char *story_path;
char *zcode_path;
+ char *write_path;
int restore_mode; /* for a save file passed from command line*/
bool use_blorb;
do_more_prompts = TRUE;
/* Parse the options */
do {
- c = zgetopt(argc, argv, "-aAh:iI:moOpPs:r:R:S:tu:vw:xZ:");
+ c = zgetopt(argc, argv, "-aAh:iI:moOpPs:r:R:S:tu:vw:W:xZ:");
switch(c) {
case 'a': f_setup.attribute_assignment = 1; break;
case 'A': f_setup.attribute_testing = 1; break;
case 'u': f_setup.undo_slots = atoi(zoptarg); break;
case 'v': print_version(); exit(2); break;
case 'w': user_screen_width = atoi(zoptarg); break;
+ case 'W': f_setup.write_path = strndup(zoptarg, PATH_MAX); break;
case 'x': f_setup.expand_abbreviations = 1; break;
case 'Z': f_setup.err_report_mode = atoi(zoptarg);
if ((f_setup.err_report_mode < ERR_REPORT_NEVER) ||
{
char buf[INPUT_BUFFER_SIZE], prompt[INPUT_BUFFER_SIZE];
FILE *fp;
+ char *tempname;
+ int i;
/* If we're restoring a game before the interpreter starts,
* our filename is already provided. Just go ahead silently.
strcpy (file_name, buf[0] ? buf : default_name);
+ /* Check if we're restricted to one directory. */
+ if (f_setup.write_path != NULL) {
+ for (i = strlen(file_name); i > 0; i--) {
+ if (file_name[i] == PATH_SEPARATOR) {
+ i++;
+ break;
+ }
+ }
+ tempname = strdup(file_name + i);
+ strcpy(file_name, f_setup.write_path);
+ if (file_name[strlen(file_name)-1] != PATH_SEPARATOR) {
+ strcat(file_name, "/");
+ }
+ strcat(file_name, tempname);
+ }
+
/* Warn if overwriting a file. */
if ((flag == FILE_SAVE || flag == FILE_SAVE_AUX || flag == FILE_RECORD)
&& ((fp = fopen(file_name, "rb")) != NULL)) {