2
// C++ Implementation: vobsub parser
7
// Author: Mean, 2005 GPL
9
// Copyright: See COPYING file that comes with this distribution
12
/***************************************************************************
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
19
***************************************************************************/
24
#include <ADM_assert.h>
25
#include "ADM_library/default.h"
26
#include "ADM_vobsubinfo.h"
28
static uint8_t fillLine(char *str,VobSubInfo *sub,uint32_t line);
29
static uint32_t countLine(FILE *f,int index);
30
uint8_t fillPalette(char *str,VobSubInfo *sub);
32
uint8_t destroySubInfo(VobSubInfo *sub)
34
if(!sub) return 1; // ?
35
if(sub->lines) delete [] sub->lines;
44
uint8_t fillLine(char *str,VobSubInfo *sub,uint32_t line)
50
ADM_assert(line<sub->nbLines);
52
o=sscanf(str,"timestamp: %d:%d:%d:%d, filepos: %x\n",&hh,&mm,&ss,&ms,&pos);
58
sub->lines[line].startTime =ti;
59
sub->lines[line].stopTime =ti+1000;
60
sub->lines[line].fileOffset =pos;
67
uint8_t fillPalette(char *str,VobSubInfo *sub)
71
o=sscanf(str,"palette: %x, %x, %x, %x, %x, %x, %x, %x,"
72
" %x, %x, %x, %x, %x, %x, %x, %x",
73
&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7],
74
&p[8],&p[9],&p[10],&p[11],&p[12],&p[13],&p[14],&p[15]);
83
uint8_t vobSubRead(char *filename,int index,VobSubInfo **info)
96
printf("Null file ?\n");
100
file=fopen(filename,"rt");
103
printf("Could not open %s file\n",filename);
106
nb_lines=countLine(file,index);
109
printf("Empty file\n");
112
// Try to read the file
114
memset(sub,0,sizeof(VobSubInfo));
116
sub->nbLines=nb_lines;
117
sub->lines=new vobSubLine[nb_lines];
118
memset(sub->lines,0,sizeof(vobSubLine)*nb_lines);
119
printf("Rebuilding %d lines of subs\n",nb_lines);
123
fgets(str,1023,file);
124
if(!strncmp(str,"palette:",7)) fillPalette(str,sub);
127
if(!strncmp(str,"timestamp: ",10) && language)
129
fillLine(str,sub,line);
134
if(!strncmp(str,"id:",3)) // Catch language/index
138
sscanf(str,"id: %s index: %d",s,&l);
139
printf("Found lang : %s index %d while searching %d\n",s,l,index);
140
if(l==index) language=1;
146
if(!strncmp(str,"size:",5)) // Catch original screen dimension
148
sscanf(str,"size:%lux%lu",&(sub->width),&(sub->height));
165
destroySubInfo( sub);
172
// count #nb beginning by timestamp in file
174
uint32_t countLine(FILE *f,int index)
176
char str[1024],s[1024];
185
if(!strncmp(str,"id:",3))
187
sscanf(str,"id: %s index: %d",s,&lang);
188
if(lang==index) match=1;
193
if(!strncmp(str,"timestamp: ",10)) nb++;
199
//*****************************************
200
vobSubLanguage *vobSubAllocateLanguage(void)
203
l=new vobSubLanguage;
204
memset(l,0,sizeof(vobSubLanguage));
207
//*****************************************
208
uint8_t vobSubDestroyLanguage(vobSubLanguage *lingua)
210
for(uint32_t i=0;i<lingua->nbLanguage;i++)
211
delete [] lingua->language[i].name;
215
//*****************************************
216
uint8_t vobSubGetLanguage(char *filename,vobSubLanguage *lingua)
223
fd=fopen(filename,"rb");
232
if(!strncmp(str,"id: ",3))
234
sscanf(str,"id: %s index: %d",s,&index);
235
lingua->language[nb].name=new char[3];
236
lingua->language[nb].name[0]=str[4];
237
lingua->language[nb].name[1]=str[5];
238
lingua->language[nb].name[2]=0;
240
lingua->language[nb].index=index;
244
lingua->nbLanguage=nb;