annotate recpt1/recpt1ctl.c @ 86:015481a6a900

clean up a bit.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 19 Jan 2010 06:33:08 +0900
parents 5a0126d8af17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 #include <sys/types.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2 #include <sys/ipc.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 #include <sys/msg.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 #include <stdio.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 #include <stdlib.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 #include <string.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 #include <ctype.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 #include <getopt.h>
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 #include "version.h"
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 #define MSGSZ 255
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 typedef struct msgbuf {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 long mtype;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17 char mtext[MSGSZ];
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18 } message_buf;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20 void
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 show_usage(char *cmd)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 fprintf(stderr, "Usage: \n%s --pid pid [--channel channel] [--extend time_to_extend] [--time recording_time]\n", cmd);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 void
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
28 show_options(void)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 fprintf(stderr, "Options:\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 fprintf(stderr, "--pid: Process id of recpt1 to control\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 fprintf(stderr, "--channel: Tune to specified channel\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33 fprintf(stderr, "--extend: Extend recording time\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
34 fprintf(stderr, "--time: Set total recording time\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35 fprintf(stderr, "--help: Show this help\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 fprintf(stderr, "--version: Show version\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37 fprintf(stderr, "--list: Show channel list\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
38 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
40 void
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 show_channels(void)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 FILE *f;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 char *home;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45 char buf[255], filename[255];
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 fprintf(stderr, "Available Channels:\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 home = getenv("HOME");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 sprintf(filename, "%s/.recpt1-channels", home);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51 f = fopen(filename, "r");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52 if(f) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
53 while(fgets(buf, 255, f))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 fprintf(stderr, "%s", buf);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55 fclose(f);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 else
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58 fprintf(stderr, "13-62: Terrestrial Channels\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 fprintf(stderr, "101ch: NHK BS1\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 fprintf(stderr, "102ch: NHK BS2\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 fprintf(stderr, "103ch: NHK BShi\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 fprintf(stderr, "141ch: BS Nittele\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64 fprintf(stderr, "151ch: BS Asahi\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
65 fprintf(stderr, "161ch: BS-TBS\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
66 fprintf(stderr, "171ch: BS Japan\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67 fprintf(stderr, "181ch: BS Fuji\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
68 fprintf(stderr, "191ch: WOWOW\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
69 fprintf(stderr, "200ch: Star Channel\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
70 fprintf(stderr, "211ch: BS11 Digital\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
71 fprintf(stderr, "222ch: TwellV\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
72 fprintf(stderr, "CS2-CS24: CS Channels\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
73 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76 parse_time(char *rectimestr, int *recsec)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
77 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78 /* indefinite */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79 if(!strcmp("-", rectimestr)) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 *recsec = -1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
81 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82 /* colon */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83 else if(strchr(rectimestr, ':')) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
84 int n1, n2, n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
85 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
86 *recsec = n1 * 3600 + n2 * 60 + n3;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88 *recsec = n1 * 3600 + n2 * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90 /* HMS */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 else {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
92 char *tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93 char *p1, *p2;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95 tmpstr = strdup(rectimestr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
96 p1 = tmpstr;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 /* hour */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 *recsec += atoi(p1) * 3600;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 /* minute */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 *p2 = '\0';
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 *recsec += atoi(p1) * 60;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 p1 = p2 + 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 while(*p1 && !isdigit(*p1))
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 p1++;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 /* second */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 *recsec += atoi(p1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121 free(tmpstr);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124 return 0; /* success */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 int
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 main(int argc, char **argv)
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 int msqid;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 int msgflg = IPC_CREAT | 0666;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 key_t key = 0;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 int channel=0, recsec = 0, extsec=0;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134 message_buf sbuf;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 size_t buf_length;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 int result;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 int option_index;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 struct option long_options[] = {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 { "pid", 1, NULL, 'p'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 { "channel", 1, NULL, 'c'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142 { "extend", 1, NULL, 'e'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 { "time", 1, NULL, 't'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 { "help", 0, NULL, 'h'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 { "version", 0, NULL, 'v'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 { "list", 0, NULL, 'l'},
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 {0, 0, NULL, 0} /* terminate */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 };
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 while((result = getopt_long(argc, argv, "p:c:e:t:hvl",
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 long_options, &option_index)) != -1) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 switch(result) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153 case 'h':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 show_usage(argv[0]);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 show_options();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 show_channels();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 fprintf(stderr, "\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 case 'v':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 fprintf(stderr, "%s %s\n", argv[0], version);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 fprintf(stderr, "control command for recpt1.\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 case 'l':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 show_channels();
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 /* following options require argument */
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 case 'p':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 key = (key_t)atoi(optarg);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 fprintf(stderr, "Pid = %d\n", key);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 case 'c':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 channel = atoi(optarg);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 fprintf(stderr, "Channel = %d\n", channel);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 case 'e':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 parse_time(optarg, &extsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 fprintf(stderr, "Extend %d sec\n", extsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185 case 't':
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 parse_time(optarg, &recsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187 fprintf(stderr, "Total recording time = %d sec\n", recsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 break;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 if(!key) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 fprintf(stderr, "Arguments are necessary!\n");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 if ((msqid = msgget(key, msgflg )) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 perror("msgget");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 sbuf.mtype = 1;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 sprintf(sbuf.mtext, "ch=%d t=%d e=%d", channel, recsec, extsec);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 buf_length = strlen(sbuf.mtext) + 1 ;
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208 if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
209 perror("msgsnd");
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 exit(1);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 }
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213 exit(0);
5a0126d8af17 landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 }