#include #include "xml.h" /* parse a string into a document */ struct kai_tag_t * kai_parse_string(const char *str) { yyscan_t scanner; struct kai_tag_t *document; kalmialex_init(&scanner); YY_BUFFER_STATE buf = kalmia_scan_string(str, scanner); int result = kalmiaparse(scanner, &document); kalmia_delete_buffer(buf, scanner); kalmialex_destroy(scanner); if (result != 0) { return NULL; } return document; } char * kai_tag_get_attr(struct kai_tag_t *t, const char *attr) { struct kai_attr_t *a = t->attrs; while (a != NULL) { if (strcmp(a->key, attr) == 0) { return a->value; } a = a->next; } return NULL; } long kai_tag_attr_to_long( struct kai_tag_t *t, const char *attr, long base, int *flag) { char *val = kai_tag_get_attr(t, attr); if (val == NULL) { /* attribute not present, fall back to base */ if (flag != NULL) *flag = 1; return base; } if (flag != NULL) *flag = 0; return strtol(val, NULL, 10); }