Use linenoise to get the save file name.
This commit is contained in:
parent
955032bd24
commit
7e1ef875fc
1 changed files with 5 additions and 4 deletions
9
misc.c
9
misc.c
|
@ -6,6 +6,7 @@
|
||||||
#include "advent.h"
|
#include "advent.h"
|
||||||
#include "funcs.h"
|
#include "funcs.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "linenoise/linenoise.h"
|
||||||
|
|
||||||
/* hack to ignore GCC Unused Result */
|
/* hack to ignore GCC Unused Result */
|
||||||
#define IGNORE(r) do{if (r){}}while(0)
|
#define IGNORE(r) do{if (r){}}while(0)
|
||||||
|
@ -819,8 +820,8 @@ void fSAVEIO(long op, long in, long arr[])
|
||||||
* automatically. Finishing reading can be a no-op as long as a subsequent
|
* automatically. Finishing reading can be a no-op as long as a subsequent
|
||||||
* SAVEIO(0,false,X) will still work.) */
|
* SAVEIO(0,false,X) will still work.) */
|
||||||
{
|
{
|
||||||
static FILE *fp = NULL;
|
static FILE *fp = NULL;
|
||||||
char name[50];
|
char* name;
|
||||||
|
|
||||||
switch (op < 0 ? -1 : (op > 0 ? 1 : 0))
|
switch (op < 0 ? -1 : (op > 0 ? 1 : 0))
|
||||||
{
|
{
|
||||||
|
@ -829,12 +830,12 @@ void fSAVEIO(long op, long in, long arr[])
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
while (fp == NULL) {
|
while (fp == NULL) {
|
||||||
printf("\nFile name: ");
|
name = linenoise("File name: ");
|
||||||
IGNORE(fgets(name, sizeof(name), stdin));
|
|
||||||
fp = fopen(name,(in ? READ_MODE : WRITE_MODE));
|
fp = fopen(name,(in ? READ_MODE : WRITE_MODE));
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
printf("Can't open file %s, try again.\n", name);
|
printf("Can't open file %s, try again.\n", name);
|
||||||
}
|
}
|
||||||
|
linenoiseFree(name);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (in)
|
if (in)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue