\10Cleaned up do_command() a little
[open-adventure.git] / saveresume.c
index ab47a3bfa56fd84a19c30e01848a7425963fc1a4..a3dbe968ebdaf4838ea2552d6c77b6e951143721 100644 (file)
@@ -1,16 +1,17 @@
 #include <stdlib.h>
 #include <string.h>
+#include <editline/readline.h>
+#include <time.h>
 
 #include "advent.h"
-#include "newdb.h"
-#include "linenoise/linenoise.h"
+#include "dungeon.h"
 
 /*
  * (ESR) This replaces  a bunch of particularly nasty FORTRAN-derived code;
  * see the history.adoc file in the source distribution for discussion.
  */
 
-#define VRSION 26      /* bump on save format change */
+#define VRSION 27      /* bump on save format change */
 
 /*
  * If you change the first three members, the resume function may not properly
@@ -26,20 +27,18 @@ struct save_t {
 };
 struct save_t save;
 
+#define IGNORE(r) do{if (r){}}while(0)
+
 int savefile(FILE *fp, long version)
-    /* Save game to file. No input or output from user. */
+/* Save game to file. No input or output from user. */
 {
-    long i, k;
-    datime(&i, &k);
-    k = i + 650 * k;
-    save.savetime = k;
+    save.savetime = time(NULL);
     save.mode = -1;
-    
     save.version = (version == 0) ? VRSION : version;
-    
+
     memcpy(&save.game, &game, sizeof(struct game_t));
     IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
-    return(0);
+    return (0);
 }
 
 /* Suspend and resume */
@@ -56,23 +55,24 @@ int suspend(void)
     FILE *fp = NULL;
 
     rspeak(SUSPEND_WARNING);
-    if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
+    if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+        return GO_CLEAROBJ;
     game.saved = game.saved + 5;
 
     while (fp == NULL) {
-        char* name = linenoise("\nFile name: ");
+        char* name = readline("\nFile name: ");
         if (name == NULL)
             return GO_TOP;
         fp = fopen(name, WRITE_MODE);
         if (fp == NULL)
             printf("Can't open file %s, try again.\n", name);
-        linenoiseFree(name);
+        free(name);
     }
 
     savefile(fp, VRSION);
     fclose(fp);
     rspeak(RESUME_HELP);
-    exit(0);
+    exit(EXIT_SUCCESS);
 }
 
 int resume(void)
@@ -85,19 +85,21 @@ int resume(void)
 #endif
     FILE *fp = NULL;
 
-    if (game.loc != 1 || game.abbrev[1] != 1) {
+    if (game.loc != 1 ||
+        game.abbrev[1] != 1) {
         rspeak(RESUME_ABANDON);
-        if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) return GO_CLEAROBJ;
+        if (!yes(arbitrary_messages[THIS_ACCEPTABLE], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+            return GO_CLEAROBJ;
     }
 
     while (fp == NULL) {
-        char* name = linenoise("\nFile name: ");
+        char* name = readline("\nFile name: ");
         if (name == NULL)
             return GO_TOP;
         fp = fopen(name, READ_MODE);
         if (fp == NULL)
             printf("Can't open file %s, try again.\n", name);
-        linenoiseFree(name);
+        free(name);
     }
 
     return restore(fp);
@@ -118,8 +120,6 @@ int restore(FILE* fp)
         rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
     } else {
         memcpy(&game, &save.game, sizeof(struct game_t));
-        //game.zzword = rndvoc(3, game.zzword);
-       make_zzword(game.zzword);
     }
     return GO_TOP;
 }