Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/unpack.m @ 14626:f947d2922feb stable rc-3-6-2-0
3.6.2-rc0 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-05-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 May 2012 13:46:18 -0400 |
parents | 72c96de7a403 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
1 ## Copyright (C) 2006-2012 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 | |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12500
diff
changeset
|
24 ## @var{dir}. If @var{file} is a list of strings, then each file is |
12500
8f2056646dba
Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
25 ## unpacked individually. If @var{dir} is not specified, it defaults to |
8f2056646dba
Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
26 ## the current directory. If a directory is in the file list, then the |
8f2056646dba
Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
27 ## @var{filetype} must also be specified. |
6082 | 28 ## |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12500
diff
changeset
|
29 ## The optional return value is a list of @var{files} unpacked. |
12500
8f2056646dba
Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
30 ## @seealso{bzip2, gzip, zip, tar} |
6082 | 31 ## @end deftypefn |
32 | |
33 ## Author: Bill Denney <denney@seas.upenn.edu> | |
34 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
35 function filelist = unpack (file, dir = ".", filetype = "") |
6082 | 36 |
37 if (nargin < 1 || nargin > 3) | |
38 print_usage (); | |
39 endif | |
40 | |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
41 if (! ischar (file) && ! iscellstr (file)) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
42 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
|
43 endif |
6082 | 44 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
45 ## character arrays of more than one string must be treated as cell strings |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
46 if (ischar (file) && ! isvector (file)) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
47 file = cellstr (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
48 endif |
6082 | 49 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
50 ## 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
|
51 if (iscellstr (file)) |
6082 | 52 files = {}; |
53 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
|
54 tmpfiles = unpack (file{i}, dir); |
6082 | 55 files = {files{:} tmpfiles{:}}; |
56 endfor | |
57 | |
8352
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
58 ## Return output if requested. |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
59 if (nargout > 0) |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
60 filelist = files; |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
61 endif |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
62 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
63 return; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
64 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
65 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
66 if (isdir (file)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
67 if (isempty (filetype)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
68 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
|
69 elseif (! any (strcmpi (filetype, "gunzip"))) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
70 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
|
71 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
72 ext = ".gz"; |
6082 | 73 else |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
74 [pathstr, name, ext] = fileparts (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
75 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
76 ## 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
|
77 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
|
78 [tmppathstr, tmpname, tmpext] = fileparts (name); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
79 if (strcmpi (tmpext, ".tar")) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
80 name = tmpname; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
81 ext = cstrcat (tmpext, ext); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
82 endif |
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 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
85 ## 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
|
86 if (! isempty (strfind (file, "://"))) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
87 ## 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
|
88 urlfile = file; |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
89 ## 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
|
90 ## 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
|
91 tmpfile = cstrcat (tmpnam (), ext); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
92 [file, success, msg] = urlwrite (urlfile, tmpfile); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
93 if (! success) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
94 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
|
95 endif |
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 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
98 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
99 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
100 ## 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
|
101 ## use that to check for existence. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
102 cfile = canonicalize_file_name (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
103 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
104 if (isempty (cfile)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
105 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
|
106 else |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
107 file = cfile; |
6082 | 108 endif |
109 | |
110 ## Instructions on what to do for any extension. | |
111 ## | |
112 ## The field names are the file extension without periods. | |
113 ## The first cell is what is executed to unpack an archive verbosely. | |
114 ## The second cell is what is executed to unpack an archive quietly. | |
115 ## The third cell is the function to execute on output to get the | |
116 ## files list. | |
117 ## The fourth cell indicates if the files may need to be manually moved | |
118 ## (i.e. tar and unzip decompress into the current directory while | |
119 ## bzip2 and gzip decompress the file at its location). | |
120 persistent commandlist; | |
121 if (isempty (commandlist)) | |
6546 | 122 commandlist.gz = {"gzip -d -v -r \"%s\"", ... |
10549 | 123 "gzip -d -r \"%s\"", ... |
124 @__parse_gzip__, true}; | |
6082 | 125 commandlist.z = commandlist.gz; |
6546 | 126 commandlist.bz2 = {"bzip2 -d -v \"%s\"", ... |
10549 | 127 "bzip2 -d \"%s\"", ... |
128 @__parse_bzip2__, true}; | |
6082 | 129 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
|
130 commandlist.tar = {"tar xvf \"%s\"", ... |
10549 | 131 "tar xf \"%s\"", ... |
132 @__parse_tar__, false}; | |
9170
81a755db4db4
pass xvf to tar instead of -x -v -f
Peter O'Gorman <pogma@thewrittenword.com>
parents:
9051
diff
changeset
|
133 commandlist.targz = {"gzip -d -c \"%s\" | tar xvf -", ... |
10549 | 134 "gzip -d -c \"%s\" | tar xf -", ... |
135 @__parse_tar__, false}; | |
6082 | 136 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
|
137 commandlist.tarbz2 = {"bzip2 -d -c \"%s\" | tar xvf -", ... |
10549 | 138 "bzip2 -d -c \"%s\" | tar xf -", ... |
139 @__parse_tar__, false}; | |
6082 | 140 commandlist.tarbz = commandlist.tarbz2; |
141 commandlist.tbz2 = commandlist.tarbz2; | |
142 commandlist.tbz = commandlist.tarbz2; | |
143 commandlist.zip = {"unzip \"%s\"", ... | |
10549 | 144 "unzip -q \"%s\"", ... |
145 @__parse_zip__, false}; | |
6082 | 146 endif |
147 | |
148 nodotext = ext(! ismember (ext, ".")); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
149 |
6082 | 150 origdir = pwd (); |
151 | |
152 if (isfield (commandlist, nodotext)) | |
153 [commandv, commandq, parser, move] = deal (commandlist.(nodotext){:}); | |
154 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
|
155 cenddir = canonicalize_file_name (dir); |
6082 | 156 needmove = move && ! strcmp (cstartdir, cenddir); |
157 if (nargout > 0 || needmove) | |
158 command = commandv; | |
159 else | |
160 command = commandq; | |
161 endif | |
162 else | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
163 warning ("unpack:filetype", "unrecognized file type, %s", ext); |
6082 | 164 files = file; |
165 return; | |
166 endif | |
167 | |
168 ## 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
|
169 s = stat (dir); |
6082 | 170 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
|
171 [status, msg] = mkdir (dir); |
6082 | 172 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
|
173 error ("unpack: mkdir failed to create %s: %s", dir, msg); |
6082 | 174 endif |
175 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
|
176 error ("unpack: %s: not a directory", dir); |
6082 | 177 endif |
178 | |
179 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
|
180 cd (dir); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7525
diff
changeset
|
181 [status, output] = system (sprintf (cstrcat (command, " 2>&1"), file)); |
6082 | 182 unwind_protect_cleanup |
183 cd (origdir); | |
184 end_unwind_protect | |
185 | |
186 if (status) | |
187 error ("unpack: unarchiving program exited with status: %d\n%s", | |
10549 | 188 status, output); |
6082 | 189 endif |
190 | |
6084 | 191 if (nargout > 0 || needmove) |
6082 | 192 ## Trim the last cr if needed. |
193 ## FIXME -- will this need to change to a check for "\r\n" for windows? | |
194 if (output(length (output)) == "\n") | |
195 output(length (output)) = []; | |
196 endif | |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8352
diff
changeset
|
197 files = parser (strsplit (output, "\n"))'; |
6082 | 198 |
199 ## Move files if necessary | |
200 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
|
201 [st, msg, msgid] = movefile (files, dir); |
6082 | 202 if (! st) |
10549 | 203 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
|
204 dir, msg); |
6082 | 205 endif |
206 | |
207 ## Fix the names for the files since they were moved. | |
208 for i = 1:numel (files) | |
10549 | 209 files{i} = strrep (files{i}, cstartdir, cenddir); |
6082 | 210 endfor |
211 endif | |
212 | |
213 ## Return output if requested. | |
214 if (nargout > 0) | |
215 filelist = files; | |
216 endif | |
217 endif | |
218 | |
219 endfunction | |
220 | |
221 function files = __parse_zip__ (output) | |
222 ## Parse the output from zip and unzip. | |
223 | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
224 ## Skip first line which is Archive header |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
225 output(1) = []; |
6082 | 226 for i = 1:length (output) |
227 files{i} = output{i}(14:length(output{i})); | |
228 endfor | |
229 endfunction | |
230 | |
231 function output = __parse_tar__ (output) | |
232 ## This is a noop, but it makes things simpler for other cases. | |
233 endfunction | |
234 | |
235 function files = __parse_gzip__ (output) | |
236 ## Parse the output from gzip and gunzip returning the files | |
237 ## commpressed (or decompressed). | |
238 | |
239 files = {}; | |
240 ## The middle ": " should indicate a good place to start looking for | |
241 ## the filename. | |
242 for i = 1:length (output) | |
243 colons = strfind (output{i}, ":"); | |
244 if (isempty (colons)) | |
6083 | 245 warning ("unpack:parsing", |
10549 | 246 "Unable to parse line (gzip missing colon):\n%s", output{i}); |
6082 | 247 else |
248 midcolon = colons(ceil (length (colons)/2)); | |
249 thisstr = output{i}(midcolon+2:length(output{i})); | |
250 idx = index (thisstr, "with") + 5; | |
251 if (isempty (idx)) | |
10549 | 252 warning ("unpack:parsing", |
253 "Unable to parse line (gzip missing with):\n%s", output{i}); | |
6082 | 254 else |
10549 | 255 files{i} = thisstr(idx:length (thisstr)); |
6082 | 256 endif |
257 endif | |
258 endfor | |
259 endfunction | |
260 | |
261 function files = __parse_bzip2__ (output) | |
262 ## Parse the output from bzip2 and bunzip2 returning the files | |
263 ## commpressed (or decompressed). | |
264 | |
265 files = {}; | |
266 for i = 1:length (output) | |
267 ## the -5 is to remove the ".bz2:" | |
268 endoffilename = rindex (output{i}, ": ") - 5; | |
269 if (isempty (endoffilename)) | |
270 warning ("unpack:parsing", "Unable to parse line:\n%s", output{i}); | |
271 else | |
272 files{i} = output{i}(3:endoffilename); | |
273 endif | |
274 endfor | |
275 endfunction |