annotate 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
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 struct tm *localtime ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 main (argc, argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 int argc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 char **argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 int period = 60;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 time_t when;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 struct tm *tp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 if (argc > 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 period = atoi (argv[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 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 /* Make sure wakeup stops when Emacs goes away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 if (getppid () == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 printf ("Wake up!\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 /* If using a period of 60, produce the output when the minute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 changes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 if (period == 60)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 time (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 tp = localtime (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 sleep (60 - tp->tm_sec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 sleep (period);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 }