annotate scripts/miscellaneous/unpack.m @ 18891:7bbe3658c5ef

maint: Use "FIXME:" coding convention in m-files. * flipdim.m, prepad.m, rotdim.m, doc.m, strread.m, textread.m, krylov.m, colon.m, dump_prefs.m, fileattrib.m, getappdata.m, __xzip__.m, unpack.m, fsolve.m, axis.m, meshc.m, print.m, __ghostscript__.m, __go_draw_axes__.m, __print_parse_opts__.m, struct2hdl.m, unique.m, spstats.m, treeplot.m, test.m, datestr.m: Use "FIXME:" coding convention in m-files.
author Rik <rik@octave.org>
date Wed, 25 Jun 2014 13:45:41 -0700
parents d63878346099
children 0ded8964c13a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17000
diff changeset
1 ## Copyright (C) 2006-2013 Bill Denney
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2 ##
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
4 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6546
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6546
diff changeset
8 ## your option) any later version.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
9 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
14 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6546
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6546
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
18
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype})
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
31 ## @end deftypefn
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
32
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
33 ## Author: Bill Denney <denney@seas.upenn.edu>
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
36
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
37 if (nargin < 1 || nargin > 3)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
38 print_usage ();
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
39 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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))
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
42 error ("unpack: invalid input file class, %s", class (file));
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
43 endif
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
52 files = {};
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
55 files = {files{:} tmpfiles{:}};
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
56 endfor
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
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)))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
78 [~, tmpname, tmpext] = fileparts (name);
12499
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;
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16724
diff changeset
81 ext = [tmpext ext];
12499
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, "://")))
18891
7bbe3658c5ef maint: Use "FIXME:" coding convention in m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
87 ## FIXME: The above is not a perfect test for a URL
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
88 urlfile = file;
18891
7bbe3658c5ef maint: Use "FIXME:" coding convention in m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
89 ## FIXME: Should we name the file that we download with the
7bbe3658c5ef maint: Use "FIXME:" coding convention in m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
90 ## same file name as the URL requests?
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16724
diff changeset
91 tmpfile = [tmpnam() ext];
12499
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)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
94 error ('unpack: could not get "%s": %s', urlfile, msg);
12499
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))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
105 error ('unpack: file "%s" not found', file);
12499
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
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
108 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
109
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
110 ## Instructions on what to do for any extension.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
111 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
112 ## The field names are the file extension without periods.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
113 ## The first cell is what is executed to unpack an archive verbosely.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
114 ## The second cell is what is executed to unpack an archive quietly.
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
115 ## The third cell is the function to execute on output to get the files list.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
116 ## The fourth cell indicates if the files may need to be manually moved
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
117 ## (i.e., tar and unzip decompress into the current directory while
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
118 ## bzip2 and gzip decompress the file at its location).
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
119 persistent commandlist;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
120 if (isempty (commandlist))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
121 commandlist.gz = {'gzip -d -v -r "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
122 'gzip -d -r "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
123 @__parse_gzip__, true};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
124 commandlist.z = commandlist.gz;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
125 commandlist.bz2 = {'bzip2 -d -v "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
126 'bzip2 -d "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
127 @__parse_bzip2__, true};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
128 commandlist.bz = commandlist.bz2;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
129 commandlist.tar = {'tar xvf "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
130 'tar xf "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
131 @__parse_tar__, false};
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
132 commandlist.targz = {'gzip -d -c "%s" | tar xvf -', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
133 'gzip -d -c "%s" | tar xf -', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
134 @__parse_tar__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
135 commandlist.tgz = commandlist.targz;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
136 commandlist.tarbz2 = {'bzip2 -d -c "%s" | tar xvf -', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
137 'bzip2 -d -c "%s" | tar xf -', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
138 @__parse_tar__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
139 commandlist.tarbz = commandlist.tarbz2;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
140 commandlist.tbz2 = commandlist.tarbz2;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
141 commandlist.tbz = commandlist.tarbz2;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
142 commandlist.zip = {'unzip -n "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
143 'unzip -nq "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
144 @__parse_zip__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
145 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
146
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
147 ## Unzip doesn't actually care about the extension
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
148 if (strcmp (filetype, "unzip"))
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
149 nodotext = "zip";
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
150 else
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
151 nodotext = ext(ext != '.');
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
152 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
153
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
154 origdir = pwd ();
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
155
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
156 if (isfield (commandlist, nodotext))
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
157 [commandv, commandq, parser, move] = deal (commandlist.(nodotext){:});
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
158 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
159 cenddir = canonicalize_file_name (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
160 needmove = move && ! strcmp (cstartdir, cenddir);
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
161 if (nargout > 0 || needmove)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
162 command = commandv;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
163 else
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
164 command = commandq;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
165 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
166 else
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
167 warning ("unpack:filetype", "unrecognized file type, %s", ext);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
168 files = file;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
169 return;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
170 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
171
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
172 ## 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
173 s = stat (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
174 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
175 [status, msg] = mkdir (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
176 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
177 error ("unpack: mkdir failed to create %s: %s", dir, msg);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
178 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
179 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
180 error ("unpack: %s: not a directory", dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
181 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
182
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
183 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
184 cd (dir);
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16724
diff changeset
185 [status, output] = system (sprintf ([command " 2>&1"], file));
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
186 unwind_protect_cleanup
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
187 cd (origdir);
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
188 end_unwind_protect
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
189
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
190 if (status)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
191 error ("unpack: unarchiving program exited with status: %d\n%s",
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
192 status, output);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
193 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
194
6084
38114c34b44a [project @ 2006-10-25 03:52:48 by jwe]
jwe
parents: 6083
diff changeset
195 if (nargout > 0 || needmove)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
196 ## Trim the last CR if needed.
18891
7bbe3658c5ef maint: Use "FIXME:" coding convention in m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
197 ## FIXME: Will this need to change to a check for "\r\n" for windows?
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
198 if (output(end) == "\n")
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
199 output(end) = [];
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
200 endif
16724
b7667fcb9fbc Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents: 16403
diff changeset
201 files = parser (ostrsplit (output, "\n"))';
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
202
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
203 ## Move files if necessary
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
204 if (needmove)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
205 [st, msg, ~] = movefile (files, dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
206 if (! st)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
207 error ('unpack: unable to move files to "%s": %s', dir, msg);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
208 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
209
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
210 ## Fix the names for the files since they were moved.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
211 for i = 1:numel (files)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
212 files{i} = strrep (files{i}, cstartdir, cenddir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
213 endfor
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
214 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
215
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
216 ## Return output if requested.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
217 if (nargout > 0)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
218 filelist = files;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
219 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
220 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
221
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
222 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
223
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
224 function files = __parse_zip__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
225 ## Parse the output from zip and unzip.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
226
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
227 ## Skip first line which is Archive header
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
228 files = char (output(2:end));
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
229 ## Trim constant width prefix and return cell array
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
230 files = cellstr (files(:,14:end))
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
231 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
232
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
233 function output = __parse_tar__ (output)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
234 ## This is a no-op, but it makes things simpler for other cases.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
235 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
236
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
237 function files = __parse_gzip__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
238 ## Parse the output from gzip and gunzip returning the files
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
239 ## commpressed (or decompressed).
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
240
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
241 files = regexprep (output, '^.+ with (.*)$', '$1');
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
242 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
243
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
244 function files = __parse_bzip2__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
245 ## Parse the output from bzip2 and bunzip2 returning the files
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
246 ## commpressed (or decompressed).
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
247
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
248 ## Strip leading blanks and .bz2 extension from file name
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
249 files = regexprep (output, '^\s+(.*)\.bz2: .*', '$1');
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
250 endfunction
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
251