annotate libinterp/corefcn/utils.cc @ 20800:fb128aafc322

eliminate return statements after calls to print_usage * syscalls.cc, time.cc, tril.cc, typecast.cc, utils.cc: Eliminate return statements after calls to print_usage.
author John W. Eaton <jwe@octave.org>
date Thu, 03 Dec 2015 18:33:00 -0500
parents 200ae1d650b7
children d9ca869ca124
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19403
diff changeset
3 Copyright (C) 1993-2015 John W. Eaton
11012
30b9b0a507f1 add missing copyright
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
4 Copyright (C) 2010 VZLU Prague
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 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: 6694
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
25 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
28 #include <cerrno>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
29 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
31 #include <fstream>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
32 #include <iostream>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
33 #include <limits>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
34 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
35
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #include <sys/types.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include <unistd.h>
367
04d377033730 [project @ 1994-02-16 08:04:52 by jwe]
jwe
parents: 341
diff changeset
38
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
39 #include "vasnprintf.h"
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
40
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
41 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
42 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
43 #include "file-stat.h"
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
44 #include "lo-mappers.h"
11006
aca961a3f387 provide gethostname function
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
45 #include "lo-utils.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
46 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
47 #include "oct-env.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19152
diff changeset
48 #include "oct-locbuf.h"
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
49 #include "pathsearch.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19152
diff changeset
50 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
51 #include "str-vec.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
52
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
53 #include "Cell.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2442
diff changeset
54 #include <defaults.h>
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
55 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
56 #include "dirfns.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
57 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
58 #include "gripes.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "input.h"
10502
f13bf183a003 isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents: 10315
diff changeset
60 #include "lex.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
61 #include "load-path.h"
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
62 #include "oct-errno.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
63 #include "oct-hist.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
64 #include "oct-obj.h"
10613
e103fb2182ce use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents: 10605
diff changeset
65 #include "ov-range.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
66 #include "pager.h"
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
67 #include "parse.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
68 #include "sysdep.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
69 #include "toplev.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
70 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
71 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
72 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
73
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
74 // Return TRUE if S is a valid identifier.
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
75
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
76 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
77 valid_identifier (const char *s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
78 {
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
79 if (! s || ! (isalpha (*s) || *s == '_' || *s == '$'))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 return false;
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
81
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
82 while (*++s != '\0')
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
83 if (! (isalnum (*s) || *s == '_' || *s == '$'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
84 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
85
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
86 return true;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
87 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
88
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
89 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
90 valid_identifier (const std::string& s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
91 {
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
92 return valid_identifier (s.c_str ());
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
93 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
94
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8715
diff changeset
95 DEFUN (isvarname, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
96 "-*- texinfo -*-\n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4783
diff changeset
97 @deftypefn {Built-in Function} {} isvarname (@var{name})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
98 Return true if @var{name} is a valid variable name.\n\
12573
232a90612254 Add new section on parsing to documentation.
Rik <octave@nomad.inbox5.com>
parents: 12546
diff changeset
99 @seealso{iskeyword, exist, who}\n\
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
100 @end deftypefn")
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
101 {
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
102 octave_value retval = false;
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
103
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
104 int nargin = args.length ();
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
105
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
106 if (nargin != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
107 print_usage ();
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
108
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
109 if (args(0).is_string ())
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
110 {
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
111 std::string varname = args(0).string_value ();
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
112
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
113 retval = valid_identifier (varname) && ! is_keyword (varname);
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
114 }
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
115
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
116 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
117 }
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
118
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
119 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
120 %!assert (isvarname ("foo"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
121 %!assert (isvarname ("_foo"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
122 %!assert (isvarname ("_1"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
123 %!assert (isvarname ("1foo"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
124 %!assert (isvarname (""), false)
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
125 %!assert (isvarname (12), false)
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
126 %!assert (isvarname ("foo+bar"), false)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
127
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
128 %!error isvarname ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
129 %!error isvarname ("foo", "bar");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
130 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
131
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
132 // Return TRUE if F and G are both names for the same file.
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
133
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
134 bool
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
135 same_file (const std::string& f, const std::string& g)
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
136 {
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6379
diff changeset
137 return same_file_internal (f, g);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
138 }
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
139
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
140 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
141 almost_match (const std::string& std, const std::string& s, int min_match_len,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
142 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
143 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
144 int stdlen = std.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
145 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
146
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
147 return (slen <= stdlen
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
148 && slen >= min_match_len
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
149 && (case_sens
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
150 ? (strncmp (std.c_str (), s.c_str (), slen) == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
151 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
152 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
153
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
154 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
155
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
156 int
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
157 keyword_almost_match (const char * const *std, int *min_len,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
158 const std::string& s,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
159 int min_toks_to_match, int max_toks)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
160 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
161 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
162 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
163 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
164
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
165 if (s.empty () || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
166 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
167
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
168 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
169
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
170 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
171 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
172 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
173 if (*t == '\t')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
174 *t = ' ';
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
175 t++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
176 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
177
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
178 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
179 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
180 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
181
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
182 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
183 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
184
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
185
3072
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
186 const char **to_match = new const char * [max_toks + 1];
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
187 const char * const *s1 = std;
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
188 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
189
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
190 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
191 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
192
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
193 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
194 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
195 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
196 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
197 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
198 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
199
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
200 while (*beg == ' ')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
201 beg++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
202
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
203 if (*beg == '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
204 break;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
205
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
206 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
207 if (tok_count >= max_toks)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
208 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
209
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
210 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
211 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
212 s2[tok_count+1] = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
213
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
214 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
215
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
216 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
217 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
218 if (! almost_match (*s1, *s2, min_len[toks_matched], 0))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
219 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
220
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
221 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
222
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
223 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
224 s2++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
225
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
226 if (! *s2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
227 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
228 status = (toks_matched >= min_toks_to_match);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
229 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
230 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
231
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
232 if (! *s1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
233 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
234 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
235
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
236 done:
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
237
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
238 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
239 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
240
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
241 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
242 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
243
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18132
diff changeset
244 // Return nonzero if either NR or NC is zero. Return -1 if this
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
245 // should be considered fatal; return 1 if this is ok.
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
246
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
247 int
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
248 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
249 {
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
250 return (nr == 0 || nc == 0);
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
251 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
252
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
253 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
254
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
255 std::string
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
256 search_path_for_file (const std::string& path, const string_vector& names)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
257 {
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
258 dir_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
259
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
260 return octave_env::make_absolute (p.find_first_of (names));
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
261 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
262
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
263 // Find all locations of the given file in the path.
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
264
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
265 string_vector
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
266 search_path_for_all_files (const std::string& path, const string_vector& names)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
267 {
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
268 dir_path p (path);
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
269
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
270 string_vector sv = p.find_all_first_of (names);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
271
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20210
diff changeset
272 octave_idx_type len = sv.numel ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
273
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
274 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
275 sv[i] = octave_env::make_absolute (sv[i]);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
276
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
277 return sv;
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
278 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
279
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
280 static string_vector
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
281 make_absolute (const string_vector& sv)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
282 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20210
diff changeset
283 octave_idx_type len = sv.numel ();
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
284
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
285 string_vector retval (len);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
286
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
287 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
288 retval[i] = octave_env::make_absolute (sv[i]);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
289
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
290 return retval;
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
291 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
292
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
293 DEFUN (file_in_loadpath, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
294 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
295 @deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
296 @deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
297 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
298 Return the absolute name of @var{file} if it can be found in\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
299 the list of directories specified by @code{path}.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
300 \n\
10646
6c50b56824aa file_in_path, file_in_loadpath: return empty string instead of empty matrix if file not found
John W. Eaton <jwe@octave.org>
parents: 10613
diff changeset
301 If no file is found, return an empty character string.\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
302 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
303 If the first argument is a cell array of strings, search each directory of\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
304 the loadpath for element of the cell array and return the first that\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
305 matches.\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
306 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
307 If the second optional argument @qcode{\"all\"} is supplied, return a cell\n\
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20172
diff changeset
308 array containing the list of all files that have the same name in the path.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
309 If no files are found, return an empty cell array.\n\
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
310 @seealso{file_in_path, dir_in_loadpath, path}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5612
diff changeset
311 @end deftypefn")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
312 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
313 octave_value retval;
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
314
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
315 int nargin = args.length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
316
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
317 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
318 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
319
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
320 string_vector names = args(0).xall_strings ("file_in_loadpath: FILE argument must be a string");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
321
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
322 if (names.numel () > 0)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
323 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
324 if (nargin == 1)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
325 retval =
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
326 octave_env::make_absolute (load_path::find_first_of (names));
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
327 else if (nargin == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
328 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
329 std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
330
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
331 if (opt == "all")
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
332 retval = Cell (make_absolute
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
333 (load_path::find_all_first_of (names)));
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
334 else
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
335 error ("file_in_loadpath: \"all\" is only valid second argument");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
336 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
337 }
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
338 else
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
339 error ("file_in_loadpath: FILE argument must not be empty");
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
340
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
341 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
342 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
343
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
344 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
345 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
346 %! f = file_in_loadpath ("plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
347 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
348 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
349
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
350 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
351 %! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
352 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
353
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
354 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
355 %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
356 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
357
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
358 %!error file_in_loadpath ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
359 %!error file_in_loadpath ("foo", "bar", 1)
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
360 %!error file_in_loadpath ([])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
361 %!error file_in_loadpath ("plot.m", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
362 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
363
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
364 DEFUN (file_in_path, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
365 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
366 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
367 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
368 Return the absolute name of @var{file} if it can be found in @var{path}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
369 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
370 The value of @var{path} should be a colon-separated list of directories in\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
371 the format described for @code{path}. If no file is found, return an empty\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
372 character string. For example:\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
373 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
374 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
375 @group\n\
5456
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
376 file_in_path (EXEC_PATH, \"sh\")\n\
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
377 @result{} \"/bin/sh\"\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
378 @end group\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
379 @end example\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
380 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
381 If the second argument is a cell array of strings, search each directory of\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
382 the path for element of the cell array and return the first that matches.\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
383 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
384 If the third optional argument @qcode{\"all\"} is supplied, return a cell\n\
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20172
diff changeset
385 array containing the list of all files that have the same name in the path.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
386 If no files are found, return an empty cell array.\n\
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
387 @seealso{file_in_loadpath, dir_in_loadpath, path}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
388 @end deftypefn")
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
389 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
390 octave_value retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
391
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
392 int nargin = args.length ();
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
393
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
394 if (nargin < 2 || nargin > 3)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
395 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
396
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
397 std::string path = args(0).xstring_value ("file_in_path: PATH must be a string");
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20559
diff changeset
398
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
399 string_vector names = args(1).xall_strings ("file_in_path: FILE argument must be a string");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
400
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
401 if (names.numel () > 0)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
402 {
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
403 if (nargin == 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
404 retval = search_path_for_file (path, names);
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
405 else if (nargin == 3)
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20559
diff changeset
406 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
407 std::string opt = args(2).xstring_value ("file_in_path: optional third argument must be a string");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
408
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
409 if (opt == "all")
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
410 retval = Cell (make_absolute
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
411 (search_path_for_all_files (path, names)));
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
412 else
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
413 error ("file_in_path: \"all\" is only valid third argument");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
414 }
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
415 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
416 else
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
417 error ("file_in_path: FILE argument must not be empty");
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
418
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
419 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
420 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
421
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
422 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
423 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
424 %! f = file_in_path (path (), "plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
425 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
426 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
427
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
428 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
429 %! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
430 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
431
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
432 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
433 %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
434 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
435
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
436 %!error file_in_path ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
437 %!error file_in_path ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
438 %!error file_in_path ("foo", "bar", "baz", 1)
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
439 %!error file_in_path ([])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
440 %!error file_in_path (path (), [])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
441 %!error file_in_path (path (), "plot.m", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
442 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
443
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
444 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
445 file_in_path (const std::string& name, const std::string& suffix)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
446 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
447 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
448
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
449 if (! suffix.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
450 nm.append (suffix);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
451
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
452 return octave_env::make_absolute (load_path::find_file (nm));
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
453 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
454
19030
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
455 std::string
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
456 find_data_file_in_load_path (const std::string& fcn,
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
457 const std::string& file,
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
458 bool require_regular_file)
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
459 {
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
460 std::string fname = file;
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
461
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
462 if (! (octave_env::absolute_pathname (fname)
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
463 || octave_env::rooted_relative_pathname (fname)))
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
464 {
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
465 // Load path will also search "." first, but we don't want to
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
466 // issue a warning if the file is found in the current directory,
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
467 // so do an explicit check for that.
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
468
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
469 file_stat fs (fname);
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
470
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
471 bool local_file_ok
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
472 = fs.exists () && (fs.is_reg () || ! require_regular_file);
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
473
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
474 if (! local_file_ok)
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
475 {
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
476 // Not directly found; search load path.
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
477
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
478 std::string tmp
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
479 = octave_env::make_absolute (load_path::find_file (fname));
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
480
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
481 if (! tmp.empty ())
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
482 {
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
483 gripe_data_file_in_path (fcn, tmp);
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
484
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
485 fname = tmp;
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
486 }
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
487 }
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
488 }
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
489
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
490 return fname;
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
491 }
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
492
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
493 // See if there is an function file in the path. If so, return the
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
494 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
495
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
496 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
497 fcn_file_in_path (const std::string& name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
498 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
499 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
500
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
501 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
502
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
503 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
504 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
505 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
506 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
507 file_stat fs (name);
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
508
17955
9fc0836cb69b Fix "get_help_text('\')" in Windows.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17818
diff changeset
509 if (fs.exists () && ! fs.is_dir ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
510 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
511 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
512 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
513 retval = load_path::find_fcn_file (name.substr (0, len-2));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
514 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
515 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
516 std::string fname = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
517 size_t pos = name.find_first_of (Vfilemarker);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
518 if (pos != std::string::npos)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
519 fname = name.substr (0, pos);
7818
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
520
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
521 retval = load_path::find_fcn_file (fname);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
522 }
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
523 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
524
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
525 return retval;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
526 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
527
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
528 // See if there is a directory called "name" in the path and if it
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
529 // contains a Contents.m file return the full path to this file.
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
530
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
531 std::string
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
532 contents_file_in_path (const std::string& dir)
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
533 {
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
534 std::string retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
535
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
536 if (dir.length () > 0)
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
537 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
538 std::string tcontents = file_ops::concat (load_path::find_dir (dir),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
539 std::string ("Contents.m"));
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
540
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
541 file_stat fs (tcontents);
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
542
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
543 if (fs.exists ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
544 retval = octave_env::make_absolute (tcontents);
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
545 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
546
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
547 return retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
548 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
549
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
550 // See if there is a .oct file in the path. If so, return the
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
551 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
552
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
553 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
554 oct_file_in_path (const std::string& name)
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
555 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
556 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
557
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
558 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
559
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
560 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
561 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
562 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
563 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
564 file_stat fs (name);
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
565
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
566 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
567 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
568 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
569 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'o'
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
570 && name[len - 2] == 'c' && name[len - 1] == 't')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
571 retval = load_path::find_oct_file (name.substr (0, len-4));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
572 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
573 retval = load_path::find_oct_file (name);
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
574 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
575
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
576 return retval;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
577 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
578
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
579 // See if there is a .mex file in the path. If so, return the
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
580 // full path to the file.
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
581
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
582 std::string
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
583 mex_file_in_path (const std::string& name)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
584 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
585 std::string retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
586
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
587 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
588
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
589 if (len > 0)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
590 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
591 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
592 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
593 file_stat fs (name);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
594
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
595 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
596 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
597 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
598 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'm'
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
599 && name[len - 2] == 'e' && name[len - 1] == 'x')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
600 retval = load_path::find_mex_file (name.substr (0, len-4));
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
601 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
602 retval = load_path::find_mex_file (name);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
603 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
604
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
605 return retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
606 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
607
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
608 // Replace backslash escapes in a string with the real values.
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
609
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
610 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
611 do_string_escapes (const std::string& s)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
612 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
613 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
614
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
615 size_t i = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
616 size_t j = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
617 size_t len = s.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
618
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
619 retval.resize (len);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
620
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
621 while (j < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
622 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
623 if (s[j] == '\\' && j+1 < len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
624 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
625 switch (s[++j])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
626 {
20210
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
627 case 'a': // alarm
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
628 retval[i] = '\a';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
629 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
630
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
631 case 'b': // backspace
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
632 retval[i] = '\b';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
633 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
634
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
635 case 'f': // formfeed
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
636 retval[i] = '\f';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
637 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
638
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
639 case 'n': // newline
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
640 retval[i] = '\n';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
641 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
642
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
643 case 'r': // carriage return
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
644 retval[i] = '\r';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
645 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
646
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
647 case 't': // horizontal tab
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
648 retval[i] = '\t';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
649 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
650
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
651 case 'v': // vertical tab
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
652 retval[i] = '\v';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
653 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
654
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
655 case '\\': // backslash
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
656 retval[i] = '\\';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
657 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
658
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
659 case '\'': // quote
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
660 retval[i] = '\'';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
661 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
662
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
663 case '"': // double quote
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
664 retval[i] = '"';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
665 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
666
20210
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
667 case '0':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
668 case '1':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
669 case '2':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
670 case '3':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
671 case '4':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
672 case '5':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
673 case '6':
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
674 case '7': // octal input
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
675 {
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
676 size_t k;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
677 int tmpi = s[j] - '0';
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
678 for (k = j+1; k < std::min (j+3, len); k++)
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
679 {
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
680 int digit = s[k] - '0';
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
681 if (digit < 0 || digit > 7)
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
682 break;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
683 tmpi <<= 3;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
684 tmpi += digit;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
685 }
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
686 retval[i] = tmpi;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
687 j = k - 1;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
688 break;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
689 }
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
690
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
691 case 'x': // hex input
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
692 {
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
693 size_t k;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
694 int tmpi = 0;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
695 for (k = j+1; k < std::min (j+3, len); k++)
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
696 {
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
697 if (! isxdigit (s[k]))
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
698 break;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
699
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
700 tmpi <<= 4;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
701 int digit = s[k];
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
702 if (digit >= 'a')
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
703 tmpi += digit - 'a' + 10;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
704 else if (digit >= 'A')
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
705 tmpi += digit - 'A' + 10;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
706 else
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
707 tmpi += digit - '0';
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
708 }
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
709
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
710 if (k == j+1)
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
711 warning ("malformed hex escape sequence '\\x' --\
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
712 converting to '\\0'");
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
713
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
714 retval[i] = tmpi;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
715 j = k - 1;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
716 break;
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
717 }
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
718
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
719 default:
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
720 warning ("unrecognized escape sequence '\\%c' --\
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
721 converting to '%c'", s[j], s[j]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
722 retval[i] = s[j];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
723 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
724 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
725 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
726 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
727 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
728 retval[i] = s[j];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
729 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
730
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
731 i++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
732 j++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
733 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
734
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3103
diff changeset
735 retval.resize (i);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
736
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
737 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
738 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
739
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
740 DEFUN (do_string_escapes, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
741 "-*- texinfo -*-\n\
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
742 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
743 Convert escape sequences in @var{string} to the characters they represent.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
744 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
745 Escape sequences begin with a leading backslash\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
746 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
747 (.e.g., @qcode{\"@xbackslashchar{}n\"} => newline).\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
748 @seealso{undo_string_escapes}\n\
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
749 @end deftypefn")
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
750 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
751 int nargin = args.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
752
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
753 if (nargin != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
754 print_usage ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
755
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
756 std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
757
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
758 return octave_value (do_string_escapes (str));
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
759 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
760
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
761 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
762 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
763 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
764 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
765 %!assert ("foo\nbar", ["foo", char(10), "bar"])
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
766
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
767 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
768 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
769 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"),
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
770 %! char ([0, 7, 8, 12, 10, 13, 9, 11]))
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
771 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11]))
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
772
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
773 %!assert (do_string_escapes ('\\'), "\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
774 %!assert (do_string_escapes ("\\\\"), "\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
775 %!assert (do_string_escapes ("\\\\"), char (92))
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
776
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
777 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
778 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
779 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
780 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
781
20210
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
782 %!assert (do_string_escapes ('A\4B'), ["A" char(4) "B"])
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
783 %!assert (do_string_escapes ('A\45B'), ["A" char(37) "B"])
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
784 %!assert (do_string_escapes ('A\123B'), ["A" char(83) "B"])
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
785 %!assert (sprintf ('\117\143\164\141\166\145'), "Octave")
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
786
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
787 %!assert (do_string_escapes ('A\x4G'), ["A" char(4) "G"])
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
788 %!assert (do_string_escapes ('A\x4AG'), ["A" char(74) "G"])
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
789 %!assert (sprintf ('\x4f\x63\x74\x61\x76\x65'), "Octave")
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
790
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
791 %!error do_string_escapes ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
792 %!error do_string_escapes ("foo", "bar")
20210
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
793 %!error <STRING argument> do_string_escapes (3)
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
794 %!warning <malformed hex escape sequence> do_string_escapes ('\xG');
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
795 %!warning <unrecognized escape sequence> do_string_escapes ('\G');
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
796 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
797
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
798 const char *
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
799 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
800 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
801 if (! c)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
802 return "";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
803
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
804 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
805 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
806 case '\0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
807 return "\\0";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
808
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
809 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
810 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
811
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
812 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
813 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
814
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
815 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
816 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
817
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
818 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
819 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
820
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
821 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
822 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
823
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
824 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
825 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
826
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
827 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
828 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
829
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
830 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
831 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
832
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
833 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
834 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
835
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
836 default:
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
837 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
838 static char retval[2];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
839 retval[0] = c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
840 retval[1] = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
841 return retval;
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
842 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
843 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
844 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
845
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
846 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
847 undo_string_escapes (const std::string& s)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
848 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
849 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
850
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
851 for (size_t i = 0; i < s.length (); i++)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
852 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
853
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
854 return retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
855 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
856
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
857 DEFUN (undo_string_escapes, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
858 "-*- texinfo -*-\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
859 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
860 Convert special characters in strings back to their escaped forms.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
861 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
862 For example, the expression\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
863 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
864 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
865 bell = \"\\a\";\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
866 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
867 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
868 @noindent\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
869 assigns the value of the alert character (control-g, ASCII code 7) to the\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
870 string variable @code{bell}. If this string is printed, the system will\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
871 ring the terminal bell (if it is possible). This is normally the desired\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
872 outcome. However, sometimes it is useful to be able to print the original\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
873 representation of the string, with the special characters replaced by their\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
874 escape sequences. For example,\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
875 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
876 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
877 @group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
878 octave:13> undo_string_escapes (bell)\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
879 ans = \\a\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
880 @end group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
881 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
882 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
883 @noindent\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
884 replaces the unprintable alert character with its printable representation.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
885 @seealso{do_string_escapes}\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
886 @end deftypefn")
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
887 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
888 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
889
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
890 if (nargin != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
891 print_usage ();
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
892
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
893 std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
894
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
895 return octave_value (undo_string_escapes (str));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
896 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
897
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
898 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
899 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar')
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
900 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
901 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
902
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
903 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v')
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
904 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
905 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])),
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
906 %! "\\a\\b\\f\\n\\r\\t\\v")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
907
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
908 %!assert (undo_string_escapes ("\\"), '\\')
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
909 %!assert (undo_string_escapes ("\\"), "\\\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
910 %!assert (undo_string_escapes (char (92)), "\\\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
911
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
912 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"')
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
913 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
914
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
915 %!error undo_string_escapes ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
916 %!error undo_string_escapes ("foo", "bar")
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
917 %!error undo_string_escapes (3)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
918 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
919
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
920 DEFUN (is_absolute_filename, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
921 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
922 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
923 Return true if @var{file} is an absolute filename.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
924 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
925 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
926 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
927 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
928
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
929 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
930 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
931
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
932 retval = (args(0).is_string ()
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
933 && octave_env::absolute_pathname (args(0).string_value ()));
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
934
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
935 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
936 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
937
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
938 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
939 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
940
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
941 %!error is_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
942 %!error is_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
943 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
944
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
945 DEFUN (is_rooted_relative_filename, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
946 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
947 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
948 Return true if @var{file} is a rooted-relative filename.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
949 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
950 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
951 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
952 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
953
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
954 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
955 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
956
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
957 retval = (args(0).is_string ()
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
958 && octave_env::rooted_relative_pathname (args(0).string_value ()));
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
959
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
960 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
961 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
962
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
963 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
964 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
965
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
966 %!error is_rooted_relative_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
967 %!error is_rooted_relative_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
968 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
969
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
970 DEFUN (make_absolute_filename, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
971 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
972 @deftypefn {Built-in Function} {} make_absolute_filename (@var{file})\n\
14819
67b6b47a22f6 doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
973 Return the full name of @var{file} beginning from the root of the file\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
974 system.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
975 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
976 No check is done for the existence of @var{file}.\n\
14819
67b6b47a22f6 doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
977 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
978 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
979 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
980 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
981 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
982
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
983 std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a filename");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
984
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
985 return octave_value (octave_env::make_absolute (nm));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
986 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
987
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
988 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
989 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
990
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
991 %!error make_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
992 %!error make_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
993 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
994
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
995 DEFUN (dir_in_loadpath, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
996 "-*- texinfo -*-\n\
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
997 @deftypefn {Built-in Function} {} dir_in_loadpath (@var{dir})\n\
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
998 @deftypefnx {Built-in Function} {} dir_in_loadpath (@var{dir}, \"all\")\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
999 Return the full name of the path element matching @var{dir}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1000 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1001 The match is performed at the end of each path element. For example, if\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16892
diff changeset
1002 @var{dir} is @qcode{\"foo/bar\"}, it matches the path element\n\
17290
17be601bc783 doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents: 17281
diff changeset
1003 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\
17be601bc783 doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents: 17281
diff changeset
1004 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\
17be601bc783 doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents: 17281
diff changeset
1005 @nospell{@qcode{\"/some/dir/allfoo/bar\"}}.\n\
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1006 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1007 If the optional second argument is supplied, return a cell array containing\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1008 all name matches rather than just the first.\n\
18062
aca545afdf25 doc: Add seealso links to find_dir_in_path function.
Rik <rik@octave.org>
parents: 17955
diff changeset
1009 @seealso{file_in_path, file_in_loadpath, path}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1010 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1011 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1012 octave_value retval = std::string ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1013
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1014 int nargin = args.length ();
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1015
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1016 std::string dir;
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1017
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1018 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1019 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1020
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1021 dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name");
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1022
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1023 if (nargin == 1)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1024 retval = load_path::find_dir (dir);
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1025 else if (nargin == 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1026 retval = Cell (load_path::find_matching_dirs (dir));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1027
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1028 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1029 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1030
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1031 /*
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1032 %!test
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1033 %! f = dir_in_loadpath ("plot");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1034 %! assert (ischar (f));
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1035 %! assert (! isempty (f));
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1036
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1037 %!test
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1038 %! f = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1039 %! assert (f, "");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1040
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1041 %!test
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1042 %! lst = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$", "all");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1043 %! assert (lst, {});
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1044
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
1045 %!error dir_in_loadpath ()
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
1046 %!error dir_in_loadpath ("foo", "bar", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1047 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1048
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1049 DEFUNX ("errno", Ferrno, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1050 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
1051 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1052 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1053 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1054 Return the current value of the system-dependent variable errno,\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1055 set its value to @var{val} and return the previous value, or return\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1056 the named error code given @var{name} as a character string, or -1\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1057 if @var{name} is not found.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1058 @seealso{errno_list}\n\
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1059 @end deftypefn")
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1060 {
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1061 octave_value retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1062
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1063 int nargin = args.length ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1064
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1065 if (nargin > 1)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1066 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1067
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1068 if (nargin == 1)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1069 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1070 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1071 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1072 std::string nm = args(0).string_value ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1073
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19697
diff changeset
1074 retval = octave_errno::lookup (nm);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1075 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1076 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1077 {
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1078 int val = args(0).xint_value ("errno: argument must be string or integer");
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1079
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1080 retval = octave_errno::set (val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1081 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1082 }
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1083 else
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1084 retval = octave_errno::get ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1085
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1086 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1087 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1088
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1089 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1090 %!assert (isnumeric (errno ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1091
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1092 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1093 %! lst = errno_list ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1094 %! fns = fieldnames (lst);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1095 %! oldval = errno (fns{1});
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1096 %! assert (isnumeric (oldval));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1097 %! errno (oldval);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1098 %! newval = errno ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1099 %! assert (oldval, newval);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1100
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1101 %!error errno ("foo", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1102 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1103
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1104 DEFUN (errno_list, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1105 "-*- texinfo -*-\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1106 @deftypefn {Built-in Function} {} errno_list ()\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1107 Return a structure containing the system-dependent errno values.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1108 @seealso{errno}\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1109 @end deftypefn")
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1110 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1111 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1112 print_usage ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1113
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1114 return octave_value (octave_errno::list ());
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1115 }
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1116
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1117 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1118 %!assert (isstruct (errno_list ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1119
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1120 %!error errno_list ("foo")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1121 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1122
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
1123 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1124 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1125 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1126 if (nr < 0 || nc < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1127 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1128 warning_with_id ("Octave:neg-dim-as-zero",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1129 "%s: converting negative dimension to zero", warnfor);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1130
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
1131 nr = (nr < 0) ? 0 : nr;
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
1132 nc = (nc < 0) ? 0 : nc;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1133 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1134 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1135
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1136 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
1137 check_dimensions (dim_vector& dim, const char *warnfor)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1138 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1139 bool neg = false;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1140
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1141 for (int i = 0; i < dim.length (); i++)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1142 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1143 if (dim(i) < 0)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1144 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1145 dim(i) = 0;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1146 neg = true;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1147 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1148 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1149
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1150 if (neg)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1151 warning_with_id ("Octave:neg-dim-as-zero",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1152 "%s: converting negative dimension to zero", warnfor);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1153 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1154
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1155
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1156 void
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1157 get_dimensions (const octave_value& a, const char *warn_for,
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
1158 dim_vector& dim)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1159 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1160 if (a.is_scalar_type ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1161 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1162 dim.resize (2);
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1163 dim(0) = a.int_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1164 dim(1) = dim(0);
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1165 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1166 else
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1167 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1168 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1169 octave_idx_type nc = a.columns ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1170
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1171 if (nr == 1 || nc == 1)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1172 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1173 Array<double> v = a.vector_value ();
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1174
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20210
diff changeset
1175 octave_idx_type n = v.numel ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1176 dim.resize (n);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1177 for (octave_idx_type i = 0; i < n; i++)
4783
55975a3073be [project @ 2004-02-17 17:16:37 by jwe]
jwe
parents: 4732
diff changeset
1178 dim(i) = static_cast<int> (fix (v(i)));
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1179 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1180 else
5257
d957f0ef5aa3 [project @ 2005-03-29 19:08:34 by jwe]
jwe
parents: 5040
diff changeset
1181 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1182 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1183
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1184 check_dimensions (dim, warn_for);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1185 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1186
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1187
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1188 void
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1189 get_dimensions (const octave_value& a, const char *warn_for,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1190 octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1191 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1192 if (a.is_scalar_type ())
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1193 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1194 nr = nc = a.int_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1195 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1196 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1197 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1198 nr = a.rows ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1199 nc = a.columns ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1200
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1201 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1202 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1203 Array<double> v = a.vector_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1204
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1205
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1206 nr = static_cast<octave_idx_type> (fix (v (0)));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1207 nc = static_cast<octave_idx_type> (fix (v (1)));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1208 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1209 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1210 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1211 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1212
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1213 check_dimensions (nr, nc, warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1214 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1215
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1216 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1217 get_dimensions (const octave_value& a, const octave_value& b,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1218 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1219 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20709
diff changeset
1220 nr = a.is_empty ()
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20709
diff changeset
1221 ? 0 : a.int_value ("%s: row dimension must be a scalar", warn_for);
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20709
diff changeset
1222 nc = b.is_empty ()
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20709
diff changeset
1223 ? 0 : b.int_value ("%s: column dimension must be a scalar", warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1224
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1225 check_dimensions (nr, nc, warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1226 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1227
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1228 octave_idx_type
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1229 dims_to_numel (const dim_vector& dims, const octave_value_list& idx_arg)
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1230 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1231 octave_idx_type retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1232
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1233 octave_idx_type len = idx_arg.length ();
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1234
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1235 if (len == 0)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1236 retval = dims.numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1237 else
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1238 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1239 const dim_vector dv = dims.redim (len);
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1240 retval = 1;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1241 for (octave_idx_type i = 0; i < len; i++)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1242 {
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1243 octave_value idxi = idx_arg(i);
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1244 if (idxi.is_magic_colon ())
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1245 retval *= dv(i);
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1246 else if (idxi.is_numeric_type ())
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1247 retval *= idxi.numel ();
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1248 else
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1249 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1250 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1251 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1252 idx_vector jdx = idxi.index_vector ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1253
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1254 retval *= jdx.length (dv(i));
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1255 }
20651
c1d94e5cd5ea catch index_exception by const reference where possible
John W. Eaton <jwe@octave.org>
parents: 20582
diff changeset
1256 catch (const index_exception& e)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1257 {
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1258 std::string idx = e.idx ();
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1259 std::string msg = e.details ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1260
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1261 error ("dims_to_numel: Invalid IDX %s. %s",
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
1262 idx.c_str (), msg.c_str ());
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20535
diff changeset
1263 }
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1264 }
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1265 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1266 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1267
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1268 return retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1269 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1270
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1271 Matrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1272 identity_matrix (octave_idx_type nr, octave_idx_type nc)
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1273 {
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1274 Matrix m (nr, nc, 0.0);
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1275
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1276 if (nr > 0 && nc > 0)
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1277 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1278 octave_idx_type n = std::min (nr, nc);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1279
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1280 for (octave_idx_type i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1281 m (i, i) = 1.0;
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1282 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1283
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1284 return m;
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1285 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1286
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1287 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1288 float_identity_matrix (octave_idx_type nr, octave_idx_type nc)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1289 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1290 FloatMatrix m (nr, nc, 0.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1291
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1292 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1293 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1294 octave_idx_type n = std::min (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1295
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1296 for (octave_idx_type i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1297 m (i, i) = 1.0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1298 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1299
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1300 return m;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1301 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1302
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1303 size_t
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1304 octave_format (std::ostream& os, const char *fmt, ...)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1305 {
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1306 size_t retval;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1307
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1308 va_list args;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1309 va_start (args, fmt);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1310
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1311 retval = octave_vformat (os, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1312
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1313 va_end (args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1314
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1315 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1316 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1317
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1318 size_t
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1319 octave_vformat (std::ostream& os, const char *fmt, va_list args)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1320 {
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1321 std::string s = octave_vasprintf (fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1322
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1323 os << s;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1324
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1325 return s.length ();
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1326 }
4135
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
1327
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1328 std::string
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1329 octave_vasprintf (const char *fmt, va_list args)
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1330 {
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1331 std::string retval;
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1332
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1333 char *result;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1334
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1335 int status = gnulib::vasprintf (&result, fmt, args);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1336
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1337 if (status >= 0)
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1338 {
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1339 retval = result;
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1340 ::free (result);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1341 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1342
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1343 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1344 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1345
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1346 std::string
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1347 octave_asprintf (const char *fmt, ...)
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1348 {
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1349 std::string retval;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1350
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1351 va_list args;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1352 va_start (args, fmt);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1353
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1354 retval = octave_vasprintf (fmt, args);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1355
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1356 va_end (args);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1357
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1358 return retval;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1359 }
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1360
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1361 void
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1362 octave_sleep (double seconds)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1363 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1364 if (seconds > 0)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1365 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1366 double t;
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1367
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1368 unsigned int usec
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1369 = static_cast<unsigned int> (modf (seconds, &t) * 1000000);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1370
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1371 unsigned int sec
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1372 = ((t > std::numeric_limits<unsigned int>::max ())
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1373 ? std::numeric_limits<unsigned int>::max ()
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1374 : static_cast<unsigned int> (t));
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1375
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1376 // Versions of these functions that accept unsigned int args are
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1377 // defined in cutils.c.
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1378 octave_sleep (sec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1379 octave_usleep (usec);
10070
897e62651c0a correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1380
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10086
diff changeset
1381 octave_quit ();
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1382 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1383 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1384
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1385 DEFUN (isindex, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1386 "-*- texinfo -*-\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1387 @deftypefn {Built-in Function} {} isindex (@var{ind})\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1388 @deftypefnx {Built-in Function} {} isindex (@var{ind}, @var{n})\n\
20084
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1389 Return true if @var{ind} is a valid index.\n\
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1390 \n\
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1391 Valid indices are either positive integers (although possibly of real data\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1392 type), or logical arrays.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1393 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1394 If present, @var{n} specifies the maximum extent of the dimension to be\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1395 indexed. When possible the internal result is cached so that subsequent\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1396 indexing using @var{ind} will not perform the check again.\n\
20084
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1397 \n\
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1398 Implementation Note: Strings are first converted to double values before the\n\
4d0c7fec0a31 doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents: 19743
diff changeset
1399 checks for valid indices are made. Unless a string contains the NULL\n\
20317
2ec049e50ed8 doc: Fix backslash characters in docstrings
Mike Miller <mtmiller@octave.org>
parents: 20194
diff changeset
1400 character @nospell{\"@xbackslashchar{}0\"}, it will always be a valid index.\n\
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1401 @end deftypefn")
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1402 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1403 octave_value retval;
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1404
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1405 octave_idx_type n = 0;
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1406
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1407 int nargin = args.length ();
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1408
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1409 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1410 print_usage ();
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1411
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1412 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1413 n = args(1).idx_type_value ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1414
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1415 unwind_protect frame;
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
1416
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1417 frame.protect_var (discard_error_messages);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1418 discard_error_messages = true;
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1419
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1420 try
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1421 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1422 idx_vector idx = args(0).index_vector (true);
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 18105
diff changeset
1423
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1424 if (nargin == 2)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1425 retval = idx.extent (n) <= n;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1426 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1427 retval = true;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1428 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1429 catch (const octave_execution_exception&)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1430 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1431 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1432
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1433 retval = false;
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1434 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1435
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1436 return retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1437 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1438
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1439 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1440 %!assert (isindex ([1, 2, 3]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1441 %!assert (isindex (1:3))
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1442 %!assert (isindex (1:3, 2), false)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1443 %!assert (isindex ([1, 2, -3]), false)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1444
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1445 %!error isindex ()
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1446 %!error isindex (1:3, 2, 3)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1447 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1448
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1449 octave_value_list
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1450 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1451 const char *fun_name, const octave_value_list& args,
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1452 int nargout)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1453 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1454 octave_value_list new_args = args, retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1455 int nargin = args.length ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1456 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1457 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1458 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1459
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1460 const Cell *ccells = cells;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1461
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1462 octave_idx_type numel = 1;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1463 dim_vector dims (1, 1);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1464
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1465 for (int i = 0; i < nargin; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1466 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1467 octave_value arg = new_args(i);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1468 iscell[i] = arg.is_cell ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1469 if (iscell[i])
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1470 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1471 cells[i] = arg.cell_value ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1472 octave_idx_type n = ccells[i].numel ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1473 if (n == 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1474 {
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1475 iscell[i] = false;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1476 new_args(i) = ccells[i](0);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1477 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1478 else if (numel == 1)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1479 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1480 numel = n;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1481 dims = ccells[i].dims ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1482 }
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1483 else if (dims != ccells[i].dims ())
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1484 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1485 error ("%s: cell arguments must have matching sizes", fun_name);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1486 break;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1487 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1488 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1489 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1490
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1491 for (int i = 0; i < nargout; i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1492 rcells[i].clear (dims);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1493
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1494 for (octave_idx_type j = 0; j < numel; j++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1495 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1496 for (int i = 0; i < nargin; i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1497 if (iscell[i])
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1498 new_args(i) = ccells[i](j);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1499
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1500 octave_quit ();
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1501
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1502 const octave_value_list tmp = fun (new_args, nargout);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1503
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1504 if (tmp.length () < nargout)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1505 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1506 error ("%s: do_simple_cellfun: internal error", fun_name);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1507 break;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1508 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1509 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1510 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1511 for (int i = 0; i < nargout; i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1512 rcells[i](j) = tmp(i);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1513 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1514 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1515
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1516 retval.resize (nargout);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1517
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1518 for (int i = 0; i < nargout; i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1519 retval(i) = rcells[i];
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1520
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1521 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1522 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1523
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1524 octave_value
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1525 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int),
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1526 const char *fun_name, const octave_value_list& args)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1527 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1528 octave_value retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1529 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1530 if (tmp.length () > 0)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1531 retval = tmp(0);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1532
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1533 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1534 }
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1535
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1536 octave_preserve_stream_state::~octave_preserve_stream_state (void)
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1537 {
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1538 stream.flags (oflags);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1539 stream.precision (oprecision);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1540 stream.width (owidth);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1541 stream.fill (ofill);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1542 }
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1543
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1544 DEFUN (isstudent, args, ,
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1545 "-*- texinfo -*-\n\
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1546 @deftypefn {Built-in Function} {} isstudent ()\n\
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1547 Return true if running in the student edition of @sc{matlab}.\n\
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1548 \n\
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1549 @code{isstudent} always returns false in Octave.\n\
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1550 @seealso{false}\n\
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1551 @end deftypefn")
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1552 {
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1553 if (args.length () != 0)
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1554 print_usage ();
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1555
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1556 return octave_value (false);
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1557 }
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1558
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1559 /*
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1560 %!assert (isstudent (), false)
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1561
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1562 %!error isstudent (1)
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1563 */