main.c (803B)
1#include "data.h" 2#include "log.h" 3#include "mpris.h" 4#include "player.h" 5#include "tui.h" 6 7#include <curses.h> 8#include <locale.h> 9 10static void stop(int sig); 11static void init(void); 12static void cleanup(int code, void *arg); 13 14void 15stop(int sig) 16{ 17 if (player.loaded) { 18 player_stop(); 19 } else { 20 exit(0); 21 } 22} 23 24void 25init(void) 26{ 27 setlocale(LC_ALL, ""); 28 srand(time(NULL)); 29 30 log_init(); 31 32 data_load(); 33 34 player_init(); 35 36 tui_init(); 37 38 dbus_init(); 39 40 on_exit(cleanup, NULL); 41 signal(SIGINT, stop); 42 signal(SIGTERM, exit); 43} 44 45void 46cleanup(int exitcode, void* arg) 47{ 48 tui_restore(); 49 50 player_deinit(); 51 52 data_save(); 53 data_free(); 54 55 dbus_deinit(); 56 57 tui_deinit(); 58 59 log_deinit(); 60} 61 62int 63main(int argc, const char **argv) 64{ 65 init(); 66 67 do { 68 dbus_update(); 69 player_update(); 70 } while (tui_update()); 71} 72