QUOTE: Be your own kind of beautiful.

rx

A terminal-based radio player

main.c (776B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <signal.h>
      4 #include <execinfo.h>
      5 #include <unistd.h>
      6 
      7 #include "../include/rx.h"
      8 
      9 #define BACKTRACE_SIZE 10
     10 
     11 void handle_segfault(int signal) {
     12   void *list[BACKTRACE_SIZE];
     13   size_t size = backtrace(list, BACKTRACE_SIZE);
     14   fprintf(stderr, "ERROR: signal %d:\n", signal);
     15   backtrace_symbols_fd(list, size, STDERR_FILENO);
     16   exit(EXIT_FAILURE);
     17 }
     18 
     19 rx_t rx;
     20 
     21 void do_update(void) {
     22   rx_update(&rx);
     23   rx_draw(&rx);
     24 }
     25 
     26 int main(void) {
     27   rx_init(&rx);
     28   struct sigaction sigint_action;
     29   sigint_action.sa_handler = handle_segfault;
     30   sigint_action.sa_flags = 0;
     31   sigemptyset(&sigint_action.sa_mask);
     32   sigaction(SIGSEGV, &sigint_action, NULL);
     33   while (!rx.quit) {
     34     do_update();
     35   }
     36   rx_free(&rx);
     37   return EXIT_SUCCESS;
     38 }