annotate libinterp/corefcn/utils.cc @ 32086:3c608abd55f5

Move "same_file" from liboctinterp to liboctave (bug #63803). * libinterp/corefcn/utils.cc, utils.h (same_file): Deprecate function. * libinterp/corefcn/sysdep.cc, sysdep.h (same_file_internal): Remove function. * liboctave/system/lo-sysdep.cc, lo-sysdep.h (same_file): Move function from liboctinterp to liboctave. * libgui/src/m-editor/file-editor.cc (file_editor::find_tab_widget), libinterp/corefcn/fcn-info.cc (file_editor::find_tab_widget), libinterp/corefcn/interpreter.cc (interpreter::execute_startup_files), libinterp/corefcn/load-path.cc (load_path::append): Use function in updated namespace.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 06 May 2023 17:48:27 +0200
parents e9fdfebc6db0
children 05b4479c29d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31607
diff changeset
3 // Copyright (C) 1993-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
30 #include <cerrno>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
31 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
32
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
33 #include <fstream>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
34 #include <limits>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25173
diff changeset
35 #include <ostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
36 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
37
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
38 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
39 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
40 #include "file-stat.h"
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
41 #include "lo-mappers.h"
32080
e9fdfebc6db0 Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32028
diff changeset
42 #include "lo-sysdep.h"
11006
aca961a3f387 provide gethostname function
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
43 #include "lo-utils.h"
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
44 #include "nanosleep-wrapper.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
45 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
46 #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
47 #include "oct-locbuf.h"
27279
1c8b20731af4 Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27277
diff changeset
48 #include "oct-string.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"
30587
5d379d2ad903 strcase-wrappers: Add wrappers for strcasecmp and strncasecmp.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
52 #include "strcase-wrappers.h"
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
53 #include "vasprintf-wrapper.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
54
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
55 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
56 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
57 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21041
diff changeset
58 #include "errwarn.h"
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25928
diff changeset
59 #include "graphics.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
60 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
61 #include "interpreter.h"
10502
f13bf183a003 isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents: 10315
diff changeset
62 #include "lex.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
63 #include "load-path.h"
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
64 #include "oct-errno.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
65 #include "oct-hist.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
66 #include "ovl.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
67 #include "ov-range.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
68 #include "pager.h"
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
69 #include "parse.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
70 #include "sysdep.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
71 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
72 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
73 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
74
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31278
diff changeset
75 OCTAVE_BEGIN_NAMESPACE(octave)
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
76
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
77 // Return TRUE if S is a valid identifier.
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
78
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
79 bool valid_identifier (const char *s)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
80 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
81 if (! s || ! (isalpha (*s) || *s == '_'))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
82 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
83
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
84 while (*++s != '\0')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
85 if (! (isalnum (*s) || *s == '_'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
86 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
87
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
88 return true;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
89 }
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
90
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
91 bool valid_identifier (const std::string& s)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
92 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
93 return valid_identifier (s.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
94 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
95
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8715
diff changeset
96 DEFUN (isvarname, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
97 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
98 @deftypefn {} {@var{tf} =} isvarname (@var{name})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
99 Return true if @var{name} is a valid variable name.
26204
82b9b970ff19 doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents: 26203
diff changeset
100
82b9b970ff19 doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents: 26203
diff changeset
101 A valid variable name is composed of letters, digits, and underscores ("_"),
82b9b970ff19 doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents: 26203
diff changeset
102 and the first character must not be a digit.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
103 @seealso{iskeyword, exist, who}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
104 @end deftypefn */)
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
105 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20812
diff changeset
106 if (args.length () != 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
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
109 octave_value retval = false;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
110
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
111 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
112 {
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
113 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
114
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
115 retval = (valid_identifier (varname)
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
116 && ! iskeyword (varname));
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
117 }
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
118
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
119 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
120 }
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
121
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
122 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
123 %!assert (isvarname ("foo"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
124 %!assert (isvarname ("_foo"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
125 %!assert (isvarname ("_1"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
126 %!assert (isvarname ("1foo"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
127 %!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
128 %!assert (isvarname (12), false)
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
129 %!assert (isvarname ("foo+bar"), false)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
130
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
131 %!error isvarname ()
21581
6fab85c1538f maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents: 21526
diff changeset
132 %!error isvarname ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
133 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
134
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
135 bool
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
136 make_valid_name (std::string& str, const make_valid_name_options& options)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
137 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
138 // If `isvarname (str)`, no modifications necessary.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
139 if (valid_identifier (str) && ! iskeyword (str))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
140 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
141
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
142 // Change whitespace followed by lowercase letter to uppercase, except
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
143 // for the first
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
144 bool previous = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
145 bool any_non_space = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
146 for (char& c : str)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
147 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
148 c = ((any_non_space && previous && std::isalpha (c)) ? std::toupper (c)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
149 : c);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
150 previous = std::isspace (c);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
151 any_non_space |= (! previous); // once true, always true
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
152 }
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
153
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
154 // Remove any whitespace.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
155 str.erase (std::remove_if (str.begin(), str.end(),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
156 [] (unsigned char x)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
157 { return std::isspace(x); }),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
158 str.end());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
159 if (str.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
160 str = options.get_prefix ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
161
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
162 // Add prefix and capitalize first character, if `str` is a reserved
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
163 // keyword.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
164 if (iskeyword (str))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
165 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
166 str[0] = std::toupper (str[0]);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
167 str = options.get_prefix () + str;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
168 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
169
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
170 // Add prefix if first character is not a letter or underscore.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
171 if (! std::isalpha (str[0]) && str[0] != '_')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
172 str = options.get_prefix () + str;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
173
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
174 // Replace non alphanumerics or underscores
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
175 if (options.get_replacement_style () == "underscore")
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
176 for (char& c : str)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
177 c = (std::isalnum (c) ? c : '_');
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
178 else if (options.get_replacement_style () == "delete")
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
179 str.erase (std::remove_if (str.begin(), str.end(),
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
180 [] (unsigned char x)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
181 { return ! std::isalnum (x) && x != '_'; }),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
182 str.end());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
183 else if (options.get_replacement_style () == "hex")
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
184 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
185 const std::string permitted_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
186 "abcdefghijklmnopqrstuvwxyz"
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
187 "_0123456789";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
188 // Get the first non-permitted char.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
189 std::size_t pos = str.find_first_not_of (permitted_chars);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
190 // Buffer for hex string "0xFF" (+1 for null terminator).
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
191 char hex_str[5];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
192 // Repeat until end of string.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
193 while (pos != std::string::npos)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
194 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
195 // Replace non-permitted char by it's hex value.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
196 std::snprintf (hex_str, sizeof (hex_str), "0x%02X", str[pos]);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
197 str.replace (pos, 1, hex_str);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
198 // Get the next occurrence from the last position.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
199 // (-1 for null terminator)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
200 pos = str.find_first_not_of (permitted_chars,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
201 pos + sizeof (hex_str) - 1);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
202 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
203 }
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
204
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
205 return true;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
206 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
207
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
208 make_valid_name_options::make_valid_name_options
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
209 (const octave_value_list& args)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
210 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
211 auto nargs = args.length ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
212 if (nargs == 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
213 return;
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
214
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
215 // nargs = 2, 4, 6, ... permitted
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
216 if (nargs % 2)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
217 error ("makeValidName: property/value options must occur in pairs");
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
218
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
219 auto str_to_lower = [] (std::string& s)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
220 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
221 std::transform (s.begin(), s.end(), s.begin(),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
222 [] (unsigned char c)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
223 { return std::tolower(c); });
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
224 };
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
225
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
226 for (auto i = 0; i < nargs; i = i + 2)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
227 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
228 std::string parameter = args(i).xstring_value ("makeValidName: "
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
229 "option argument must be a string");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
230 str_to_lower (parameter);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
231 if (parameter == "replacementstyle")
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
232 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
233 m_replacement_style = args(i + 1).xstring_value ("makeValidName: "
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
234 "'ReplacementStyle' value must be a string");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
235 str_to_lower (m_replacement_style);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
236 if ((m_replacement_style != "underscore")
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
237 && (m_replacement_style != "delete")
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
238 && (m_replacement_style != "hex"))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
239 error ("makeValidName: invalid 'ReplacementStyle' value '%s'",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
240 m_replacement_style.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
241 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
242 else if (parameter == "prefix")
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
243 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
244 m_prefix = args(i + 1).xstring_value ("makeValidName: "
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
245 "'Prefix' value must be a string");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
246 if (! valid_identifier (m_prefix)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
247 || iskeyword (m_prefix))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
248 error ("makeValidName: invalid 'Prefix' value '%s'",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
249 m_prefix.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
250 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
251 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
252 error ("makeValidName: unknown property '%s'", parameter.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
253 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
254 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
255
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
256 DEFUN (__make_valid_name__, args, ,
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
257 doc: /* -*- texinfo -*-
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
258 @deftypefn {} {@var{varname} =} __make_valid_name__ (@var{str})
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
259 @deftypefnx {} {@var{varname} =} __make_valid_name__ (@var{str}, @qcode{"ReplacementStyle"})
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
260 @deftypefnx {} {@var{varname} =} __make_valid_name__ (@var{str}, @qcode{"ReplacementStyle"}, @qcode{"Prefix"})
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
261 @deftypefnx {} {[@var{varname}, @var{ismodified}] =} __make_valid_name__ (@dots{})
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
262 Return a valid variable name @var{varname} from input @var{str}.
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
263
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
264 For more documentation, see @code{matlab.lang.makeValidName}.
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
265
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
266 @seealso{isvarname, matlab.lang.makeValidName}
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
267 @end deftypefn */)
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
268 {
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
269 auto nargin = args.length ();
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
270 if (nargin < 1)
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
271 print_usage ();
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
272
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
273 make_valid_name_options options (args.slice (1, nargin - 1));
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
274
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
275 if (args(0).is_string ())
29094
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
276 {
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
277 std::string varname = args(0).string_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
278 bool is_modified = make_valid_name (varname, options);
29094
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
279 return ovl (varname, is_modified);
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
280 }
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
281 else if (args(0).iscellstr ())
29094
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
282 {
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
283 Array<std::string> varnames = args(0).cellstr_value ();
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
284 Array<bool> is_modified (varnames.dims ());
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
285 for (auto i = 0; i < varnames.numel (); i++)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
286 is_modified(i) = make_valid_name (varnames(i), options);
29094
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
287 return ovl (varnames, is_modified);
d09dde091073 utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29091
diff changeset
288 }
29091
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
289 else
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
290 error ("makeValidName: STR must be a string or cellstr");
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
291 }
b924b916dc91 matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 28888
diff changeset
292
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
293 // Return TRUE if F and G are both names for the same file.
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
294
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
295 bool same_file (const std::string& f, const std::string& g)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
296 {
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32080
diff changeset
297 return sys::same_file (f, g);
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
298 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
299
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
300 DEFUN (is_same_file, args, ,
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
301 doc: /* -*- texinfo -*-
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
302 @deftypefn {} {@var{same} =} is_same_file (@var{filepath1}, @var{filepath2})
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
303 Return true if @var{filepath1} and @var{filepath2} refer to the same file.
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
304
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
305 If either @var{filepath1} or @var{filepath2} is a cell array of strings, then
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
306 an array of the same size is returned, containing the values described above
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
307 for every member of the cell array. The other argument may also be a cell
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
308 array of strings (of the same size) or a string.
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
309
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
310 Programming Notes: Depending on the operating system and file system, the same
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
311 file or folder can be referred to with different paths. In particular, paths
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
312 on the Windows platform may differ in case (@file{file1} vs.@: @file {FILE1}),
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
313 file separator (@samp{\} vs.@: @samp{/}), and format (@file{A~spaces.txt} (8.3
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
314 convention) vs.@: @file{A filename with spaces.txt}). This function returns
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
315 true if the paths in @var{filepath1} and @var{filepath2} actually refer to the
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
316 same file or folder, and false otherwise.
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
317
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
318 Note that unlike @code{strcmp}, this function requires that @var{filepath1}
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
319 and @var{filepath2} exist, as well as point to the same location, in order to
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
320 return true.
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
321
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
322 @seealso{canonicalize_file_name, strcmp}
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
323 @end deftypefn */)
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
324 {
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
325 if (args.length () != 2)
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
326 print_usage ();
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
327
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
328 octave_value retval;
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
329
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
330 bool s1_string = args(0).is_string ();
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
331 bool s1_cellstr = args(0).iscellstr ();
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
332 bool s2_string = args(1).is_string ();
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
333 bool s2_cellstr = args(1).iscellstr ();
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
334
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
335 if (s1_string && s2_string)
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
336 {
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
337 std::string file1 = args(0).string_value ();
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
338 std::string file2 = args(1).string_value ();
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
339
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32080
diff changeset
340 retval = sys::same_file (file1, file2);
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
341 }
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
342 else if ((s1_string && s2_cellstr) || (s1_cellstr && s2_string))
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
343 {
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
344 octave_value str_arg, cellstr_arg;
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
345
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
346 if (s1_string)
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
347 {
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
348 str_arg = args(0);
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
349 cellstr_arg = args(1);
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
350 }
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
351 else
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
352 {
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
353 str_arg = args(1);
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
354 cellstr_arg = args(0);
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
355 }
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
356
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
357 const Array<std::string> cellstr = cellstr_arg.cellstr_value ();
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
358 const std::string str = str_arg.string_value ();
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
359
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
360 boolNDArray output (cellstr.dims (), false);
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
361
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
362 for (octave_idx_type idx = 0; idx < cellstr.numel (); idx++)
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32080
diff changeset
363 output(idx) = sys::same_file (str, cellstr(idx));
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
364
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
365 retval = output;
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
366 }
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
367 else if (s1_cellstr && s2_cellstr)
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
368 {
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
369 const Array<std::string> cellstr1 = args(0).cellstr_value ();
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
370 const Array<std::string> cellstr2 = args(1).cellstr_value ();
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
371
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
372 const dim_vector size1 = cellstr1.dims ();
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
373 const dim_vector size2 = cellstr2.dims ();
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
374
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
375 if (size1 != size2)
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
376 error ("is_same_file: cellstr arrays FILEPATH1 and FILEPATH2 must be the same size");
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
377
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
378 boolNDArray output (size1, false);
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
379
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
380 for (octave_idx_type idx = 0; idx < cellstr1.numel (); idx++)
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32080
diff changeset
381 output(idx) = sys::same_file (cellstr1(idx), cellstr2(idx));
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
382
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
383 retval = output;
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
384 }
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
385 else
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
386 error ("is_same_file: FILEPATH1 and FILEPATH2 must be strings or cell arrays of strings");
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
387
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
388 return retval;
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
389 }
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
390
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
391 /*
27580
e7df1df55f0e Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents: 27571
diff changeset
392 %!testif ; ! ispc ()
e7df1df55f0e Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents: 27571
diff changeset
393 %! assert (is_same_file ("~", tilde_expand ("~")));
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
394 %!testif ; ispc ()
32002
939e5d952675 Use upper/lower in preference to toupper/tolower to match Matlab.
Rik <rik@octave.org>
parents: 31718
diff changeset
395 %! assert (is_same_file (lower (tempdir ()), upper (tempdir ())), true);
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
396 %!assert (is_same_file ({pwd(), ".", tempdir()}, canonicalize_file_name (".")),
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
397 %! [true, true, false])
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
398
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
399 %!error is_same_file ()
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
400 %!error is_same_file ("foo")
27571
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
401 %!error is_same_file ("foo", "bar", "baz")
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
402 %!error <must be strings or cell arrays of strings> is_same_file ("foo", 1)
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
403 %!error <must be strings or cell arrays of strings> is_same_file (1, "foo")
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
404 %!error <must be strings or cell arrays of strings> is_same_file ("foo", {1})
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
405 %!error <must be strings or cell arrays of strings> is_same_file ({1}, "foo")
24618a510749 Polish implementation of is_same_file().
Rik <rik@octave.org>
parents: 27569
diff changeset
406 %!error <arrays .* must be the same size> is_same_file ({"1", "2"}, {"1"; "2"})
27569
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
407 */
29ccef7e5295 New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27474
diff changeset
408
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
409 int almost_match (const std::string& std, const std::string& s,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
410 int min_match_len, int case_sens)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
411 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
412 int stdlen = std.length ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
413 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
414
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
415 return (slen <= stdlen
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
416 && slen >= min_match_len
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
417 && (case_sens
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
418 ? (strncmp (std.c_str (), s.c_str (), slen) == 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
419 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
420 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
421
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
422 // Ugh.
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
423
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
424 int keyword_almost_match (const char *const *std, int *min_len,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
425 const std::string& s,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
426 int min_toks_to_match, int max_toks)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
427 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
428 int status = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
429 int tok_count = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
430 int toks_matched = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
431
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
432 if (s.empty () || max_toks < 1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
433 return status;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
434
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
435 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
436
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
437 char *t = kw;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
438 while (*t != '\0')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
439 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
440 if (*t == '\t')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
441 *t = ' ';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
442 t++;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
443 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
444
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
445 char *beg = kw;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
446 while (*beg == ' ')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
447 beg++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
448
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
449 if (*beg == '\0')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
450 return status;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
451
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
452 const char **to_match = new const char *[max_toks + 1];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
453 const char *const *s1 = std;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
454 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
455
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
456 if (! s1 || ! s2)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
457 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
458
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
459 s2[tok_count] = beg;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
460 char *end;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
461 while ((end = strchr (beg, ' ')) != nullptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
462 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
463 *end = '\0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
464 beg = end + 1;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
465
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
466 while (*beg == ' ')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
467 beg++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
468
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
469 if (*beg == '\0')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
470 break;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
471
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
472 tok_count++;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
473 if (tok_count >= max_toks)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
474 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
475
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
476 s2[tok_count] = beg;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
477 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
478 s2[tok_count+1] = nullptr;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
479
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
480 s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
481
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
482 for (;;)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
483 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
484 if (! almost_match (*s1, *s2, min_len[toks_matched], 0))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
485 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
486
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
487 toks_matched++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
488
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
489 s1++;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
490 s2++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
491
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
492 if (! *s2)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
493 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
494 status = (toks_matched >= min_toks_to_match);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
495 goto done;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
496 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
497
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
498 if (! *s1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
499 goto done;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
500 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
501
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
502 done:
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
503
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
504 delete [] kw;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
505 delete [] to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
506
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
507 return status;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
508 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
509
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
510 // See if the given file is in the path.
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
511
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
512 std::string search_path_for_file (const std::string& path,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
513 const string_vector& names)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
514 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
515 directory_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
516
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
517 return sys::env::make_absolute (p.find_first_of (names.std_list ()));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
518 }
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
519
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
520 // Find all locations of the given file in the path.
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
521
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
522 string_vector search_path_for_all_files (const std::string& path,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
523 const string_vector& names)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
524 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
525 directory_path p (path);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
526
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
527 string_vector sv = p.find_all_first_of (names.std_list ());
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
528
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
529 octave_idx_type len = sv.numel ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
530
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
531 for (octave_idx_type i = 0; i < len; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
532 sv[i] = sys::env::make_absolute (sv[i]);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
533
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
534 return sv;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
535 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
536
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
537 static string_vector make_absolute (const string_vector& sv)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
538 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
539 octave_idx_type len = sv.numel ();
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
540
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
541 string_vector retval (len);
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
542
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
543 for (octave_idx_type i = 0; i < len; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
544 retval[i] = sys::env::make_absolute (sv[i]);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
545
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
546 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
547 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
548
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23468
diff changeset
549 DEFMETHOD (file_in_loadpath, interp, args, ,
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23468
diff changeset
550 doc: /* -*- texinfo -*-
23988
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
551 @deftypefn {} {@var{fname} =} file_in_loadpath (@var{file})
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
552 @deftypefnx {} {@var{fname} =} file_in_loadpath (@var{file}, "all")
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
553 Return the absolute name of @var{file} if it can be found in the list of
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
554 directories specified by @code{path}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
555
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
556 If no file is found, return an empty character string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
557
23988
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
558 When @var{file} is already an absolute name, the name is checked against the
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
559 file system instead of Octave's loadpath. In this case, if @var{file} exists
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
560 it will be returned in @var{fname}, otherwise an empty string is returned.
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
561
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
562 If the first argument is a cell array of strings, search each directory of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
563 the loadpath for element of the cell array and return the first that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
564 matches.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
565
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
566 If the second optional argument @qcode{"all"} is supplied, return a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
567 array containing the list of all files that have the same name in the path.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
568 If no files are found, return an empty cell array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
569 @seealso{file_in_path, dir_in_loadpath, path}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
570 @end deftypefn */)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
571 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
572 int nargin = args.length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
573
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
574 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
575 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
576
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
577 string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string");
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
578
20973
7af34656efed maint: utils.cc: Clean up code.
Rik <rik@octave.org>
parents: 20966
diff changeset
579 if (names.empty ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
580 error ("file_in_loadpath: FILE argument must not be empty");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
581
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
582 load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
583
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
584 if (nargin == 1)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
585 return ovl (sys::env::make_absolute (lp.find_first_of (names)));
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
586 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
587 {
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
588 std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
589
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
590 if (opt != "all")
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23795
diff changeset
591 error (R"(file_in_loadpath: "all" is only valid second argument)");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
592
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
593 return ovl (Cell (make_absolute (lp.find_all_first_of (names))));
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
594 }
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
595 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
596
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
597 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
598 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
599 %! f = file_in_loadpath ("plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
600 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
601 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
602
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
603 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
604 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
605 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
606
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
607 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
608 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
609 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
610
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
611 %!error file_in_loadpath ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
612 %!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
613 %!error file_in_loadpath ([])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
614 %!error file_in_loadpath ("plot.m", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
615 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
616
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
617 DEFUN (file_in_path, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
618 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
619 @deftypefn {} {@var{fname} =} file_in_path (@var{path}, @var{file})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
620 @deftypefnx {} {@var{fname} =} file_in_path (@var{path}, @var{file}, "all")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
621 Return the absolute name of @var{file} if it can be found in @var{path}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
622
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
623 The value of @var{path} should be a colon-separated list of directories in
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
624 the format described for @code{path}. If no file is found, return an empty
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
625 character string. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
626
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
627 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
628 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
629 file_in_path (EXEC_PATH, "sh")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
630 @result{} "/bin/sh"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
631 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
632 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
633
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
634 If the second argument is a cell array of strings, search each directory of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
635 the path for element of the cell array and return the first that matches.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
636
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
637 If the third optional argument @qcode{"all"} is supplied, return a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
638 array containing the list of all files that have the same name in the path.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
639 If no files are found, return an empty cell array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
640 @seealso{file_in_loadpath, dir_in_loadpath, path}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
641 @end deftypefn */)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
642 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
643 int nargin = args.length ();
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
644
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
645 if (nargin < 2 || nargin > 3)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
646 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
647
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
648 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
649
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20973
diff changeset
650 string_vector names = args(1).xstring_vector_value ("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
651
20973
7af34656efed maint: utils.cc: Clean up code.
Rik <rik@octave.org>
parents: 20966
diff changeset
652 if (names.empty ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
653 error ("file_in_path: FILE argument must not be empty");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
654
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
655 if (nargin == 2)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
656 return ovl (search_path_for_file (path, names));
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
657 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
658 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
659 std::string opt = args(2).xstring_value ("file_in_path: optional third argument must be a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
660
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
661 if (opt != "all")
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23795
diff changeset
662 error (R"(file_in_path: "all" is only valid third argument)");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
663
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
664 return ovl (Cell (make_absolute (search_path_for_all_files (path, names))));
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
665 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
666 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
667
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
668 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
669 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
670 %! f = file_in_path (path (), "plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
671 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
672 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
673
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
674 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
675 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
676 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
677
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
678 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
679 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
680 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
681
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
682 %!error file_in_path ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
683 %!error file_in_path ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
684 %!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
685 %!error file_in_path ([])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
686 %!error file_in_path (path (), [])
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
687 %!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
688 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
689
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
690 std::string file_in_path (const std::string& name, const std::string& suffix)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
691 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
692 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
693
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
694 if (! suffix.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
695 nm.append (suffix);
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
696
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
697 load_path& lp = __get_load_path__ ();
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
698
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
699 return sys::env::make_absolute (lp.find_file (nm));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
700 }
19030
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
701
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
702 std::string find_data_file_in_load_path (const std::string& fcn,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
703 const std::string& file,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
704 bool require_regular_file)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
705 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
706 std::string fname = file;
19030
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
707
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
708 if (! (sys::env::absolute_pathname (fname)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
709 || sys::env::rooted_relative_pathname (fname)))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
710 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
711 // Load path will also search "." first, but we don't want to
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
712 // issue a warning if the file is found in the current directory,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
713 // so do an explicit check for that.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
714 bool local_file_ok
32080
e9fdfebc6db0 Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32028
diff changeset
715 = sys::file_exists (fname, ! require_regular_file);
19030
9ef10e6a5987 make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
716
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
717 if (! local_file_ok)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
718 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
719 load_path& lp = __get_load_path__ ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
720
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
721 // Not directly found; search load path.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
722 std::string tmp = sys::env::make_absolute (lp.find_file (fname));
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
723
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
724 if (! tmp.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
725 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
726 warn_data_file_in_path (fcn, tmp);
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
727
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
728 fname = tmp;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
729 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
730 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
731 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
732
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
733 return fname;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
734 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
735
32080
e9fdfebc6db0 Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32028
diff changeset
736 // See if there is a function file in the path.
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
737 // If so, return the full path to the file.
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
738
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
739 std::string fcn_file_in_path (const std::string& name)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
740 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
741 std::string retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
742
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
743 int len = name.length ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
744
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
745 if (len > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
746 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
747 if (sys::env::absolute_pathname (name))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
748 {
32080
e9fdfebc6db0 Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32028
diff changeset
749 if (sys::file_exists (name, false))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
750 retval = name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
751 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
752 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
753 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
754 load_path& lp = __get_load_path__ ();
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
755
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
756 retval = lp.find_fcn_file (name.substr (0, len-2));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
757 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
758 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
759 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
760 std::string fname = name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
761 std::size_t pos = name.find_first_of ('>');
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
762 if (pos != std::string::npos)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
763 fname = name.substr (0, pos);
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
764
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
765 load_path& lp = __get_load_path__ ();
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
766
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
767 retval = lp.find_fcn_file (fname);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
768 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
769 }
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
770
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
771 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
772 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
773
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
774 // See if there is a directory called "name" in the path and if it
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
775 // contains a Contents.m file. If so, return the full path to this file.
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
776
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
777 std::string contents_file_in_path (const std::string& dir)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
778 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
779 std::string retval;
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
780
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
781 if (! dir.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
782 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
783 load_path& lp = __get_load_path__ ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
784
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
785 std::string tcontents
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
786 = sys::file_ops::concat (lp.find_dir (dir), "Contents.m");
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
787
32080
e9fdfebc6db0 Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32028
diff changeset
788 if (sys::file_exists (tcontents))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
789 retval = sys::env::make_absolute (tcontents);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
790 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
791
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
792 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
793 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
794
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
795 // Replace backslash escapes in a string with the real values.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
796
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
797 std::string do_string_escapes (const std::string& s)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
798 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
799 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
800
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
801 std::size_t i = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
802 std::size_t j = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
803 std::size_t len = s.length ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
804
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
805 retval.resize (len);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
806
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
807 while (j < len)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
808 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
809 if (s[j] == '\\' && j+1 < len)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
810 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
811 switch (s[++j])
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
812 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
813 case 'a': // alarm
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
814 retval[i] = '\a';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
815 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
816
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
817 case 'b': // backspace
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
818 retval[i] = '\b';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
819 break;
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
820
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
821 case 'f': // formfeed
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
822 retval[i] = '\f';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
823 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
824
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
825 case 'n': // newline
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
826 retval[i] = '\n';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
827 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
828
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
829 case 'r': // carriage return
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
830 retval[i] = '\r';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
831 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
832
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
833 case 't': // horizontal tab
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
834 retval[i] = '\t';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
835 break;
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
836
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
837 case 'v': // vertical tab
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
838 retval[i] = '\v';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
839 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
840
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
841 case '\\': // backslash
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
842 retval[i] = '\\';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
843 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
844
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
845 case '\'': // quote
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
846 retval[i] = '\'';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
847 break;
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
848
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
849 case '"': // double quote
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
850 retval[i] = '"';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
851 break;
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
852
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
853 case '0':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
854 case '1':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
855 case '2':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
856 case '3':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
857 case '4':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
858 case '5':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
859 case '6':
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
860 case '7': // octal input
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
861 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
862 std::size_t k;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
863 int tmpi = s[j] - '0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
864 for (k = j+1; k < std::min (j+3, len); k++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
865 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
866 int digit = s[k] - '0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
867 if (digit < 0 || digit > 7)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
868 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
869 tmpi <<= 3;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
870 tmpi += digit;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
871 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
872 retval[i] = tmpi;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
873 j = k - 1;
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
874 break;
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
875 }
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
876
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
877 case 'x': // hex input
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
878 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
879 std::size_t k;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
880 int tmpi = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
881 for (k = j+1; k < std::min (j+3, len); k++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
882 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
883 if (! isxdigit (s[k]))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
884 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
885
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
886 tmpi <<= 4;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
887 int digit = s[k];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
888 if (digit >= 'a')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
889 tmpi += digit - 'a' + 10;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
890 else if (digit >= 'A')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
891 tmpi += digit - 'A' + 10;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
892 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
893 tmpi += digit - '0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
894 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
895
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
896 if (k == j+1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
897 warning (R"(malformed hex escape sequence '\x' -- converting to '\0')");
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
898
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
899 retval[i] = tmpi;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
900 j = k - 1;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
901 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
902 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
903
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
904 default:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
905 warning (R"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
906 retval[i] = s[j];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
907 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
908 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
909 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
910 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
911 retval[i] = s[j];
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
912
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
913 i++;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
914 j++;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
915 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
916
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
917 retval.resize (i);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
918
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
919 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
920 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
921
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
922 DEFUN (do_string_escapes, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
923 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
924 @deftypefn {} {@var{newstr} =} do_string_escapes (@var{string})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
925 Convert escape sequences in @var{string} to the characters they represent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
926
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
927 Escape sequences begin with a leading backslash
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 29094
diff changeset
928 (@qcode{'@backslashchar{}'}) followed by 1--3 characters
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 29094
diff changeset
929 (.e.g., @qcode{"@backslashchar{}n"} => newline).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
930 @seealso{undo_string_escapes}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
931 @end deftypefn */)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
932 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20812
diff changeset
933 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
934 print_usage ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
935
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
936 std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string");
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
937
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
938 return ovl (do_string_escapes (str));
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
939 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
940
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
941 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
942 %!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
943 %!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
944 %!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
945 %!assert ("foo\nbar", ["foo", char(10), "bar"])
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
946
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
947 %!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
948 %!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
949 %!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
950 %! 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
951 %!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
952
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
953 %!assert (do_string_escapes ('\\'), "\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
954 %!assert (do_string_escapes ("\\\\"), "\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
955 %!assert (do_string_escapes ("\\\\"), char (92))
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
956
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
957 %!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
958 %!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
959 %!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
960 %!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
961
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
962 %!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
963 %!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
964 %!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
965 %!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
966
29eb47fe8e8c Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents: 20194
diff changeset
967 %!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
968 %!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
969 %!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
970
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
971 %!error do_string_escapes ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
972 %!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
973 %!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
974 %!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
975 %!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
976 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
977
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
978 const char * undo_string_escape (char c)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
979 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
980 switch (c)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
981 {
32027
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
982 case '\0': // NUL byte
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
983 return R"(\0)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
984
32027
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
985 case '\a': // alarm
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
986 return R"(\a)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
987
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
988 case '\b': // backspace
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
989 return R"(\b)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
990
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
991 case '\f': // formfeed
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
992 return R"(\f)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
993
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
994 case '\n': // newline
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
995 return R"(\n)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
996
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
997 case '\r': // carriage return
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
998 return R"(\r)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
999
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1000 case '\t': // horizontal tab
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1001 return R"(\t)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1002
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1003 case '\v': // vertical tab
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1004 return R"(\v)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1005
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1006 case '\\': // backslash
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1007 return R"(\\)";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1008
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1009 case '"': // double quote
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1010 return R"(\")";
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1011
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1012 default:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1013 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1014 static char retval[2] {'\0', '\0'};
20973
7af34656efed maint: utils.cc: Clean up code.
Rik <rik@octave.org>
parents: 20966
diff changeset
1015
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1016 retval[0] = c;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1017 return retval;
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
1018 }
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1019 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1020 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1021
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1022 std::string undo_string_escapes (const std::string& s)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1023 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1024 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1025
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1026 for (std::size_t i = 0; i < s.length (); i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1027 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1028
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1029 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1030 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1031
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1032 DEFUN (undo_string_escapes, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1033 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1034 @deftypefn {} {@var{newstr} =} undo_string_escapes (@var{string})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1035 Convert special characters in @var{string} back to their escaped forms.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1036
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1037 For example, the expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1038
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1039 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1040 @var{bell} = "\a";
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1041 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1042
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1043 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1044 assigns the value of the alert character (control-g, ASCII code 7) to the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1045 string variable @code{bell}. If this string is printed, the system will
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1046 ring the terminal bell (if it is possible). This is normally the desired
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1047 outcome. However, sometimes it is useful to be able to print the original
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1048 representation of the string, with the special characters replaced by their
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1049 escape sequences. For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1050
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1051 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1052 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1053 octave:13> undo_string_escapes (bell)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1054 ans = \a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1055 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1056 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1057
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1058 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1059 replaces the unprintable alert character with its printable representation.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1060 @seealso{do_string_escapes}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1061 @end deftypefn */)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1062 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20812
diff changeset
1063 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1064 print_usage ();
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1065
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1066 std::string str = args(0).xstring_value ("undo_string_escapes: STRING argument must be a string");
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1067
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1068 return ovl (undo_string_escapes (str));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1069 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
1070
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1071 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1072 %!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
1073 %!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
1074 %!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
1075
32027
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1076 %!assert (undo_string_escapes ("\0\a\b\f\n\r\t\v"), '\0\a\b\f\n\r\t\v')
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1077 %!assert (undo_string_escapes ("\0\a\b\f\n\r\t\v"), "\\0\\a\\b\\f\\n\\r\\t\\v")
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1078 %!assert (undo_string_escapes (char ([0, 7, 8, 12, 10, 13, 9, 11])),
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1079 %! "\\0\\a\\b\\f\\n\\r\\t\\v")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1080
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1081 %!assert (undo_string_escapes ("\\"), '\\')
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1082 %!assert (undo_string_escapes ("\\"), "\\\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1083 %!assert (undo_string_escapes (char (92)), "\\\\")
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1084
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1085 %!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
1086 %!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
1087
32027
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1088 %!error <Invalid call> undo_string_escapes ()
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1089 %!error <Invalid call> undo_string_escapes ("foo", "bar")
783b69da1b45 undo_string_escapes: Return '\0' for NUL byte input (bug #64051)
Rik <rik@octave.org>
parents: 31706
diff changeset
1090 %!error <STRING argument> undo_string_escapes (3)
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
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1093 DEFUN (is_absolute_filename, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1094 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1095 @deftypefn {} {@var{tf} =} is_absolute_filename (@var{file})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1096 Return true if @var{file} is an absolute filename.
25781
e04c56bbbace isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents: 25659
diff changeset
1097 @seealso{is_rooted_relative_filename, make_absolute_filename, isfolder}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1098 @end deftypefn */)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1099 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1100 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1101 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1102
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1103 return ovl (args(0).is_string ()
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1104 && sys::env::absolute_pathname (args(0).string_value ()));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1105 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1106
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1107 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1108 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1109
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1110 %!error is_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1111 %!error is_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1112 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1113
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1114 DEFUN (is_rooted_relative_filename, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1115 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1116 @deftypefn {} {@var{tf} =} is_rooted_relative_filename (@var{file})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1117 Return true if @var{file} is a rooted-relative filename.
25781
e04c56bbbace isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents: 25659
diff changeset
1118 @seealso{is_absolute_filename, make_absolute_filename, isfolder}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1119 @end deftypefn */)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1120 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1121 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1122 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1123
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1124 return ovl (args(0).is_string ()
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1125 && sys::env::rooted_relative_pathname (args(0).string_value ()));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1126 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1127
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1128 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1129 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1130
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1131 %!error is_rooted_relative_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1132 %!error is_rooted_relative_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1133 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1134
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1135 DEFUN (make_absolute_filename, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1136 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1137 @deftypefn {} {@var{abs_fname} =} make_absolute_filename (@var{file})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1138 Return the full name of @var{file} beginning from the root of the file system.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1139
28292
5bf3f462c11e Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 28012
diff changeset
1140 No check is done for the existence of @var{file}. No tilde expansion of
5bf3f462c11e Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 28012
diff changeset
1141 @var{file} is performed.
30329
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30269
diff changeset
1142 @seealso{canonicalize_file_name, is_absolute_filename,
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30269
diff changeset
1143 is_rooted_relative_filename, isfolder, tilde_expand}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1144 @end deftypefn */)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1145 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1146 if (args.length () != 1)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1147 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1148
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1149 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
1150
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1151 return ovl (sys::env::make_absolute (nm));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1152 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1153
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1154 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1155 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1156
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1157 %!error make_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1158 %!error make_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1159 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1160
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23468
diff changeset
1161 DEFMETHOD (dir_in_loadpath, interp, args, ,
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23468
diff changeset
1162 doc: /* -*- texinfo -*-
23988
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1163 @deftypefn {} {@var{dirname} =} dir_in_loadpath (@var{dir})
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1164 @deftypefnx {} {@var{dirname} =} dir_in_loadpath (@var{dir}, "all")
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1165 Return the absolute name of the loadpath element matching @var{dir} if it can
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1166 be found in the list of directories specified by @code{path}.
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1167
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1168 If no match is found, return an empty character string.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1169
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1170 The match is performed at the end of each path element. For example, if
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1171 @var{dir} is @qcode{"foo/bar"}, it matches the path element
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1172 @nospell{@qcode{"/some/dir/foo/bar"}}, but not
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1173 @nospell{@qcode{"/some/dir/foo/bar/baz"}}
23988
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1174 @nospell{@qcode{"/some/dir/allfoo/bar"}}. When @var{dir} is an absolute name,
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1175 rather than just a path fragment, it is matched against the file system
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1176 instead of Octave's loadpath. In this case, if @var{dir} exists it will be
bdde51fda657 doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents: 23925
diff changeset
1177 returned in @var{dirname}, otherwise an empty string is returned.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1178
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1179 If the optional second argument is supplied, return a cell array containing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1180 all name matches rather than just the first.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1181 @seealso{file_in_path, file_in_loadpath, path}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1182 @end deftypefn */)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1183 {
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1184 int nargin = args.length ();
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1185
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1186 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1187 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1188
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20800
diff changeset
1189 std::string dir;
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20800
diff changeset
1190
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1191 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
1192
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1193 load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1194
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1195 if (nargin == 1)
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1196 return ovl (lp.find_dir (dir));
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1197 else
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1198 return ovl (Cell (lp.find_matching_dirs (dir)));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1199 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
1200
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1201 /*
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1202 %!test
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1203 %! f = dir_in_loadpath ("plot");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1204 %! assert (ischar (f));
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1205 %! assert (! isempty (f));
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1206
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1207 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
1208 %! f = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$");
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1209 %! assert (f, "");
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1210
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1211 %!test
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
1212 %! lst = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$", "all");
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1213 %! assert (lst, {});
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1214
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18105
diff changeset
1215 %!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
1216 %!error dir_in_loadpath ("foo", "bar", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1217 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1218
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1219 DEFUNX ("errno", Ferrno, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1220 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1221 @deftypefn {} {@var{err} =} errno ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1222 @deftypefnx {} {@var{err} =} errno (@var{val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1223 @deftypefnx {} {@var{err} =} errno (@var{name})
25106
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1224 Query or set the system-dependent variable errno.
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1225
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1226 When called with no inputs, return the current value of errno.
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1227
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1228 When called with a numeric input @var{val}, set the current value of errno
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1229 to the specified value. The previous value of errno is returned as @var{err}.
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1230
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1231 When called with a character string @var{name}, return the numeric value of
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1232 errno which corresponds to the specified error code. If @var{name} is not
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1233 a recognized error code then -1 is returned.
d7ad543255c5 doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents: 25103
diff changeset
1234
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1235 @seealso{errno_list}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1236 @end deftypefn */)
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1237 {
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1238 int nargin = args.length ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1239
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1240 if (nargin > 1)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1241 print_usage ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1242
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1243 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1244
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1245 if (nargin == 1)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1246 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1247 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1248 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1249 std::string nm = args(0).string_value ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1250
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19697
diff changeset
1251 retval = octave_errno::lookup (nm);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1252 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1253 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1254 {
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1255 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
1256
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1257 retval = octave_errno::set (val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1258 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1259 }
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1260 else
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1261 retval = octave_errno::get ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1262
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1263 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1264 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1265
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1266 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1267 %!assert (isnumeric (errno ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1268
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1269 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1270 %! lst = errno_list ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1271 %! fns = fieldnames (lst);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1272 %! oldval = errno (fns{1});
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1273 %! assert (isnumeric (oldval));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1274 %! errno (oldval);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1275 %! newval = errno ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1276 %! assert (oldval, newval);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1277
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1278 %!error errno ("foo", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1279 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1280
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1281 DEFUN (errno_list, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1282 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30822
diff changeset
1283 @deftypefn {} {@var{S} =} errno_list ()
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1284 Return a structure containing the system-dependent errno values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1285 @seealso{errno}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1286 @end deftypefn */)
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1287 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1288 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1289 print_usage ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1290
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1291 return ovl (octave_errno::list ());
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1292 }
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1293
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1294 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1295 %!assert (isstruct (errno_list ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1296
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1297 %!error errno_list ("foo")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1298 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1299
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1300 static void check_dimensions (octave_idx_type& nr, octave_idx_type& nc,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1301 const char *warnfor)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1302 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1303 if (nr < 0 || nc < 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1304 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1305 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
1306 "%s: converting negative dimension to zero", warnfor);
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1307
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1308 nr = (nr < 0) ? 0 : nr;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1309 nc = (nc < 0) ? 0 : nc;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1310 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1311 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1312
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1313 void check_dimensions (dim_vector& dim, const char *warnfor)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1314 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1315 bool neg = false;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1316
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1317 for (int i = 0; i < dim.ndims (); i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1318 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1319 if (dim(i) < 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1320 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1321 dim(i) = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1322 neg = true;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1323 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1324 }
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1325
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1326 if (neg)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1327 warning_with_id ("Octave:neg-dim-as-zero",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1328 "%s: converting negative dimension to zero", warnfor);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1329 }
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1330
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1331 void get_dimensions (const octave_value& a, const char *warn_for,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1332 dim_vector& dim)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1333 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1334 // We support dimensions to be specified by a vector, even if it's empty.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1335 // If the vector is empty, the final dimensions end up being 0x0.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1336 if (! a.dims ().isvector () && a.dims ().numel () != 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1337 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21301
diff changeset
1338
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1339 const Array<octave_idx_type> v = a.octave_idx_type_vector_value (true);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1340 const octave_idx_type n = v.numel ();
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21301
diff changeset
1341
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1342 dim.resize (n); // even if n < 2, resize sets it back to 2
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1343 if (n == 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1344 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1345 dim(0) = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1346 dim(1) = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1347 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1348 else if (n == 1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1349 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1350 dim(0) = v(0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1351 dim(1) = v(0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1352 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1353 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1354 for (octave_idx_type i = 0; i < n; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1355 dim(i) = v(i);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1356
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1357 check_dimensions (dim, warn_for);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1358 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1359
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1360 void get_dimensions (const octave_value& a, const char *warn_for,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1361 octave_idx_type& nr, octave_idx_type& nc)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1362 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1363 if (a.is_scalar_type ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1364 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1365 nr = nc = a.idx_type_value (true);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1366 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1367 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1368 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1369 nr = a.rows ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1370 nc = a.columns ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1371
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1372 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1373 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
1374
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1375 Array<octave_idx_type> v = a.octave_idx_type_vector_value (true);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1376 nr = v(0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1377 nc = v(1);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1378 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1379
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1380 check_dimensions (nr, nc, warn_for);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1381 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1382
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1383 void get_dimensions (const octave_value& a, const octave_value& b,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1384 const char *warn_for, octave_idx_type& nr,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1385 octave_idx_type& nc)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1386 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1387 nr = (a.isempty () ? 0 : a.idx_type_value (true));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1388 nc = (b.isempty () ? 0 : b.idx_type_value (true));
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1389
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1390 check_dimensions (nr, nc, warn_for);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1391 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1392
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1393 octave_idx_type dims_to_numel (const dim_vector& dims,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1394 const octave_value_list& idx_arg)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1395 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1396 octave_idx_type retval;
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1397
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1398 octave_idx_type len = idx_arg.length ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1399
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1400 if (len == 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1401 retval = dims.numel ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1402 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1403 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1404 const dim_vector dv = dims.redim (len);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1405 retval = 1;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1406 for (octave_idx_type i = 0; i < len; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1407 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1408 octave_value idxi = idx_arg(i);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1409 if (idxi.is_magic_colon ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1410 retval *= dv(i);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1411 else if (idxi.isnumeric ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1412 retval *= idxi.numel ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1413 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1414 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1415 try
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1416 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1417 idx_vector jdx = idxi.index_vector ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1418
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1419 retval *= jdx.length (dv(i));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1420 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1421 catch (const index_exception& ie)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1422 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1423 error ("dims_to_numel: invalid index %s", ie.what ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1424 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1425 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1426 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1427 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1428
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1429 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1430 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1431
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1432 Matrix identity_matrix (octave_idx_type nr, octave_idx_type nc)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1433 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1434 Matrix m (nr, nc, 0.0);
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1435
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1436 if (nr > 0 && nc > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1437 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1438 octave_idx_type n = std::min (nr, nc);
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1439
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1440 for (octave_idx_type i = 0; i < n; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1441 m (i, i) = 1.0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1442 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1443
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1444 return m;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1445 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1446
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1447 FloatMatrix float_identity_matrix (octave_idx_type nr, octave_idx_type nc)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1448 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1449 FloatMatrix m (nr, nc, 0.0);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1450
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1451 if (nr > 0 && nc > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1452 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1453 octave_idx_type n = std::min (nr, nc);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1454
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1455 for (octave_idx_type i = 0; i < n; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1456 m (i, i) = 1.0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1457 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1458
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1459 return m;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1460 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1461
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1462 std::size_t format (std::ostream& os, const char *fmt, ...)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1463 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1464 std::size_t retval;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1465
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1466 va_list args;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1467 va_start (args, fmt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1468
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1469 retval = vformat (os, fmt, args);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1470
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1471 va_end (args);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1472
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1473 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1474 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1475
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1476 std::size_t vformat (std::ostream& os, const char *fmt, va_list args)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1477 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1478 std::string s = vasprintf (fmt, args);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1479
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1480 os << s;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1481
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1482 return s.length ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1483 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1484
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1485 std::string vasprintf (const char *fmt, va_list args)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1486 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1487 std::string retval;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1488
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1489 char *result;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1490
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1491 int status = octave_vasprintf_wrapper (&result, fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1492
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1493 if (status >= 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1494 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1495 retval = result;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1496 ::free (result);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1497 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1498
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1499 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1500 }
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1501
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1502 std::string asprintf (const char *fmt, ...)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1503 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1504 std::string retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1505
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1506 va_list args;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1507 va_start (args, fmt);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1508
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1509 retval = vasprintf (fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1510
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1511 va_end (args);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1512
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1513 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1514 }
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1515
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1516 // FIXME: sleep is complicated because we want it to be interruptible.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1517 // With the way this program handles signals, the sleep system call
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1518 // won't respond to SIGINT. Maybe there is a better way than
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1519 // breaking this up into multiple shorter intervals?
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1520
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1521 void sleep (double seconds, bool do_graphics_events)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1522 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1523 if (seconds <= 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1524 return;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1525
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1526 // Allow free access to graphics resources while the interpreter thread
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1527 // is asleep
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1528
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1529 gh_manager& gh_mgr = __get_gh_manager__ ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1530
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1531 if (do_graphics_events)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1532 gh_mgr.unlock ();
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1533
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1534 if (math::isinf (seconds))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1535 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1536 // Wait for kbhit
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1537 int c = -1;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1538 flush_stdout ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1539
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1540 struct timespec one_tenth = { 0, 100000000 };
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
1541
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1542 while (c < 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1543 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1544 octave_nanosleep_wrapper (&one_tenth, nullptr);
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27279
diff changeset
1545
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1546 octave_quit ();
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27279
diff changeset
1547
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1548 if (do_graphics_events)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1549 gh_mgr.process_events ();
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1550
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1551 c = kbhit (false);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1552 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1553 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1554 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1555 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1556 sys::time now;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1557 double end_time = now.double_value () + seconds;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1558 double remaining_time = seconds;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1559
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1560 // Split pause into 100 ms time steps to allow the execution of
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1561 // graphics events and interrupts.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1562 struct timespec nano_laps = { 0, 100000000 };
24604
6b3c78f84d3b allow octave_sleep to be interruptible (bug #52876)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1563
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1564 while (remaining_time > 0.1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1565 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1566 octave_quit ();
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25928
diff changeset
1567
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1568 if (do_graphics_events)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1569 {
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27279
diff changeset
1570 gh_mgr.process_events ();
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25928
diff changeset
1571
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1572 now.stamp ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1573 remaining_time = end_time - now.double_value ();
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25928
diff changeset
1574
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1575 if (remaining_time < 0.1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1576 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1577 }
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25928
diff changeset
1578
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1579 octave_nanosleep_wrapper (&nano_laps, nullptr);
27094
f16471efcdf4 Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1580
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1581 now.stamp ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1582 remaining_time = end_time - now.double_value ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1583 }
27094
f16471efcdf4 Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1584
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1585 if (remaining_time > 0.0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1586 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1587 nano_laps = { 0, static_cast<int> (remaining_time * 1e9) };
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1588 octave_nanosleep_wrapper (&nano_laps, nullptr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1589 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1590 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1591 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1592
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
1593 DEFMETHOD (isindex, interp, args, ,
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
1594 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1595 @deftypefn {} {@var{tf} =} isindex (@var{ind})
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1596 @deftypefnx {} {@var{tf} =} isindex (@var{ind}, @var{n})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1597 Return true if @var{ind} is a valid index.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1598
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1599 Valid indices are either positive integers (although possibly of real data
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1600 type), or logical arrays.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1601
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1602 If present, @var{n} specifies the maximum extent of the dimension to be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1603 indexed. When possible the internal result is cached so that subsequent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1604 indexing using @var{ind} will not perform the check again.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1605
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1606 Implementation Note: Strings are first converted to double values before the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1607 checks for valid indices are made. Unless a string contains the NULL
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 29094
diff changeset
1608 character @nospell{"@backslashchar{}0"}, it will always be a valid index.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1609 @end deftypefn */)
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1610 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1611 int nargin = args.length ();
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1612
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1613 if (nargin < 1 || nargin > 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1614 print_usage ();
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1615
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1616 octave_idx_type n = 0;
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1617 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1618 n = args(1).idx_type_value ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1619
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1620 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1621
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1622 try
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1623 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1624 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
1625
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1626 if (nargin == 2)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1627 retval = idx.extent (n) <= n;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1628 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1629 retval = true;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1630 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
1631 catch (const execution_exception&)
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1632 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
1633 interp.recover_from_exception ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1634
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1635 retval = false;
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1636 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1637
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1638 return retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1639 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1640
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1641 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1642 %!assert (isindex ([1, 2, 3]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1643 %!assert (isindex (1:3))
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1644 %!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
1645 %!assert (isindex ([1, 2, -3]), false)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1646
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1647 %!error isindex ()
19138
ebeb3defae37 codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents: 19128
diff changeset
1648 %!error isindex (1:3, 2, 3)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1649 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1650
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1651 octave_value_list
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1652 do_simple_cellfun (octave_value_list (*fcn) (const octave_value_list&, int),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1653 const char *fcn_name, const octave_value_list& args,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1654 int nargout)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1655 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1656 octave_value_list new_args = args;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1657 octave_value_list retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1658 int nargin = args.length ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1659 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1660 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1661 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1662
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1663 const Cell *ccells = cells;
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1664
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1665 octave_idx_type numel = 1;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1666 dim_vector dims (1, 1);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1667
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1668 for (int i = 0; i < nargin; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1669 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1670 octave_value arg = new_args(i);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1671 iscell[i] = arg.iscell ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1672 if (iscell[i])
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1673 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1674 cells[i] = arg.cell_value ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1675 octave_idx_type n = ccells[i].numel ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1676 if (n == 1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1677 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1678 iscell[i] = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1679 new_args(i) = ccells[i](0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1680 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1681 else if (numel == 1)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1682 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1683 numel = n;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1684 dims = ccells[i].dims ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1685 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1686 else if (dims != ccells[i].dims ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1687 error ("%s: cell arguments must have matching sizes", fcn_name);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1688 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1689 }
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1690
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1691 for (int i = 0; i < nargout; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1692 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
1693
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1694 for (octave_idx_type j = 0; j < numel; j++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1695 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1696 for (int i = 0; i < nargin; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1697 if (iscell[i])
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1698 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
1699
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1700 octave_quit ();
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1701
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1702 const octave_value_list tmp = fcn (new_args, nargout);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1703
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1704 if (tmp.length () < nargout)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1705 error ("%s: do_simple_cellfun: internal error", fcn_name);
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
1706
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1707 for (int i = 0; i < nargout; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1708 rcells[i](j) = tmp(i);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1709 }
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1710
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1711 retval.resize (nargout);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1712
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1713 for (int i = 0; i < nargout; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1714 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
1715
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1716 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1717 }
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1718
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1719 octave_value
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1720 do_simple_cellfun (octave_value_list (*fcn) (const octave_value_list&, int),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1721 const char *fcn_name, const octave_value_list& args)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1722 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1723 octave_value retval;
20973
7af34656efed maint: utils.cc: Clean up code.
Rik <rik@octave.org>
parents: 20966
diff changeset
1724
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1725 const octave_value_list tmp = do_simple_cellfun (fcn, fcn_name, args, 1);
20973
7af34656efed maint: utils.cc: Clean up code.
Rik <rik@octave.org>
parents: 20966
diff changeset
1726
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1727 if (tmp.length () > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1728 retval = tmp(0);
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1729
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1730 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1731 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1732
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1733 DEFUN (isstudent, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1734 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1735 @deftypefn {} {@var{tf} =} isstudent ()
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1736 Return true if running in the student edition of @sc{matlab}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1737
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1738 @code{isstudent} always returns false in Octave.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1739 @seealso{false}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
1740 @end deftypefn */)
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1741 {
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1742 if (args.length () != 0)
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1743 print_usage ();
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1744
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20926
diff changeset
1745 return ovl (false);
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1746 }
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1747
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1748 /*
19152
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1749 %!assert (isstudent (), false)
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1750
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19138
diff changeset
1751 %!error isstudent (1)
19128
4990d5988cf5 new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents: 19030
diff changeset
1752 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1753
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31278
diff changeset
1754 OCTAVE_END_NAMESPACE(octave)