annotate src/utils.cc @ 4135:e865976c2084

[project @ 2002-10-30 01:32:43 by jwe]
author jwe
date Wed, 30 Oct 2002 01:32:43 +0000
parents 0435429c1050
children 62afb31c1f85
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
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
47 #include "SLStack.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
48
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
49 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
50 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
51 #include "file-stat.h"
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 3893
diff changeset
52 #include "lo-sstream.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
53 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
54 #include "oct-env.h"
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
55 #include "pathsearch.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
56 #include "str-vec.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
57
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2442
diff changeset
58 #include <defaults.h>
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
60 #include "dirfns.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
62 #include "gripes.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
63 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
64 #include "oct-hist.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
65 #include "oct-obj.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
66 #include "pager.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
67 #include "sysdep.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
68 #include "toplev.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
69 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
70 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
71 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
72
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
73 // 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
74 // 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
75 // 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
76 // considered an error.
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
77 static int Vtreat_neg_dim_as_zero;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
78
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
79 // Top level context (?)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
80 extern jmp_buf toplevel;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
81
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
82 // Return to the main command loop in octave.cc.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
83
3350
729ad2b6a052 [project @ 1999-11-12 16:18:16 by jwe]
jwe
parents: 3301
diff changeset
84 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
85 jump_to_top_level (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
86 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2926
diff changeset
87 unwind_protect::run_all ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
88
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
89 longjmp (toplevel, 1);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
90 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
91
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
92 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
93 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
94 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
95 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
96 int stdlen = std.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
97 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
98
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
99 return (slen <= stdlen
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
100 && slen >= min_match_len
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
101 && (case_sens
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
102 ? (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
103 : (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
104 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
105
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
106 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
107
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
108 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
109 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
110 int min_toks_to_match, int max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
111 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
112 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
113 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
114 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
115
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
116 if (s.empty () || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
117 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
118
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
119 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
120
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
121 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
122 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
123 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
124 if (*t == '\t')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
125 *t = ' ';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
126 t++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
127 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
128
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
129 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
130 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
131 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
132
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
133 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
134 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
135
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
136
3072
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
137 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
138 const char * const *s1 = std;
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
139 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
140
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
141 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
142 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
143
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
144 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
145 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
146 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
147 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
148 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
149 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
150
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
151 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
152 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
153
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
154 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
155 break;
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 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
158 if (tok_count >= max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
159 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
160
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
161 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
162 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
163 s2[tok_count+1] = 0;
287
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 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
166
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
167 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
168 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
169 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
170 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
171
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
172 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
173
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
174 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
175 s2++;
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 if (! *s2)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
178 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
179 status = (toks_matched >= min_toks_to_match);
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
180 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
181 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
182
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
183 if (! *s1)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
184 goto done;
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
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
187 done:
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
188
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
189 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
190 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
191
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
192 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
193 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
194
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
195 // 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
196 // 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
197
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
198 int
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
199 empty_arg (const char *name, int nr, int nc)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
200 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
201 int is_empty = 0;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
202
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
203 if (nr == 0 || nc == 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
204 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
205 int flag = Vpropagate_empty_matrices;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
206
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
207 if (flag < 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
208 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
209 gripe_empty_arg (name, 0);
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
210 is_empty = 1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
211 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
212 else if (flag == 0)
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
213 {
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
214 gripe_empty_arg (name, 1);
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
215 is_empty = -1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
216 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
217 else
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
218 is_empty = 1;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
219 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
220
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
221 return is_empty;
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
222 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
223
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
224 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
225
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
226 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
227 search_path_for_file (const std::string& path, const std::string& name)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
228 {
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
229 dir_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
230
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
231 return octave_env::make_absolute (p.find (name), octave_env::getcwd ());
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
232 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
233
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
234 DEFUN (file_in_loadpath, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
235 "-*- texinfo -*-\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
236 @deftypefn {Built-in Function} {} file_in_loadpath (@var{name})\n\
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
237 \n\
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
238 Look up @var{name} in Octave's @code{LOADPATH}.\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
239 @end deftypefn\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
240 @seealso{file_in_path}")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
241 {
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
242 octave_value_list retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
243
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
244 int argc = args.length () + 1;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
245
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
246 string_vector argv = args.make_argv ("file_in_loadpath");
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
247
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
248 if (error_state)
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
249 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
250
3225
7aae2c3636a7 [project @ 1998-12-04 23:20:12 by jwe]
jwe
parents: 3195
diff changeset
251 if (argc == 2)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
252 retval = octave_env::make_absolute (Vload_path_dir_path.find (argv[1]),
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
253 octave_env::getcwd ());
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
254 else
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
255 print_usage ("file_in_loadpath");
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
256
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
257 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
258 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
259
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
260 DEFUN (file_in_path, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
261 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
262 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
263 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
264 @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
265 directories in the format described for the built-in variable\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
266 @code{LOADPATH}.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
267 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
268 If the file cannot be found in the path, an empty matrix is returned.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
269 For example,\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
270 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
271 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
272 file_in_path (LOADPATH, \"nargchk.m\")\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
273 @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
274 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
275 @end deftypefn")
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
276 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2010
diff changeset
277 octave_value_list retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
278
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
279 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
280
1968
a2e206524aa0 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents: 1957
diff changeset
281 string_vector argv = args.make_argv ("file_in_path");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
282
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
283 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
284 return retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
285
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
286 if (argc == 3)
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
287 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
288 std::string fname = search_path_for_file (argv[1], argv[2]);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
289
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
290 if (fname.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
291 retval = Matrix ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
292 else
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
293 retval = fname;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
294 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
295 else
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
296 print_usage ("file_in_path");
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
297
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
298 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
299 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
300
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
301 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
302 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
303 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
304 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
305
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
306 if (! suffix.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
307 nm.append (suffix);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
308
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
309 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
310 octave_env::getcwd ());
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
311 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
312
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
313 // 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
314 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
315
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
316 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
317 fcn_file_in_path (const std::string& name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
318 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
319 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
320
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
321 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
322
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
323 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
324 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
325 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
326 retval = file_in_path (name, "");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
327 else
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
328 retval = file_in_path (name, ".m");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
329 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
330
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
331 return retval;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
332 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
333
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
334 // 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
335 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
336
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
337 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
338 oct_file_in_path (const std::string& name)
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
339 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
340 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
341
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
342 int len = name.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
343
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
344 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
345 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
346 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
347 && name [len - 2] == 'c' && name [len - 1] == 't')
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
348 retval = file_in_path (name, "");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
349 else
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
350 retval = file_in_path (name, ".oct");
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
351 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
352
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
353 return retval;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
354 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
355
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
356 // 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
357
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
358 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
359 do_string_escapes (const std::string& s)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
360 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
361 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
362
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
363 size_t i = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
364 size_t j = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
365 size_t len = s.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
366
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
367 retval.resize (len);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
368
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
369 while (j < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
370 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
371 if (s[j] == '\\' && j+1 < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
372 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
373 switch (s[++j])
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
374 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
375 case '0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
376 retval[i] = '\0';
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
377 break;
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
378
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
379 case 'a':
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
380 retval[i] = '\a';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
381 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
382
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
383 case 'b': // backspace
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
384 retval[i] = '\b';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
385 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
386
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
387 case 'f': // formfeed
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
388 retval[i] = '\f';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
389 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
390
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
391 case 'n': // newline
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
392 retval[i] = '\n';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
393 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
394
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
395 case 'r': // carriage return
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
396 retval[i] = '\r';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
397 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
398
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
399 case 't': // horizontal tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
400 retval[i] = '\t';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
401 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
402
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
403 case 'v': // vertical tab
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
404 retval[i] = '\v';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
405 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
406
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
407 case '\\': // backslash
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
408 retval[i] = '\\';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
409 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
410
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
411 case '\'': // quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
412 retval[i] = '\'';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
413 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
414
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
415 case '"': // double quote
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
416 retval[i] = '"';
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
417 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
418
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
419 default:
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
420 warning ("unrecognized escape sequence `\\%c' --\
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
421 converting to `%c'", s[j], s[j]);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
422 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
423 break;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
424 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
425 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
426 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
427 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
428 retval[i] = s[j];
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
429 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
430
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
431 i++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
432 j++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
433 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
434
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3103
diff changeset
435 retval.resize (i);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
436
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
437 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
438 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
439
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
440 DEFUN (do_string_escapes, args, ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
441 "-*- texinfo -*-\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
442 @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
443 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
444 @end deftypefn")
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
445 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
446 octave_value retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
447
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
448 int nargin = args.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
449
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
450 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
451 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
452 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
453 retval = do_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
454 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
455 error ("do_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
456 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
457 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
458 print_usage ("do_string_escapes");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
459
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
460 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
461 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
462
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
463 const char *
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
464 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
465 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
466 if (! c)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
467 return "";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
468
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
469 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
470 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
471 case '\0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
472 return "\\0";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
473
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
474 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
475 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
476
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
477 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
478 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
479
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
480 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
481 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
482
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
483 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
484 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
485
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
486 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
487 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
488
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
489 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
490 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
491
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
492 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
493 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
494
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
495 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
496 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
497
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
498 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
499 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
500
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
501 default:
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
502 {
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
503 static char retval[2];
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
504 retval[0] = c;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
505 retval[1] = '\0';
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
506 return retval;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
507 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
508 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
509 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
510
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
511 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
512 undo_string_escapes (const std::string& s)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
513 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
514 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
515
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
516 for (size_t i = 0; i < s.length (); i++)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
517 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
518
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
519 return retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
520 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
521
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
522 DEFUN (undo_string_escapes, args, ,
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
523 "-*- texinfo -*-\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
524 @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
525 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
526 example, the expression\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
527 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
528 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
529 bell = \"\\a\";\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
530 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
531 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
532 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
533 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
534 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
535 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
536 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
537 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
538 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
539 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
540 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
541 octave:13> undo_string_escapes (bell)\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
542 ans = \\a\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
543 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
544 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
545 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
546 replaces the unprintable alert character with its printable\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
547 representation.\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
548 @end deftypefn")
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
549 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2010
diff changeset
550 octave_value retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
551
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
552 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
553
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
554 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
555 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
556 if (args(0).is_string ())
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
557 retval = undo_string_escapes (args(0).string_value ());
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
558 else
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
559 error ("undo_string_escapes: argument must be a string");
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
560 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
561 else
1023
914348f891f0 [project @ 1995-01-11 02:53:50 by jwe]
jwe
parents: 1009
diff changeset
562 print_usage ("undo_string_escapes");
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
563
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
564 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
565 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
566
3879
7200bfd25c97 [project @ 2002-03-08 21:00:54 by jwe]
jwe
parents: 3775
diff changeset
567 // #if 0
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
568
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
569 // 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
570 // 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
571
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
572 DEFUN (ERRNO, args, ,
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
573 "-*- texinfo -*-\n\
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
574 @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
575 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
576 @end deftypefn")
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
577 {
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
578 octave_value retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
579
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
580 if (args.length () == 0)
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
581 retval = static_cast<double> (errno);
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
582 else
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
583 print_usage ("errno");
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
584
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
585 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
586 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
587
3879
7200bfd25c97 [project @ 2002-03-08 21:00:54 by jwe]
jwe
parents: 3775
diff changeset
588 // #endif
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
589
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
590 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
591 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
592 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
593 warning
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
594 ("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
595 sval.c_str (), (val ? 1 : 0));
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
596 }
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
597
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
598 // 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
599 // something.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
600 //
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
601 // return of 1 => always ok.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
602 // return of 0 => never ok.
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
603 // return of -1 => ok, but give me warning (default).
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
604
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
605 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
606 check_preference (const std::string& var)
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
607 {
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
608 int pref = -1;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
609
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
610 std::string val = builtin_string_variable (var);
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
611
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
612 if (val.empty ())
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
613 {
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
614 double dval = 0;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
615 if (builtin_real_scalar_variable (var, dval))
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
616 pref = NINT (dval);
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
617 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
618 else
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
619 {
3565
4290f11c8d3b [project @ 2000-02-03 08:32:41 by jwe]
jwe
parents: 3536
diff changeset
620 if (val == "yes" || val == "true")
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
621 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
622 warn_old_style_preference (true, val);
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
623 pref = 1;
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
624 }
3565
4290f11c8d3b [project @ 2000-02-03 08:32:41 by jwe]
jwe
parents: 3536
diff changeset
625 else if (val == "never" || val == "no" || val == "false")
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
626 {
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
627 warn_old_style_preference (false, val);
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
628 pref = 0;
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
629 }
2204
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
630 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
631
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
632 return pref;
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
633 }
a24158362f9f [project @ 1996-05-15 06:09:42 by jwe]
jwe
parents: 2180
diff changeset
634
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
635 static void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
636 check_dimensions (int& nr, int& nc, const char *warnfor)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
637 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
638 if (nr < 0 || nc < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
639 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
640 if (Vtreat_neg_dim_as_zero)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
641 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
642 nr = (nr < 0) ? 0 : nr;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
643 nc = (nc < 0) ? 0 : nc;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
644
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
645 if (Vtreat_neg_dim_as_zero < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
646 warning ("%s: converting negative dimension to zero",
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
647 warnfor);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
648 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
649 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
650 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
651 warnfor);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
652 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
653 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
654
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
655 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
656 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
657 int& nr, int& nc)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
658 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
659 if (a.is_scalar_type ())
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
660 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
661 nr = nc = a.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
662 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
663 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
664 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
665 nr = a.rows ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
666 nc = a.columns ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
667
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
668 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
669 {
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
670 Array<double> v = a.vector_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
671
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
672 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
673 return;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
674
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
675 nr = NINT (v (0));
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
676 nc = NINT (v (1));
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
677 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
678 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
679 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
680 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
681
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
682 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
683 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
684
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
685 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
686 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
687 const char *warn_for, int& nr, int& nc)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
688 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
689 nr = a.is_empty () ? 0 : a.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
690 nc = b.is_empty () ? 0 : b.nint_value ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
691
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
692 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
693 error ("%s: expecting two scalar arguments", warn_for);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
694 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
695 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
696 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
697
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
698 extern int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
699 octave_format (std::ostream& os, const char *fmt, ...)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
700 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
701 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
702
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
703 va_list args;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
704 va_start (args, fmt);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
705
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
706 retval = octave_vformat (os, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
707
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
708 va_end (args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
709
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
710 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
711 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
712
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
713 extern int
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
714 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
715 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
716 int retval = -1;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
717
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
718 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
719
4135
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
720 std::streambuf *sb = os.rdbuf ();
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
721
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
722 if (sb)
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
723 retval = sb->vform (fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
724
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
725 #else
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
726
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
727 char *s = octave_vsnprintf (fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
728
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
729 if (s)
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
730 {
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
731 os << s;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
732
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
733 retval = strlen (s);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
734 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
735
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
736 #endif
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
737
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
738 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
739 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
740
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
741 void
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
742 octave_sleep (double seconds)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
743 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
744 if (seconds > 0)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
745 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
746 double t;
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
747
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
748 unsigned int usec
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
749 = static_cast <unsigned int> (modf (seconds, &t) * 1000000);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
750
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
751 unsigned int sec
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
752 = (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
753
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
754 octave_sleep (sec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
755 octave_usleep (usec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
756 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
757 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
758
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
759 static int
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
760 treat_neg_dim_as_zero (void)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
761 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
762 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
763
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
764 return 0;
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
765 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
766
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
767 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
768 symbols_of_utils (void)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
769 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
770 DEFVAR (treat_neg_dim_as_zero, 0.0, treat_neg_dim_as_zero,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
771 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
772 @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
773 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
774 like\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
775 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
776 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
777 eye (-1)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
778 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
779 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
780 @noindent\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
781 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
782 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
783 top level. The default value is 0.\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
784 @end defvr");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
785 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
786
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
787 /*
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
788 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
789 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
790 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
791 */