int ini_parser(const char* file, int line, const char* section, char *key, char* value, void* data) { if ( section != NULL && key != NULL && value != NULL ) printf( "Section %s -> key %s:value %s\n", section, key, value); else return 0; if(IS_VAL("Router","id")){ inet_pton(AF_INET, value, &device_id); device_id = ntohl(device_id); return 0; } if(IS_VAL("Router","ip")) { strcpy(routerip, value); return 0; } if (IS_VAL("PMA","ip")){ strcpy(pmaip, value); return 0; } if (IS_VAL("PMA","port")){ pmaport = atoi(value); return 0; } return 0; }
/* *** equality *** */ bool val_equal(value_t a, value_t b) { if (val_eq(a, b)) { return true; } if (IS_VAL(a) || IS_VAL(b)) { // if both are only plain values, // they should have been equal by <eq?> return false; } ptrvalue_t *pa = AS_PTR(a); ptrvalue_t *pb = AS_PTR(b); if (pa->type != pb->type) { return false; } if (pa->type == T_CONS) { cons_t *consa = (cons_t *) pa; cons_t *consb = (cons_t *) pb; return val_equal(consa->car, consb->car) && val_equal(consa->cdr, consb->cdr); } else if (pa->type == T_STRING) { string_t *stra = (string_t *) pa; string_t *strb = (string_t *) pb; return stra->len == strb->len && stra->hash == strb->hash && memcmp(stra->value, strb->value, stra->len * sizeof(char)) == 0; } else if (pa->type == T_SYMBOL) { symbol_t *syma = (symbol_t *) pa; symbol_t *symb = (symbol_t *) pb; if ((syma->len == symb->len) && (memcmp(syma->name, symb->name, syma->len * sizeof(char)) == 0)) { // we should never get here! - two symbols with same name are eq? fprintf(stderr, "Error: symbol not interned!"); } return false; } else if (pa->type == T_VECTOR) { vector_t *veca = (vector_t *) pa; vector_t *vecb = (vector_t *) pb; if (veca->count != vecb->count) { return false; } for (uint32_t i = 0; i < veca->count; i++) { if (!val_equal(veca->data[i], vecb->data[i])) { return false; } } return true; } return false; }