Mercurial > octave-nkf
annotate scripts/miscellaneous/unpack.m @ 12499:a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 03 Mar 2011 11:59:05 -0800 |
parents | d5bd2766c640 |
children | 8f2056646dba |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2006-2011 Bill Denney |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2 ## |
6082 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6082 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6082 | 18 |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
20 ## @deftypefn {Function File} {@var{files} =} unpack (@var{file}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}) |
6082 | 22 ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype}) |
23 ## Unpack the archive @var{file} based on its extension to the directory | |
24 ## @var{dir}. If @var{file} is a cellstr, then all files will be | |
25 ## handled individually. If @var{dir} is not specified, it defaults to | |
26 ## the current directory. It returns a list of @var{files} | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## unpacked. If a directory is in the file list, then the |
6082 | 28 ## @var{filetype} to unpack must also be specified. |
29 ## | |
30 ## The @var{files} includes the entire path to the output files. | |
8297 | 31 ## @seealso{bunzip2, tar, untar, gzip, gunzip, zip, unzip} |
6082 | 32 ## @end deftypefn |
33 | |
34 ## Author: Bill Denney <denney@seas.upenn.edu> | |
35 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 function filelist = unpack (file, dir = ".", filetype = "") |
6082 | 37 |
38 if (nargin < 1 || nargin > 3) | |
39 print_usage (); | |
40 endif | |
41 | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
42 if (! ischar (file) && ! iscellstr (file)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
43 error ("unpack: invalid input file class, %s", class(file)); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
44 endif |
6082 | 45 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
46 ## character arrays of more than one string must be treated as cell strings |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
47 if (ischar (file) && ! isvector (file)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
48 file = cellstr (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
49 endif |
6082 | 50 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
51 ## Recursively unpack cellstr arrays one file at a time |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
52 if (iscellstr (file)) |
6082 | 53 files = {}; |
54 for i = 1:numel (file) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
55 tmpfiles = unpack (file{i}, dir); |
6082 | 56 files = {files{:} tmpfiles{:}}; |
57 endfor | |
58 | |
8352
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
59 ## Return output if requested. |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
60 if (nargout > 0) |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
61 filelist = files; |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
62 endif |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
63 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
64 return; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
65 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
66 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
67 if (isdir (file)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
68 if (isempty (filetype)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
69 error ("unpack: FILETYPE must be given for a directory"); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
70 elseif (! any (strcmpi (filetype, "gunzip"))) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
71 error ("unpack: FILETYPE must be gunzip for a directory"); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
72 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
73 ext = ".gz"; |
6082 | 74 else |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
75 [pathstr, name, ext] = fileparts (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
76 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
77 ## Check to see if it's .tar.gz, .tar.Z, etc. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
78 if (any (strcmpi ({".gz" ".Z" ".bz2" ".bz"}, ext))) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
79 [tmppathstr, tmpname, tmpext] = fileparts (name); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
80 if (strcmpi (tmpext, ".tar")) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
81 name = tmpname; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
82 ext = cstrcat (tmpext, ext); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
83 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
84 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
85 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
86 ## If the file is a URL, download it and then work with that file. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
87 if (! isempty (strfind (file, "://"))) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
88 ## FIXME -- the above is not a perfect test for a URL |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
89 urlfile = file; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
90 ## FIXME -- should we name the file that we download with the |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
91 ## same file name as the URL requests? |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
92 tmpfile = cstrcat (tmpnam (), ext); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
93 [file, success, msg] = urlwrite (urlfile, tmpfile); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
94 if (! success) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
95 error ("unpack: could not get \"%s\": %s", urlfile, msg); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
96 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
97 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
98 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
99 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
100 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
101 ## canonicalize_file_name returns empty if the file isn't found, so |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
102 ## use that to check for existence. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
103 cfile = canonicalize_file_name (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
104 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
105 if (isempty (cfile)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
106 error ("unpack: file \"%s\" not found", file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
107 else |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
108 file = cfile; |
6082 | 109 endif |
110 | |
111 ## Instructions on what to do for any extension. | |
112 ## | |
113 ## The field names are the file extension without periods. | |
114 ## The first cell is what is executed to unpack an archive verbosely. | |
115 ## The second cell is what is executed to unpack an archive quietly. | |
116 ## The third cell is the function to execute on output to get the | |
117 ## files list. | |
118 ## The fourth cell indicates if the files may need to be manually moved | |
119 ## (i.e. tar and unzip decompress into the current directory while | |
120 ## bzip2 and gzip decompress the file at its location). | |
121 persistent commandlist; | |
122 if (isempty (commandlist)) | |
6546 | 123 commandlist.gz = {"gzip -d -v -r \"%s\"", ... |
10549 | 124 "gzip -d -r \"%s\"", ... |
125 @__parse_gzip__, true}; | |
6082 | 126 commandlist.z = commandlist.gz; |
6546 | 127 commandlist.bz2 = {"bzip2 -d -v \"%s\"", ... |
10549 | 128 "bzip2 -d \"%s\"", ... |
129 @__parse_bzip2__, true}; | |
6082 | 130 commandlist.bz = commandlist.bz2; |
9170
81a755db4db4
pass xvf to tar instead of -x -v -f
Peter O'Gorman <pogma@thewrittenword.com>
parents:
9051
diff
changeset
|
131 commandlist.tar = {"tar xvf \"%s\"", ... |
10549 | 132 "tar xf \"%s\"", ... |
133 @__parse_tar__, false}; | |
9170
81a755db4db4
pass xvf to tar instead of -x -v -f
Peter O'Gorman <pogma@thewrittenword.com>
parents:
9051
diff
changeset
|
134 commandlist.targz = {"gzip -d -c \"%s\" | tar xvf -", ... |
10549 | 135 "gzip -d -c \"%s\" | tar xf -", ... |
136 @__parse_tar__, false}; | |
6082 | 137 commandlist.tgz = commandlist.targz; |
9170
81a755db4db4
pass xvf to tar instead of -x -v -f
Peter O'Gorman <pogma@thewrittenword.com>
parents:
9051
diff
changeset
|
138 commandlist.tarbz2 = {"bzip2 -d -c \"%s\" | tar xvf -", ... |
10549 | 139 "bzip2 -d -c \"%s\" | tar xf -", ... |
140 @__parse_tar__, false}; | |
6082 | 141 commandlist.tarbz = commandlist.tarbz2; |
142 commandlist.tbz2 = commandlist.tarbz2; | |
143 commandlist.tbz = commandlist.tarbz2; | |
144 commandlist.zip = {"unzip \"%s\"", ... | |
10549 | 145 "unzip -q \"%s\"", ... |
146 @__parse_zip__, false}; | |
6082 | 147 endif |
148 | |
149 nodotext = ext(! ismember (ext, ".")); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
150 |
6082 | 151 origdir = pwd (); |
152 | |
153 if (isfield (commandlist, nodotext)) | |
154 [commandv, commandq, parser, move] = deal (commandlist.(nodotext){:}); | |
155 cstartdir = canonicalize_file_name (origdir); | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
156 cenddir = canonicalize_file_name (dir); |
6082 | 157 needmove = move && ! strcmp (cstartdir, cenddir); |
158 if (nargout > 0 || needmove) | |
159 command = commandv; | |
160 else | |
161 command = commandq; | |
162 endif | |
163 else | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
164 warning ("unpack:filetype", "unrecognized file type, %s", ext); |
6082 | 165 files = file; |
166 return; | |
167 endif | |
168 | |
169 ## Create the directory if necessary. | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
170 s = stat (dir); |
6082 | 171 if (isempty (s)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
172 [status, msg] = mkdir (dir); |
6082 | 173 if (! status) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
174 error ("unpack: mkdir failed to create %s: %s", dir, msg); |
6082 | 175 endif |
176 elseif (! S_ISDIR (s.mode)) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
177 error ("unpack: %s: not a directory", dir); |
6082 | 178 endif |
179 | |
180 unwind_protect | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
181 cd (dir); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7525
diff
changeset
|
182 [status, output] = system (sprintf (cstrcat (command, " 2>&1"), file)); |
6082 | 183 unwind_protect_cleanup |
184 cd (origdir); | |
185 end_unwind_protect | |
186 | |
187 if (status) | |
188 error ("unpack: unarchiving program exited with status: %d\n%s", | |
10549 | 189 status, output); |
6082 | 190 endif |
191 | |
6084 | 192 if (nargout > 0 || needmove) |
6082 | 193 ## Trim the last cr if needed. |
194 ## FIXME -- will this need to change to a check for "\r\n" for windows? | |
195 if (output(length (output)) == "\n") | |
196 output(length (output)) = []; | |
197 endif | |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8352
diff
changeset
|
198 files = parser (strsplit (output, "\n"))'; |
6082 | 199 |
200 ## Move files if necessary | |
201 if (needmove) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
202 [st, msg, msgid] = movefile (files, dir); |
6082 | 203 if (! st) |
10549 | 204 error ("unpack: unable to move files to \"%s\": %s", |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
205 dir, msg); |
6082 | 206 endif |
207 | |
208 ## Fix the names for the files since they were moved. | |
209 for i = 1:numel (files) | |
10549 | 210 files{i} = strrep (files{i}, cstartdir, cenddir); |
6082 | 211 endfor |
212 endif | |
213 | |
214 ## Return output if requested. | |
215 if (nargout > 0) | |
216 filelist = files; | |
217 endif | |
218 endif | |
219 | |
220 endfunction | |
221 | |
222 function files = __parse_zip__ (output) | |
223 ## Parse the output from zip and unzip. | |
224 | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
225 ## Skip first line which is Archive header |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
226 output(1) = []; |
6082 | 227 for i = 1:length (output) |
228 files{i} = output{i}(14:length(output{i})); | |
229 endfor | |
230 endfunction | |
231 | |
232 function output = __parse_tar__ (output) | |
233 ## This is a noop, but it makes things simpler for other cases. | |
234 endfunction | |
235 | |
236 function files = __parse_gzip__ (output) | |
237 ## Parse the output from gzip and gunzip returning the files | |
238 ## commpressed (or decompressed). | |
239 | |
240 files = {}; | |
241 ## The middle ": " should indicate a good place to start looking for | |
242 ## the filename. | |
243 for i = 1:length (output) | |
244 colons = strfind (output{i}, ":"); | |
245 if (isempty (colons)) | |
6083 | 246 warning ("unpack:parsing", |
10549 | 247 "Unable to parse line (gzip missing colon):\n%s", output{i}); |
6082 | 248 else |
249 midcolon = colons(ceil (length (colons)/2)); | |
250 thisstr = output{i}(midcolon+2:length(output{i})); | |
251 idx = index (thisstr, "with") + 5; | |
252 if (isempty (idx)) | |
10549 | 253 warning ("unpack:parsing", |
254 "Unable to parse line (gzip missing with):\n%s", output{i}); | |
6082 | 255 else |
10549 | 256 files{i} = thisstr(idx:length (thisstr)); |
6082 | 257 endif |
258 endif | |
259 endfor | |
260 endfunction | |
261 | |
262 function files = __parse_bzip2__ (output) | |
263 ## Parse the output from bzip2 and bunzip2 returning the files | |
264 ## commpressed (or decompressed). | |
265 | |
266 files = {}; | |
267 for i = 1:length (output) | |
268 ## the -5 is to remove the ".bz2:" | |
269 endoffilename = rindex (output{i}, ": ") - 5; | |
270 if (isempty (endoffilename)) | |
271 warning ("unpack:parsing", "Unable to parse line:\n%s", output{i}); | |
272 else | |
273 files{i} = output{i}(3:endoffilename); | |
274 endif | |
275 endfor | |
276 endfunction |