Mercurial > mplayer.hg
annotate unrar_exec.c @ 26896:4559d4a7c3cb
Check for ALTIVEC_H instead of __APPLE_CC__ to decide which AltiVec vector
declaration syntax to use. Checking for HAVE_ALTIVEC_VECTOR_BRACES would be
better, but this variant is more likely to be mergeable upstream.
author | diego |
---|---|
date | Fri, 30 May 2008 12:09:06 +0000 |
parents | 0f42fb42843c |
children | 32725ca88fed |
rev | line source |
---|---|
25361
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
1 /* |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
2 * List files and extract file from rars by using external executable unrar. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
3 * |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
4 * Copyright (C) 2005 Jindrich Makovicka <makovick gmail com> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
5 * Copyright (C) 2007 Ulion <ulion2002 gmail com> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
6 * |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
7 * This file is part of MPlayer. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
8 * |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
9 * MPlayer is free software; you can redistribute it and/or modify |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
12 * (at your option) any later version. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
13 * |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
14 * MPlayer is distributed in the hope that it will be useful, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
17 * GNU General Public License for more details. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
18 * |
26743
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
25399
diff
changeset
|
19 * You should have received a copy of the GNU General Public License along |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
25399
diff
changeset
|
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
25399
diff
changeset
|
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
25361
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
22 */ |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
23 |
25399
45d3ecc4c7e0
Use correct #include for waitpid, fixes the warning:
diego
parents:
25361
diff
changeset
|
24 #include <sys/wait.h> |
25361
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
25 #include <unistd.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
26 #include <fcntl.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
27 #include <stdlib.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
28 #include <stdio.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
29 #include <string.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
30 #include <errno.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
31 #include <locale.h> |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
32 #include "unrar_exec.h" |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
33 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
34 #include "mp_msg.h" |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
35 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
36 #define UNRAR_LIST 1 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
37 #define UNRAR_EXTRACT 2 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
38 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
39 char* unrar_executable = NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
40 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
41 static FILE* launch_pipe(pid_t *apid, const char *executable, int action, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
42 const char *archive, const char *filename) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
43 { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
44 if (!executable || access(executable, R_OK | X_OK)) return NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
45 if (access(archive, R_OK)) return NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
46 { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
47 int mypipe[2]; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
48 pid_t pid; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
49 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
50 if (pipe(mypipe)) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
51 mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Cannot create pipe.\n"); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
52 return NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
53 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
54 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
55 pid = fork(); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
56 if (pid == 0) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
57 /* This is the child process. Execute the unrar executable. */ |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
58 close(mypipe[0]); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
59 // Close MPlayer's stdin, stdout and stderr so the unrar binary |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
60 // can not mess them up. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
61 // TODO: Close all other files except the pipe. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
62 close(0); close(1); close(2); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
63 // Assign new stdin, stdout and stderr and check they actually got the |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
64 // right descriptors. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
65 if (open("/dev/null", O_RDONLY) != 0 || dup(mypipe[1]) != 1 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
66 || open("/dev/null", O_WRONLY) != 2) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
67 _exit(EXIT_FAILURE); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
68 if (action == UNRAR_LIST) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
69 execl(executable, executable, "v", archive, NULL); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
70 else if (action == UNRAR_EXTRACT) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
71 execl(executable, executable, "p", "-inul", "-p-", |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
72 archive,filename,NULL); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
73 mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Cannot execute %s\n", executable); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
74 _exit(EXIT_FAILURE); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
75 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
76 if (pid < 0) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
77 /* The fork failed. Report failure. */ |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
78 mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Fork failed\n"); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
79 return NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
80 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
81 /* This is the parent process. Prepare the pipe stream. */ |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
82 close(mypipe[1]); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
83 *apid = pid; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
84 if (action == UNRAR_LIST) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
85 mp_msg(MSGT_GLOBAL, MSGL_V, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
86 "UnRAR: call unrar with command line: %s v %s\n", |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
87 executable, archive); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
88 else if (action == UNRAR_EXTRACT) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
89 mp_msg(MSGT_GLOBAL, MSGL_V, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
90 "UnRAR: call unrar with command line: %s p -inul -p- %s %s\n", |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
91 executable, archive, filename); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
92 return fdopen(mypipe[0], "r"); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
93 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
94 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
95 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
96 #define ALLOC_INCR 1 * 1024 * 1024 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
97 int unrar_exec_get(unsigned char **output, unsigned long *size, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
98 const char *filename, const char *rarfile) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
99 { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
100 int bufsize = ALLOC_INCR, bytesread; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
101 pid_t pid; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
102 int status = 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
103 FILE *rar_pipe; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
104 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
105 rar_pipe=launch_pipe(&pid,unrar_executable,UNRAR_EXTRACT,rarfile,filename); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
106 if (!rar_pipe) return 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
107 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
108 *size = 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
109 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
110 *output = malloc(bufsize); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
111 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
112 while (*output) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
113 bytesread=fread(*output+*size, 1, bufsize-*size, rar_pipe); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
114 if (bytesread <= 0) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
115 break; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
116 *size += bytesread; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
117 if (*size == bufsize) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
118 char *p; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
119 bufsize += ALLOC_INCR; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
120 p = realloc(*output, bufsize); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
121 if (!p) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
122 free(*output); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
123 *output = p; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
124 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
125 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
126 fclose(rar_pipe); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
127 pid = waitpid(pid, &status, 0); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
128 if (!*output || !*size || (pid == -1 && errno != ECHILD) || |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
129 (pid > 0 && status)) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
130 free(*output); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
131 *output = NULL; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
132 *size = 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
133 return 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
134 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
135 if (bufsize > *size) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
136 char *p = realloc(*output, *size); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
137 if (p) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
138 *output = p; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
139 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
140 mp_msg(MSGT_GLOBAL, MSGL_V, "UnRAR: got file %s len %lu\n", filename,*size); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
141 return 1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
142 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
143 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
144 #define PARSE_NAME 0 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
145 #define PARSE_PROPS 1 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
146 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
147 int unrar_exec_list(const char *rarfile, ArchiveList_struct **list) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
148 { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
149 char buf[1024], fname[1024]; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
150 char *p; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
151 pid_t pid; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
152 int status = 0, file_num = -1, ignore_next_line = 0, state = PARSE_NAME; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
153 FILE *rar_pipe; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
154 ArchiveList_struct *alist = NULL, *current = NULL, *new; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
155 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
156 rar_pipe = launch_pipe(&pid, unrar_executable, UNRAR_LIST, rarfile, NULL); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
157 if (!rar_pipe) return -1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
158 while (fgets(buf, sizeof(buf), rar_pipe)) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
159 int packsize, unpsize, ratio, day, month, year, hour, min; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
160 int llen = strlen(buf); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
161 // If read nothing, we got a file_num -1. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
162 if (file_num == -1) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
163 file_num = 0; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
164 if (buf[llen-1] != '\n') |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
165 // The line is too long, ignore it. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
166 ignore_next_line = 2; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
167 if (ignore_next_line) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
168 --ignore_next_line; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
169 state = PARSE_NAME; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
170 continue; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
171 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
172 // Trim the line. |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
173 while (llen > 0 && strchr(" \t\n\r\v\f", buf[llen-1])) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
174 --llen; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
175 buf[llen] = '\0'; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
176 p = buf; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
177 while (*p && strchr(" \t\n\r\v\f", *p)) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
178 ++p; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
179 if (!*p) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
180 state = PARSE_NAME; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
181 continue; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
182 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
183 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
184 if (state == PARSE_PROPS && sscanf(p, "%d %d %d%% %d-%d-%d %d:%d", |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
185 &unpsize, &packsize, &ratio, &day, |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
186 &month, &year, &hour, &min) == 8) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
187 new = calloc(1, sizeof(ArchiveList_struct)); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
188 if (!new) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
189 file_num = -1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
190 break; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
191 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
192 if (!current) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
193 alist = new; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
194 else |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
195 current->next = new; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
196 current = new; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
197 current->item.Name = strdup(fname); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
198 state = PARSE_NAME; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
199 if (!current->item.Name) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
200 file_num = -1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
201 break; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
202 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
203 current->item.PackSize = packsize; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
204 current->item.UnpSize = unpsize; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
205 ++file_num; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
206 continue; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
207 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
208 strcpy(fname, p); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
209 state = PARSE_PROPS; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
210 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
211 fclose(rar_pipe); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
212 pid = waitpid(pid, &status, 0); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
213 if (file_num < 0 || (pid == -1 && errno != ECHILD) || |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
214 (pid > 0 && status)) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
215 unrar_exec_freelist(alist); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
216 return -1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
217 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
218 if (!alist) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
219 return -1; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
220 *list = alist; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
221 mp_msg(MSGT_GLOBAL, MSGL_V, "UnRAR: list got %d files\n", file_num); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
222 return file_num; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
223 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
224 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
225 void unrar_exec_freelist(ArchiveList_struct *list) |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
226 { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
227 ArchiveList_struct* tmp; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
228 |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
229 while (list) { |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
230 tmp = list->next; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
231 free(list->item.Name); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
232 free(list); |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
233 list = tmp; |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
234 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
235 } |
f95cd1391ea0
Support using unrar executable to access rar-compressed vobsub files.
ulion
parents:
diff
changeset
|
236 |