Buff* parser_get_buff(ParserElement* element) { Buff* buff; List* l; if (element->type != PARSER_LIST) { fprintf(stderr, "<%s:%i> Buff is not a list.\n", element->filename, element->lineno); return NULL; } buff = malloc(sizeof(Buff)); memset(buff, 0, sizeof(Buff)); for (l = element->value; l; l = l->next) { element = l->data; if (!strcmp(element->name, "name")) buff->name = parser_get_string(element, NULL); else if (!strcmp(element->name, "attack")) buff->attack = parser_get_integer(element, NULL); else if (!strcmp(element->name, "defense")) buff->defense = parser_get_integer(element, NULL); else fprintf(stderr, "<%s:%i> Unknown property ignored: %s.\n", element->filename, element->lineno, element->name); } return buff; }
void unit_test(char *data, char *mask) { t_command *command; if (!data || !mask) printf("un pointeur d entree au moins est a nul\n"); else printf("checking : data = \"%s\"\nwith : mask = \"%s\"\n", data, mask); if ((command = parser_parse(data, mask))) { int i = 0; while (i < list_size(&command->arguments)) { printf("string %d {value = \"%s\"}\n", i, parser_get_string(command, i)); printf("int %d {value = \"%d\"}\n", i, parser_get_int(command, i)); i++; } parser_command_destroy(command); } else printf("dismatch\n"); }
/* ==================================================================== Return the domain out of the given parse-tree. If not contained, construct the domain from the file name. Will be allocated on the heap. ==================================================================== */ char *determine_domain(struct PData *tree, const char *filename) { char *domain; char *pos; if ( parser_get_string(tree, "domain", &domain) ) return domain; domain = strdup(get_basename(filename)); pos = strchr(domain, '.'); if (pos) *pos = 0; return domain; }