From 002c67a1eb237141d98ff493d92e9d867123bffb Mon Sep 17 00:00:00 2001 From: kdx Date: Fri, 13 Jan 2023 04:17:50 +0100 Subject: generate good html --- cite.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/cite.c b/cite.c index 12545c5..6c9852b 100644 --- a/cite.c +++ b/cite.c @@ -15,6 +15,7 @@ typedef struct { char nationality[256]; char pitch[2048]; char poster[256]; + char week_times[4096]; char times[4096]; } Movie; @@ -23,8 +24,12 @@ CURL *curl = NULL; static void print_style(void) { + puts(""); + puts(""); + puts(""); puts(""); puts(""); + puts(""); } static void print_times(Movie *movie) @@ -129,11 +134,13 @@ static int set_movie_base_fields(Movie *movie, const xmlNode *node) const xmlChar *nationality = xmlGetProp(node, "nationalite"); const xmlChar *pitch = xmlGetProp(node, "synopsis"); const xmlChar *poster = xmlGetProp(node, "affichette"); + const xmlChar *week_times = xmlNodeGetContent(times_node); const xmlChar *times = xmlNodeGetContent(times_node->next); if (title == NULL || og_title == NULL || directors == NULL || actors == NULL || prod_year == NULL || release_date == NULL || duration == NULL || main_genres == NULL || nationality == NULL || - pitch == NULL || poster == NULL || times == NULL) { + pitch == NULL || poster == NULL || week_times == NULL || + times == NULL) { err = 1; goto set_fields_panic; } @@ -148,7 +155,10 @@ static int set_movie_base_fields(Movie *movie, const xmlNode *node) strncpy(movie->nationality, nationality, sizeof(movie->nationality) - 1); strncpy(movie->pitch, pitch, sizeof(movie->pitch) - 1); strncpy(movie->poster, poster, sizeof(movie->poster) - 1); - strncpy(movie->times, times, sizeof(movie->times) - 1); + strncpy(movie->week_times, week_times, sizeof(movie->week_times) - 1); + strcpy(movie->times, ""); + strncat(movie->times, times, sizeof(movie->times) - 1); + strncat(movie->times, "", sizeof(movie->times) - 1); set_fields_panic: xfree(title); xfree(og_title); @@ -161,6 +171,8 @@ set_fields_panic: xfree(nationality); xfree(pitch); xfree(poster); + xfree(week_times); + xfree(times); return err; } @@ -169,11 +181,18 @@ static int append_movie_times(Movie *movie, const xmlNode *node) const xmlNode *times_node = node->children; if (times_node == NULL || times_node->next == NULL) return 1; + const xmlChar *week_times = xmlNodeGetContent(times_node); const xmlChar *times = xmlNodeGetContent(times_node->next); - if (times == NULL) + if (week_times == NULL || times == NULL) { + xfree(week_times); + xfree(times); return 1; + } + strncat(movie->week_times, "\n", sizeof(movie->week_times) - 1); + strncat(movie->week_times, week_times, sizeof(movie->week_times) - 1); strncat(movie->times, ";", sizeof(movie->times) - 1); strncat(movie->times, times, sizeof(movie->times) - 1); + xfree(week_times); xfree(times); return 0; } @@ -213,11 +232,14 @@ int main(int argc, char **argv) } } print_style(); - printf("

cinéma de la cité

\n"); + puts(""); + puts("

cinéma de la cité

"); for (Movie *movie = movies; movie->id != 0; movie++) { download_poster(movie); print_movie(movie, atoi(argv[2])); } + puts(""); + puts(""); curl_easy_cleanup(curl); xmlFreeDoc(document); xmlCleanupParser(); -- cgit v1.2.3