2023-10-12 14:25:48 -07:00
|
|
|
#include "movies.h"
|
|
|
|
|
2023-10-14 16:57:09 -07:00
|
|
|
int haschanged = 0;
|
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
int main(int argc, char** argv) {
|
2023-10-12 14:25:48 -07:00
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
if(argc < 2) {
|
|
|
|
printf("Please Specify Filename\n");
|
|
|
|
return 64;
|
|
|
|
}
|
2023-10-12 14:25:48 -07:00
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
struct node* head = parse_csv(argv[1]);
|
2023-10-12 14:25:48 -07:00
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
enum OPTIONS menu_select = 0;
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
menu_select = menu();
|
|
|
|
|
|
|
|
switch(menu_select) {
|
|
|
|
case YEAR:
|
|
|
|
movie_year(head);
|
|
|
|
break;
|
|
|
|
case RATE:
|
|
|
|
movie_rate(head);
|
|
|
|
break;
|
|
|
|
case LANGUAGE:
|
|
|
|
movie_lang(head);
|
|
|
|
break;
|
|
|
|
case EXIT:
|
|
|
|
printf("Goodbye~\n");
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
printf("You naughty~ Pick a correct option next time.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-10-12 14:25:48 -07:00
|
|
|
print_movies(head);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-10-13 01:39:26 -07:00
|
|
|
|
|
|
|
int menu() {
|
|
|
|
|
|
|
|
printf("1. Show movies released in the specified year\n");
|
|
|
|
printf("2. Show highest rated movie for each year\n");
|
|
|
|
printf("3. Show the title and year of release of all movies in a specific language\n");
|
2023-10-14 16:57:09 -07:00
|
|
|
printf("4. Exit from the program\n");
|
2023-10-13 01:39:26 -07:00
|
|
|
|
2023-10-13 03:29:13 -07:00
|
|
|
int option;
|
|
|
|
do {
|
|
|
|
option = integer_input("Enter a choice from 1 to 4: ");
|
|
|
|
} while(option > 4 || option < 1);
|
2023-10-13 01:39:26 -07:00
|
|
|
|
|
|
|
return option;
|
|
|
|
}
|
|
|
|
|
2023-10-14 16:57:09 -07:00
|
|
|
void year_print(struct csv* data, void* val) {
|
2023-10-13 03:29:13 -07:00
|
|
|
|
|
|
|
if(data->year != *(int*)val)
|
2023-10-14 16:57:09 -07:00
|
|
|
return;
|
2023-10-13 03:29:13 -07:00
|
|
|
|
|
|
|
printf("%s\n", data->title);
|
2023-10-14 16:57:09 -07:00
|
|
|
haschanged = 1;
|
2023-10-13 03:29:13 -07:00
|
|
|
}
|
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
void movie_year(struct node* head) {
|
2023-10-13 03:29:13 -07:00
|
|
|
|
|
|
|
void* f = &year_print;
|
|
|
|
int* val = malloc(sizeof(int));
|
|
|
|
|
|
|
|
*val = integer_input("Enter year to search movies from: ");
|
2023-10-14 16:57:09 -07:00
|
|
|
haschanged = 0;
|
2023-10-13 03:29:13 -07:00
|
|
|
|
|
|
|
iterate_nodes(head, f, val);
|
|
|
|
|
2023-10-14 16:57:09 -07:00
|
|
|
if(!haschanged) {
|
|
|
|
printf("No data about movies released in the year %d", *val);
|
|
|
|
}
|
|
|
|
|
2023-10-13 03:29:13 -07:00
|
|
|
printf("\n\n");
|
2023-10-13 01:39:26 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void movie_rate(struct node* head) {
|
|
|
|
printf("stub\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-14 16:57:09 -07:00
|
|
|
void lang_print(struct csv* data, void* val) {
|
|
|
|
|
|
|
|
for(int i = 0; i < data->numlang; i++) {
|
|
|
|
|
|
|
|
if(!strcmp(val, data->languages[i])) {
|
|
|
|
printf("%d %s\n", data->year, data->title);
|
|
|
|
haschanged = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
void movie_lang(struct node* head) {
|
|
|
|
|
2023-10-14 16:57:09 -07:00
|
|
|
void* f = &lang_print;
|
|
|
|
char val[41];
|
|
|
|
|
|
|
|
printf("Enter Language to search for: ");
|
|
|
|
fflush(stdout);
|
|
|
|
fgets(val, 40, stdin);
|
|
|
|
|
|
|
|
// Replace newline character with the null terminator
|
|
|
|
val[strlen(val)-1] = '\0';
|
|
|
|
|
|
|
|
haschanged = 0;
|
|
|
|
iterate_nodes(head, f, &val);
|
|
|
|
|
|
|
|
if(!haschanged)
|
|
|
|
printf("No data about movies released in %s\n", val);
|
|
|
|
printf("\n");
|
2023-10-13 01:39:26 -07:00
|
|
|
|
|
|
|
}
|