From 93fda613a2df3622268aa292d492da0419d98384 Mon Sep 17 00:00:00 2001 From: Antonio Bibiano Date: Mon, 11 Jul 2016 15:26:56 +1000 Subject: [PATCH] Brought everything up to date, removed spawn TODO, fixed double print error --- TODO | 5 ++--- config.def.h | 4 ++-- config.mk | 13 ++++++------- spt.c | 40 +++++++++++++++++++++++----------------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 5ec4066..3cb9e0f 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ -1. Add #ifdef to make libnotify an optional dependency -2. Add more support for non-libnotify such as echo(1) -3. Pause and continue the timer +1. Add more support for non-libnotify such as echo(1) +2. Pause and continue the timer Misc ---- diff --git a/config.def.h b/config.def.h index 96a8a9d..6f2f66e 100644 --- a/config.def.h +++ b/config.def.h @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ -/* Notification */ -static char *notifycmd = ""; /* Use libnotify or given command */ +/* Notification, replace libnotify if you don't want it */ +static char *notifycmd = ""; /* Use libnotify or command given*/ static char *notifyext = ""; /* Notify with extra command (eg. play an alarm) */ /* diff --git a/config.mk b/config.mk index d6e5d81..e45227a 100644 --- a/config.mk +++ b/config.mk @@ -2,20 +2,19 @@ VERSION = 0.1 # Customize below to fit your system -#USE_LIBNOTIFY = -DUSE_LIBNOTIFY -#LIBNOTIFY_CFLAGS = `pkg-config --cflags libnotify` -#LIBNOTIFY_LIBS = `pkg-config --libs libnotify` # paths PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man -# includes and libs -INCS = -I. -I/usr/include ${USE_LIBNOTIFY} ${LIBNOTIFY_CFLAGS} -LIBS = -L/usr/lib ${LIBNOTIFY_LIBSS} + +# libnotify - comment if you don't want it (config.h too) +INCS = #-I. -I/usr/include `pkg-config --cflags libnotify` +LIBS = #-L/usr/lib `pkg-config --libs libnotify` +DEFS = #-DNOTIFY # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${DEFS} ${CPPFLAGS} LDFLAGS += -g ${LIBS} # compiler and linker diff --git a/spt.c b/spt.c index 81b41d2..aa926a0 100644 --- a/spt.c +++ b/spt.c @@ -5,6 +5,9 @@ #include #include #include +#ifdef NOTIFY +#include +#endif /* NOTIFY */ #include "arg.h" @@ -24,7 +27,7 @@ static int i, timecount; /* function declarations */ static void die(const char *errstr, ...); -static void spawn(char *); +static void spawn(char *, char *); static void notify_send(char *); static void remaining_time(int); static void usage(void); @@ -42,11 +45,12 @@ die(const char *errstr, ...) } void -spawn(char *cmd) +spawn(char *cmd, char *cmt) { if (fork() == 0) { setsid(); - execvp("sh", (char *const []){"/bin/sh", "-c", cmd, 0}); + //execvp("sh", (char *const []){"/bin/sh", "-c", cmd, cmt, NULL}); + execvp(cmd, (char *const []){cmd,cmt, NULL}); fprintf(stderr, "spt: execvp %s", cmd); perror(" failed"); exit(0); @@ -56,21 +60,21 @@ spawn(char *cmd) void notify_send(char *cmt) { - if (strcmp(notifycmd, "")) { - /* TODO(pickfire): merge this into spawn() */ - if (fork() == 0) { - setsid(); - execlp(notifycmd, "spt", cmt, NULL); - fprintf(stderr, "spt: execlp %s", notifycmd); - perror(" failed"); - exit(0); - } - } else { - fprintf(stdout,"%s\n",cmt); + if (!strcmp(notifycmd, "libnotify")) { /* use libnotify */ +#ifdef NOTIFY + notify_init("spt"); + NotifyNotification *n = notify_notification_new("spt", cmt, \ + "dialog-information"); + notify_notification_show(n, NULL); + g_object_unref(G_OBJECT(n)); + notify_uninit(); +#endif /* NOTIFY */ + } else if (strcmp(notifycmd, "")) { + spawn(notifycmd, cmt); } if (strcmp(notifyext, "")) /* extra commands to use */ - spawn(notifyext); + spawn(notifyext, NULL); } void @@ -91,7 +95,7 @@ remaining_time(int sigint) void usage(void) { - die("usage: %s [-n notifycmd] [-e notifyext] [-v]\n", argv0); + die("usage: %s [-e notifyext] [-n notifycmd] [-v]\n", argv0); } int @@ -117,7 +121,9 @@ main(int argc, char *argv[]) } run: - notify_send(timers[i].cmt); + //if (fork() == 0) { + notify_send(timers[i].cmt); + //} for (timecount = 0; timecount < timers[i].tmr; timecount++) { sleep(1);