annotate src/utils.cc @ 4264:4e2d2516da22

[project @ 2003-01-03 05:30:34 by jwe]
author jwe
date Fri, 03 Jan 2003 05:30:34 +0000
parents df5f2e433a11
children ebc2d8e4968b
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
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2492
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 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
8 under the terms of the GNU General Public License as published by the
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 later version.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 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
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1266
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
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
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
23 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
24 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
27 #include <cerrno>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
28 #include <climits>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
29 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
31 #include <fstream>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
32 #include <iostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
33 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
34
1350
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1349
diff changeset
35 #ifdef HAVE_UNISTD_H
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2285
diff changeset
36 #ifdef HAVE_SYS_TYPES_H
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include <sys/types.h>
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2285
diff changeset
38 #endif
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
39 #include <unistd.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40 #endif
367
04d377033730 [project @ 1994-02-16 08:04:52 by jwe]
jwe
parents: 341
diff changeset
41
3566
4b1a93f83264 [project @ 2000-02-03 09:19:49 by jwe]
jwe
parents: 3565
diff changeset
42 // Include setjmp.h, not csetjmp since the latter might only define
4b1a93f83264 [project @ 2000-02-03 09:19:49 by jwe]
jwe
parents: 3565
diff changeset
43 // the ANSI standard C interface.
4b1a93f83264 [project @ 2000-02-03 09:19:49 by jwe]
jwe
parents: 3565
diff changeset
44
4b1a93f83264 [project @ 2000-02-03 09:19:49 by jwe]
jwe
parents: 3565
diff changeset
45 #include <setjmp.h>
4b1a93f83264 [project @ 2000-02-03 09:19:49 by jwe]
jwe
parents: 3565
diff changeset
46
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
47 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
48 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
49 #include "file-stat.h"
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3893
diff changeset
50 #include "lo-sstream.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
51 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
52 #include "oct-env.h"
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
53 #include "pathsearch.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
54 #include "str-vec.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
55
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
56 #include "Cell.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2442
diff changeset
57 #include <defaults.h>
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
58 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "dirfns.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
60 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "gripes.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
62 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
63 #include "oct-hist.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
64 #include "oct-obj.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
65 #include "pager.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
66 #include "sysdep.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
67 #include "toplev.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
68 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
69 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
70 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
71
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
72 // Should expressions like ones (-1, 5) result in an empty matrix or
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
73 // an error? A positive value means yes. A negative value means
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
74 // yes, but print a warning message. Zero means it should be
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
75 // considered an error.
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
76 static int Vtreat_neg_dim_as_zero;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
77
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
78 // Return TRUE if S is a valid identifier.
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 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
81 valid_identifier (const char *s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
82 {
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
83 if (! s || ! (isalpha (*s) || *s == '_'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
84 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
85
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
86 while (*++s != '\0')
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
87 if (! (isalnum (*s) || *s == '_'))
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
88 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
89
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
90 return true;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
91 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
92
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
93 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
94 valid_identifier (const std::string& s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
95 {
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
96 return valid_identifier (s.c_str ());
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
97 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
98
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
99 DEFCMD (isvarname, args, ,
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
100 "@deftypefn {Built-in Function} {} isvarname (@var{name})\n\
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
101 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
102 @end deftypefn")
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 octave_value retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
105
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
106 int argc = args.length () + 1;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
107
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
108 string_vector argv = args.make_argv ("help");
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
109
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
110 if (error_state)
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
111 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
112
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
113 if (argc == 2)
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
114 retval = valid_identifier (argv[1]);
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
115 else
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
116 print_usage ("isvarname");
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
117
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
118 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
119 }
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
120
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
121 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
122 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
123 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
124 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
125 int stdlen = std.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
126 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
127
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
128 return (slen <= stdlen
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
129 && slen >= min_match_len
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
130 && (case_sens
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
131 ? (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
132 : (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
133 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
134
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
135 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
136
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
137 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
138 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
139 int min_toks_to_match, int max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
140 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
141 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
142 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
143 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
144
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
145 if (s.empty () || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
146 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
147
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
148 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
149
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
150 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
151 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
152 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
153 if (*t == '\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 t++;
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
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
158 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
159 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
160 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
161
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
162 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
163 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
164
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
165
3072
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
166 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
167 const char * const *s1 = std;
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
168 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
169
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
170 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
171 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
172
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
173 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
174 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
175 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
176 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
177 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
178 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
179
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
180 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
181 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
182
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
183 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
184 break;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
185
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
186 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
187 if (tok_count >= max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
188 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
189
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
190 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
191 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
192 s2[tok_count+1] = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
193
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
194 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
195
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
196 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
197 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
198 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
199 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
200
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
201 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
202
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
203 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
204 s2++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
205
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
206 if (! *s2)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
207 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
208 status = (toks_matched >= min_toks_to_match);
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
209 goto done;
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
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
212 if (! *s1)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
213 goto done;
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
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
216 done:
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
217
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
218 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
219 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
220
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
221 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
222 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
223
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
224 // 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
225 // 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
226
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
227 int
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
228 empty_arg (const char *name, int nr, int nc)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
229 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
230 int is_empty = 0;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
231
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
232 if (nr == 0 || nc == 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
233 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
234 int flag = Vpropagate_empty_matrices;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
235
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
236 if (flag < 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
237 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
238 gripe_empty_arg (name, 0);
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
239 is_empty = 1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
240 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
241 else if (flag == 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
242 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
243 gripe_empty_arg (name, 1);
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
244 is_empty = -1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
245 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
246 else
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
247 is_empty = 1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
248 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
249
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
250 return is_empty;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
251 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
252
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
253 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
254
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
255 std::string
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
256 search_path_for_file (const std::string& path, const string_vector& names)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
257 {
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
258 dir_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
259
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
260 return octave_env::make_absolute (p.find_first_of (names),
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
261 octave_env::getcwd ());
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
262 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
263
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
264 // 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
265
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
266 string_vector
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
267 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
268 {
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
269 dir_path p (path);
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
270
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
271 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
272
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
273 int len = sv.length ();
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
274
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
275 for (int i = 0; i < len; i++)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
276 sv[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ());
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
277
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
278 return sv;
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
279 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
280
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
281 static string_vector
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
282 make_absolute (const string_vector& sv)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
283 {
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
284 int len = sv.length ();
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
285
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
286 for (int i = 0; i < len; i++)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
287 sv[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ());
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
288
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
289 return sv;
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
290 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
291
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
292 DEFUN (file_in_loadpath, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
293 "-*- texinfo -*-\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
294 @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
295 @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
296 \n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
297 Return the absolute name name of @var{file} if it can be found in\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
298 the list of directories specified by @code{LOADPATH}.\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
299 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
300 \n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
301 If the first argument is a cell array of of strings, search each\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
302 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
303 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
304 \n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
305 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
306 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
307 name in the path. If no files are found, return an empty cell array.\n\
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
308 @end deftypefn\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
309 @seealso{file_in_path}")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
310 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
311 octave_value retval;
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
312
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
313 int nargin = args.length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
314
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
315 if (nargin == 1 || nargin == 2)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
316 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
317 string_vector names = args(0).all_strings ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
318
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
319 if (! error_state && names.length () > 0)
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 if (nargin == 1)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
322 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
323 std::string fname = octave_env::make_absolute
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
324 (Vload_path_dir_path.find_first_of (names),
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
325 octave_env::getcwd ());
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
326
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
327 if (fname.empty ())
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
328 retval = Matrix ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
329 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
330 retval = fname;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
331 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
332 else if (nargin == 2)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
333 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
334 std::string opt = args(1).string_value ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
335
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
336 if (! error_state && opt == "all")
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
337 retval = Cell (make_absolute (Vload_path_dir_path.find_all_first_of (names)));
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
338 else
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
339 error ("file_in_loadpath: invalid option");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
340 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
341 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
342 else
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
343 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
344 }
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
345 else
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
346 print_usage ("file_in_loadpath");
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
347
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
348 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
349 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
350
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
351 DEFUN (file_in_path, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
352 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
353 @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
354 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
355 Return the absolute name name of @var{file} if it can be found in\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
356 @var{path}. The value of @var{path} should be a colon-separated list of\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
357 directories in the format described for the built-in variable\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
358 @code{LOADPATH}. If no file is found, return an empty matrix.\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
359 For example,\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
360 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
361 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
362 file_in_path (LOADPATH, \"nargchk.m\")\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
363 @result{} \"@value{OCTAVEHOME}/share/octave/2.0/m/general/nargchk.m\"\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
364 @end example\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
365 \n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
366 If the second argument is a cell array of of strings, search each\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
367 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
368 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
369 \n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
370 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
371 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
372 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
373 @seealso{file_in_loadpath}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
374 @end deftypefn")
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
375 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
376 octave_value retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
377
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
378 int nargin = args.length ();
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
379
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
380 if (nargin == 2 || nargin == 3)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
381 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
382 std::string path = args(0).string_value ();
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)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
385 {
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
386 string_vector names = args(1).all_strings ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
387
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
388 if (! error_state && names.length () > 0)
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 if (nargin == 2)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
391 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
392 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
393
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
394 if (fname.empty ())
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
395 retval = Matrix ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
396 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
397 retval = fname;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
398 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
399 else if (nargin == 3)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
400 {
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
401 std::string opt = args(2).string_value ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
402
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
403 if (! error_state && opt == "all")
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
404 retval = Cell (make_absolute (search_path_for_all_files (path, names)));
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
405 else
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
406 error ("file_in_path: invalid option");
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
407 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
408 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
409 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
410 error ("file_in_path: expecting string as second argument");
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
411 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
412 else
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
413 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
414 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
415 else
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
416 print_usage ("file_in_path");
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
417
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
418 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
419 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
420
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
421 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
422 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
423 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
424 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
425
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
426 if (! suffix.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
427 nm.append (suffix);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
428
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
429 return octave_env::make_absolute (Vload_path_dir_path.find (nm),
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
430 octave_env::getcwd ());
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
431 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
432
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
433 // 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
434 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
435
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
436 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
437 fcn_file_in_path (const std::string& name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
438 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
439 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
440
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
441 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
442
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
443 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
444 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
445 if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm')
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
446 retval = file_in_path (name, "");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
447 else
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
448 retval = file_in_path (name, ".m");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
449 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
450
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
451 return retval;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
452 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
453
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
454 // See if there is an octave file in the path. If so, return the
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
455 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
456
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
457 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
458 oct_file_in_path (const std::string& name)
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
459 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
460 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
461
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
462 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
463
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
464 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
465 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
466 if (len > 2 && name [len - 4] == '.' && name [len - 3] == 'o'
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
467 && name [len - 2] == 'c' && name [len - 1] == 't')
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
468 retval = file_in_path (name, "");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
469 else
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
470 retval = file_in_path (name, ".oct");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
471 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
472
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
473 return retval;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
474 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
475
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
476 // 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
477
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
478 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
479 do_string_escapes (const std::string& s)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
480 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
481 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
482
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
483 size_t i = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
484 size_t j = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
485 size_t len = s.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
486
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
487 retval.resize (len);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
488
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
489 while (j < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
490 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
491 if (s[j] == '\\' && j+1 < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
492 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
493 switch (s[++j])
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
494 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
495 case '0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
496 retval[i] = '\0';
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
497 break;
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
498
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
499 case 'a':
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
500 retval[i] = '\a';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
501 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
502
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
503 case 'b': // backspace
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
504 retval[i] = '\b';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
505 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
506
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
507 case 'f': // formfeed
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
508 retval[i] = '\f';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
509 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
510
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
511 case 'n': // newline
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
512 retval[i] = '\n';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
513 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
514
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
515 case 'r': // carriage return
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
516 retval[i] = '\r';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
517 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
518
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
519 case 't': // horizontal tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
520 retval[i] = '\t';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
521 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
522
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
523 case 'v': // vertical tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
524 retval[i] = '\v';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
525 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
526
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
527 case '\\': // backslash
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
528 retval[i] = '\\';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
529 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
530
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
531 case '\'': // quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
532 retval[i] = '\'';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
533 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
534
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
535 case '"': // double quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
536 retval[i] = '"';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
537 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
538
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
539 default:
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
540 warning ("unrecognized escape sequence `\\%c' --\
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
541 converting to `%c'", s[j], s[j]);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
542 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
543 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
544 }
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 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
547 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
548 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
549 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
550
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
551 i++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
552 j++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
553 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
554
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3103
diff changeset
555 retval.resize (i);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
556
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
557 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
558 }
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 DEFUN (do_string_escapes, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
561 "-*- texinfo -*-\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
562 @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
563 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
564 @end deftypefn")
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
565 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
566 octave_value retval;
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 int nargin = args.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
569
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
570 if (nargin == 1)
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 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
573 retval = do_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
574 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
575 error ("do_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
576 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
577 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
578 print_usage ("do_string_escapes");
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 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
581 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
582
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
583 const char *
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
584 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
585 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
586 if (! c)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
587 return "";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
588
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
589 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
590 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
591 case '\0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
592 return "\\0";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
593
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
594 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
595 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
596
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
597 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
598 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
599
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
600 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
601 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
602
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
603 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
604 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
605
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
606 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
607 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
608
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
609 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
610 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
611
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
612 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
613 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
614
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
615 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
616 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
617
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
618 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
619 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
620
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
621 default:
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
622 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
623 static char retval[2];
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
624 retval[0] = c;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
625 retval[1] = '\0';
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
626 return retval;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
627 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
628 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
629 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
630
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
631 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
632 undo_string_escapes (const std::string& s)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
633 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
634 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
635
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
636 for (size_t i = 0; i < s.length (); i++)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
637 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
638
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
639 return retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
640 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
641
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
642 DEFUN (undo_string_escapes, args, ,
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
643 "-*- texinfo -*-\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
644 @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
645 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
646 example, the expression\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
647 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
648 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
649 bell = \"\\a\";\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
650 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
651 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
652 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
653 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
654 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
655 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
656 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
657 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
658 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
659 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
660 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
661 octave:13> undo_string_escapes (bell)\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
662 ans = \\a\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
663 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
664 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
665 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
666 replaces the unprintable alert character with its printable\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
667 representation.\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
668 @end deftypefn")
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
669 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2010
diff changeset
670 octave_value retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
671
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
672 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
673
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
674 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
675 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
676 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
677 retval = undo_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
678 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
679 error ("undo_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
680 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
681 else
1023
914348f891f0 [project @ 1995-01-11 02:53:50 by jwe]
jwe
parents: 1009
diff changeset
682 print_usage ("undo_string_escapes");
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
683
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
684 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
685 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
686
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
687 DEFUN (find_first_of_in_loadpath, args, , "")
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
688 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
689 octave_value retval;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
690
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
691 if (args.length () == 1)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
692 {
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
693 string_vector names = args(0).all_strings ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
694
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
695 if (! error_state)
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
696 retval = Vload_path_dir_path.find_all_first_of (names);
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
697 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
698 else
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
699 print_usage ("find_first_of_in_loadpath");
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
700
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
701 return retval;
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
702 }
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
703
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
704
3879
7200bfd25c97 [project @ 2002-03-08 21:00:54 by jwe]
jwe
parents: 3775
diff changeset
705 // #if 0
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
706
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
707 // Octave could use some way to access the value of ERRNO, but this is
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
708 // probably not the best interface, so don't depend on it...
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
709
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
710 DEFUN (ERRNO, args, ,
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
711 "-*- texinfo -*-\n\
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
712 @deftypefn {Built-in Function} {@var{system_error_number}} errno ()\n\
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
713 Return the current value of the system-dependent variable errno.\n\
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
714 @end deftypefn")
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
715 {
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
716 octave_value retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
717
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
718 if (args.length () == 0)
4254
df5f2e433a11 [project @ 2002-12-31 19:43:07 by jwe]
jwe
parents: 4249
diff changeset
719 retval = errno;
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
720 else
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
721 print_usage ("errno");
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
722
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
723 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
724 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
725
3879
7200bfd25c97 [project @ 2002-03-08 21:00:54 by jwe]
jwe
parents: 3775
diff changeset
726 // #endif
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
727
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
728 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
729 warn_old_style_preference (bool val, const std::string& sval)
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
730 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
731 warning
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
732 ("preference of \"%s\" is obsolete -- use numeric value of %d instead",
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
733 sval.c_str (), (val ? 1 : 0));
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
734 }
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
735
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
736 // Check the value of a string variable to see if it it's ok to do
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
737 // something.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
738 //
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
739 // return of 1 => always ok.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
740 // return of 0 => never ok.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
741 // return of -1 => ok, but give me warning (default).
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
742
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
743 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
744 check_preference (const std::string& var)
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
745 {
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
746 int pref = -1;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
747
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
748 std::string val = builtin_string_variable (var);
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
749
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
750 if (val.empty ())
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
751 {
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
752 double dval = 0;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
753 if (builtin_real_scalar_variable (var, dval))
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
754 pref = NINT (dval);
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
755 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
756 else
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
757 {
3565
4290f11c8d3b [project @ 2000-02-03 08:32:41 by jwe]
jwe
parents: 3536
diff changeset
758 if (val == "yes" || val == "true")
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
759 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
760 warn_old_style_preference (true, val);
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
761 pref = 1;
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
762 }
3565
4290f11c8d3b [project @ 2000-02-03 08:32:41 by jwe]
jwe
parents: 3536
diff changeset
763 else if (val == "never" || val == "no" || val == "false")
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
764 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
765 warn_old_style_preference (false, val);
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
766 pref = 0;
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
767 }
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
768 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
769
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
770 return pref;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
771 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
772
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
773 static void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
774 check_dimensions (int& nr, int& nc, const char *warnfor)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
775 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
776 if (nr < 0 || nc < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
777 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
778 if (Vtreat_neg_dim_as_zero)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
779 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
780 nr = (nr < 0) ? 0 : nr;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
781 nc = (nc < 0) ? 0 : nc;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
782
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
783 if (Vtreat_neg_dim_as_zero < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
784 warning ("%s: converting negative dimension to zero",
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
785 warnfor);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
786 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
787 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
788 error ("%s: can't create a matrix with negative dimensions",
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
789 warnfor);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
790 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
791 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
792
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
793 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
794 get_dimensions (const octave_value& a, const char *warn_for,
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
795 int& nr, int& nc)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
796 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
797 if (a.is_scalar_type ())
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
798 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
799 nr = nc = a.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
800 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
801 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
802 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
803 nr = a.rows ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
804 nc = a.columns ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
805
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
806 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
807 {
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
808 Array<double> v = a.vector_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
809
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
810 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
811 return;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
812
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
813 nr = NINT (v (0));
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
814 nc = NINT (v (1));
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
815 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
816 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
817 warning ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
818 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
819
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
820 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
821 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
822
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
823 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
824 get_dimensions (const octave_value& a, const octave_value& b,
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
825 const char *warn_for, int& nr, int& nc)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
826 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
827 nr = a.is_empty () ? 0 : a.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
828 nc = b.is_empty () ? 0 : b.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
829
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
830 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
831 error ("%s: expecting two scalar arguments", warn_for);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
832 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
833 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
834 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
835
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
836 extern int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
837 octave_format (std::ostream& os, const char *fmt, ...)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
838 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
839 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
840
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
841 va_list args;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
842 va_start (args, fmt);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
843
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
844 retval = octave_vformat (os, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
845
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
846 va_end (args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
847
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
848 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
849 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
850
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
851 extern int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
852 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
853 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
854 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
855
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
856 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
857
4135
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
858 std::streambuf *sb = os.rdbuf ();
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
859
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
860 if (sb)
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
861 retval = sb->vform (fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
862
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
863 #else
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
864
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
865 char *s = octave_vsnprintf (fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
866
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
867 if (s)
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
868 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
869 os << s;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
870
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
871 retval = strlen (s);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
872 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
873
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
874 #endif
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
875
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
876 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
877 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
878
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
879 void
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
880 octave_sleep (double seconds)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
881 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
882 if (seconds > 0)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
883 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
884 double t;
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
885
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
886 unsigned int usec
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
887 = static_cast <unsigned int> (modf (seconds, &t) * 1000000);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
888
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
889 unsigned int sec
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
890 = (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
891
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
892 octave_sleep (sec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
893 octave_usleep (usec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
894 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
895 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
896
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
897 static int
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
898 treat_neg_dim_as_zero (void)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
899 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
900 Vtreat_neg_dim_as_zero = check_preference ("treat_neg_dim_as_zero");
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
901
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
902 return 0;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
903 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
904
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
905 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
906 symbols_of_utils (void)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
907 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4216
diff changeset
908 DEFVAR (treat_neg_dim_as_zero, false, treat_neg_dim_as_zero,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
909 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
910 @defvr {Built-in Variable} treat_neg_dim_as_zero\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
911 If the value of @code{treat_neg_dim_as_zero} is nonzero, expressions\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
912 like\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
913 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
914 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
915 eye (-1)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
916 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
917 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
918 @noindent\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
919 produce an empty matrix (i.e., row and column dimensions are zero).\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
920 Otherwise, an error message is printed and control is returned to the\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
921 top level. The default value is 0.\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
922 @end defvr");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
923 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
924
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
925 /*
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
926 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
927 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
928 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
929 */