source: svn/newcon3bcm2_21bu/dst/dmw/src/cc/cc_util.c @ 69

Last change on this file since 69 was 69, checked in by phkim, 10 years ago

1.phkim

  1. 광주방송
  2. 변경내용
    • VBI 캡션 disabled
  • Property svn:executable set to *
File size: 7.2 KB
Line 
1
2#include "cc_config.h"
3#include "cc_type.h"
4#include "cc_def.h"
5#include "cc_private.h"
6
7//#include <string.h>
8#include <stdarg.h>
9
10#if 0
11__STRING__() {}
12#endif
13
14#if USE_ADVANCED_KSX_TO_UNICODE_TABLE
15#include "ksx_uni_table2.h"
16#else
17
18#if USE_INNER_KSX_TO_UNICODE_TABLE
19#include "cc_ksx_unicode_table.h"
20#else
21//UINT16 *p_ck2uk_table=DST_cktouk;
22extern UINT16 p_ck2uk_table[];
23#endif
24
25#endif
26
27
28int DCCUtil_UStrLen(UINT16 *str)
29{
30        int i;
31       
32        for(i=0; str[i]; i++);
33       
34        return i;
35}
36
37#if USE_ADVANCED_KSX_TO_UNICODE_TABLE
38
39UINT16 DCCUtil_Ksx1001toUnicode(UINT16 code)
40{
41        UINT8 byte1=(code>>8), byte2=(code&0xff);
42        int tab_idx = ((int)byte1 - 0x00a1) * 94 + (int)byte2 - 0x00a1;
43        long code_ucs2;
44       
45        if(code<0xa1a0 || code>0xfdff) return code;
46       
47        if(code==0xa2e6) return 0x20ac;
48        else if(code==0xa1a1) return 0x20;
49        //else if(code==0xa3dc) return 0x209a;
50        else if(code==0xa2a6) return 0x7e;
51        else if(code==0xa2e7) return 0x00ae;
52        else if(code>=0xa3a0 && code<0xa4a0) return code-0xa3a0+0x20;
53        else if(code>=0xa4a0 && code<0xa5a0) return code-0xa4a0+0x2f80+0x1b0;
54        else if (tab_idx >= 0 && tab_idx < ksc5601max) {
55                code_ucs2 = tabksc5601[tab_idx];
56                if (code_ucs2 != -1) return code_ucs2;
57        }
58       
59        return 0x20; //if not exist, then return 0x20(blank)
60}
61
62#else
63
64UINT16 DCCUtil_Ksx1001toUnicode(UINT16 code)
65{
66        UINT16 ret_code;
67       
68        if(!p_ck2uk_table) return code;
69       
70        if(code<0xa1a0 || code>0xfdff) return code;
71       
72        if(code>=0xa3a0 && code<=0xa3fe) {
73                ret_code=code-0xa380;
74        }
75        else {
76                code |= 0x8080;
77               
78                if(code>=0xb0a1 && code<=0xc8fe) {
79                        code-=45217;
80                        code=code/256*94 + code%256;
81                        ret_code=p_ck2uk_table[code];
82                }
83                else if(code==0xa1a1) //space
84                        ret_code=0x20;
85                else if(code==0xa3dc) //back slash -> won
86                        ret_code=0x20a9;
87                else if(code>=0xa3a0 && code<=0xa3fe)
88                        ret_code=code-0xa380;
89                else if(code==0xa2a6)
90                        ret_code=0x7e;
91                else
92                        ret_code=0x20;//Áö¿øÇÏÁö ¾Ê´Â ÄÚµå´Â °ø¹é ó¸®//ret_code=0x25af; //Áö¿øÇÏÁö ¾Ê´Â codeÀÎ °æ¿ì ¼¼¿î Á÷»ç°¢Çü
93        }
94       
95        return ret_code;
96}
97
98#endif
99
100
101#if 0
102__DEBUG__() {}
103#endif
104
105
106
107#define MAX_NAME_LEN 16
108#define MAX_DBG_ITEM 64
109
110static struct {
111        char name[MAX_NAME_LEN];
112        BOOL is_on;
113} p_dbg_info[MAX_DBG_ITEM]=
114{ 
115        {"noti", FALSE},
116        {"warn", TRUE},
117        {"error", TRUE},
118        {"ud", FALSE},
119        {"dmx708", FALSE},
120        {"parse708", FALSE},
121        {"parse708ex", FALSE},
122        {"win_ch", FALSE},
123        {"win_chex", FALSE},
124        {"win_rect", FALSE},
125        {"win_line", FALSE},
126        {"spl", FALSE},
127        {"dfx", FALSE},
128        {"708data", FALSE},
129        //{"ddi_box", TRUE},
130        //{"ddi_ch", TRUE},
131};
132
133static int p_dbg_idx=14;
134static UINT32 p_ms_debug_off;
135static BOOL p_is_dbg_on=TRUE;
136
137
138void DCCUtil_DbgPrint(char *pname, char *fmt, ...)
139{
140        int i;
141       
142        if(!p_is_dbg_on) return;
143       
144        for(i=0; i<p_dbg_idx; i++) {
145                if(strcmp(pname, p_dbg_info[i].name)==0) {
146                        if(!p_dbg_info[i].is_on) return;
147                               
148                        break;
149                }
150        }
151       
152        if(i==p_dbg_idx) { /* ãÁö ¸øÇÔ, µî·Ï */
153                if(p_dbg_idx<MAX_DBG_ITEM-1) {
154                        strcpy(p_dbg_info[p_dbg_idx++].name, pname);
155                }
156                else {
157                        DHL_OS_Printf("!! dbg item is over MAX_DBG_ITEM(%d)\n", MAX_DBG_ITEM);
158                }
159               
160                return;
161        }
162       
163        if(DCCDDI_GetCurMs()-p_ms_debug_off<3000) return;
164                /* 3ÃÊ Á¤µµ ½Ã°£À» ¹ø´Ù */
165       
166        if(1) {
167                char buf[512];
168                va_list v;
169                sprintf(buf, "[CC:%05d][%8s] ", DCCDDI_GetCurMs()/10, pname);
170               
171                va_start(v, fmt);
172#if SUPPORT_WINDOWS
173                _vsnprintf(buf+strlen(buf), 512-strlen(buf), fmt, v);
174#else
175                vsnprintf(buf+strlen(buf), 512-strlen(buf), fmt, v);
176#endif
177                va_end(v);
178
179                DHL_OS_Printf(buf);
180
181        }
182}
183
184void DCCUtil_ShowDbgItem()
185{
186        int i;
187       
188        p_ms_debug_off=DCCDDI_GetCurMs();
189       
190        DHL_OS_Printf("Debug Info.\n");
191        DHL_OS_Printf("--------------------------------------------------\n");
192        DHL_OS_Printf("id   on     name\n");
193        DHL_OS_Printf("--------------------------------------------------\n");
194        for(i=0; i<p_dbg_idx; i++) {
195                DHL_OS_Printf("%2d : %s | %s\n", i, p_dbg_info[i].is_on?"On ":"Off", p_dbg_info[i].name);
196        }
197       
198        DHL_OS_Printf("--------------------------------------------------\n");
199       
200}
201
202
203void DCCUtil_SetDbgOn(char *pname, BOOL is_on)
204{
205        int i;
206       
207        for(i=0; i<p_dbg_idx; i++) {
208                if(strcmp(pname, p_dbg_info[i].name)==0) {
209                        p_dbg_info[i].is_on=is_on;
210                        return;
211                }
212        }
213       
214        if(p_dbg_idx<MAX_DBG_ITEM-1) {
215                strcpy(p_dbg_info[p_dbg_idx].name, pname);
216                p_dbg_info[p_dbg_idx].is_on=is_on;
217                p_dbg_idx++;
218        }
219}
220
221
222void DCCUtil_ToggleDbgOn(char *pname)
223{
224        int i;
225       
226        for(i=0; i<p_dbg_idx; i++) {
227                if(strcmp(pname, p_dbg_info[i].name)==0) {
228                        p_dbg_info[i].is_on=p_dbg_info[i].is_on?FALSE:TRUE;
229                        return;
230                }
231        }
232}
233
234
235void DCCUtil_SetDbgOnByIdx(int idx, BOOL is_on)
236{
237        if(idx>=p_dbg_idx) {
238                DHL_OS_Printf("!! bad idx num\n");
239                return;
240        }
241       
242        p_dbg_info[idx].is_on=is_on;
243}
244
245
246void DCCUtil_ToggleDbgOnByIdx(int idx)
247{
248        if(idx>=p_dbg_idx) {
249                DHL_OS_Printf("!! bad idx num\n");
250                return;
251        }
252       
253        p_dbg_info[idx].is_on=p_dbg_info[idx].is_on?FALSE:TRUE;
254}
255
256void cda(char *pname) /* cc debug active */
257{
258        DCCUtil_SetDbgOn(pname, TRUE);
259}
260
261void cdi(char *pname) /* cc debug inactive */
262{
263        DCCUtil_SetDbgOn(pname, FALSE);
264}
265
266void csd() /* cc show debug */
267{
268        DCCUtil_ShowDbgItem();
269}
270
271void cdai(int idx) /* cc debug active by index */
272{
273        DCCUtil_SetDbgOnByIdx(idx, TRUE);
274}
275
276void cdii(int idx) /* cc debug inactive by index */
277{
278        DCCUtil_SetDbgOnByIdx(idx, FALSE);
279}
280
281void ctn(char *pname) /* cc toggle by name */
282{
283        DCCUtil_ToggleDbgOn(pname);
284}
285
286void cti(int idx) /* cc toggle by index */
287{
288        DCCUtil_ToggleDbgOnByIdx(idx);
289}
290
291void cdo()
292{
293        p_is_dbg_on=p_is_dbg_on?FALSE:TRUE;
294}
295
296#if 0
297__BIT_BUFFER__() {}
298#endif
299
300#define MAX_SIZE_BIT_BUF (256+3)
301
302static UINT8 p_regBitBuf[MAX_SIZE_BIT_BUF];//neverdai 070522.
303static UINT16 p_regBitBufSize, p_regBitBufIdx;
304
305static void p_attach_end_marker()//neverdai 070522.
306{
307        p_regBitBuf[p_regBitBufSize/8]=0x0;
308        p_regBitBuf[p_regBitBufSize/8+1]=0x0;
309        p_regBitBuf[p_regBitBufSize/8+2]=0x1;
310        p_regBitBufSize+=24;
311}
312
313
314void DCCUtil_InitBitBuf(UINT8 *pdata, int size)
315{
316        if(!pdata || size==0) {
317                p_regBitBufSize=0;
318                return;
319        }
320
321        if(size>=MAX_SIZE_BIT_BUF) {
322                CCPRINT("warn", "!! Error..size is over 256\n");
323#if 0
324                p_regBitBufSize=0;
325                return;
326#else
327                size=MAX_SIZE_BIT_BUF;
328#endif
329        }
330               
331        memcpy(p_regBitBuf, pdata, size);
332        p_regBitBufSize=size<<3;//p_regBitBufSize*8;
333        p_regBitBufIdx=0;
334        p_attach_end_marker();
335}
336
337
338UINT32 DCCUtil_NextBits(UINT8 size)
339{
340        int i;
341        UINT32 retVal;
342        UINT8 temp;
343
344        //bit under flow check
345        if(p_regBitBufIdx+size>p_regBitBufSize) {
346                return 0;
347        }
348       
349        temp=p_regBitBuf[p_regBitBufIdx/8];
350       
351        for(i=p_regBitBufIdx, retVal=0 ;i<p_regBitBufIdx+size;) {
352               
353                retVal=(retVal<<1)|((temp>>(7-i%8))&0x1);
354               
355                if(++i%8==0)
356                        temp=p_regBitBuf[i/8];
357        }
358       
359        return retVal; 
360}
361               
362
363UINT32 DCCUtil_GetBits(UINT8 size)
364{
365        int retValue;
366       
367        //bit under flow check 
368        if(p_regBitBufIdx+size>p_regBitBufSize) {
369                return 0;
370        }
371       
372        retValue=DCCUtil_NextBits(size);
373       
374        p_regBitBufIdx+=size;
375       
376        return retValue;
377}
378
379void DCCUtil_UngetBits(UINT32 size, UINT32 data)
380{
381        //ÇÊ¿ä¾øÀ» µí.
382}
383
384//GetBits³ª NextBits Àü¿¡ bit underflow check.
385int DCCUtil_CheckBits(UINT8 size)
386{
387        if(p_regBitBufIdx+size>p_regBitBufSize) {
388                return -1;
389        }
390        return 0;       //success
391}
392
393
394
Note: See TracBrowser for help on using the repository browser.