~ubuntu-branches/ubuntu/wily/octave-miscellaneous/wily

« back to all changes in this revision

Viewing changes to inst/slurp_file.m

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere, Sébastien Villemot
  • Date: 2012-10-17 13:40:55 UTC
  • mfrom: (1.2.1) (12 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: package-import@ubuntu.com-20121017134055-vatltexghy77fnv7
Tags: 1.2.0-1
[ Rafael Laboissiere ]
* Imported Upstream version 1.2.0
* Bump Standards-Version to 3.9.4 (no changes needed)
* Refresh for new upstream release
* Use Sébastien Villemot's @debian.org email address
* Remove obsolete DM-Upload-Allowed flag
* Add patch autoload-yes.patch
* Add copyright info for file lauchli.m (included in a Debian patch)
* Add patch partcnt-test-succeeds.patch
* Build-depends on octave-pkg-dev >= 1.0.3

[ Sébastien Villemot ]
* debian/control: fix versioned dependency on debhelper
* Add lintian override for false positive on hardening (fortify)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
## Copyright (C) 2002 Etienne Grossmann.  All rights reserved.
2
 
##
3
 
## This program is free software; you can redistribute it and/or modify it
4
 
## under the terms of the GNU General Public License as published by the
5
 
## Free Software Foundation; either version 2, or (at your option) any
6
 
## later version.
7
 
##
8
 
## This is distributed in the hope that it will be useful, but WITHOUT
 
1
## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
 
2
##
 
3
## This program is free software; you can redistribute it and/or modify it under
 
4
## the terms of the GNU General Public License as published by the Free Software
 
5
## Foundation; either version 3 of the License, or (at your option) any later
 
6
## version.
 
7
##
 
8
## This program is distributed in the hope that it will be useful, but WITHOUT
9
9
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11
 
## for more details.
 
10
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
11
## details.
 
12
##
 
13
## You should have received a copy of the GNU General Public License along with
 
14
## this program; if not, see <http://www.gnu.org/licenses/>.
12
15
 
13
16
## -*- texinfo -*-
14
17
## @deftypefn{Function File} {@var{s} = } slurp_file ( f ) 
21
24
## If @var{f} is not an absolute filename, and 
22
25
## is not an immediately accessible file, slurp_file () 
23
26
## will look for @var{f} in the path.
24
 
## @seealso{}
25
27
## @end deftypefn
26
28
 
27
 
## Author  : Etienne Grossmann <etienne@cs.uky.edu>
28
29
function s = slurp_file (f)
29
30
 
30
 
if ! ischar (f),  error ("slurp_file :  f  is not a string"); end
31
 
if isempty (f), error ("slurp_file :  f  is empty"); end
32
 
 
33
 
s = "";
34
 
 
35
 
f0 = f;
36
 
[st,err,msg] = stat (f);
37
 
if err && f(1) != "/", 
38
 
  f = file_in_loadpath (f);
39
 
                                # Could not find it anywhere. Open will
40
 
                                # fail.
41
 
  if isempty (f)
42
 
    f = f0;
43
 
    error ("slurp_file : Can't find '%s' anywhere",f0);
 
31
  if (nargin != 1)
 
32
    print_usage;
 
33
  elseif ! ischar (f)
 
34
    error ("f  is not a string");
 
35
  elseif isempty (f)
 
36
    error ("f  is empty");
 
37
  endif
 
38
 
 
39
  s = "";
 
40
 
 
41
  f0 = f;
 
42
  [st,err,msg] = stat (f);
 
43
  if err && f(1) != "/", 
 
44
    f = file_in_loadpath (f);
 
45
    if isempty (f)
 
46
      ## Could not find it anywhere. Open will fail
 
47
      f = f0;
 
48
      error ("slurp_file : Can't find '%s' anywhere",f0);
 
49
    end
44
50
  end
45
 
end
46
51
 
47
 
## I'll even get decent error messages!
48
 
[status, s] = system (sprintf ("cat '%s'",f), 1);
 
52
  ## I'll even get decent error messages!
 
53
  [status, s] = system (sprintf ("cat '%s'",f), 1);
 
54
endfunction