OSDN Git Service

38dc1e12c5ff07eda56c78aa43bf3ba763900dfd
[rec10/rec10-git.git] / epgdump / epgdump.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <getopt.h>
6 #include <iconv.h>
7 #include <time.h>
8
9 #include "ts.h"
10 #include "sdt.h"
11 #include "eit.h"
12 #include "ts_ctl.h"
13
14 typedef         struct  _ContentTYPE{
15         char    *japanese ;
16         char    *english ;
17 }CONTENT_TYPE;
18
19 #define         CAT_COUNT               16
20 static  CONTENT_TYPE    ContentCatList[CAT_COUNT] = {
21         { "¥Ë¥å¡¼¥¹¡¦ÊóÆ»", "news" },
22         { "¥¹¥Ý¡¼¥Ä", "sports" },
23         { "¾ðÊó", "information" },
24         { "¥É¥é¥Þ", "drama" },
25         { "²»³Ú", "music" },
26         { "¥Ð¥é¥¨¥Æ¥£", "variety" },
27         { "±Ç²è", "cinema" },
28         { "¥¢¥Ë¥á¡¦Æû£", "anime" },
29         { "¥É¥­¥å¥á¥ó¥¿¥ê¡¼¡¦¶µÍÜ", "documentary" },
30         { "±é·à", "stage" },
31         { "¼ñÌ£¡¦¼ÂÍÑ", "hobby" },
32         { "Ê¡»ã", "etc" },                      //Ê¡»ã
33         { "ͽÈ÷", "etc" }, //ͽÈ÷
34         { "ͽÈ÷", "etc" }, //ͽÈ÷
35         { "ͽÈ÷", "etc" }, //ͽÈ÷
36         { "¤½¤Î¾", "etc" } //¤½¤Î¾
37 };
38 typedef struct _TAG_STATION
39 {
40         char    *name;
41         char    *ontv;
42         int             tsId;           // OriginalNetworkID
43         int             onId;           // TransportStreamID
44         int             svId;           // ServiceID
45 } STATION;
46
47 static STATION bsSta[] = {
48         { "NHK BS1", "3001.ontvjapan.com", 16625, 4, 101},
49         { "NHK BS2", "3002.ontvjapan.com", 16625, 4, 102},
50         { "NHK BSh", "3003.ontvjapan.com", 16626, 4, 103},
51         { "BSÆü¥Æ¥ì", "3004.ontvjapan.com", 16592, 4, 141},
52         { "BSÄ«Æü", "3005.ontvjapan.com", 16400, 4, 151},
53         { "BS-i", "3006.ontvjapan.com", 16401, 4, 161},
54         { "BS¥¸¥ã¥Ñ¥ó", "3007.ontvjapan.com", 16433, 4, 171},
55         { "BS¥Õ¥¸", "3008.ontvjapan.com", 16593, 4, 181},
56         { "WOWOW", "3009.ontvjapan.com", 16432, 4, 191},
57         { "WOWOW2", "3010.ontvjapan.com", 16432, 4, 192},
58         { "WOWOW3", "3011.ontvjapan.com", 16432, 4, 193},
59         { "BS11", "3013.ontvjapan.com", 16528, 4, 211},
60         { "TwellV", "3014.ontvjapan.com", 16530, 4, 222},
61 };
62
63 static int bsStaCount = sizeof(bsSta) / sizeof (STATION);
64
65
66
67 static STATION csSta[] = {
68         { "¥¹¥¿¡¼£ã£è¥×¥é¥¹", "1002.ontvjapan.com", 24608, 6, 237},
69         { "ÆüËܱDzèÀìÌç£ã£è£È£Ä", "1086.ontvjapan.com", 24608, 6, 239},
70         { "¥Õ¥¸¥Æ¥ì¥Ó£Ã£Ó£È£Ä", "306ch.epgdata.ontvjapan", 24608, 6, 306},
71         { "¥·¥ç¥Ã¥×¥Á¥ã¥ó¥Í¥ë", "1059.ontvjapan.com", 24704, 6, 55},
72         { "¥­¥Ã¥º¥¹¥Æ¡¼¥·¥ç¥ó£È£Ä", "335ch.ontvjapan.com", 24704, 6, 335},
73         { "¥¶¡¦¥·¥Í¥Þ", "1217.ontvjapan.com", 24736, 6, 228},
74         { "¥¹¥«¥Á¥ã¥ó£È£Ä£¸£°£°", "800ch.epgdata.ontvjapan", 24736, 6, 800},
75         { "¥¹¥«¥Á¥ã¥ó£¸£°£±", "801ch.epgdata.ontvjapan", 24736, 6, 801},
76         { "¥¹¥«¥Á¥ã¥ó£¸£°£²", "802ch.epgdata.ontvjapan", 24736, 6, 802},
77         { "£å£²¥×¥í¥â", "100ch.epgdata.ontvjapan", 28736, 7, 100},
78         { "¥¤¥ó¥¿¡¼¥í¡¼¥«¥ë£Ô£Ö", "194ch.epgdata.ontvjapan", 28736, 7, 194},
79         { "£Ê¥¹¥Ý¡¼¥Ä¡¡£Å£Ó£Ð£Î", "1025.ontvjapan.com", 28736, 7, 256},
80         { "£Æ£Ï£Ø", "1016.ontvjapan.com", 28736, 7, 312},
81         { "¥¹¥Ú¡¼¥¹¥·¥ã¥ï¡¼£Ô£Ö", "1018.ontvjapan.com", 28736, 7, 322},
82         { "¥«¡¼¥È¥¥¡¼¥ó¡¡¥Í¥Ã¥È", "1046.ontvjapan.com", 28736, 7, 331},
83         { "¥È¥¥¡¼¥ó¡¦¥Ç¥£¥º¥Ë¡¼", "1213.ontvjapan.com", 28736, 7, 334},
84         { "Åì±Ç¥Á¥ã¥ó¥Í¥ë", "1010.ontvjapan.com", 28768, 7, 221},
85         { "±ÒÀ±·à¾ì", "1005.ontvjapan.com", 28768, 7, 222},
86         { "¥Á¥ã¥ó¥Í¥ë£Î£Å£Ã£Ï", "1008.ontvjapan.com", 28768, 7, 223},
87         { "Íβè¡ú¥·¥Í¥Õ¥£¥ë", "1009.ontvjapan.com", 28768, 7, 224},
88         { "¥¹¥¿¡¼¡¦¥¯¥é¥·¥Ã¥¯", "1003.ontvjapan.com", 28768, 7, 238},
89         { "»þÂå·àÀìÌç¥Á¥ã¥ó¥Í¥ë", "1133.ontvjapan.com", 28768, 7, 292},
90         { "¥¹¡¼¥Ñ¡¼¥É¥é¥Þ", "1006.ontvjapan.com", 28768, 7, 310},
91         { "£Á£Ø£Î", "1014.ontvjapan.com", 28768, 7, 311},
92         { "¥Ê¥·¥ç¥¸¥ª¥Á¥ã¥ó¥Í¥ë", "1204.ontvjapan.com", 28768, 7, 343},
93         { "¥ï¥ó¥Æ¥ó¥Ý¡¼¥¿¥ë", "110ch.epgdata.ontvjapan", 28864, 7, 110},
94         { "¥´¥ë¥Õ¥Á¥ã¥ó¥Í¥ë", "1028.ontvjapan.com", 28864, 7, 260},
95         { "¥Æ¥ìÄ«¥Á¥ã¥ó¥Í¥ë", "1092.ontvjapan.com", 28864, 7, 303},
96         { "£Í£Ô£Ö", "1019.ontvjapan.com", 28864, 7, 323},
97         { "¥ß¥å¡¼¥¸¥Ã¥¯¡¦¥¨¥¢", "1024.ontvjapan.com", 28864, 7, 324},
98         { "Ä«Æü¥Ë¥å¡¼¥¹¥¿¡¼", "1067.ontvjapan.com", 28864, 7, 352},
99         { "£Â£Â£Ã¥ï¡¼¥ë¥É", "1070.ontvjapan.com", 28864, 7, 353},
100         { "£Ã£Î£Î£ê", "1069.ontvjapan.com", 28864, 7, 354},
101         { "¥¸¥ã¥¹¥È¡¦¥¢¥¤", "361ch.epgdata.ontvjapan", 28864, 7, 361},
102         { "£Ê¥¹¥Ý¡¼¥Ä¡¡£±", "1041.ontvjapan.com", 28896, 7, 251},
103         { "£Ê¥¹¥Ý¡¼¥Ä¡¡£²", "1042.ontvjapan.com", 28896, 7, 252},
104         { "£Ê¥¹¥Ý¡¼¥Ä£Ð£ì£õ£ó£È", "1043.ontvjapan.com", 28896, 7, 253},
105         { "£Ç£Á£Ï£Ò£Á", "1026.ontvjapan.com", 28896, 7, 254},
106         { "£ó£ë£ù¡¦£Á¥¹¥Ý¡¼¥Ä¡Ü", "1040.ontvjapan.com", 28896, 7, 255},
107         { "ÊõÄÍ¥×¥í¥â¥Á¥ã¥ó¥Í¥ë", "101ch.epgdata.ontvjapan", 28928, 7, 101},
108         { "£Ó£Ë£Ù¡¦£Ó£Ô£Á£Ç£Å", "1207.ontvjapan.com", 28928, 7, 290},
109         { "¥Á¥ã¥ó¥Í¥ë¶ä²Ï", "305ch.epgdata.ontvjapan", 28928, 7, 305},
110         { "£Á£Ô-£Ø", "1201.ontvjapan.com", 28928, 7, 333},
111         { "¥Ò¥¹¥È¥ê¡¼¥Á¥ã¥ó¥Í¥ë", "1050.ontvjapan.com", 28928, 7, 342},
112         { "¥¹¥«¥Á¥ã¥ó£¸£°£³", "803ch.epgdata.ontvjapan", 28928, 7, 803},
113         { "¥¹¥«¥Á¥ã¥ó£¸£°£´", "804ch.epgdata.ontvjapan", 28928, 7, 804},
114         { "¥à¡¼¥Ó¡¼¥×¥é¥¹£È£Ä", "1007.ontvjapan.com", 28960, 7, 240},
115         { "¥´¥ë¥Õ¥Í¥Ã¥È¥ï¡¼¥¯", "1027.ontvjapan.com", 28960, 7, 262},
116         { "£Ì£á£Ì£á¡¡£È£Ä", "1074.ontvjapan.com", 28960, 7, 314},
117         { "¥Õ¥¸¥Æ¥ì¥Ó£Ï£Î£Å", "1073.ontvjapan.com", 28992, 7, 307},
118         { "¥Õ¥¸¥Æ¥ì¥Ó£Ô£×£Ï", "1072.ontvjapan.com", 28992, 7, 308},
119         { "¥¢¥Ë¥Þ¥Ã¥¯¥¹", "1047.ontvjapan.com", 28992, 7, 332},
120         { "¥Ç¥£¥¹¥«¥Ð¥ê¡¼", "1062.ontvjapan.com", 28992, 7, 340},
121         { "¥¢¥Ë¥Þ¥ë¥×¥é¥Í¥Ã¥È", "1193.ontvjapan.com", 28992, 7, 341},
122         { "£Ã-£Ô£Â£Ó¥¦¥¨¥ë¥«¥à", "160ch.epgdata.ontvjapan", 29024, 7, 160},
123         { "£Ñ£Ö£Ã", "1120.ontvjapan.com", 29024, 7, 161},
124         { "¥×¥é¥¤¥à£³£¶£µ¡¥£Ô£Ö", "185ch.epgdata.ontvjapan", 29024, 7, 185},
125         { "¥Õ¥¡¥ß¥ê¡¼·à¾ì", "1015.ontvjapan.com", 29024, 7, 293},
126         { "£Ô£Â£Ó¥Á¥ã¥ó¥Í¥ë", "3201.ontvjapan.com", 29024, 7, 301},
127         { "¥Ç¥£¥º¥Ë¡¼¥Á¥ã¥ó¥Í¥ë", "1090.ontvjapan.com", 29024, 7, 304},
128         { "MUSIC ON! TV", "1022.ontvjapan.com", 29024, 7, 325},
129         { "¥­¥Ã¥º¥¹¥Æ¡¼¥·¥ç¥ó", "1045.ontvjapan.com", 29024, 7, 330},
130         { "£Ô£Â£Ó¥Ë¥å¡¼¥¹¥Ð¡¼¥É", "1076.ontvjapan.com", 29024, 7, 351},
131         { "£Ã£ÓÆüËÜÈÖÁÈ¥¬¥¤¥É", "147ch.epgdata.ontvjapan", 29056, 7, 147},
132         { "Æü¥Æ¥ì£Ç¡Ü", "1068.ontvjapan.com", 29056, 7, 257},
133         { "fashion TV", "5004.ontvjapan.com", 29056, 7, 291},
134         { "Æü¥Æ¥ì¥×¥é¥¹", "300ch.epgdata.ontvjapan", 29056, 7, 300},
135         { "¥¨¥³¥ß¥å¡¼¥¸¥Ã¥¯£Ô£Ö", "1023.ontvjapan.com", 29056, 7, 320},
136         { "Music Japan TV", "1208.ontvjapan.com", 29056, 7, 321},
137         { "Æü¥Æ¥ì£Î£Å£×£Ó£²£´", "2002.ontvjapan.com", 29056, 7, 350},
138 };
139
140 static int csStaCount = sizeof(csSta) / sizeof (STATION);
141 SVT_CONTROL     *svttop = NULL;
142 #define         SECCOUNT        4
143 char    title[1024];
144 char    subtitle[1024];
145 char    desc[102400] = {0};
146 char    Category[1024];
147 char    ServiceName[1024];
148 iconv_t cd ;
149
150 void    xmlspecialchars(char *str)
151 {
152         strrep(str, "&", "&amp;");
153         strrep(str, "'", "&apos;");
154         strrep(str, "\"", "&quot;");
155         strrep(str, "<", "&lt;");
156         strrep(str, ">", "&gt;");
157 }
158
159
160
161 void    GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)
162 {
163         SECcache  *bsecs;
164
165         while((bsecs = readTS(infile, secs, count)) != NULL) {
166                 /* SDT */
167                 if((bsecs->pid & 0xFF) == 0x11) {
168                         dumpSDT(bsecs->buf, svttop);
169                 }
170         }
171 }
172 void    GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int count)
173 {
174         SECcache  *bsecs;
175         EIT_CONTROL     *eitcur ;
176         EIT_CONTROL     *eitnext ;
177         EIT_CONTROL     *eittop = NULL;
178         char    *outptr ;
179         char    *inptr ;
180         size_t  ilen;
181         size_t  olen;
182         time_t  l_time ;
183         time_t  end_time ;
184         struct  tm      tl ;
185         struct  tm      *endtl ;
186         char    cendtime[32];
187         char    cstarttime[32];
188
189         eittop = calloc(1, sizeof(EIT_CONTROL));
190         eitcur = eittop ;
191         fseek(infile, 0, SEEK_SET);
192         while((bsecs = readTS(infile, secs, SECCOUNT)) != NULL) {
193                 /* EIT */
194                 if((bsecs->pid & 0xFF) == 0x12) {
195                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
196                 }else if((bsecs->pid & 0xFF) == 0x26) {
197                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
198                 }else if((bsecs->pid & 0xFF) == 0x27) {
199                         dumpEIT(bsecs->buf, psta->svId, psta->onId, psta->tsId, eittop);
200                 }
201         }
202         eitcur = eittop ;
203         while(eitcur != NULL){
204                 if(!eitcur->servid){
205                         eitcur = eitcur->next ;
206                         continue ;
207                 }
208                 if(eitcur->content_type > CAT_COUNT){
209                         eitcur->content_type = CAT_COUNT -1 ;
210                 }
211                 outptr = title ;
212                 memset(title, '\0', sizeof(title));
213                 ilen = strlen(eitcur->title);
214                 olen = sizeof(title);
215                 inptr = eitcur->title;
216                 iconv(cd, &inptr, &ilen, &outptr, &olen);
217                 xmlspecialchars(title);
218
219                 memset(subtitle, '\0', sizeof(subtitle));
220                 ilen = strlen(eitcur->subtitle);
221                 olen = sizeof(subtitle);
222                 outptr = subtitle ;
223                 inptr = eitcur->subtitle;
224                 iconv(cd, &inptr, &ilen, &outptr, &olen);
225                 xmlspecialchars(subtitle);
226
227                 memset(desc, '\0', sizeof(desc));
228                 if ( eitcur->desc ) {
229                         ilen = strlen(eitcur->desc);
230                         olen = sizeof(desc);
231                         outptr = desc ;
232                         inptr = eitcur->desc;
233                         iconv(cd, &inptr, &ilen, &outptr, &olen);
234                         xmlspecialchars(desc);
235                 }
236
237                 memset(Category, '\0', sizeof(Category));
238                 ilen = strlen(ContentCatList[eitcur->content_type].japanese);
239                 olen = sizeof(Category);
240                 outptr = Category ;
241                 inptr = ContentCatList[eitcur->content_type].japanese;
242                 iconv(cd, &inptr, &ilen, &outptr, &olen);
243                 xmlspecialchars(Category);
244
245                 tl.tm_sec = eitcur->ss ;
246                 tl.tm_min = eitcur->hm ;
247                 tl.tm_hour = eitcur->hh ;
248                 tl.tm_mday = eitcur->dd ;
249                 tl.tm_mon = (eitcur->mm - 1);
250                 tl.tm_year = (eitcur->yy - 1900);
251                 tl.tm_wday = 0;
252                 tl.tm_isdst = 0;
253                 tl.tm_yday = 0;
254                 l_time = mktime(&tl);
255                 if((eitcur->ehh == 0) && (eitcur->emm == 0) && (eitcur->ess == 0)){
256                         (void)time(&l_time);
257                         end_time = l_time + (60 * 5);           // £µÊ¬¸å¤ËÀßÄê
258                 endtl = localtime(&end_time);
259                 }else{
260                         end_time = l_time + eitcur->ehh * 3600 + eitcur->emm * 60 + eitcur->ess;
261                         endtl = localtime(&end_time);
262                 }
263                 memset(cendtime, '\0', sizeof(cendtime));
264                 memset(cstarttime, '\0', sizeof(cstarttime));
265                 strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
266                 strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
267 #if 1
268                 fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\">\n", 
269                                 cstarttime, cendtime, psta->ontv);
270                 fprintf(outfile, "    <title lang=\"ja_JP\">%s</title>\n", title);
271                 fprintf(outfile, "    <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
272                 fprintf(outfile, "    <longdesc lang=\"ja_JP\">%s</longdesc>\n", desc);
273                 fprintf(outfile, "    <category lang=\"ja_JP\">%s</category>\n", Category);
274 //              fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
275                 fprintf(outfile, "  </programme>\n");
276 #else
277                 fprintf(outfile, "(%x:%x:%x)%s,%s,%s,%s,%s,%s\n",
278                                         eitcur->servid, eitcur->table_id, eitcur->event_id,
279                                         cstarttime, cendtime,
280                                         title, subtitle,
281                                         Category,
282                                         ContentCatList[eitcur->content_type].english);
283 #endif
284 #if 0
285                 fprintf(outfile, "(%x:%x)%04d/%02d/%02d,%02d:%02d:%02d,%02d:%02d:%02d,%s,%s,%s,%s\n",
286                                         eitcur->table_id, eitcur->event_id,
287                                         eitcur->yy, eitcur->mm, eitcur->dd,
288                                         eitcur->hh, eitcur->hm, eitcur->ss,
289                                         eitcur->ehh, eitcur->emm, eitcur->ess,
290                                         eitcur->title, eitcur->subtitle,
291                                         ContentCatList[eitcur->content_type].japanese,
292                                         ContentCatList[eitcur->content_type].english);
293 #endif
294                 eitnext = eitcur->next ;
295                 free(eitcur->title);
296                 free(eitcur->subtitle);
297                 free(eitcur);
298                 eitcur = eitnext ;
299         }
300         free(eittop);
301         eittop = NULL;
302 }
303 int main(int argc, char *argv[])
304 {
305
306         FILE *infile = stdin;
307         FILE *outfile = stdout;
308         int             arg_maxcount = 1 ;
309         char    *arg_onTV ;
310         int   mode = 1;
311         int             staCount ;
312         int   eitcnt;
313         char *file;
314         int   inclose = 0;
315         int   outclose = 0;
316         int             flag = 0 ;
317         SVT_CONTROL     *svtcur ;
318         SVT_CONTROL     *svtsave ;
319         char    *outptr ;
320         char    *inptr ;
321         size_t  ilen;
322         size_t  olen;
323         SECcache   secs[SECCOUNT];
324         int rtn;
325         int             lp ;
326         STATION *pStas ;
327         int             act ;
328
329         /* ¶½Ì£¤Î¤¢¤ëpid¤ò»ØÄê */
330         memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
331         secs[0].pid = 0x11;
332         secs[1].pid = 0x12;
333         secs[2].pid = 0x26;
334         secs[3].pid = 0x27;
335
336         if(argc == 4){
337                 arg_onTV = argv[1];
338                 file = argv[2];
339                 if(strcmp(file, "-")) {
340                         infile = fopen(file, "r");
341                         inclose = 1;
342                 }
343                 if(strcmp(argv[3], "-")) {
344                         outfile = fopen(argv[3], "w+");
345                         outclose = 1;
346                 }
347         }else{
348                 fprintf(stdout, "Usage : %s /BS <tsFile> <outfile>\n", argv[0]);
349                 fprintf(stdout, "Usage : %s <ontvcode> <tsFile> <outfile>\n", argv[0]);
350                 fprintf(stdout, "ontvcode ¥Á¥ã¥ó¥Í¥ë¼±Ê̻ҡ£****.ontvjapan.com ¤Ê¤É\n");
351                 fprintf(stdout, "/BS      BS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éBSÁ´¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
352                 fprintf(stdout, "/CS      CS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éÊ£¿ô¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
353                 return 0;
354         }
355
356         if(strcmp(arg_onTV, "/BS") == 0){
357                 pStas = bsSta;
358                 staCount = bsStaCount;
359                 act = 0 ;
360         }else if(strcmp(arg_onTV, "/CS") == 0){
361                 pStas = csSta;
362                 staCount = csStaCount;
363                 act = 0 ;
364         }else{
365                 act = 1 ;
366                 svttop = calloc(1, sizeof(SVT_CONTROL));
367                 GetSDT(infile, svttop, secs, SECCOUNT);
368                 svtcur = svttop->next ; //ÀèƬ
369                 if(svtcur == NULL){
370                         free(svttop);
371                         return ;
372                 }
373
374                 pStas = calloc(1, sizeof(STATION));
375                 pStas->tsId = svtcur->transport_stream_id ;
376                 pStas->onId = svtcur->original_network_id ;
377                 pStas->svId = svtcur->event_id ;
378                 pStas->ontv = arg_onTV ;
379                 pStas->name = svtcur->servicename ;
380                 staCount = 1;
381         }
382
383         fprintf(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
384         fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
385         fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
386
387         cd = iconv_open("UTF-8", "EUC-JP");
388         for(lp = 0 ; lp < staCount ; lp++){
389                 memset(ServiceName, '\0', sizeof(ServiceName));
390                 ilen = strlen(pStas[lp].name);
391                 olen = sizeof(ServiceName);
392                 outptr = ServiceName ;
393                 inptr = pStas[lp].name ;
394                 iconv(cd, &inptr, &ilen, &outptr, &olen);
395                 xmlspecialchars(ServiceName);
396
397                 fprintf(outfile, "  <channel id=\"%s\">\n", pStas[lp].ontv);
398                 fprintf(outfile, "    <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
399                 fprintf(outfile, "  </channel>\n");
400         }
401         for(lp = 0 ; lp < staCount ; lp++){
402                 GetEIT(infile, outfile, &pStas[lp], secs, SECCOUNT);
403         }
404         fprintf(outfile, "</tv>\n");
405         if(inclose) {
406                 fclose(infile);
407         }
408
409         if(outclose) {
410                 fclose(outfile);
411         }
412         iconv_close(cd);
413         if(act){
414                 free(pStas);
415                 svtcur = svttop ;       //ÀèƬ
416                 while(svtcur != NULL){
417                         svtsave = svtcur->next ;
418                         free(svtcur);
419                         svtcur = svtsave ;
420                 }
421         }
422
423         return 0;
424 }