From eed7858a7405e8b3861b77dc77bde4aae359c8ac Mon Sep 17 00:00:00 2001 From: albeu Date: Tue, 22 Jan 2002 22:46:12 +0000 Subject: Objectization of the play_tree_parser for more flexiblity git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4309 b3059339-0415-0410-9bf9-f77b7e298cf2 --- playtreeparser.c | 244 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 102 deletions(-) (limited to 'playtreeparser.c') diff --git a/playtreeparser.c b/playtreeparser.c index 0d0ba72625..47918925c3 100644 --- a/playtreeparser.c +++ b/playtreeparser.c @@ -12,20 +12,16 @@ #include #include #include "playtree.h" +#include "playtreeparser.h" #include "libmpdemux/stream.h" #include "mp_msg.h" extern play_tree_t* -asx_parser_build_tree(char* buffer); - - -static char* buffer = NULL; -static int buffer_size = 0, buffer_end = 0; - +asx_parser_build_tree(char* buffer, int ref); play_tree_t* -parse_asx(stream_t* stream) { +parse_asx(play_tree_parser_t* p) { int r; int comments = 0,read = 1,eof = 0; @@ -35,70 +31,70 @@ parse_asx(stream_t* stream) { if(read && eof) // Eof reached before anything useful return NULL; if(read) { - if(buffer_size - buffer_end < 50) buffer_size += 255; - buffer = (char*)realloc(buffer,buffer_size*sizeof(char)); - if(buffer == NULL) { - mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",buffer_size*sizeof(char)); - buffer_size = buffer_end = 0; + if(p->buffer_size - p->buffer_end < 50) p->buffer_size += 255; + p->buffer = (char*)realloc(p->buffer,p->buffer_size*sizeof(char)); + if(p->buffer == NULL) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",p->buffer_size*sizeof(char)); + p->buffer_size = p->buffer_end = 0; return NULL; } - r = stream_read(stream,buffer+buffer_end,buffer_size-buffer_end-1); + r = stream_read(p->stream,p->buffer+p->buffer_end,p->buffer_size-p->buffer_end-1); if(r < 0) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't read from stream r=%d\n",r); return NULL; } else if(r == 0) eof = 1; - buffer_end += r; - buffer[buffer_end] = '\0'; + p->buffer_end += r; + p->buffer[p->buffer_end] = '\0'; } if(comments) { // Jump comments int e; - char* end = strstr(buffer,"-->"); + char* end = strstr(p->buffer,"-->"); if(!end) { - if(buffer[buffer_end-1] != '-') - buffer_end = 0; // Drop buffer content if last char isn't '-' + if(p->buffer[p->buffer_end-1] != '-') + p->buffer_end = 0; // Drop buffer content if last char isn't '-' continue; } comments = 0; - e = end - buffer + 3; - if(e >= buffer_end) { // > seems impossible - buffer_end = 0; // Drop buffer content + e = end - p->buffer + 3; + if(e >= p->buffer_end) { // > seems impossible + p->buffer_end = 0; // Drop buffer content read = 1; continue; } - buffer_end -= e; - memmove(buffer,end+3,buffer_end); // Drop comments + p->buffer_end -= e; + memmove(p->buffer,end+3,p->buffer_end); // Drop comments continue; } - for(r= 0 ; r < buffer_end ; r++) { - if(strchr(" \n\r\t",buffer[r]) != NULL) // Jump space + for(r= 0 ; r < p->buffer_end ; r++) { + if(strchr(" \n\r\t",p->buffer[r]) != NULL) // Jump space continue; - if(buffer[r] != '<') { - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",buffer[r]); - mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",buffer); + if(p->buffer[r] != '<') { + mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",p->buffer[r]); + mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",p->buffer); return NULL; } break; // Stop on first '<' } - if(r > buffer_end-4) { // We need more + if(r > p->buffer_end-4) { // We need more if(r > 0) { // Drop unuseful beggining - buffer_end -= r; - memmove(buffer,&buffer[r],buffer_end); + p->buffer_end -= r; + memmove(p->buffer,&p->buffer[r],p->buffer_end); } read = 1; continue; } - if(strncmp(&buffer[r],"