annotate libinterp/corefcn/utils.cc @ 27335:50216d7a2f6b

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