aboutsummaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-10 19:49:48 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-10 19:49:48 +0200
commit5e291466fbbc45aed74f67a1b2e555d1f0c44d8f (patch)
treeebe96c88599d55ee1b986412f1d0456f55f950a9 /shell.c
parentd4fadc24ee1993104bac7fd854ed6ca83f60ee66 (diff)
downloadnissy-core-5e291466fbbc45aed74f67a1b2e555d1f0c44d8f.tar.gz
nissy-core-5e291466fbbc45aed74f67a1b2e555d1f0c44d8f.zip
Improved error messages and add some comments in nissy.h
Diffstat (limited to '')
-rw-r--r--shell.c56
1 files changed, 15 insertions, 41 deletions
diff --git a/shell.c b/shell.c
index efff70b..efabc6c 100644
--- a/shell.c
+++ b/shell.c
@@ -56,9 +56,6 @@ typedef struct {
56 int64_t maxsolutions; 56 int64_t maxsolutions;
57} args_t; 57} args_t;
58 58
59static void print_cube_result(int64_t, char [static 22]);
60static void print_str_result(int64_t, char *);
61
62static int64_t compose_exec(args_t *); 59static int64_t compose_exec(args_t *);
63static int64_t inverse_exec(args_t *); 60static int64_t inverse_exec(args_t *);
64static int64_t applymoves_exec(args_t *); 61static int64_t applymoves_exec(args_t *);
@@ -240,36 +237,6 @@ rand64(void)
240 return ret; 237 return ret;
241} 238}
242 239
243static void
244print_cube_result(int64_t ret, char result[static 22])
245{
246 switch (ret) {
247 case 0:
248 break;
249 case 1:
250 fprintf(stderr, "Warning: resulting cube not solvable\n");
251 break;
252 case 2: /* Fallthrough */
253 default:
254 fprintf(stderr, "Unknown error (result is inconsistent)\n");
255 }
256
257 printf("%s\n", result);
258}
259
260static void
261print_str_result(int64_t ret, char *result)
262{
263 switch (ret) {
264 case 0:
265 break;
266 default:
267 fprintf(stderr, "Unknown error\n");
268 }
269
270 printf("%s\n", result);
271}
272
273static int64_t 240static int64_t
274compose_exec(args_t *args) 241compose_exec(args_t *args)
275{ 242{
@@ -277,7 +244,8 @@ compose_exec(args_t *args)
277 int64_t ret; 244 int64_t ret;
278 245
279 ret = nissy_compose(args->cube, args->cube_perm, result); 246 ret = nissy_compose(args->cube, args->cube_perm, result);
280 print_cube_result(ret, result); 247 if (ret == 0)
248 printf("%s\n", result);
281 249
282 return ret; 250 return ret;
283} 251}
@@ -289,7 +257,8 @@ inverse_exec(args_t *args)
289 int64_t ret; 257 int64_t ret;
290 258
291 ret = nissy_inverse(args->cube, result); 259 ret = nissy_inverse(args->cube, result);
292 print_cube_result(ret, result); 260 if (ret == 0)
261 printf("%s\n", result);
293 262
294 return ret; 263 return ret;
295} 264}
@@ -301,7 +270,8 @@ applymoves_exec(args_t *args)
301 int64_t ret; 270 int64_t ret;
302 271
303 ret = nissy_applymoves(args->cube, args->str_moves, result); 272 ret = nissy_applymoves(args->cube, args->str_moves, result);
304 print_cube_result(ret, result); 273 if (ret == 0)
274 printf("%s\n", result);
305 275
306 return ret; 276 return ret;
307} 277}
@@ -313,7 +283,8 @@ applytrans_exec(args_t *args)
313 int64_t ret; 283 int64_t ret;
314 284
315 ret = nissy_applytrans(args->cube, args->str_trans, result); 285 ret = nissy_applytrans(args->cube, args->str_trans, result);
316 print_cube_result(ret, result); 286 if (ret == 0)
287 printf("%s\n", result);
317 288
318 return ret; 289 return ret;
319} 290}
@@ -325,7 +296,8 @@ frommoves_exec(args_t *args)
325 int64_t ret; 296 int64_t ret;
326 297
327 ret = nissy_frommoves(args->str_moves, result); 298 ret = nissy_frommoves(args->str_moves, result);
328 print_cube_result(ret, result); 299 if (ret == 0)
300 printf("%s\n", result);
329 301
330 return ret; 302 return ret;
331} 303}
@@ -338,7 +310,8 @@ convert_exec(args_t *args)
338 310
339 ret = nissy_convert( 311 ret = nissy_convert(
340 args->str_format_in, args->str_format_out, args->str_cube, result); 312 args->str_format_in, args->str_format_out, args->str_cube, result);
341 print_str_result(ret, result); 313 if (ret == 0)
314 printf("%s\n", result);
342 315
343 return ret; 316 return ret;
344} 317}
@@ -354,7 +327,8 @@ randomcube_exec(args_t *args)
354 cp = rand64(); 327 cp = rand64();
355 co = rand64(); 328 co = rand64();
356 ret = nissy_getcube(ep, eo, cp, co, "fix", result); 329 ret = nissy_getcube(ep, eo, cp, co, "fix", result);
357 print_str_result(ret, result); 330 if (ret == 0)
331 printf("%s\n", result);
358 332
359 return ret; 333 return ret;
360} 334}
@@ -526,7 +500,7 @@ help_exec(args_t *args)
526 printf("Available commands and usage:\n\n"); 500 printf("Available commands and usage:\n\n");
527 for (i = 0; commands[i].name != NULL; i++) 501 for (i = 0; commands[i].name != NULL; i++)
528 printf("%-15s%s\n", commands[i].name, commands[i].syn); 502 printf("%-15s%s\n", commands[i].name, commands[i].syn);
529 printf("\nUse 'help COMMAND' for more information.\n"); 503 printf("\nUse 'help -command COMMAND' for more information.\n");
530 } else { 504 } else {
531 for (i = 0; commands[i].name != NULL; i++) 505 for (i = 0; commands[i].name != NULL; i++)
532 if (!strcmp(args->str_command, commands[i].name)) 506 if (!strcmp(args->str_command, commands[i].name))

Generated with cgit - Back to sebastiano.tronto.net