54Fermer56
GodzilLe 12/01/2015 à 17:14
int ret = -ERR_XML_PARSE; const char *oldlocale = setlocale(LC_TIME,NULL); [...] switch (ret) { case 1: data = xmliter_data(1); if (!data || (strlen(data) > 255)) { ret = -ERR_PARSE; goto parse_error; } strcpy(title,data); free(data); break; case 2: data = xmliter_data(1); if (is_atom) { if (!data || (sscanf(data,"%4d-%2d-%2dT%2d:%2d:%2dZ",&y,&m,&d,&hr,&mn,&sc) < 6)) { goto xml_parse_error; } } else { if (!data || (sscanf(data,"%*3c, %d %3c %d %2d:%2d:%2d",&d,datebuffer,&y,&hr,&mn,&sc) < 6)) { goto xml_parse_error; } if (!strncmp(datebuffer,"Jan",3)) { m=1; } else if (!strncmp(datebuffer,"Feb",3)) { m=2; } else if (!strncmp(datebuffer,"Mar",3)) { m=3; } else if (!strncmp(datebuffer,"Apr",3)) { m=4; } else if (!strncmp(datebuffer,"May",3)) { m=5; } else if (!strncmp(datebuffer,"Jun",3)) { m=6; } else if (!strncmp(datebuffer,"Jul",3)) { m=7; } else if (!strncmp(datebuffer,"Aug",3)) { m=8; } else if (!strncmp(datebuffer,"Sep",3)) { m=9; } else if (!strncmp(datebuffer,"Oct",3)) { m=10; } else if (!strncmp(datebuffer,"Nov",3)) { m=11; } else if (!strncmp(datebuffer,"Dec",3)) { m=12; } else { goto xml_parse_error; } } tm.tm_year = y-1900; tm.tm_mon = m-1; tm.tm_mday = d; tm.tm_hour = hr; tm.tm_min = mn; tm.tm_sec = sc; setlocale(LC_TIME,"C"); strftime(datebuffer, 99, "%B %d, %Y %H:%M:%S", &tm); setlocale(LC_TIME,oldlocale); free(data); break; case 3: data = xmliter_data(1); if (!data || strlen(data)>255) { goto xml_parse_error; } strcpy(author,data); free(data); break; case 4: xchat_commandf(ph, "notice %s %s %s", nick, datebuffer, author); xchat_commandf(ph, "notice %s %s", nick, title); nc++; break; } [...] ret = 0; goto exit; xml_parse_error: free(data); xmliter_done(); parse_error: [...] exit: return ret; }

Tellement plus propre...