OSDN Git Service

commit local dev ver
authorlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 26 Jan 2011 02:41:26 +0000 (02:41 +0000)
committerlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 26 Jan 2011 02:41:26 +0000 (02:41 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@815 4e526526-5e11-4fc0-8910-f8fd03428081

26 files changed:
epgdump/Makefile
epgdump/aribstr.c
epgdump/cdt.c [new file with mode: 0644]
epgdump/cdt.h [new file with mode: 0644]
epgdump/clt2png.c [new file with mode: 0644]
epgdump/clt2png.h [new file with mode: 0644]
epgdump/dsmcc.c [new file with mode: 0644]
epgdump/dsmcc.h [new file with mode: 0644]
epgdump/eit.c
epgdump/eit.h
epgdump/epgdump.c
epgdump/psi.c [new file with mode: 0644]
epgdump/psi.h [new file with mode: 0644]
epgdump/readme.txt
epgdump/sdt.c
epgdump/sdt.h
epgdump/sdtt.c [new file with mode: 0644]
epgdump/sdtt.h [new file with mode: 0644]
epgdump/tags [new file with mode: 0644]
epgdump/tot.c [new file with mode: 0644]
epgdump/tot.h [new file with mode: 0644]
epgdump/ts.c
epgdump/ts_ctl.h
epgdump/util.c
epgdump/util.h
epgdump/xmldata.c

index ab2ce18..8f2d778 100644 (file)
@@ -1,11 +1,16 @@
 PREFIX         = /usr/local
 TARGETS        = epgdump
-OBJ_TARGETS    = epgdump.o aribstr.o eit.o ts.o util.o sdt.o
-HEDDERDEPEND   = eit.h sdt.h aribstr.h ts.h util.h
+OBJ_TARGETS    = epgdump.o aribstr.o eit.o ts.o util.o psi.o sdt.o cdt.o sdtt.o dsmcc.o tot.o clt2png.o
+HEDDERDEPEND   = eit.h psi.h sdt.h cdt.h sdtt.h dsmcc.h tot.h clt2png.h aribstr.h ts.h util.h
 
 LANG           = C
 CC             = gcc
-CFLAGS         = -std=c99 -O2 -Wall -g
+
+#CFLAGS                = -std=c99 -O2 -Wall -g
+CFLAGS         = -std=c99 -O0 -Wall -ggdb
+#CFLAGS                = -std=c99 -O2 -Wall -ggdb
+#CFLAGS                = -std=c99 -O2 -Wall -ggdb -lefence
+
 LIBS           = 
 
 .c.o:                  ${CC} ${CFLAGS} -c $<
index 1e736ea..44c62bf 100755 (executable)
@@ -6,7 +6,7 @@
 
 #include "aribstr.h"
 
-#define CODE_UNKNOWN           0       // ÉÔÌÀ¤Ê¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È(ÈóÂбþ)
+#define CODE_UNKNOWN           0       // 不明なグラフィックセット(非対応)
 #define CODE_KANJI             1       // Kanji
 #define CODE_ALPHANUMERIC      2       // Alphanumeric
 #define CODE_HIRAGANA          3       // Hiragana
@@ -50,6 +50,7 @@ static        const DWORD ProcessCharCode(TCHAR *lpszDst, const WORD wCode, const CODE_
 
 static const DWORD PutKanjiChar(TCHAR *lpszDst, const WORD wCode);
 static const DWORD PutAlphanumericChar(TCHAR *lpszDst, const WORD wCode);
+//static       const DWORD PutAlphanumericHankakuChar(TCHAR *lpszDst, const WORD wCode);
 static const DWORD PutHiraganaChar(TCHAR *lpszDst, const WORD wCode);
 static const DWORD PutKatakanaChar(TCHAR *lpszDst, const WORD wCode);
 static const DWORD PutJisKatakanaChar(TCHAR *lpszDst, const WORD wCode);
@@ -64,11 +65,9 @@ static       void SingleShiftGL(const BYTE byIndexG);
 static const bool DesignationGSET(const BYTE byIndexG, const BYTE byCode);
 static const bool DesignationDRCS(const BYTE byIndexG, const BYTE byCode);
 
-static WORD convertjis(DWORD);
-
 static const bool abCharSizeTable[] =
 {
-       false,  // CODE_UNKNOWN                                 ÉÔÌÀ¤Ê¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È(ÈóÂбþ)
+       false,  // CODE_UNKNOWN                                 不明なグラフィックセット(非対応)
        true,   // CODE_KANJI                                   Kanji
        false,  // CODE_ALPHANUMERIC                    Alphanumeric
        false,  // CODE_HIRAGANA                                Hiragana
@@ -86,6 +85,57 @@ static const bool abCharSizeTable[] =
        true    // CODE_ADDITIONAL_SYMBOLS              Additional symbols
 };
 
+typedef enum{
+       STR_SMALL = 0,  //SSZ
+       STR_MEDIUM,             //MSZ
+       STR_NORMAL,             //NSZ
+       STR_MICRO,              //SZX 0x60
+       STR_HIGH_W,             //SZX 0x41
+       STR_WIDTH_W,    //SZX 0x44
+       STR_W,                  //SZX 0x45
+       STR_SPECIAL_1,  //SZX 0x6B
+       STR_SPECIAL_2,  //SZX 0x64
+} STRING_SIZE;
+
+STRING_SIZE m_emStrSize;
+
+bool IsSmallCharMode(void)
+{
+       bool bRet = false;
+       switch(m_emStrSize){
+               case STR_SMALL:
+                       bRet = true;
+                       break;
+               case STR_MEDIUM:
+                       bRet = true;
+                       break;
+               case STR_NORMAL:
+                       bRet = false;
+                       break;
+               case STR_MICRO:
+                       bRet = true;
+                       break;
+               case STR_HIGH_W:
+                       bRet = false;
+                       break;
+               case STR_WIDTH_W:
+                       bRet = false;
+                       break;
+               case STR_W:
+                       bRet = false;
+                       break;
+               case STR_SPECIAL_1:
+                       bRet = false;
+                       break;
+               case STR_SPECIAL_2:
+                       bRet = false;
+                       break;
+               default:
+                       break;
+       }
+       return bRet;
+}
+
 int AribToString(
        char *lpszDst, 
        const char *pSrcData, 
@@ -104,7 +154,7 @@ const DWORD AribToStringInternal(TCHAR *lpszDst,
        DWORD dwDstLen = 0UL;
        int   dwSrcData;
   
-       // ¾õÂÖ½é´üÀßÄê
+       // 状態初期設定
        m_byEscSeqCount = 0U;
        m_pSingleGL = NULL;
 
@@ -116,70 +166,82 @@ const DWORD AribToStringInternal(TCHAR *lpszDst,
        m_pLockingGL = &m_CodeG[0];
        m_pLockingGR = &m_CodeG[2];
 
+       m_emStrSize = STR_NORMAL;
        while(dwSrcPos < dwSrcLen){
                dwSrcData = pSrcData[dwSrcPos] & 0xFF;
 
+               //printf("Arib:pos%d:%d:%s\n",dwSrcPos,dwSrcData,lpszDst);
                if(!m_byEscSeqCount){
       
-                       // GL/GRÎΰè
+                       // GL/GR領域
                        if((dwSrcData >= 0x21U) && (dwSrcData <= 0x7EU)){
-                               // GLÎΰè
+                               // GL領域
                                const CODE_SET CurCodeSet = (m_pSingleGL)? *m_pSingleGL : *m_pLockingGL;
                                m_pSingleGL = NULL;
                                
                                if(abCharSizeTable[CurCodeSet]){
-                                       // 2¥Ð¥¤¥È¥³¡¼¥É
+                                       // 2バイトコード
                                        if((dwSrcLen - dwSrcPos) < 2UL)break;
                                        
                                        dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((WORD)pSrcData[dwSrcPos + 0] << 8) | (WORD)pSrcData[dwSrcPos + 1], CurCodeSet);
                                        dwSrcPos++;
                                }
                                else{
-                                       // 1¥Ð¥¤¥È¥³¡¼¥É
+                                       // 1バイトコード
                                        dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (WORD)dwSrcData, CurCodeSet);
                                }
                        }
                        else if((dwSrcData >= 0xA1U) && (dwSrcData <= 0xFEU)){
-                               // GRÎΰè
+                               // GR領域
                                const CODE_SET CurCodeSet = *m_pLockingGR;
                                
                                if(abCharSizeTable[CurCodeSet]){
-                                       // 2¥Ð¥¤¥È¥³¡¼¥É
+                                       // 2バイトコード
                                        if((dwSrcLen - dwSrcPos) < 2UL)break;
                                        
                                        dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((WORD)(pSrcData[dwSrcPos + 0] & 0x7FU) << 8) | (WORD)(pSrcData[dwSrcPos + 1] & 0x7FU), CurCodeSet);
                                        dwSrcPos++;
                                }
                                else{
-                                       // 1¥Ð¥¤¥È¥³¡¼¥É
+                                       // 1バイトコード
                                        dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (WORD)(dwSrcData & 0x7FU), CurCodeSet);
                                }
                        }
                        else{
-                               // À©¸æ¥³¡¼¥É
+                               // 制御コード
                                switch(dwSrcData){
                                case 0x0FU      : LockingShiftGL(0U);                           break;  // LS0
                                case 0x0EU      : LockingShiftGL(1U);                           break;  // LS1
                                case 0x19U      : SingleShiftGL(2U);                            break;  // SS2
                                case 0x1DU      : SingleShiftGL(3U);                            break;  // SS3
                                case 0x1BU      : m_byEscSeqCount = 1U;                         break;  // ESC
+                               case 0x89U      : m_emStrSize = STR_MEDIUM;                     break;  // MSZ
+                               case 0x8AU      : m_emStrSize = STR_NORMAL;                     break;  // NSZ
                                case 0x20U      :
-                               case 0xA0U      : lpszDst[dwDstLen++] = TEXT(' ');      break;  // SP
-                               default         : break;        // ÈóÂбþ
+                               case 0xA0U      :
+                                       //SP 空白
+                                       //空白は文字サイズの影響あり
+                                       if( IsSmallCharMode() == false ){
+                                               strcpy(&lpszDst[dwDstLen], " ");
+                                               dwDstLen += 3U;
+                                       } else {
+                                               lpszDst[dwDstLen++] = TEXT(' ');
+                                       }
+                                       break;
+                               default         : break;        // 非対応
                                }
                        }
                }
                else{
-                       // ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹½èÍý
+                       // エスケープシーケンス処理
                        ProcessEscapeSeq(dwSrcData);
                }
                
                dwSrcPos++;
        }
 
-       // ½ªÃ¼Ê¸»ú
+       // 終端文字
        lpszDst[dwDstLen] = TEXT('\0');
-
        return dwDstLen;
 }
 
@@ -189,32 +251,39 @@ const DWORD ProcessCharCode(TCHAR *lpszDst, const WORD wCode, const CODE_SET Cod
        case CODE_KANJI :
        case CODE_JIS_KANJI_PLANE_1 :
        case CODE_JIS_KANJI_PLANE_2 :
-               // ´Á»ú¥³¡¼¥É½ÐÎÏ
+               // 漢字コード出力
                return PutKanjiChar(lpszDst, wCode);
 
        case CODE_ALPHANUMERIC :
        case CODE_PROP_ALPHANUMERIC :
-               // ±Ñ¿ô»ú¥³¡¼¥É½ÐÎÏ
+               // 英数字コード出力
+               if( IsSmallCharMode() == false ){
+                       //全角テーブルコード取得
                return PutAlphanumericChar(lpszDst, wCode);
+               } else {
+                       //半角はそのまま出力
+                       lpszDst[0] = wCode;
+                       return 1UL;
+               }
 
        case CODE_HIRAGANA :
        case CODE_PROP_HIRAGANA :
-               // ¤Ò¤é¤¬¤Ê¥³¡¼¥É½ÐÎÏ
+               // ひらがなコード出力
                return PutHiraganaChar(lpszDst, wCode);
 
        case CODE_PROP_KATAKANA :
        case CODE_KATAKANA :
-               // ¥«¥¿¥«¥Ê¥³¡¼¥É½ÐÎÏ
+               // カタカナコード出力
                return PutKatakanaChar(lpszDst, wCode);
 
        case CODE_JIS_X0201_KATAKANA :
-               // JIS¥«¥¿¥«¥Ê¥³¡¼¥É½ÐÎÏ
+               // JISカタカナコード出力
                return PutJisKatakanaChar(lpszDst, wCode);
-#if 1
+
        case CODE_ADDITIONAL_SYMBOLS :
-               // Äɲå·¥ó¥Ü¥ë¥³¡¼¥É½ÐÎÏ
+               // 追加シンボルコード出力
                return PutSymbolsChar(lpszDst, wCode);
-#endif
+
        default :
                return 0UL;
        }
@@ -222,185 +291,232 @@ const DWORD ProcessCharCode(TCHAR *lpszDst, const WORD wCode, const CODE_SET Cod
 
 const DWORD PutKanjiChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // JIS¢ªShift-JIS´Á»ú¥³¡¼¥ÉÊÑ´¹
-       const WORD wShiftJIS = convertjis(wCode);
+       char code[9];
+       char xcode[5];
+       iconv_t cd;
 
-#ifdef _UNICODE
-       // Shift-JIS ¢ª UNICODE
-       const char szShiftJIS[3] = {(char)(wShiftJIS >> 8), (char)(wShiftJIS & 0x00FFU), '\0'};
-       ::MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, szShiftJIS, 2, lpszDst, 2);
+       size_t inbyte = 8;
+       size_t outbyte = sizeof(xcode);
 
-       return 1UL;
-#else
-       // Shift-JIS ¢ª Shift-JIS
-       lpszDst[0] = (wShiftJIS >> 8) & 0xFF;
-       lpszDst[1] = (char)(wShiftJIS & 0x00FFU);
+       memset(xcode, '\0', sizeof(xcode));
   
-       return 2UL;
-#endif
+       const char *fptr;
+       char *tptr;
+
+       code[0] = 0x1BU;
+       code[1] = 0x24U;
+       code[2] = 0x40U;
+       code[3] = wCode >> 8;
+       code[4] = wCode & 0xFF;
+       code[5] = 0x1BU;
+       code[6] = 0x28U;
+       code[7] = 0x4AU;
+       code[8] = '\0';
+
+       cd = iconv_open("UTF-8","ISO-2022-JP");
+
+       fptr = code;
+       tptr = xcode;
+       iconv(cd, &fptr, &inbyte, &tptr, &outbyte);
+
+       iconv_close(cd);
+
+       strncpy(lpszDst, xcode, strlen(xcode));
+
+       return strlen(lpszDst);
 }
 
 const DWORD PutAlphanumericChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // ±Ñ¿ô»úʸ»ú¥³¡¼¥ÉÊÑ´¹
+       // 英数字全角文字コード変換
        static const TCHAR *acAlphanumericTable = 
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿")
-               TEXT("£°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©")
-               TEXT("¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï")
-               TEXT("£Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡ï¡Ï¡°¡²")
-               TEXT("¡¡£á£â£ã£ä£å£æ£ç£è£é£ì£ë£ì£í£î£ï")
-               TEXT("£ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡±¡¡");
+               TEXT("                ")
+               TEXT("                ")
+               TEXT(" !”#$%&’()*+,-./")
+               TEXT("0123456789:;<=>?")
+               TEXT("@ABCDEFGHIJKLMNO")
+               TEXT("PQRSTUVWXYZ[¥]^_")
+               TEXT(" abcdefghijklmno")
+               TEXT("pqrstuvwxyz{|} ̄ ");
 
 #ifdef _UNICODE
-       lpszDst[0] = acAlphanumericTable[wCode];
+       lpszDst[0] = acAlphanumericTableZenkaku[wCode];
 
        return 1UL;
 #else
-       lpszDst[0] = acAlphanumericTable[wCode * 2U + 0U];
-       lpszDst[1] = acAlphanumericTable[wCode * 2U + 1U];
+       lpszDst[0] = acAlphanumericTable[wCode * 3U + 0U];
+       lpszDst[1] = acAlphanumericTable[wCode * 3U + 1U];
+       lpszDst[2] = acAlphanumericTable[wCode * 3U + 2U];
 
-       return 2UL;
+       return 3UL;
 #endif
 }
 
 const DWORD PutHiraganaChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // ¤Ò¤é¤¬¤Êʸ»ú¥³¡¼¥ÉÊÑ´¹
+       // ひらがな文字コード変換
        static const TCHAR *acHiraganaTable = 
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¤¡¤¢¤£¤¤¤¥¤¦¤§¤¨¤©¤ª¤«¤¬¤­¤®¤¯")
-               TEXT("¤°¤±¤²¤³¤´¤µ¤¶¤·¤¸¤¹¤º¤»¤¼¤½¤¾¤¿")
-               TEXT("¤À¤Á¤Â¤Ã¤Ä¤Å¤Æ¤Ç¤È¤É¤Ê¤Ë¤Ì¤Í¤Î¤Ï")
-               TEXT("¤Ð¤Ñ¤Ò¤Ó¤Ô¤Õ¤Ö¤×¤Ø¤Ù¤Ú¤Û¤Ü¤Ý¤Þ¤ß")
-               TEXT("¤à¤á¤â¤ã¤ä¤å¤æ¤ç¤è¤é¤ê¤ë¤ì¤í¤î¤ï")
-               TEXT("¤ð¤ñ¤ò¤ó¡¡¡¡¡¡¡µ¡¶¡¼¡£¡Ö¡×¡¢¡¦¡¡");
+               TEXT("                ")
+               TEXT("                ")
+               TEXT(" ぁあぃいぅうぇえぉおかがきぎく")
+               TEXT("ぐけげこごさざしじすずせぜそぞた")
+               TEXT("だちぢっつづてでとどなにぬねのは")
+               TEXT("ばぱひびぴふぶぷへべぺほぼぽまみ")
+               TEXT("むめもゃやゅゆょよらりるれろゎわ")
+               TEXT("ゐゑをん   ゝゞー。「」、・ ");
        
 #ifdef _UNICODE
        lpszDst[0] = acHiraganaTable[wCode];
 
        return 1UL;
 #else
-       lpszDst[0] = acHiraganaTable[wCode * 2U + 0U];
-       lpszDst[1] = acHiraganaTable[wCode * 2U + 1U];
+       lpszDst[0] = acHiraganaTable[wCode * 3U + 0U];
+       lpszDst[1] = acHiraganaTable[wCode * 3U + 1U];
+       lpszDst[2] = acHiraganaTable[wCode * 3U + 2U];
 
-       return 2UL;
+       return 3UL;
 #endif
 }
 
 const DWORD PutKatakanaChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // ¥«¥¿¥«¥Ê±Ñ¿ô»úʸ»ú¥³¡¼¥ÉÊÑ´¹
+       // カタカナ英数字文字コード変換
        static const TCHAR *acKatakanaTable = 
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¥¡¥¢¥£¥¤¥¥¥¦¥§¥¨¥©¥ª¥«¥¬¥­¥®¥¯")
-               TEXT("¥°¥±¥²¥³¥´¥µ¥¶¥·¥¸¥¹¥º¥»¥¼¥½¥¾¥¿")
-               TEXT("¥À¥Á¥Â¥Ã¥Ä¥Å¥Æ¥Ç¥È¥É¥Ê¥Ë¥Ì¥Í¥Î¥Ï")
-               TEXT("¥Ð¥Ñ¥Ò¥Ó¥Ô¥Õ¥Ö¥×¥Ø¥Ù¥Ú¥Û¥Ü¥Ý¥Þ¥ß")
-               TEXT("¥à¥á¥â¥ã¥ä¥å¥æ¥ç¥è¥é¥ê¥ë¥ì¥í¥î¥ï")
-               TEXT("¥ð¥ñ¥ò¥ó¥ô¥õ¥ö¡³¡´¡¼¡£¡Ö¡×¡¢¡¦¡¡");
+               TEXT("                ")
+               TEXT("                ")
+               TEXT("ã\80\80ã\82¡ã\82¢ã\82£ã\82¤ã\82¥ã\82¦ã\82§ã\82¨ã\82©ã\82ªã\82«ã\82¬ã\82­ã\82®ã\82¯")
+               TEXT("ã\82°ã\82±ã\82²ã\82³ã\82´ã\82µã\82¶ã\82·ã\82¸ã\82¹ã\82ºã\82»ã\82¼ã\82½ã\82¾ã\82¿")
+               TEXT("ダチヂッツヅテデトドナニヌネノハ")
+               TEXT("バパヒビピフブプヘベペホボポマミ")
+               TEXT("ムメモャヤュユョヨラリルレロヮワ")
+               TEXT("ヰヱヲンヴヵヶヽヾー。「」、・ ");
        
 #ifdef _UNICODE
        lpszDst[0] = acKatakanaTable[wCode];
 
        return 1UL;
 #else
-       lpszDst[0] = acKatakanaTable[wCode * 2U + 0U];
-       lpszDst[1] = acKatakanaTable[wCode * 2U + 1U];
+       lpszDst[0] = acKatakanaTable[wCode * 3U + 0U];
+       lpszDst[1] = acKatakanaTable[wCode * 3U + 1U];
+       lpszDst[2] = acKatakanaTable[wCode * 3U + 2U];
 
-       return 2UL;
+       return 3UL;
 #endif
 }
 
 const DWORD PutJisKatakanaChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // JIS¥«¥¿¥«¥Êʸ»ú¥³¡¼¥ÉÊÑ´¹
+       // JISカタカナ文字コード変換
        static const TCHAR *acJisKatakanaTable = 
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡£¡Ö¡×¡¢¡¦¥ò¥¡¥£¥¥¥§¥©¥ã¥å¥ç¥Ã")
-               TEXT("¡¼¥¢¥¤¥¦¥¨¥ª¥«¥­¥¯¥±¥³¥µ¥·¥¹¥»¥½")
-               TEXT("¥¿¥Á¥Ä¥Æ¥È¥Ê¥Ë¥Ì¥Í¥Î¥Ï¥Ò¥Õ¥Ø¥Û¥Þ")
-               TEXT("¥ß¥à¥á¥â¥ä¥æ¥è¥é¥ê¥ë¥ì¥í¥ï¥ó¡«¡¬")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡")
-               TEXT("¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡");
+               TEXT("                ")
+               TEXT("                ")
+               TEXT(" 。「」、・ヲァィゥェォャュョッ")
+               TEXT("ã\83¼ã\82¢ã\82¤ã\82¦ã\82¨ã\82ªã\82«ã\82­ã\82¯ã\82±ã\82³ã\82µã\82·ã\82¹ã\82»ã\82½")
+               TEXT("タチツテトナニヌネノハヒフヘホマ")
+               TEXT("ミムメモヤユヨラリルレロワン゛゜")
+               TEXT("                ")
+               TEXT("                ");
        
 #ifdef _UNICODE
        lpszDst[0] = acJisKatakanaTable[wCode];
 
        return 1UL;
 #else
-       lpszDst[0] = acJisKatakanaTable[wCode * 2U + 0U];
-       lpszDst[1] = acJisKatakanaTable[wCode * 2U + 1U];
+       lpszDst[0] = acJisKatakanaTable[wCode * 3U + 0U];
+       lpszDst[1] = acJisKatakanaTable[wCode * 3U + 1U];
+       lpszDst[2] = acJisKatakanaTable[wCode * 3U + 2U];
 
