Brought everything up to date, removed spawn TODO, fixed double print error
This commit is contained in:
		
							parent
							
								
									d55edcb9b6
								
							
						
					
					
						commit
						93fda613a2
					
				
							
								
								
									
										5
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								TODO
									
									
									
									
									
								
							|  | @ -1,6 +1,5 @@ | ||||||
| 1. Add #ifdef to make libnotify an optional dependency | 1. Add more support for non-libnotify such as echo(1) | ||||||
| 2. Add more support for non-libnotify such as echo(1) | 2. Pause and continue the timer | ||||||
| 3. Pause and continue the timer |  | ||||||
| 
 | 
 | ||||||
| Misc | Misc | ||||||
| ---- | ---- | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| /* See LICENSE file for copyright and license details. */ | /* See LICENSE file for copyright and license details. */ | ||||||
| 
 | 
 | ||||||
| /* Notification */ | /* Notification, replace libnotify if you don't want it */ | ||||||
| static char *notifycmd = ""; /* Use libnotify or given command */ | static char *notifycmd = ""; /* Use libnotify or command given*/ | ||||||
| static char *notifyext = ""; /* Notify with extra command (eg. play an alarm) */ | static char *notifyext = ""; /* Notify with extra command (eg. play an alarm) */ | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  |  | ||||||
							
								
								
									
										13
									
								
								config.mk
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								config.mk
									
									
									
									
									
								
							|  | @ -2,20 +2,19 @@ | ||||||
| VERSION = 0.1 | VERSION = 0.1 | ||||||
| 
 | 
 | ||||||
| # Customize below to fit your system
 | # Customize below to fit your system
 | ||||||
| #USE_LIBNOTIFY = -DUSE_LIBNOTIFY
 |  | ||||||
| #LIBNOTIFY_CFLAGS =  `pkg-config --cflags libnotify`
 |  | ||||||
| #LIBNOTIFY_LIBS = `pkg-config --libs libnotify`
 |  | ||||||
| 
 | 
 | ||||||
| # paths
 | # paths
 | ||||||
| PREFIX = /usr/local | PREFIX = /usr/local | ||||||
| MANPREFIX = ${PREFIX}/share/man | MANPREFIX = ${PREFIX}/share/man | ||||||
| # includes and libs
 | 
 | ||||||
| INCS = -I. -I/usr/include ${USE_LIBNOTIFY} ${LIBNOTIFY_CFLAGS} | # libnotify - comment if you don't want it (config.h too)
 | ||||||
| LIBS = -L/usr/lib ${LIBNOTIFY_LIBSS} | INCS = #-I. -I/usr/include `pkg-config --cflags libnotify` | ||||||
|  | LIBS = #-L/usr/lib `pkg-config --libs libnotify` | ||||||
|  | DEFS = #-DNOTIFY | ||||||
| 
 | 
 | ||||||
| # flags
 | # flags
 | ||||||
| CPPFLAGS = -DVERSION=\"${VERSION}\" | 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} | LDFLAGS += -g ${LIBS} | ||||||
| 
 | 
 | ||||||
| # compiler and linker
 | # compiler and linker
 | ||||||
|  |  | ||||||
							
								
								
									
										38
									
								
								spt.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								spt.c
									
									
									
									
									
								
							|  | @ -5,6 +5,9 @@ | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <signal.h> | #include <signal.h> | ||||||
|  | #ifdef NOTIFY | ||||||
|  | #include <libnotify/notify.h> | ||||||
|  | #endif /* NOTIFY */ | ||||||
| 
 | 
 | ||||||
| #include "arg.h" | #include "arg.h" | ||||||
| 
 | 
 | ||||||
|  | @ -24,7 +27,7 @@ static int i, timecount; | ||||||
| 
 | 
 | ||||||
| /* function declarations */ | /* function declarations */ | ||||||
| static void die(const char *errstr, ...); | static void die(const char *errstr, ...); | ||||||
| static void spawn(char *); | static void spawn(char *, char *); | ||||||
| static void notify_send(char *); | static void notify_send(char *); | ||||||
| static void remaining_time(int); | static void remaining_time(int); | ||||||
| static void usage(void); | static void usage(void); | ||||||
|  | @ -42,11 +45,12 @@ die(const char *errstr, ...) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| spawn(char *cmd) | spawn(char *cmd, char *cmt) | ||||||
| { | { | ||||||
| 	if (fork() == 0) { | 	if (fork() == 0) { | ||||||
| 		setsid(); | 		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); | 		fprintf(stderr, "spt: execvp %s", cmd); | ||||||
| 		perror(" failed"); | 		perror(" failed"); | ||||||
| 		exit(0); | 		exit(0); | ||||||
|  | @ -56,21 +60,21 @@ spawn(char *cmd) | ||||||
| void | void | ||||||
| notify_send(char *cmt) | notify_send(char *cmt) | ||||||
| { | { | ||||||
| 	if (strcmp(notifycmd, "")) { | 	if (!strcmp(notifycmd, "libnotify")) { /* use libnotify */ | ||||||
| 		/* TODO(pickfire): merge this into spawn() */ | #ifdef NOTIFY | ||||||
| 		if (fork() == 0) { | 		notify_init("spt"); | ||||||
| 			setsid(); | 		NotifyNotification *n = notify_notification_new("spt", cmt, \ | ||||||
| 			execlp(notifycmd, "spt", cmt, NULL); | 					"dialog-information"); | ||||||
| 			fprintf(stderr, "spt: execlp %s", notifycmd); | 		notify_notification_show(n, NULL); | ||||||
| 			perror(" failed"); | 		g_object_unref(G_OBJECT(n)); | ||||||
| 			exit(0); | 		notify_uninit(); | ||||||
| 		} | #endif /* NOTIFY */ | ||||||
| 	} else { | 	} else if (strcmp(notifycmd, "")) { | ||||||
| 		fprintf(stdout,"%s\n",cmt); | 		spawn(notifycmd, cmt); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (strcmp(notifyext, "")) /* extra commands to use */ | 	if (strcmp(notifyext, "")) /* extra commands to use */ | ||||||
| 		spawn(notifyext); | 		spawn(notifyext, NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
|  | @ -91,7 +95,7 @@ remaining_time(int sigint) | ||||||
| void | void | ||||||
| usage(void) | usage(void) | ||||||
| { | { | ||||||
| 	die("usage: %s [-n notifycmd] [-e notifyext]  [-v]\n", argv0); | 	die("usage: %s [-e notifyext] [-n notifycmd] [-v]\n", argv0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int | int | ||||||
|  | @ -117,7 +121,9 @@ main(int argc, char *argv[]) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| run: | run: | ||||||
|  | 	//if (fork() == 0) {
 | ||||||
| 		notify_send(timers[i].cmt); | 		notify_send(timers[i].cmt); | ||||||
|  | 	//}
 | ||||||
| 
 | 
 | ||||||
| 	for (timecount = 0; timecount < timers[i].tmr; timecount++) { | 	for (timecount = 0; timecount < timers[i].tmr; timecount++) { | ||||||
| 		sleep(1); | 		sleep(1); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user