*** empty log message ***
[bpt/emacs.git] / lib-src / wakeup.c
CommitLineData
58fd8a81
DM
1/* Program to produce output at regular intervals. */
2
b98cf43f 3#ifdef HAVE_CONFIG_H
18160b98 4#include <config.h>
b98cf43f 5#endif
af40bbfa 6
58fd8a81 7#include <stdio.h>
11e5be7d 8#include <sys/types.h>
af40bbfa
JB
9
10#ifdef TIME_WITH_SYS_TIME
2198e8fe 11#include <sys/time.h>
af40bbfa
JB
12#include <time.h>
13#else
14#ifdef HAVE_SYS_TIME_H
15#include <sys/time.h>
16#else
17#include <time.h>
18#endif
19#endif
58fd8a81
DM
20
21struct tm *localtime ();
22
340ff9de 23void
58fd8a81
DM
24main (argc, argv)
25 int argc;
26 char **argv;
27{
28 int period = 60;
1da14ffd 29 time_t when;
58fd8a81
DM
30 struct tm *tp;
31
32 if (argc > 1)
33 period = atoi (argv[1]);
34
35 while (1)
36 {
7fb0d26f
JB
37 /* Make sure wakeup stops when Emacs goes away. */
38 if (getppid () == 1)
39 exit (0);
58fd8a81
DM
40 printf ("Wake up!\n");
41 fflush (stdout);
42 /* If using a period of 60, produce the output when the minute
43 changes. */
44 if (period == 60)
45 {
46 time (&when);
47 tp = localtime (&when);
48 sleep (60 - tp->tm_sec);
49 }
50 else
51 sleep (period);
52 }
53}