Mercurial > hg > xemacs-beta
comparison lib-src/wakeup.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 /* Program to produce output at regular intervals. */ | |
2 | |
3 #include <../src/config.h> | |
4 | |
5 #if __STDC__ || defined(STDC_HEADERS) | |
6 #include <stdlib.h> | |
7 #include <unistd.h> | |
8 #endif | |
9 | |
10 #include <stdio.h> | |
11 #include <sys/types.h> | |
12 | |
13 #ifdef TIME_WITH_SYS_TIME | |
14 #include <sys/time.h> | |
15 #include <time.h> | |
16 #else | |
17 #ifdef HAVE_SYS_TIME_H | |
18 #include <sys/time.h> | |
19 #else | |
20 #include <time.h> | |
21 #endif | |
22 #endif | |
23 | |
24 struct tm *localtime (); | |
25 | |
26 void | |
27 main (argc, argv) | |
28 int argc; | |
29 char **argv; | |
30 { | |
31 int period = 60; | |
32 time_t when; | |
33 struct tm *tp; | |
34 | |
35 if (argc > 1) | |
36 period = atoi (argv[1]); | |
37 | |
38 while (1) | |
39 { | |
40 /* Make sure wakeup stops when Emacs goes away. */ | |
41 if (getppid () == 1) | |
42 exit (0); | |
43 printf ("Wake up!\n"); | |
44 fflush (stdout); | |
45 /* If using a period of 60, produce the output when the minute | |
46 changes. */ | |
47 if (period == 60) | |
48 { | |
49 time (&when); | |
50 tp = localtime (&when); | |
51 sleep (60 - tp->tm_sec); | |
52 } | |
53 else | |
54 sleep (period); | |
55 } | |
56 } |