1 |
root |
1.1 |
#include <sys/time.h> |
2 |
|
|
#include <sys/types.h> |
3 |
|
|
#include <unistd.h> |
4 |
|
|
#include <stdlib.h> |
5 |
|
|
#include <stdio.h> |
6 |
|
|
#include <string.h> |
7 |
|
|
|
8 |
|
|
/* return filehandle */ |
9 |
|
|
static int if_init (int argc, char *argv[]); |
10 |
|
|
static void if_exit (int fd); |
11 |
|
|
static void if_parse (int fd); |
12 |
|
|
|
13 |
|
|
void |
14 |
|
|
tx_error (const char *err) |
15 |
|
|
{ |
16 |
|
|
char buf[512]; |
17 |
|
|
write (1, buf, snprintf (buf, sizeof (buf), "E%s", err) + 1); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
void |
21 |
|
|
tx_abort (const char *err) |
22 |
|
|
{ |
23 |
|
|
if (err) |
24 |
|
|
tx_error (err); |
25 |
|
|
|
26 |
|
|
exit (1); |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
void tx_code (const char *raw, const char *cooked) |
30 |
|
|
{ |
31 |
|
|
char buf[512]; |
32 |
|
|
struct timeval tv; |
33 |
|
|
|
34 |
|
|
gettimeofday (&tv, 0); |
35 |
|
|
write (1, buf, snprintf (buf, sizeof (buf), "=%ld.%06ld\x01%s\x01%s", |
36 |
|
|
tv.tv_sec, tv.tv_usec, |
37 |
|
|
raw, cooked) + 1); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
#define USAGE "This program should only be called by the perl RCU module\n" |
41 |
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b)) |
42 |
|
|
|
43 |
|
|
int |
44 |
|
|
main (int argc, char *argv[]) |
45 |
|
|
{ |
46 |
|
|
int ifd; |
47 |
|
|
|
48 |
|
|
if (argc < 2) |
49 |
|
|
{ |
50 |
|
|
write (1, USAGE, sizeof USAGE); |
51 |
|
|
exit (1); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
ifd = if_init (argc - 2, argv + 2); |
55 |
|
|
|
56 |
|
|
if (ifd >= 0) |
57 |
|
|
{ |
58 |
|
|
write (1, "I", 2); /* I<nul> */ |
59 |
|
|
|
60 |
|
|
for(;;) |
61 |
|
|
{ |
62 |
|
|
fd_set fds; |
63 |
|
|
|
64 |
|
|
FD_ZERO (&fds); |
65 |
|
|
FD_SET (ifd, &fds); |
66 |
|
|
FD_SET (0, &fds); |
67 |
|
|
|
68 |
|
|
if (select (ifd + 1, &fds, 0, 0, 0) >= 0) |
69 |
|
|
{ |
70 |
|
|
if (FD_ISSET (0, &fds)) |
71 |
|
|
break; |
72 |
|
|
|
73 |
|
|
if (FD_ISSET (ifd, &fds)) |
74 |
|
|
if_parse (ifd); |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
else |
79 |
|
|
tx_abort ("unable to set-up ir-link"); |
80 |
|
|
|
81 |
|
|
if_exit (ifd); |
82 |
|
|
|
83 |
|
|
return 0; |
84 |
|
|
} |