1 ## Copyright (C) 2002 Etienne Grossmann <etienne@isr.ist.utl.pt>
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
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
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/>.
17 ## @deftypefn{Function File} {@var{s} = } slurp_file ( f )
19 ## slurp_file return a whole text file @var{f} as a string @var{s}.
21 ## @var{f} : string : filename
22 ## @var{s} : string : contents of the file
24 ## If @var{f} is not an absolute filename, and
25 ## is not an immediately accessible file, slurp_file ()
26 ## will look for @var{f} in the path.
29 function s = slurp_file (f)
34 error ("f is not a string");
42 [st,err,msg] = stat (f);
43 if err && f(1) != "/",
44 f = file_in_loadpath (f);
46 ## Could not find it anywhere. Open will fail
48 error ("slurp_file : Can't find '%s' anywhere",f0);
52 ## I'll even get decent error messages!
53 [status, s] = system (sprintf ("cat '%s'",f), 1);