From 7ae60bddeb3fb91487658369c523a4491038df17 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 05 Oct 2019 02:52:03 -0400 Subject: main(): Detect and report speech_new() errors --- diff --git a/src/main.c b/src/main.c index b35d079..3963e88 100644 --- a/src/main.c +++ b/src/main.c @@ -19,16 +19,51 @@ * along with Timeteller. If not, see . */ +#include +#include +#include +#include + #include "speech.h" +static const char *program_name; + +static void +set_program_name(const char *name) +{ + assert(name && *name); + + program_name = name; +} + +static void +error(const char *format, ...) +{ + va_list ap; + + assert(format); + + fprintf(stderr, "%s: Error: ", program_name); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + fputs("\n", stderr); +} + int main(int argc, char **argv) { struct speech *speech; + set_program_name(argv[0]); + speech = speech_new(); + if (speech == NULL) { + error("Failed to initialize speech synthesis engine"); + return EXIT_FAILURE; + } speech_play_time(speech); speech_destroy(&speech); - return 0; + return EXIT_SUCCESS; } -- cgit v0.9.1