int main(int argc, char *argv[]) { Irc freenode; struct pollfd pfd[4]; int i, ready, murm_listenfd = -1; initialize(argc, argv); for (i = 0; i < SIZE(pfd); i++) { pfd[i].fd = -1; pfd[i].events = POLLIN; } if (add_murmur_callbacks(cfg.murmur_port)) pfd[MURM_LISTEN].fd = murm_listenfd = sock_listen(LOCALHOST, CB_LISTEN_PORT_S); else fprintf(stderr, "Could not connect to Murmur\n"); if ((pfd[MPD].fd = mpdfd = mpd_connect(cfg.mpd_port)) < 0) fprintf(stderr, "Could not connect to MPD\n"); // Connect to server and set IRC details if (!(freenode = irc_connect(cfg.server, cfg.port))) exit_msg("Irc connection failed"); pfd[IRC].fd = get_socket(freenode); set_nick(freenode, cfg.nick); set_user(freenode, cfg.user); for (i = 0; i < cfg.channels_set; i++) join_channel(freenode, cfg.channels[i]); while ((ready = poll(pfd, SIZE(pfd), TIMEOUT)) > 0) { // Keep reading & parsing lines as long the connection is active and act on any registered actions found if (pfd[IRC].revents & POLLIN) while (parse_irc_line(freenode) > 0); if (pfd[MURM_LISTEN].revents & POLLIN) if ((pfd[MURM_ACCEPT].fd = accept_murmur_connection(murm_listenfd)) > 0) pfd[MURM_LISTEN].fd = -1; // Stop listening for connections if (pfd[MURM_ACCEPT].revents & POLLIN) { if (!listen_murmur_callbacks(freenode, pfd[MURM_ACCEPT].fd)) { pfd[MURM_ACCEPT].fd = -1; pfd[MURM_LISTEN].fd = murm_listenfd; // Start listening again for Murmur connections } } if (pfd[MPD].revents & POLLIN) if (!print_song(freenode, default_channel(freenode))) pfd[MPD].fd = mpdfd = mpd_connect(cfg.mpd_port); } // If we reach here, it means we got disconnected from server. Exit with error (1) if (ready == -1) perror("poll"); else fprintf(stderr, "%d minutes passed without getting a message, exiting...\n", TIMEOUT / 1000 / 60); quit_server(freenode, cfg.quit_msg); cleanup(); return 1; }
/* Parameters: library: Pointer to Start of Library Array */ void shuffle(struct song_node* *library) { int i; for (i = 0; i < 25; i++) { if (library[i]) print_song( random_song( library[i] ) ); } }
/* Parameters: library: Pointer to Start of Library Array song_name: Artist of song */ void search_song_artist(struct song_node* *library, char *song_artist) { if (find_song_by_artist( library[ letter_to_index(song_artist) ], song_artist ) ) { printf("First Song Fond: "); print_song( find_song_by_artist( library[ letter_to_index(song_artist) ], song_artist) ); } else printf ("Artist Not Found\n"); }
song* find_song(song* list, char* n) { while (list) { if (strcmp(list->name, n) == 0) { print_song(list); return list; } list = list->next; } printf("Song does not exist\n"); return list; }
song* find_artist(song* list, char* a) { while (list) { if (strcmp(list->artist,a) == 0) { while (strcmp(list->artist,a) == 0) { print_song(list); list = list->next; } return list; } list = list->next; } printf("Artist does not exist"); return list; }
/* Parameters: library: Pointer to Start of Library Array song_name: Name of song */ void search_song_name(struct song_node* *library, char *song_name) { int i; int counter = 0; for (i = 0; i < 25; i++) { if (find_song_by_name( library[i], song_name )) { print_song( find_song_by_name( library[i], song_name ) ); counter++; } } if (! counter) printf("No Songs Found.\n"); }
/* Parameter: library: Pointer to Start of Library Array artist: Artist to Print */ void print_artist_songs(struct song_node* *library, char* song_artist) { struct song_node* head = library[ letter_to_index(song_artist) ]; int counter = 0; while(head) { if (! strcmp( head->artist, song_artist )) { print_song(head); counter++; } head = head->next; } if (! counter) printf("No Songs by this Artist Found.\n"); }
/*============================ PRINT LIBRARY ============================*/ void print_MusicLibrary() { for(int i = 0; i < song_count; i++ ) print_song(i); }
/*============================ LOOK UP SONG ============================*/ void look_up_song_with_name(char* key) { if (contains_song(key, 0, song_count-1)) print_song(find_index_of_song_with_name(key)); }
void print_list(song* list) { while(list) { print_song(list); list = list->next; } }