-       return 2UL;
+       return 3UL;
 #endif
 }
 
 const DWORD PutSymbolsChar(TCHAR *lpszDst, const WORD wCode)
 {
-       // Äɲå·¥ó¥Ü¥ëʸ»ú¥³¡¼¥ÉÊÑ´¹(¤È¤ê¤¢¤¨¤ºÉ¬Íפ½¤¦¤Ê¤â¤Î¤À¤±)
+       // 追加シンボル文字コード変換(とりあえず必要そうなものだけ)
        static const TCHAR *aszSymbolsTable1[] =
                {
-                       _T("[HV]"),             _T("[SD]"),             _T("[£Ð]"),             _T("[£×]"),             _T("[MV]"),             _T("[¼ê]"),             _T("[»ú]"),             _T("[ÁÐ]"),                     // 0x7A50 - 0x7A57      90/48 - 90/55
-                       _T("[¥Ç]"),             _T("[£Ó]"),             _T("[Æó]"),             _T("[¿]"),             _T("[²ò]"),             _T("[SS]"),             _T("[£Â]"),             _T("[£Î]"),                     // 0x7A58 - 0x7A5F      90/56 - 90/63
-                       _T("¢£"),               _T("¡ü"),               _T("[Å·]"),             _T("[¸ò]"),             _T("[±Ç]"),             _T("[̵]"),             _T("[ÎÁ]"),             _T("[ǯÎðÀ©¸Â]"),       // 0x7A60 - 0x7A67      90/64 - 90/71
-                       _T("[Á°]"),             _T("[¸å]"),             _T("[ºÆ]"),             _T("[¿·]"),             _T("[½é]"),             _T("[½ª]"),             _T("[À¸]"),             _T("[ÈÎ]"),                     // 0x7A68 - 0x7A6F      90/72 - 90/79
-                       _T("[À¼]"),             _T("[¿á]"),             _T("[PPV]"),    _T("(Èë)"),             _T("¤Û¤«")                                                                                                                      // 0x7A70 - 0x7A74      90/80 - 90/84
+                       _T("[HV]"),             _T("[SD]"),             _T("[P]"),            _T("[W]"),            _T("[MV]"),             _T("[手]"),            _T("[字]"),            _T("[双]"),                    // 0x7A50 - 0x7A57      90/48 - 90/55
+                       _T("[デ]"),            _T("[S]"),            _T("[二]"),            _T("[多]"),            _T("[解]"),            _T("[SS]"),             _T("[B]"),            _T("[N]"),                    // 0x7A58 - 0x7A5F      90/56 - 90/63
+                       _T("■"),              _T("●"),              _T("[天]"),            _T("[交]"),            _T("[映]"),            _T("[無]"),            _T("[料]"),            _T("[年齢制限]"),   // 0x7A60 - 0x7A67      90/64 - 90/71
+                       _T("[前]"),            _T("[後]"),            _T("[再]"),            _T("[新]"),            _T("[初]"),            _T("[終]"),            _T("[生]"),            _T("[販]"),                    // 0x7A68 - 0x7A6F      90/72 - 90/79
+                       _T("[声]"),            _T("[吹]"),            _T("[PPV]"),    _T("(秘)"),            _T("ほか")                                                                                                                    // 0x7A70 - 0x7A74      90/80 - 90/84
                };
 
        static const TCHAR *aszSymbolsTable2[] =
                {
-                       _T("¢ª"),               _T("¢«"),               _T("¢¬"),               _T("¢­"),               _T("¡ü"),               _T("¡û"),               _T("ǯ"),               _T("·î"),                       // 0x7C21 - 0x7C28      92/01 - 92/08
-                       _T("Æü"),               _T("±ß"),               _T("­Ö"),               _T("ΩÊý£í"),   _T("­Ñ"),               _T("Ê¿Êý­Ñ"),   _T("ΩÊý­Ñ"),   _T("£°."),                      // 0x7C29 - 0x7C30      92/09 - 92/16
-                       _T("£±."),              _T("£²."),              _T("£³."),              _T("£´."),              _T("£µ."),              _T("£¶."),              _T("£·."),              _T("£¸."),                      // 0x7C31 - 0x7C38      92/17 - 92/24
-                       _T("£¹."),              _T("»á"),               _T("Éû"),               _T("¸µ"),               _T("¸Î"),               _T("Á°"),               _T("¿·"),               _T("£°,"),                      // 0x7C39 - 0x7C40      92/25 - 92/32
-                       _T("£±,"),              _T("£²,"),              _T("£³,"),              _T("£´,"),              _T("£µ,"),              _T("£¶,"),              _T("£·,"),              _T("£¸,"),                      // 0x7C41 - 0x7C48      92/33 - 92/40
-                       _T("£¹,"),              _T("(¼Ò)"),             _T("(ºâ)"),             _T("(Í­)"),             _T("(³ô)"),             _T("(Âå)"),             _T("(Ìä)"),             _T("¡ä"),                       // 0x7C49 - 0x7C50      92/41 - 92/48
-                       _T("¡ã"),               _T("¡Ú"),               _T("¡Û"),               _T("¡þ"),               _T("^2"),               _T("^3"),               _T("(CD)"),             _T("(vn)"),                     // 0x7C51 - 0x7C58      92/49 - 92/56
+                       _T("→"),              _T("←"),              _T("↑"),              _T("↓"),              _T("●"),              _T("○"),              _T("年"),              _T("月"),                      // 0x7C21 - 0x7C28      92/01 - 92/08
+                       _T("日"),              _T("円"),              _T("㎡"),              _T("㎥"),              _T("㎝"),              _T("㎠"),              _T("㎤"),              _T("0."),                     // 0x7C29 - 0x7C30      92/09 - 92/16
+                       _T("1."),             _T("2."),             _T("3."),             _T("4."),             _T("5."),             _T("6."),             _T("7."),             _T("8."),                     // 0x7C31 - 0x7C38      92/17 - 92/24
+                       _T("9."),             _T("氏"),              _T("副"),              _T("元"),              _T("故"),              _T("前"),              _T("新"),              _T("0,"),                     // 0x7C39 - 0x7C40      92/25 - 92/32
+                       _T("1,"),             _T("2,"),             _T("3,"),             _T("4,"),             _T("5,"),             _T("6,"),             _T("7,"),             _T("8,"),                     // 0x7C41 - 0x7C48      92/33 - 92/40
+                       _T("9,"),             _T("(社)"),            _T("(財)"),            _T("(有)"),            _T("(株)"),            _T("(代)"),            _T("(問)"),            _T("▶"),                      // 0x7C49 - 0x7C50      92/41 - 92/48
+                       _T("◀"),              _T("〖"),              _T("〗"),              _T("⟐"),              _T("^2"),               _T("^3"),               _T("(CD)"),             _T("(vn)"),                     // 0x7C51 - 0x7C58      92/49 - 92/56
                        _T("(ob)"),             _T("(cb)"),             _T("(ce"),              _T("mb)"),              _T("(hp)"),             _T("(br)"),             _T("(p)"),              _T("(s)"),                      // 0x7C59 - 0x7C60      92/57 - 92/64
                        _T("(ms)"),             _T("(t)"),              _T("(bs)"),             _T("(b)"),              _T("(tb)"),             _T("(tp)"),             _T("(ds)"),             _T("(ag)"),                     // 0x7C61 - 0x7C68      92/65 - 92/72
                        _T("(eg)"),             _T("(vo)"),             _T("(fl)"),             _T("(ke"),              _T("y)"),               _T("(sa"),              _T("x)"),               _T("(sy"),                      // 0x7C69 - 0x7C70      92/73 - 92/80
-                       _T("n)"),               _T("(or"),              _T("g)"),               _T("(pe"),              _T("r)"),               _T("(R)"),              _T("(C)"),              _T("(ä·)"),                     // 0x7C71 - 0x7C78      92/81 - 92/88
-                       _T("DJ"),               _T("[±é]"),             _T("Fax")                                                                                                                                                                                       // 0x7C79 - 0x7C7B      92/89 - 92/91
+                       _T("n)"),               _T("(or"),              _T("g)"),               _T("(pe"),              _T("r)"),               _T("(R)"),              _T("(C)"),              _T("(箏)"),                    // 0x7C71 - 0x7C78      92/81 - 92/88
+                       _T("DJ"),               _T("[演]"),            _T("Fax")                                                                                                                                                                                       // 0x7C79 - 0x7C7B      92/89 - 92/91
                };
 
        static const TCHAR *aszSymbolsTable3[] =
                {
-                       _T("(·î)"),             _T("(²Ð)"),             _T("(¿å)"),             _T("(ÌÚ)"),             _T("(¶â)"),             _T("(ÅÚ)"),             _T("(Æü)"),             _T("(½Ë)"),                     // 0x7D21 - 0x7D28      93/01 - 93/08
-                       _T("­í"),               _T("­î"),               _T("­ï"),               _T("­ß"),               _T("­â"),               _T("­ä"),               _T("(¢©)"),             _T("¡û"),                       // 0x7D29 - 0x7D30      93/09 - 93/16
-                       _T("¡ÌËÜ¡Í"),   _T("¡Ì»°¡Í"),   _T("¡ÌÆó¡Í"),   _T("¡Ì°Â¡Í"),   _T("¡ÌÅÀ¡Í"),   _T("¡ÌÂÇ¡Í"),   _T("¡ÌÅð¡Í"),   _T("¡Ì¾¡¡Í"),           // 0x7D31 - 0x7D38      93/17 - 93/24
-                       _T("¡ÌÇÔ¡Í"),   _T("¡Ì£Ó¡Í"),   _T("¡ÎÅê¡Ï"),   _T("¡ÎÊá¡Ï"),   _T("¡Î°ì¡Ï"),   _T("¡ÎÆó¡Ï"),   _T("¡Î»°¡Ï"),   _T("¡ÎÍ·¡Ï"),           // 0x7D39 - 0x7D40      93/25 - 93/32
-                       _T("¡Îº¸¡Ï"),   _T("¡ÎÃæ¡Ï"),   _T("¡Î±¦¡Ï"),   _T("¡Î»Ø¡Ï"),   _T("¡ÎÁö¡Ï"),   _T("¡ÎÂÇ¡Ï"),   _T("­È"),               _T("­Ô"),                       // 0x7D41 - 0x7D48      93/33 - 93/40
-                       _T("Hz"),               _T("ha"),               _T("km"),               _T("Ê¿Êýkm"),   _T("hPa"),              _T("¡¦"),               _T("¡¦"),               _T("1/2"),                      // 0x7D49 - 0x7D50      93/41 - 93/48
+                       _T("㈪"),              _T("㈫"),              _T("㈬"),              _T("㈭"),              _T("㈮"),              _T("㈯"),              _T("㈰"),              _T("㈷"),                      // 0x7D21 - 0x7D28      93/01 - 93/08
+                       _T("㍾"),              _T("㍽"),              _T("㍼"),              _T("㍻"),              _T("№"),              _T("℡"),              _T("〶"),              _T("○"),                      // 0x7D29 - 0x7D30      93/09 - 93/16
+                       _T("〔本〕"),        _T("〔三〕"),        _T("〔二〕"),        _T("〔安〕"),        _T("〔点〕"),        _T("〔打〕"),        _T("〔盗〕"),        _T("〔勝〕"),                // 0x7D31 - 0x7D38      93/17 - 93/24
+                       _T("〔敗〕"),        _T("〔S〕"),        _T("[投]"),        _T("[捕]"),        _T("[一]"),        _T("[二]"),        _T("[三]"),        _T("[遊]"),                // 0x7D39 - 0x7D40      93/25 - 93/32
+                       _T("[左]"),        _T("[中]"),        _T("[右]"),        _T("[指]"),        _T("[走]"),        _T("[打]"),        _T("㍑"),              _T("㎏"),                      // 0x7D41 - 0x7D48      93/33 - 93/40
+                       _T("㎐"),              _T("ha"),               _T("㎞"),              _T("㎢"),              _T("㍱"),              _T("・"),              _T("・"),              _T("1/2"),                      // 0x7D49 - 0x7D50      93/41 - 93/48
                        _T("0/3"),              _T("1/3"),              _T("2/3"),              _T("1/4"),              _T("3/4"),              _T("1/5"),              _T("2/5"),              _T("3/5"),                      // 0x7D51 - 0x7D58      93/49 - 93/56
-                       _T("4/5"),              _T("1/6"),              _T("5/6"),              _T("1/7"),              _T("1/8"),              _T("1/9"),              _T("1/10"),             _T("À²¤ì"),                     // 0x7D59 - 0x7D60      93/57 - 93/64
-                       _T("ÆÞ¤ê"),             _T("±«"),               _T("Àã"),               _T("¢¤"),               _T("¢¥"),               _T("¢¦"),               _T("¢§"),               _T("¢¡"),                       // 0x7D61 - 0x7D68      93/65 - 93/72
-                       _T("¡¦"),               _T("¡¦"),               _T("¡¦"),               _T("¡þ"),               _T("¡ý"),               _T("!!"),               _T("!?"),               _T("ÆÞ/À²"),            // 0x7D69 - 0x7D70      93/73 - 93/80
-                       _T("±«"),               _T("±«"),               _T("Àã"),               _T("ÂçÀã"),             _T("Íë"),               _T("Í뱫"),             _T("¡¡"),               _T("¡¦"),                       // 0x7D71 - 0x7D78      93/81 - 93/88
-                       _T("¡¦"),               _T("¢ö"),               _T("­ä")                                                                                                                                                                                        // 0x7D79 - 0x7D7B      93/89 - 93/91
+                       _T("4/5"),              _T("1/6"),              _T("5/6"),              _T("1/7"),              _T("1/8"),              _T("1/9"),              _T("1/10"),             _T("☀"),                      // 0x7D59 - 0x7D60      93/57 - 93/64
+                       _T("☁"),              _T("☂"),              _T("☃"),              _T("☖"),              _T("☗"),              _T("▽"),              _T("▼"),              _T("♦"),                      // 0x7D61 - 0x7D68      93/65 - 93/72
+                       _T("♥"),              _T("♣"),              _T("♠"),              _T("⌺"),              _T("⦿"),              _T("‼"),              _T("⁉"),              _T("(曇/晴)"),                // 0x7D69 - 0x7D70      93/73 - 93/80
+                       _T("☔"),              _T("(雨)"),            _T("(雪)"),            _T("(大雪)"), _T("⚡"),              _T("(雷雨)"), _T(" "),              _T("・"),                      // 0x7D71 - 0x7D78      93/81 - 93/88
+                       _T("・"),              _T("♬"),              _T("☎")                                                                                                                                                                                       // 0x7D79 - 0x7D7B      93/89 - 93/91
                };
 
        static const TCHAR *aszSymbolsTable4[] =
                {
-                       _T("­µ"),               _T("­¶"),               _T("­·"),               _T("­¸"),               _T("­¹"),               _T("­º"),               _T("­»"),               _T("­¼"),                       // 0x7E21 - 0x7E28      94/01 - 94/08
-                       _T("­½"),               _T("­¾"),               _T("XI"),               _T("X­¶"),              _T("­±"),               _T("­²"),               _T("­³"),               _T("­´"),                       // 0x7E29 - 0x7E30      94/09 - 94/16
-                       _T("(1)"),              _T("(2)"),              _T("(3)"),              _T("(4)"),              _T("(5)"),              _T("(6)"),              _T("(7)"),              _T("(8)"),                      // 0x7E31 - 0x7E38      94/17 - 94/24
-                       _T("(9)"),              _T("(10)"),             _T("(11)"),             _T("(12)"),             _T("(21)"),             _T("(22)"),             _T("(23)"),             _T("(24)"),                     // 0x7E39 - 0x7E40      94/25 - 94/32
+                       _T("Ⅰ"),              _T("Ⅱ"),              _T("Ⅲ"),              _T("Ⅳ"),              _T("Ⅴ"),              _T("Ⅵ"),              _T("Ⅶ"),              _T("Ⅷ"),                      // 0x7E21 - 0x7E28      94/01 - 94/08
+                       _T("Ⅸ"),              _T("Ⅹ"),              _T("Ⅺ"),              _T("Ⅻ"),              _T("⑰"),              _T("⑱"),              _T("⑲"),              _T("⑳"),                      // 0x7E29 - 0x7E30      94/09 - 94/16
+                       _T("⑴"),              _T("⑵"),              _T("⑶"),              _T("⑷"),              _T("⑸"),              _T("⑹"),              _T("⑺"),              _T("⑻"),                      // 0x7E31 - 0x7E38      94/17 - 94/24
+                       _T("⑼"),              _T("⑽"),              _T("⑾"),              _T("⑿"),              _T("㉑"),              _T("㉒"),              _T("㉓"),              _T("㉔"),                      // 0x7E39 - 0x7E40      94/25 - 94/32
                        _T("(A)"),              _T("(B)"),              _T("(C)"),              _T("(D)"),              _T("(E)"),              _T("(F)"),              _T("(G)"),              _T("(H)"),                      // 0x7E41 - 0x7E48      94/33 - 94/40
                        _T("(I)"),              _T("(J)"),              _T("(K)"),              _T("(L)"),              _T("(M)"),              _T("(N)"),              _T("(O)"),              _T("(P)"),                      // 0x7E49 - 0x7E50      94/41 - 94/48
                        _T("(Q)"),              _T("(R)"),              _T("(S)"),              _T("(T)"),              _T("(U)"),              _T("(V)"),              _T("(W)"),              _T("(X)"),                      // 0x7E51 - 0x7E58      94/49 - 94/56
-                       _T("(Y)"),              _T("(Z)"),              _T("(25)"),             _T("(26)"),             _T("(27)"),             _T("(28)"),             _T("(29)"),             _T("(30)"),                     // 0x7E59 - 0x7E60      94/57 - 94/64
-                       _T("­¡"),               _T("­¢"),               _T("­£"),               _T("­¤"),               _T("­¥"),               _T("­¦"),               _T("­§"),               _T("­¨"),                       // 0x7E61 - 0x7E68      94/65 - 94/72
-                       _T("­©"),               _T("­ª"),               _T("­«"),               _T("­¬"),               _T("­­"),               _T("­®"),               _T("­¯"),               _T("­°"),                       // 0x7E69 - 0x7E70      94/73 - 94/80
-                       _T("­¡"),               _T("­¢"),               _T("­£"),               _T("­¤"),               _T("­¥"),               _T("­¦"),               _T("­§"),               _T("­¨"),                       // 0x7E71 - 0x7E78      94/81 - 94/88
-                       _T("­©"),               _T("­ª"),               _T("­«"),               _T("­¬"),               _T("(31)")                                                                                                                      // 0x7E79 - 0x7E7D      94/89 - 94/93
+                       _T("(Y)"),              _T("(Z)"),              _T("㉕"),              _T("㉖"),              _T("㉗"),              _T("㉘"),              _T("㉙"),              _T("㉚"),                      // 0x7E59 - 0x7E60      94/57 - 94/64
+                       _T("①"),              _T("②"),              _T("③"),              _T("④"),              _T("⑤"),              _T("⑥"),              _T("⑦"),              _T("⑧"),                      // 0x7E61 - 0x7E68      94/65 - 94/72
+                       _T("⑨"),              _T("⑩"),              _T("⑪"),              _T("⑫"),              _T("⑬"),              _T("⑭"),              _T("⑮"),              _T("⑯"),                      // 0x7E69 - 0x7E70      94/73 - 94/80
+                       _T("❶"),              _T("❷"),              _T("❸"),              _T("❹"),              _T("❺"),              _T("❻"),              _T("❼"),              _T("❽"),                      // 0x7E71 - 0x7E78      94/81 - 94/88
+                       _T("❾"),              _T("❿"),              _T("⓫"),              _T("⓬"),              _T("㉛")                                                                                                                       // 0x7E79 - 0x7E7D      94/89 - 94/93
                };
 
-       // ¥·¥ó¥Ü¥ë¤òÊÑ´¹¤¹¤ë
+       static const TCHAR *aszSymbolsTable5[] =
+               {
+                       _T("㐂"),              _T("亭"),              _T("份"),              _T("仿"),              _T("侚"),              _T("俉"),              _T("傜"),              _T("儞"),                      // 0x7521 - 0x7528      85/01 - 85/08
+                       _T("冼"),              _T("㔟"),              _T("匇"),              _T("卡"),              _T("卬"),              _T("詹"),              _T("吉"),              _T("呍"),                      // 0x7529 - 0x7530      85/09 - 85/16
+                       _T("咖"),              _T("咜"),              _T("咩"),              _T("唎"),              _T("啊"),              _T("噲"),              _T("囤"),              _T("圳"),                      // 0x7531 - 0x7538      85/17 - 85/24
+                       _T("圴"),              _T("塚"),              _T("墀"),              _T("姤"),              _T("娣"),              _T("婕"),              _T("寬"),              _T("﨑"),                      // 0x7539 - 0x7540      85/25 - 85/32
+                       _T("㟢"),              _T("庬"),              _T("弴"),              _T("彅"),              _T("德"),              _T("怗"),              _T("恵"),              _T("愰"),                      // 0x7541 - 0x7548      85/33 - 85/40
+                       _T("昤"),              _T("曈"),              _T("曙"),              _T("曺"),              _T("曻"),              _T("桒"),              _T("・"),              _T("椑"),                      // 0x7549 - 0x7550      85/41 - 85/48
+                       _T("椻"),              _T("橅"),              _T("檑"),              _T("櫛"),              _T("・"),              _T("・"),              _T("・"),              _T("毱"),                      // 0x7551 - 0x7558      85/49 - 85/56
+                       _T("泠"),              _T("洮"),              _T("海"),              _T("涿"),              _T("淊"),              _T("淸"),              _T("渚"),              _T("潞"),                      // 0x7559 - 0x7560      85/57 - 85/64
+                       _T("濹"),              _T("灤"),              _T("・"),              _T("・"),              _T("煇"),              _T("燁"),              _T("爀"),              _T("玟"),                      // 0x7561 - 0x7568      85/65 - 85/72
+                       _T("・"),              _T("珉"),              _T("珖"),              _T("琛"),              _T("琡"),              _T("琢"),              _T("琦"),              _T("琪"),                      // 0x7569 - 0x7570      85/73 - 85/80
+                       _T("琬"),              _T("琹"),              _T("瑋"),              _T("㻚"),              _T("畵"),              _T("疁"),              _T("睲"),              _T("䂓"),                      // 0x7571 - 0x7578      85/81 - 85/88
+                       _T("磈"),              _T("磠"),              _T("祇"),              _T("禮"),              _T("・"),              _T("・")                                                                                       // 0x7579 - 0x757E      85/89 - 85/94
+               };
+
+       static const TCHAR *aszSymbolsTable6[] =
+               {
+                       _T("・"),              _T("秚"),              _T("稞"),              _T("筿"),              _T("簱"),              _T("䉤"),              _T("綋"),              _T("羡"),                      // 0x7621 - 0x7628      86/01 - 86/08
+                       _T("脘"),              _T("脺"),              _T("・"),              _T("芮"),              _T("葛"),              _T("蓜"),              _T("蓬"),              _T("蕙"),                      // 0x7629 - 0x7630      86/09 - 86/16
+                       _T("藎"),              _T("蝕"),              _T("蟬"),              _T("蠋"),              _T("裵"),              _T("角"),              _T("諶"),              _T("跎"),                      // 0x7631 - 0x7638      86/17 - 86/24
+                       _T("辻"),              _T("迶"),              _T("郝"),              _T("鄧"),              _T("鄭"),              _T("醲"),              _T("鈳"),              _T("銈"),                      // 0x7639 - 0x7640      86/25 - 86/32
+                       _T("錡"),              _T("鍈"),              _T("閒"),              _T("雞"),              _T("餃"),              _T("饀"),              _T("髙"),              _T("鯖"),                      // 0x7641 - 0x7648      86/33 - 86/40
+                       _T("鷗"),              _T("麴"),              _T("麵")                                                                                                                                                                                       // 0x7649 - 0x764B      86/41 - 86/43
+               };
+
+       // シンボルを変換する
        if((wCode >= 0x7A50U) && (wCode <= 0x7A74U)){
                strcpy(lpszDst, aszSymbolsTable1[wCode - 0x7A50U]);
        }
@@ -413,8 +529,14 @@ const DWORD PutSymbolsChar(TCHAR *lpszDst, const WORD wCode)
        else if((wCode >= 0x7E21U) && (wCode <= 0x7E7DU)){
                strcpy(lpszDst, aszSymbolsTable4[wCode - 0x7E21U]);
        }
+       else if((wCode >= 0x7521U) && (wCode <= 0x757EU)){
+               strcpy(lpszDst, aszSymbolsTable5[wCode - 0x7521U]);
+       }
+       else if((wCode >= 0x7621U) && (wCode <= 0x764BU)){
+               strcpy(lpszDst, aszSymbolsTable6[wCode - 0x7621U]);
+       }
        else{
-               strcpy(lpszDst, TEXT("¡¦"));
+               strcpy(lpszDst, TEXT(""));
        }
 
        return strlen(lpszDst);
@@ -422,9 +544,9 @@ const DWORD PutSymbolsChar(TCHAR *lpszDst, const WORD wCode)
 
 void ProcessEscapeSeq(const BYTE byCode)
 {
-       // ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹½èÍý
+       // エスケープシーケンス処理
        switch(m_byEscSeqCount){
-               // 1¥Ð¥¤¥ÈÌÜ
+               // 1バイト目
        case 1U :
                switch(byCode){
                        // Invocation of code elements
@@ -440,11 +562,11 @@ void ProcessEscapeSeq(const BYTE byCode)
                case 0x29U      : m_byEscSeqIndex = 1U;         break;
                case 0x2AU      : m_byEscSeqIndex = 2U;         break;
                case 0x2BU      : m_byEscSeqIndex = 3U;         break;
-               default         : m_byEscSeqCount = 0U;         return;         // ¥¨¥é¡¼
+               default         : m_byEscSeqCount = 0U;         return;         // ã\82¨ã\83©ã\83¼
                }
                break;
 
-               // 2¥Ð¥¤¥ÈÌÜ
+               // 2バイト目
        case 2U :
                if(DesignationGSET(m_byEscSeqIndex, byCode)){
                        m_byEscSeqCount = 0U;
@@ -457,11 +579,11 @@ void ProcessEscapeSeq(const BYTE byCode)
                case 0x29       : m_bIsEscSeqDrcs = false;      m_byEscSeqIndex = 1U;   break;
                case 0x2A       : m_bIsEscSeqDrcs = false;      m_byEscSeqIndex = 2U;   break;
                case 0x2B       : m_bIsEscSeqDrcs = false;      m_byEscSeqIndex = 3U;   break;
-               default         : m_byEscSeqCount = 0U;         return;         // ¥¨¥é¡¼
+               default         : m_byEscSeqCount = 0U;         return;         // ã\82¨ã\83©ã\83¼
                }
                break;
 
-               // 3¥Ð¥¤¥ÈÌÜ
+               // 3バイト目
        case 3U :
                if(!m_bIsEscSeqDrcs){
                        if(DesignationGSET(m_byEscSeqIndex, byCode)){
@@ -480,13 +602,13 @@ void ProcessEscapeSeq(const BYTE byCode)
                        m_bIsEscSeqDrcs = true;
                }
                else{
-                       // ¥¨¥é¡¼
+                       // ã\82¨ã\83©ã\83¼
                        m_byEscSeqCount = 0U;
                        return;
                }
                break;
 
-               // 4¥Ð¥¤¥ÈÌÜ
+               // 4バイト目
        case 4U :
                DesignationDRCS(m_byEscSeqIndex, byCode);
                m_byEscSeqCount = 0U;
@@ -516,7 +638,7 @@ void SingleShiftGL(const BYTE byIndexG)
 
 const bool DesignationGSET(const BYTE byIndexG, const BYTE byCode)
 {
-       // G¤Î¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È¤ò³ä¤êÅö¤Æ¤ë
+       // Gのグラフィックセットを割り当てる
        switch(byCode){
        case 0x42U      : m_CodeG[byIndexG] = CODE_KANJI;                               return true;    // Kanji
        case 0x4AU      : m_CodeG[byIndexG] = CODE_ALPHANUMERIC;                return true;    // Alphanumeric
@@ -533,13 +655,13 @@ const bool DesignationGSET(const BYTE byIndexG, const BYTE byCode)
        case 0x39U      : m_CodeG[byIndexG] = CODE_JIS_KANJI_PLANE_1;   return true;    // JIS compatible Kanji Plane 1
        case 0x3AU      : m_CodeG[byIndexG] = CODE_JIS_KANJI_PLANE_2;   return true;    // JIS compatible Kanji Plane 2
        case 0x3BU      : m_CodeG[byIndexG] = CODE_ADDITIONAL_SYMBOLS;  return true;    // Additional symbols
-       default         : return false;         // ÉÔÌÀ¤Ê¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È
+       default         : return false;         // 不明なグラフィックセット
        }
 }
 
 const bool DesignationDRCS(const BYTE byIndexG, const BYTE byCode)
 {
-       // DRCS¤Î¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È¤ò³ä¤êÅö¤Æ¤ë
+       // DRCSのグラフィックセットを割り当てる
        switch(byCode){
        case 0x40U      : m_CodeG[byIndexG] = CODE_UNKNOWN;                             return true;    // DRCS-0
        case 0x41U      : m_CodeG[byIndexG] = CODE_UNKNOWN;                             return true;    // DRCS-1
@@ -558,42 +680,6 @@ const bool DesignationDRCS(const BYTE byIndexG, const BYTE byCode)
        case 0x4EU      : m_CodeG[byIndexG] = CODE_UNKNOWN;                             return true;    // DRCS-14
        case 0x4FU      : m_CodeG[byIndexG] = CODE_UNKNOWN;                             return true;    // DRCS-15
        case 0x70U      : m_CodeG[byIndexG] = CODE_UNKNOWN;                             return true;    // Macro
-       default         : return false;         // ÉÔÌÀ¤Ê¥°¥é¥Õ¥£¥Ã¥¯¥»¥Ã¥È
-       }
+       default         : return false;         // 不明なグラフィックセット
 }
-
-WORD convertjis(DWORD jiscode) {
-       char code[3];
-       char xcode[4];
-       iconv_t cd;
-  
-       size_t inbyte = 2;
-       size_t outbyte = 4;
-
-       const char *fptr;
-       char *tptr;
-
-       WORD rtn;
-
-       code[0] = jiscode >> 8;
-       code[1] = jiscode & 0xFF;
-       code[3] = '\0';
-
-       /*
-         cd = iconv_open("ISO-2022-JP","UTF-8");
-
-         fptr = code;
-         tptr = xcode;
-         iconv(cd, &fptr, &inbyte, &tptr, &outbyte);
-
-         iconv_close(cd);
-       */
-
-       xcode[0] = code[0] | 0x80;
-       xcode[1] = code[1] | 0x80;
-
-       rtn = ((xcode[0] << 8) & 0xFF00) | (xcode[1] & 0xFF);
-
-       return rtn;
-
 }
diff --git a/epgdump/cdt.c b/epgdump/cdt.c
new file mode 100644 (file)
index 0000000..a55acbd
--- /dev/null
@@ -0,0 +1,131 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cdt.h"
+#include "ts_ctl.h"
+#include "clt2png.h"
+
+int parseCDThead(unsigned char *data, CDThead *h) {
+       int boff = 0;
+
+       memset(h, 0, sizeof(CDThead));
+
+       h->table_id = getBit(data, &boff, 8);
+       h->section_syntax_indicator = getBit(data, &boff, 1);
+       h->reserved_future_use1 = getBit(data, &boff, 1);
+       h->reserved1 = getBit(data, &boff, 2);
+       h->section_length = getBit(data, &boff, 12);
+       h->download_data_id = getBit(data, &boff, 16);
+       h->reserved2 = getBit(data, &boff, 2);
+       h->version_number = getBit(data, &boff, 5);
+       h->current_next_indicator = getBit(data, &boff, 1);
+       h->section_number = getBit(data, &boff, 8);
+       h->last_section_number = getBit(data, &boff, 8);
+       h->original_network_id = getBit(data, &boff, 16);
+       h->data_type = getBit(data, &boff, 8);
+       h->reserved_future_use2 = getBit(data, &boff, 4);
+       h->descriptors_loop_length = getBit(data, &boff, 12);
+
+       return 13;
+}
+
+int parseCDTdesc(unsigned char *data, CDTdesc *desc) {
+// ほとんど呼ばれることはない
+       int boff = 0;
+
+       memset(desc, 0, sizeof(CDTdesc));
+
+       desc->descriptor_tag = getBit(data, &boff, 8);
+       desc->descriptor_length = getBit(data, &boff, 8);
+
+       return desc->descriptor_length + 2;
+}
+
+int parseCDTdata(unsigned char *data, CDTdata *cdtd) {
+       int boff = 0;
+
+       memset(cdtd, 0, sizeof(CDTdata));
+
+       cdtd->logo_type = getBit(data, &boff, 8);
+       cdtd->reserved_future_use1 = getBit(data, &boff, 7);
+       cdtd->logo_id = getBit(data, &boff, 9);
+       cdtd->reserved_future_use2 = getBit(data, &boff, 4);
+       cdtd->logo_version = getBit(data, &boff, 12);
+       cdtd->data_size = getBit(data, &boff, 16);
+       cdtd->data = calloc(1, cdtd->data_size);
+       memcpy(cdtd->data, data + boff / 8, cdtd->data_size);
+       //boff += cdtd->data_size * 8;
+
+       return cdtd->data_size + 7;
+}
+
+void dumpCDT(unsigned char *ptr, STATION *station, int station_count)
+{
+       CDThead  cdth;
+       CDTdesc  desc;
+       CDTdata  cdtd;
+       LOGO * pLogo;
+
+       int len = 0;
+       int loop_len = 0;
+       int desc_len = 0;
+       int i = 0;
+
+       /* CDT */
+       len = parseCDThead(ptr, &cdth);
+       ptr += len;
+       loop_len = cdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
+
+       desc_len = cdth.descriptors_loop_length;
+       while(desc_len > 0) {
+               len = parseCDTdesc(ptr, &desc);
+               ptr += len;
+               desc_len -= len;
+       }
+
+       while(loop_len > 0) {
+               /*
+               logo_type
+               0x00 24x48 864  SD4:3 スモール 
+               0x01 24x36 648  SD16:9 スモール
+               0x02 27x48 972  HD スモール 
+               0x03 36x72 1296 SD4:3 ラージ 
+               0x04 36x54 972  SD16:9 ラージ 
+               0x05 36x64 1152 HD ラージ 
+               */
+               len = parseCDTdata(ptr, &cdtd);
+               ptr += len;
+               loop_len -= len;
+/*
+               char fname[16];
+               sprintf(fname,"%d_%d.png",cdth.download_data_id,cdtd.logo_type);
+               FILE* png = fopen(fname,"wb");
+               void* mem_png = NULL;
+               int size_png;
+               clt2png(cdtd.data,&mem_png, &size_png);
+               fwrite(mem_png, 1, size_png, png);
+               fclose(png);
+*/
+#if 0
+               printf("CDT=(%d:%d:%d:%d:%d:%dbyte:desc%dbyte)%d,%d,%d,%d\n",
+                       cdth.table_id, cdth.download_data_id, cdth.version_number, 
+                       cdth.original_network_id, cdth.data_type, 
+                       cdth.section_length, cdth.descriptors_loop_length, 
+
+                       cdtd.logo_type, cdtd.logo_id, cdtd.logo_version,
+                       cdtd.data_size);
+#endif
+               for ( i = 0; i < station_count; i++ ) {
+                       pLogo = &station[i].logo_array[cdtd.logo_type];
+                       if ( station[i].logo_download_data_id == cdth.download_data_id ) {
+                               pLogo->logo = NULL;
+                               clt2png(cdtd.data, &pLogo->logo, &pLogo->logo_size);
+                       }
+               }
+       }
+       return;
+}
+
diff --git a/epgdump/cdt.h b/epgdump/cdt.h
new file mode 100644 (file)
index 0000000..9d39bf6
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef CDT_H
+#define CDT_H 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "sdt.h"
+#include "util.h"
+#include "ts_ctl.h"
+
+typedef struct _CDThead {
+       unsigned char table_id;
+       int  section_syntax_indicator;
+       int  reserved_future_use1;
+       int  reserved1;
+       int  section_length;
+       int  download_data_id;
+       int  reserved2;
+       int  version_number;
+       int  current_next_indicator;
+       int  section_number;
+       int  last_section_number;
+       int  original_network_id;
+       int  reserved_future_use2;
+       int  data_type;
+       int  descriptors_loop_length;
+} CDThead;
+
+typedef struct _CDTdesc {
+       unsigned char  descriptor_tag;
+       int  descriptor_length;
+} CDTdesc;
+
+typedef struct _CDTdata {
+       int     logo_type;
+       int     reserved_future_use1;
+       int     logo_id;
+       int     reserved_future_use2;
+       int     logo_version;
+       int     data_size;
+       void    *data;
+} CDTdata;
+
+#ifdef __cplusplus
+extern "C"{
+#endif /* __cplusplus */
+
+       int parseCDThead(unsigned char *data, CDThead *h);
+       int parseCDTdesc(unsigned char *data, CDTdesc *desc);
+       void dumpCDT(unsigned char *ptr, STATION *station, int station_count);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/epgdump/clt2png.c b/epgdump/clt2png.c
new file mode 100644 (file)
index 0000000..fecc5c7
--- /dev/null
@@ -0,0 +1,465 @@
+// \83f\81[\83^\95ú\91\97\97p\83v\83\8d\83O\83\89\83\80\8bl\82ß\8d\87\82í\82¹ \82»\82Ì2\82æ\82è\97¬\97p\r
+// \83J\83\89\81[\83}\83b\83v\83f\81[\83^\82ðPNG\82É\93K\97p\82·\82é\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#define bool char\r
+#define true  1\r
+#define false 0\r
+#define inline\r
+\r
+typedef unsigned char byte;\r
+typedef unsigned short uint16;\r
+typedef unsigned long uint32;\r
+\r
+typedef struct _rgb_color {\r
+       byte r;\r
+       byte g;\r
+       byte b;\r
+       byte a;\r
+} rgb_color;\r
+\r
+typedef struct _color_map_data {\r
+       byte clut_type;\r
+       byte depth;\r
+       byte region_flag;\r
+       byte start_end_flag;\r
+       byte reserved_future_use;\r
+       uint16 top_left_x;\r
+       uint16 top_left_y;\r
+       uint16 bottom_right_x;\r
+       uint16 bottom_right_y;\r
+       uint16 start_index;\r
+       uint16 end_index;\r
+       rgb_color color_map[0x10000];\r
+} color_map_data;\r
+\r
+static const rgb_color default_colormap[128] = {\r
+       {  0,     0,      0,    255},\r
+       {255,     0,      0,    255},\r
+       {  0,   255,      0,    255},\r
+       {255,   255,      0,    255},\r
+       {  0,     0,      0,    255},\r
+       {255,     0,    255,    255},\r
+       {  0,   255,    255,    255},\r
+       {255,   255,    255,    255},\r
+       {  0,     0,      0,      0},\r
+       {170,     0,      0,    255},\r
+       {  0,   170,      0,    255},\r
+       {170,   170,      0,    255},\r
+       {  0,     0,    170,    255},\r
+       {170,     0,    170,    255},\r
+       {  0,   170,    170,    255},\r
+       {170,   170,    170,    255},\r
+       {  0,     0,     85,    255},\r
+       {  0,    85,      0,    255},\r
+       {  0,    85,     85,    255},\r
+       {  0,    85,    170,    255},\r
+       {  0,    85,    255,    255},\r
+       {  0,   170,     85,    255},\r
+       {  0,   170,    255,    255},\r
+       {  0,   255,     85,    255},\r
+       {  0,   255,    170,    255},\r
+       { 85,     0,      0,    255},\r
+       { 85,     0,     85,    255},\r
+       { 85,     0,    170,    255},\r
+       { 85,     0,    255,    255},\r
+       { 85,    85,      0,    255},\r
+       { 85,    85,     85,    255},\r
+       { 85,    85,    170,    255},\r
+       { 85,    85,    255,    255},\r
+       { 85,   170,      0,    255},\r
+       { 85,   170,     85,    255},\r
+       { 85,   170,    170,    255},\r
+       { 85,   170,    255,    255},\r
+       { 85,   255,      0,    255},\r
+       { 85,   255,     85,    255},\r
+       { 85,   255,    170,    255},\r
+       { 85,   255,    255,    255},\r
+       {170,     0,     85,    255},\r
+       {170,     0,    255,    255},\r
+       {170,    85,      0,    255},\r
+       {170,    85,     85,    255},\r
+       {170,    85,    170,    255},\r
+       {170,    85,    255,    255},\r
+       {170,   170,     85,    255},\r
+       {170,   170,    255,    255},\r
+       {170,   255,      0,    255},\r
+       {170,   255,     85,    255},\r
+       {170,   255,    170,    255},\r
+       {170,   255,    255,    255},\r
+       {255,     0,     85,    255},\r
+       {255,     0,    170,    255},\r
+       {255,    85,      0,    255},\r
+       {255,    85,     85,    255},\r
+       {255,    85,    170,    255},\r
+       {255,    85,    255,    255},\r
+       {255,   170,      0,    255},\r
+       {255,   170,     85,    255},\r
+       {255,   170,    170,    255},\r
+       {255,   170,    255,    255},\r
+       {255,   225,     85,    255},\r
+       {225,   225,    170,    255},\r
+       {  0,     0,      0,    128},\r
+       {255,     0,      0,    128},\r
+       {  0,   255,      0,    128},\r
+       {255,   255,      0,    128},\r
+       {  0,     0,    255,    128},\r
+       {255,     0,    255,    128},\r
+       {  0,   255,    255,    128},\r
+       {255,   255,    255,    128},\r
+       {170,     0,      0,    128},\r
+       {  0,   170,      0,    128},\r
+       {170,   170,      0,    128},\r
+       {  0,     0,    170,    128},\r
+       {170,     0,    170,    128},\r
+       {  0,   170,    170,    128},\r
+       {170,   170,    170,    128},\r
+       {  0,     0,     85,    128},\r
+       {  0,    85,      0,    128},\r
+       {  0,    85,     85,    128},\r
+       {  0,    85,    170,    128},\r
+       {  0,    85,    255,    128},\r
+       {  0,   170,     85,    128},\r
+       {  0,   170,    255,    128},\r
+       {  0,   255,     85,    128},\r
+       {  0,   255,    170,    128},\r
+       { 85,     0,      0,    128},\r
+       { 85,     0,     85,    128},\r
+       { 85,     0,    170,    128},\r
+       { 85,     0,    255,    128},\r
+       { 85,    85,      0,    128},\r
+       { 85,    85,     85,    128},\r
+       { 85,    85,    170,    128},\r
+       { 85,    85,    255,    128},\r
+       { 85,   170,      0,    128},\r
+       { 85,   170,     85,    128},\r
+       { 85,   170,    170,    128},\r
+       { 85,   170,    255,    128},\r
+       { 85,   255,      0,    128},\r
+       { 85,   255,     85,    128},\r
+       { 85,   255,    170,    128},\r
+       { 85,   255,    255,    128},\r
+       {170,     0,     85,    128},\r
+       {170,     0,    255,    128},\r
+       {170,    85,      0,    128},\r
+       {170,    85,     85,    128},\r
+       {170,    85,    170,    128},\r
+       {170,    85,    255,    128},\r
+       {170,   170,     85,    128},\r
+       {170,   170,    255,    128},\r
+       {170,   255,      0,    128},\r
+       {170,   255,     85,    128},\r
+       {170,   255,    170,    128},\r
+       {170,   255,    255,    128},\r
+       {255,     0,     85,    128},\r
+       {255,     0,    170,    128},\r
+       {255,    85,      0,    128},\r
+       {255,    85,     85,    128},\r
+       {255,    85,    170,    128},\r
+       {255,    85,    255,    128},\r
+       {255,   170,      0,    128},\r
+       {255,   170,     85,    128},\r
+       {255,   170,    170,    128},\r
+       {255,   170,    255,    128},\r
+       {255,   255,     85,    128},\r
+};\r
+\r
+\r
+/*\r
+       Y  = 0.2126 * R + 0.7152 * G + 0.0722 * B\r
+       Cb = -(0.2126/1.8556)*(224/219) * R -(0.7152/1.8556)*(224/219) * G 0.5*(224/219) * B\r
+       Cr = 0.5*(224/219) * R -(0.7152/1.5748)*(224/219) * G -(0.0722/1.5748)*(224/219) * B\r
+*/\r
+\r
+inline byte ycbcr_to_r(int y,int cb,int cr)\r
+{\r
+       int r=(76309*(y-16)+104597*(cr-128)+32768)/65536;\r
+       return (byte)(r<0?0:r>255?255:r);\r
+}\r
+\r
+inline byte ycbcr_to_g(int y,int cb,int cr)\r
+{\r
+       int g=(76309*(y-16)-25675*(cb-128)-53279*(cr-128)+32768)/65536;\r
+       return (byte)(g<0?0:g>255?255:g);\r
+}\r
+\r
+inline byte ycbcr_to_b(int y,int cb,int cr)\r
+{\r
+       int b=(76309*(y-16)+132201*(cb-128)+32768)/65536;\r
+       return (byte)(b<0?0:b>255?255:b);\r
+}\r
+\r
+\r
+byte read_byte(void *fp, int *index_fp)\r
+{\r
+       int data = *((unsigned char*)fp + *index_fp++);\r
+       return (byte)data;\r
+}\r
+\r
+\r
+uint16 read_word(void *fp, int *index_fp)\r
+{\r
+       byte data=read_byte(fp, index_fp);\r
+\r
+       return ((uint16)data<<8)|(uint16)read_byte(fp, index_fp);\r
+}\r
+\r
+\r
+uint32 read_dword(void *fp, int *index_fp)\r
+{\r
+       byte data1=read_byte(fp, index_fp);\r
+       byte data2=read_byte(fp, index_fp);\r
+       byte data3=read_byte(fp, index_fp);\r
+       byte data4=read_byte(fp, index_fp);\r
+\r
+       return ((uint32)data1<<24)|((uint32)data2<<16)|((uint32)data3<<8)|(uint32)data4;\r
+}\r
+\r
+\r
+void read_data(void *fp,int *index_fp,void *data,size_t size)\r
+{\r
+       memcpy(data,fp + *index_fp, size);\r
+       *index_fp += size;\r
+}\r
+\r
+\r
+void write_dword(void **fp, int *index_fp,uint32 value)\r
+{\r
+       byte data[4];\r
+\r
+       data[0]=(byte)(value>>24);\r
+       data[1]=(byte)((value>>16)&0xFF);\r
+       data[2]=(byte)((value>>8)&0xFF);\r
+       data[3]=(byte)(value&0xFF);\r
+       *fp = realloc(*fp, *index_fp + 4);\r
+       memcpy(*fp + *index_fp, data, 4);\r
+       *index_fp += 4;\r
+}\r
+\r
+\r
+void write_data(void **fp,int *index_fp,void *data,size_t size)\r
+{\r
+       *fp = realloc(*fp, *index_fp + size);\r
+       memcpy(*fp + *index_fp, data, size);\r
+       *index_fp += size;\r
+}\r
+\r
+\r
+uint32 calc_crc(const byte *data,size_t size)\r
+{\r
+       static const uint32 crc_table[256] = {\r
+               0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,\r
+               0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,\r
+               0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,\r
+               0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,\r
+               0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,\r
+               0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,\r
+               0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,\r
+               0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,\r
+               0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,\r
+               0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,\r
+               0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,\r
+               0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,\r
+               0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,\r
+               0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,\r
+               0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,\r
+               0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,\r
+               0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,\r
+               0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,\r
+               0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,\r
+               0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,\r
+               0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,\r
+               0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,\r
+               0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,\r
+               0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,\r
+               0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,\r
+               0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,\r
+               0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,\r
+               0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,\r
+               0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,\r
+               0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,\r
+               0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,\r
+               0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,\r
+               0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,\r
+               0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,\r
+               0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,\r
+               0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,\r
+               0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,\r
+               0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,\r
+               0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,\r
+               0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,\r
+               0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,\r
+               0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,\r
+               0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,\r
+               0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,\r
+               0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,\r
+               0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,\r
+               0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,\r
+               0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,\r
+               0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,\r
+               0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,\r
+               0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,\r
+               0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,\r
+               0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,\r
+               0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,\r
+               0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,\r
+               0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,\r
+               0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,\r
+               0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,\r
+               0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,\r
+               0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,\r
+               0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,\r
+               0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,\r
+               0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,\r
+               0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,\r
+       };\r
+       uint32 crc;\r
+\r
+       crc=0xFFFFFFFFUL;\r
+       for (size_t i=0;i<size;i++)\r
+               crc=(crc>>8)^crc_table[(crc^data[i])&0x000000FFUL];\r
+       return ~crc;\r
+}\r
+\r
+\r
+int clt2png(void* input, void** output, int* output_size)\r
+{\r
+       int input_index = 0, output_index = 0;\r
+\r
+       color_map_data colormap;\r
+       memset(colormap.color_map,0,sizeof(colormap.color_map));\r
+       memcpy(colormap.color_map,default_colormap,sizeof(default_colormap));\r
+\r
+       if (input!=NULL) {\r
+               // Parse color_map_data\r
+               byte b=read_byte(input, &input_index);\r
+               colormap.clut_type=(b&0x80)>>7;\r
+               colormap.depth=(b&0x60)>>5;\r
+               if (colormap.depth==3) {\r
+                       printf("Error : Unknown depth (%d)\n",colormap.depth);\r
+                       return 1;\r
+               }\r
+               colormap.region_flag=(b&0x10)>>4;\r
+               colormap.start_end_flag=(b&0x08)>>3;\r
+               colormap.reserved_future_use=b&0x07;\r
+               if (colormap.region_flag) {\r
+                       colormap.top_left_x=read_word(input, &input_index);\r
+                       colormap.top_left_y=read_word(input, &input_index);\r
+                       colormap.bottom_right_x=read_word(input, &input_index);\r
+                       colormap.bottom_right_y=read_word(input, &input_index);\r
+               }\r
+               if (colormap.start_end_flag) {\r
+                       if (colormap.depth==0) {\r
+                               b=read_byte(input, &input_index);\r
+                               colormap.start_index=b>>4;\r
+                               colormap.end_index=b&0x0F;\r
+                       } else if (colormap.depth==1) {\r
+                               colormap.start_index=read_byte(input, &input_index);\r
+                               colormap.end_index=read_byte(input, &input_index);\r
+                       } else if (colormap.depth==2) {\r
+                               colormap.start_index=read_word(input, &input_index);\r
+                               colormap.end_index=read_word(input, &input_index);\r
+                       }\r
+               } else {\r
+                       colormap.start_index=0;\r
+                       switch (colormap.depth) {\r
+                       case 0: colormap.end_index=15;          break;\r
+                       case 1: colormap.end_index=255;         break;\r
+                       case 2: colormap.end_index=65535;       break;\r
+                       }\r
+               }\r
+               for (uint16 i=colormap.start_index;i<=colormap.end_index;i++) {\r
+                       if (colormap.clut_type==0) {\r
+                               int y,cb,cr;\r
+                               y=read_byte(input, &input_index);\r
+                               cb=read_byte(input, &input_index);\r
+                               cr=read_byte(input, &input_index);\r
+                               colormap.color_map[i].r=ycbcr_to_r(y,cb,cr);\r
+                               colormap.color_map[i].g=ycbcr_to_g(y,cb,cr);\r
+                               colormap.color_map[i].b=ycbcr_to_b(y,cb,cr);\r
+                       } else {\r
+                               colormap.color_map[i].r=read_byte(input, &input_index);\r
+                               colormap.color_map[i].g=read_byte(input, &input_index);\r
+                               colormap.color_map[i].b=read_byte(input, &input_index);\r
+                       }\r
+                       colormap.color_map[i].a=read_byte(input, &input_index);\r
+               }\r
+               input_index = 0;\r
+       }\r
+\r
+       // Open PNG file\r
+\r
+       byte buffer[8];\r
+       read_data(input,&input_index,buffer,8);\r
+       if (memcmp(buffer,"\x89PNG\r\n\x1A\n",8)!=0) {\r
+               printf("Error : Not a PNG format\n");\r
+               return 1;\r
+       }\r
+       write_data(output,&output_index,buffer,8);\r
+       int bit_depth=0,color_type=-1;\r
+       bool has_palette=false;\r
+       while (true) {\r
+               read_data(input,&input_index,buffer,8);\r
+               uint32 data_size=((uint32)buffer[0]<<24)|((uint32)buffer[1]<<16)|((uint32)buffer[2]<<8)|(uint32)buffer[3];\r
+               if (memcmp(buffer+4,"IHDR",4)==0) {\r
+                       byte header[13];\r
+                       read_data(input,&input_index,header,13);\r
+                       bit_depth=header[8];\r
+                       color_type=header[9];\r
+                       input_index -= 13;\r
+               } else if (memcmp(buffer+4,"PLTE",4)==0) {\r
+                       has_palette=true;\r
+               } else if (memcmp(buffer+4,"IDAT",4)==0) {\r
+                       if (!has_palette && bit_depth<=8 && color_type==3) {\r
+                               int num_colors=1<<bit_depth;\r
+                               byte data[4+256*3];\r
+                               int i;\r
+                               uint32 crc;\r
+\r
+                               // tRNS\r
+                               for (i=0;i<num_colors;i++) {\r
+                                       if (colormap.color_map[i].a<255)\r
+                                               break;\r
+                               }\r
+                               if (i<num_colors) {\r
+                                       write_dword(output,&output_index,num_colors);\r
+                                       memcpy(data,"tRNS",4);\r
+                                       for (int i=0;i<num_colors;i++)\r
+                                               data[4+i]=colormap.color_map[i].a;\r
+                                       write_data(output,&output_index,data,4+num_colors);\r
+                                       crc=calc_crc(data,4+num_colors);\r
+                                       write_dword(output,&output_index,crc);\r
+                               }\r
+\r
+                               // Generate PLTE chunk\r
+                               uint32 palette_size=num_colors*3;\r
+                               write_dword(output,&output_index,palette_size);\r
+                               memcpy(data,"PLTE",4);\r
+                               for (i=0;i<num_colors;i++) {\r
+                                       data[4+i*3+0]=colormap.color_map[i].r;\r
+                                       data[4+i*3+1]=colormap.color_map[i].g;\r
+                                       data[4+i*3+2]=colormap.color_map[i].b;\r
+                               }\r
+                               write_data(output,&output_index,data,4+palette_size);\r
+                               crc=calc_crc(data,4+palette_size);\r
+                               write_dword(output,&output_index,crc);\r
+                       }\r
+               }\r
+               // Copy chunk\r
+               write_data(output,&output_index,buffer,8);\r
+               void *data = malloc(data_size+4);\r
+               read_data(input,&input_index,data,data_size+4);\r
+               write_data(output,&output_index,data,data_size+4);\r
+               free(data);\r
+               if (memcmp(buffer+4,"IEND",4)==0)\r
+                       break;\r
+       }\r
+\r
+       *output_size = output_index;\r
+\r
+       return 0;\r
+}\r
+\r
diff --git a/epgdump/clt2png.h b/epgdump/clt2png.h
new file mode 100644 (file)
index 0000000..b3dbbde
--- /dev/null
@@ -0,0 +1,10 @@
+// \83f\81[\83^\95ú\91\97\97p\83v\83\8d\83O\83\89\83\80\8bl\82ß\8d\87\82í\82¹ \82»\82Ì2\82æ\82è\97¬\97p\r
+// \83J\83\89\81[\83}\83b\83v\83f\81[\83^\82ðPNG\82É\93K\97p\82·\82é\r
+\r
+#ifndef        __CLT2PNG_H__\r
+#define        __CLT2PNG_H__\r
+\r
+int clt2png(void* input, void** output, int* output_size);\r
+\r
+#endif\r
+\r
diff --git a/epgdump/dsmcc.c b/epgdump/dsmcc.c
new file mode 100644 (file)
index 0000000..c521769
--- /dev/null
@@ -0,0 +1,192 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dsmcc.h"
+#include "ts_ctl.h"
+#include "clt2png.h"
+
+// STD-B21 p130 (144)
+int parseDSMCChead(unsigned char *data, DSMCChead *dsmh) {
+       int boff = 0;
+
+       memset(dsmh, 0, sizeof(DSMCChead));
+
+       dsmh->table_id = getBit(data, &boff, 8);
+       dsmh->section_syntax_indicator = getBit(data, &boff, 1);
+       dsmh->complement_indicator = getBit(data, &boff,1);
+       dsmh->reserved1 = getBit(data, &boff, 2);
+       dsmh->section_length = getBit(data, &boff, 12);
+       dsmh->table_id_extension = getBit(data, &boff, 16);
+       dsmh->reserved2 = getBit(data, &boff, 2);
+       dsmh->version_number = getBit(data, &boff, 5);
+       dsmh->current_next_indicator = getBit(data, &boff, 1);
+       dsmh->section_number = getBit(data, &boff, 8);
+       dsmh->last_section_number = getBit(data, &boff, 8);
+
+       return 8;
+}
+
+int parseDSMCCbodyDII(unsigned char *data, DSMCCbodyDII *dsmbdii) {
+       int boff = 0, i;
+       DSMCCbodyDIIModule *module;
+
+       memset(dsmbdii, 0, sizeof(DSMCCbodyDII));
+
+       // header
+       dsmbdii->protocolDiscriminator = getBit(data, &boff, 8);
+       dsmbdii->dsmccType = getBit(data, &boff, 8);
+       dsmbdii->messageId = getBit(data, &boff, 16);
+       dsmbdii->transaction_id = getBit(data, &boff, 32);
+       dsmbdii->reserved = getBit(data, &boff, 8);
+       dsmbdii->adaptationLength = getBit(data, &boff, 8);
+       dsmbdii->messageLength = getBit(data, &boff, 16);
+       if ( dsmbdii->adaptationLength > 0 ) {
+               dsmbdii->dsmccAdaptationHeader = allocCopy(data, &boff, dsmbdii->adaptationLength);
+       }
+
+       // body
+       dsmbdii->downloadId = getBit(data, &boff, 32);
+       dsmbdii->blockSize = getBit(data, &boff, 16);
+       dsmbdii->windowSize = getBit(data, &boff, 8);
+       dsmbdii->ackPeriod = getBit(data, &boff, 8);
+       dsmbdii->tCDownloadWindow = getBit(data, &boff, 32);
+       dsmbdii->tCDownloadScenario = getBit(data, &boff, 32);
+       dsmbdii->compatibilityDescriptor = getBit(data, &boff, 16);
+/*
+       see http://www.atsc.org/cms/standards/a_90-with-att.pdf
+
+       compatibilityDescriptorLength   16
+       descriptorCount 16
+       for(i=0;i<descriptorCount;i++) {
+               descriptorType          8
+               descriptorLength        8
+               specifierType           8
+               specifierData           24
+               model                           16
+               version                         16
+               subDescriptorCount      8
+               for(j=0;j<subDescriptorCount;j++) {
+                       subDescriptor() {
+                               subDescriptorType       8
+                               subDescriptorLength     8
+                               for(k=0;k<subDescriptorLength;k++) {
+                                       additionalInformation   8
+               }
+       }
+*/
+       boff += dsmbdii->compatibilityDescriptor * 8;
+       dsmbdii->numberOfModules = getBit(data, &boff, 16);
+
+       if ( dsmbdii->numberOfModules > 0 ) {
+               dsmbdii->modules = calloc(1, sizeof(DSMCCbodyDIIModule) * dsmbdii->numberOfModules);
+
+               for (i=0; i<dsmbdii->numberOfModules; i++) {
+                       module = dsmbdii->modules + sizeof(DSMCCbodyDIIModule) * i;
+                       module->moduleId = getBit(data, &boff, 16);
+                       module->moduleSize = getBit(data, &boff, 32);
+                       module->moduleVersion = getBit(data, &boff, 8);
+                       module->moduleInfoLength = getBit(data, &boff, 8);
+                       module->moduleInfo = allocCopy(data, &boff, module->moduleInfoLength);
+               }
+       }
+
+       dsmbdii->privateDataLength = getBit(data, &boff, 8);
+       dsmbdii->privateData = allocCopy(data, &boff, dsmbdii->privateDataLength);
+
+       return boff / 8;
+}
+
+int parseDSMCCbodyDDB(unsigned char *data, DSMCCbodyDDB *dsmbddb) {
+       int boff = 0;
+
+       memset(dsmbddb, 0, sizeof(DSMCCbodyDDB));
+
+       // header
+       dsmbddb->protocolDiscriminator = getBit(data, &boff, 8);
+       dsmbddb->dsmccType = getBit(data, &boff, 8);
+       dsmbddb->messageId = getBit(data, &boff, 16);
+       dsmbddb->downloadId = getBit(data, &boff, 32);
+       dsmbddb->reserved1 = getBit(data, &boff, 8);
+       dsmbddb->adaptationLength = getBit(data, &boff, 8);
+       dsmbddb->messageLength = getBit(data, &boff, 16);
+       if ( dsmbddb->adaptationLength > 0 ) {
+               dsmbddb->dsmccAdaptationHeader = allocCopy(data, &boff, dsmbddb->adaptationLength);
+       }
+
+       // body
+       dsmbddb->moduleId = getBit(data, &boff, 16);
+       dsmbddb->moduleVersion = getBit(data, &boff, 8);
+       dsmbddb->reserved2 = getBit(data, &boff, 8);
+       dsmbddb->blockNumber = getBit(data, &boff, 16);
+       dsmbddb->blockData = allocCopy(data, &boff, dsmbddb->adaptationLength);
+
+       return boff / 8;
+}
+
+void dumpDSMCC(unsigned char *ptr, STATION *station, int station_count)
+{
+       DSMCChead  dsmh;
+       DSMCCbodyDII  dsmbdii;
+       DSMCCbodyDDB  dsmbddb;
+       DSMCCbodyDIIModule *module;
+
+       int len = 0;
+       int loop_len = 0;
+       int i = 0;
+
+       /* DSMCC */
+       len = parseDSMCChead(ptr, &dsmh);
+       ptr += len;
+       //loop_len = dsmh.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
+/*
+       printf("DSMCChead=(%d:%d:%d:%d)\n",
+               dsmh.table_id, dsmh.section_length, 
+               dsmh.table_id_extension, dsmh.section_number);
+*/
+       if ( dsmh.table_id == 0x3B ) {
+               len = parseDSMCCbodyDII(ptr, &dsmbdii);
+#if 1
+               printf("DSMCCbDDI=(%d:%d:%d:%d:%d:%d) (%d:%d:%d:%d)\n",
+                       dsmbdii.protocolDiscriminator, dsmbdii.dsmccType, 
+                       dsmbdii.messageId, dsmbdii.transaction_id, 
+                       dsmbdii.adaptationLength, dsmbdii.messageLength, 
+
+                       dsmbdii.downloadId , dsmbdii.blockSize , dsmbdii.compatibilityDescriptor , 
+                       dsmbdii.numberOfModules);
+#endif
+               for (i=0; i<dsmbdii.numberOfModules; i++) {
+                       module = dsmbdii.modules + sizeof(DSMCCbodyDIIModule) * i;
+                       /*
+                       if ( *module->moduleInfo == 0x01 ) {
+                               printf("1 %d %s\n",module, module->moduleInfo + 2);
+                       }
+                       else if ( *module->moduleInfo == 0x02 ) {
+                               printf("2 %s\n",module->moduleInfo + 2);
+                       }
+                       else if ( *module->moduleInfo == 0x03 ) {
+                               printf("3 %s\n",module->moduleInfo);
+                       }
+                       */
+               }
+       }
+       else if ( dsmh.table_id == 0x3C ) {
+               len = parseDSMCCbodyDDB(ptr, &dsmbddb);
+//             if ( station[0].logo_download_data_id == dsmbddb.downloadId ) {
+//             if ( 151585024 == dsmbddb.downloadId ) {
+#if 1
+                       printf("DSMCCbDDB=(%d:%d:%d:%d:%d:%d) (%d:%d:%d)\n",
+                               dsmbddb.protocolDiscriminator, dsmbddb.dsmccType, 
+                               dsmbddb.messageId, dsmbddb.downloadId, 
+                               dsmbddb.adaptationLength, dsmbddb.messageLength, 
+
+                               dsmbddb.moduleId , dsmbddb.moduleVersion , dsmbddb.blockNumber);
+#endif
+//             }
+       }
+
+       return;
+}
+
diff --git a/epgdump/dsmcc.h b/epgdump/dsmcc.h
new file mode 100644 (file)
index 0000000..4ff5a06
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef DSMCC_H
+#define DSMCC_H 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "sdt.h"
+#include "util.h"
+#include "ts_ctl.h"
+
+typedef struct _DSMCChead {
+       int table_id;
+       int section_syntax_indicator;
+       int complement_indicator;
+       int reserved1;
+       int section_length;
+       int table_id_extension;
+       int reserved2;
+       int version_number;
+       int current_next_indicator;
+       int section_number;
+       int last_section_number;
+} DSMCChead;
+/*
+typedef struct _DSMCCmsghead {
+       int  protocolDiscriminator;
+       int  dsmccType;
+       int  messageId;
+       int  transaction_id;
+       int  reserved;
+       int  adaptationLength;
+       int  messageLength;
+       void *dsmccAdaptationHeader;
+} DSMCCmsghead;
+*/
+typedef struct _DSMCCbodyDIIModule {
+       int  moduleId;
+       int  moduleSize;
+       int  moduleVersion;
+       int  moduleInfoLength;
+       unsigned char *moduleInfo;
+} DSMCCbodyDIIModule;
+
+typedef struct _DSMCCbodyDII {
+       int  protocolDiscriminator;
+       int  dsmccType;
+       int  messageId;
+       int  transaction_id;
+       int  reserved;
+       int  adaptationLength;
+       int  messageLength;
+       void *dsmccAdaptationHeader;
+
+       int  downloadId;
+       int  blockSize;
+       int  windowSize;
+       int  ackPeriod;
+       int  tCDownloadWindow;
+       int  tCDownloadScenario;
+       int  compatibilityDescriptor;
+       int  numberOfModules;
+       void *modules;
+       int  privateDataLength;
+       void *privateData;
+} DSMCCbodyDII;
+
+typedef struct _DSMCCbodyDDB {
+       int  protocolDiscriminator;
+       int  dsmccType;
+       int  messageId;
+       unsigned int  downloadId;
+       int  reserved1;
+       int  adaptationLength;
+       int  messageLength;
+       void *dsmccAdaptationHeader;
+
+       int  moduleId;
+       int  moduleVersion;
+       int  reserved2;
+       int  blockNumber;
+       void *blockData;
+} DSMCCbodyDDB;
+
+#ifdef __cplusplus
+extern "C"{
+#endif /* __cplusplus */
+
+       int parseDSMCChead(unsigned char *data, DSMCChead *h);
+       int parseDSMCCbodyDDB(unsigned char *data, DSMCCbodyDDB *dsmbddb);
+       void dumpDSMCC(unsigned char *ptr, STATION *station, int station_count);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
index 23857df..f977e0c 100755 (executable)
@@ -1,3 +1,6 @@
+// -*- tab-width:4 -*-
+// see TR-B14 4-296 (p.318)
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -5,18 +8,11 @@
 #include "eit.h"
 
 char           *subtitle_cnv_str[] = {
-//     "¡¡Âè",
-//     "¡¼Âè",
-//     "-Âè",
-//     " Âè",
-//     "¡¡¡Ö",
-//     "¡¡¡ô",
-//     "¡Ê",
-//     "¡Ö",
        NULL
 };
 static void timecmp(int *,int *,int *,
                                        int, int, int);
+void append_desc(EIT_CONTROL* eittop, int service_id, int event_id, EEVTDitem* eevtitem);
 
 int parseEIThead(unsigned char *data, EIThead *h) {
        int boff = 0;
@@ -62,7 +58,7 @@ int parseEITbody(unsigned char *data, EITbody *b)
        b->free_CA_mode = getBit(data, &boff, 1);
        b->descriptors_loop_length = getBit(data, &boff, 12);
 
-       /* ÆüÉÕÊÑ´¹ */
+       /* 日付変換 */
        tnum = (b->start_time[0] & 0xFF) << 8 | (b->start_time[1] & 0xFF);
   
        b->yy = (tnum - 15078.2) / 365.25;
@@ -96,14 +92,14 @@ int parseEITbody(unsigned char *data, EITbody *b)
                b->dhh = b->dhm = b->dss = 0;
        }else{
                memset(buf, '\0', sizeof(buf));
-       sprintf(buf, "%x", b->duration[0]);
-       b->dhh = atoi(buf);
+               sprintf(buf, "%x", b->duration[0]);
+               b->dhh = atoi(buf);
                memset(buf, '\0', sizeof(buf));
-       sprintf(buf, "%x", b->duration[1]);
-       b->dhm = atoi(buf);
+               sprintf(buf, "%x", b->duration[1]);
+               b->dhm = atoi(buf);
                memset(buf, '\0', sizeof(buf));
-       sprintf(buf, "%x", b->duration[2]);
-       b->dss = atoi(buf);
+               sprintf(buf, "%x", b->duration[2]);
+               b->dss = atoi(buf);
        }
        return 12;
 }
@@ -140,7 +136,7 @@ int parseContentDesc(unsigned char *data, ContentDesc *desc) {
        }
        desc->descriptor_length = getBit(data, &boff, 8);
        memcpy(desc->content, data+(boff/8), desc->descriptor_length);
-       //getStr(desc->content, data, &boff, desc->descriptor_length);
+       /* getStr(desc->content, data, &boff, desc->descriptor_length); */
        return desc->descriptor_length + 2;
 }
 
@@ -197,11 +193,13 @@ int parseEEVTDitem(unsigned char *data, EEVTDitem *desc) {
        memset(desc, 0, sizeof(EEVTDitem));
 
        desc->item_description_length = getBit(data, &boff, 8);
+       memset(desc->item_description, 0, MAXSECLEN);
        getStr(desc->item_description, data, &boff, desc->item_description_length);
 
        desc->item_length = getBit(data, &boff, 8);
-//     memcpy(desc->item, data + (boff / 8), desc->item_length);
-       getStr(desc->item, data, &boff, desc->item_length);
+       memset(desc->item, 0, MAXSECLEN);
+       memcpy(desc->item, data + (boff / 8), desc->item_length);
+       /* getStr(desc->item, data, &boff, desc->item_length); */
 
        return desc->item_description_length + desc->item_length + 2;
 }
@@ -212,6 +210,7 @@ int parseEEVTDtail(unsigned char *data, EEVTDtail *desc) {
        memset(desc, 0, sizeof(EEVTDtail));
 
        desc->text_length = getBit(data, &boff, 8);
+       memset(desc->text, 0, MAXSECLEN);
        getStr(desc->text, data, &boff, desc->text_length);
 
        return desc->text_length + 1;
@@ -221,76 +220,44 @@ int checkEEVTDitem(EEVTDitem *save, EEVTDitem *new, int descriptor_number) {
 
        EEVTDitem swap;
        int boff = 0;
+
        if(new == NULL) {
                if(save->item_length != 0) {
                        swap = *save;
+                       memset(save->item, 0, MAXSECLEN);
                        getStr(save->item, (unsigned char*)swap.item, &boff, swap.item_length);
-
-
-                        //save->descriptor_number = descriptor_number;
-                        //*new = swap;
-                       //*save = swap;
-                        if (swap.descriptor_number==1){
-//                            printf("descriptor_num %d   typeB\n",swap.descriptor_number);
-                        }
-
                        return 1;
                } else {
-
-
-                        //printf("descriptor_num %d   typeC\n",swap.descriptor_number);
-
-
-
                        return 0;
                }
        }
 
        if(new->item_description_length == 0) {
-               /* Â³¤­ Êݸ */
+               /* 続き 保存 */
                memcpy(save->item + save->item_length, new->item, new->item_length);
                save->item_length += new->item_length;
-
-
-                if (swap.descriptor_number==1){
-                            printf("descriptor_num %d   typeD\n",swap.descriptor_number);
-                        }
-
-
                return 0;
        } else {
-               /* ¥Ö¥ì¡¼¥¯¡£save¤ò°õºþÂоݤˤ¹¤ë¡£save¤ò¥¯¥ê¥¢? */
+               /* ã\83\96ã\83¬ã\83¼ã\82¯ã\80\82saveã\82\92å\8d°å\88·å¯¾è±¡ã\81«ã\81\99ã\82\8bã\80\82saveã\82\92ã\82¯ã\83ªã\82¢? */
                if(save->item_length != 0) {
-                       /* ÂàÈòºÑ¤ß¤¬¤¢¤ê */
+                       /* 退避済みがあり */
                        swap = *save;
+                       memset(save->item, 0, MAXSECLEN);
                        getStr(save->item, (unsigned char*)swap.item, &boff, swap.item_length);
+
+                       // swap save new -> swap save new
+                       //         b   c -> ( c)    c   b
                        swap = *new;
                        *new = *save;
                        *save = swap;
                        save->descriptor_number = descriptor_number;
-                       
-
-
-
-                        if (swap.descriptor_number==1){
-                            printf("descriptor_num %d   typeE\n",swap.descriptor_number);
-                        }
-                        
-
+                       return 1;
                } else {
                        *save = *new;
                        save->descriptor_number = descriptor_number;
-
-                        if (swap.descriptor_number==1){
-                            printf("descriptor_num %d   typeF\n",swap.descriptor_number);
-                        }
-
-
                        return 0;
                }
        }
-
-       return 1;
 }
 EIT_CONTROL    *searcheit(EIT_CONTROL *top, int servid, int eventid)
 {
@@ -306,11 +273,34 @@ EIT_CONTROL       *searcheit(EIT_CONTROL *top, int servid, int eventid)
        }
        return NULL ;
 }
+char   *strstr_eucjp(const char *str, const char *search)
+{
+       char *pos ;
+       pos = (char *)str ;
+
+       while (*pos != '\0') {
+               if (*pos == *search) {
+                       if (strncmp(pos, search, strlen(search)) == 0) {
+                               return pos ;
+                       }
+               }
+               if ((unsigned char)*pos == 0x8Fu) {
+                       pos += 3 ;
+               } else if ((unsigned char)*pos >= 0x80u) {
+                       pos += 2 ;
+               } else {
+                       pos += 1 ;
+               }
+       }
+
+       return NULL ;
+}
 void   conv_title_subtitle(EIT_CONTROL *eitptr)
 {
        int             lp = 0 ;
-       size_t  addsize ;
+//     size_t  addsize ;
        char    *ptr ;
+       char    *ptr2 ;
        char    *newsubtitle ;
 
        for(lp = 0 ; subtitle_cnv_str[lp] != NULL ; lp++){
@@ -318,14 +308,25 @@ void      conv_title_subtitle(EIT_CONTROL *eitptr)
                if(ptr == NULL){
                        continue ;
                }
-               // ¥¿¥¤¥È¥ë¤¬¤Ê¤¯¤Ê¤é¤Ê¤¤¤è¤¦¤Ë
+               // タイトルがなくならないように
                if(ptr == eitptr->title){
                        continue ;
                }
+               /*
+               ptr2 = ptr ;
+               for( ; (unsigned char)*ptr2 == 0x20u ; ptr2++ );
+               for( ; (unsigned char)*ptr2 == 0xA1u && (unsigned char)*(ptr2+1) == 0xA1u ; ptr2 += 2);
+               for( ; (unsigned char)*ptr2 == 0x20u ; ptr2++ );
+               newsubtitle = calloc(1, ((strlen(ptr2) + 2) + (strlen(eitptr->subtitle) + 1)));
+               memcpy(newsubtitle, ptr2, strlen(ptr2));
+//             *(newsubtitle+strlen(ptr)) = ' ';
+               strcat(newsubtitle, "▽");
+               */
                newsubtitle = calloc(1, ((strlen(ptr) + 1) + (strlen(eitptr->subtitle) + 1)));
                memcpy(newsubtitle, ptr, strlen(ptr));
                newsubtitle[strlen(ptr)] = ' ';
-               *ptr = NULL ;
+
+               *ptr = '\0';
                strcat(newsubtitle, eitptr->subtitle);
                free(eitptr->subtitle);
                eitptr->subtitle = newsubtitle ;
@@ -407,7 +408,6 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
        int loop_len = 0;
        int loop_blen = 0;
        int loop_elen = 0;
-       int str_alen = 0;
 
        int ehh, emm, ess;
 
@@ -415,23 +415,29 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
        len = parseEIThead(ptr, &eith); 
 
        ptr += len;
-       loop_len = eith.section_length - (len - 3 + 4); // 3¤Ï¶¦Ḁ̈إåÀĹ 4¤ÏCRC
+       loop_len = eith.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
        while(loop_len > 0) {
-               /* Ï¢Â³¤¹¤ë³ÈÄ¥¥¤¥Ù¥ó¥È¤Ï¡¢´Á»ú¥³¡¼¥É¤¬µã¤­Ê̤줷¤Æ
-                  Ê¬³ä¤µ¤ì¤ë¤è¤¦¤À¡£Ï¢Â³¤«¤É¤¦¤«¤Ï¡¢item_description_length¤¬
-                  ÀßÄꤵ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÇȽÃǤǤ­¤ë¤è¤¦¤À¡£ */
+               /* 連続する拡張イベントは、漢字コードが泣き別れして
+                  分割されるようだ。連続かどうかは、item_description_lengthが
+                  設定されているかどうかで判断できるようだ。 */
                memset(&save_eevtitem, 0, sizeof(EEVTDitem));
 
                len = parseEITbody(ptr, &eitb);
                ptr += len;
                loop_len -= len;
-    
+
                /* printf("evtid:%d\n", eitb.event_id); */
-    
+
                loop_blen = eitb.descriptors_loop_length;
                loop_len -= loop_blen;
+
                while(loop_blen > 0) {
 
+                       /*yukikaze-test*/
+                       //printf("desc_tag");
+                       //int itt=getBit(*ptr,0,8);
+                       //printf("%x",itt);
+
                        len = parseSEVTdesc(ptr, &sevtd);
                        if(len > 0) {
 
@@ -483,10 +489,10 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                len = parseEEVTDhead(ptr, &eevthead);
 
                                /*
-                                 if(eith.service_id == 19304 && 
-                                 eitb.event_id == 46564) {
-                                 printf("aa");
-                                 }
+                               if(eith.service_id == 19304 && 
+                               eitb.event_id == 46564) {
+                               printf("aa");
+                               }
                                */
 
                                if(len > 0) {
@@ -501,60 +507,27 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                                ptr += len;
                                                loop_elen -= len;
                                                loop_blen -= len;
-                                                
-                                               if (1||checkEEVTDitem(&save_eevtitem, &eevtitem,
-                                                                                 eevthead.descriptor_number)) {
-#if 0
-                                                       {
-                                                            if (eevtitem.descriptor_number>0){
-                                                                //printf("descriptor_num %d\n",eevtitem.descriptor_number);
-                                                            }
-
-                                                            /* long format */
-                                                            //printf("descriptor_num %d\n",eevtitem.descriptor_number);
-#if 1
-                                                            printf("EEVT,%d,%d,%d,%s,%s\n",
-                                                                               eith.service_id,
-                                                                                       eitb.event_id,
-                                                                                       eevtitem.descriptor_number, // ÂàÈò¹àÌÜ
-                                                                               eevtitem.item_description,
-                                                                               eevtitem.item);
-#endif
 
-                                                       }
-#endif
-                                                       cur = searcheit(eittop, eith.service_id, eitb.event_id);
-                                                       if(cur == NULL){
-                                                               curtmp = NULL;
-                                                               cur = calloc(1, sizeof(EIT_CONTROL));
-                                                       }
-                                                       else {
-                                                               curtmp = cur;
-                                                       }
+                                               if(checkEEVTDitem(&save_eevtitem, &eevtitem, 
+                                                       eevthead.descriptor_number)) {
 
-#if 1
-                                                       if ( cur->desc ) {
-                                                               str_alen = strlen( cur->desc );
-                                                       }
-                                                       else {
-                                                               str_alen = 0;
-                                                       }
-                                                       eevtitem.item_description_length = strlen(eevtitem.item_description);
-                                                       eevtitem.item_length = strlen(eevtitem.item);
-                                                       cur->desc = realloc(cur->desc, str_alen + eevtitem.item_description_length + eevtitem.item_length + 1000);
-                                                       if ( !str_alen ) *cur->desc = '\0';
-
-                                                       if ( eevtitem.item_description_length && !strstr(cur->desc, eevtitem.item_description) ) {
-                                                               strcat(cur->desc, eevtitem.item_description);
-                                                               strcat(cur->desc, "\t");
+                                                       {
+                                                               if (eevtitem.descriptor_number>0){
+                                                                       //printf("descriptor_num %d\n",eevtitem.descriptor_number);
+                                                               }
+                                                               /* long format */
+                                                               //printf("descriptor_num %d\n",eevtitem.descriptor_number);
+#if 0
+                                                               printf("EEVT,%d,%d,%d,%s,%s\n",
+                                                                       eith.service_id,
+                                                                       eitb.event_id,
+                                                                       eevtitem.descriptor_number, // 退避項目
+                                                                       eevtitem.item_description,
+                                                                       eevtitem.item);
+#endif
                                                        }
+                                                       append_desc(eittop, eith.service_id, eitb.event_id, &eevtitem);
 
-                                                       if ( eevtitem.item_length && !strstr(cur->desc, eevtitem.item)  ) {
-                                                               strcat(cur->desc, eevtitem.item);
-                                                               strcat(cur->desc, "\\n");
-                                                       }
-#endif
-                                                       if ( !curtmp ) enqueue(eittop, cur);
                                                }
                                        }
 
@@ -572,7 +545,7 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                        ContentDesc contentDesc;
                                        len = parseContentDesc(ptr, &contentDesc);
                                        if (len > 0) {
-                                               int header_printed = 0;
+                                               //int header_printed = 0;
                                                for (int i = 0; i < contentDesc.descriptor_length - 1; i+=2) {
                                                        /*
                                                        if (0xff == (unsigned char)contentDesc.content[i])
@@ -580,16 +553,15 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                                        */
 #if 0
                                                        if (!header_printed) {
-                                                               fprintf(out, "Content,%d,%d",
+                                                               fprintf(out, "Content,%d,%d\n",
                                                                        eith.service_id,
                                                                        eitb.event_id);
                                                                header_printed = 1;
                                                        }
 #endif
 
-#if 0
-                                                       fprintf(out, ",%02x%02x", (unsigned char)contentDesc.content[i], (unsigned char)contentDesc.content[i+1]);
-#endif
+                                                       //fprintf(out, ",%02x%02x", (unsigned char)contentDesc.content[i], (unsigned char)contentDesc.content[i+1]);
+
                                                }
                                                if((eith.original_network_id == original_network_id) && (eith.transport_stream_id == transport_stream_id)){
                                                        cur = searcheit(eittop, eith.service_id, eitb.event_id);
@@ -600,8 +572,8 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                                                fprintf(stdout, ",%02x%02x", (unsigned char)contentDesc.content[0], (unsigned char)contentDesc.content[1]);
                                                                fprintf(stdout, ",%02x%02x\n", (unsigned char)contentDesc.content[2], (unsigned char)contentDesc.content[3]);
 #endif
-
                                                        }
+
 #if 0
                                                        if (header_printed) {
                                                                fprintf(out, "\n");
@@ -634,12 +606,12 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                        ptr += len;
                        loop_blen -= len;
                }
-               /* ºÇ¸å¤Î¥Ö¥ì¡¼¥¯¥Á¥§¥Ã¥¯ */
-    
+               /* æ\9c\80å¾\8cã\81®ã\83\96ã\83¬ã\83¼ã\82¯ã\83\81ã\82§ã\83\83ã\82¯ */
+
                if(checkEEVTDitem(&save_eevtitem, NULL, 0)) {
 #if 0
-                       if(mode == 1) { /* long format */
-                               fprintf(out, "EEVT,%d,%d,%d,%s,%s\n", 
+                       { /* long format */
+                               fprintf(stdout, "EEVT,%d,%d,%d,%s,%s\n", 
                                                eith.service_id,
                                                eitb.event_id,
                                                save_eevtitem.descriptor_number,
@@ -647,12 +619,45 @@ void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int trans
                                                save_eevtitem.item);
                        }
 #endif
+                       append_desc(eittop, eith.service_id, eitb.event_id, &save_eevtitem);
                }
        }
 
        return;
 }
 
+void append_desc(EIT_CONTROL* eittop, int service_id, int event_id, EEVTDitem* eevtitem) {
+       EIT_CONTROL *cur;
+       int str_alen = 0;
+
+       cur = searcheit(eittop, service_id, event_id);
+       if (cur == NULL) {
+               return;
+       }
+
+       if ( cur->desc ) {
+               str_alen = strlen( cur->desc );
+       }
+       else {
+               str_alen = 0;
+       }
+       //eevtitem->item_description_length = strlen(eevtitem->item_description);
+       //eevtitem->item_length = strlen(eevtitem->item);
+       cur->desc = realloc(cur->desc, str_alen + eevtitem->item_description_length + eevtitem->item_length + 1000);
+       if ( !str_alen ) *cur->desc = '\0';
+
+       if ( eevtitem->item_description_length && !strstr(cur->desc, eevtitem->item_description) ) {
+               strcat(cur->desc + str_alen, eevtitem->item_description);
+               strcat(cur->desc, "\t");
+       }
+
+       if ( eevtitem->item_length && !strstr(cur->desc, eevtitem->item) ) {
+               strcat(cur->desc + str_alen, eevtitem->item);
+       //printf("%s\n",eevtitem->item);
+               strcat(cur->desc, "\\n");
+       }
+}
+
 void timecmp(int *thh, int *tmm, int *tss,
                         int dhh, int dmm, int dss) {
 
index 15f910b..2301fe9 100755 (executable)
@@ -32,7 +32,7 @@ typedef struct _EITbody {
        int running_status;
        int free_CA_mode;
        int descriptors_loop_length;
-       /* °Ê²¼¤Ï²òÀÏ·ë²ÌÊݸÍÑ */
+       /* 以下は解析結果保存用 */
        int yy;
        int mm;
        int dd;
@@ -87,7 +87,7 @@ typedef struct _EEVTDitem {
        char item_description[MAXSECLEN];
        int  item_length;
        char item[MAXSECLEN];
-       /* ÂàÈòÍÑ */
+       /* 退避用 */
        int  descriptor_number;
 } EEVTDitem;
 
index 38dc1e1..305b838 100755 (executable)
@@ -7,8 +7,11 @@
 #include <time.h>
 
 #include "ts.h"
+#include "psi.h"
 #include "sdt.h"
+#include "sdtt.h"
 #include "eit.h"
+#include "dsmcc.h"
 #include "ts_ctl.h"
 
 typedef                struct  _ContentTYPE{
@@ -18,134 +21,83 @@ typedef            struct  _ContentTYPE{
 
 #define                CAT_COUNT               16
 static  CONTENT_TYPE   ContentCatList[CAT_COUNT] = {
-       { "¥Ë¥å¡¼¥¹¡¦ÊóÆ»", "news" },
-       { "¥¹¥Ý¡¼¥Ä", "sports" },
-       { "¾ðÊó", "information" },
-       { "¥É¥é¥Þ", "drama" },
-       { "²»³Ú", "music" },
-       { "¥Ð¥é¥¨¥Æ¥£", "variety" },
-       { "±Ç²è", "cinema" },
-       { "¥¢¥Ë¥á¡¦Æû£", "anime" },
-       { "¥É¥­¥å¥á¥ó¥¿¥ê¡¼¡¦¶µÍÜ", "documentary" },
-       { "±é·à", "stage" },
-       { "¼ñÌ£¡¦¼ÂÍÑ", "hobby" },
-       { "Ê¡»ã", "etc" },                      //Ê¡»ã
-       { "ͽÈ÷", "etc" }, //ͽÈ÷
-       { "ͽÈ÷", "etc" }, //ͽÈ÷
-       { "ͽÈ÷", "etc" }, //ͽÈ÷
-       { "¤½¤Î¾", "etc" } //¤½¤Î¾
-};
-typedef struct _TAG_STATION
-{
-       char    *name;
-       char    *ontv;
-       int             tsId;           // OriginalNetworkID
-       int             onId;           // TransportStreamID
-       int             svId;           // ServiceID
-} STATION;
-
-static STATION bsSta[] = {
-       { "NHK BS1", "3001.ontvjapan.com", 16625, 4, 101},
-       { "NHK BS2", "3002.ontvjapan.com", 16625, 4, 102},
-       { "NHK BSh", "3003.ontvjapan.com", 16626, 4, 103},
-       { "BSÆü¥Æ¥ì", "3004.ontvjapan.com", 16592, 4, 141},
-       { "BSÄ«Æü", "3005.ontvjapan.com", 16400, 4, 151},
-       { "BS-i", "3006.ontvjapan.com", 16401, 4, 161},
-       { "BS¥¸¥ã¥Ñ¥ó", "3007.ontvjapan.com", 16433, 4, 171},
-       { "BS¥Õ¥¸", "3008.ontvjapan.com", 16593, 4, 181},
-       { "WOWOW", "3009.ontvjapan.com", 16432, 4, 191},
-       { "WOWOW2", "3010.ontvjapan.com", 16432, 4, 192},
-       { "WOWOW3", "3011.ontvjapan.com", 16432, 4, 193},
-       { "BS11", "3013.ontvjapan.com", 16528, 4, 211},
-       { "TwellV", "3014.ontvjapan.com", 16530, 4, 222},
+       { "ニュース・報道", "news" },
+       { "スポーツ", "sports" },
+       { "情報", "information" },
+       { "ドラマ", "drama" },
+       { "音楽", "music" },
+       { "バラエティ", "variety" },
+       { "映画", "cinema" },
+       { "アニメ・特撮", "anime" },
+       { "ドキュメンタリー・教養", "documentary" },
+       { "演劇", "stage" },
+       { "趣味・実用", "hobby" },
+       { "福祉", "etc" },                    //福祉
+       { "予備", "etc" }, //予備
+       { "予備", "etc" }, //予備
+       { "予備", "etc" }, //予備
+       { "その他", "etc" } //その他
 };
 
-static int bsStaCount = sizeof(bsSta) / sizeof (STATION);
-
-
-
-static STATION csSta[] = {
-       { "¥¹¥¿¡¼£ã£è¥×¥é¥¹", "1002.ontvjapan.com", 24608, 6, 237},
-       { "ÆüËܱDzèÀìÌç£ã£è£È£Ä", "1086.ontvjapan.com", 24608, 6, 239},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£Ã£Ó£È£Ä", "306ch.epgdata.ontvjapan", 24608, 6, 306},
-       { "¥·¥ç¥Ã¥×¥Á¥ã¥ó¥Í¥ë", "1059.ontvjapan.com", 24704, 6, 55},
-       { "¥­¥Ã¥º¥¹¥Æ¡¼¥·¥ç¥ó£È£Ä", "335ch.ontvjapan.com", 24704, 6, 335},
-       { "¥¶¡¦¥·¥Í¥Þ", "1217.ontvjapan.com", 24736, 6, 228},
-       { "¥¹¥«¥Á¥ã¥ó£È£Ä£¸£°£°", "800ch.epgdata.ontvjapan", 24736, 6, 800},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£±", "801ch.epgdata.ontvjapan", 24736, 6, 801},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£²", "802ch.epgdata.ontvjapan", 24736, 6, 802},
-       { "£å£²¥×¥í¥â", "100ch.epgdata.ontvjapan", 28736, 7, 100},
-       { "¥¤¥ó¥¿¡¼¥í¡¼¥«¥ë£Ô£Ö", "194ch.epgdata.ontvjapan", 28736, 7, 194},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£Å£Ó£Ð£Î", "1025.ontvjapan.com", 28736, 7, 256},
-       { "£Æ£Ï£Ø", "1016.ontvjapan.com", 28736, 7, 312},
-       { "¥¹¥Ú¡¼¥¹¥·¥ã¥ï¡¼£Ô£Ö", "1018.ontvjapan.com", 28736, 7, 322},
-       { "¥«¡¼¥È¥¥¡¼¥ó¡¡¥Í¥Ã¥È", "1046.ontvjapan.com", 28736, 7, 331},
-       { "¥È¥¥¡¼¥ó¡¦¥Ç¥£¥º¥Ë¡¼", "1213.ontvjapan.com", 28736, 7, 334},
-       { "Åì±Ç¥Á¥ã¥ó¥Í¥ë", "1010.ontvjapan.com", 28768, 7, 221},
-       { "±ÒÀ±·à¾ì", "1005.ontvjapan.com", 28768, 7, 222},
-       { "¥Á¥ã¥ó¥Í¥ë£Î£Å£Ã£Ï", "1008.ontvjapan.com", 28768, 7, 223},
-       { "Íβè¡ú¥·¥Í¥Õ¥£¥ë", "1009.ontvjapan.com", 28768, 7, 224},
-       { "¥¹¥¿¡¼¡¦¥¯¥é¥·¥Ã¥¯", "1003.ontvjapan.com", 28768, 7, 238},
-       { "»þÂå·àÀìÌç¥Á¥ã¥ó¥Í¥ë", "1133.ontvjapan.com", 28768, 7, 292},
-       { "¥¹¡¼¥Ñ¡¼¥É¥é¥Þ", "1006.ontvjapan.com", 28768, 7, 310},
-       { "£Á£Ø£Î", "1014.ontvjapan.com", 28768, 7, 311},
-       { "¥Ê¥·¥ç¥¸¥ª¥Á¥ã¥ó¥Í¥ë", "1204.ontvjapan.com", 28768, 7, 343},
-       { "¥ï¥ó¥Æ¥ó¥Ý¡¼¥¿¥ë", "110ch.epgdata.ontvjapan", 28864, 7, 110},
-       { "¥´¥ë¥Õ¥Á¥ã¥ó¥Í¥ë", "1028.ontvjapan.com", 28864, 7, 260},
-       { "¥Æ¥ìÄ«¥Á¥ã¥ó¥Í¥ë", "1092.ontvjapan.com", 28864, 7, 303},
-       { "£Í£Ô£Ö", "1019.ontvjapan.com", 28864, 7, 323},
-       { "¥ß¥å¡¼¥¸¥Ã¥¯¡¦¥¨¥¢", "1024.ontvjapan.com", 28864, 7, 324},
-       { "Ä«Æü¥Ë¥å¡¼¥¹¥¿¡¼", "1067.ontvjapan.com", 28864, 7, 352},
-       { "£Â£Â£Ã¥ï¡¼¥ë¥É", "1070.ontvjapan.com", 28864, 7, 353},
-       { "£Ã£Î£Î£ê", "1069.ontvjapan.com", 28864, 7, 354},
-       { "¥¸¥ã¥¹¥È¡¦¥¢¥¤", "361ch.epgdata.ontvjapan", 28864, 7, 361},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£±", "1041.ontvjapan.com", 28896, 7, 251},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£²", "1042.ontvjapan.com", 28896, 7, 252},
-       { "£Ê¥¹¥Ý¡¼¥Ä£Ð£ì£õ£ó£È", "1043.ontvjapan.com", 28896, 7, 253},
-       { "£Ç£Á£Ï£Ò£Á", "1026.ontvjapan.com", 28896, 7, 254},
-       { "£ó£ë£ù¡¦£Á¥¹¥Ý¡¼¥Ä¡Ü", "1040.ontvjapan.com", 28896, 7, 255},
-       { "ÊõÄÍ¥×¥í¥â¥Á¥ã¥ó¥Í¥ë", "101ch.epgdata.ontvjapan", 28928, 7, 101},
-       { "£Ó£Ë£Ù¡¦£Ó£Ô£Á£Ç£Å", "1207.ontvjapan.com", 28928, 7, 290},
-       { "¥Á¥ã¥ó¥Í¥ë¶ä²Ï", "305ch.epgdata.ontvjapan", 28928, 7, 305},
-       { "£Á£Ô-£Ø", "1201.ontvjapan.com", 28928, 7, 333},
-       { "¥Ò¥¹¥È¥ê¡¼¥Á¥ã¥ó¥Í¥ë", "1050.ontvjapan.com", 28928, 7, 342},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£³", "803ch.epgdata.ontvjapan", 28928, 7, 803},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£´", "804ch.epgdata.ontvjapan", 28928, 7, 804},
-       { "¥à¡¼¥Ó¡¼¥×¥é¥¹£È£Ä", "1007.ontvjapan.com", 28960, 7, 240},
-       { "¥´¥ë¥Õ¥Í¥Ã¥È¥ï¡¼¥¯", "1027.ontvjapan.com", 28960, 7, 262},
-       { "£Ì£á£Ì£á¡¡£È£Ä", "1074.ontvjapan.com", 28960, 7, 314},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£Ï£Î£Å", "1073.ontvjapan.com", 28992, 7, 307},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£Ô£×£Ï", "1072.ontvjapan.com", 28992, 7, 308},
-       { "¥¢¥Ë¥Þ¥Ã¥¯¥¹", "1047.ontvjapan.com", 28992, 7, 332},
-       { "¥Ç¥£¥¹¥«¥Ð¥ê¡¼", "1062.ontvjapan.com", 28992, 7, 340},
-       { "¥¢¥Ë¥Þ¥ë¥×¥é¥Í¥Ã¥È", "1193.ontvjapan.com", 28992, 7, 341},
-       { "£Ã-£Ô£Â£Ó¥¦¥¨¥ë¥«¥à", "160ch.epgdata.ontvjapan", 29024, 7, 160},
-       { "£Ñ£Ö£Ã", "1120.ontvjapan.com", 29024, 7, 161},
-       { "¥×¥é¥¤¥à£³£¶£µ¡¥£Ô£Ö", "185ch.epgdata.ontvjapan", 29024, 7, 185},
-       { "¥Õ¥¡¥ß¥ê¡¼·à¾ì", "1015.ontvjapan.com", 29024, 7, 293},
-       { "£Ô£Â£Ó¥Á¥ã¥ó¥Í¥ë", "3201.ontvjapan.com", 29024, 7, 301},
-       { "¥Ç¥£¥º¥Ë¡¼¥Á¥ã¥ó¥Í¥ë", "1090.ontvjapan.com", 29024, 7, 304},
-       { "MUSIC ON! TV", "1022.ontvjapan.com", 29024, 7, 325},
-       { "¥­¥Ã¥º¥¹¥Æ¡¼¥·¥ç¥ó", "1045.ontvjapan.com", 29024, 7, 330},
-       { "£Ô£Â£Ó¥Ë¥å¡¼¥¹¥Ð¡¼¥É", "1076.ontvjapan.com", 29024, 7, 351},
-       { "£Ã£ÓÆüËÜÈÖÁÈ¥¬¥¤¥É", "147ch.epgdata.ontvjapan", 29056, 7, 147},
-       { "Æü¥Æ¥ì£Ç¡Ü", "1068.ontvjapan.com", 29056, 7, 257},
-       { "fashion TV", "5004.ontvjapan.com", 29056, 7, 291},
-       { "Æü¥Æ¥ì¥×¥é¥¹", "300ch.epgdata.ontvjapan", 29056, 7, 300},
-       { "¥¨¥³¥ß¥å¡¼¥¸¥Ã¥¯£Ô£Ö", "1023.ontvjapan.com", 29056, 7, 320},
-       { "Music Japan TV", "1208.ontvjapan.com", 29056, 7, 321},
-       { "Æü¥Æ¥ì£Î£Å£×£Ó£²£´", "2002.ontvjapan.com", 29056, 7, 350},
-};
 
-static int csStaCount = sizeof(csSta) / sizeof (STATION);
 SVT_CONTROL    *svttop = NULL;
-#define                SECCOUNT        4
+#define                SECCOUNT        64
 char   title[1024];
 char   subtitle[1024];
 char   desc[102400] = {0};
 char   Category[1024];
 char   ServiceName[1024];
-iconv_t        cd ;
+char   Logo[8192];
+static unsigned char *base64 = (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static void base64_char(unsigned long bb, int srclen, unsigned char *dest, int j)
+{
+       int x, i, base;
+
+       /* 最終位置の計算 */
+       for ( i = srclen; i < 2; i++ ) 
+               bb <<= 8;
+
+       /* BASE64変換 */
+       for ( base = 18, x = 0; x < srclen + 2; x++, base -= 6) {
+               dest[j++] = base64[ (unsigned long)((bb>>base) & 0x3F) ];
+       }
+
+       /* 端数の判断 */
+       for ( i = x; i < 4; i++ ) {
+               dest[j++] = (unsigned char)'=';         /* 端数 */
+       }
+       
+}
+
+static void base64_encode(unsigned char *dest, const unsigned char *src, int len)
+{
+       unsigned char *p = src;
+       unsigned long bb = (unsigned long)0;
+       int i = 0, j = 0;
+
+       while (len--)
+       {
+               bb <<= 8;
+               bb |= (unsigned long)*p;
+
+               /* 24bit単位に編集 */
+               if (i == 2) {
+                       base64_char(bb, i, dest, j);
+
+                       j = j + 4;
+                       i = 0;
+                       bb = 0;
+               } else
+                       i++;
+
+               p++;
+       }
+
+       /* 24bitに満たない場合 */
+       if (i) base64_char(bb, i - 1, dest, j);
+
+}
 
 void   xmlspecialchars(char *str)
 {
@@ -158,27 +110,67 @@ void      xmlspecialchars(char *str)
 
 
 
-void   GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)
+void   GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, 
+       int count, STATION **station, int * station_count, char *header, int is_bs_cs)
 {
        SECcache  *bsecs;
+       int pmtpids[SECCOUNT];
+       memset(pmtpids, 0, sizeof(pmtpids));
+       int dsmccpids[SECCOUNT];
+       memset(dsmccpids, 0, sizeof(dsmccpids));
+       int i = 0;
 
        while((bsecs = readTS(infile, secs, count)) != NULL) {
+               /* PAT */
+               if(is_bs_cs && (bsecs->pid & 0xFF) == 0x00) {
+                       dumpPAT(bsecs->buf, secs, count, pmtpids);
+               }
                /* SDT */
-               if((bsecs->pid & 0xFF) == 0x11) {
-                       dumpSDT(bsecs->buf, svttop);
+               else if((bsecs->pid & 0xFF) == 0x11) {
+                       dumpSDT(bsecs->buf, svttop, station, station_count, header);
+               }
+               /* TOT */
+               else if((bsecs->pid & 0xFF) == 0x14) {
+                       dumpTOT(bsecs->buf);
+               }
+               /* SDTT */
+               else if((bsecs->pid & 0xFF) == 0x23) {
+                       dumpSDTT(bsecs->buf, *station, *station_count);
+               }
+               /* CDT */
+               else if((bsecs->pid & 0xFF) == 0x29) {
+                       dumpCDT(bsecs->buf, *station, *station_count);
+               }
+               else if ( is_bs_cs ) {
+                       for ( i = 1; i < SECCOUNT; i++ ) {
+                               if ( pmtpids[i] == 0 ) {
+                                       break;
+                               }
+                               /* PMT specified by PAT */
+                               if ( bsecs->pid == pmtpids[i] ) {
+                                       dumpPMT(bsecs->buf, secs, count, dsmccpids);
+                               }
+                       }
+
+                       for ( i = 0; i < SECCOUNT; i++ ) {
+                               if ( dsmccpids[i] == 0 ) {
+                                       break;
+                               }
+                               /* DSM-CC specified by PMT */
+                               if ( bsecs->pid == dsmccpids[i] ) {
+                                       dumpDSMCC(bsecs->buf, *station, *station_count);
+                               }
+                       }
                }
        }
 }
-void   GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int count)
+
+void   GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs)
 {
        SECcache  *bsecs;
        EIT_CONTROL     *eitcur ;
        EIT_CONTROL     *eitnext ;
        EIT_CONTROL     *eittop = NULL;
-       char    *outptr ;
-       char    *inptr ;
-       size_t  ilen;
-       size_t  olen;
        time_t  l_time ;
        time_t  end_time ;
        struct  tm      tl ;
@@ -186,6 +178,11 @@ void       GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int coun
        char    cendtime[32];
        char    cstarttime[32];
 
+       memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
+       secs[0].pid = 0x12; /* EIT  */
+       secs[1].pid = 0x26; /* EIT  */
+       secs[2].pid = 0x27; /* EIT  */
+
        eittop = calloc(1, sizeof(EIT_CONTROL));
        eitcur = eittop ;
        fseek(infile, 0, SEEK_SET);
@@ -208,38 +205,22 @@ void      GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int coun
                if(eitcur->content_type > CAT_COUNT){
                        eitcur->content_type = CAT_COUNT -1 ;
                }
-               outptr = title ;
                memset(title, '\0', sizeof(title));
-               ilen = strlen(eitcur->title);
-               olen = sizeof(title);
-               inptr = eitcur->title;
-               iconv(cd, &inptr, &ilen, &outptr, &olen);
+               strcpy(title, eitcur->title);
                xmlspecialchars(title);
 
                memset(subtitle, '\0', sizeof(subtitle));
-               ilen = strlen(eitcur->subtitle);
-               olen = sizeof(subtitle);
-               outptr = subtitle ;
-               inptr = eitcur->subtitle;
-               iconv(cd, &inptr, &ilen, &outptr, &olen);
+               strcpy(subtitle, eitcur->subtitle);
                xmlspecialchars(subtitle);
 
                memset(desc, '\0', sizeof(desc));
                if ( eitcur->desc ) {
-                       ilen = strlen(eitcur->desc);
-                       olen = sizeof(desc);
-                       outptr = desc ;
-                       inptr = eitcur->desc;
-                       iconv(cd, &inptr, &ilen, &outptr, &olen);
+                       strcpy(desc, eitcur->desc);
                        xmlspecialchars(desc);
                }
 
                memset(Category, '\0', sizeof(Category));
-               ilen = strlen(ContentCatList[eitcur->content_type].japanese);
-               olen = sizeof(Category);
-               outptr = Category ;
-               inptr = ContentCatList[eitcur->content_type].japanese;
-               iconv(cd, &inptr, &ilen, &outptr, &olen);
+               strcpy(Category, ContentCatList[eitcur->content_type].japanese);
                xmlspecialchars(Category);
 
                tl.tm_sec = eitcur->ss ;
@@ -254,7 +235,7 @@ void        GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int coun
                l_time = mktime(&tl);
                if((eitcur->ehh == 0) && (eitcur->emm == 0) && (eitcur->ess == 0)){
                        (void)time(&l_time);
-                       end_time = l_time + (60 * 5);           // £µÊ¬¸å¤ËÀßÄê
+                       end_time = l_time + (60 * 5);           // 5分後に設定
                endtl = localtime(&end_time);
                }else{
                        end_time = l_time + eitcur->ehh * 3600 + eitcur->emm * 60 + eitcur->ess;
@@ -264,24 +245,22 @@ void      GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int coun
                memset(cstarttime, '\0', sizeof(cstarttime));
                strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
                strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
-#if 1
-               fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\">\n", 
-                               cstarttime, cendtime, psta->ontv);
+               fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\" event=\"%d\">\n",    
+                               cstarttime, cendtime, psta->ontv, eitcur->event_id);
                fprintf(outfile, "    <title lang=\"ja_JP\">%s</title>\n", title);
                fprintf(outfile, "    <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
                fprintf(outfile, "    <longdesc lang=\"ja_JP\">%s</longdesc>\n", desc);
                fprintf(outfile, "    <category lang=\"ja_JP\">%s</category>\n", Category);
-//             fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
+               //fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
                fprintf(outfile, "  </programme>\n");
-#else
+#if 0
                fprintf(outfile, "(%x:%x:%x)%s,%s,%s,%s,%s,%s\n",
                                        eitcur->servid, eitcur->table_id, eitcur->event_id,
                                        cstarttime, cendtime,
                                        title, subtitle,
                                        Category,
                                        ContentCatList[eitcur->content_type].english);
-#endif
-#if 0
+
                fprintf(outfile, "(%x:%x)%04d/%02d/%02d,%02d:%02d:%02d,%02d:%02d:%02d,%s,%s,%s,%s\n",
                                        eitcur->table_id, eitcur->event_id,
                                        eitcur->yy, eitcur->mm, eitcur->dd,
@@ -300,75 +279,195 @@ void     GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs, int coun
        free(eittop);
        eittop = NULL;
 }
+void checkSta_BS(STATION **station,int *stalength){
+       STATION *statmp;
+       int chl[30];
+       int chlt=0;
+       int stal=0;
+       STATION * statin= *station;
+       statmp=malloc(sizeof(STATION)*2);
+       for (int i=0;i<*stalength;i++){
+               int noidinchl=1;
+               for (int j=0;j<chlt;j++){
+                       if (chl[j]==statin[i].svId || statin[i].svId >= 290){
+                               noidinchl=0;
+                       }
+               }
+               if (noidinchl==1){
+                       statmp=realloc(statmp,(stal+1)*sizeof(STATION));
+                       statmp[stal]=statin[i];
+                       //memcpy(statmp[stal-1],station[i],sizeof(STATION));
+                       chl[chlt]=statin[i].svId;
+                       chlt++;
+                       stal++;
+               }
+       }
+       //*station=realloc(station,(stal+1)*sizeof(STATION));
+       //memcpy(*station,statmp,(stal+1)*sizeof(STATION));
+       *station=statmp;
+       *stalength=stal;
+       //memcpy(statin,statmp,chlt*sizeof(STATION));
+       //free(statmp);
+}
+
+void checkSta(STATION **station,int *stalength){
+       STATION *statmp;
+       int chl[90];
+       int chlt=0;
+       int stal=0;
+       STATION * statin= *station;
+       statmp=malloc(sizeof(STATION)*2);
+       for (int i=0;i<*stalength;i++){
+               int noidinchl=1;
+               for (int j=0;j<chlt;j++){
+                       if (chl[j]==statin[i].svId){
+                               noidinchl=0;
+                       }
+               }
+               if (noidinchl==1){
+                       statmp=realloc(statmp,(stal+1)*sizeof(STATION));
+                       statmp[stal]=statin[i];
+                       //memcpy(statmp[stal-1],station[i],sizeof(STATION));
+                       chl[chlt]=statin[i].svId;
+                       chlt++;
+                       stal++;
+               }
+       }
+       *station=statmp;
+       *stalength=stal;//ここいらが怪しい
+       //memcpy(statin,statmp,chlt*sizeof(STATION));
+       //free(statmp);
+       return;
+}
 int main(int argc, char *argv[])
 {
 
        FILE *infile = stdin;
        FILE *outfile = stdout;
-       int             arg_maxcount = 1 ;
        char    *arg_onTV ;
-       int   mode = 1;
        int             staCount ;
-       int   eitcnt;
-       char *file;
        int   inclose = 0;
        int   outclose = 0;
-       int             flag = 0 ;
        SVT_CONTROL     *svtcur ;
        SVT_CONTROL     *svtsave ;
-       char    *outptr ;
-       char    *inptr ;
-       size_t  ilen;
-       size_t  olen;
        SECcache   secs[SECCOUNT];
-       int rtn;
        int             lp ;
        STATION *pStas ;
-       int             act ;
+       int             act = 0;
+       int             i ;
 
-       /* ¶½Ì£¤Î¤¢¤ëpid¤ò»ØÄê */
+       /* 興味のあるpidを指定 */
        memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
-       secs[0].pid = 0x11;
-       secs[1].pid = 0x12;
-       secs[2].pid = 0x26;
-       secs[3].pid = 0x27;
+       secs[0].pid = 0x00; /* PAT  */
+       secs[1].pid = 0x11; /* SDT  */
+       secs[2].pid = 0x12; /* EIT  */
+       secs[3].pid = 0x23; /* SDTT */
+       secs[4].pid = 0x26; /* EIT  */
+       secs[5].pid = 0x27; /* EIT  */
+       secs[6].pid = 0x29; /* CDT  */
 
        if(argc == 4){
                arg_onTV = argv[1];
-               file = argv[2];
-               if(strcmp(file, "-")) {
-                       infile = fopen(file, "r");
+               if(strcmp(argv[2], "-")) {
+                       infile = fopen(argv[2], "r");
+                       if ( !infile) {
+                         printf( "tsFile not found.\n" );
+                         exit( -1 );
+                       }
                        inclose = 1;
                }
+               else {
+                       infile = stdin;
+               }
                if(strcmp(argv[3], "-")) {
                        outfile = fopen(argv[3], "w+");
+                       if ( !outfile) {
+                         printf( "xmlfile not found.\n" );
+                         exit( -1 );
+                       }
                        outclose = 1;
                }
+               else {
+                       outfile = stdout;
+               }
        }else{
-               fprintf(stdout, "Usage : %s /BS <tsFile> <outfile>\n", argv[0]);
-               fprintf(stdout, "Usage : %s <ontvcode> <tsFile> <outfile>\n", argv[0]);
-               fprintf(stdout, "ontvcode ¥Á¥ã¥ó¥Í¥ë¼±Ê̻ҡ£****.ontvjapan.com ¤Ê¤É\n");
-               fprintf(stdout, "/BS      BS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éBSÁ´¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
-               fprintf(stdout, "/CS      CS¥â¡¼¥É¡£°ì¤Ä¤ÎTS¤«¤éÊ£¿ô¶É¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£\n");
+               fprintf(stdout, "Usage : %s {/BS|/CS} <tsFile> <outfile>\n", argv[0]);
+               fprintf(stdout, "Usage : %s <id> <tsFile> <outfile>\n", argv[0]);
+               fprintf(stdout, "\n");
+               fprintf(stdout, "id       チャンネル識別子。地上波の物理チャンネルを与えます。\n");
+               fprintf(stdout, "/BS      BSモード。一つのTSからBS全局のデータを読み込みます。\n");
+               fprintf(stdout, "/CS      CSモード。一つのTSから複数局のデータを読み込みます。\n");
+               fprintf(stdout, "/TIME    時刻合わせモード。TSからTOT(Time Offset Table)を読み込みます。\n");
+               fprintf(stdout, "         recpt1 <任意> 10(秒以上) - | epgdump /TIME - <任意>の形で使用してください。\n");
+               fprintf(stdout, "         TOTは5秒に1回しか来ないため、recpt1に与える時間をある程度長くしてください。\n");
+/*
+               fprintf(stdout, "  ontvcode   Channel identifier (ex. ****.ontvjapan.com)\n");
+               fprintf(stdout, "  /BS        BS mode\n");
+               fprintf(stdout, "               This mode reads the data of all BS TV stations\n");
+               fprintf(stdout, "               from one TS data.\n");
+               fprintf(stdout, "  /CS        CS mode\n");
+               fprintf(stdout, "               This mode reads the data of two or more CS TV stations\n");
+               fprintf(stdout, "               from one TS data.\n");
+*/
                return 0;
        }
 
        if(strcmp(arg_onTV, "/BS") == 0){
-               pStas = bsSta;
-               staCount = bsStaCount;
+               STATION *sta = NULL;
+               int sta_count = 0;
+               svttop = calloc(1, sizeof(SVT_CONTROL));
+               char *head="BS";
+               GetSDT(infile, svttop, secs, SECCOUNT,&sta, &sta_count, head, 1);
+               checkSta_BS(&sta,&sta_count);
+               pStas = sta;
+               staCount = sta_count;
+               //staCount = sizeof(pStas) / sizeof (STATION);
                act = 0 ;
        }else if(strcmp(arg_onTV, "/CS") == 0){
-               pStas = csSta;
-               staCount = csStaCount;
+               STATION *sta=NULL;
+               int sta_count = 0;
+               svttop = calloc(1, sizeof(SVT_CONTROL));
+               char *head="CS";
+               GetSDT(infile, svttop, secs, SECCOUNT,&sta, &sta_count, head, 1);
+               checkSta(&sta,&sta_count);
+               pStas = sta;
+               staCount = sta_count;
+               //staCount=sizeof(pStas) / sizeof (STATION);
+               act = 0 ;
+       }else if(strcmp(arg_onTV, "/TEST") == 0){
+               STATION *sta=NULL;
+               int sta_count = 0;
+               svttop = calloc(1, sizeof(SVT_CONTROL));
+               char *head="TEST";
+               GetSDT(infile, svttop, secs, SECCOUNT,&sta, &sta_count, head, 0);
+               checkSta(&sta,&sta_count);
+               //if (sta_count) 
+               printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
+               pStas = sta;
+               staCount = sta_count;// sizeof(pStas) / sizeof (STATION);
                act = 0 ;
+       }else if(strcmp(arg_onTV, "/TIME") == 0){
+               printf("TSに載っている時刻データは2秒ほど早めてあるのかもしれません。\n");
+               memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
+               secs[0].pid = 0x14; /* TOT  */
+
+               GetSDT(infile, NULL, secs, SECCOUNT,NULL, NULL,NULL, 0);
+               act = 0 ;
+
+               goto cleanup;
        }else{
+               if(infile == NULL){
+                       fprintf(stderr, "Can't open file: %s\n", argv[2]);
+                       return 1;
+               }
+               /*
                act = 1 ;
                svttop = calloc(1, sizeof(SVT_CONTROL));
                GetSDT(infile, svttop, secs, SECCOUNT);
-               svtcur = svttop->next ; //ÀèƬ
+               svtcur = svttop->next ; //先頭
                if(svtcur == NULL){
                        free(svttop);
-                       return ;
+                       return 1;
                }
 
                pStas = calloc(1, sizeof(STATION));
@@ -378,41 +477,58 @@ int main(int argc, char *argv[])
                pStas->ontv = arg_onTV ;
                pStas->name = svtcur->servicename ;
                staCount = 1;
+               */
+
+               // 地上波のマルチチャンネル対応のため
+               STATION *sta = NULL;
+               int sta_count = 0;
+               svttop = calloc(1, sizeof(SVT_CONTROL));
+               //char *head=arg_onTV;
+               GetSDT(infile, svttop, secs, SECCOUNT, &sta, &sta_count, arg_onTV, 0);
+               checkSta(&sta, &sta_count);
+               //if (sta_count) printf("Station count: %d\n1st ontv=%s,name=%s\n",sta_count, sta[0].ontv, sta[0].name);
+               pStas = sta;
+               staCount = sta_count;// sizeof(pStas) / sizeof (STATION);
+               act = 0 ;
        }
 
        fprintf(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
        fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
 
-       cd = iconv_open("UTF-8", "EUC-JP");
        for(lp = 0 ; lp < staCount ; lp++){
                memset(ServiceName, '\0', sizeof(ServiceName));
-               ilen = strlen(pStas[lp].name);
-               olen = sizeof(ServiceName);
-               outptr = ServiceName ;
-               inptr = pStas[lp].name ;
-               iconv(cd, &inptr, &ilen, &outptr, &olen);
+               strcpy(ServiceName, pStas[lp].name);
                xmlspecialchars(ServiceName);
 
                fprintf(outfile, "  <channel id=\"%s\">\n", pStas[lp].ontv);
                fprintf(outfile, "    <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
+
+               memset(Logo, '\0', sizeof(Logo));
+               for ( i = 0 ; i < 6 ; i++) {
+                       if (pStas[lp].logo_array[i].logo) {
+                               base64_encode(Logo, pStas[lp].logo_array[i].logo, pStas[lp].logo_array[i].logo_size);
+                               xmlspecialchars(Logo);
+                               fprintf(outfile, "    <logo id=\"%02d\">%s</logo>\n", i, Logo);
+                       }
+               }
+
                fprintf(outfile, "  </channel>\n");
        }
        for(lp = 0 ; lp < staCount ; lp++){
-               GetEIT(infile, outfile, &pStas[lp], secs, SECCOUNT);
+               GetEIT(infile, outfile, &pStas[lp], secs);
        }
        fprintf(outfile, "</tv>\n");
+cleanup: 
        if(inclose) {
                fclose(infile);
        }
-
        if(outclose) {
                fclose(outfile);
        }
-       iconv_close(cd);
        if(act){
                free(pStas);
-               svtcur = svttop ;       //ÀèƬ
+               svtcur = svttop ;       //先頭
                while(svtcur != NULL){
                        svtsave = svtcur->next ;
                        free(svtcur);
diff --git a/epgdump/psi.c b/epgdump/psi.c
new file mode 100644 (file)
index 0000000..bfeaeda
--- /dev/null
@@ -0,0 +1,203 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "psi.h"
+
+int parsePAThead(unsigned char *data, PAThead *path) {
+       int boff = 0;
+
+       memset(path, 0, sizeof(PAThead));
+
+       path->table_id = getBit(data, &boff, 8);
+       path->section_syntax_indicator = getBit(data, &boff, 1);
+       path->zero = getBit(data, &boff, 1);
+       path->reserved1 = getBit(data, &boff, 2);
+       path->section_length = getBit(data, &boff, 12);
+       path->transport_stream_id = getBit(data, &boff, 16);
+       path->reserved2 = getBit(data, &boff, 2);
+       path->version_number = getBit(data, &boff, 5);
+       path->current_next_indicator = getBit(data, &boff, 1);
+       path->section_number = getBit(data, &boff, 8);
+       path->last_section_number = getBit(data, &boff, 8);
+
+       return 8;
+}
+
+int parsePATbody(unsigned char *data, PATbody *patb) {
+       int boff = 0;
+
+       memset(patb, 0, sizeof(PATbody));
+
+       patb->program_number = getBit(data, &boff, 16);
+       patb->reserved = getBit(data, &boff, 3);
+       if ( patb->program_number == 0 ) {
+               patb->network_PID = getBit(data, &boff, 13);
+       }
+       else {
+               patb->program_map_PID = getBit(data, &boff, 13);
+       }
+
+       return 4;
+}
+
+void dumpPAT(unsigned char *ptr, SECcache *secs, int count, int *pmtpids)
+{
+       int len = 0;
+       int loop_len = 0;
+       int i;
+
+       PAThead path;
+       PATbody patb;
+
+       /* PAT */
+       len = parsePAThead(ptr, &path);
+       ptr += len;
+
+       // printf("PAT=()\n");
+
+       loop_len = path.section_length;
+       while ( loop_len > 0 ) {
+               len = parsePATbody(ptr, &patb);
+               ptr += len;
+               loop_len -= len;
+
+               if ( patb.program_number != 0 ) {
+                       for ( i = 1; i < count; i++ ) {
+                               if ( secs[i].pid == patb.program_map_PID ) {
+                                       break;
+                               }
+                               if ( secs[i].pid == 0 ) {
+                                       // printf("PAT: Adding PID(0x%04x) to secs[%d]\n", patb.program_map_PID, i);
+                                       secs[i].pid = patb.program_map_PID;
+                                       break;
+                               }
+                       }
+                       for ( i = 0; i < count; i++ ) {
+                               if ( pmtpids[i] == patb.program_map_PID ) {
+                                       break;
+                               }
+                               if ( pmtpids[i] == 0 ) {
+                                       // printf("PAT: Adding PID(0x%04x) to pmtpids[%d]\n", patb.program_map_PID, i);
+                                       pmtpids[i] = patb.program_map_PID;
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       return;
+}
+
+int parsePMThead(unsigned char *data, PMThead *pmth) {
+       int boff = 0;
+
+       memset(pmth, 0, sizeof(PMThead));
+
+       pmth->table_id = getBit(data, &boff, 8);
+       pmth->section_syntax_indicator = getBit(data, &boff, 1);
+       pmth->zero = getBit(data, &boff, 1);
+       pmth->reserved1 = getBit(data, &boff, 2);
+       pmth->section_length = getBit(data, &boff, 12);
+       pmth->program_number = getBit(data, &boff, 16);
+       pmth->reserved2 = getBit(data, &boff, 2);
+       pmth->version_number = getBit(data, &boff, 5);
+       pmth->current_next_indicator = getBit(data, &boff, 1);
+       pmth->section_number = getBit(data, &boff, 8);
+       pmth->last_section_number = getBit(data, &boff, 8);
+       pmth->reserved3 = getBit(data, &boff, 3);
+       pmth->PCR_PID = getBit(data, &boff, 13);
+       pmth->reserved4 = getBit(data, &boff, 4);
+       pmth->program_info_length = getBit(data, &boff, 12);
+
+       return 12;
+}
+
+int parsePMTbody(unsigned char *data, PMTbody *pmtb) {
+       int boff = 0;
+
+       memset(pmtb, 0, sizeof(PMTbody));
+
+       pmtb->stream_type = getBit(data, &boff, 8);
+       pmtb->reserved1 = getBit(data, &boff, 3);
+       pmtb->elementary_PID = getBit(data, &boff, 13);
+       pmtb->reserved2 = getBit(data, &boff, 4);
+       pmtb->ES_info_length = getBit(data, &boff, 12);
+
+       return 5;
+}
+
+void dumpPMT(unsigned char *ptr, SECcache *secs, int count, int *dsmccpids)
+{
+       int len = 0;
+       int loop_len = 0;
+       int desc_len = 0;
+       int i;
+
+       PMThead pmth;
+       PMTbody pmtb;
+
+       /* PMT */
+       len = parsePMThead(ptr, &pmth);
+       ptr += len;
+/*
+       printf("PMT=(%d:%d:%d:%d:%d:%d:%d:%d)\n", 
+               pmth.table_id, pmth.section_length , 
+               pmth.program_number , pmth.version_number , 
+               pmth.section_number , pmth.last_section_number , 
+               pmth.PCR_PID , pmth.program_info_length);
+*/
+       loop_len = pmth.program_info_length;
+       while ( loop_len > 0 ) {
+               len = parseOTHERdesc(ptr);
+               ptr += len;
+               loop_len -= len;
+       }
+
+       loop_len = pmth.section_length - pmth.program_info_length - 13;// 9はヘッダ長 4はCRC
+       while ( loop_len > 0 ) {
+               len = parsePMTbody(ptr, &pmtb);
+               ptr += len;
+               loop_len -= len;
+/*
+               printf("PMTb=(0x%x:%d:%d)\n", 
+                       pmtb.stream_type , pmtb.elementary_PID , pmtb.ES_info_length);
+*/
+               if ( pmtb.stream_type == 0x0B || pmtb.stream_type == 0x0D ) {
+                       for ( i = 1; i < count; i++ ) {
+                               if ( secs[i].pid == pmtb.elementary_PID ) {
+                                       break;
+                               }
+                               if ( secs[i].pid == 0 ) {
+                                       printf("PMT: Adding PID(0x%04x) to secs[%d]\n", pmtb.elementary_PID, i);
+                                       secs[i].pid = pmtb.elementary_PID;
+                                       break;
+                               }
+                       }
+                       for ( i = 0; i < count; i++ ) {
+                               if ( dsmccpids[i] == pmtb.elementary_PID ) {
+                                       break;
+                               }
+                               if ( dsmccpids[i] == 0 ) {
+                                       printf("PMT: Adding PID(0x%04x) to dsmccpids[%d]\n", pmtb.elementary_PID, i);
+                                       dsmccpids[i] = pmtb.elementary_PID;
+                                       break;
+                               }
+                       }
+               }
+
+               desc_len = pmtb.ES_info_length;
+               loop_len -= desc_len;
+
+               while ( desc_len > 0 ) {
+                       len = parseOTHERdesc(ptr);
+                       ptr += len;
+                       desc_len -= len;
+               }
+       }
+
+       return;
+}
+
diff --git a/epgdump/psi.h b/epgdump/psi.h
new file mode 100644 (file)
index 0000000..fa00c1d
--- /dev/null
@@ -0,0 +1,71 @@
+#ifndef PSI_H
+#define PSI_H 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ts.h"
+#include "util.h"
+
+typedef struct _PAThead {
+       unsigned char table_id;
+       int  section_syntax_indicator;
+       int  zero;
+       int  reserved1;
+       int  section_length;
+       int  transport_stream_id;
+       int  reserved2;
+       int  version_number;
+       int  current_next_indicator;
+       int  section_number;
+       int  last_section_number;
+} PAThead;
+
+typedef struct _PATbody {
+       int  program_number;
+       int  reserved;
+       int  network_PID;
+       int  program_map_PID;
+} PATbody;
+
+typedef struct _PMThead {
+       int  table_id;
+       int  section_syntax_indicator;
+       int  zero;
+       int  reserved1;
+       int  section_length;
+       int  program_number;
+       int  reserved2;
+       int  version_number;
+       int  current_next_indicator;
+       int  section_number;
+       int  last_section_number;
+       int  reserved3;
+       int  PCR_PID;
+       int  reserved4;
+       int  program_info_length;
+} PMThead;
+
+typedef struct _PMTbody {
+       int  stream_type;
+       int  reserved1;
+       int  elementary_PID;
+       int  reserved2;
+       int  ES_info_length;
+} PMTbody;
+
+#ifdef __cplusplus
+extern "C"{
+#endif /* __cplusplus */
+
+       int parsePAThead(unsigned char *data, PAThead *path);
+       int parsePATbody(unsigned char *data, PATbody *patb);
+       void dumpPAT(unsigned char *ptr, SECcache *secs, int count, int *pmtpids);
+       void dumpPMT(unsigned char *ptr, SECcache *secs, int count, int *dsmccpids);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
index 7727058..95df4db 100755 (executable)
@@ -17,11 +17,15 @@ Linux
 
 \8eg\97p\95û\96@\82Í\88È\89º\82Ì\92Ê\82è\82Å\82·\81B
 
-Usage : ./epgdump /BS <tsFile> <outfile>
-Usage : ./epgdump <ontvcode> <tsFile> <outfile>
-ontvcode \83`\83\83\83\93\83l\83\8b\8e¯\95Ê\8eq\81B****.ontvjapan.com \82È\82Ç
+Usage : ./epgdump {/BS|/CS} <tsFile> <outfile>
+Usage : ./epgdump <id> <tsFile> <outfile>
+
+id       \83`\83\83\83\93\83l\83\8b\8e¯\95Ê\8eq\81B\92n\8fã\94g\82Ì\95¨\97\9d\83`\83\83\83\93\83l\83\8b\82ð\97^\82¦\82Ü\82·\81B
 /BS      BS\83\82\81[\83h\81B\88ê\82Â\82ÌTS\82©\82çBS\91S\8bÇ\82Ì\83f\81[\83^\82ð\93Ç\82Ý\8d\9e\82Ý\82Ü\82·\81B
 /CS      CS\83\82\81[\83h\81B\88ê\82Â\82ÌTS\82©\82ç\95¡\90\94\8bÇ\82Ì\83f\81[\83^\82ð\93Ç\82Ý\8d\9e\82Ý\82Ü\82·\81B
+/TIME    \8e\9e\8d\8f\8d\87\82í\82¹\83\82\81[\83h\81BTS\82©\82çTOT(Time Offset Table)\82ð\93Ç\82Ý\8d\9e\82Ý\82Ü\82·\81B
+         recpt1 <\94C\88Ó> 10(\95b\88È\8fã) - | epgdump /TIME - <\94C\88Ó>\82Ì\8c`\82Å\8eg\97p\82µ\82Ä\82­\82¾\82³\82¢\81B
+         TOT\82Í5\95b\82É1\89ñ\82µ\82©\97\88\82È\82¢\82½\82ß\81Arecpt1\82É\97^\82¦\82é\8e\9e\8aÔ\82ð\82 \82é\92ö\93x\92·\82­\82µ\82Ä\82­\82¾\82³\82¢\81B
 
 make\82·\82é\82Æepgdump\82ª\83r\83\8b\83h\82³\82ê\82Ü\82·\81B
 
@@ -49,6 +53,7 @@ Special Thanks:
 \81E\8ag\92£\83c\81[\83\8b\92\86\82Ì\90l
 \81E\81\9fN/E9PqspSk\8e\81
 \81EARIB(\8e\91\97¿\82Ì\96³\97¿\83_\83E\83\93\83\8d\81[\83h\82É\91Î\82µ\82Ä)
+\81E\83f\81[\83^\95ú\91\97\97p\83v\83\8d\83O\83\89\83\80\8bl\82ß\8d\87\82í\82¹ \82»\82Ì2\82Ì\95û(clt2png\82Ì\83\\81[\83X\83R\81[\83h\82ð\8eg\97p)
 
 \93®\8dì\8am\94F\8aÂ\8b«:
   Debian GNU/Linux sid
index 46a74ff..bfc3c28 100755 (executable)
@@ -1,3 +1,5 @@
+// -*- tab-width:4 -*-
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -46,10 +48,10 @@ int parseSDTbody(unsigned char *data, SDTbody *b) {
 }
 
 int parseSVCdesc(unsigned char *data, SVCdesc *desc) {
+//0x48のサービス記述子、放送局の名前などが入っているよう
        int boff = 0;
-  
-       memset(desc, 0, sizeof(SVCdesc));
 
+       memset(desc, 0, sizeof(SVCdesc));
        desc->descriptor_tag = getBit(data, &boff, 8);
        desc->descriptor_length = getBit(data, &boff, 8);
        desc->service_type = getBit(data, &boff, 8);
@@ -60,7 +62,36 @@ int parseSVCdesc(unsigned char *data, SVCdesc *desc) {
 
        return desc->descriptor_length + 2;
 }
-int            serachid(SVT_CONTROL *top, int service_id)
+
+int parseLOGdesc(unsigned char *data, LOGdesc *desc) {
+//0xC1のデジタルコピー制御記述子
+//0xCFのロゴ伝送記述子
+       int boff = 0;
+
+       memset(desc, 0, sizeof(LOGdesc));
+       desc->descriptor_tag = getBit(data, &boff, 8);
+       desc->descriptor_length = getBit(data, &boff, 8);
+       desc->logo_transmission_type = getBit(data, &boff, 8);
+       if ( desc->logo_transmission_type == 0x01 ) {
+               desc->reserved_future_use1 = getBit(data, &boff, 7);
+               desc->logo_id = getBit(data, &boff, 9);
+               desc->reserved_future_use2 = getBit(data, &boff, 4);
+               desc->logo_version = getBit(data, &boff, 12);
+               desc->download_data_id = getBit(data, &boff, 16);
+       }
+       else if ( desc->logo_transmission_type == 0x02 ) {
+               desc->reserved_future_use1 = getBit(data, &boff, 7);
+               desc->logo_id = getBit(data, &boff, 9);
+       }
+       else if ( desc->logo_transmission_type == 0x03 ) {
+               memcpy(desc->logo_char, data + boff / 8, desc->descriptor_length);
+               // getStr(desc->logo_char, data, &boff, desc->descriptor_length);
+       }
+
+       return desc->descriptor_length + 2;
+}
+
+int serachid(SVT_CONTROL *top, int service_id)
 {
        SVT_CONTROL     *cur = top ;
        while(cur != NULL){
@@ -72,7 +103,7 @@ int          serachid(SVT_CONTROL *top, int service_id)
        return 0 ;
 }
 
-void   enqueue_sdt(SVT_CONTROL *top, SVT_CONTROL *sdtptr)
+void enqueue_sdt(SVT_CONTROL *top, SVT_CONTROL *sdtptr)
 {
        SVT_CONTROL     *cur ;
 
@@ -103,64 +134,140 @@ void     enqueue_sdt(SVT_CONTROL *top, SVT_CONTROL *sdtptr)
 
 }
 
-void dumpSDT(unsigned char *ptr, SVT_CONTROL *top)
+void dumpSDT(unsigned char *ptr, SVT_CONTROL *top,STATION **station, int * station_count,char *ontvheader)
 {
 
        SDThead  sdth;
        SDTbody  sdtb;
        SVCdesc  desc;
+       LOGdesc  logd;
        SVT_CONTROL     *svtptr ;
+       STATION * pStation = *station;
        int             rc ;
 
        int len = 0;
        int loop_len = 0;
+       int desc_len = 0;
+       char sid[80];
+       int stationi = *station_count;
+       int i = 0;
 
        /* SDT */
        len = parseSDThead(ptr, &sdth); 
        ptr += len;
-       loop_len = sdth.section_length - (len - 3 + 4); // 3¤Ï¶¦Ḁ̈إåÀĹ 4¤ÏCRC
+       loop_len = sdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
        while(loop_len > 0) {
                len = parseSDTbody(ptr, &sdtb);
+               //printf("body %d - %d = %d\n",loop_len,len,loop_len - len);
                ptr += len;
                loop_len -= len;
-               parseSVCdesc(ptr, &desc);
-
-               rc = serachid(top, sdtb.service_id);
-               if(rc == 0){
-                       svtptr = calloc(1, sizeof(SVT_CONTROL));
-                       svtptr->event_id = sdtb.service_id;
-                       svtptr->original_network_id = sdth.original_network_id;
-                       svtptr->transport_stream_id = sdth.transport_stream_id;
-                       svtptr->event_id = sdtb.service_id;
-                       memcpy(svtptr->servicename, desc.service_name, strlen(desc.service_name));
-                       enqueue_sdt(top, svtptr);
+
+               desc_len = sdtb.descriptors_loop_length;
+               loop_len -= desc_len;
+               while(desc_len > 0) {
+                       if ( *ptr == 0xCF ) {
+                               len = parseLOGdesc(ptr, &logd);
+                               ptr += len;
+                               desc_len -= len;
+
+                               #if 0
+                               printf("LOG=%d,%d,%d,%d\n",
+                                       logd.logo_transmission_type, logd.logo_id, 
+                                       logd.logo_version, logd.download_data_id);
+                               #endif
+
+                               if ( logd.logo_transmission_type != 0x01 ) continue;
+                               for (i=0; i<stationi; i++) {
+                                       if ( pStation[i].svId == sdtb.service_id ) {
+                                               pStation[i].logo_download_data_id = logd.download_data_id;
+                                       }
+                               }
+
+                               continue;
+                       }
+                       else if ( *ptr != 0x48 ) {
+                               len = parseOTHERdesc(ptr);
+                               ptr += len;
+                               desc_len -= len;
+                               continue;
+                       }
+                       len = parseSVCdesc(ptr, &desc);
+                       //printf("desc %d - %d = %d\n",desc_len,len,desc_len - len);
+                       ptr += len;
+                       desc_len -= len;
+
+                       rc = serachid(top, sdtb.service_id);
+                       if(rc == 0){
+                               svtptr = calloc(1, sizeof(SVT_CONTROL));
+                               svtptr->original_network_id = sdth.original_network_id;
+                               svtptr->transport_stream_id = sdth.transport_stream_id;
+                               svtptr->event_id = sdtb.service_id;
+                               memcpy(svtptr->servicename, desc.service_name, strlen(desc.service_name));
+                               if (desc.service_type == 1){
+                                       enqueue_sdt(top, svtptr);
+
+                                       sprintf(sid, "%s_%d", ontvheader, sdtb.service_id );
+                                       for (i=0; i<stationi; i++) {
+                                               if ( !strcmp( pStation[i].ontv, sid ) ) {
+                                                       // 既に同じものが含まれるのでスキップ
+                                                       break;
+                                               }
+                                       }
+
+                                       pStation = realloc(pStation,(stationi+1)*sizeof(STATION));
+                                       if (!pStation) printf( "Realloc returned NULL!!! stationi = %d\n", stationi);
+                                       pStation[stationi].name = malloc( strlen(desc.service_name) + 1 );
+                                       pStation[stationi].ontv = malloc( strlen(sid) + 1 );
+                                       pStation[stationi].tsId = sdth.transport_stream_id;
+                                       pStation[stationi].onId = sdth.original_network_id;
+                                       pStation[stationi].svId = sdtb.service_id;
+                                       memset(pStation[stationi].logo_array, 0, sizeof(pStation[stationi].logo_array));
+
+                                       strcpy(pStation[stationi].name, desc.service_name);
+                                       strcpy(pStation[stationi].ontv, sid);
+
+                                       stationi++;
+                               }
+
 #if 0
-                       printf("SDT=%s,%d,%x,%x,%x,%x,%x,%x,%x\n",
-                               desc.service_name, sdtb.service_id, sdtb.reserved_future_use1,
-                               sdtb.EIT_user_defined_flags, sdtb.EIT_schedule_flag, sdtb.EIT_present_following_flag,
-                               sdtb.running_status, sdtb.free_CA_mode, sdtb.descriptors_loop_length);
+                               printf("STATION=%s,%d,%d,%d,%d,%d\n",
+                                       desc.service_name,sdtb.service_id,sdth.transport_stream_id,
+                                       sdth.original_network_id,sdtb.service_id,desc.service_type);
+
+                               printf("SDT=%s,%d,%x,%x,%x,%x,%x,%x,%x\n",
+                                       desc.service_name, sdtb.service_id, sdtb.reserved_future_use1,
+                                       sdtb.EIT_user_defined_flags, sdtb.EIT_schedule_flag, sdtb.EIT_present_following_flag,
+                                       sdtb.running_status, sdtb.free_CA_mode, sdtb.descriptors_loop_length);
 /*
-#else
-0x01:\83f\83W\83^\83\8bTV\83T\81[\83r\83X
-0xA5:\83v\83\8d\83\82\81[\83V\83\87\83\93\89f\91\9c\83T\81[\83r\83X
-0x0C:\83f\81[\83^\83T\81[\83r\83X
- */
-                       printf("SDT=(%x:%x)%s,%d,%d,%d,%d,%d(%d,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x)\n",
-                                       sdth.table_id, desc.service_type, 
-                                       desc.service_name, sdtb.service_id,
-                                       desc.descriptor_tag, desc.descriptor_length, desc.service_type,
-                                       desc.service_provider_name_length, desc.service_name_length,
-                                       sdth.table_id, sdth.section_syntax_indicator, sdth.reserved_future_use1,
-                                       sdth.reserved1, sdth.section_length, sdth.transport_stream_id,
-                                       sdth.reserved2, sdth.version_number, sdth.current_next_indicator,
-                                       sdth.section_number, sdth.last_section_number, sdth.original_network_id,
-                                       sdth.reserved_future_use2);
+0x01:デジタルTVサービス
+0xA5:プロモーション映像サービス
+0x0C:データサービス
+*/
+                               printf("SDT=(%x:%x)%s,%d,%d,%d,%d,%d(%d,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x)\n",
+                                               sdth.table_id, desc.service_type, 
+                                               desc.service_name, sdtb.service_id,
+                                               desc.descriptor_tag, desc.descriptor_length, desc.service_type,
+                                               desc.service_provider_name_length, desc.service_name_length,
+                                               sdth.table_id, sdth.section_syntax_indicator, sdth.reserved_future_use1,
+                                               sdth.reserved1, sdth.section_length, sdth.transport_stream_id,
+                                               sdth.reserved2, sdth.version_number, sdth.current_next_indicator,
+                                               sdth.section_number, sdth.last_section_number, sdth.original_network_id,
+                                               sdth.reserved_future_use2);
 #endif
+                       }
                }
-
-               ptr += sdtb.descriptors_loop_length;
+/*
+               //ptr += sdtb.descriptors_loop_length;
                loop_len -= sdtb.descriptors_loop_length;
+               
+               if (loop_len>0){
+                       ptr += sdtb.descriptors_loop_length;
+               }
+*/
        }
-  
+       *station = pStation;
+       *station_count = stationi;
+       //printf("stationi %d -",stationi);//stationi==294で落ちる
        return;
 }
+
index 81f7335..f6b877a 100755 (executable)
@@ -44,6 +44,35 @@ typedef struct _SVCdesc {
        char service_name[MAXSECLEN];
 } SVCdesc;
 
+typedef struct _LOGdesc {
+       int  descriptor_tag;
+       int  descriptor_length;
+       int  logo_transmission_type;
+       int  reserved_future_use1;
+       int  logo_id;
+       int  reserved_future_use2;
+       int  logo_version;
+       int  download_data_id;
+
+       char logo_char[MAXSECLEN];
+} LOGdesc;
+
+typedef struct _TAG_LOGO
+{
+       void    *logo;
+       int             logo_size;
+} LOGO;
+
+typedef struct _TAG_STATION
+{
+       char    *name;
+       char    *ontv;
+       int             tsId;           // OriginalNetworkID
+       int             onId;           // TransportStreamID
+       int             svId;           // ServiceID
+       unsigned int    logo_download_data_id;
+       LOGO    logo_array[6];
+} STATION;
 
 #ifdef __cplusplus
 extern "C"{
@@ -52,7 +81,7 @@ extern "C"{
        int parseSDThead(unsigned char *data, SDThead *h);
        int parseSDTbody(unsigned char *data, SDTbody *b);
        int parseSVCdesc(unsigned char *data, SVCdesc *desc);
-       void dumpSDT(unsigned char *data, SVT_CONTROL *top);
+       void dumpSDT(unsigned char *ptr, SVT_CONTROL *top, STATION **station, int * station_count, char *ontvheader);
 
 #ifdef __cplusplus
 }
diff --git a/epgdump/sdtt.c b/epgdump/sdtt.c
new file mode 100644 (file)
index 0000000..cdb2fdd
--- /dev/null
@@ -0,0 +1,290 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "sdtt.h"
+#include "ts_ctl.h"
+#include "clt2png.h"
+
+// STD-B21 p130 (144)
+int parseSDTThead(unsigned char *data, SDTThead *h) {
+       int boff = 0;
+
+       memset(h, 0, sizeof(SDTThead));
+
+       h->table_id = getBit(data, &boff, 8);
+       h->section_syntax_indicator = getBit(data, &boff, 1);
+       h->reserved_future_use1 = getBit(data, &boff, 1);
+       h->reserved1 = getBit(data, &boff, 2);
+       h->section_length = getBit(data, &boff, 12);
+       h->maker_id = getBit(data, &boff, 8);
+       h->model_id = getBit(data, &boff, 8);
+       // boff -= 16;
+       // h->table_id_ext = getBit(data, &boff, 16);
+       h->reserved2 = getBit(data, &boff, 2);
+       h->version_number = getBit(data, &boff, 5);
+       h->current_next_indicator = getBit(data, &boff, 1);
+       h->section_number = getBit(data, &boff, 8);
+       h->last_section_number = getBit(data, &boff, 8);
+       h->transport_stream_id = getBit(data, &boff, 16);
+       h->original_network_id = getBit(data, &boff, 16);
+       h->service_id = getBit(data, &boff, 16);
+       h->num_of_contents = getBit(data, &boff, 8);
+
+       return 15;
+}
+
+// STD-B21 p130 (144)
+int parseSDTTcont(unsigned char *data, SDTTcont *sdtc) {
+       int boff = 0;
+
+       memset(sdtc, 0, sizeof(SDTTcont));
+       sdtc->group = getBit(data, &boff, 4);
+       sdtc->target_version = getBit(data, &boff, 12);
+       sdtc->new_version = getBit(data, &boff, 12);
+       sdtc->download_level = getBit(data, &boff, 2);
+       sdtc->version_indicator = getBit(data, &boff, 2);
+       sdtc->content_description_length = getBit(data, &boff, 12);
+       sdtc->reserved1 = getBit(data, &boff, 4);
+       sdtc->schedule_description_length = getBit(data, &boff, 12);
+       sdtc->schedule_timeshift_information = getBit(data, &boff, 4);  
+       /*
+       for (i=0; i<sdtc->schedule_description_length / 8; i++) {
+               sdtc->start_time = getBit(data, &boff, 40);
+               sdtc->duration = getBit(data, &boff, 24);
+       }
+       */
+
+       return sdtc->schedule_description_length + 8;
+       //return sdtc->content_description_length + 8;
+}
+
+// STD-B21 p132 (146)
+int parseSDTTdesc(unsigned char *data, SDTTdesc *sdts) {
+// 0xC9(201)
+       int boff = 0;
+       int i = 0;
+       SDTTdescModule *module;
+
+       memset(sdts, 0, sizeof(SDTTdesc));
+       sdts->descriptor_tag = getBit(data, &boff, 8);
+       sdts->descriptor_length = getBit(data, &boff, 8);
+       sdts->reboot = getBit(data, &boff, 1);
+       sdts->add_on = getBit(data, &boff, 1);
+       sdts->compatibility_flag = getBit(data, &boff, 1);
+       sdts->module_info_flag = getBit(data, &boff, 1);
+       sdts->text_info_flag = getBit(data, &boff, 1);
+       sdts->reserved1 = getBit(data, &boff, 3);
+       sdts->component_size = getBit(data, &boff, 32);
+       sdts->download_id = getBit(data, &boff, 32);
+       sdts->time_out_value_DII = getBit(data, &boff, 32);
+       sdts->leak_rate = getBit(data, &boff, 22);
+       sdts->reserved2 = getBit(data, &boff,2);
+       sdts->component_tag = getBit(data, &boff, 8);
+
+       if ( sdts->compatibility_flag == 1) {
+               sdts->compatibility_length = getBit(data, &boff, 16);
+               boff += sdts->compatibility_length * 8;
+       }
+       if ( sdts->module_info_flag == 1) {
+               sdts->num_of_modules = getBit(data, &boff, 16);
+
+               if ( sdts->num_of_modules > 0 ) 
+                       sdts->modules = calloc(1, sizeof(SDTTdescModule) * ( sdts->num_of_modules + 1 ));
+
+               for (i=0; i<sdts->num_of_modules; i++) {
+                       module = sdts->modules + sizeof(SDTTdescModule) * i;// &sdts->modules[i];
+                       module->module_id = getBit(data, &boff, 16);
+                       module->module_size = getBit(data, &boff, 32);
+                       module->module_info_length = getBit(data, &boff, 8);
+                       if ( *(data + boff / 8) == 0x01 ) {
+                               /* Type 記述子 モジュールの型(MIME 形式等) */
+                               module->descriptor_tag = getBit(data, &boff, 8);
+                               module->descriptor_length = getBit(data, &boff, 8);
+                               module->Type = allocCopy(data, &boff, module->descriptor_length);
+                               module->Type[module->descriptor_length] = '\0';
+                               // +1 byte for null-terminated
+                       }
+                       else if ( *(data + boff / 8) == 0x02 ) {
+                               /* Name 記述子 モジュール名(ファイル名) */
+                               module->descriptor_tag = getBit(data, &boff, 8);
+                               module->descriptor_length = getBit(data, &boff, 8);
+                               module->Name = allocCopy(data, &boff, module->descriptor_length);
+                               module->Name[module->descriptor_length] = '\0';
+                       }
+                       else if ( *(data + boff / 8) == 0x03 ) {
+                               /* Info 記述子 モジュール情報(文字型) */
+                               module->descriptor_tag = getBit(data, &boff, 8);
+                               module->descriptor_length = getBit(data, &boff, 8);
+                               boff += 24; // ISO_639_language_code
+                               module->Info = allocCopy(data, &boff, module->descriptor_length - 3);
+                               module->Info[module->descriptor_length] = '\0';
+                       }
+                       else {
+                               module->module_info_byte = allocCopy(data, &boff, module->module_info_length);
+                       }
+               }
+       }
+       sdts->private_data_length = getBit(data, &boff, 8);
+       sdts->private_data_byte = allocCopy(data, &boff, sdts->private_data_length);
+       if ( sdts->text_info_flag == 1) {
+               sdts->ISO_639_language_code = getBit(data, &boff, 24);
+               sdts->text_length = getBit(data, &boff, 8);
+               getStr(sdts->text_char, data, &boff, sdts->text_length);
+               //sdts->text_char = allocCopy(data, &boff, sdts->text_length);
+       }
+
+       return boff / 8;
+}
+
+// STD-B21 p193 (209)
+int parseSDTTdata(unsigned char *data, SDTTdata *cdtd) {
+       int boff = 0, i, j;
+       SDTTdataLoop *loop;
+       SDTTdataService *service;
+
+       memset(cdtd, 0, sizeof(SDTTdata));
+
+       cdtd->logo_type = getBit(data, &boff, 8);
+       cdtd->number_of_loop = getBit(data, &boff, 16);
+       cdtd->loop = calloc(1, sizeof(SDTTdataLoop) * cdtd->number_of_loop);
+
+       for (i=0; i<cdtd->number_of_loop; i++) {
+               loop = cdtd->loop + sizeof(SDTTdataLoop) * i;
+
+               loop->reserved_future_use1 = getBit(data, &boff, 7);
+               loop->logo_id = getBit(data, &boff, 9);
+               loop->number_of_services = getBit(data, &boff, 8);
+               loop->services = calloc(1, sizeof(SDTTdataService) * loop->number_of_services);
+
+               for (j=0; j<loop->number_of_services; j++) {
+                       service = loop->services + sizeof(SDTTdataService) * j;
+                       service->original_network_id = getBit(data, &boff, 16);
+                       service->transport_stream_id = getBit(data, &boff, 16);
+                       service->service_id = getBit(data, &boff, 16);
+               }
+               loop->data_size = getBit(data, &boff, 16);
+               loop->data = allocCopy(data, &boff, loop->data_size);
+       }
+
+       return boff / 8;
+}
+
+void dumpSDTT(unsigned char *ptr, STATION *station, int station_count)
+{
+       SDTThead  sdth;
+       SDTTcont  sdtc;
+       SDTTdesc  sdts;
+       SDTTdata  sdtd;
+       SDTTdescModule *module;
+
+       int len = 0;
+       int loop_len = 0;
+       int desc_len = 0;
+       int i, j;
+
+       /* SDTT */
+       len = parseSDTThead(ptr, &sdth);
+       ptr += len;
+       loop_len = sdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
+
+       /*
+       printf("SDTT=(%d:%d:%d:%d:%d:%d:%d:%d:%d:%d)\n",
+               sdth.table_id, sdth.section_number, sdth.version_number, 
+               sdth.maker_id, sdth.model_id, 
+               sdth.transport_stream_id, sdth.original_network_id, 
+               sdth.service_id, sdth.num_of_contents, sdth.section_length);
+       */
+
+       if ( sdth.maker_id == 0xff && sdth.model_id == 0xfe )
+               printf("BS FOUND\n");
+
+       if ( sdth.maker_id == 0xff && sdth.model_id == 0xfc )
+               printf("BS/広帯域 CS FOUND\n");
+
+       if ( ! ( sdth.maker_id == 0xff && ( sdth.model_id == 0xfc || sdth.model_id == 0xfe ) ) )
+               return;
+
+       while(loop_len > 0) {
+               /*
+               logo_type
+               0x00 24x48 864  SD4:3 スモール 
+               0x01 24x36 648  SD16:9 スモール
+               0x02 27x48 972  HD スモール 
+               0x03 36x72 1296 SD4:3 ラージ 
+               0x04 36x54 972  SD16:9 ラージ 
+               0x05 36x64 1152 HD ラージ 
+               */
+
+               for (i=0; i<sdth.num_of_contents; i++) {
+                       len = parseSDTTcont(ptr, &sdtc);
+                       ptr += len;
+                       loop_len -= len;
+
+                       desc_len = sdtc.content_description_length - sdtc.schedule_description_length;
+                       loop_len -= desc_len;
+
+                       while(desc_len > 0) {
+                               if ( *ptr != 0xC9 ) {
+                                       len = parseOTHERdesc(ptr);
+                                       ptr += len;
+                                       desc_len -= len;
+                                       continue;
+                               }
+
+                               len = parseSDTTdesc(ptr, &sdts);
+                               ptr += len;
+                               desc_len -= len;
+#if 1
+                               printf("SDTTdesc %d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%s\n",
+                                       sdts.descriptor_tag, sdts.descriptor_length, 
+                                       sdts.reboot, sdts.add_on, 
+                                       sdts.compatibility_flag, sdts.module_info_flag, sdts.text_info_flag, 
+                                       sdts.component_size, sdts.download_id, sdts.time_out_value_DII, 
+                                       sdts.leak_rate, sdts.component_tag, 
+                                       sdts.text_info_flag ? sdts.text_char : "");
+#endif
+                               for (i=0; i<sdts.num_of_modules; i++) {
+                                       module = sdts.modules + sizeof(SDTTdescModule) * i;
+                                       if ( module->descriptor_tag == 0x01 ) {
+                                               printf("sdts.Type %s id:%d\n", module->Type, sdts.download_id);
+                                       }
+                                       else if ( module->descriptor_tag == 0x02 ) {
+                                               printf("sdts.Name %s id:%d\n", module->Name, sdts.download_id);
+
+                                               if ( strstr( module->Name, "CS_LOGO" ) ) {
+                                                       station[0].logo_download_data_id = sdts.download_id;
+                                               }
+                                               else if ( strstr( module->Name, "LOGO" ) ) {
+                                                       station[0].logo_download_data_id = sdts.download_id;
+                                               }
+                                       }
+                                       else if ( module->descriptor_tag == 0x03 ) {
+                                               printf("sdts.Info %s id:%d\n", module->Info, sdts.download_id);
+                                       }
+                                       else {
+                                               printf("MIB: %s\n", module->module_info_byte);
+                                       }
+                               }
+/*
+                               len = parseSDTTdata(ptr, &sdtd);
+                               ptr += len;
+                               desc_len -= len;
+*/
+#if 0
+                       printf("SDTT=(%d:%d:%d:%d:%d:%dbyte:desc%dbyte)%d,%d,%d,%d\n",
+                               cdth.table_id, cdth.download_data_id, cdth.version_number, 
+                               cdth.original_network_id, cdth.data_type, 
+                               cdth.section_length, cdth.descriptors_loop_length, 
+
+                               cdtdte.logo_type, cdtdte.logo_id, cdtdte.logo_version,
+                               cdtdte.data_size);
+#endif
+                       }
+               }
+       }
+       return;
+}
+
diff --git a/epgdump/sdtt.h b/epgdump/sdtt.h
new file mode 100644 (file)
index 0000000..65eaad9
--- /dev/null
@@ -0,0 +1,115 @@
+#ifndef SDTT_H
+#define SDTT_H 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "sdt.h"
+#include "util.h"
+#include "ts_ctl.h"
+
+typedef struct _SDTThead {
+       unsigned char table_id;
+       int  section_syntax_indicator;
+       int  reserved_future_use1;
+       int  reserved1;
+       int  section_length;
+       int  maker_id;
+       int  model_id;
+//     int  table_id_ext;
+       int  reserved2;
+       int  version_number;
+       int  current_next_indicator;
+       int  section_number;
+       int  last_section_number;
+       int  transport_stream_id;
+       int  original_network_id;
+       int  service_id;
+       int  num_of_contents;
+} SDTThead;
+
+typedef struct _SDTTcont {
+       int  group;
+       int  target_version;
+       int  new_version;
+       int  download_level;
+       int  version_indicator;
+       int  content_description_length;
+       int  reserved1;
+       int  schedule_description_length;
+       int  schedule_timeshift_information;
+} SDTTcont;
+
+typedef struct _SDTTdescModule {
+       int     module_id;
+       int     module_size;
+       int     module_info_length;
+       void    *module_info_byte;
+       int     descriptor_tag;
+       int     descriptor_length;
+       char    *Type;
+       char    *Name;
+       char    *Info;
+} SDTTdescModule;
+
+typedef struct _SDTTdesc {
+       int  descriptor_tag;
+       int  descriptor_length;
+       int  reboot;
+       int  add_on;
+       int  compatibility_flag;
+       int  compatibility_length;
+       int  module_info_flag;
+       int  text_info_flag;
+       int  reserved1;
+       int  component_size;
+       unsigned int  download_id;
+       int  time_out_value_DII;
+       int  leak_rate;
+       int  reserved2;
+       int  component_tag;
+       int  num_of_modules;
+       void  *modules;
+       int  private_data_length;
+       void  *private_data_byte;
+       int  ISO_639_language_code;
+       int  text_length;
+       //void  *text_char;
+       char text_char;
+} SDTTdesc;
+
+typedef struct _SDTTdataService {
+       int  original_network_id;
+       int  transport_stream_id;
+       int  service_id;
+} SDTTdataService;
+
+typedef struct _SDTTdataLoop {
+       int     reserved_future_use1;
+       int     logo_id;
+       int     number_of_services;
+       SDTTdataService *services;
+       int     data_size;
+       void    *data;
+} SDTTdataLoop;
+
+typedef struct _SDTTdataBC {
+       int     logo_type;
+       int     number_of_loop;
+       SDTTdataLoop    *loop;
+} SDTTdata;
+
+#ifdef __cplusplus
+extern "C"{
+#endif /* __cplusplus */
+
+       int parseSDTThead(unsigned char *data, SDTThead *h);
+       int parseSDTTdesc(unsigned char *data, SDTTdesc *sdts);
+       void dumpSDTT(unsigned char *ptr, STATION *station, int station_count);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
diff --git a/epgdump/tags b/epgdump/tags
new file mode 100644 (file)
index 0000000..5f87182
--- /dev/null
@@ -0,0 +1,113 @@
+!_TAG_FILE_FORMAT      2       /extended format; --format=1 will not append ;" to lines/
+!_TAG_FILE_SORTED      1       /0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_PROGRAM_AUTHOR   Darren Hiebert  /dhiebert@users.sourceforge.net/
+!_TAG_PROGRAM_NAME     Exuberant Ctags //
+!_TAG_PROGRAM_URL      http://ctags.sourceforge.net    /official site/
+!_TAG_PROGRAM_VERSION  5.7     //
+AribToString   aribstr.c       /^int AribToString($/;" f
+AribToStringInternal   aribstr.c       /^const DWORD AribToStringInternal(TCHAR *lpszDst, $/;" f
+BYTE   aribstr.c       28;"    d       file:
+CAT_COUNT      epgdump.c       18;"    d       file:
+CODE_ADDITIONAL_SYMBOLS        aribstr.c       24;"    d       file:
+CODE_ALPHANUMERIC      aribstr.c       11;"    d       file:
+CODE_HIRAGANA  aribstr.c       12;"    d       file:
+CODE_JIS_KANJI_PLANE_1 aribstr.c       22;"    d       file:
+CODE_JIS_KANJI_PLANE_2 aribstr.c       23;"    d       file:
+CODE_JIS_X0201_KATAKANA        aribstr.c       21;"    d       file:
+CODE_KANJI     aribstr.c       10;"    d       file:
+CODE_KATAKANA  aribstr.c       13;"    d       file:
+CODE_MOSAIC_A  aribstr.c       14;"    d       file:
+CODE_MOSAIC_B  aribstr.c       15;"    d       file:
+CODE_MOSAIC_C  aribstr.c       16;"    d       file:
+CODE_MOSAIC_D  aribstr.c       17;"    d       file:
+CODE_PROP_ALPHANUMERIC aribstr.c       18;"    d       file:
+CODE_PROP_HIRAGANA     aribstr.c       19;"    d       file:
+CODE_PROP_KATAKANA     aribstr.c       20;"    d       file:
+CODE_SET       aribstr.c       36;"    d       file:
+CODE_UNKNOWN   aribstr.c       9;"     d       file:
+CONTENT_TYPE   epgdump.c       /^}CONTENT_TYPE;$/;"    t       typeref:struct:_ContentTYPE     file:
+CalcCrc        ts.c    /^unsigned int CalcCrc(unsigned int crc, unsigned char *buf, int len) {$/;"     f
+Category       epgdump.c       /^char  Category[1024];$/;"     v
+ContentCatList epgdump.c       /^static  CONTENT_TYPE  ContentCatList[CAT_COUNT] = {$/;"       v       file:
+DWORD  aribstr.c       30;"    d       file:
+DesignationDRCS        aribstr.c       /^const bool DesignationDRCS(const BYTE byIndexG, const BYTE byCode)$/;"        f
+DesignationGSET        aribstr.c       /^const bool DesignationGSET(const BYTE byIndexG, const BYTE byCode)$/;"        f
+GetEIT epgdump.c       /^void  GetEIT(FILE *infile, FILE *outfile, SVT_CONTROL *svtcur, SECcache *secs, int count)$/;" f
+GetSDT epgdump.c       /^void  GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)$/;"        f
+LockingShiftGL aribstr.c       /^void LockingShiftGL(const BYTE byIndexG)$/;"  f
+LockingShiftGR aribstr.c       /^void LockingShiftGR(const BYTE byIndexG)$/;"  f
+ProcessCharCode        aribstr.c       /^const DWORD ProcessCharCode(TCHAR *lpszDst, const WORD wCode, const CODE_SET CodeSet)$/;"     f
+ProcessEscapeSeq       aribstr.c       /^void ProcessEscapeSeq(const BYTE byCode)$/;"  f
+PutAlphanumericChar    aribstr.c       /^const DWORD PutAlphanumericChar(TCHAR *lpszDst, const WORD wCode)$/;" f
+PutHiraganaChar        aribstr.c       /^const DWORD PutHiraganaChar(TCHAR *lpszDst, const WORD wCode)$/;"     f
+PutJisKatakanaChar     aribstr.c       /^const DWORD PutJisKatakanaChar(TCHAR *lpszDst, const WORD wCode)$/;"  f
+PutKanjiChar   aribstr.c       /^const DWORD PutKanjiChar(TCHAR *lpszDst, const WORD wCode)$/;"        f
+PutKatakanaChar        aribstr.c       /^const DWORD PutKatakanaChar(TCHAR *lpszDst, const WORD wCode)$/;"     f
+PutSymbolsChar aribstr.c       /^const DWORD PutSymbolsChar(TCHAR *lpszDst, const WORD wCode)$/;"      f
+SECCOUNT       epgdump.c       140;"   d       file:
+STATION        epgdump.c       /^} STATION;$/;"        t       typeref:struct:_TAG_STATION     file:
+ServiceName    epgdump.c       /^char  ServiceName[1024];$/;"  v
+SingleShiftGL  aribstr.c       /^void SingleShiftGL(const BYTE byIndexG)$/;"   f
+TCHAR  aribstr.c       27;"    d       file:
+TEXT   aribstr.c       34;"    d       file:
+WORD   aribstr.c       29;"    d       file:
+_ContentTYPE   epgdump.c       /^typedef               struct  _ContentTYPE{$/;"       s       file:
+_T     aribstr.c       35;"    d       file:
+_TAG_STATION   epgdump.c       /^typedef struct _TAG_STATION$/;"       s       file:
+abCharSizeTable        aribstr.c       /^static const bool abCharSizeTable[] =$/;"     v       file:
+bool   aribstr.c       31;"    d       file:
+bsSta  epgdump.c       /^static STATION bsSta[] = {$/;"        v       file:
+bsSta  xmldata.c       /^static STATION bsSta[] = {$/;"        v       file:
+bsStaCount     epgdump.c       /^static int bsStaCount = sizeof(bsSta) \/ sizeof (STATION);$/;"        v       file:
+bsStaCount     xmldata.c       /^static int bsStaCount = sizeof(bsSta) \/ sizeof (STATION);$/;"        v       file:
+cd     epgdump.c       /^iconv_t       cd ;$/;"        v
+checkEEVTDitem eit.c   /^int checkEEVTDitem(EEVTDitem *save, EEVTDitem *new, int descriptor_number) {$/;"      f
+checkcrc       ts.c    /^int checkcrc(SECcache *secs) {$/;"    f
+convertjis     aribstr.c       /^WORD convertjis(DWORD jiscode) {$/;"  f
+csSta  epgdump.c       /^static STATION csSta[] = {$/;"        v       file:
+csSta  xmldata.c       /^static STATION csSta[] = {$/;"        v       file:
+csStaCount     epgdump.c       /^static int csStaCount = sizeof(csSta) \/ sizeof (STATION);$/;"        v       file:
+csStaCount     xmldata.c       /^static int csStaCount = sizeof(csSta) \/ sizeof (STATION);$/;"        v       file:
+dumpEIT        eit.c   /^void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int transport_stream_id, EIT_CONTROL *eittop)$/;"      f
+dumpSDT        sdt.c   /^void dumpSDT(unsigned char *ptr, SVT_CONTROL *top)$/;"        f
+english        epgdump.c       /^      char    *english ;$/;"  m       struct:_ContentTYPE     file:
+enqueue        eit.c   /^void  enqueue(EIT_CONTROL *top, EIT_CONTROL *eitptr)$/;"      f
+enqueue_sdt    sdt.c   /^void  enqueue_sdt(SVT_CONTROL *top, SVT_CONTROL *sdtptr)$/;"  f
+false  aribstr.c       33;"    d       file:
+getBit util.c  /^int getBit(unsigned char *byte, int *pbit, int gbit) {$/;"    f
+getStr util.c  /^void getStr(char *tostr, unsigned char *byte, int *pbit, int len) {$/;"       f
+japanese       epgdump.c       /^      char    *japanese ;$/;" m       struct:_ContentTYPE     file:
+m_CodeG        aribstr.c       /^static int m_CodeG[4];$/;"    v       file:
+m_bIsEscSeqDrcs        aribstr.c       /^static        bool m_bIsEscSeqDrcs;$/;"       v       file:
+m_byEscSeqCount        aribstr.c       /^static        BYTE m_byEscSeqCount;$/;"       v       file:
+m_byEscSeqIndex        aribstr.c       /^static        BYTE m_byEscSeqIndex;$/;"       v       file:
+m_pLockingGL   aribstr.c       /^static int *m_pLockingGL;$/;" v       file:
+m_pLockingGR   aribstr.c       /^static int *m_pLockingGR;$/;" v       file:
+m_pSingleGL    aribstr.c       /^static int *m_pSingleGL;$/;"  v       file:
+main   epgdump.c       /^int main(int argc, char *argv[])$/;"  f
+name   epgdump.c       /^      char    *name;$/;"      m       struct:_TAG_STATION     file:
+onId   epgdump.c       /^      int             onId;           \/\/ TransportStreamID$/;"      m       struct:_TAG_STATION     file:
+ontv   epgdump.c       /^      char    *ontv;$/;"      m       struct:_TAG_STATION     file:
+parseContentDesc       eit.c   /^int parseContentDesc(unsigned char *data, ContentDesc *desc) {$/;"    f
+parseEEVTDhead eit.c   /^int parseEEVTDhead(unsigned char *data, EEVTDhead *desc) {$/;"        f
+parseEEVTDitem eit.c   /^int parseEEVTDitem(unsigned char *data, EEVTDitem *desc) {$/;"        f
+parseEEVTDtail eit.c   /^int parseEEVTDtail(unsigned char *data, EEVTDtail *desc) {$/;"        f
+parseEITbody   eit.c   /^int parseEITbody(unsigned char *data, EITbody *b) {$/;"       f
+parseEIThead   eit.c   /^int parseEIThead(unsigned char *data, EIThead *h) {$/;"       f
+parseOTHERdesc util.c  /^int parseOTHERdesc(unsigned char *data) {$/;" f
+parseSDTbody   sdt.c   /^int parseSDTbody(unsigned char *data, SDTbody *b) {$/;"       f
+parseSDThead   sdt.c   /^int parseSDThead(unsigned char *data, SDThead *h) {$/;"       f
+parseSEVTdesc  eit.c   /^int parseSEVTdesc(unsigned char *data, SEVTdesc *desc) {$/;"  f
+parseSVCdesc   sdt.c   /^int parseSVCdesc(unsigned char *data, SVCdesc *desc) {$/;"    f
+parseSeriesDesc        eit.c   /^int parseSeriesDesc(unsigned char *data, SeriesDesc *desc) {$/;"      f
+readTS ts.c    /^SECcache *readTS(FILE *in, SECcache secs[], int size) {$/;"   f
+searcheit      eit.c   /^EIT_CONTROL   *searcheit(EIT_CONTROL *top, int servid, int eventid)$/;"       f
+serachid       sdt.c   /^int           serachid(SVT_CONTROL *top, int service_id)$/;"  f
+subtitle       epgdump.c       /^char  subtitle[1024];$/;"     v
+svId   epgdump.c       /^      int             svId;           \/\/ ServiceID$/;"      m       struct:_TAG_STATION     file:
+svttop epgdump.c       /^SVT_CONTROL   *svttop = NULL;$/;"     v
+timecmp        eit.c   /^void timecmp(int *thh, int *tmm, int *tss,$/;"        f
+title  epgdump.c       /^char  title[1024];$/;"        v
+true   aribstr.c       32;"    d       file:
+tsId   epgdump.c       /^      int             tsId;           \/\/ OriginalNetworkID$/;"      m       struct:_TAG_STATION     file:
+xmlspecialchars        epgdump.c       /^void  xmlspecialchars(char *str)$/;"  f
diff --git a/epgdump/tot.c b/epgdump/tot.c
new file mode 100644 (file)
index 0000000..15c7641
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tot.h"
+#include "ts_ctl.h"
+
+int parseTOThead(unsigned char *data, TOThead *toth) {
+       int boff = 0;
+
+       memset(toth, 0, sizeof(TOThead));
+
+       toth->table_id = getBit(data, &boff, 8);
+       toth->section_syntax_indicator = getBit(data, &boff, 1);
+       toth->reserved_future_use1 = getBit(data, &boff, 1);
+       toth->reserved1 = getBit(data, &boff, 2);
+       toth->section_length = getBit(data, &boff, 12);
+       memcpy(toth->JST_time, data + boff / 8, 5);
+       boff += 40;
+       // toth->JST_time = getBit(data, &boff, 40);
+       toth->reserved2 = getBit(data, &boff, 4);
+       toth->descriptors_loop_length = getBit(data, &boff, 12);
+
+       return 10;
+}
+
+int parseTOTdesc(unsigned char *data, TOTdesc *totd) {
+       int boff = 0;
+
+       memset(totd, 0, sizeof(TOTdesc));
+
+       totd->descriptor_tag = getBit(data, &boff, 8);
+       totd->descriptor_length = getBit(data, &boff, 8);
+
+       return totd->descriptor_length + 2;
+}
+
+void dumpTOT(unsigned char *ptr)
+{
+       TOThead  toth;
+       TOTdesc  totd;
+
+       int len = 0;
+       int loop_len = 0;
+       int desc_len = 0;
+       int i = 0;
+       time_t tot;
+
+       /* TOT */
+       len = parseTOThead(ptr, &toth);
+       ptr += len;
+       loop_len = toth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
+
+       tot = parseMJD( toth.JST_time );
+       printf("TOT diff:%d[秒] %s",
+               (int)difftime( time(NULL), tot ), ctime(&tot));
+       //ptm = localtime(time(NULL));
+/*
+       desc_len = toth.descriptors_loop_length;
+       while(desc_len > 0) {
+               len = parseTOTdesc(ptr, &totd);
+               ptr += len;
+               desc_len -= len;
+       }
+*/
+       return;
+}
+
diff --git a/epgdump/tot.h b/epgdump/tot.h
new file mode 100644 (file)
index 0000000..4699370
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef TOT_H
+#define TOT_H 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "util.h"
+#include "ts_ctl.h"
+
+typedef struct _TOThead {
+       unsigned char table_id;
+       int  section_syntax_indicator;
+       int  reserved_future_use1;
+       int  reserved1;
+       int  section_length;
+       unsigned char  JST_time[5];
+       int  reserved2;
+       int  descriptors_loop_length;
+} TOThead;
+
+typedef struct _TOTdesc {
+       unsigned char  descriptor_tag;
+       int  descriptor_length;
+} TOTdesc;
+
+#ifdef __cplusplus
+extern "C"{
+#endif /* __cplusplus */
+
+       int parseTOThead(unsigned char *data, TOThead *toth);
+       int parseTOTdesc(unsigned char *data, TOTdesc *totd);
+       void dumpTOT(unsigned char *ptr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
index c6cac1c..7036bc3 100755 (executable)
@@ -22,7 +22,7 @@ SECcache *readTS(FILE *in, SECcache secs[], int size) {
        int inchar;
        int i;
 
-       /* sync¥Ð¥¤¥È¤Þ¤ÇÆɤßÈô¤Ð¤· */
+       /* syncバイトまで読み飛ばし */
        if(rcount == 0) {
                while((inchar = fgetc(in)) != EOF) {
                        if((inchar & 0xFF) == 0x47) {
@@ -38,9 +38,9 @@ SECcache *readTS(FILE *in, SECcache secs[], int size) {
 
 retry:
   
-       /* Ì᤹¤Ù¤­»Ä¤ê¤¬¤¢¤ë¤«? */
+       /* 戻すべき残りがあるか? */
        if(ridx >= 0 && secs[ridx].cont) {
-               /* ¥Ð¥Ã¥Õ¥¡¥Á¥§¥Ã¥¯ */
+               /* ã\83\90ã\83\83ã\83\95ã\82¡ã\83\81ã\82§ã\83\83ã\82¯ */
                if((secs[ridx].cur.payload[secs[ridx].curlen] & 0xFF) == 0xFF) {
                        secs[ridx].cont = 0;
                        secs[ridx].seclen = 0;
@@ -48,14 +48,14 @@ retry:
                        secs[ridx].curlen = 0;
                } else {
                        len = secs[ridx].cur.payloadlen - secs[ridx].curlen;
-                       /* Á´ÉôÀßÄêºÑ¤ß¥Á¥§¥Ã¥¯ */
+                       /* å\85¨é\83¨è¨­å®\9aæ¸\88ã\81¿ã\83\81ã\82§ã\83\83ã\82¯ */
                        if(len == 0) {
                                secs[ridx].cont = 0;
                                secs[ridx].seclen = 0;
                                secs[ridx].setlen = 0;
                                secs[ridx].curlen = 0;
                        } else {
-                               /* ¤³¤³¤Çseclen¤¬¸Ù¤ë¤è¤¦¤ËTSʬ³ä¤µ¤ì¤Æ¤¤¤ë¤Èº¤¤ë¤Ê @@
+                               /* ここでseclenが跨るようにTS分割されていると困るな @@
                                   if(secs[ridx].pid == 0x12) {
                                   int check = secs[ridx].cur.payload[secs[ridx].curlen] & 0xFF;
                                   if(!(check == 0x4E ||
@@ -67,7 +67,14 @@ retry:
                                */
        
                                boff = 12;
-                               secs[ridx].seclen = getBit(&secs[ridx].cur.payload[secs[ridx].curlen], &boff, 12) + 3; // ¥Ø¥Ã¥À
+                               secs[ridx].seclen = getBit(&secs[ridx].cur.payload[secs[ridx].curlen], &boff, 12) + 3; // ヘッダ
+                               /*
+                               if(secs[ridx].seclen > MAXSECLEN){
+                                       // セクションが MAXSECLEN より大きい時はこのセクションをスキップ
+                                       secs[ridx].cont = 0;
+                                       goto retry;
+                               }
+                               */
        
                                /*
                                  if(secs[ridx].seclen == 2334) {
@@ -75,13 +82,13 @@ retry:
                                  }
                                */
        
-                               /* TS¥Ç¡¼¥¿Ä¹-ÀßÄêºÑ¤ß¥Ç¡¼¥¿Ä¹ */
+                               /* TSデータ長-設定済みデータ長 */
                                if(secs[ridx].seclen > len) {
                                        memcpy(secs[ridx].buf, &secs[ridx].cur.payload[secs[ridx].curlen], len);
                                        secs[ridx].setlen = len;
                                        secs[ridx].curlen = 0;
                                        secs[ridx].cont   = 1;
-                                       /* ¼¡¤Î¥ì¥³¡¼¥ÉÆɤ߹þ¤ß */
+                                       /* 次のレコード読み込み */
                                } else {
                                        memcpy(secs[ridx].buf, 
                                                   &secs[ridx].cur.payload[secs[ridx].curlen], secs[ridx].seclen);
@@ -89,11 +96,11 @@ retry:
                                        secs[ridx].curlen += secs[ridx].seclen;
                                        secs[ridx].cont = 1;
 
-                                       /* CRC¤Î¥Á¥§¥Ã¥¯ */
+                                       /* CRCã\81®ã\83\81ã\82§ã\83\83ã\82¯ */
                                        if(checkcrc(&(secs[ridx]))) {
-                                               return &(secs[ridx]); /* Ìá¤ë */
+                                               return &(secs[ridx]); /* 戻る */
                                        }
-                                       goto retry; /* ¤â¤¦°ì²ó */
+                                       goto retry; /* もう一回 */
                                }
                        }
                }
@@ -102,14 +109,14 @@ retry:
        int roffset = 0;
        while(1) {
                if(fread(buf+roffset, 188-roffset, 1, in) != 1) {
-                       /* »Ä¤ê¤Î½èÍý? */
+                       /* 残りの処理? */
                        return NULL;
                }
                roffset = 0;
                rcount++;
 
                if((buf[0] & 0xFF) != 0x47) {
-                       /* ºÇ½é¤ÏbufÃæ¤Ë0x47¤¬¤¢¤ë¤«¥Á¥§¥Ã¥¯ */
+                       /* æ\9c\80å\88\9dã\81¯buf中ã\81«0x47ã\81\8cã\81\82ã\82\8bã\81\8bã\83\81ã\82§ã\83\83ã\82¯ */
                        for(i = 1; i < 188; i++) {
                                if((buf[i] & 0xFF) == 0x47) {
                                        break;
@@ -117,7 +124,7 @@ retry:
                        }
 
                        if(i < 188) {
-                               /* ¤½¤³¤«¤éºÆÆɤ߹þ¤ß¤·¤ÆÍߤ·¤¤¤Î¤Çseek */
+                               /* そこから再読み込みして欲しいのでseek */
                                //fseek(in, (188 - i) * -1, SEEK_CUR);
                                roffset = i;
                                memmove(buf, buf + i, 188 - i);
@@ -197,16 +204,17 @@ retry:
                   shall be '1', indicating that the first byte of the payload of this Transport Stream packet carries the pointer_field.
                */
                if(pk.payload_unit_start_indicator == 1) {
-                       /* pointer_field¤Ï¤¤¤é¤Ê¤¤ */
+                       /* pointer_fieldはいらない */
                        payptr += 1;
                        pk.payloadlen -= 1;
                }
+
                memset(pk.payload, 0xFF, sizeof(pk.payload));
-#if 1  /* 07/07/2009 add: */
+               /* 07/07/2009 add: */
+               //if((pk.payloadlen <= 0) || (pk.payloadlen > sizeof(pk.payload))){
                if( pk.payloadlen > sizeof(pk.payload) ){
                        continue;
                }
-#endif
                memcpy(pk.payload, payptr, pk.payloadlen);
     
                /*
@@ -219,15 +227,22 @@ retry:
                  }
                */
     
-               /* ¶½Ì£¤Î¤¢¤ëpid¤«³Îǧ */
+               /* 興味のあるpidか確認 */
                for(int i = 0;i < size; i++) {
                        if(secs[i].pid == pk.pid) {
                                secs[i].cur = pk;
-                               /* ÅÓÃæ½èÍýÃ椫ºÇ½é¤«? */
+                               /* 途中処理中か最初か? */
                                if(!secs[i].cont) {
-                                       /* ºÇ½é ¥»¥¯¥·¥ç¥óŤòÄ´¤Ù¤ë */
+                                       /* 最初 セクション長を調べる */
                                        boff = 12;
-                                       secs[i].seclen = getBit(secs[i].cur.payload, &boff, 12) + 3; // ¥Ø¥Ã¥À;
+                                       secs[i].seclen = getBit(secs[i].cur.payload, &boff, 12) + 3; // ヘッダ;
+                                       /*
+                                       if(secs[i].seclen > MAXSECLEN){
+                                               // セクション長が MAXSECLEN より長いときはこのセクションをスキップ
+                                               secs[i].cont = 0;
+                                               goto retry;
+                                       }
+                                       */
                                        /*
                                          if(secs[i].seclen == 2334) {
                                          printf("aa");
@@ -245,32 +260,32 @@ retry:
                                        secs[i].curlen = secs[i].seclen;
                                        secs[i].cont = 1;
                                        ridx = i;
-                                       /* CRC¤Î¥Á¥§¥Ã¥¯ */
+                                       /* CRCã\81®ã\83\81ã\82§ã\83\83ã\82¯ */
                                        if(checkcrc(&(secs[ridx]))) {
-                                               return &(secs[i]); /* ¼è¤ê¹ç¤¨¤ºÌá¤ë */
+                                               return &(secs[i]); /* 取り合えず戻る */
                                        }
-                                       goto retry; /* »Ä¤ê½èÍý¤Ø */
+                                       goto retry; /* 残り処理へ */
                                }
-                               /* ¥»¥¯¥·¥ç¥óĹ-ÀßÄêºÑ¤ßĹ */
+                               /* セクション長-設定済み長 */
                                len = secs[i].seclen - secs[i].setlen;
                                if(len > secs[i].cur.payloadlen) {
-                                       /* Á´ÂΞÁ÷ */
+                                       /* 全体転送 */
                                        memcpy(&secs[i].buf[secs[i].setlen], 
                                                   secs[i].cur.payload, secs[i].cur.payloadlen);
                                        secs[i].setlen += secs[i].cur.payloadlen;
                                        continue;
                                }
-                               /* ¥»¥¯¥·¥ç¥óŤλĤê¤òÀßÄê */
+                               /* セクション長の残りを設定 */
                                memcpy(&secs[i].buf[secs[i].setlen], secs[i].cur.payload, len);
                                secs[i].setlen  = secs[i].seclen;
                                secs[i].curlen += len;
                                secs[i].cont    = 1;
                                ridx = i;
-                               /* CRC¤Î¥Á¥§¥Ã¥¯ */
+                               /* CRCã\81®ã\83\81ã\82§ã\83\83ã\82¯ */
                                if(checkcrc(&(secs[ridx]))) {
                                        return &(secs[i]);
                                }
-                               goto retry; /* »Ä¤ê½èÍý¤Ø */
+                               goto retry; /* 残り処理へ */
                        }
                }
        }
@@ -278,7 +293,7 @@ retry:
        //return NULL;
 }
 
-/* BonTest/TsStream.cpp¤«¤é¤Î¥Ñ¥¯¥ê */
+/* BonTest/TsStream.cppからのパクリ */
 unsigned int CalcCrc(unsigned int crc, unsigned char *buf, int len) {
        unsigned int c = crc;
        int n;
@@ -312,17 +327,16 @@ unsigned int CalcCrc(unsigned int crc, unsigned char *buf, int len) {
 
 int checkcrc(SECcache *secs) {
 
-#if 1  /* 07/07/2009 add: °Û¾ï¾õÂÖ²óÈò¤Î¤¿¤á */
-       /* ¥»¥¯¥·¥ç¥óºÇÂçŤòĶ¤¨¤ë¤³¤È¤Ê¤É¤¢¤êÆÀ¤Ê¤¤¤Ï¤º¤À¤¬... */
+       /* 07/07/2009 add: 異常状態回避のため */
+       /* セクション最大長を超えることなどあり得ないはずだが... */
        if( secs->seclen > MAXSECLEN ){
-               /* ¤è¤¯Ê¬¤«¤é¤ó¤Î¤ÇÇË´þ¤·¤Æ¤ä¤ë */
+               /* よく分からんので破棄してやる */
                return 0;
        }
-#endif
 
-       /* ¥»¥¯¥·¥ç¥ó¤Î½ª¤ê¤ËÃÖ¤«¤ì¤ë4¥Ð¥¤¥È¤ÎCRC32¤Ï¡¢
-          CRC·×»»¤Î·ë²Ì0¤Ë¤Ê¤ë¤è¤¦¤ËÀßÄꤵ¤ì¤ë¡£
-          Ãͤ¬È¯À¸¤·¤¿¾ì¹ç¤Ï¡¢¥¨¥é¡¼¤Ê¤Î¤ÇÂоݳ°¤Ë¤¹¤ë */
+       /* セクションの終りに置かれる4バイトのCRC32は、
+          CRC計算の結果0になるように設定される。
+          値が発生した場合は、エラーなので対象外にする */
        if(CalcCrc(0xffffffffU, secs->buf, secs->seclen)) {
 //             fprintf(stderr, "tblid:0x%x CRC error\n", secs->buf[0]);
                return 0;
index 1d74dd0..098ac73 100755 (executable)
@@ -7,10 +7,10 @@ typedef       struct  _SVT_CONTROL    SVT_CONTROL;
 struct _SVT_CONTROL{
        SVT_CONTROL     *next ;
        SVT_CONTROL     *prev ;
-       int             event_id ;                      // ¥¤¥Ù¥ó¥ÈID
+       int             event_id ;                      // イベントID
        int             original_network_id ;                   // OriginalNetworkID
-       int             transport_stream_id ;                   // TransporrtStreamID
-       char    servicename[MAXSECLEN] ;                // ¥µ¡¼¥Ó¥¹Ì¾
+       int             transport_stream_id ;                   // TransportStreamID
+       char    servicename[MAXSECLEN] ;                // サービス名
 };
 
 typedef        struct  _EIT_CONTROL    EIT_CONTROL;
@@ -19,13 +19,13 @@ struct      _EIT_CONTROL{
        EIT_CONTROL     *prev ;
        int             table_id ;
        int             servid ;
-       int             event_id ;                      // ¥¤¥Ù¥ó¥ÈID
-       int             content_type ;          // ¥³¥ó¥Æ¥ó¥È¥¿¥¤¥×
-    int                yy;
-    int                mm;
-    int                dd;
-    int                hh;
-    int                hm;
+       int             event_id ;                      // イベントID
+       int             content_type ;          // コンテントタイプ
+       int             yy;
+       int             mm;
+       int             dd;
+       int             hh;
+       int             hm;
        int             ss;
        int             dhh;
        int             dhm;
@@ -33,8 +33,10 @@ struct       _EIT_CONTROL{
        int             ehh;
        int             emm;
        int             ess;
-       char    *title ;                        // ¥¿¥¤¥È¥ë
-       char    *subtitle ;                     // ¥µ¥Ö¥¿¥¤¥È¥ë
-       char    *desc ;                 // Description
+       char    *title ;                        // タイトル
+       char    *subtitle ;                     // サブタイトル
+       char    *desc ;                         // Description
+       int     desc_length ;                   // Description Length
 };
 #endif
+
index 1dc39bb..f85021f 100755 (executable)
@@ -7,16 +7,28 @@
 
 int strrep(char *buf, char *mae, char *ato)
 {
-    char *mituke;
+    char *mitsuke, *findpos;
        size_t maelen, atolen;
+       int shift;
                    
+       findpos = buf;
        maelen = strlen(mae);
        atolen = strlen(ato);
-       if (maelen == 0 || (mituke = strstr(buf, mae)) == NULL) return 0;
-       memmove(mituke + atolen, mituke + maelen, strlen(buf) - (mituke + maelen - buf ) + 1);
-       memcpy(mituke, ato, atolen);
+       shift = (int)(strlen(ato)-strlen(mae));
+
+       if (maelen == 0 || strstr(findpos, mae) == NULL) return 0;
+       while ((mitsuke = strstr(findpos, mae)) != NULL) {
+               if (shift > 0) {
+                       memmove(mitsuke + shift, mitsuke, strlen(mitsuke) + 1);
+               } else if (shift < 0) {
+                       memmove(mitsuke, mitsuke - shift, strlen(mitsuke) + shift + 1);
+               }
+               memmove(mitsuke, ato, atolen);
+               findpos = mitsuke + atolen;
+       }
        return 1;
 }
+
 int getBit(unsigned char *byte, int *pbit, int gbit) {
        int pbyte = *pbit / 8;
        unsigned char *fbyte = byte + pbyte;
@@ -24,19 +36,19 @@ int getBit(unsigned char *byte, int *pbit, int gbit) {
        int cutbit = *pbit - (pbyte * 8);
        int lcutbit = 32 - (cutbit + gbit);
 
-       unsigned char tbuf[4]; /* int¤ÎºÇÂç32bit */
+       unsigned char tbuf[4]; /* intの最大32bit */
        unsigned int tnum;
 
        memcpy(tbuf, fbyte, sizeof(unsigned char) * 4);
 
-       /* ÀèƬ¥Ð¥¤¥È¤«¤éÉÔÍ×bit¤ò¥«¥Ã¥È */
+       /* 先頭バイトから不要bitをカット */
        tbuf[0] = tbuf[0] << cutbit;
        tbuf[0] = tbuf[0] >> cutbit;
 
-       /* int¤Ë¤·¤Æ¤·¤Þ¤¦ */
+       /* intにしてしまう */
        tnum = tbuf[0] << 24 | tbuf[1] << 16 | tbuf[2] << 8 | tbuf[3];
 
-       /* ¸å¤í¤ÎÉÔÍץХ¤¥È¤ò¥«¥Ã¥È */
+       /* 後ろの不要バイトをカット */
        tnum = tnum >> lcutbit;
 
        *pbit += gbit;
@@ -74,3 +86,43 @@ int parseOTHERdesc(unsigned char *data) {
        return descriptor_length + 2;
 }
 
+void* allocCopy(void* src, int *boff, size_t size) {
+       void* mem = NULL;
+       if ( size == 0 ) return NULL;
+
+       mem = malloc(size);
+       memcpy(mem, src + *boff / 8, size);
+       *boff += size * 8;
+       return mem;
+}
+
+//#define BCD(n) ((n/100)<<8)|(((n%100)/10)<<4)|(n%10)
+#define BCD(n) ((n>>4)*10+(n&0xf))
+
+time_t parseMJD( unsigned char *data ) {
+       int tnum, year, mon, mday;
+       struct tm MJD;
+
+       tnum = (data[0] & 0xFF) << 8 | (data[1] & 0xFF);
+       year = (tnum - 15078.2) / 365.25;
+       mon  = ((tnum - 14956.1) - (int)(year * 365.25)) / 30.6001;
+       mday = (tnum - 14956) - (int)(year * 365.25) - (int)(mon * 30.6001);
+
+       if(mon == 14 || mon == 15) {
+               year += 1;
+               mon  -= 13;
+       } else {
+               mon -= 1;
+       }
+
+       memset( &MJD, 0, sizeof(MJD) );
+       MJD.tm_year = year;
+       MJD.tm_mon  = mon - 1;
+       MJD.tm_mday = mday;
+
+       MJD.tm_hour = BCD(data[2]);
+       MJD.tm_min  = BCD(data[3]);
+       MJD.tm_sec  = BCD(data[4]);
+       return mktime( &MJD );
+}
+
index 483f624..2cc701c 100755 (executable)
@@ -1,15 +1,19 @@
 #ifndef UTIL_H
-#define UTILH 1
+#define UTIL_H 1
 
 #define MAXSECLEN 4096
 
+#include <time.h>
+
 #ifdef __cplusplus
 extern "C"{
 #endif /* __cplusplus */
 
-       int   getBit(unsigned char *byte, int *pbit, int gbit);
-       void  getStr(char *tostr, unsigned char *byte, int *pbit, int len);
-       int   parseOTHERdesc(unsigned char *data);
+       int    getBit(unsigned char *byte, int *pbit, int gbit);
+       void   getStr(char *tostr, unsigned char *byte, int *pbit, int len);
+       int    parseOTHERdesc(unsigned char *data);
+       void*  allocCopy(void* src, int *boff, size_t size);
+       time_t parseMJD( unsigned char *data );
 
 #ifdef __cplusplus
 }
index 56e087b..06a617e 100755 (executable)
@@ -2,14 +2,15 @@ static STATION bsSta[] = {
        { "NHK BS1", "3001.ontvjapan.com", 16625, 4, 101},
        { "NHK BS2", "3002.ontvjapan.com", 16625, 4, 102},
        { "NHK BSh", "3003.ontvjapan.com", 16626, 4, 103},
-       { "BSÆü¥Æ¥ì", "3004.ontvjapan.com", 16592, 4, 141},
-       { "BSÄ«Æü", "3005.ontvjapan.com", 16400, 4, 151},
-       { "BS-i", "3006.ontvjapan.com", 16401, 4, 161},
-       { "BS¥¸¥ã¥Ñ¥ó", "3007.ontvjapan.com", 16433, 4, 171},
-       { "BS¥Õ¥¸", "3008.ontvjapan.com", 16593, 4, 181},
+       { "BS日テレ", "3004.ontvjapan.com", 16592, 4, 141},
+       { "BS朝日", "3005.ontvjapan.com", 16400, 4, 151},
+       { "BS-TBS", "3006.ontvjapan.com", 16401, 4, 161},
+       { "BSジャパン", "3007.ontvjapan.com", 16433, 4, 171},
+       { "BSã\83\95ã\82¸", "3008.ontvjapan.com", 16593, 4, 181},
        { "WOWOW", "3009.ontvjapan.com", 16432, 4, 191},
        { "WOWOW2", "3010.ontvjapan.com", 16432, 4, 192},
        { "WOWOW3", "3011.ontvjapan.com", 16432, 4, 193},
+       { "スター・チャンネル", "3012.ontvjapan.com", 16529, 4, 200},
        { "BS11", "3013.ontvjapan.com", 16528, 4, 211},
        { "TwellV", "3014.ontvjapan.com", 16530, 4, 222},
 };
@@ -19,75 +20,75 @@ static int bsStaCount = sizeof(bsSta) / sizeof (STATION);
 
 
 static STATION csSta[] = {
-       { "¥¹¥¿¡¼£ã£è¥×¥é¥¹", "1002.ontvjapan.com", 24608, 6, 237},
-       { "ÆüËܱDzèÀìÌç£ã£è£È£Ä", "1086.ontvjapan.com", 24608, 6, 239},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£Ã£Ó£È£Ä", "306ch.epgdata.ontvjapan", 24608, 6, 306},
-       { "¥·¥ç¥Ã¥×¥Á¥ã¥ó¥Í¥ë", "1059.ontvjapan.com", 24704, 6, 55},
-       { "¥¶¡¦¥·¥Í¥Þ", "1217.ontvjapan.com", 24736, 6, 228},
-       { "¥¹¥«¥Á¥ã¥ó£È£Ä£¸£°£°", "800ch.epgdata.ontvjapan", 24736, 6, 800},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£±", "801ch.epgdata.ontvjapan", 24736, 6, 801},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£²", "802ch.epgdata.ontvjapan", 24736, 6, 802},
-       { "£å£²¥×¥í¥â", "100ch.epgdata.ontvjapan", 28736, 7, 100},
-       { "¥¤¥ó¥¿¡¼¥í¡¼¥«¥ë£Ô£Ö", "194ch.epgdata.ontvjapan", 28736, 7, 194},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£Å£Ó£Ð£Î", "1025.ontvjapan.com", 28736, 7, 256},
-       { "£Æ£Ï£Ø", "1016.ontvjapan.com", 28736, 7, 312},
-       { "¥¹¥Ú¡¼¥¹¥·¥ã¥ï¡¼£Ô£Ö", "1018.ontvjapan.com", 28736, 7, 322},
-       { "¥«¡¼¥È¥¥¡¼¥ó¡¡¥Í¥Ã¥È", "1046.ontvjapan.com", 28736, 7, 331},
-       { "¥È¥¥¡¼¥ó¡¦¥Ç¥£¥º¥Ë¡¼", "1213.ontvjapan.com", 28736, 7, 334},
-       { "Åì±Ç¥Á¥ã¥ó¥Í¥ë", "1010.ontvjapan.com", 28768, 7, 221},
-       { "±ÒÀ±·à¾ì", "1005.ontvjapan.com", 28768, 7, 222},
-       { "¥Á¥ã¥ó¥Í¥ë£Î£Å£Ã£Ï", "1008.ontvjapan.com", 28768, 7, 223},
-       { "Íβè¡ú¥·¥Í¥Õ¥£¥ë", "1009.ontvjapan.com", 28768, 7, 224},
-       { "¥¹¥¿¡¼¡¦¥¯¥é¥·¥Ã¥¯", "1003.ontvjapan.com", 28768, 7, 238},
-       { "»þÂå·àÀìÌç¥Á¥ã¥ó¥Í¥ë", "1133.ontvjapan.com", 28768, 7, 292},
-       { "¥¹¡¼¥Ñ¡¼¥É¥é¥Þ", "1006.ontvjapan.com", 28768, 7, 310},
-       { "£Á£Ø£Î", "1014.ontvjapan.com", 28768, 7, 311},
-       { "¥Ê¥·¥ç¥¸¥ª¥Á¥ã¥ó¥Í¥ë", "1204.ontvjapan.com", 28768, 7, 343},
-       { "¥ï¥ó¥Æ¥ó¥Ý¡¼¥¿¥ë", "110ch.epgdata.ontvjapan", 28864, 7, 110},
-       { "¥´¥ë¥Õ¥Á¥ã¥ó¥Í¥ë", "1028.ontvjapan.com", 28864, 7, 260},
-       { "¥Æ¥ìÄ«¥Á¥ã¥ó¥Í¥ë", "1092.ontvjapan.com", 28864, 7, 303},
-       { "£Í£Ô£Ö", "1019.ontvjapan.com", 28864, 7, 323},
-       { "¥ß¥å¡¼¥¸¥Ã¥¯¡¦¥¨¥¢", "1024.ontvjapan.com", 28864, 7, 324},
-       { "Ä«Æü¥Ë¥å¡¼¥¹¥¿¡¼", "1067.ontvjapan.com", 28864, 7, 352},
-       { "£Â£Â£Ã¥ï¡¼¥ë¥É", "1070.ontvjapan.com", 28864, 7, 353},
-       { "£Ã£Î£Î£ê", "1069.ontvjapan.com", 28864, 7, 354},
-       { "¥¸¥ã¥¹¥È¡¦¥¢¥¤", "361ch.epgdata.ontvjapan", 28864, 7, 361},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£±", "1041.ontvjapan.com", 28896, 7, 251},
-       { "£Ê¥¹¥Ý¡¼¥Ä¡¡£²", "1042.ontvjapan.com", 28896, 7, 252},
-       { "£Ê¥¹¥Ý¡¼¥Ä£Ð£ì£õ£ó£È", "1043.ontvjapan.com", 28896, 7, 253},
-       { "£Ç£Á£Ï£Ò£Á", "1026.ontvjapan.com", 28896, 7, 254},
-       { "£ó£ë£ù¡¦£Á¥¹¥Ý¡¼¥Ä¡Ü", "1040.ontvjapan.com", 28896, 7, 255},
-       { "ÊõÄÍ¥×¥í¥â¥Á¥ã¥ó¥Í¥ë", "101ch.epgdata.ontvjapan", 28928, 7, 101},
-       { "£Ó£Ë£Ù¡¦£Ó£Ô£Á£Ç£Å", "1207.ontvjapan.com", 28928, 7, 290},
-       { "¥Á¥ã¥ó¥Í¥ë¶ä²Ï", "305ch.epgdata.ontvjapan", 28928, 7, 305},
-       { "£Á£Ô-£Ø", "1201.ontvjapan.com", 28928, 7, 333},
-       { "¥Ò¥¹¥È¥ê¡¼¥Á¥ã¥ó¥Í¥ë", "1050.ontvjapan.com", 28928, 7, 342},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£³", "803ch.epgdata.ontvjapan", 28928, 7, 803},
-       { "¥¹¥«¥Á¥ã¥ó£¸£°£´", "804ch.epgdata.ontvjapan", 28928, 7, 804},
-       { "¥à¡¼¥Ó¡¼¥×¥é¥¹£È£Ä", "1007.ontvjapan.com", 28960, 7, 240},
-       { "¥´¥ë¥Õ¥Í¥Ã¥È¥ï¡¼¥¯", "1027.ontvjapan.com", 28960, 7, 262},
-       { "£Ì£á£Ì£á¡¡£È£Ä", "1074.ontvjapan.com", 28960, 7, 314},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£·£³£¹", "1073.ontvjapan.com", 28992, 7, 258},
-       { "¥Õ¥¸¥Æ¥ì¥Ó£·£²£±", "1072.ontvjapan.com", 28992, 7, 302},
-       { "¥¢¥Ë¥Þ¥Ã¥¯¥¹", "1047.ontvjapan.com", 28992, 7, 332},
-       { "¥Ç¥£¥¹¥«¥Ð¥ê¡¼", "1062.ontvjapan.com", 28992, 7, 340},
-       { "¥¢¥Ë¥Þ¥ë¥×¥é¥Í¥Ã¥È", "1193.ontvjapan.com", 28992, 7, 341},
-       { "£Ã-£Ô£Â£Ó¥¦¥¨¥ë¥«¥à", "160ch.epgdata.ontvjapan", 29024, 7, 160},
-       { "£Ñ£Ö£Ã", "1120.ontvjapan.com", 29024, 7, 161},
-       { "¥×¥é¥¤¥à£³£¶£µ¡¥£Ô£Ö", "185ch.epgdata.ontvjapan", 29024, 7, 185},
-       { "¥Õ¥¡¥ß¥ê¡¼·à¾ì", "1015.ontvjapan.com", 29024, 7, 293},
-       { "£Ô£Â£Ó¥Á¥ã¥ó¥Í¥ë", "3201.ontvjapan.com", 29024, 7, 301},
-       { "¥Ç¥£¥º¥Ë¡¼¥Á¥ã¥ó¥Í¥ë", "1090.ontvjapan.com", 29024, 7, 304},
+       { "ã\82¹ã\82¿ã\83¼ï½\83ï½\88ã\83\97ã\83©ã\82¹", "1002.ontvjapan.com", 24608, 6, 237},
+       { "日本映画専門chHD", "1086.ontvjapan.com", 24608, 6, 239},
+       { "フジテレビCSHD", "306ch.epgdata.ontvjapan", 24608, 6, 306},
+       { "ショップチャンネル", "1059.ontvjapan.com", 24704, 6, 55},
+       { "ザ・シネマ", "1217.ontvjapan.com", 24736, 6, 228},
+       { "スカチャンHD800", "800ch.epgdata.ontvjapan", 24736, 6, 800},
+       { "スカチャン801", "801ch.epgdata.ontvjapan", 24736, 6, 801},
+       { "スカチャン802", "802ch.epgdata.ontvjapan", 24736, 6, 802},
+       { "e2プロモ", "100ch.epgdata.ontvjapan", 28736, 7, 100},
+       { "インターローカルTV", "194ch.epgdata.ontvjapan", 28736, 7, 194},
+       { "Jスポーツ ESPN", "1025.ontvjapan.com", 28736, 7, 256},
+       { "FOX", "1016.ontvjapan.com", 28736, 7, 312},
+       { "スペースシャワーTV", "1018.ontvjapan.com", 28736, 7, 322},
+       { "カートゥーン ネット", "1046.ontvjapan.com", 28736, 7, 331},
+       { "ã\83\88ã\82¥ã\83¼ã\83³ã\83»ã\83\87ã\82£ã\82ºã\83\8bã\83¼", "1213.ontvjapan.com", 28736, 7, 334},
+       { "東映チャンネル", "1010.ontvjapan.com", 28768, 7, 221},
+       { "衛星劇場", "1005.ontvjapan.com", 28768, 7, 222},
+       { "チャンネルNECO", "1008.ontvjapan.com", 28768, 7, 223},
+       { "洋画★シネフィル", "1009.ontvjapan.com", 28768, 7, 224},
+       { "ã\82¹ã\82¿ã\83¼ã\83»ã\82¯ã\83©ã\82·ã\83\83ã\82¯", "1003.ontvjapan.com", 28768, 7, 238},
+       { "時代劇専門チャンネル", "1133.ontvjapan.com", 28768, 7, 292},
+       { "スーパードラマ", "1006.ontvjapan.com", 28768, 7, 310},
+       { "AXN", "1014.ontvjapan.com", 28768, 7, 311},
+       { "ナショジオチャンネル", "1204.ontvjapan.com", 28768, 7, 343},
+       { "ワンテンポータル", "110ch.epgdata.ontvjapan", 28864, 7, 110},
+       { "ゴルフチャンネル", "1028.ontvjapan.com", 28864, 7, 260},
+       { "テレ朝チャンネル", "1092.ontvjapan.com", 28864, 7, 303},
+       { "MTV", "1019.ontvjapan.com", 28864, 7, 323},
+       { "ã\83\9fã\83¥ã\83¼ã\82¸ã\83\83ã\82¯ã\83»ã\82¨ã\82¢", "1024.ontvjapan.com", 28864, 7, 324},
+       { "æ\9c\9dæ\97¥ã\83\8bã\83¥ã\83¼ã\82¹ã\82¿ã\83¼", "1067.ontvjapan.com", 28864, 7, 352},
+       { "BBCワールド", "1070.ontvjapan.com", 28864, 7, 353},
+       { "CNNj", "1069.ontvjapan.com", 28864, 7, 354},
+       { "ã\82¸ã\83£ã\82¹ã\83\88ã\83»ã\82¢ã\82¤", "361ch.epgdata.ontvjapan", 28864, 7, 361},
+       { "Jスポーツ 1", "1041.ontvjapan.com", 28896, 7, 251},
+       { "Jスポーツ 2", "1042.ontvjapan.com", 28896, 7, 252},
+       { "JスポーツPlusH", "1043.ontvjapan.com", 28896, 7, 253},
+       { "GAORA", "1026.ontvjapan.com", 28896, 7, 254},
+       { "sky・Aスポーツ+", "1040.ontvjapan.com", 28896, 7, 255},
+       { "宝塚プロモチャンネル", "101ch.epgdata.ontvjapan", 28928, 7, 101},
+       { "SKY・STAGE", "1207.ontvjapan.com", 28928, 7, 290},
+       { "チャンネル銀河", "305ch.epgdata.ontvjapan", 28928, 7, 305},
+       { "AT-X", "1201.ontvjapan.com", 28928, 7, 333},
+       { "ヒストリーチャンネル", "1050.ontvjapan.com", 28928, 7, 342},
+       { "スカチャン803", "803ch.epgdata.ontvjapan", 28928, 7, 803},
+       { "スカチャン804", "804ch.epgdata.ontvjapan", 28928, 7, 804},
+       { "ムービープラスHD", "1007.ontvjapan.com", 28960, 7, 240},
+       { "ã\82´ã\83«ã\83\95ã\83\8dã\83\83ã\83\88ã\83¯ã\83¼ã\82¯", "1027.ontvjapan.com", 28960, 7, 262},
+       { "LaLa HD", "1074.ontvjapan.com", 28960, 7, 314},
+       { "フジテレビ739", "1073.ontvjapan.com", 28992, 7, 258},
+       { "フジテレビ721", "1072.ontvjapan.com", 28992, 7, 302},
+       { "ã\82¢ã\83\8bã\83\9eã\83\83ã\82¯ã\82¹", "1047.ontvjapan.com", 28992, 7, 332},
+       { "ã\83\87ã\82£ã\82¹ã\82«ã\83\90ã\83ªã\83¼", "1062.ontvjapan.com", 28992, 7, 340},
+       { "アニマルプラネット", "1193.ontvjapan.com", 28992, 7, 341},
+       { "C-TBSウエルカム", "160ch.epgdata.ontvjapan", 29024, 7, 160},
+       { "QVC", "1120.ontvjapan.com", 29024, 7, 161},
+       { "プライム365.TV", "185ch.epgdata.ontvjapan", 29024, 7, 185},
+       { "ファミリー劇場", "1015.ontvjapan.com", 29024, 7, 293},
+       { "TBSチャンネル", "3201.ontvjapan.com", 29024, 7, 301},
+       { "ディズニーチャンネル", "1090.ontvjapan.com", 29024, 7, 304},
        { "MUSIC ON! TV", "1022.ontvjapan.com", 29024, 7, 325},
-       { "¥­¥Ã¥º¥¹¥Æ¡¼¥·¥ç¥ó", "1045.ontvjapan.com", 29024, 7, 330},
-       { "£Ô£Â£Ó¥Ë¥å¡¼¥¹¥Ð¡¼¥É", "1076.ontvjapan.com", 29024, 7, 351},
-       { "£Ã£ÓÆüËÜÈÖÁÈ¥¬¥¤¥É", "147ch.epgdata.ontvjapan", 29056, 7, 147},
-       { "Æü¥Æ¥ì£Ç¡Ü", "1068.ontvjapan.com", 29056, 7, 257},
+       { "キッズステーション", "1045.ontvjapan.com", 29024, 7, 330},
+       { "TBSニュースバード", "1076.ontvjapan.com", 29024, 7, 351},
+       { "CS日本番組ガイド", "147ch.epgdata.ontvjapan", 29056, 7, 147},
+       { "日テレG+", "1068.ontvjapan.com", 29056, 7, 257},
        { "fashion TV", "5004.ontvjapan.com", 29056, 7, 291},
-       { "Æü¥Æ¥ì¥×¥é¥¹", "300ch.epgdata.ontvjapan", 29056, 7, 300},
-       { "¥¨¥³¥ß¥å¡¼¥¸¥Ã¥¯£Ô£Ö", "1023.ontvjapan.com", 29056, 7, 320},
+       { "æ\97¥ã\83\86ã\83¬ã\83\97ã\83©ã\82¹", "300ch.epgdata.ontvjapan", 29056, 7, 300},
+       { "エコミュージックTV", "1023.ontvjapan.com", 29056, 7, 320},
        { "Music Japan TV", "1208.ontvjapan.com", 29056, 7, 321},
-       { "Æü¥Æ¥ì£Î£Å£×£Ó£²£´", "2002.ontvjapan.com", 29056, 7, 350},
+       { "日テレNEWS24", "2002.ontvjapan.com", 29056, 7, 350},
 };
 
 static int csStaCount = sizeof(csSta) / sizeof (STATION);