Mercurial > pt1
comparison recpt1/recpt1ctl.c @ 140:c9b1d21c5035
separate common function to core library
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 25 Apr 2013 16:06:15 +0900 |
parents | 5a0126d8af17 |
children |
comparison
equal
deleted
inserted
replaced
139:61ff9cabf962 | 140:c9b1d21c5035 |
---|---|
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <ctype.h> | 8 #include <ctype.h> |
9 #include <getopt.h> | 9 #include <getopt.h> |
10 | 10 #include "recpt1core.h" |
11 #include "version.h" | |
12 | 11 |
13 #define MSGSZ 255 | 12 #define MSGSZ 255 |
14 | |
15 typedef struct msgbuf { | |
16 long mtype; | |
17 char mtext[MSGSZ]; | |
18 } message_buf; | |
19 | 13 |
20 void | 14 void |
21 show_usage(char *cmd) | 15 show_usage(char *cmd) |
22 { | 16 { |
23 fprintf(stderr, "Usage: \n%s --pid pid [--channel channel] [--extend time_to_extend] [--time recording_time]\n", cmd); | 17 fprintf(stderr, "Usage: \n%s --pid pid [--channel channel] [--extend time_to_extend] [--time recording_time]\n", cmd); |
33 fprintf(stderr, "--extend: Extend recording time\n"); | 27 fprintf(stderr, "--extend: Extend recording time\n"); |
34 fprintf(stderr, "--time: Set total recording time\n"); | 28 fprintf(stderr, "--time: Set total recording time\n"); |
35 fprintf(stderr, "--help: Show this help\n"); | 29 fprintf(stderr, "--help: Show this help\n"); |
36 fprintf(stderr, "--version: Show version\n"); | 30 fprintf(stderr, "--version: Show version\n"); |
37 fprintf(stderr, "--list: Show channel list\n"); | 31 fprintf(stderr, "--list: Show channel list\n"); |
38 } | |
39 | |
40 void | |
41 show_channels(void) | |
42 { | |
43 FILE *f; | |
44 char *home; | |
45 char buf[255], filename[255]; | |
46 | |
47 fprintf(stderr, "Available Channels:\n"); | |
48 | |
49 home = getenv("HOME"); | |
50 sprintf(filename, "%s/.recpt1-channels", home); | |
51 f = fopen(filename, "r"); | |
52 if(f) { | |
53 while(fgets(buf, 255, f)) | |
54 fprintf(stderr, "%s", buf); | |
55 fclose(f); | |
56 } | |
57 else | |
58 fprintf(stderr, "13-62: Terrestrial Channels\n"); | |
59 | |
60 fprintf(stderr, "101ch: NHK BS1\n"); | |
61 fprintf(stderr, "102ch: NHK BS2\n"); | |
62 fprintf(stderr, "103ch: NHK BShi\n"); | |
63 fprintf(stderr, "141ch: BS Nittele\n"); | |
64 fprintf(stderr, "151ch: BS Asahi\n"); | |
65 fprintf(stderr, "161ch: BS-TBS\n"); | |
66 fprintf(stderr, "171ch: BS Japan\n"); | |
67 fprintf(stderr, "181ch: BS Fuji\n"); | |
68 fprintf(stderr, "191ch: WOWOW\n"); | |
69 fprintf(stderr, "200ch: Star Channel\n"); | |
70 fprintf(stderr, "211ch: BS11 Digital\n"); | |
71 fprintf(stderr, "222ch: TwellV\n"); | |
72 fprintf(stderr, "CS2-CS24: CS Channels\n"); | |
73 } | |
74 | |
75 int | |
76 parse_time(char *rectimestr, int *recsec) | |
77 { | |
78 /* indefinite */ | |
79 if(!strcmp("-", rectimestr)) { | |
80 *recsec = -1; | |
81 } | |
82 /* colon */ | |
83 else if(strchr(rectimestr, ':')) { | |
84 int n1, n2, n3; | |
85 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3) | |
86 *recsec = n1 * 3600 + n2 * 60 + n3; | |
87 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2) | |
88 *recsec = n1 * 3600 + n2 * 60; | |
89 } | |
90 /* HMS */ | |
91 else { | |
92 char *tmpstr; | |
93 char *p1, *p2; | |
94 | |
95 tmpstr = strdup(rectimestr); | |
96 p1 = tmpstr; | |
97 while(*p1 && !isdigit(*p1)) | |
98 p1++; | |
99 | |
100 /* hour */ | |
101 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) { | |
102 *p2 = '\0'; | |
103 *recsec += atoi(p1) * 3600; | |
104 p1 = p2 + 1; | |
105 while(*p1 && !isdigit(*p1)) | |
106 p1++; | |
107 } | |
108 | |
109 /* minute */ | |
110 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) { | |
111 *p2 = '\0'; | |
112 *recsec += atoi(p1) * 60; | |
113 p1 = p2 + 1; | |
114 while(*p1 && !isdigit(*p1)) | |
115 p1++; | |
116 } | |
117 | |
118 /* second */ | |
119 *recsec += atoi(p1); | |
120 | |
121 free(tmpstr); | |
122 } | |
123 | |
124 return 0; /* success */ | |
125 } | 32 } |
126 | 33 |
127 int | 34 int |
128 main(int argc, char **argv) | 35 main(int argc, char **argv) |
129 { | 36 { |