annotate lib-src/wakeup.c @ 438:84b14dcb0985 r21-2-27

Import from CVS: tag r21-2-27
author cvs
date Mon, 13 Aug 2007 11:32:25 +0200
parents 3ecd8885ac67
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Program to produce output at regular intervals. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
3 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 #if __STDC__ || defined(STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 #ifdef WINDOWSNT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 #define WIN32_LEAN_AND_MEAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 #include <windows.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 #undef sleep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 #define sleep(t) Sleep ((t) * 1000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 #define getppid() (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 #undef HAVE_SYS_TIME_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 #endif /* WINDOWSNT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #ifdef TIME_WITH_SYS_TIME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include <sys/time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #ifdef HAVE_SYS_TIME_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include <sys/time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 int period = 60;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 if (argc > 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 period = atoi (argv[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 /* Make sure wakeup stops when Emacs goes away. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 if (getppid () == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 printf ("Wake up!\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 /* If fflush fails, then our stdout pipe is broken. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 if (fflush (stdout) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 /* If using a period of 60, produce the output when the minute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 changes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 if (period == 60)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 time_t when;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 struct tm *tp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 time (&when);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 tp = localtime (&when);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 sleep (60 - tp->tm_sec);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 sleep (period);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 }