--- cheapglk/cgfref.c.orig	Mon Jul 23 13:10:07 2001
+++ cheapglk/cgfref.c	Tue Aug 14 11:46:01 2001
@@ -133,6 +133,8 @@
     char buf2[256];
     int len;
     char *cx;
+    int strip_leading = 0;
+    char *new_start;
     
     len = strlen(name);
     if (len > 255)
@@ -167,6 +169,30 @@
     
     sprintf(buf2, "%s/%s", workingdir, buf);
 
+    strip_leading = 0;
+    /* scan for directory delimiters */
+    for ( cx=buf2; *cx; cx++) {
+        if (*cx=='/') {
+	    strip_leading = 1;
+        }
+    }
+    /* found one, wipe it... */
+    if ( strip_leading == 1 ) {
+        new_start = buf2;
+        for ( cx=buf2; *cx; cx++) {
+	    if (*cx=='/') {
+	        new_start = cx;
+		new_start++;
+            }
+        }
+	sprintf( buf2, "%s", new_start );
+	if ( buf2[0] == '\0' )
+	{
+	    buf2[0] = 'X';
+	    buf2[1] = '\0';
+	}
+    }
+
     fref = gli_new_fileref(buf2, usage, rock);
     if (!fref) {
         gli_strict_warning("fileref_create_by_name: unable to create fileref.");
@@ -184,6 +210,8 @@
     char *cx;
     int val;
     char *prompt, *prompt2;
+    int strip_leading = 0;
+    char *new_start;
     
     switch (usage & fileusage_TypeMask) {
         case fileusage_SavedGame:
@@ -206,7 +234,7 @@
     else
         prompt2 = "to store";
     
-    printf("%s %s: ", prompt, prompt2);
+    printf("%s %s: \n", prompt, prompt2);
     
     fgets(buf, 255, stdin);
     val = strlen(buf);
@@ -217,7 +245,8 @@
             || buf[val-1] == ' '))
         val--;
     buf[val] = '\0';
-    
+
+    /* eliminate leading spaces */
     for (cx = buf; *cx == ' '; cx++) { }
     
     val = strlen(cx);
@@ -226,11 +255,38 @@
             default value, but this implementation is too cheap. */
         return NULL;
     }
-    
+
     if (cx[0] == '/')
         strcpy(newbuf, cx);
     else
         sprintf(newbuf, "%s/%s", workingdir, cx);
+
+    /* cleanup -- no relative or absolute paths allowed! */
+    /* scan for directory delimiters */
+    strip_leading = 0;
+    for ( cx=newbuf; *cx; cx++) {
+        if (*cx=='/')
+	    strip_leading = 1;
+    }
+    /* found one, wipe it... */
+    if ( strip_leading ) {
+        for ( cx=newbuf; *cx; cx++) {
+	    if (*cx=='/') {
+	        new_start = cx;
+		new_start++;
+            }
+        }
+	sprintf( newbuf, "%s", new_start );
+	if ( newbuf[0] == '\0' )
+	{
+	    newbuf[0] = 'X';
+	    newbuf[1] = '\0';
+	}
+    }
+    for (cx=newbuf; *cx; cx++) {
+        if (*cx == '/')
+            *cx = '-';
+    }
 
     fref = gli_new_fileref(newbuf, usage, rock);
     if (!fref) {
