OSDN Git Service

add dist
[rec10/rec10-git.git] / dist / trunk / tstools / epgdump / util.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "aribstr.h"
6 #include "util.h"
7
8 int strrep(char *buf, char *mae, char *ato)
9 {
10     char *mituke;
11         size_t maelen, atolen;
12                     
13         maelen = strlen(mae);
14         atolen = strlen(ato);
15         if (maelen == 0 || (mituke = strstr(buf, mae)) == NULL) return 0;
16         memmove(mituke + atolen, mituke + maelen, strlen(buf) - (mituke + maelen - buf ) + 1);
17         memcpy(mituke, ato, atolen);
18         return 1;
19 }
20 int getBit(unsigned char *byte, int *pbit, int gbit) {
21         int pbyte = *pbit / 8;
22         unsigned char *fbyte = byte + pbyte;
23
24         int cutbit = *pbit - (pbyte * 8);
25         int lcutbit = 32 - (cutbit + gbit);
26
27         unsigned char tbuf[4]; /* int¤ÎºÇÂç32bit */
28         unsigned int tnum;
29
30         memcpy(tbuf, fbyte, sizeof(unsigned char) * 4);
31
32         /* ÀèƬ¥Ð¥¤¥È¤«¤éÉÔÍ×bit¤ò¥«¥Ã¥È */
33         tbuf[0] = tbuf[0] << cutbit;
34         tbuf[0] = tbuf[0] >> cutbit;
35
36         /* int¤Ë¤·¤Æ¤·¤Þ¤¦ */
37         tnum = tbuf[0] << 24 | tbuf[1] << 16 | tbuf[2] << 8 | tbuf[3];
38
39         /* ¸å¤í¤ÎÉÔÍץХ¤¥È¤ò¥«¥Ã¥È */
40         tnum = tnum >> lcutbit;
41
42         *pbit += gbit;
43
44         return tnum;
45   
46 }
47
48 void getStr(char *tostr, unsigned char *byte, int *pbit, int len) {
49         char str[MAXSECLEN];
50         int pbyte = *pbit / 8;
51         unsigned char *fbyte = byte + pbyte;
52
53         memset(str, 0, sizeof(char) * MAXSECLEN);
54         memcpy(str, fbyte, len);
55
56         *pbit += (len * 8);
57   
58         AribToString(tostr, str, len);
59
60         return;
61   
62 }
63
64 int parseOTHERdesc(unsigned char *data) {
65         int boff = 0;
66         int descriptor_tag;
67         int descriptor_length;
68
69         descriptor_tag = getBit(data, &boff, 8);
70         descriptor_length = getBit(data, &boff, 8);
71
72         /* printf("other desc_tag:0x%x\n", descriptor_tag); */
73
74         return descriptor_length + 2;
75 }
76