annotate src/utils.cc @ 1346:9e41dbb74bca

[project @ 1995-09-05 06:37:49 by jwe]
author jwe
date Tue, 05 Sep 1995 06:41:09 +0000
parents 1ddfcf6b19a0
children d1e6997f0788
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 // utils.cc -*- C++ -*-
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3
1009
dfe01093f657 [project @ 1995-01-04 04:05:12 by jwe]
jwe
parents: 958
diff changeset
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 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
11 later version.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
19 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
20 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
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
25 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
28 #include <climits>
1345
1ddfcf6b19a0 [project @ 1995-09-05 06:29:02 by jwe]
jwe
parents: 1343
diff changeset
29 #include <csetjmp>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
30 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
31
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
32 #include <sys/types.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33 #ifdef HAVE_UNISTD_H
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
34 #include <unistd.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
35 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #include <sys/param.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include <iostream.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
38 #include <strstream.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
39 #include <fstream.h>
367
04d377033730 [project @ 1994-02-16 08:04:52 by jwe]
jwe
parents: 341
diff changeset
40
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
41 #include <Complex.h>
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
42
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
43 extern "C"
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
44 {
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
45 #ifndef HAVE_STRNCASECMP
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
46 extern int strncasecmp (const char*, const char*, size_t);
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
47 #endif
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
48
138
b3b67829e001 [project @ 1993-09-29 21:24:21 by jwe]
jwe
parents: 106
diff changeset
49 #if defined (HAVE_TERMIOS_H)
b3b67829e001 [project @ 1993-09-29 21:24:21 by jwe]
jwe
parents: 106
diff changeset
50 #include <termios.h>
b3b67829e001 [project @ 1993-09-29 21:24:21 by jwe]
jwe
parents: 106
diff changeset
51 #elif defined (HAVE_TERMIO_H)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
52 #include <termio.h>
138
b3b67829e001 [project @ 1993-09-29 21:24:21 by jwe]
jwe
parents: 106
diff changeset
53 #elif defined (HAVE_SGTTY_H)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54 #include <sgtty.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
55 #else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
56 LOSE! LOSE!
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
57 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
58
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
59 #include <readline/tilde.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
60 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
61
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
62 // This mess suggested by the autoconf manual.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
63 // unistd.h defines _POSIX_VERSION on POSIX.1 systems.
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
64 #if defined (HAVE_DIRENT_H) || defined (_POSIX_VERSION)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
65 #include <dirent.h>
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
66 #define NLENGTH(dirent) (strlen((dirent)->d_name))
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
67 #else
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
68 #define dirent direct
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
69 #define NLENGTH(dirent) ((dirent)->d_namlen)
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
70 #if defined (HAVE_SYS_NDIR_H)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
71 #include <sys/ndir.h>
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
72 #endif
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
73 #if defined (HAVE_SYS_DIR_H)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
74 #include <sys/dir.h>
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
75 #endif
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
76 #if defined (HAVE_NDIR_H)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
77 #include <ndir.h>
958
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
78 #endif
41f8acf06573 [project @ 1994-12-05 18:29:46 by jwe]
jwe
parents: 912
diff changeset
79 #endif
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
80
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
81 #include "SLStack.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
82
1155
22741d6ed818 [project @ 1995-02-27 04:26:21 by jwe]
jwe
parents: 1104
diff changeset
83 #include "pathsearch.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
84 #include "procstream.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
85 #include "user-prefs.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
86 #include "variables.h"
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
87 #include "dirfns.h"
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
88 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
89 #include "error.h"
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
90 #include "help.h"
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
91 #include "gripes.h"
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
92 #include "pager.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
93 #include "utils.h"
175
bff84a41f944 [project @ 1993-10-22 19:03:52 by jwe]
jwe
parents: 169
diff changeset
94 #include "input.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
95 #include "octave.h"
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
96 #include "oct-obj.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
97 #include "mappers.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
98 #include "tree-const.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
99 #include "unwind-prot.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
100 #include "octave-hist.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
101
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
102 // Top level context (?)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
103 extern jmp_buf toplevel;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
104
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
105 // Save a string.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
106
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
107 char *
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
108 strsave (const char *s)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
109 {
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
110 if (! s)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
111 return 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
112
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
113 int len = strlen (s);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
114 char *tmp = new char [len+1];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
115 tmp = strcpy (tmp, s);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
116 return tmp;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
117 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
118
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
119 // Concatenate two strings.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
120
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
121 char *
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
122 strconcat (const char *s, const char *t)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
123 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
124 int len = strlen (s) + strlen (t);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
125 char *tmp = new char [len+1];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
126 strcpy (tmp, s);
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
127 strcat (tmp, t);
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
128 return tmp;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
129 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
130
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
131 // Throw away input until a given character is read.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
132
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
133 void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
134 discard_until (istream& stream, char character)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
135 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
136 int c;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
137 for (;;)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
138 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
139 stream >> c;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
140 if (c == EOF || c == character)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
141 break;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
142 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
143 if (c != EOF)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
144 stream.putback ((char) c);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
145 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
146
607
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
147 #if 0
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
148
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
149 // XXX UNTESTED XXX
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
150
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
151 // Read input until a given character is read. Returns characters
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
152 // read in a new string that must be freed by the caller.
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
153
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
154 char *
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
155 read_until (istream& stream, char character)
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
156 {
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
157 int grow_size = 8;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
158 int limit = grow_size;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
159 char *buf = new char [limit];
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
160 char *bp = buf;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
161
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
162 get_more:
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
163 is.getline (bp, limit, character);
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
164
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
165 if (is.gcount () == 0)
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
166 {
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
167 delete [] buf;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
168 return 0;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
169 }
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
170
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
171 if (is.gcount () == limit && buf[limit-1] != '\0')
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
172 {
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
173 char *tmp = new char [limit + grow_size];
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
174 strcpy (tmp, buf);
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
175 delete [] buf;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
176 buf = tmp;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
177 bp = tmp + limit - 1;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
178 limit += grow_size;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
179 grow_size *= 2;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
180 goto get_more;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
181 }
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
182
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
183 return buf;
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
184 }
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
185 #endif
ae3b8b2924a0 [project @ 1994-08-13 20:11:17 by jwe]
jwe
parents: 581
diff changeset
186
661
9ccf86647203 [project @ 1994-08-30 04:41:56 by jwe]
jwe
parents: 643
diff changeset
187 // Get a temporary file name.
643
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
188
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
189 char *
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
190 octave_tmp_file_name (void)
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
191 {
662
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
192 static char *retval = 0;
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
193
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
194 if (retval)
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
195 free (retval);
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
196
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
197 retval = tempnam (0, "oct-");
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
198
661
9ccf86647203 [project @ 1994-08-30 04:41:56 by jwe]
jwe
parents: 643
diff changeset
199 if (! retval)
9ccf86647203 [project @ 1994-08-30 04:41:56 by jwe]
jwe
parents: 643
diff changeset
200 error ("can't open temporary file!");
662
fdf4ce2d855e [project @ 1994-08-30 04:49:31 by jwe]
jwe
parents: 661
diff changeset
201
661
9ccf86647203 [project @ 1994-08-30 04:41:56 by jwe]
jwe
parents: 643
diff changeset
202 return retval;
643
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
203 }
cf16ec9a2428 [project @ 1994-08-24 04:38:14 by jwe]
jwe
parents: 636
diff changeset
204
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
205 DEFUN ("octave_tmp_file_name", Foctave_tmp_file_name,
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
206 Soctave_tmp_file_name, 0, 1,
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
207 "octave_tmp_file_name ()")
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
208 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
209 tree_constant retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
210
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
211 if (args.length () == 0)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
212 retval = octave_tmp_file_name ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
213 else
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
214 print_usage ("octave_tmp_file_name");
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
215
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
216 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
217 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
218
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
219 char **
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
220 pathstring_to_vector (char *pathstring)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
221 {
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
222 static char **path = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
223
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
224 if (pathstring)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
225 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
226 int nelem = 0;
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
227 char *tmp_path = strsave (pathstring);
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
228 if (*tmp_path != '\0')
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
229 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
230 nelem++;
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
231 char *ptr = tmp_path;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
232 while (*ptr != '\0')
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
233 {
1104
3535aa4d38c6 [project @ 1995-02-14 22:12:34 by jwe]
jwe
parents: 1086
diff changeset
234 if (*ptr == SEPCHAR)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
235 nelem++;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
236 ptr++;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
237 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
238 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
239
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
240 char **foo = path;
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
241 while (foo && *foo)
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
242 delete [] *foo++;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
243 delete [] path;
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
244
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
245 path = new char * [nelem+1];
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
246 path[nelem] = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
247
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
248 int i = 0;
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
249 char *ptr = tmp_path;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
250 while (i < nelem)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
251 {
1104
3535aa4d38c6 [project @ 1995-02-14 22:12:34 by jwe]
jwe
parents: 1086
diff changeset
252 char *end = strchr (ptr, SEPCHAR);
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
253 if (end)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
254 *end = '\0';
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
255 char *result = tilde_expand (ptr);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
256 path[i] = strsave (result);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
257 free (result);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
258 ptr = end + 1;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
259 i++;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
260 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
261
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
262 delete [] tmp_path;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
263 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
264
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
265 return path;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
266 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
267
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
268 // Return to the main command loop in octave.cc.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
269
189
de0e58f9b064 [project @ 1993-10-28 08:52:15 by jwe]
jwe
parents: 186
diff changeset
270 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
271 jump_to_top_level (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
272 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
273 run_all_unwind_protects ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
274
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
275 longjmp (toplevel, 1);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
276 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
277
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
278 int
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
279 almost_match (const char *std, const char *s, int min_match_len,
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
280 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
281 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
282 int stdlen = strlen (std);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
283 int slen = strlen (s);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
284
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
285 return (slen <= stdlen
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
286 && slen >= min_match_len
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
287 && (case_sens
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
288 ? (strncmp (std, s, slen) == 0)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
289 : (strncasecmp (std, s, slen) == 0)));
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
290 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
291
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
292 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
293
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
294 int
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
295 keyword_almost_match (const char **std, int *min_len, const char *s,
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
296 int min_toks_to_match, int max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
297 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
298 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
299 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
300 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
301
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
302 if (! s || *s == '\0' || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
303 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
304
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
305 char *kw = strsave (s);
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
306
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
307 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
308 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
309 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
310 if (*t == '\t')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
311 *t = ' ';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
312 t++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
313 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
314
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
315 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
316 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
317 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
318
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
319 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
320 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
321
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
322
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
323 char **to_match = new char * [max_toks + 1];
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
324 const char **s1 = std;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
325 char **s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
326
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
327 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
328 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
329
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
330 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
331 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
332 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
333 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
334 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
335 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
336
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
337 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
338 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
339
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
340 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
341 break;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
342
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
343 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
344 if (tok_count >= max_toks)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
345 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
346
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
347 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
348 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
349 s2[tok_count+1] = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
350
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
351 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
352
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
353 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
354 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
355 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
356 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
357
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
358 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
359
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
360 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
361 s2++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
362
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
363 if (! *s2)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
364 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
365 status = (toks_matched >= min_toks_to_match);
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
366 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
367 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
368
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
369 if (! *s1)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
370 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
371 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
372
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
373 done:
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
374
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
375 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
376 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
377
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
378 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
379 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
380
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
381 char **
338
82d30a23c979 [project @ 1994-02-07 07:09:33 by jwe]
jwe
parents: 320
diff changeset
382 get_fcn_file_names (int& num, const char *dir, int no_suffix)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
383 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
384 static int num_max = 256;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
385 char **retval = new char * [num_max];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
386 int i = 0;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
387
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
388 DIR *dirp = opendir (dir);
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
389 if (dirp)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
390 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
391 struct dirent *entry;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
392 while ((entry = readdir (dirp)) != 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
393 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
394 int len = NLENGTH (entry);
826
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
395 #ifdef WITH_DLD
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
396 if ((len > 2
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
397 && entry->d_name[len-2] == '.'
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
398 && entry->d_name[len-1] == 'm')
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
399 || (len > 4
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
400 && entry->d_name[len-4] == '.'
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
401 && entry->d_name[len-3] == 'o'
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
402 && entry->d_name[len-2] == 'c'
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
403 && entry->d_name[len-1] == 't'))
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
404 #else
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
405 if (len > 2
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
406 && entry->d_name[len-2] == '.'
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
407 && entry->d_name[len-1] == 'm')
826
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
408 #endif
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
409 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
410 retval[i] = strsave (entry->d_name);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
411 if (no_suffix)
826
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
412 {
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
413 if (retval[i][len-1] == 'm')
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
414 retval[i][len-2] = '\0';
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
415 else
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
416 retval[i][len-4] = '\0';
6ed384cf51ec [project @ 1994-10-17 02:48:12 by jwe]
jwe
parents: 801
diff changeset
417 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
418
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
419 i++;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
420
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
421 if (i == num_max - 1)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
422 {
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
423 // Reallocate the array. Only copy pointers, not the strings they
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
424 // point to, then only delete the original array of pointers, and not
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
425 // the strings they point to.
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
426
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
427 num_max += 256;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
428 char **tmp = new char * [num_max];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
429 for (int j = 0; j < i; j++)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
430 tmp[j] = retval[j];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
431
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
432 delete [] retval;
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
433
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
434 retval = tmp;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
435 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
436 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
437 }
106
38f924cd2055 [project @ 1993-09-13 19:29:26 by jwe]
jwe
parents: 102
diff changeset
438 closedir (dirp);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
439 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
440
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
441 retval[i] = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
442 num = i;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
443
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
444 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
445 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
446
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
447 char **
338
82d30a23c979 [project @ 1994-02-07 07:09:33 by jwe]
jwe
parents: 320
diff changeset
448 get_fcn_file_names (int& num, int no_suffix)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
449 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
450 static int num_max = 1024;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
451 char **retval = new char * [num_max];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
452 int i = 0;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
453
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
454 char *path_elt = kpse_path_element (user_pref.loadpath);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
455
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
456 while (path_elt)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
457 {
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
458 str_llist_type *elt_dirs = kpse_element_dirs (path_elt);
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
459
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
460 str_llist_elt_type *dir;
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
461 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
462 {
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
463 char *elt_dir = STR_LLIST (*dir);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
464
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
465 if (elt_dir)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
466 {
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
467 int tmp_num;
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
468 char **names = get_fcn_file_names (tmp_num, elt_dir, no_suffix);
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
469
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
470 if (i + tmp_num >= num_max - 1)
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
471 {
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
472 // Reallocate the array. Only copy pointers, not the strings they
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
473 // point to, then only delete the original array of pointers, and not
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
474 // the strings they point to.
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
475
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
476 num_max += 1024;
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
477 char **tmp = new char * [num_max];
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
478 for (int j = 0; j < i; j++)
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
479 tmp[j] = retval[j];
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
480
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
481 delete [] retval;
244
d66cc97f77a9 [project @ 1993-12-03 01:30:19 by jwe]
jwe
parents: 240
diff changeset
482
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
483 retval = tmp;
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
484 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
485
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
486 int k = 0;
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
487 while (k < tmp_num)
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
488 retval[i++] = names[k++];
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
489 }
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
490 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
491
679
93c63deed7aa [project @ 1994-09-09 13:50:40 by jwe]
jwe
parents: 673
diff changeset
492 path_elt = kpse_path_element (0);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
493 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
494
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
495 retval[i] = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
496 num = i;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
497
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
498 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
499 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
500
1086
75fc98220389 [project @ 1995-01-31 04:17:15 by jwe]
jwe
parents: 1023
diff changeset
501 // Convert X to the nearest integer value. Should not pass NaN to
75fc98220389 [project @ 1995-01-31 04:17:15 by jwe]
jwe
parents: 1023
diff changeset
502 // this function.
75fc98220389 [project @ 1995-01-31 04:17:15 by jwe]
jwe
parents: 1023
diff changeset
503
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
504 int
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
505 NINT (double x)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
506 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
507 if (x > INT_MAX)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
508 return INT_MAX;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
509 else if (x < INT_MIN)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
510 return INT_MIN;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
511 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
512 return (x > 0) ? ((int) (x + 0.5)) : ((int) (x - 0.5));
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
513 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
514
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
515 double
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
516 D_NINT (double x)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
517 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
518 if (xisinf (x) || xisnan (x))
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
519 return x;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
520 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
521 return floor (x + 0.5);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
522 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
523
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
524 // XXX FIXME XXX -- put these in some file, and make them extern.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
525
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
526 static int
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
527 all_strings (const Octave_object& args)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
528 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
529 int n = args.length ();
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 707
diff changeset
530 for (int i = 0; i < n; i++)
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 607
diff changeset
531 if (! args(i).is_string ())
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
532 return 0;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
533 return 1;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
534 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
535
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
536 char **
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
537 make_argv (const Octave_object& args, const char *fcn_name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
538 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
539 char **argv = 0;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
540 if (all_strings (args))
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
541 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
542 int n = args.length ();
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
543 argv = new char * [n + 1];
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
544 argv[0] = strsave (fcn_name);
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 707
diff changeset
545 for (int i = 0; i < n; i++)
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 707
diff changeset
546 argv[i+1] = strsave (args(i).string_value ());
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
547 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
548 else
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
549 error ("%s: expecting all arguments to be strings", fcn_name);
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
550
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
551 return argv;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
552 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
553
719
02814aea28c8 [project @ 1994-09-21 15:01:30 by jwe]
jwe
parents: 712
diff changeset
554 // Return non-zero if either NR or NC is zero. Return -1 if this
02814aea28c8 [project @ 1994-09-21 15:01:30 by jwe]
jwe
parents: 712
diff changeset
555 // should be considered fatal; return 1 if this is ok.
02814aea28c8 [project @ 1994-09-21 15:01:30 by jwe]
jwe
parents: 712
diff changeset
556
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
557 int
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
558 empty_arg (const char *name, int nr, int nc)
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
559 {
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
560 int is_empty = 0;
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
561
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
562 if (nr == 0 || nc == 0)
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
563 {
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
564 int flag = user_pref.propagate_empty_matrices;
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
565
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
566 if (flag < 0)
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
567 {
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
568 gripe_empty_arg (name, 0);
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
569 is_empty = 1;
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
570 }
673
8af8709c349e [project @ 1994-09-07 22:58:35 by jwe]
jwe
parents: 662
diff changeset
571 else if (flag == 0)
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
572 {
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
573 gripe_empty_arg (name, 1);
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
574 is_empty = -1;
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
575 }
719
02814aea28c8 [project @ 1994-09-21 15:01:30 by jwe]
jwe
parents: 712
diff changeset
576 else
02814aea28c8 [project @ 1994-09-21 15:01:30 by jwe]
jwe
parents: 712
diff changeset
577 is_empty = 1;
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
578 }
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
579
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
580 return is_empty;
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
581 }
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
582
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
583 // Format a list in neat columns. Mostly stolen from GNU ls. This
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
584 // should maybe be in utils.cc.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
585
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
586 ostrstream&
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
587 list_in_columns (ostrstream& os, char **list)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
588 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
589 // Compute the maximum name length.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
590
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
591 int max_name_length = 0;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
592 int total_names = 0;
1321
64819a909ed7 [project @ 1995-08-22 05:39:43 by jwe]
jwe
parents: 1315
diff changeset
593 char **names = 0;
64819a909ed7 [project @ 1995-08-22 05:39:43 by jwe]
jwe
parents: 1315
diff changeset
594 for (names = list; *names; names++)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
595 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
596 total_names++;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
597 int name_length = strlen (*names);
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
598 if (name_length > max_name_length)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
599 max_name_length = name_length;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
600 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
601
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
602 // Allow at least two spaces between names.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
603
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
604 max_name_length += 2;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
605
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
606 // Calculate the maximum number of columns that will fit.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
607
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
608 int line_length = terminal_columns ();
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
609 int cols = line_length / max_name_length;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
610 if (cols == 0)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
611 cols = 1;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
612
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
613 // Calculate the number of rows that will be in each column except
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
614 // possibly for a short column on the right.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
615
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
616 int rows = total_names / cols + (total_names % cols != 0);
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
617
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
618 // Recalculate columns based on rows.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
619
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
620 cols = total_names / rows + (total_names % rows != 0);
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
621
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
622 names = list;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
623 int count;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
624 for (int row = 0; row < rows; row++)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
625 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
626 count = row;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
627 int pos = 0;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
628
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
629 // Print the next row.
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
630
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
631 while (1)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
632 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
633 os << *(names + count);
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
634 int name_length = strlen (*(names + count));
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
635
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
636 count += rows;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
637 if (count >= total_names)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
638 break;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
639
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
640 int spaces_to_pad = max_name_length - name_length;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
641 for (int i = 0; i < spaces_to_pad; i++)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
642 os << " ";
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
643 pos += max_name_length;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
644 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
645 os << "\n";
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
646 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
647
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
648 return os;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
649 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
650
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
651 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
652
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
653 char *
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
654 search_path_for_file (const char *path, const char *name)
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
655 {
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
656 char *retval = 0;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
657
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
658 char *tmp = kpse_path_search (path, name, kpathsea_true);
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
659
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
660 if (tmp)
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
661 {
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
662 retval = make_absolute (tmp, the_current_working_directory);
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
663 free (tmp);
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
664 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
665
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
666 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
667 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
668
912
33ae9f667c6d [project @ 1994-11-10 15:53:33 by jwe]
jwe
parents: 908
diff changeset
669 DEFUN ("file_in_path", Ffile_in_path, Sfile_in_path, 3, 1,
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
670 "file_in_path (PATH, NAME)")
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
671 {
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
672 Octave_object retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
673
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
674 DEFINE_ARGV("file_in_path");
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
675
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
676 if (argc == 3)
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
677 {
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
678 char *fname = search_path_for_file (argv[1], argv[2]);
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
679
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
680 if (fname)
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
681 retval = fname;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
682 else
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
683 retval = Matrix ();
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
684 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
685 else
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
686 print_usage ("file_in_path");
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
687
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
688 DELETE_ARGV;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
689
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
690 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
691 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
692
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
693
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
694 char *
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
695 file_in_path (const char *name, const char *suffix)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
696 {
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
697 char *retval = 0;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
698
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
699 char *nm = 0;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
700
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
701 if (suffix)
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
702 nm = strconcat (name, suffix);
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
703 else
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1215
diff changeset
704 nm = strsave (name);
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
705
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
706 if (! the_current_working_directory)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
707 get_working_directory ("file_in_path");
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
708
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
709 retval = search_path_for_file (user_pref.loadpath, nm);
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
710
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
711 delete [] nm;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
712
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
713 return retval;
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
714 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
715
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
716 // 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
717 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
718
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
719 char *
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
720 fcn_file_in_path (const char *name)
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
721 {
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
722 if (name)
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
723 {
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
724 int len = strlen (name);
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
725
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
726 if (name [len - 2] == '.' && name [len - 1] == 'm')
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
727 return file_in_path (name, "");
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
728 else
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
729 return file_in_path (name, ".m");
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
730 }
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
731 else
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
732 return 0;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
733 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
734
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
735 // 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
736 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
737
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
738 char *
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
739 oct_file_in_path (const char *name)
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
740 {
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
741 if (name)
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
742 {
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
743 int len = strlen (name);
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
744
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
745 if (name [len - 4] == '.' && name [len - 3] == 'o'
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
746 && name [len - 2] == 'c' && name [len - 1] == 't')
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
747 return file_in_path (name, "");
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
748 else
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
749 return file_in_path (name, ".oct");
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
750 }
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
751 else
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
752 return 0;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
753 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
754
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
755 char *
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
756 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
757 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
758 static char retval[2];
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
759 retval[1] = '\0';
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
760
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
761 if (! c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
762 return 0;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
763
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
764 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
765 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
766 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
767 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
768
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
769 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
770 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
771
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
772 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
773 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
774
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
775 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
776 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
777
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
778 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
779 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
780
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
781 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
782 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
783
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
784 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
785 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
786
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
787 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
788 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
789
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
790 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
791 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
792
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
793 default:
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
794 retval[0] = c;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
795 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
796 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
797 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
798
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
799 char *
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
800 undo_string_escapes (char *s)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
801 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
802 ostrstream buf;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
803
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
804 char *t;
1215
c56c0565afd5 [project @ 1995-04-06 05:12:20 by jwe]
jwe
parents: 1192
diff changeset
805 while ((t = undo_string_escape (*s++)))
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
806 buf << t;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
807 buf << ends;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
808
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
809 return buf.str ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
810 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
811
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
812 DEFUN ("undo_string_escapes", Fundo_string_escapes,
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
813 Sundo_string_escapes, 1, 1,
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
814 "undo_string_escapes (STRING)")
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
815 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
816 tree_constant retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
817
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
818 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
819
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
820 if (nargin == 1 && args(0).is_string ())
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
821 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
822 char *str = undo_string_escapes (args(0).string_value ());
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
823 retval = str;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
824 delete [] str;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
825 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
826 else
1023
914348f891f0 [project @ 1995-01-11 02:53:50 by jwe]
jwe
parents: 1009
diff changeset
827 print_usage ("undo_string_escapes");
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
828
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
829 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
830 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
831
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
832 /*
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
833 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
834 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
835 ;;; page-delimiter: "^/\\*" ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
836 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
837 */