OSDN Git Service

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