diff -urN vanilla/main/cfg-common.h main/cfg-common.h --- vanilla/main/cfg-common.h 2005-04-03 09:38:19.000000000 +0200 +++ main/cfg-common.h 2005-04-17 13:02:33.382056605 +0200 @@ -261,6 +261,9 @@ {"sub-bg-alpha", &sub_bg_alpha, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, {"sub-no-text-pp", &sub_no_text_pp, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"sub-fuzziness", &sub_match_fuzziness, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, +#ifdef UNRARLIB_FAKE + {"rarexec", &rar_executable, CONF_TYPE_STRING, 0, 0, 0, NULL}, +#endif #endif #ifdef USE_OSD {"font", &font_name, CONF_TYPE_STRING, 0, 0, 0, NULL}, diff -urN vanilla/main/configure main/configure --- vanilla/main/configure 2005-04-13 13:50:10.000000000 +0200 +++ main/configure 2005-04-17 13:01:10.063516059 +0200 @@ -179,6 +179,7 @@ --disable-freetype Disable freetype2 font rendering support [autodetect] --disable-fontconfig Disable fontconfig font lookup support [autodetect] --disable-unrarlib Disable Unique RAR File Library [enabled] + --enable-rarexec Enable using of RAR executable [disabled] --enable-menu Enable OSD menu support (NOT DVD MENU) [disabled] --disable-sortsub Disable subtitles sorting [enabled] --enable-fribidi Enable using the FriBiDi libs [disabled] @@ -1353,6 +1354,7 @@ _alsa=auto _fastmemcpy=yes _unrarlib=yes +_unrarlib_fake=no _win32=auto _dshow=yes _select=yes @@ -1650,8 +1652,10 @@ --disable-freetype) _freetype=no ;; --enable-fontconfig) _fontconfig=yes ;; --disable-fontconfig) _fontconfig=no ;; - --enable-unrarlib) _unrarlib=yes ;; + --enable-unrarlib) _unrarlib=yes _unrarlib_fake=no ;; --disable-unrarlib) _unrarlib=no ;; + --enable-rarexec) _unrarlib_fake=yes _unrarlib=no ;; + --disable-rarexec) _unrarlib_fake=no ;; --enable-ftp) _ftp=yes ;; --disable-ftp) _ftp=no ;; --enable-vstream) _vstream=yes ;; @@ -6089,6 +6093,14 @@ fi echores "$_unrarlib" +echocheck "RAR executable" +if test "$_unrarlib_fake" = yes ; then + _def_unrarlib_fake='#define USE_UNRARLIB_FAKE 1' +else + _def_unrarlib_fake='#undef USE_UNRARLIB_FAKE' +fi +echores "$_unrarlib_fake" + echocheck "TV interface" if test "$_tv" = yes ; then _def_tv='#define USE_TV 1' @@ -6730,6 +6742,7 @@ TREMOR_FLAGS = $_tremor_flags UNRARLIB = $_unrarlib +UNRARLIB_FAKE = $_unrarlib_fake HAVE_FFPOSTPROCESS = $_def_haveffpostprocess PNG = $_mkf_png JPEG = $_mkf_jpg @@ -7204,6 +7217,9 @@ /* Use unrarlib for Vobsubs */ $_def_unrarlib +/* Use RAR executable for Vobsubs */ +$_def_unrarlib_fake + /* gui support, please do not edit this option */ $_def_gui diff -urN vanilla/main/Makefile main/Makefile --- vanilla/main/Makefile 2005-04-17 11:18:46.000000000 +0200 +++ main/Makefile 2005-04-17 13:01:36.537286342 +0200 @@ -26,6 +26,9 @@ ifeq ($(UNRARLIB),yes) SRCS_COMMON += unrarlib.c endif +ifeq ($(UNRARLIB_FAKE),yes) +SRCS_COMMON += unrarlib_fake.c +endif OBJS_MENCODER = $(SRCS_MENCODER:.c=.o) OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o) diff -urN vanilla/main/unrarlib_fake.c main/unrarlib_fake.c --- vanilla/main/unrarlib_fake.c 1970-01-01 01:00:00.000000000 +0100 +++ main/unrarlib_fake.c 2005-04-17 13:43:26.373513614 +0200 @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include +#include "unrarlib_fake.h" + +#include "mp_msg.h" + +static char *regex1 = ""; + +static FILE *rar_pipe = NULL; + +#define RAR_LIST 1 +#define RAR_EXTRACT 2 + +char* rar_executable = "/usr/bin/rar"; + +static int file_readable(char *fname) +{ + FILE *f; + f = fopen(fname, "r"); + if (!f) return 0; + fclose(f); + return 1; +} + +static FILE* launch_pipe(pid_t *apid, char *executable, int action, char *archive, char *filename) +{ + int mypipe[2]; + pid_t pid; + + if (pipe(mypipe)) { + mp_msg(MSGT_GLOBAL, MSGL_ERR, "RAR: Cannot create pipe.\n"); + return NULL; + } + + pid = fork(); + if (pid == 0) { + /* This is the child process. Execute the shell command. */ + close(mypipe[0]); + dup2(mypipe[1], 1); + close(2); /* suppress stderr messages */ + if (action == RAR_LIST) { + execl(executable, executable, "l", archive, NULL); + } else if (action == RAR_EXTRACT) { + execl(executable, executable, "p", "-inul", archive, filename, NULL); + } + mp_msg(MSGT_GLOBAL, MSGL_ERR, "RAR: Cannot execute %s\n", executable); + _exit(EXIT_FAILURE); + } else if (pid < 0) { + /* The fork failed. Report failure. */ + mp_msg(MSGT_GLOBAL, MSGL_ERR, "RAR: Fork failed\n"); + return NULL; + } else { + /* This is the parent process. Prepare the pipe stream. */ + close(mypipe[1]); + *apid = pid; + return fdopen(mypipe[0], "r"); + } +} + +#define ALLOC_INCR 65536 +int urarlib_get(unsigned char **output, unsigned long *size, char *filename, void *rarfile, char *libpassword) +{ + int bufsize, bytesread; + pid_t pid; + int status; + + if (!file_readable(rarfile)) return 0; + + rar_pipe = launch_pipe(&pid, rar_executable, RAR_EXTRACT, rarfile, filename); + if (!rar_pipe) return 0; + + *size = 0; + + *output = (char*)malloc(ALLOC_INCR); + + while (bytesread = fread(*output + *size, 1, ALLOC_INCR, rar_pipe)) { + *size += bytesread; + if (bytesread == ALLOC_INCR) { + *output = (char*)realloc(*output, *size + ALLOC_INCR); + } else { + break; + } + } + fclose(rar_pipe); + waitpid(pid, &status, 0); + if (status != 0) { + free(*output); + return 0; + } + return 1; +} + +int urarlib_list(void *rarfile, ArchiveList_struct **list) +{ + char buf[1024]; + pid_t pid; + int status; + + ArchiveList_struct *alist = NULL, *current = NULL, *new; + + if (!file_readable(rarfile)) return 0; + + rar_pipe = launch_pipe(&pid, rar_executable, RAR_LIST, rarfile, NULL); + if (!rar_pipe) return 0; + while (fgets(buf, 1024, rar_pipe)) { + char fname[1024]; + int packsize, unpsize, ratio; + int day, month, year, hour, min; + + if (sscanf(buf, "%1023s %d %d %d%% %d-%d-%d %d:%d", + fname, &unpsize, &packsize, &ratio, + &day, &month, &year, &hour, &min) == 9) { + new = (ArchiveList_struct *)malloc(sizeof(ArchiveList_struct)); + memset(new, 0, sizeof(ArchiveList_struct)); + if (current == NULL) { + current = alist = new; + } else { + current->next = new; + current = new; + } + current->item.Name = strdup(fname); + current->item.PackSize = packsize; + current->item.UnpSize = unpsize; + } + } + fclose(rar_pipe); + waitpid(pid, &status, 0); + if (status != 0) { + urarlib_freelist(alist); + return 0; + } + if (!alist) { + return 0; + } + *list = alist; + return 1; +} + +void urarlib_freelist(ArchiveList_struct *list) +{ + ArchiveList_struct* tmp = list; + + while ( list ) { + tmp = list->next; + free( list->item.Name ); + free( list ); + list = tmp; + } +} + diff -urN vanilla/main/unrarlib_fake.h main/unrarlib_fake.h --- vanilla/main/unrarlib_fake.h 1970-01-01 01:00:00.000000000 +0100 +++ main/unrarlib_fake.h 2005-04-17 12:26:11.000000000 +0200 @@ -0,0 +1,20 @@ +/* Fake unrarlib which calls rar executable */ + +struct RAR20_archive_entry /* These infos about files are */ +{ /* stored in RAR v2.0 archives */ + char *Name; + unsigned int PackSize; + unsigned int UnpSize; +}; + +typedef struct archivelist /* used to list archives */ +{ + struct RAR20_archive_entry item; + struct archivelist *next; +} ArchiveList_struct; + +extern char* rar_executable; + +int urarlib_get(unsigned char **output, unsigned long *size, char *filename, void *rarfile, char *libpassword);; +int urarlib_list(void *rarfile, ArchiveList_struct **list); +void urarlib_freelist(ArchiveList_struct *list); diff -urN vanilla/main/vobsub.c main/vobsub.c --- vanilla/main/vobsub.c 2004-12-25 13:08:33.000000000 +0100 +++ main/vobsub.c 2005-04-17 13:07:38.515767905 +0200 @@ -23,6 +23,9 @@ #ifdef USE_UNRARLIB #include "unrarlib.h" #endif +#ifdef USE_UNRARLIB_FAKE +#include "unrarlib_fake.h" +#endif #define MIN(a, b) ((a)<(b)?(a):(b)) #define MAX(a, b) ((a)>(b)?(a):(b)) @@ -34,7 +37,7 @@ * The RAR file must have the same basename as the file to open * See **********************************************************************/ -#ifdef USE_UNRARLIB +#if defined(USE_UNRARLIB) || defined(USE_UNRARLIB_FAKE) typedef struct { FILE *file; unsigned char *data; @@ -95,7 +98,11 @@ int i, num_files, name_len; ArchiveList_struct *list, *lp; /* the cast in the next line is a hack to overcome a design flaw (IMHO) in unrarlib */ +#ifdef USE_UNRARLIB num_files = urarlib_list (rar_filename, (ArchiveList_struct *)&list); +#else /* USE_UNRARLIB_FAKE */ + num_files = urarlib_list (rar_filename, &list); +#endif if (num_files > 0) { char *demanded_ext; demanded_ext = strrchr (p, '.');