nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

main.c (1015B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include "../src/nissy.h"
      5 
      6 #define MAX_SOLS 999
      7 
      8 static char buf[TABLESFILESIZE];
      9 
     10 int
     11 main(int argc, char *argv[])
     12 {
     13 	char sols[99999];
     14 	FILE *file;
     15 	long size;
     16 
     17 	if ((file = fopen("tables", "rb")) == NULL)
     18 		return -2;
     19 
     20 	fseek(file, 0, SEEK_END);
     21 	size = ftell(file);
     22 	rewind(file);
     23 	fread(buf, 1, size, file);
     24 
     25 	nissy_init(buf);
     26 
     27 	if (argc != 6) {
     28 		fprintf(stderr, "Not enough arguments given\n");
     29 		return -1;
     30 	}
     31 
     32 	char *step = argv[1];
     33 	char *trans = argv[2];
     34 	int d = strtol(argv[3], NULL, 10);
     35 	char *type = argv[4];
     36 	char *scramble = argv[5];
     37 
     38 	switch (nissy_solve(step, trans, d, type, scramble, sols)) {
     39 	case 1:
     40 		fprintf(stderr, "Error parsing step: %s\n", step);
     41 		return -1;
     42 	case 2:
     43 		fprintf(stderr, "Error parsing trans: %s\n", trans);
     44 		return -1;
     45 	case 4:
     46 		fprintf(stderr, "Error parsing type: %s\n", type);
     47 		return -1;
     48 	case 5:
     49 		fprintf(stderr, "Error applying scramble: %s\n", scramble);
     50 		return -1;
     51 	default:
     52 		printf("%s", sols);
     53 	}
     54 
     55 	return 0;
     56 }