aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-03-01 18:32:49 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2026-03-01 18:32:49 +0100
commit2ac46cb4d4133e5d5de90bacfc9b6e979d1d6046 (patch)
treee0836773b1e802446437ea1d4aec7b1c8df45d2d /shell
parent895a8ec484ead49ab243772895b24b787e94ef0e (diff)
downloadnissy-core-0.3.tar.gz
nissy-core-0.3.zip
Shell improvementsv0.3
Ask before overwriting a table file.
Diffstat (limited to '')
-rw-r--r--shell/shell.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/shell/shell.c b/shell/shell.c
index 698252d..3469300 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -10,6 +10,7 @@
10 10
11#include "../src/nissy.h" 11#include "../src/nissy.h"
12 12
13#define INPUT_BUFFER_SIZE UINT64_C(1024)
13#define PRINTCUBE_BUFFER_SIZE UINT64_C(1024) 14#define PRINTCUBE_BUFFER_SIZE UINT64_C(1024)
14#define SOLUTIONS_BUFFER_SIZE UINT64_C(500000) 15#define SOLUTIONS_BUFFER_SIZE UINT64_C(500000)
15#define MAX_PATH_LENGTH UINT64_C(10000) 16#define MAX_PATH_LENGTH UINT64_C(10000)
@@ -328,6 +329,7 @@ gendata_exec(args_t *args)
328 int i; 329 int i;
329 FILE *file; 330 FILE *file;
330 char path[MAX_PATH_LENGTH], dataid[NISSY_SIZE_DATAID]; 331 char path[MAX_PATH_LENGTH], dataid[NISSY_SIZE_DATAID];
332 char r[INPUT_BUFFER_SIZE];
331 unsigned char *buf; 333 unsigned char *buf;
332 int64_t ret, size; 334 int64_t ret, size;
333 size_t written; 335 size_t written;
@@ -340,10 +342,21 @@ gendata_exec(args_t *args)
340 return -3; 342 return -3;
341 } 343 }
342 344
343 /* TODO: should give warning if overwriting existing file */
344 for (i = 0; tablepaths[i] != NULL; i++) { 345 for (i = 0; tablepaths[i] != NULL; i++) {
345 strcpy(path, tablepaths[i]); 346 strcpy(path, tablepaths[i]);
346 strcat(path, dataid); 347 strcat(path, dataid);
348
349 if ((file = fopen(path, "rb")) != NULL) {
350 fclose(file);
351 fprintf(stderr, "gendata: file %s already exists, "
352 "overwrite? [Y/n] ", path);
353 fgets(r, INPUT_BUFFER_SIZE, stdin);
354 if (r[0] != '\n' && r[0] != 'Y' && r[0] != 'y') {
355 fprintf(stderr, "gendata: aborting.\n");
356 return -1;
357 }
358 }
359
347 file = fopen(path, "wb"); 360 file = fopen(path, "wb");
348 if (file != NULL) 361 if (file != NULL)
349 break; 362 break;

Generated with cgit - Back to sebastiano.tronto.net