aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nissy.c78
1 files changed, 36 insertions, 42 deletions
diff --git a/src/nissy.c b/src/nissy.c
index f22f606..f744fa8 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -60,7 +60,7 @@ parse_h48_solver(const char *buf, uint8_t h[static 1], uint8_t k[static 1])
60parse_h48_solver_error: 60parse_h48_solver_error:
61 *h = 0; 61 *h = 0;
62 *k = 0; 62 *k = 0;
63 LOG("Error parsing solver: must be in \"h48h*k*\" format," 63 LOG("Error parsing H48 solver: must be in \"h48h*k*\" format,"
64 " but got %s\n", fullbuf); 64 " but got %s\n", fullbuf);
65 return NISSY_ERROR_INVALID_SOLVER; 65 return NISSY_ERROR_INVALID_SOLVER;
66} 66}
@@ -72,7 +72,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1])
72 72
73 if (my_strnlen(info->solver, INFO_SOLVER_STRLEN) 73 if (my_strnlen(info->solver, INFO_SOLVER_STRLEN)
74 == INFO_SOLVER_STRLEN) { 74 == INFO_SOLVER_STRLEN) {
75 LOG("checkdata: error reading table info\n"); 75 LOG("[checkdata] Error reading table info\n");
76 return false; 76 return false;
77 } else if (!strncmp(info->solver, "cocsep", 6)) { 77 } else if (!strncmp(info->solver, "cocsep", 6)) {
78 getdistribution_cocsep( 78 getdistribution_cocsep(
@@ -88,7 +88,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1])
88 } else if (!strncmp(info->solver, "coord helper table for ", 23)) { 88 } else if (!strncmp(info->solver, "coord helper table for ", 23)) {
89 return true; 89 return true;
90 } else { 90 } else {
91 LOG("checkdata: unknown solver %s\n", info->solver); 91 LOG("[checkdata] unknown solver %s\n", info->solver);
92 return false; 92 return false;
93 } 93 }
94 94
@@ -154,7 +154,7 @@ nissy_compose(
154 c = readcube("B32", cube); 154 c = readcube("B32", cube);
155 155
156 if (!isconsistent(c)) { 156 if (!isconsistent(c)) {
157 LOG("Error in nissy_compose: given cube is invalid\n"); 157 LOG("[compose] Error: the given cube is invalid\n");
158 err = NISSY_ERROR_INVALID_CUBE; 158 err = NISSY_ERROR_INVALID_CUBE;
159 goto nissy_compose_error; 159 goto nissy_compose_error;
160 } 160 }
@@ -162,7 +162,7 @@ nissy_compose(
162 p = readcube("B32", permutation); 162 p = readcube("B32", permutation);
163 163
164 if (!isconsistent(p)) { 164 if (!isconsistent(p)) {
165 LOG("Error in nissy_compose: given permutation is invalid\n"); 165 LOG("[compose] Error: given permutation is invalid\n");
166 err = NISSY_ERROR_INVALID_CUBE; 166 err = NISSY_ERROR_INVALID_CUBE;
167 goto nissy_compose_error; 167 goto nissy_compose_error;
168 } 168 }
@@ -170,7 +170,7 @@ nissy_compose(
170 res = compose(c, p); 170 res = compose(c, p);
171 171
172 if (!isconsistent(res)) { 172 if (!isconsistent(res)) {
173 LOG("Unknown error: resulting cube is invalid\n"); 173 LOG("[compose] Unknown error: resulting cube is invalid\n");
174 err = NISSY_ERROR_UNKNOWN; 174 err = NISSY_ERROR_UNKNOWN;
175 goto nissy_compose_error; 175 goto nissy_compose_error;
176 } 176 }
@@ -194,7 +194,7 @@ nissy_inverse(
194 c = readcube("B32", cube); 194 c = readcube("B32", cube);
195 195
196 if (iserror(c)) { 196 if (iserror(c)) {
197 LOG("Error in nissy_inverse: given cube is invalid\n"); 197 LOG("[inverse] Error: the given cube is invalid\n");
198 err = NISSY_ERROR_INVALID_CUBE; 198 err = NISSY_ERROR_INVALID_CUBE;
199 goto nissy_inverse_error; 199 goto nissy_inverse_error;
200 } 200 }
@@ -202,7 +202,7 @@ nissy_inverse(
202 res = inverse(c); 202 res = inverse(c);
203 203
204 if (!isconsistent(res)) { 204 if (!isconsistent(res)) {
205 LOG("Unknown error: inverted cube is invalid\n"); 205 LOG("[inverse] Unknown error: inverted cube is invalid\n");
206 err = NISSY_ERROR_UNKNOWN; 206 err = NISSY_ERROR_UNKNOWN;
207 goto nissy_inverse_error; 207 goto nissy_inverse_error;
208 } 208 }
@@ -225,7 +225,7 @@ nissy_applymoves(
225 long long err; 225 long long err;
226 226
227 if (moves == NULL) { 227 if (moves == NULL) {
228 LOG("Error: 'moves' argument is NULL\n"); 228 LOG("[applymoves] Error: 'moves' argument is NULL\n");
229 err = NISSY_ERROR_NULL_POINTER; 229 err = NISSY_ERROR_NULL_POINTER;
230 goto nissy_applymoves_error; 230 goto nissy_applymoves_error;
231 } 231 }
@@ -233,7 +233,7 @@ nissy_applymoves(
233 c = readcube("B32", cube); 233 c = readcube("B32", cube);
234 234
235 if (!isconsistent(c)) { 235 if (!isconsistent(c)) {
236 LOG("Error in nissy_applymoves: given cube is invalid\n"); 236 LOG("[applymoves] Error: given cube is invalid\n");
237 err = NISSY_ERROR_INVALID_CUBE; 237 err = NISSY_ERROR_INVALID_CUBE;
238 goto nissy_applymoves_error; 238 goto nissy_applymoves_error;
239 } 239 }
@@ -266,7 +266,7 @@ nissy_applytrans(
266 c = readcube("B32", cube); 266 c = readcube("B32", cube);
267 267
268 if (!isconsistent(c)) { 268 if (!isconsistent(c)) {
269 LOG("Error in nissy_applytrans: given cube is invalid\n"); 269 LOG("[applytrans] Error: given cube is invalid\n");
270 err = NISSY_ERROR_INVALID_CUBE; 270 err = NISSY_ERROR_INVALID_CUBE;
271 goto nissy_applytrans_error; 271 goto nissy_applytrans_error;
272 } 272 }
@@ -299,19 +299,19 @@ nissy_convert(
299 long long err; 299 long long err;
300 300
301 if (format_in == NULL) { 301 if (format_in == NULL) {
302 LOG("Error: 'format_in' argument is NULL\n"); 302 LOG("[convert] Error: 'format_in' argument is NULL\n");
303 err = NISSY_ERROR_NULL_POINTER; 303 err = NISSY_ERROR_NULL_POINTER;
304 goto nissy_convert_error; 304 goto nissy_convert_error;
305 } 305 }
306 306
307 if (format_out == NULL) { 307 if (format_out == NULL) {
308 LOG("Error: 'format_out' argument is NULL\n"); 308 LOG("[convert] Error: 'format_out' argument is NULL\n");
309 err = NISSY_ERROR_NULL_POINTER; 309 err = NISSY_ERROR_NULL_POINTER;
310 goto nissy_convert_error; 310 goto nissy_convert_error;
311 } 311 }
312 312
313 if (cube_string == NULL) { 313 if (cube_string == NULL) {
314 LOG("Error: 'cube_string' argument is NULL\n"); 314 LOG("[convert] Error: 'cube_string' argument is NULL\n");
315 err = NISSY_ERROR_NULL_POINTER; 315 err = NISSY_ERROR_NULL_POINTER;
316 goto nissy_convert_error; 316 goto nissy_convert_error;
317 } 317 }
@@ -344,7 +344,7 @@ nissy_getcube(
344 cube_t c; 344 cube_t c;
345 345
346 if (options == NULL) { 346 if (options == NULL) {
347 LOG("Error: 'options' argument is NULL\n"); 347 LOG("[getcube] Error: 'options' argument is NULL\n");
348 return NISSY_ERROR_NULL_POINTER; 348 return NISSY_ERROR_NULL_POINTER;
349 } 349 }
350 350
@@ -355,8 +355,8 @@ nissy_getcube(
355 c = getcube(ep, eo, cp, co); 355 c = getcube(ep, eo, cp, co);
356 356
357 if (!isconsistent(c)) { 357 if (!isconsistent(c)) {
358 LOG("Error: could not get cube with ep=%lld, eo=%lld, " 358 LOG("[getcube] Error: could not get cube with ep=%lld, "
359 "cp=%lld, co=%lld.\n", ep, eo, cp, co); 359 "eo=%lld, cp=%lld, co=%lld.\n", ep, eo, cp, co);
360 return NISSY_ERROR_OPTIONS; 360 return NISSY_ERROR_OPTIONS;
361 } 361 }
362 362
@@ -374,7 +374,7 @@ nissy_datainfo(
374 long long ret; 374 long long ret;
375 375
376 if ((size_t)data % 8 != 0) { 376 if ((size_t)data % 8 != 0) {
377 LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); 377 LOG("[datainfo] Error: buffer is not 8-byte aligned\n");
378 return NISSY_ERROR_DATA; 378 return NISSY_ERROR_DATA;
379 } 379 }
380 380
@@ -429,7 +429,7 @@ nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID])
429 } else if (!strncmp(solver, "coord_", 6)) { 429 } else if (!strncmp(solver, "coord_", 6)) {
430 return dataid_coord(solver+6, dataid); 430 return dataid_coord(solver+6, dataid);
431 } else { 431 } else {
432 LOG("gendata: unknown solver %s\n", solver); 432 LOG("[gendata] Unknown solver %s\n", solver);
433 return NISSY_ERROR_INVALID_SOLVER; 433 return NISSY_ERROR_INVALID_SOLVER;
434 } 434 }
435} 435}
@@ -469,12 +469,12 @@ nissy_gendata_unsafe(
469 gendata_h48_arg_t arg; 469 gendata_h48_arg_t arg;
470 470
471 if (solver == NULL) { 471 if (solver == NULL) {
472 LOG("Error: 'solver' argument is NULL\n"); 472 LOG("[gendata] Error: 'solver' argument is NULL\n");
473 return NISSY_ERROR_NULL_POINTER; 473 return NISSY_ERROR_NULL_POINTER;
474 } 474 }
475 475
476 if ((size_t)data % 8 != 0) { 476 if ((size_t)data % 8 != 0) {
477 LOG("nissy_gendata: buffere is not 8-byte aligned\n"); 477 LOG("[gendata] Error: buffer is not 8-byte aligned\n");
478 return NISSY_ERROR_DATA; 478 return NISSY_ERROR_DATA;
479 } 479 }
480 480
@@ -489,7 +489,7 @@ nissy_gendata_unsafe(
489 } else if (!strncmp(solver, "coord_", 6)) { 489 } else if (!strncmp(solver, "coord_", 6)) {
490 return gendata_coord_dispatch(solver+6, data); 490 return gendata_coord_dispatch(solver+6, data);
491 } else { 491 } else {
492 LOG("gendata: unknown solver %s\n", solver); 492 LOG("[gendata] Unknown solver %s\n", solver);
493 return NISSY_ERROR_INVALID_SOLVER; 493 return NISSY_ERROR_INVALID_SOLVER;
494 } 494 }
495} 495}
@@ -505,7 +505,7 @@ nissy_checkdata(
505 int64_t err; 505 int64_t err;
506 506
507 if ((size_t)data % 8 != 0) { 507 if ((size_t)data % 8 != 0) {
508 LOG("nissy_checkdata: buffere is not 8-byte aligned\n"); 508 LOG("[checkdata] Error: buffer is not 8-byte aligned\n");
509 return NISSY_ERROR_DATA; 509 return NISSY_ERROR_DATA;
510 } 510 }
511 511
@@ -514,8 +514,8 @@ nissy_checkdata(
514 buf += info.next, data_size -= info.next) 514 buf += info.next, data_size -= info.next)
515 { 515 {
516 if (!checkdata(buf, &info)) { 516 if (!checkdata(buf, &info)) {
517 LOG("Error: data for solver '%s' is corrupted!\n", 517 LOG("[checkdata] Error: data for solver '%s' is "
518 info.solver); 518 "corrupted!\n", info.solver);
519 return NISSY_ERROR_DATA; 519 return NISSY_ERROR_DATA;
520 } 520 }
521 521
@@ -549,44 +549,38 @@ nissy_solve(
549 int t; 549 int t;
550 550
551 if (solver == NULL) { 551 if (solver == NULL) {
552 LOG("Error: 'solver' argument is NULL\n"); 552 LOG("[solve] Error: 'solver' argument is NULL\n");
553 return NISSY_ERROR_NULL_POINTER; 553 return NISSY_ERROR_NULL_POINTER;
554 } 554 }
555 555
556 c = readcube_B32(cube); 556 c = readcube_B32(cube);
557 557
558 if (!isconsistent(c)) { 558 if (!isconsistent(c)) {
559 LOG("solve: cube is invalid\n"); 559 LOG("[solve] Error: cube is invalid\n");
560 return NISSY_ERROR_INVALID_CUBE; 560 return NISSY_ERROR_INVALID_CUBE;
561 } 561 }
562 562
563 if (!issolvable(c)) { 563 if (!issolvable(c)) {
564/* TODO: this is step-dependent */ 564/* TODO: this is step-dependent */
565 LOG("solve: cube is not solvable\n"); 565 LOG("[solve] Error: cube is not solvable\n");
566 return NISSY_ERROR_UNSOLVABLE_CUBE; 566 return NISSY_ERROR_UNSOLVABLE_CUBE;
567 } 567 }
568 568
569/* TODO: checks for minmoves, maxmoves, nissflag */ 569/* TODO: checks for minmoves, maxmoves, nissflag */
570 570
571 if (maxsols == 0) { 571 if (maxsols == 0) {
572 LOG("solve: 'maxsols' is 0, returning no solution\n"); 572 LOG("[solve] 'maxsols' is 0, returning no solution\n");
573 return 0; 573 return 0;
574 } 574 }
575 575
576 t = threads == 0 ? THREADS : threads; 576 if (threads > THREADS)
577 if (t < 0) { 577 LOG("[solve] Selected number of threads (%u) is above the "
578 LOG("solve: 'threads' is negative. Please provide a " 578 "maximum value (%d), using %d threads instead\n",
579 "number of threads between 1 and %d\n", THREADS); 579 threads, THREADS, THREADS);
580 return NISSY_ERROR_OPTIONS; 580 t = threads == 0 ? THREADS : MIN(THREADS, threads);
581 }
582 if (t > THREADS) {
583 LOG("solve: 'threads' is above the maximum value of %d\n",
584 THREADS);
585 return NISSY_ERROR_OPTIONS;
586 }
587 581
588 if ((size_t)data % 8 != 0) { 582 if ((size_t)data % 8 != 0) {
589 LOG("nissy_solve: buffere is not 8-byte aligned\n"); 583 LOG("[solve] Error: data buffer is not 8-byte aligned\n");
590 return NISSY_ERROR_DATA; 584 return NISSY_ERROR_DATA;
591 } 585 }
592 586
@@ -601,7 +595,7 @@ nissy_solve(
601 minmoves, maxmoves, maxsols, optimal, t, data_size, data, 595 minmoves, maxmoves, maxsols, optimal, t, data_size, data,
602 sols_size, sols); 596 sols_size, sols);
603 } else { 597 } else {
604 LOG("solve: unknown solver '%s'\n", solver); 598 LOG("[solve] Error: unknown solver '%s'\n", solver);
605 return NISSY_ERROR_INVALID_SOLVER; 599 return NISSY_ERROR_INVALID_SOLVER;
606 } 600 }
607} 601}

Generated with cgit - Back to sebastiano.tronto.net