Package: xzip / 1:1.8.2-4

002_savename.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Keep savename files in $HOME

--- a/fileio.c
+++ b/fileio.c
@@ -78,46 +78,41 @@
 const char *storyname;
 #endif
 {
-    char *per_pos=0;
-
-    /* experimental setting of save_name, added by John Holder 26 July 1995 */
-    per_pos = strrchr(storyname,'.'); /* find last '.' in storyname. */
-    if (per_pos) /* The story file looks like "Odius.dat" or "odieus.z3" */
-    {
-      strcpy(save_name, storyname);
-      per_pos=strrchr(save_name,'.');
-      *(per_pos) = '\0';
-      strcat(save_name,".sav");
-
-      strcpy(script_name, storyname);
-      per_pos=strrchr(script_name,'.');
-      *(per_pos) = '\0';
-      strcat(script_name,".scr");
-
-      strcpy(savedata_name, storyname);
-      per_pos=strrchr(savedata_name,'.');
-      *(per_pos) = '\0';
-      strcat(savedata_name,".dat");
-
-      strcpy(record_name, storyname);
-      per_pos=strrchr(record_name,'.');
-      *(per_pos) = '\0';
-      strcat(record_name,".rec");
-    }
-    else /* The story file looks like: "OdieusQuest" */
-    {
-      strcpy(save_name, storyname);
-      strcat(save_name,".sav");
-
-      strcpy(script_name, storyname);
-      strcat(script_name,".scr");
-
-      strcpy(savedata_name, storyname);
-      strcat(savedata_name,".dat");
-
-      strcpy(record_name, storyname);
-      strcat(record_name,".rec");
-    }
+    char *dot_pos ;
+    char *slash_pos ;
+    char *home ;
+    char basename[FILENAME_MAX+1] ;
+
+    /* Find base name */
+    if( slash_pos = strrchr( storyname, '/' ) )
+      strcpy( basename, ++slash_pos ) ;
+    else
+      strcpy( basename, storyname ) ;
+
+    if( dot_pos = strrchr( basename, '.' ) )
+      *dot_pos = '\0' ;
+
+    /* Find correct directory */
+    if( home = getenv( "HOME" ) )
+      {
+	strcpy( save_name, home ) ;
+	strcat( save_name, "/.infocom/" ) ;
+	mkdir( save_name, 0777 ) ;
+      }
+
+    /* Home directory + basename */
+    strcat( save_name, basename ) ;
+
+    /* Copy to other three strings */
+    strcpy( script_name, save_name ) ;
+    strcpy( record_name, save_name ) ;
+    strcpy( savedata_name, save_name ) ;
+
+    /* Add extensions */
+    strcat(save_name,".sav");
+    strcat(script_name,".scr");
+    strcat(record_name,".rec");
+    strcat(savedata_name,".dat");
 } /* set_names */
 
 /*