annotate lib-src/wakeup.c @ 163:0132846995bd r20-3b8

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