summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-10-05 02:52:03 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-10-05 02:52:44 (EDT)
commit7ae60bddeb3fb91487658369c523a4491038df17 (patch)
tree35b9d5c16f5f04209237513146568ee61cdc8eb9
parent1c0ab0332c05ce688f370f9d40e0c2ba99a0c32e (diff)
downloadtimeteller-7ae60bddeb3fb91487658369c523a4491038df17.zip
timeteller-7ae60bddeb3fb91487658369c523a4491038df17.tar.gz
timeteller-7ae60bddeb3fb91487658369c523a4491038df17.tar.bz2
main(): Detect and report speech_new() errors
-rw-r--r--src/main.c37
1 files changed, 36 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
*/
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#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;
}