diff options
author | hubertf <hubertf@NetBSD.org> | 1999-07-28 01:45:41 +0000 |
---|---|---|
committer | hubertf <hubertf@NetBSD.org> | 1999-07-28 01:45:41 +0000 |
commit | 932e74d4028472671e706b8d64965ef4a4293d0f (patch) | |
tree | 7155c281e751417d576084fd2feebae3a4e5159e /battlestar/cypher.c | |
parent | d0abda98e89948088de49cb3c2f192c15aa4518d (diff) | |
download | bsdgames-darwin-932e74d4028472671e706b8d64965ef4a4293d0f.tar.gz bsdgames-darwin-932e74d4028472671e706b8d64965ef4a4293d0f.tar.zst bsdgames-darwin-932e74d4028472671e706b8d64965ef4a4293d0f.zip |
This patch improves the handling of save files in battlestar(6), by
allowing the user to choose the name of the save file and specify it
on the command line when restoring. It also eliminates a buffer
overrun in determining the path to the save file, and any particular
arbitrary limit on the name length. In the name of a tidier home
directory, the default name is changed from "Bstar" to ".Bstar".
Patch supplied in PR 8085 by Joseph Myers <jsm28@cam.ac.uk>
Minor modification (s/startup/filename/ in initialize()) by me.
Diffstat (limited to 'battlestar/cypher.c')
-rw-r--r-- | battlestar/cypher.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/battlestar/cypher.c b/battlestar/cypher.c index 7e0e1ba2..5fa8f546 100644 --- a/battlestar/cypher.c +++ b/battlestar/cypher.c @@ -1,4 +1,4 @@ -/* $NetBSD: cypher.c,v 1.8 1999/03/25 16:46:08 hubertf Exp $ */ +/* $NetBSD: cypher.c,v 1.9 1999/07/28 01:45:42 hubertf Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cypher.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: cypher.c,v 1.8 1999/03/25 16:46:08 hubertf Exp $"); +__RCSID("$NetBSD: cypher.c,v 1.9 1999/07/28 01:45:42 hubertf Exp $"); #endif #endif /* not lint */ @@ -51,6 +51,8 @@ cypher() int junk; int lflag = -1; char buffer[10]; + char *filename, *rfilename; + size_t filename_len; while (wordtype[wordnumber] == ADJS) wordnumber++; @@ -367,7 +369,21 @@ cypher() break; case SAVE: - save(); + printf("\nSave file name (default %s) ", + DEFAULT_SAVE_FILE); + filename = fgetln(stdin, &filename_len); + if (filename_len == 0 + || (filename_len == 1 && filename[0] == '\n')) + rfilename = save_file_name(DEFAULT_SAVE_FILE, + strlen(DEFAULT_SAVE_FILE)); + else { + if (filename[filename_len - 1] == '\n') + filename_len--; + rfilename = save_file_name(filename, + filename_len); + } + save(rfilename); + free(rfilename); break; case FOLLOW: |