-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
106 lines (96 loc) · 2.8 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "queue.h"
#include "dll.h"
#include "music_player.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
playlist_t* create_buggy_playlist(int n, int s)
{
playlist_t* pl = create_playlist();
node_t* start = NULL;
for (int i = 0; i < n; i++)
{
add_song(pl, i, -1);
if(i == s){
start = pl->list->head;
}
}
pl->list->tail->next = start;
return pl;
}
int main(){
int lines;
FILE *fptr;
if ((fptr = fopen("input.txt","r")) == NULL){
printf("Error! opening file");
exit(1);
}
fscanf(fptr,"%d", &lines);
char operation[20];
char ops[2];
playlist_t* p;
music_queue_t* mq;
int id, where, song_id, k, s, n;
song_t* song;
for(int i = 0; i < lines; i++){
fscanf(fptr,"%s", operation);
if(strcmp(operation, "create_playlist") == 0){
p = create_playlist();
}
else if(strcmp(operation, "delete_playlist") == 0){
delete_playlist(p);
}
else if(strcmp(operation, "create_music_queue") == 0){
mq = create_music_queue();
}
else if(strcmp(operation, "clear_music_queue") == 0){
clear_music_queue(mq);
}
else if(strcmp(operation, "add_song") == 0){
fscanf(fptr,"%d %d", &id, &where);
add_song(p, id, where);
}
else if(strcmp(operation, "delete_song") == 0){
fscanf(fptr,"%d", &id);
delete_song(p, id);
}
else if(strcmp(operation, "search_and_play") == 0){
fscanf(fptr,"%d", &song_id);
search_and_play(p, song_id);
}
else if(strcmp(operation, "play_next") == 0){
play_next(p, mq);
}
else if(strcmp(operation, "play_previous") == 0){
play_previous(p);
}
else if(strcmp(operation, "insert_to_queue") == 0){
fscanf(fptr,"%d", &id);
insert_to_queue(mq, id);
}
else if(strcmp(operation, "shuffle") == 0){
fscanf(fptr,"%d", &k);
shuffle(p, k);
}
else if(strcmp(operation, "debug") == 0){
fscanf(fptr, "%d %d", &n, &s);
playlist_t* bp = create_buggy_playlist(n, s);
song = debug(bp);
if(song != NULL){
printf("Found cycle at: %d\n", song->data);
}
else{
printf("No loop!\n");
}
}
else if(strcmp(operation, "display_playlist") == 0){
display_playlist(p);
}
else{
printf("Invalid Input Format!\n");
exit(0);
}
}
fclose(fptr);
return 0;
}