annotate lib-src/wakeup.c @ 266:18d185df8c54

Added tag r20-5b31 for changeset 8efd647ea9ca
author cvs
date Mon, 13 Aug 2007 10:25:39 +0200
parents 15872534500d
children e11d67e05968
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
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
24 int
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
25 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 int period = 60;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 if (argc > 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 period = atoi (argv[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 /* Make sure wakeup stops when Emacs goes away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 if (getppid () == 1)
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
36 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 printf ("Wake up!\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 /* If using a period of 60, produce the output when the minute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 changes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 if (period == 60)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 {
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
43 time_t when;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
44 struct tm *tp;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 time (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 tp = localtime (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 sleep (60 - tp->tm_sec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 sleep (period);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 }