-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg.c
226 lines (190 loc) · 6.8 KB
/
cg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (C) 2002 John Todd Larason <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rtv.h"
#include "cg.h"
#include "dump.h"
#include "program.h"
int parse_parts(unsigned char **pp, struct parts * parts)
{
unsigned char * p = *pp;
parts->part = rtv_to_u16(&p);
parts->of = rtv_to_u16(&p);
*pp = p;
return 0;
}
int parse_movie(unsigned char **pp, struct movie * movie)
{
unsigned char * p = *pp;
movie->mpaa = rtv_to_u16(&p);
movie->stars = rtv_to_u16(&p);
movie->year = rtv_to_u16(&p);
movie->runtime = rtv_to_u16(&p);
*pp = p;
return 0;
}
int parse_fixed_program_record(unsigned char **pp,
struct fixed_program_record * prog,
int varsize)
{
unsigned char * p = *pp;
int data_len;
u8 offset;
memset(prog, 0, sizeof prog);
prog->flags = rtv_to_u32(&p);
prog->event_time = rtv_to_u32(&p);
prog->tmsid = rtv_to_u32(&p);
prog->minutes = rtv_to_u16(&p);
prog->genre1 = *p++;
prog->genre2 = *p++;
prog->genre3 = *p++;
prog->genre4 = *p++;
prog->record_len = rtv_to_u16(&p);
prog->title_len = *p++;
prog->episode_len = *p++;
prog->description_len = *p++;
prog->actor_len = *p++;
prog->guest_len = *p++;
prog->suzuki_len = *p++;
prog->producer_len = *p++;
prog->director_len = *p++;
if (varsize)
data_len = prog->record_len - 28;
else
data_len = sizeof(prog->datablock);
memcpy(prog->datablock, p, data_len);
p += data_len;
*pp = p;
p = prog->datablock;
if (prog->flags & 0x0040)
parse_parts(&p, &prog->parts);
if (prog->flags & 0x0020)
parse_movie(&p, &prog->movie);
offset = p - prog->datablock;
prog->title_offset = offset; offset += prog->title_len;
prog->episode_offset = offset; offset += prog->episode_len;
prog->description_offset = offset; offset += prog->description_len;
prog->actor_offset = offset; offset += prog->actor_len;
prog->guest_offset = offset; offset += prog->guest_len;
prog->suzuki_offset = offset; offset += prog->suzuki_len;
prog->producer_offset = offset; offset += prog->producer_len;
prog->director_offset = offset; offset += prog->director_len;
expect(prog->record_len == 0 ||
((offset + 28 + 3) & 0xfffc) == prog->record_len);
return 0;
}
int parse_cg2_channel(unsigned char **pp, struct cg2_channel * chan)
{
unsigned char * p = *pp;
memset(chan, 0, sizeof *chan);
chan->mod_time = rtv_to_u32(&p);
chan->tmsid = rtv_to_u32(&p);
chan->data_len = rtv_to_u32(&p);
*pp = p;
return 0;
}
static int count_programs(unsigned char * p, struct cg2_channel * chan)
{
unsigned char * start;
unsigned char * tmp;
u16 record_len;
int count;
count = 0;
start = p;
while (p < start + chan->data_len) {
tmp = p + 18;
record_len = rtv_to_u16(&tmp);
p += record_len;
count++;
}
return count;
}
int parse_cg2_programlist(unsigned char **pp, struct cg2_channel * chan)
{
unsigned char * p = *pp;
int i;
chan->num_programs = count_programs(p, chan);
chan->programs = calloc(chan->num_programs, sizeof *chan->programs);
for (i = 0; i < chan->num_programs; i++)
parse_fixed_program_record(&p, &chan->programs[i], 1);
*pp = p;
return 0;
}
void dump_parts(struct parts * p)
{
dump_group_start ("Parts");
dump_u16 ("Part Number", p->part);
dump_u16 ("Total Parts", p->of);
dump_group_end ();
}
void dump_movie(struct movie * p)
{
dump_group_start ("Movie");
dump_bitmapping ("MPAA Rating", p->mpaa, mpaa_mapping);
dump_u16 ("Stars Times Ten", p->stars);
dump_u16 ("Year", p->year);
dump_u16 ("Runtime", p->runtime);
dump_group_end ();
}
void dump_fixed_program_record(struct fixed_program_record * p)
{
dump_group_start ("Program");
dump_bitmapping ("Flags", p->flags, program_flags_mapping);
dump_time ("Event Time", p->event_time);
dump_u32 ("TMS ID", p->tmsid);
dump_u16 ("Minutes", p->minutes);
if (p->genre1)
dump_mapping ("Genre 1", p->genre1, genre_mapping);
if (p->genre2)
dump_mapping ("Genre 2", p->genre2, genre_mapping);
if (p->genre3)
dump_mapping ("Genre 3", p->genre3, genre_mapping);
if (p->genre4)
dump_mapping ("Genre 4", p->genre4, genre_mapping);
dump_u16 ("Record Length",p->record_len);
if (p->flags & 0x0040)
dump_parts ( &p->parts);
if (p->flags & 0x0020)
dump_movie ( &p->movie);
if (p->title_len > 1)
dump_string ("Title", p->datablock + p->title_offset);
if (p->episode_len > 1)
dump_string ("Episode", p->datablock + p->episode_offset);
if (p->description_len > 1)
dump_string ("Description", p->datablock + p->description_offset);
if (p->actor_len > 1)
dump_string ("Actor", p->datablock + p->actor_offset);
if (p->guest_len > 1)
dump_string ("Guest", p->datablock + p->guest_offset);
if (p->suzuki_len > 1)
dump_string ("Suzuki", p->datablock + p->suzuki_offset);
if (p->producer_len > 1)
dump_string ("Producer", p->datablock + p->producer_offset);
if (p->director_len > 1)
dump_string ("Director", p->datablock + p->director_offset);
dump_group_end ();
}
void dump_cg2_channel(struct cg2_channel * p)
{
int i;
dump_group_start ("Channel Lineup");
dump_time ("Modification Time", p->mod_time);
dump_u32 ("TMS ID", p->tmsid);
dump_u32 ("Data Length", p->data_len);
for (i = 0; i < p->num_programs; i++)
dump_fixed_program_record(&p->programs[i]);
dump_group_end ();
}