annotate lib-src/wakeup.c @ 357:4711e16a8e49 r21-1-8

Import from CVS: tag r21-1-8
author cvs
date Mon, 13 Aug 2007 10:57:04 +0200
parents e11d67e05968
children 74fd4e045ea6
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
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
13 #ifdef WINDOWSNT
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
14 #define WIN32_LEAN_AND_MEAN
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
15 #include <windows.h>
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
16 #undef sleep
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
17 #define sleep(t) Sleep ((t) * 1000)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
18 #define getppid() (0)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
19 #undef HAVE_SYS_TIME_H
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
20 #endif /* WINDOWSNT */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
21
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 #ifdef TIME_WITH_SYS_TIME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #include <sys/time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #ifdef HAVE_SYS_TIME_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <sys/time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
33 int
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
34 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 int period = 60;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 if (argc > 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 period = atoi (argv[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* Make sure wakeup stops when Emacs goes away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 if (getppid () == 1)
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
45 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 printf ("Wake up!\n");
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
47 /* If fflush fails, then our stdout pipe is broken. */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
48 if (fflush (stdout) != 0)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 169
diff changeset
49 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* If using a period of 60, produce the output when the minute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 changes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 if (period == 60)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 {
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
54 time_t when;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 2
diff changeset
55 struct tm *tp;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 time (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 tp = localtime (&when);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 sleep (60 - tp->tm_sec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 sleep (period);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 }