root/trunk/epgdumpr2/util.c

リビジョン 136, 1.8 kB (コミッタ: sorshi, コミット時期: 13 年 前)

foltiaで利用しているepgdumpを追加

Line 
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 *mitsuke, *findpos;
11         size_t maelen, atolen;
12         int shift;
13                    
14         findpos = buf;
15         maelen = strlen(mae);
16         atolen = strlen(ato);
17         shift = (int)(strlen(ato)-strlen(mae));
18
19         if (maelen == 0 || strstr(findpos, mae) == NULL) return 0;
20         while ((mitsuke = strstr(findpos, mae)) != NULL) {
21                 if (shift > 0) {
22                         memmove(mitsuke + shift, mitsuke, strlen(mitsuke) + 1);
23                 } else if (shift < 0) {
24                         memmove(mitsuke, mitsuke - shift, strlen(mitsuke) + shift + 1);
25                 }
26                 memmove(mitsuke, ato, atolen);
27                 findpos = mitsuke + atolen;
28         }
29         return 1;
30 }
31
32 int getBit(unsigned char *byte, int *pbit, int gbit) {
33         int pbyte = *pbit / 8;
34         unsigned char *fbyte = byte + pbyte;
35
36         int cutbit = *pbit - (pbyte * 8);
37         int lcutbit = 32 - (cutbit + gbit);
38
39         unsigned char tbuf[4]; /* int���紊�2bit */
40         unsigned int tnum;
41
42         memcpy(tbuf, fbyte, sizeof(unsigned char) * 4);
43
44         /* ������������荀�it������ */
45         tbuf[0] = tbuf[0] << cutbit;
46         tbuf[0] = tbuf[0] >> cutbit;
47
48         /* int�������障� */
49         tnum = tbuf[0] << 24 | tbuf[1] << 16 | tbuf[2] << 8 | tbuf[3];
50
51         /* 緇�����荀���ゃ������� */
52         tnum = tnum >> lcutbit;
53
54         *pbit += gbit;
55
56         return tnum;
57  
58 }
59
60 void getStr(char *tostr, unsigned char *byte, int *pbit, int len) {
61         char str[MAXSECLEN];
62         int pbyte = *pbit / 8;
63         unsigned char *fbyte = byte + pbyte;
64
65         memset(str, 0, sizeof(char) * MAXSECLEN);
66         memcpy(str, fbyte, len);
67
68         *pbit += (len * 8);
69  
70         AribToString(tostr, str, len);
71
72         return;
73  
74 }
75
76 int parseOTHERdesc(unsigned char *data) {
77         int boff = 0;
78         int descriptor_tag;
79         int descriptor_length;
80
81         descriptor_tag = getBit(data, &boff, 8);
82         descriptor_length = getBit(data, &boff, 8);
83
84         /* printf("other desc_tag:0x%x\n", descriptor_tag); */
85
86         return descriptor_length + 2;
87 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed