From 2fd3a9d009d19e48eefda098cbedcf1aa02b660d Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Thu, 16 Sep 2021 23:39:39 +0100 Subject: Updated Code Path --- include/utils.h | 1 - include/video.h | 1 + queryt.c | 2 +- src/utils.c | 48 ------------------------------------------------ src/video.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/include/utils.h b/include/utils.h index 89326d9..48ada10 100644 --- a/include/utils.h +++ b/include/utils.h @@ -7,4 +7,3 @@ void freeTokens (char **tokens, int size); char *queryNormalizer (char *query); char *extractQueryJSON (char *youtubeurl); int checkNumber (char *num); -void printVideoInfo (char *format, Video *videos, int numberOfVideos); diff --git a/include/video.h b/include/video.h index 5156600..71cf047 100644 --- a/include/video.h +++ b/include/video.h @@ -6,4 +6,5 @@ typedef struct video } Video; Video createVideo (char *title, char *author, char *id, char *duration); +void printVideo (char *format, Video *videos, int numberOfVideos); void freeVideo (Video *v); diff --git a/queryt.c b/queryt.c index 35c1874..17f6cfa 100644 --- a/queryt.c +++ b/queryt.c @@ -104,7 +104,7 @@ processOptions (int *options, char **args, int argc) ? checkNumber (args[1]) : videoCount; char *format = (options[0]) ? args[0] : ""; - printVideoInfo (format, videos, printedVideos); + printVideo (format, videos, printedVideos); for (int i = 0; i < videoCount; i++) { diff --git a/src/utils.c b/src/utils.c index d625fed..5391e6d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -207,51 +207,3 @@ checkNumber (char *num) return number; } - -void -printVideoInfo (char *format, Video *videos, int numberOfVideos) -{ - if (format != NULL && strlen (format) > 0) - { - for (int i = 0; i < numberOfVideos; i++) - { - for (int j = 0; j < strlen (format); j++) - { - switch (format[j]) - { - case 'a': - printf ("%s", videos[i].author); - break; - case 'd': - printf ("%s", videos[i].duration); - break; - case 'i': - printf ("%s", videos[i].id); - break; - case 't': - printf ("%s", videos[i].title); - break; - case 'R': - printf ("\n"); - break; - case 'T': - printf ("\t"); - break; - default: - if (!isalpha (format[j])) - { - printf ("%c", format[j]); - } - } - } - printf ("\n"); - } - } - else - { - for (int i = 0; i < numberOfVideos; i++) - { - printf ("%s\t%s\n", videos[i].id, videos[i].title); - } - } -} diff --git a/src/video.c b/src/video.c index 0e09437..e48245b 100644 --- a/src/video.c +++ b/src/video.c @@ -1,4 +1,5 @@ #include "../include/video.h" +#include #include #include #include @@ -35,6 +36,54 @@ createVideo (char *title, char *author, char *id, char *duration) return video; } +void +printVideo (char *format, Video *videos, int numberOfVideos) +{ + if (format != NULL && strlen (format) > 0) + { + for (int i = 0; i < numberOfVideos; i++) + { + for (int j = 0; j < strlen (format); j++) + { + switch (format[j]) + { + case 'a': + printf ("%s", videos[i].author); + break; + case 'd': + printf ("%s", videos[i].duration); + break; + case 'i': + printf ("%s", videos[i].id); + break; + case 't': + printf ("%s", videos[i].title); + break; + case 'R': + printf ("\n"); + break; + case 'T': + printf ("\t"); + break; + default: + if (!isalpha (format[j])) + { + printf ("%c", format[j]); + } + } + } + printf ("\n"); + } + } + else + { + for (int i = 0; i < numberOfVideos; i++) + { + printf ("%s\t%s\n", videos[i].id, videos[i].title); + } + } +} + void freeVideo (Video *v) { -- cgit v1.2.3