nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

utils.h (1667B)


      1 STATIC coord_t *parse_coord(size_t, const char *);
      2 STATIC multicoord_t *parse_multicoord(size_t, const char *);
      3 STATIC void parse_coord_and_trans(
      4     const char *, coord_t **, multicoord_t **, uint8_t *);
      5 STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]);
      6 
      7 STATIC coord_t *
      8 parse_coord(size_t n, const char *coord)
      9 {
     10 	int i;
     11 	const char *name;
     12 
     13 	for (i = 0; all_coordinates[i] != NULL; i++) {
     14 		name = all_coordinates[i]->name;
     15 		if (n == strlen(name) && !strncmp(name, coord, n))
     16 			return all_coordinates[i];
     17 	}
     18 
     19 	return NULL;
     20 }
     21 
     22 STATIC multicoord_t *
     23 parse_multicoord(size_t n, const char *coord)
     24 {
     25 	int i;
     26 	const char *name;
     27 
     28 	for (i = 0; all_multicoordinates[i] != NULL; i++) {
     29 		name = all_multicoordinates[i]->name;
     30 		if (n == strlen(name) && !strncmp(name, coord, n))
     31 			return all_multicoordinates[i];
     32 	}
     33 
     34 	return NULL;
     35 }
     36 
     37 STATIC void
     38 parse_coord_and_trans(
     39 	const char *str,
     40 	coord_t **coord,
     41 	multicoord_t **mcoord,
     42 	uint8_t *trans
     43 )
     44 {
     45 	size_t i;
     46 
     47 	for (i = 7; i < strlen(str); i++)
     48 		if (str[i] == '_')
     49 			break;
     50 
     51 	if (coord != NULL)
     52 		*coord = parse_coord(i-6, str+6);
     53 
     54 	if (mcoord != NULL)
     55 		*mcoord = parse_multicoord(i-7, str+7);
     56 
     57 	if (trans != NULL)
     58 		*trans = i == strlen(str) ?
     59 		    UINT8_ERROR : readrotation(str+i+1);
     60 }
     61 
     62 STATIC long long
     63 dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID])
     64 {
     65 	coord_t *c;
     66 	multicoord_t *mc;
     67 
     68 	parse_coord_and_trans(ca, &c, &mc, NULL);
     69 
     70 	if (c != NULL) {
     71 		strcpy(dataid, c->name);
     72 		return NISSY_OK;
     73 	}
     74 
     75 	if (mc != NULL) {
     76 		strcpy(dataid, mc->name);
     77 		return NISSY_OK;
     78 	}
     79 
     80 	LOG("Error: cannot parse coordinate from '%s'\n", ca);
     81 	return NISSY_ERROR_INVALID_SOLVER;
     82 }