annotate src/utils.cc @ 10257:cd550069240e

assume vsnprintf from gnulib; use sstream instead of snprintf
author John W. Eaton <jwe@octave.org>
date Wed, 03 Feb 2010 06:34:29 -0500
parents 2d47356a7a1a
children 57a59eae83cc
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
25 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
28 #include <cerrno>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
29 #include <climits>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
30 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
31
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
32 #include <fstream>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
33 #include <iostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
34 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
35
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #include <sys/types.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include <unistd.h>
367
04d377033730 [project @ 1994-02-16 08:04:52 by jwe]
jwe
parents: 341
diff changeset
38
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
39 #include "quit.h"
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
40
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
41 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
42 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
43 #include "file-stat.h"
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
44 #include "lo-mappers.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
45 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
46 #include "oct-env.h"
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
47 #include "pathsearch.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
48 #include "str-vec.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
49
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
50 #include "Cell.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2442
diff changeset
51 #include <defaults.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"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
55 #include "gripes.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
56 #include "input.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
57 #include "load-path.h"
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
58 #include "oct-errno.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
59 #include "oct-hist.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
60 #include "oct-obj.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "pager.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
62 #include "sysdep.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
63 #include "toplev.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
64 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
65 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
66 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
67
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
68 // Return TRUE if S is a valid identifier.
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
69
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
70 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
71 valid_identifier (const char *s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
72 {
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
73 if (! s || ! (isalpha (*s) || *s == '_' || *s == '$'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
74 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
75
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
76 while (*++s != '\0')
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
77 if (! (isalnum (*s) || *s == '_' || *s == '$'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
78 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
79
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
80 return true;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
81 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
82
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
83 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
84 valid_identifier (const std::string& s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
85 {
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
86 return valid_identifier (s.c_str ());
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
87 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
88
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8715
diff changeset
89 DEFUN (isvarname, args, ,
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4783
diff changeset
90 "-*- texinfo -*-\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4783
diff changeset
91 @deftypefn {Built-in Function} {} isvarname (@var{name})\n\
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
92 Return true if @var{name} is a valid variable name\n\
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
93 @end deftypefn")
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
94 {
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
95 octave_value retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
96
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
97 int argc = args.length () + 1;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
98
4610
02d2fcf835fc [project @ 2003-11-14 17:08:59 by jwe]
jwe
parents: 4564
diff changeset
99 string_vector argv = args.make_argv ("isvarname");
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
100
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
101 if (error_state)
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
102 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
103
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
104 if (argc == 2)
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
105 retval = valid_identifier (argv[1]);
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
106 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
107 print_usage ();
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
108
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
109 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
110 }
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
111
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
112 // Return TRUE if F and G are both names for the same file.
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
113
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
114 bool
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
115 same_file (const std::string& f, const std::string& g)
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
116 {
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6379
diff changeset
117 return same_file_internal (f, g);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
118 }
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
119
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
120 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
121 almost_match (const std::string& std, const std::string& s, int min_match_len,
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
122 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
123 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
124 int stdlen = std.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
125 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
126
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
127 return (slen <= stdlen
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
128 && slen >= min_match_len
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
129 && (case_sens
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
130 ? (strncmp (std.c_str (), s.c_str (), slen) == 0)
3350
729ad2b6a052 [project @ 1999-11-12 16:18:16 by jwe]
jwe
parents: 3301
diff changeset
131 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
132 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
133
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
134 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
135
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
136 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
137 keyword_almost_match (const char * const *std, int *min_len, const std::string& s,
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
138 int min_toks_to_match, int max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
139 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
140 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
141 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
142 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
143
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
144 if (s.empty () || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
145 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
146
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
147 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
148
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
149 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
150 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
151 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
152 if (*t == '\t')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
153 *t = ' ';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
154 t++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
155 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
156
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
157 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
158 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
159 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
160
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
161 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
162 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
163
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
164
3072
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
165 const char **to_match = new const char * [max_toks + 1];
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
166 const char * const *s1 = std;
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
167 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
168
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
169 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
170 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
171
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
172 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
173 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
174 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
175 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
176 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
177 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
178
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
179 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
180 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
181
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
182 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
183 break;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
184
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
185 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
186 if (tok_count >= max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
187 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
188
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
189 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
190 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
191 s2[tok_count+1] = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
192
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
193 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
194
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
195 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
196 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
197 if (! almost_match (*s1, *s2, min_len[toks_matched], 0))
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
198 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
199
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
200 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
201
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
202 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
203 s2++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
204
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
205 if (! *s2)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
206 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
207 status = (toks_matched >= min_toks_to_match);
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
208 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
209 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
210
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
211 if (! *s1)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
212 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
213 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
214
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
215 done:
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
216
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
217 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
218 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
219
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
220 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
221 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
222
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
223 // Return non-zero if either NR or NC is zero. Return -1 if this
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
224 // should be considered fatal; return 1 if this is ok.
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
225
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
226 int
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
227 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
228 {
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
229 return (nr == 0 || nc == 0);
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
230 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
231
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
232 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
233
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
234 std::string
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
235 search_path_for_file (const std::string& path, const string_vector& names)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
236 {
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
237 dir_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
238
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
239 return octave_env::make_absolute (p.find_first_of (names));
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
240 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
241
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
242 // Find all locations of the given file in the path.
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
243
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
244 string_vector
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
245 search_path_for_all_files (const std::string& path, const string_vector& names)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
246 {
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
247 dir_path p (path);
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
248
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
249 string_vector sv = p.find_all_first_of (names);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
250
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
251 octave_idx_type len = sv.length ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
252
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
253 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
254 sv[i] = octave_env::make_absolute (sv[i]);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
255
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
256 return sv;
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
257 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
258
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
259 static string_vector
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
260 make_absolute (const string_vector& sv)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
261 {
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
262 octave_idx_type len = sv.length ();
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
263
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
264 string_vector retval (len);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
265
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
266 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
267 retval[i] = octave_env::make_absolute (sv[i]);
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
268
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
269 return retval;
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
270 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
271
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
272 DEFUN (file_in_loadpath, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
273 "-*- texinfo -*-\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
274 @deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
275 @deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
276 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
277 Return the absolute name of @var{file} if it can be found in\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
278 the list of directories specified by @code{path}.\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
279 If no file is found, return an empty matrix.\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
280 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
281 If the first argument is a cell array of strings, search each\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
282 directory of the loadpath for element of the cell array and return\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
283 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
284 \n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
285 If the second optional argument @code{\"all\"} is supplied, return\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
286 a cell array containing the list of all files that have the same\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
287 name in the path. If no files are found, return an empty cell array.\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
288 @seealso{file_in_path, path}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5612
diff changeset
289 @end deftypefn")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
290 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
291 octave_value retval;
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
292
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
293 int nargin = args.length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
294
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
295 if (nargin == 1 || nargin == 2)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
296 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
297 string_vector names = args(0).all_strings ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
298
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
299 if (! error_state && names.length () > 0)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
300 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
301 if (nargin == 1)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
302 {
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
303 std::string fname
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
304 = octave_env::make_absolute (load_path::find_first_of (names));
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
305
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
306 if (fname.empty ())
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
307 retval = Matrix ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
308 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
309 retval = fname;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
310 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
311 else if (nargin == 2)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
312 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
313 std::string opt = args(1).string_value ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
314
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
315 if (! error_state && opt == "all")
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
316 retval = Cell (make_absolute
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
317 (load_path::find_all_first_of (names)));
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
318 else
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
319 error ("file_in_loadpath: invalid option");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
320 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
321 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
322 else
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
323 error ("file_in_loadpath: expecting string as first argument");
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
324 }
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
325 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
326 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
327
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
328 return retval;
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
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
331 DEFUN (file_in_path, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
332 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
333 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
334 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
335 Return the absolute name of @var{file} if it can be found in\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
336 @var{path}. The value of @var{path} should be a colon-separated list of\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
337 directories in the format described for @code{path}. If no file\n\
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5781
diff changeset
338 is found, return an empty matrix. For example,\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
339 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
340 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
341 @group\n\
5456
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
342 file_in_path (EXEC_PATH, \"sh\")\n\
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
343 @result{} \"/bin/sh\"\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
344 @end group\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
345 @end example\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
346 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
347 If the second argument is a cell array of strings, search each\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
348 directory of the path for element of the cell array and return\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
349 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
350 \n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
351 If the third optional argument @code{\"all\"} is supplied, return\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
352 a cell array containing the list of all files that have the same\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
353 name in the path. If no files are found, return an empty cell array.\n\
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
354 @seealso{file_in_loadpath}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
355 @end deftypefn")
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
356 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
357 octave_value retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
358
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
359 int nargin = args.length ();
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
360
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
361 if (nargin == 2 || nargin == 3)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
362 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
363 std::string path = args(0).string_value ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
364
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
365 if (! error_state)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
366 {
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
367 string_vector names = args(1).all_strings ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
368
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
369 if (! error_state && names.length () > 0)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
370 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
371 if (nargin == 2)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
372 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
373 std::string fname = search_path_for_file (path, names);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
374
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
375 if (fname.empty ())
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
376 retval = Matrix ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
377 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
378 retval = fname;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
379 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
380 else if (nargin == 3)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
381 {
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
382 std::string opt = args(2).string_value ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
383
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
384 if (! error_state && opt == "all")
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
385 retval = Cell (make_absolute
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
386 (search_path_for_all_files (path, names)));
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
387 else
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
388 error ("file_in_path: invalid option");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
389 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
390 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
391 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
392 error ("file_in_path: expecting string as second argument");
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
393 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
394 else
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
395 error ("file_in_path: expecting string as first argument");
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
396 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
397 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
398 print_usage ();
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 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
401 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
402
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
403 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
404 file_in_path (const std::string& name, const std::string& suffix)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
405 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
406 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
407
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
408 if (! suffix.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
409 nm.append (suffix);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
410
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
411 return octave_env::make_absolute (load_path::find_file (nm));
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
412 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
413
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
414 // See if there is an function file in the path. If so, return the
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
415 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
416
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
417 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
418 fcn_file_in_path (const std::string& name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
419 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
420 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
421
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
422 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
423
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
424 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
425 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
426 if (octave_env::absolute_pathname (name))
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
427 {
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
428 file_stat fs (name);
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
429
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
430 if (fs.exists ())
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
431 retval = name;
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
432 }
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
433 else if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm')
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
434 retval = load_path::find_fcn_file (name.substr (0, len-2));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
435 else
7818
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
436 {
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
437 std::string fname = name;
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
438 size_t pos = name.find_first_of (Vfilemarker);
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
439 if (pos != std::string::npos)
7818
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
440 fname = name.substr (0, pos);
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
441
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
442 retval = load_path::find_fcn_file (fname);
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
443 }
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
444 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
445
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
446 return retval;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
447 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
448
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
449 // See if there is a directory called "name" in the path and if it
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
450 // contains a Contents.m file return the full path to this file.
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
451
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
452 std::string
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
453 contents_file_in_path (const std::string& dir)
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
454 {
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
455 std::string retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
456
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
457 if (dir.length () > 0)
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
458 {
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
459 std::string tcontents = file_ops::concat (load_path::find_dir (dir),
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
460 std::string ("Contents.m"));
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
461
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
462 file_stat fs (tcontents);
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
463
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
464 if (fs.exists ())
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
465 retval = octave_env::make_absolute (tcontents);
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
466 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
467
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
468 return retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
469 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
470
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
471 // See if there is a .oct file in the path. If so, return the
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
472 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
473
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
474 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
475 oct_file_in_path (const std::string& name)
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
476 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
477 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
478
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
479 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
480
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
481 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
482 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
483 if (octave_env::absolute_pathname (name))
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
484 {
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
485 file_stat fs (name);
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
486
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
487 if (fs.exists ())
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
488 retval = name;
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
489 }
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
490 else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'o'
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
491 && name [len - 2] == 'c' && name [len - 1] == 't')
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
492 retval = load_path::find_oct_file (name.substr (0, len-4));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
493 else
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
494 retval = load_path::find_oct_file (name);
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
495 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
496
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
497 return retval;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
498 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
499
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
500 // See if there is a .mex file in the path. If so, return the
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
501 // full path to the file.
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
502
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
503 std::string
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
504 mex_file_in_path (const std::string& name)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
505 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
506 std::string retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
507
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
508 int len = name.length ();
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
509
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
510 if (len > 0)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
511 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
512 if (octave_env::absolute_pathname (name))
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
513 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
514 file_stat fs (name);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
515
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
516 if (fs.exists ())
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
517 retval = name;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
518 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
519 else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'm'
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
520 && name [len - 2] == 'e' && name [len - 1] == 'x')
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
521 retval = load_path::find_mex_file (name.substr (0, len-4));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
522 else
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
523 retval = load_path::find_mex_file (name);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
524 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
525
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
526 return retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
527 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
528
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
529 // Replace backslash escapes in a string with the real values.
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
530
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
531 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
532 do_string_escapes (const std::string& s)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
533 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
534 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
535
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
536 size_t i = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
537 size_t j = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
538 size_t len = s.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
539
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
540 retval.resize (len);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
541
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
542 while (j < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
543 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
544 if (s[j] == '\\' && j+1 < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
545 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
546 switch (s[++j])
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
547 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
548 case '0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
549 retval[i] = '\0';
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
550 break;
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
551
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
552 case 'a':
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
553 retval[i] = '\a';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
554 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
555
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
556 case 'b': // backspace
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
557 retval[i] = '\b';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
558 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
559
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
560 case 'f': // formfeed
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
561 retval[i] = '\f';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
562 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
563
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
564 case 'n': // newline
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
565 retval[i] = '\n';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
566 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
567
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
568 case 'r': // carriage return
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
569 retval[i] = '\r';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
570 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
571
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
572 case 't': // horizontal tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
573 retval[i] = '\t';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
574 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
575
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
576 case 'v': // vertical tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
577 retval[i] = '\v';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
578 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
579
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
580 case '\\': // backslash
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
581 retval[i] = '\\';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
582 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
583
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
584 case '\'': // quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
585 retval[i] = '\'';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
586 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
587
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
588 case '"': // double quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
589 retval[i] = '"';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
590 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
591
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
592 default:
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
593 warning ("unrecognized escape sequence `\\%c' --\
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
594 converting to `%c'", s[j], s[j]);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
595 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
596 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
597 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
598 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
599 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
600 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
601 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
602 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
603
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
604 i++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
605 j++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
606 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
607
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3103
diff changeset
608 retval.resize (i);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
609
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
610 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
611 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
612
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
613 DEFUN (do_string_escapes, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
614 "-*- texinfo -*-\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
615 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
616 Convert special characters in @var{string} to their escaped forms.\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
617 @end deftypefn")
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
618 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
619 octave_value retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
620
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
621 int nargin = args.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
622
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
623 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
624 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
625 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
626 retval = do_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
627 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
628 error ("do_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
629 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
630 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
631 print_usage ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
632
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
633 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
634 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
635
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
636 const char *
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
637 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
638 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
639 if (! c)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
640 return "";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
641
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
642 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
643 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
644 case '\0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
645 return "\\0";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
646
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
647 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
648 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
649
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
650 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
651 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
652
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
653 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
654 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
655
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
656 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
657 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
658
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
659 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
660 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
661
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
662 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
663 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
664
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
665 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
666 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
667
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
668 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
669 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
670
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
671 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
672 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
673
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
674 default:
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
675 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
676 static char retval[2];
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
677 retval[0] = c;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
678 retval[1] = '\0';
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
679 return retval;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
680 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
681 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
682 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
683
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
684 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
685 undo_string_escapes (const std::string& s)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
686 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
687 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
688
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
689 for (size_t i = 0; i < s.length (); i++)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
690 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
691
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
692 return retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
693 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
694
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
695 DEFUN (undo_string_escapes, args, ,
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
696 "-*- texinfo -*-\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
697 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
698 Converts special characters in strings back to their escaped forms. For\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
699 example, the expression\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
700 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
701 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
702 bell = \"\\a\";\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
703 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
704 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
705 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
706 assigns the value of the alert character (control-g, ASCII code 7) to\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
707 the string variable @code{bell}. If this string is printed, the\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
708 system will ring the terminal bell (if it is possible). This is\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
709 normally the desired outcome. However, sometimes it is useful to be\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
710 able to print the original representation of the string, with the\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
711 special characters replaced by their escape sequences. For example,\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
712 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
713 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
714 @group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
715 octave:13> undo_string_escapes (bell)\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
716 ans = \\a\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
717 @end group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
718 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
719 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
720 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
721 replaces the unprintable alert character with its printable\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
722 representation.\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
723 @end deftypefn")
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
724 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2010
diff changeset
725 octave_value retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
726
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
727 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
728
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
729 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
730 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
731 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
732 retval = undo_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
733 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
734 error ("undo_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
735 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
736 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
737 print_usage ();
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
738
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
739 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
740 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
741
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
742 DEFUN (is_absolute_filename, args, ,
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
743 "-*- texinfo -*-\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
744 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
745 Return true if @var{file} is an absolute filename.\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
746 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
747 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
748 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
749
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
750 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
751 retval = (args(0).is_string ()
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
752 && octave_env::absolute_pathname (args(0).string_value ()));
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
753 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
754 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
755
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
756 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
757 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
758
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
759 DEFUN (is_rooted_relative_filename, args, ,
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
760 "-*- texinfo -*-\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
761 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
762 Return true if @var{file} is a rooted-relative filename.\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
763 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
764 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
765 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
766
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
767 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
768 retval = (args(0).is_string ()
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
769 && octave_env::rooted_relative_pathname (args(0).string_value ()));
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
770 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
771 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
772
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
773 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
774 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
775
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
776 DEFUN (make_absolute_filename, args, ,
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
777 "-*- texinfo -*-\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
778 @deftypefn {Built-in Function} {} make_absolute_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
779 Return the full name of @var{file}, relative to the current directory.\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
780 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
781 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
782 octave_value retval = std::string ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
783
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
784 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
785 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
786 std::string nm = args(0).string_value ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
787
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
788 if (! error_state)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
789 retval = octave_env::make_absolute (nm);
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
790 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
791 error ("make_absolute_filename: expecting argument to be a file name");
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
792 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
793 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
794 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
795
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
796 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
797 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
798
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
799 DEFUN (find_dir_in_path, args, ,
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
800 "-*- texinfo -*-\n\
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
801 @deftypefn {Built-in Function} {} find_dir_in_path (@var{dir}, \"all\")\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
802 Return the full name of the path element matching @var{dir}. The\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
803 match is performed at the end of each path element. For example, if\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
804 @var{dir} is @code{\"foo/bar\"}, it matches the path element\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
805 @code{\"/some/dir/foo/bar\"}, but not @code{\"/some/dir/foo/bar/baz\"}\n\
8715
954b6f69f51d doc fixes
John W. Eaton <jwe@octave.org>
parents: 8229
diff changeset
806 or @code{\"/some/dir/allfoo/bar\"}.\n\
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
807 \n\
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
808 The second argument is optional. If it is supplied, return a cell array\n\
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
809 containing all the directory names that match.\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
810 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
811 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
812 octave_value retval = std::string ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
813
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
814 int nargin = args.length ();
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
815
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
816 std::string dir;
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
817
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
818 if (nargin == 1 || nargin == 2)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
819 {
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
820 dir = args(0).string_value ();
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
821
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
822 if (! error_state)
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
823 {
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
824 if (nargin == 1)
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
825 retval = load_path::find_dir (dir);
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
826 else if (nargin == 2)
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
827 retval = Cell (load_path::find_matching_dirs (dir));
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
828 }
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
829 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
830 error ("find_dir_in_path: expecting argument to be a directory name");
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
831 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
832 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
833 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
834
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
835 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
836 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
837
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
838 DEFUNX ("errno", Ferrno, args, ,
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
839 "-*- texinfo -*-\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
840 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
841 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
842 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
843 Return the current value of the system-dependent variable errno,\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
844 set its value to @var{val} and return the previous value, or return\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
845 the named error code given @var{name} as a character string, or -1\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
846 if @var{name} is not found.\n\
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
847 @end deftypefn")
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
848 {
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
849 octave_value retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
850
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
851 int nargin = args.length ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
852
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
853 if (nargin == 1)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
854 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
855 if (args(0).is_string ())
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
856 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
857 std::string nm = args(0).string_value ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
858
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
859 if (! error_state)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
860 retval = octave_errno::lookup (nm);
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
861 else
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
862 error ("errno: expecting character string argument");
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
863 }
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
864 else
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
865 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
866 int val = args(0).int_value ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
867
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
868 if (! error_state)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
869 retval = octave_errno::set (val);
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
870 else
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
871 error ("errno: expecting integer argument");
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
872 }
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
873 }
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
874 else if (nargin == 0)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
875 retval = octave_errno::get ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
876 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
877 print_usage ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
878
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
879 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
880 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
881
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
882 DEFUN (errno_list, args, ,
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
883 "-*- texinfo -*-\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
884 @deftypefn {Built-in Function} {} errno_list ()\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
885 Return a structure containing the system-dependent errno values.\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
886 @end deftypefn")
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
887 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
888 octave_value retval;
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
889
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
890 if (args.length () == 0)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
891 retval = octave_errno::list ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
892 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
893 print_usage ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
894
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
895 return retval;
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
896 }
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
897
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
898 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
899 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
900 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
901 if (nr < 0 || nc < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
902 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
903 warning_with_id ("Octave:neg-dim-as-zero",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
904 "%s: converting negative dimension to zero", warnfor);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
905
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
906 nr = (nr < 0) ? 0 : nr;
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
907 nc = (nc < 0) ? 0 : nc;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
908 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
909 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
910
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
911 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
912 check_dimensions (dim_vector& dim, const char *warnfor)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
913 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
914 bool neg = false;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
915
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
916 for (int i = 0; i < dim.length (); i++)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
917 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
918 if (dim(i) < 0)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
919 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
920 dim(i) = 0;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
921 neg = true;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
922 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
923 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
924
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
925 if (neg)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
926 warning_with_id ("Octave:neg-dim-as-zero",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
927 "%s: converting negative dimension to zero", warnfor);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
928 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
929
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
930
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
931 void
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
932 get_dimensions (const octave_value& a, const char *warn_for,
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
933 dim_vector& dim)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
934 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
935 if (a.is_scalar_type ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
936 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
937 dim.resize (2);
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
938 dim(0) = a.int_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
939 dim(1) = dim(0);
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
940 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
941 else
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
942 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
943 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
944 octave_idx_type nc = a.columns ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
945
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
946 if (nr == 1 || nc == 1)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
947 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
948 Array<double> v = a.vector_value ();
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
949
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
950 if (error_state)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
951 return;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
952
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
953 octave_idx_type n = v.length ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
954 dim.resize (n);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
955 for (octave_idx_type i = 0; i < n; i++)
4783
55975a3073be [project @ 2004-02-17 17:16:37 by jwe]
jwe
parents: 4732
diff changeset
956 dim(i) = static_cast<int> (fix (v(i)));
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
957 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
958 else
5257
d957f0ef5aa3 [project @ 2005-03-29 19:08:34 by jwe]
jwe
parents: 5040
diff changeset
959 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
960 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
961
5258
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
962 if (! error_state)
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
963 check_dimensions (dim, warn_for); // May set error_state.
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
964 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
965
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
966
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
967 void
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
968 get_dimensions (const octave_value& a, const char *warn_for,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
969 octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
970 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
971 if (a.is_scalar_type ())
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
972 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
973 nr = nc = a.int_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
974 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
975 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
976 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
977 nr = a.rows ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
978 nc = a.columns ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
979
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
980 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
981 {
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
982 Array<double> v = a.vector_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
983
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
984 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
985 return;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
986
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
987 nr = static_cast<octave_idx_type> (fix (v (0)));
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
988 nc = static_cast<octave_idx_type> (fix (v (1)));
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
989 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
990 else
5257
d957f0ef5aa3 [project @ 2005-03-29 19:08:34 by jwe]
jwe
parents: 5040
diff changeset
991 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
992 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
993
5258
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
994 if (! error_state)
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
995 check_dimensions (nr, nc, warn_for); // May set error_state.
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
996 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
997
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
998 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
999 get_dimensions (const octave_value& a, const octave_value& b,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1000 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1001 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1002 nr = a.is_empty () ? 0 : a.int_value ();
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1003 nc = b.is_empty () ? 0 : b.int_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1004
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1005 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1006 error ("%s: expecting two scalar arguments", warn_for);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1007 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1008 check_dimensions (nr, nc, warn_for); // May set error_state.
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1009 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1010
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1011 octave_idx_type
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1012 dims_to_numel (const dim_vector& dims, const octave_value_list& idx)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1013 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1014 octave_idx_type retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1015
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1016 octave_idx_type len = idx.length ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1017
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1018 if (len == 0)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1019 retval = dims.numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1020 else
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1021 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1022 const dim_vector dv = dims.redim (len);
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1023 retval = 1;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1024 for (octave_idx_type i = 0; i < len; i++)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1025 {
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1026 octave_value idxi = idx(i);
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1027 if (idxi.is_magic_colon ())
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1028 retval *= dv(i);
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1029 else if (idxi.is_numeric_type ())
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1030 retval *= idxi.numel ();
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1031 else
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1032 {
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1033 idx_vector jdx = idxi.index_vector ();
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1034 if (error_state)
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1035 break;
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1036 retval *= jdx.length (dv(i));
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1037 }
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1038 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1039 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1040
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1041 return retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1042 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1043
10033
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1044 void
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1045 decode_subscripts (const char* name, const octave_value& arg,
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1046 std::string& type_string,
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1047 std::list<octave_value_list>& idx)
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1048 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1049 Octave_map m = arg.map_value ();
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1050
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1051 if (! error_state
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1052 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs"))
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1053 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1054 Cell& type = m.contents ("type");
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1055 Cell& subs = m.contents ("subs");
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1056
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1057 type_string = std::string (type.length(), '\0');
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1058
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1059 for (int k = 0; k < type.length (); k++)
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1060 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1061 std::string item = type(k).string_value ();
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1062
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1063 if (! error_state)
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1064 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1065 if (item == "{}")
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1066 type_string[k] = '{';
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1067 else if (item == "()")
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1068 type_string[k] = '(';
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1069 else if (item == ".")
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1070 type_string[k] = '.';
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1071 else
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1072 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1073 error("%s: invalid indexing type `%s'", name, item.c_str ());
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1074 return;
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1075 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1076 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1077 else
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1078 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1079 error ("%s: expecting type(%d) to be a character string",
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1080 name, k+1);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1081 return;
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1082 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1083
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1084 octave_value_list idx_item;
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1085
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1086 if (subs(k).is_string ())
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1087 idx_item(0) = subs(k);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1088 else if (subs(k).is_cell ())
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1089 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1090 Cell subs_cell = subs(k).cell_value ();
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1091
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1092 for (int n = 0; n < subs_cell.length (); n++)
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1093 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1094 if (subs_cell(n).is_string ()
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1095 && subs_cell(n).string_value () == ":")
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1096 idx_item(n) = octave_value(octave_value::magic_colon_t);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1097 else
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1098 idx_item(n) = subs_cell(n);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1099 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1100 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1101 else
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1102 {
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1103 error ("%s: expecting subs(%d) to be a character string or cell array",
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1104 name, k+1);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1105 return;
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1106 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1107
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1108 idx.push_back (idx_item);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1109 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1110 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1111 else
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1112 error ("%s: second argument must be a structure with fields `type' and `subs'", name);
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1113 }
f349847c4541 optimize cellfun (@subsref, args, {subs}, uniformoutput, true) case
Jaroslav Hajek <highegg@gmail.com>
parents: 9842
diff changeset
1114
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1115 Matrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1116 identity_matrix (octave_idx_type nr, octave_idx_type nc)
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1117 {
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1118 Matrix m (nr, nc, 0.0);
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1119
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1120 if (nr > 0 && nc > 0)
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1121 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1122 octave_idx_type n = std::min (nr, nc);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1123
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1124 for (octave_idx_type i = 0; i < n; i++)
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1125 m (i, i) = 1.0;
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1126 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1127
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1128 return m;
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1129 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1130
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1131 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1132 float_identity_matrix (octave_idx_type nr, octave_idx_type nc)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1133 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1134 FloatMatrix m (nr, nc, 0.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1135
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1136 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1137 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1138 octave_idx_type n = std::min (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1139
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1140 for (octave_idx_type i = 0; i < n; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1141 m (i, i) = 1.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1142 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1143
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1144 return m;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1145 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1146
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
1147 int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1148 octave_format (std::ostream& os, const char *fmt, ...)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1149 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1150 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1151
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1152 va_list args;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1153 va_start (args, fmt);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1154
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1155 retval = octave_vformat (os, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1156
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1157 va_end (args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1158
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1159 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1160 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1161
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
1162 int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1163 octave_vformat (std::ostream& os, const char *fmt, va_list args)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1164 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1165 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1166
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
1167 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1168
4135
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
1169 std::streambuf *sb = os.rdbuf ();
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
1170
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
1171 if (sb)
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1172 {
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1173 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1174
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1175 retval = sb->vform (fmt, args);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1176
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1177 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1178 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1179
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1180 #else
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1181
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1182 char *s = octave_vsnprintf (fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1183
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1184 if (s)
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1185 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1186 os << s;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1187
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1188 retval = strlen (s);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1189 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1190
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1191 #endif
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1192
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1193 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1194 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1195
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1196 // We manage storage. User should not free it, and its contents are
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1197 // only valid until next call to vsnprintf.
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1198
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1199 // Interrupts might happen if someone makes a call with something that
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1200 // will require a very large buffer. If we are interrupted in that
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1201 // case, we should make the buffer size smaller for the next call.
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1202
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1203 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF \
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1204 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1205 delete [] buf; \
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1206 buf = 0; \
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1207 size = initial_size; \
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
1208 octave_rethrow_exception (); \
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1209 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1210
4485
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1211 #if defined __GNUC__ && defined __va_copy
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1212 #define SAVE_ARGS(saved_args, args) __va_copy (saved_args, args)
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1213 #elif defined va_copy
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1214 #define SAVE_ARGS(saved_args, args) va_copy (saved_args, args)
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1215 #else
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1216 #define SAVE_ARGS(saved_args, args) saved_args = args
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1217 #endif
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1218
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1219 char *
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1220 octave_vsnprintf (const char *fmt, va_list args)
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1221 {
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1222 static const size_t initial_size = 100;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1223
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1224 static size_t size = initial_size;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1225
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1226 static char *buf = 0;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1227
8929
379297a149f0 utils.cc (octave_vsnprintf): avoid uninitialized variable warning
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1228 int nchars = 0;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1229
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1230 if (! buf)
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1231 buf = new char [size];
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1232
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1233 if (! buf)
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1234 return 0;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1235
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1236 while (1)
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1237 {
4485
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1238 va_list saved_args;
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1239
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1240 SAVE_ARGS (saved_args, args);
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1241
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1242 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1243
4485
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1244 nchars = octave_raw_vsnprintf (buf, size, fmt, saved_args);
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1245
bd3cfa59eb61 [project @ 2003-08-21 20:29:34 by jwe]
jwe
parents: 4482
diff changeset
1246 va_end (saved_args);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1247
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1248 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1249
10257
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1250 if (nchars > -1 && nchars < size)
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1251 break;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1252 else
10257
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1253 {
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1254 delete [] buf;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1255
10257
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1256 size = nchars + 1;;
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1257
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1258 buf = new char [size];
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1259
10257
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1260 if (! buf)
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1261 return 0;
cd550069240e assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1262 }
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1263 }
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1264
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1265 return buf;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1266 }
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1267
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1268 char *
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1269 octave_snprintf (const char *fmt, ...)
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1270 {
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1271 char *retval = 0;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1272
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1273 va_list args;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1274 va_start (args, fmt);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1275
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1276 retval = octave_vsnprintf (fmt, args);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1277
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1278 va_end (args);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1279
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1280 return retval;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1281 }
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1282
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1283 void
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1284 octave_sleep (double seconds)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1285 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1286 if (seconds > 0)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1287 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1288 double t;
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1289
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1290 unsigned int usec
4783
55975a3073be [project @ 2004-02-17 17:16:37 by jwe]
jwe
parents: 4732
diff changeset
1291 = static_cast<unsigned int> (modf (seconds, &t) * 1000000);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1292
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1293 unsigned int sec
4783
55975a3073be [project @ 2004-02-17 17:16:37 by jwe]
jwe
parents: 4732
diff changeset
1294 = (t > UINT_MAX) ? UINT_MAX : static_cast<unsigned int> (t);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1295
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1296 // Versions of these functions that accept unsigned int args are
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1297 // defined in cutils.c.
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1298 octave_sleep (sec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1299 octave_usleep (usec);
10070
897e62651c0a correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1300
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10086
diff changeset
1301 octave_quit ();
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1302 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1303 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1304
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1305 DEFUN (isindex, args, ,
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1306 "-*- texinfo -*-\n\
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1307 @deftypefn {Built-in Function} {} isindex (@var{ind}, @var{n})\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9705
diff changeset
1308 Returns true if @var{ind} is a valid index. Valid indices can be\n\
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1309 either positive integers (though possibly real data), or logical arrays.\n\
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1310 If present, @var{n} specifies the extent of the dimension to be indexed.\n\
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1311 Note that, if possible, the internal conversion result is cached so that\n\
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1312 subsequent indexing will not perform the checking again.\n\
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1313 @end deftypefn")
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1314 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1315 octave_value retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1316 int nargin = args.length ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1317 octave_idx_type n = 0;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1318
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1319 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1320 n = args(1).idx_type_value ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1321 else if (nargin != 1)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1322 print_usage ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1323
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1324 if (! error_state)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1325 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1326 unwind_protect frame;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1327 frame.protect_var (error_state);
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1328 frame.protect_var (discard_error_messages);
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1329 discard_error_messages = true;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1330
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1331 try
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1332 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1333 idx_vector idx = args(0).index_vector ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1334 if (! error_state)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1335 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1336 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1337 retval = idx.extent (n) <= n;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1338 else
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1339 retval = true;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1340 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1341 else
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1342 retval = false;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1343 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1344 catch (octave_execution_exception)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1345 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1346 retval = false;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1347 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1348 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1349
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1350 return retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1351 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1352
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1353 octave_value_list
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1354 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int),
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1355 const char *fun_name, const octave_value_list& args,
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1356 int nargout)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1357 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1358 octave_value_list new_args = args, retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1359 int nargin = args.length ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1360 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1361 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1362 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1363
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1364 const Cell *ccells = cells;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1365
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1366 octave_idx_type numel = 1;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1367 dim_vector dims (1, 1);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1368
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1369 for (int i = 0; i < nargin; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1370 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1371 octave_value arg = new_args(i);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1372 iscell[i] = arg.is_cell ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1373 if (iscell[i])
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1374 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1375 cells[i] = arg.cell_value ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1376 octave_idx_type n = ccells[i].numel ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1377 if (n == 1)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1378 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1379 iscell[i] = false;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1380 new_args(i) = ccells[i](0);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1381 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1382 else if (numel == 1)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1383 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1384 numel = n;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1385 dims = ccells[i].dims ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1386 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1387 else if (dims != ccells[i].dims ())
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1388 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1389 error ("%s: cell arguments must have matching sizes", fun_name);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1390 break;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1391 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1392 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1393 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1394
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1395 if (! error_state)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1396 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1397 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1398 rcells[i].clear (dims);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1399
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1400 for (octave_idx_type j = 0; j < numel; j++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1401 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1402 for (int i = 0; i < nargin; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1403 if (iscell[i])
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1404 new_args(i) = ccells[i](j);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1405
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10086
diff changeset
1406 octave_quit ();
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1407
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1408 const octave_value_list tmp = fun (new_args, nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1409
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1410 if (tmp.length () < nargout)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1411 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1412 error ("%s: do_simple_cellfun: internal error", fun_name);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1413 break;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1414 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1415 else
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1416 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1417 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1418 rcells[i](j) = tmp(i);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1419 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1420 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1421 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1422
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1423 if (! error_state)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1424 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1425 retval.resize (nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1426 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1427 retval(i) = rcells[i];
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1428 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1429
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1430 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1431 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1432
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1433 octave_value
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1434 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int),
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1435 const char *fun_name, const octave_value_list& args)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1436 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1437 octave_value retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1438 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1439 if (tmp.length () > 0)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1440 retval = tmp(0);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1441
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1442 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1443 }