void xmlatoi(int* dest, ezxml_t xml, ...) { va_list ap; ezxml_t r; va_start(ap, xml); r = ezxml_vget(xml, ap); va_end(ap); if (r) { *dest = atoi(r->txt); } }
void xmlstrncpy(char* dest, int len, ezxml_t xml, ...) { va_list ap; ezxml_t r; va_start(ap, xml); r = ezxml_vget(xml, ap); va_end(ap); if (r) { strncpy(dest, r->txt, len); dest[len-1] = 0; } }
void xmlatof(float* dest, ezxml_t xml, ...) { va_list ap; ezxml_t r; va_start(ap, xml); r = ezxml_vget(xml, ap); va_end(ap); if (r) { /* some locales use "wrong" decimal sign, and atof() follows locale strictly. so we change to a known locale temporarily. */ char* prevlocale = setlocale(LC_NUMERIC, "C"); *dest = (float)atof(r->txt); setlocale(LC_NUMERIC, prevlocale); } }
void xml_parse_version(struct playlist* pl, ezxml_t xml, ...) { va_list ap; ezxml_t r; va_start(ap, xml); r = ezxml_vget(xml, ap); va_end(ap); if (r) { char ver[64]; strncpy(ver, r->txt, sizeof ver); ver[sizeof ver-1] = 0; int collab; if (sscanf(ver, "%u,%u,%u,%u", &pl->revision, &pl->num_tracks, &pl->checksum, &collab) != 4) { DSFYDEBUG("!!! List version parsing failed (%s)\n", ver); } pl->is_collaborative = collab; } }
void xml_parse_version(struct playlist* pl, ezxml_t xml, ...) { va_list ap; ezxml_t r; va_start(ap, xml); r = ezxml_vget(xml, ap); va_end(ap); if (r) { char ver[64]; strncpy(ver, r->txt, sizeof ver); ver[sizeof ver-1] = 0; int revision, num_tracks, checksum, collab; char *p = &ver; if((revision = atoi(p)) < 0) p = NULL; else p = strchr(p, ','); if(p) p++; if(!p || (num_tracks = atoi(p)) < 0) p = NULL; else p = strchr(p, ','); if(p) p++; if(!p || (checksum = atoi(p)) < 0) p = NULL; else p = strchr(p, ','); if(p) p++; if(!p || (collab = atoi(p)) < 0) p = NULL; if(p) p++; if (!p) { DSFYDEBUG("!!! List version parsing failed (%s)\n", ver); } else { pl->revision = revision; pl->num_tracks = num_tracks; pl->checksum = checksum; pl->is_collaborative = collab; } } }