Prevent macro hell
This commit is contained in:
		
							parent
							
								
									58d1470890
								
							
						
					
					
						commit
						c89ef49965
					
				
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							|  | @ -1,4 +1,4 @@ | ||||||
| Copyright (c) 2015-2016, Ivan Tham | Copyright (c) 2015-2016, Ivan Tham <pickfire@riseup.net> | ||||||
| 
 | 
 | ||||||
| Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||||
| purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| # spt version
 | # spt version
 | ||||||
| VERSION = 0.1 | VERSION = 0.2 | ||||||
| 
 | 
 | ||||||
| # Customize below to fit your system
 | # Customize below to fit your system
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								spt.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								spt.c
									
									
									
									
									
								
							|  | @ -15,13 +15,6 @@ char *argv0; | ||||||
| 
 | 
 | ||||||
| /* macros */ | /* macros */ | ||||||
| #define LEN(a)  (sizeof(a) / sizeof(a[0])) | #define LEN(a)  (sizeof(a) / sizeof(a[0])) | ||||||
| #define SPAWN(cmd)	if (fork() == 0) {\ |  | ||||||
| 				setsid();\ |  | ||||||
| 				cmd;\ |  | ||||||
| 				die("spt: spawn\n");\ |  | ||||||
| 				perror(" failed");\ |  | ||||||
| 				exit(0);\ |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|  | @ -35,6 +28,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 *cmd, char *cmt); | ||||||
| static void notify_send(char *cmt); | static void notify_send(char *cmt); | ||||||
| static void remaining_time(int sigint); | static void remaining_time(int sigint); | ||||||
| static void usage(void); | static void usage(void); | ||||||
|  | @ -48,7 +42,19 @@ die(const char *errstr, ...) | ||||||
| 	va_start(ap, errstr); | 	va_start(ap, errstr); | ||||||
| 	vfprintf(stderr, errstr, ap); | 	vfprintf(stderr, errstr, ap); | ||||||
| 	va_end(ap); | 	va_end(ap); | ||||||
| 	exit(EXIT_FAILURE); | 	exit(1); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void | ||||||
|  | spawn(char *cmd, char *cmt) | ||||||
|  | { | ||||||
|  | 	if (fork() == 0) { | ||||||
|  | 		setsid(); | ||||||
|  | 		execlp(cmd, cmd, "spt", cmt, NULL); | ||||||
|  | 		die("spt: execlp %s\n", cmd); | ||||||
|  | 		perror(" failed"); | ||||||
|  | 		exit(0); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
|  | @ -63,25 +69,25 @@ notify_send(char *cmt) | ||||||
| 	notify_uninit(); | 	notify_uninit(); | ||||||
| #else | #else | ||||||
| 	if (strcmp(notifycmd, "")) /* TODO: call function in config.h */ | 	if (strcmp(notifycmd, "")) /* TODO: call function in config.h */ | ||||||
| 		SPAWN(execlp(notifycmd, notifycmd, "spt", cmt, NULL)) | 		spawn(notifycmd, cmt); | ||||||
| #endif /* NOTIFY */ | #endif /* NOTIFY */ | ||||||
| 
 | 
 | ||||||
| 	if (strcmp(notifyext, "")) /* extra commands to use */ | 	if (strcmp(notifyext, "")) /* extra commands to use */ | ||||||
| 		SPAWN(execvp("sh", (char *const []){"/bin/sh", "-c", notifyext, NULL})) | 		spawn(notifyext, NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| remaining_time(int sigint) | remaining_time(int sigint) | ||||||
| { | { | ||||||
| 	char remainingtext[17]; | 	char buf[17]; | ||||||
| 	if (signal(SIGUSR1, SIG_IGN) != SIG_IGN) | 	if (signal(SIGUSR1, SIG_IGN) != SIG_IGN) | ||||||
| 		signal(SIGUSR1, remaining_time); | 		signal(SIGUSR1, remaining_time); | ||||||
| 
 | 
 | ||||||
| 	snprintf(remainingtext, 17, "Remaining: %02d:%02d\n", | 	snprintf(buf, 17, "Remaining: %02d:%02d\n", | ||||||
| 		 (timers[i].tmr - timecount) / 60, | 		 (timers[i].tmr - timecount) / 60, | ||||||
| 		 (timers[i].tmr - timecount) % 60); | 		 (timers[i].tmr - timecount) % 60); | ||||||
| 
 | 
 | ||||||
| 	notify_send(remainingtext); | 	notify_send(buf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user