1
|
1 // builtins.cc -*- C++ -*- |
|
2 /* |
|
3 |
275
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
181
|
29 #include <strstream.h> |
1
|
30 #include <math.h> |
|
31 #include <float.h> |
|
32 |
|
33 #include "tree-const.h" |
|
34 #include "t-builtins.h" |
|
35 #include "g-builtins.h" |
|
36 #include "builtins.h" |
|
37 #include "octave.h" |
|
38 #include "utils.h" |
|
39 #include "tree.h" |
164
|
40 #include "help.h" |
181
|
41 #include "pager.h" |
444
|
42 #include "sysdep.h" |
1
|
43 #include "mappers.h" |
290
|
44 #include "variables.h" |
1
|
45 #include "user-prefs.h" |
290
|
46 #include "missing-math.h" |
1
|
47 |
|
48 // NOTE: nargin == 1 means that the function takes no arguments (just |
|
49 // like C, the first argument is (or should be, anyway) the function |
|
50 // name). Also, -1 is shorthand for infinity. |
|
51 |
|
52 // The following initializations may eventually need to be reworked |
|
53 // like the builtin functions in bash were around version 1.12... |
|
54 |
|
55 static builtin_mapper_functions mapper_functions[] = |
|
56 { |
330
|
57 { "abs", 0, 0.0, 0.0, fabs, abs, NULL, |
181
|
58 "abs (X): compute abs (X) for each element of X", }, |
1
|
59 |
330
|
60 { "acos", 1, -1.0, 1.0, acos, NULL, acos, |
181
|
61 "acos (X): compute acos (X) for each element of X", }, |
1
|
62 |
330
|
63 { "acosh", 1, 1.0, DBL_MAX, acosh, NULL, acosh, |
181
|
64 "acosh (X): compute acosh (X) for each element of X", }, |
1
|
65 |
330
|
66 { "angle", 0, 0.0, 0.0, arg, arg, NULL, |
181
|
67 "angle (X): compute arg (X) for each element of X", }, |
1
|
68 |
330
|
69 { "arg", 0, 0.0, 0.0, arg, arg, NULL, |
181
|
70 "arg (X): compute arg (X) for each element of X", }, |
1
|
71 |
330
|
72 { "asin", 1, -1.0, 1.0, asin, NULL, asin, |
181
|
73 "asin (X): compute asin (X) for each element of X", }, |
1
|
74 |
330
|
75 { "asinh", 0, 0.0, 0.0, asinh, NULL, asinh, |
181
|
76 "asinh (X): compute asinh (X) for each element of X", }, |
1
|
77 |
330
|
78 { "atan", 0, 0.0, 0.0, atan, NULL, atan, |
181
|
79 "atan (X): compute atan (X) for each element of X", }, |
1
|
80 |
330
|
81 { "atanh", 1, -1.0, 1.0, atanh, NULL, atanh, |
181
|
82 "atanh (X): compute atanh (X) for each element of X", }, |
1
|
83 |
330
|
84 { "ceil", 0, 0.0, 0.0, ceil, NULL, ceil, |
181
|
85 "ceil (X): round elements of X toward +Inf", }, |
1
|
86 |
330
|
87 { "conj", 0, 0.0, 0.0, conj, NULL, conj, |
181
|
88 "conj (X): compute complex conjugate for each element of X", }, |
1
|
89 |
330
|
90 { "cos", 0, 0.0, 0.0, cos, NULL, cos, |
181
|
91 "cos (X): compute cos (X) for each element of X", }, |
1
|
92 |
330
|
93 { "cosh", 0, 0.0, 0.0, cosh, NULL, cosh, |
181
|
94 "cosh (X): compute cosh (X) for each element of X", }, |
1
|
95 |
330
|
96 { "exp", 0, 0.0, 0.0, exp, NULL, exp, |
181
|
97 "exp (X): compute exp (X) for each element of X", }, |
1
|
98 |
330
|
99 { "finite", 0, 0.0, 0.0, xfinite, xfinite, NULL, |
181
|
100 "finite (X): return 1 for finite elements of X", }, |
1
|
101 |
330
|
102 { "fix", 0, 0.0, 0.0, fix, NULL, fix, |
181
|
103 "fix (X): round elements of X toward zero", }, |
1
|
104 |
330
|
105 { "floor", 0, 0.0, 0.0, floor, NULL, floor, |
181
|
106 "floor (X): round elements of X toward -Inf", }, |
1
|
107 |
330
|
108 { "isinf", 0, 0.0, 0.0, xisinf, xisinf, NULL, |
181
|
109 "isinf (X): return 1 for elements of X infinite", }, |
1
|
110 |
330
|
111 { "imag", 0, 0.0, 0.0, imag, imag, NULL, |
181
|
112 "imag (X): return imaginary part for each elements of X", }, |
1
|
113 |
|
114 #ifdef HAVE_ISNAN |
330
|
115 { "isnan", 0, 0.0, 0.0, xisnan, xisnan, NULL, |
181
|
116 "isnan (X): return 1 where elements of X are NaNs", }, |
1
|
117 #endif |
|
118 |
330
|
119 { "log", 1, 0.0, DBL_MAX, log, NULL, log, |
181
|
120 "log (X): compute log (X) for each element of X", }, |
1
|
121 |
330
|
122 { "log10", 1, 0.0, DBL_MAX, log10, NULL, log10, |
181
|
123 "log10 (X): compute log10 (X) for each element of X", }, |
1
|
124 |
330
|
125 { "real", 0, 0.0, 0.0, real, real, NULL, |
181
|
126 "real (X): return real part for each element of X", }, |
1
|
127 |
330
|
128 { "round", 0, 0.0, 0.0, round, NULL, round, |
181
|
129 "round (X): round elements of X to nearest integer", }, |
1
|
130 |
330
|
131 { "sign", 0, 0.0, 0.0, signum, NULL, signum, |
181
|
132 "sign (X): apply signum function to elements of X", }, |
1
|
133 |
330
|
134 { "sin", 0, 0.0, 0.0, sin, NULL, sin, |
181
|
135 "sin (X): compute sin (X) for each element of X", }, |
1
|
136 |
330
|
137 { "sinh", 0, 0.0, 0.0, sinh, NULL, sinh, |
181
|
138 "sinh (X): compute sinh (X) for each element of X", }, |
1
|
139 |
330
|
140 { "sqrt", 1, 0.0, DBL_MAX, sqrt, NULL, sqrt, |
181
|
141 "sqrt (X): compute sqrt (X) for each element of X", }, |
1
|
142 |
330
|
143 { "tan", 0, 0.0, 0.0, tan, NULL, tan, |
181
|
144 "tan (X): compute tan (X) for each element of X", }, |
1
|
145 |
330
|
146 { "tanh", 0, 0.0, 0.0, tanh, NULL, tanh, |
181
|
147 "tanh (X): compute tanh (X) for each element of X", }, |
1
|
148 |
330
|
149 { NULL, -1, 0.0, 0.0, NULL, NULL, NULL, NULL, }, |
1
|
150 }; |
|
151 |
|
152 static builtin_text_functions text_functions[] = |
|
153 { |
|
154 { "casesen", 2, builtin_casesen, |
181
|
155 "casesen [on|off]", }, |
1
|
156 |
|
157 { "cd", 2, builtin_cd, |
181
|
158 "cd [dir]\n\n\ |
|
159 change current working directory\n\ |
|
160 if no arguments are given, the current directory is changed to the\n\ |
|
161 users home directory", }, |
1
|
162 |
|
163 { "clear", -1, builtin_clear, |
181
|
164 "clear [name ...]\n\n\ |
|
165 clear symbol(s) matching a list of regular expressions\n\ |
|
166 if no arguments are given, clear all user-defined variables and functions", }, |
1
|
167 |
|
168 { "dir", -1, builtin_ls, |
181
|
169 "dir [options]\n\nprint a directory listing", }, |
1
|
170 |
|
171 { "document", -1, builtin_document, |
181
|
172 "document symbol string ...\n\n", }, |
1
|
173 |
|
174 { "edit_history", -1, builtin_edit_history, |
181
|
175 "edit_history [first] [last]\n\nedit commands from the history list", }, |
1
|
176 |
|
177 { "format", -1, builtin_format, |
181
|
178 "format [style]\n\nset output formatting style", }, |
1
|
179 |
|
180 { "help", -1, builtin_help, |
181
|
181 "help [-i] [topic ...]\n\nprint cryptic yet witty messages", }, |
1
|
182 |
|
183 { "history", -1, builtin_history, |
181
|
184 "history [N] [-w file] [-r file] [-q]\n\n\ |
|
185 display, save, or load command history", }, |
1
|
186 |
|
187 { "load", -1, builtin_load, |
181
|
188 "load [-force] file\n\nload variables from a file", }, |
1
|
189 |
|
190 { "ls", -1, builtin_ls, |
181
|
191 "ls [options]\n\nprint a directory listing", }, |
1
|
192 |
61
|
193 { "run_history", -1, builtin_run_history, |
181
|
194 "run_history [first] [last]\n\nrun commands from the history list", }, |
61
|
195 |
1
|
196 { "save", -1, builtin_save, |
181
|
197 "save file [var ...]\n\nsave variables in a file", }, |
1
|
198 |
|
199 { "set", -1, builtin_set, |
181
|
200 "set [options]\n\nset plotting options", }, |
1
|
201 |
|
202 { "show", -1, builtin_show, |
181
|
203 "show [options]\n\nshow plotting options", }, |
1
|
204 |
|
205 { "who", -1, builtin_who, |
204
|
206 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\n\ |
|
207 List currently defined symbol(s). Options may be shortened to one\n\ |
|
208 character, but may not be combined.", }, |
1
|
209 |
|
210 { NULL, -1, NULL, NULL, }, |
|
211 }; |
|
212 |
|
213 static builtin_general_functions general_functions[] = |
|
214 { |
|
215 { "all", 2, 1, builtin_all, |
181
|
216 "all (X): are all elements of X nonzero?", }, |
1
|
217 |
|
218 { "any", 2, 1, builtin_any, |
181
|
219 "any (X): are any elements of X nonzero?", }, |
1
|
220 |
19
|
221 { "balance", 4, 4, builtin_balance, |
181
|
222 "aa = balance (a [, opt]) or [[dd,] aa] = balance (a [, opt])\n\ |
19
|
223 generalized eigenvalue problem:\n\ |
181
|
224 [cc, dd, aa, bb] = balance (a, b [, opt])\n\ |
|
225 where \"opt\" is an optional single character argument as follows: \n\ |
|
226 \"N\" or \"n\": no balancing; arguments copied, transformation(s) \n\ |
19
|
227 set to identity\n\ |
181
|
228 \"P\" or \"p\": permute argument(s) to isolate eigenvalues where possible\n\ |
|
229 \"S\" or \"s\": scale to improve accuracy of computed eigenvalues\n\ |
|
230 \"B\" or \"b\": (default) permute and scale, in that order. Rows/columns of a \n\ |
19
|
231 (and b) that are isolated by permutation are not scaled\n\ |
|
232 [dd, aa] = balance (a, opt) returns aa = dd\a*dd,\n\ |
181
|
233 [cc, dd, aa, bb] = balance (a, b, opt) returns aa (bb) = cc*a*dd (cc*b*dd)", }, |
|
234 |
|
235 { "chol", 2, 1, builtin_chol, |
|
236 "chol (X): cholesky factorization", }, |
19
|
237 |
1
|
238 { "clc", 1, 0, builtin_clc, |
181
|
239 "clc (): clear screen", }, |
1
|
240 |
|
241 { "clock", 1, 0, builtin_clock, |
181
|
242 "clock (): return current date and time in vector", }, |
1
|
243 |
|
244 { "closeplot", 1, 0, builtin_closeplot, |
181
|
245 "closeplot (): close the stream to plotter", }, |
1
|
246 |
|
247 { "colloc", 7, 4, builtin_colloc, |
181
|
248 "[r, A, B, q] = colloc (n [, \"left\"] [, \"right\"]): collocation weights", }, |
1
|
249 |
|
250 { "cumprod", 2, 1, builtin_cumprod, |
181
|
251 "cumprod (X): cumulative products", }, |
1
|
252 |
|
253 { "cumsum", 2, 1, builtin_cumsum, |
181
|
254 "cumsum (X): cumulative sums", }, |
1
|
255 |
|
256 { "dassl", 5, 1, builtin_dassl, |
181
|
257 "dassl (\"function_name\", x_0, xdot_0, t_out)\n\ |
|
258 dassl (\"function_name\", x_0, xdot_0, t_out, t_crit)\n\ |
1
|
259 \n\ |
|
260 The first argument is the name of the function to call to\n\ |
|
261 compute the vector of residuals. It must have the form\n\ |
|
262 \n\ |
|
263 res = f (x, xdot, t)\n\ |
|
264 \n\ |
181
|
265 where x, xdot, and res are vectors, and t is a scalar.", }, |
1
|
266 |
272
|
267 { "dassl_options", -1, 1, builtin_dassl_options, |
287
|
268 "dassl_options (keyword, value)\n\n\ |
|
269 Set or show options for dassl. Keywords may be abbreviated\n\ |
|
270 to the shortest match.", }, |
272
|
271 |
1
|
272 { "date", 1, 0, builtin_date, |
181
|
273 "date (): return current date in a string", }, |
1
|
274 |
|
275 { "det", 2, 1, builtin_det, |
181
|
276 "det (X): determinant of a square matrix", }, |
1
|
277 |
|
278 { "diag", 3, 1, builtin_diag, |
181
|
279 "diag (X [,k]): form/extract diagonals", }, |
1
|
280 |
|
281 { "disp", 3, 1, builtin_disp, |
181
|
282 "disp (X): display value", }, |
1
|
283 |
|
284 { "eig", 2, 1, builtin_eig, |
181
|
285 "eig (x) or [v, d] = eig (x): compute eigenvalues and eigenvectors of x", }, |
1
|
286 |
|
287 { "error", 2, 1, builtin_error, |
181
|
288 "error (\"message\"): print message and jump to top level", }, |
1
|
289 |
|
290 { "eval", 2, 1, builtin_eval, |
181
|
291 "eval (\"string\"): evaluate text as octave source", }, |
1
|
292 |
|
293 { "exist", 2, 1, builtin_exist, |
181
|
294 "exist (\"name\"): check if variable or file exists", }, |
1
|
295 |
|
296 { "exit", 1, 0, builtin_quit, |
181
|
297 "exit (): exit Octave gracefully", }, |
1
|
298 |
|
299 { "expm", 2, 1, builtin_expm, |
181
|
300 "expm (X): matrix exponential, e^A", }, |
1
|
301 |
|
302 { "eye", 3, 1, builtin_eye, |
181
|
303 "eye (n), eye (n, m), eye (X): create an identity matrix", }, |
1
|
304 |
|
305 { "fclose", 2, 1, builtin_fclose, |
181
|
306 "fclose (\"filename\" or filenum): close a file", }, |
1
|
307 |
444
|
308 { "feof", 3, 1, builtin_feof, |
|
309 "eof = feof (filenum)\n\n\ |
|
310 Returns a non zero eof for an end of file condition for the\n\ |
|
311 file specified by \"filenum\" from fopen", }, |
|
312 |
|
313 { "ferror", 3, 1, builtin_ferror, |
|
314 "error = ferror (filenum)\n\n\ |
|
315 Returns a non zero \"error\" for an error condition on the\n\ |
|
316 file specified by \"filenum\" from fopen", }, |
|
317 |
1
|
318 { "feval", -1, 1, builtin_feval, |
181
|
319 "feval (\"name\", args, ...): evaluate first argument as function", }, |
1
|
320 |
|
321 { "fflush", 2, 1, builtin_fflush, |
181
|
322 "fflush (\"filename\" or filenum): flush buffered data to output file", }, |
1
|
323 |
|
324 { "fft", 2, 1, builtin_fft, |
181
|
325 "fft (X): fast fourier transform of a vector", }, |
1
|
326 |
|
327 { "fgets",3, 2, builtin_fgets, |
181
|
328 "[string, length] = fgets (\"filename\" or filenum, length): read a string from a file", }, |
1
|
329 |
|
330 { "find", -1, 1, builtin_find, |
181
|
331 "find (x): return vector of indices of nonzero elements", }, |
1
|
332 |
|
333 { "flops", 2, 1, builtin_flops, |
181
|
334 "flops (): count floating point operations", }, |
1
|
335 |
|
336 { "fopen", 3, 1, builtin_fopen, |
181
|
337 "filenum = fopen (\"filename\", \"mode\"): open a file\n\n\ |
333
|
338 Valid values for mode include:\n\n\ |
181
|
339 r : open text file for reading\n\ |
|
340 w : open text file for writing; discard previous contents if any\n\ |
|
341 a : append; open or create text file for writing at end of file\n\ |
|
342 r+ : open text file for update (i.e., reading and writing)\n\ |
|
343 w+ : create text file for update; discard previous contents if any\n\ |
|
344 a+ : append; open or create text file for update, writing at end\n\n\ |
|
345 Update mode permits reading from and writing to the same file.\n", }, |
1
|
346 |
|
347 { "fprintf", -1, 1, builtin_fprintf, |
181
|
348 "fprintf (\"file\", \"fmt\", ...)", }, |
1
|
349 |
444
|
350 { "fread", 3, 1, builtin_fread, |
|
351 "[data, count] = fread (filenum, size, \"precision\")\n\n\ |
|
352 Reads data in binary form of type \"precision\" from a file.\n\n\ |
|
353 filenum : file number from fopen\n\ |
|
354 size : size specification for the Data matrix\n\ |
|
355 precision : type of data to read, valid types are\n\n\ |
|
356 'char', 'schar', 'short', 'int', 'long', 'float'\n\ |
|
357 'double', 'uchar', 'ushort', 'uint', 'ulong'\n\n\ |
|
358 data : matrix in which the data is stored\n\ |
|
359 count : number of elements read", }, |
|
360 |
1
|
361 { "freport", 1, 1, builtin_freport, |
181
|
362 "freport (): list open files and their status", }, |
1
|
363 |
|
364 { "frewind", 2, 1, builtin_frewind, |
181
|
365 "frewind (\"filename\" or filenum): set file position at beginning of file", }, |
1
|
366 |
|
367 { "fscanf", 3, -1, builtin_fscanf, |
181
|
368 "[a, b, c, ...] = fscanf (\"file\", \"fmt\")", }, |
1
|
369 |
|
370 { "fseek", 4, 1, builtin_fseek, |
181
|
371 "fseek (\"filename\" or filenum, offset [, origin]): set file position for reading or writing", }, |
1
|
372 |
|
373 { "fsolve", 5, 1, builtin_fsolve, |
|
374 "Solve nonlinear equations using Minpack. Usage:\n\ |
|
375 \n\ |
181
|
376 [x, info] = fsolve (\"f\", x0)\n\ |
1
|
377 \n\ |
|
378 Where the first argument is the name of the function to call to\n\ |
|
379 compute the vector of function values. It must have the form\n\ |
|
380 \n\ |
|
381 y = f (x) |
|
382 \n\ |
181
|
383 where y and x are vectors.", }, |
1
|
384 |
272
|
385 { "fsolve_options", -1, 1, builtin_fsolve_options, |
287
|
386 "fsolve_options (keyword, value)\n\n\ |
|
387 Set or show options for fsolve. Keywords may be abbreviated\n\ |
|
388 to the shortest match.", }, |
272
|
389 |
1
|
390 { "fsqp", 11, 3, builtin_fsqp, |
181
|
391 #if defined (FSQP_MISSING) |
|
392 "This function requires FSQP, which is not freely\n\ |
|
393 redistributable. For more information, read the file\n\ |
|
394 libcruft/fsqp/README.MISSING in the source distribution.", }, |
|
395 #else |
|
396 "[x, phi] = fsqp (x, \"phi\" [, lb, ub] [, lb, A, ub] [, lb, \"g\", ub])\n\n\ |
|
397 Groups of arguments surrounded in `[]' are optional, but\n\ |
|
398 must appear in the same relative order shown above.", }, |
|
399 #endif |
1
|
400 |
272
|
401 { "fsqp_options", -1, 1, builtin_fsqp_options, |
282
|
402 #if defined (FSQP_MISSING) |
|
403 "This function requires FSQP, which is not freely\n\ |
|
404 redistributable. For more information, read the file\n\ |
|
405 libcruft/fsqp/README.MISSING in the source distribution.", }, |
|
406 #else |
287
|
407 "fsqp_options (keyword, value)\n\n\ |
|
408 Set or show options for fsqp. Keywords may be abbreviated\n\ |
|
409 to the shortest match.", }, |
282
|
410 #endif |
272
|
411 |
1
|
412 { "ftell", 2, 1, builtin_ftell, |
181
|
413 "position = ftell (\"filename\" or filenum): returns the current file position", }, |
1
|
414 |
444
|
415 { "fwrite", 3, 1, builtin_fwrite, |
|
416 "count = fwrite (filenum, Data, \"precision\")\n\n\ |
|
417 Writes data to a file in binary form of size \"precision\"\n\n\ |
|
418 filenum : file number from fopen\n\ |
|
419 Data : matrix of elements to be written\n\ |
|
420 precision : type of data to read, valid types are\n\n\ |
|
421 'char', 'schar', 'short', 'int', 'long', 'float'\n\ |
|
422 'double', 'uchar', 'ushort', 'uint', 'ulong'\n\n\ |
|
423 count : number of elements written", }, |
|
424 |
1
|
425 { "getenv", 2, 1, builtin_getenv, |
181
|
426 "getenv (\"string\"): get environment variable values", }, |
1
|
427 |
31
|
428 { "givens", 3, 2, builtin_givens, |
181
|
429 "G = givens (x, y): compute orthogonal matrix G = [c s; -conj (s) c]\n\ |
|
430 such that G [x; y] = [*; 0] (x, y scalars)\n\n\ |
|
431 [c, s] = givens (x, y) returns the (c, s) values themselves.", }, |
31
|
432 |
1
|
433 { "hess", 2, 2, builtin_hess, |
181
|
434 "[P, H] = hess (A) or H = hess (A): Hessenberg decomposition", }, |
1
|
435 |
|
436 { "home", 1, 0, builtin_clc, |
181
|
437 "home (): clear screen", }, |
1
|
438 |
|
439 { "input", 3, 1, builtin_input, |
181
|
440 "input (\"prompt\" [, \"s\"]): prompt user for [string] input", }, |
1
|
441 |
|
442 { "ifft", 2, 1, builtin_ifft, |
181
|
443 "ifft (X): inverse fast fourier transform of a vector", }, |
1
|
444 |
|
445 { "inv", 2, 1, builtin_inv, |
181
|
446 "inv (X): inverse of a square matrix", }, |
1
|
447 |
|
448 { "inverse", 2, 1, builtin_inv, |
181
|
449 "inverse (X): inverse of a square matrix", }, |
1
|
450 |
195
|
451 { "is_global", 2, 1, builtin_is_global, |
|
452 "is_global (X): return 1 if the string X names a global variable", }, |
|
453 |
1
|
454 { "isstr", 2, 1, builtin_isstr, |
181
|
455 "isstr (X): return 1 if X is a string", }, |
1
|
456 |
|
457 { "keyboard", 2, 1, builtin_keyboard, |
338
|
458 "keyboard (\"prompt\"): maybe help in debugging function files", }, |
1
|
459 |
|
460 { "logm", 2, 1, builtin_logm, |
181
|
461 "logm (x): matrix logarithm", }, |
1
|
462 |
181
|
463 { "lp_solve", 11, 3, builtin_lpsolve, |
|
464 "lp_solve (): solve linear programs using lp_solve.", }, |
1
|
465 |
272
|
466 { "lp_solve_options", -1, 1, builtin_lpsolve_options, |
287
|
467 "lp_solve_options (keyword, value)\n\n\ |
|
468 Set or show options for lp_solve. Keywords may be abbreviated\n\ |
|
469 to the shortest match.", }, |
272
|
470 |
1
|
471 { "lsode", 6, 1, builtin_lsode, |
181
|
472 "lsode (\"function_name\", x0, t_out, t_crit)\n\ |
1
|
473 \n\ |
|
474 The first argument is the name of the function to call to\n\ |
|
475 compute the vector of right hand sides. It must have the form\n\ |
|
476 \n\ |
|
477 xdot = f (x, t)\n\ |
|
478 \n\ |
181
|
479 where xdot and x are vectors and t is a scalar.\n", }, |
1
|
480 |
272
|
481 { "lsode_options", -1, 1, builtin_lsode_options, |
287
|
482 "lsode_options (keyword, value)\n\n\ |
|
483 Set or show options for lsode. Keywords may be abbreviated\n\ |
|
484 to the shortest match.", }, |
272
|
485 |
1
|
486 { "lu", 2, 3, builtin_lu, |
181
|
487 "[L, U, P] = lu (A): LU factorization", }, |
1
|
488 |
|
489 { "max", 3, 2, builtin_max, |
181
|
490 "max (x): maximum value(s) of a vector (matrix)", }, |
1
|
491 |
|
492 { "min", 3, 2, builtin_min, |
181
|
493 "min (x): minimum value(s) of a vector (matrix)", }, |
1
|
494 |
|
495 { "npsol", 11, 3, builtin_npsol, |
181
|
496 #if defined (NPSOL_MISSING) |
|
497 "This function requires NPSOL, which is not freely\n\ |
|
498 redistributable. For more information, read the file\n\ |
|
499 libcruft/npsol/README.MISSING in the source distribution.", }, |
|
500 #else |
|
501 "[x, obj, info, lambda] = npsol (x, \"phi\" [, lb, ub] [, lb, A, ub] [, lb, \"g\", ub])\n\n\ |
|
502 Groups of arguments surrounded in `[]' are optional, but\n\ |
|
503 must appear in the same relative order shown above.\n\ |
1
|
504 \n\ |
181
|
505 The second argument is a string containing the name of the objective\n\ |
|
506 function to call. The objective function must be of the form\n\ |
1
|
507 \n\ |
181
|
508 y = phi (x)\n\ |
1
|
509 \n\ |
181
|
510 where x is a vector and y is a scalar.", }, |
|
511 #endif |
1
|
512 |
272
|
513 { "npsol_options", -1, 1, builtin_npsol_options, |
282
|
514 #if defined (NPSOL_MISSING) |
|
515 "This function requires NPSOL, which is not freely\n\ |
|
516 redistributable. For more information, read the file\n\ |
|
517 libcruft/npsol/README.MISSING in the source distribution.", }, |
|
518 #else |
287
|
519 "npsol_options (keyword, value)\n\n\ |
|
520 Set or show options for npsol. Keywords may be abbreviated\n\ |
|
521 to the shortest match.", }, |
282
|
522 #endif |
272
|
523 |
1
|
524 { "ones", 3, 1, builtin_ones, |
181
|
525 "ones (n), ones (n, m), ones (x): create a matrix of all ones", }, |
1
|
526 |
|
527 { "pause", 1, 0, builtin_pause, |
181
|
528 "pause (seconds): suspend program execution", }, |
1
|
529 |
|
530 { "purge_tmp_files", 5, 1, builtin_purge_tmp_files, |
181
|
531 "delete temporary data files used for plotting", }, |
1
|
532 |
|
533 { "printf", -1, 1, builtin_printf, |
181
|
534 "printf (\"fmt\", ...)", }, |
1
|
535 |
|
536 { "prod", 2, 1, builtin_prod, |
181
|
537 "prod (X): products", }, |
1
|
538 |
|
539 { "pwd", 1, 0, builtin_pwd, |
181
|
540 "pwd (): print current working directory", }, |
1
|
541 |
|
542 { "qpsol", 9, 3, builtin_qpsol, |
181
|
543 #if defined (QPSOL_MISSING) |
|
544 "This function requires QPSOL, which is not freely\n\ |
|
545 redistributable. For more information, read the file\n\ |
|
546 libcruft/qpsol/README.MISSING in the source distribution.", }, |
|
547 #else |
|
548 "[x, obj, info, lambda] = qpsol (x, H, c [, lb, ub] [, lb, A, ub])\n\ |
1
|
549 \n\ |
|
550 Groups of arguments surrounded in `[]' are optional, but\n\ |
|
551 must appear in the same relative order shown above.", }, |
181
|
552 #endif |
1
|
553 |
272
|
554 { "qpsol_options", -1, 1, builtin_qpsol_options, |
282
|
555 #if defined (QPSOL_MISSING) |
|
556 "This function requires QPSOL, which is not freely\n\ |
|
557 redistributable. For more information, read the file\n\ |
|
558 libcruft/qpsol/README.MISSING in the source distribution.", }, |
|
559 #else |
287
|
560 "qpsol_options (keyword, value)\n\n\ |
|
561 Set or show options for qpsol. Keywords may be abbreviated\n\ |
|
562 to the shortest match.", }, |
282
|
563 #endif |
272
|
564 |
1
|
565 { "qr", 2, 2, builtin_qr, |
181
|
566 "[q, r] = qr (X): form QR factorization of X", }, |
1
|
567 |
|
568 { "quad", 6, 3, builtin_quad, |
181
|
569 "[v, ier, nfun] = quad (\"f\", a, b [, tol] [, sing])\n\ |
1
|
570 \n\ |
|
571 Where the first argument is the name of the function to call to\n\ |
|
572 compute the value of the integrand. It must have the form\n\ |
|
573 \n\ |
|
574 y = f (x) |
|
575 \n\ |
|
576 where y and x are scalars.\n\ |
|
577 \n\ |
|
578 The second and third arguments are limits of integration. Either or\n\ |
|
579 both may be infinite. The optional argument tol specifies the desired\n\ |
|
580 accuracy of the result. The optional argument sing is a vector of\n\ |
181
|
581 at which the integrand is singular.\n", }, |
1
|
582 |
272
|
583 { "quad_options", -1, 1, builtin_quad_options, |
287
|
584 "quad_options (keyword, value)\n\n\ |
|
585 Set or show options for quad. Keywords may be abbreviated\n\ |
|
586 to the shortest match.", }, |
272
|
587 |
1
|
588 { "quit", 1, 0, builtin_quit, |
181
|
589 "quit (): exit Octave gracefully", }, |
1
|
590 |
45
|
591 { "qzval", 3, 1, builtin_qzval, |
181
|
592 "x = qzval (A,B): compute generalized eigenvalues of \n\ |
|
593 the matrix pencil (A - lambda B). A and B must be real matrices.", }, |
45
|
594 |
1
|
595 { "rand", 2, 1, builtin_rand, |
181
|
596 "rand -- generate a random value\n\ |
|
597 rand (n) -- generate N x N matrix\n\ |
|
598 rand (A) -- generate matrix the size of A\n\ |
|
599 rand (n, m) -- generate N x M matrix\n\ |
|
600 rand (\"dist\") -- get current distribution\n\ |
|
601 rand (\"distribution\") -- set distribution\n\ |
|
602 rand (\"seed\") -- get current seed\n\ |
|
603 rand (\"seed\", n) -- set seed", }, |
1
|
604 |
|
605 { "replot", 1, 0, builtin_replot, |
181
|
606 "replot (): redisplay current plot", }, |
1
|
607 |
|
608 { "scanf", 2, -1, builtin_scanf, |
181
|
609 "[a, b, c, ...] = scanf (\"fmt\")", }, |
1
|
610 |
|
611 { "setstr", 2, 1, builtin_setstr, |
181
|
612 "setstr (v): convert a vector to a string", }, |
1
|
613 |
|
614 { "shell_cmd", 2, 1, builtin_shell_command, |
181
|
615 "shell_cmd (string [, return_output]): execute shell commands", }, |
1
|
616 |
|
617 { "schur", 3, 2, builtin_schur, |
181
|
618 "[U, S] = schur (A) or S = schur (A)\n\n\ |
|
619 or, for ordered Schur:\n\n\ |
|
620 [U, S] = schur (A, \"A, D, or U\") or S = schur (A, \"A, D, or U\")\n\ |
|
621 where:\n\n\ |
|
622 A = continuous time poles\n\ |
|
623 D = discrete time poles\n\ |
|
624 U = unordered schur (default)", }, |
|
625 |
1
|
626 |
|
627 { "size", 2, 1, builtin_size, |
181
|
628 "[m, n] = size (x): return rows and columns of X", }, |
1
|
629 |
|
630 { "sort", 2, 2, builtin_sort, |
181
|
631 "[s, i] = sort (x): sort the columns of x, optionally return sort index", }, |
1
|
632 |
|
633 { "sqrtm", 2, 1, builtin_sqrtm, |
181
|
634 "sqrtm (x): matrix sqrt", }, |
1
|
635 |
|
636 { "sprintf", -1, 1, builtin_sprintf, |
181
|
637 "s = sprintf (\"fmt\", ...)", }, |
1
|
638 |
|
639 { "sscanf", 3, -1, builtin_sscanf, |
181
|
640 "[a, b, c, ...] = sscanf (string, \"fmt\")", }, |
1
|
641 |
|
642 { "sum", 2, 1, builtin_sum, |
181
|
643 "sum (X): sum of elements", }, |
1
|
644 |
|
645 { "sumsq", 2, 1, builtin_sumsq, |
181
|
646 "sumsq (X): sum of squares of elements", }, |
1
|
647 |
|
648 { "svd", 2, 3, builtin_svd, |
181
|
649 "s = svd (x) or [u, s, v] = svd (x): return SVD of x", }, |
1
|
650 |
38
|
651 { "syl", 4, 1, builtin_syl, |
181
|
652 "X = syl (A, B, C): solve the Sylvester equation A X + X B + C = 0", }, |
38
|
653 |
210
|
654 { "va_arg", 1, 1, builtin_va_arg, |
|
655 "va_arg (): return next argument in function taking varible\n\ |
|
656 number of parameters", }, |
|
657 |
|
658 { "va_start", 1, 0, builtin_va_start, |
|
659 "va_start (): reset the pointer to the list of optional arguments\n\ |
|
660 to the beginning", }, |
|
661 |
1
|
662 { "warranty", 1, 0, builtin_warranty, |
181
|
663 "warranty (): describe copying conditions", }, |
1
|
664 |
|
665 { "zeros", 3, 1, builtin_zeros, |
181
|
666 "zeros (n), zeros (n, m), zeros (x): create a matrix of all zeros", }, |
1
|
667 |
|
668 { NULL, -1, -1, NULL, NULL, }, |
|
669 }; |
|
670 |
|
671 // This is a lie. Some of these get reassigned to be numeric |
|
672 // variables. See below. |
|
673 |
|
674 static builtin_string_variables string_variables[] = |
|
675 { |
195
|
676 { "EDITOR", "??", sv_editor, |
|
677 "name of the editor to be invoked by the edit_history command", }, |
|
678 |
1
|
679 { "I", "??", NULL, |
181
|
680 "sqrt (-1)", }, |
1
|
681 |
|
682 { "Inf", "??", NULL, |
181
|
683 "infinity", }, |
1
|
684 |
191
|
685 { "INFO_FILE", "??", sv_info_file, |
|
686 "name of the Octave info file", }, |
|
687 |
1
|
688 { "J", "??", NULL, |
181
|
689 "sqrt (-1)", }, |
1
|
690 |
|
691 #if defined (HAVE_ISNAN) |
|
692 { "NaN", "??", NULL, |
181
|
693 "not a number", }, |
1
|
694 #endif |
|
695 |
|
696 { "LOADPATH", "??", sv_loadpath, |
181
|
697 "colon separated list of directories to search for scripts", }, |
1
|
698 |
|
699 { "PAGER", "??", sv_pager_binary, |
181
|
700 "path to pager binary", }, |
1
|
701 |
|
702 { "PS1", "\\s:\\#> ", sv_ps1, |
181
|
703 "primary prompt string", }, |
1
|
704 |
|
705 { "PS2", "> ", sv_ps2, |
181
|
706 "secondary prompt string", }, |
1
|
707 |
|
708 { "PWD", "??PWD??", sv_pwd, |
181
|
709 "current working directory", }, |
1
|
710 |
|
711 { "SEEK_SET", "??", NULL, |
181
|
712 "used with fseek to position file relative to the beginning", }, |
1
|
713 |
|
714 { "SEEK_CUR", "??", NULL, |
181
|
715 "used with fseek to position file relative to the current position", }, |
1
|
716 |
|
717 { "SEEK_END", "??", NULL, |
181
|
718 "used with fseek to position file relative to the end", }, |
1
|
719 |
429
|
720 { "commas_in_literal_matrix", "", commas_in_literal_matrix, |
|
721 "control auto-insertion of commas in literal matrices", }, |
|
722 |
1
|
723 { "do_fortran_indexing", "false", do_fortran_indexing, |
181
|
724 "allow single indices for matrices", }, |
1
|
725 |
|
726 { "empty_list_elements_ok", "warn", empty_list_elements_ok, |
181
|
727 "ignore the empty element in expressions like `a = [[], 1]'", }, |
1
|
728 |
|
729 { "eps", "??", NULL, |
181
|
730 "machine precision", }, |
1
|
731 |
|
732 { "gnuplot_binary", "gnuplot", sv_gnuplot_binary, |
181
|
733 "path to gnuplot binary", }, |
1
|
734 |
|
735 { "i", "??", NULL, |
181
|
736 "sqrt (-1)", }, |
1
|
737 |
195
|
738 { "ignore_function_time_stamp", "system", ignore_function_time_stamp, |
338
|
739 "don't check to see if function files have changed since they were\n\ |
|
740 last compiled. Possible values are \"system\" and \"all\"", }, |
195
|
741 |
1
|
742 { "implicit_str_to_num_ok", "false", implicit_str_to_num_ok, |
181
|
743 "allow implicit string to number conversion", }, |
1
|
744 |
|
745 { "inf", "??", NULL, |
181
|
746 "infinity", }, |
1
|
747 |
|
748 { "j", "??", NULL, |
181
|
749 "sqrt (-1)", }, |
1
|
750 |
|
751 #if defined (HAVE_ISNAN) |
|
752 { "nan", "??", NULL, |
181
|
753 "not a number", }, |
1
|
754 #endif |
|
755 |
|
756 { "ok_to_lose_imaginary_part", "warn", ok_to_lose_imaginary_part, |
181
|
757 "silently convert from complex to real by dropping imaginary part", }, |
1
|
758 |
|
759 { "output_max_field_width", "??", set_output_max_field_width, |
181
|
760 "maximum width of an output field for numeric output", }, |
1
|
761 |
|
762 { "output_precision", "??", set_output_precision, |
181
|
763 "number of significant figures to display for numeric output", }, |
1
|
764 |
|
765 { "page_screen_output", "true", page_screen_output, |
181
|
766 "if possible, send output intended for the screen through the pager", }, |
1
|
767 |
|
768 { "pi", "??", NULL, |
181
|
769 "ratio of the circumference of a circle to its diameter", }, |
1
|
770 |
|
771 { "prefer_column_vectors", "true", prefer_column_vectors, |
181
|
772 "prefer column/row vectors", }, |
1
|
773 |
|
774 { "prefer_zero_one_indexing", "false", prefer_zero_one_indexing, |
181
|
775 "when there is a conflict, prefer zero-one style indexing", }, |
1
|
776 |
|
777 { "print_answer_id_name", "true", print_answer_id_name, |
181
|
778 "set output style to print `var_name = ...'", }, |
1
|
779 |
|
780 { "print_empty_dimensions", "true", print_empty_dimensions, |
181
|
781 "also print dimensions of empty matrices", }, |
1
|
782 |
|
783 { "propagate_empty_matrices", "true", propagate_empty_matrices, |
181
|
784 "operations on empty matrices return an empty matrix, not an error", }, |
1
|
785 |
|
786 { "resize_on_range_error", "true", resize_on_range_error, |
181
|
787 "enlarge matrices on assignment", }, |
1
|
788 |
|
789 { "return_last_computed_value", "false", return_last_computed_value, |
|
790 "if a function does not return any values explicitly, return the\n\ |
181
|
791 last computed value", }, |
1
|
792 |
275
|
793 { "save_precision", "??", set_save_precision, |
|
794 "number of significant figures kept by the ASCII save command", }, |
|
795 |
1
|
796 { "silent_functions", "false", silent_functions, |
181
|
797 "suppress printing results in called functions", }, |
1
|
798 |
|
799 { "split_long_rows", "true", split_long_rows, |
181
|
800 "split long matrix rows instead of wrapping", }, |
1
|
801 |
|
802 { "stdin", "??", NULL, |
181
|
803 "file number of the standard input stream", }, |
1
|
804 |
|
805 { "stdout", "??", NULL, |
181
|
806 "file number of the standard output stream", }, |
1
|
807 |
|
808 { "stderr", "??", NULL, |
181
|
809 "file number of the standard error stream", }, |
1
|
810 |
|
811 { "treat_neg_dim_as_zero", "false", treat_neg_dim_as_zero, |
181
|
812 "convert negative dimensions to zero", }, |
1
|
813 |
|
814 { "warn_assign_as_truth_value", "true", warn_assign_as_truth_value, |
181
|
815 "produce warning for assignments used as truth values", }, |
1
|
816 |
|
817 { "warn_comma_in_global_decl", "true", warn_comma_in_global_decl, |
181
|
818 "produce warning for commas in global declarations", }, |
1
|
819 |
|
820 { "warn_divide_by_zero", "true", warn_divide_by_zero, |
181
|
821 "on IEEE machines, allow divide by zero errors to be suppressed", }, |
1
|
822 |
|
823 { NULL, NULL, NULL, NULL, }, |
|
824 }; |
|
825 |
|
826 void |
|
827 install_builtins (void) |
|
828 { |
|
829 // So that the clear function can't delete other builtin variables and |
|
830 // functions, they are given eternal life. |
|
831 |
|
832 builtin_mapper_functions *mfptr = mapper_functions; |
|
833 while (mfptr->name != (char *) NULL) |
|
834 { |
195
|
835 install_builtin_mapper_function (mfptr); |
1
|
836 mfptr++; |
|
837 } |
|
838 |
|
839 builtin_text_functions *tfptr = text_functions; |
|
840 while (tfptr->name != (char *) NULL) |
|
841 { |
195
|
842 install_builtin_text_function (tfptr); |
1
|
843 tfptr++; |
|
844 } |
|
845 |
|
846 builtin_general_functions *gfptr = general_functions; |
|
847 while (gfptr->name != (char *) NULL) |
|
848 { |
195
|
849 install_builtin_general_function (gfptr); |
1
|
850 gfptr++; |
|
851 } |
|
852 |
|
853 // Most built-in variables are not protected because the user should |
|
854 // be able to redefine them. |
|
855 |
|
856 builtin_string_variables *svptr = string_variables; |
|
857 while (svptr->name != (char *) NULL) |
|
858 { |
195
|
859 install_builtin_variable (svptr); |
1
|
860 svptr++; |
|
861 } |
|
862 |
|
863 // IMPORTANT: Always create a new tree_constant for each variable. |
|
864 |
|
865 tree_constant *tmp = NULL_TREE_CONST; |
195
|
866 bind_builtin_variable ("ans", tmp); |
1
|
867 |
|
868 Complex ctmp (0.0, 1.0); |
|
869 tmp = new tree_constant (ctmp); |
195
|
870 bind_builtin_variable ("I", tmp, 1, 1); |
1
|
871 |
|
872 tmp = new tree_constant (ctmp); |
195
|
873 bind_builtin_variable ("J", tmp, 1, 1); |
1
|
874 |
|
875 // Let i and j be functions so they can be redefined without being |
|
876 // wiped out. |
|
877 |
|
878 tmp = new tree_constant (ctmp); |
195
|
879 install_builtin_variable_as_function ("i", tmp, 1, 1); |
1
|
880 |
|
881 tmp = new tree_constant (ctmp); |
195
|
882 install_builtin_variable_as_function ("j", tmp, 1, 1); |
1
|
883 |
|
884 tmp = new tree_constant (get_working_directory ("initialize_globals")); |
195
|
885 bind_builtin_variable ("PWD", tmp, 1, 1); |
1
|
886 |
|
887 tmp = new tree_constant (load_path); |
195
|
888 bind_builtin_variable ("LOADPATH", tmp, 0, 1); |
1
|
889 |
191
|
890 tmp = new tree_constant (info_file); |
195
|
891 bind_builtin_variable ("INFO_FILE", tmp, 0, 1); |
|
892 |
|
893 tmp = new tree_constant (editor); |
|
894 bind_builtin_variable ("EDITOR", tmp, 0, 1); |
191
|
895 |
1
|
896 tmp = new tree_constant (default_pager ()); |
195
|
897 bind_builtin_variable ("PAGER", tmp, 0, 1); |
1
|
898 |
|
899 tmp = new tree_constant (0.0); |
323
|
900 bind_builtin_variable ("SEEK_SET", tmp, 1, 1); |
1
|
901 |
|
902 tmp = new tree_constant (1.0); |
323
|
903 bind_builtin_variable ("SEEK_CUR", tmp, 1, 1); |
1
|
904 |
|
905 tmp = new tree_constant (2.0); |
323
|
906 bind_builtin_variable ("SEEK_END", tmp, 1, 1); |
1
|
907 |
|
908 tmp = new tree_constant (DBL_EPSILON); |
195
|
909 bind_builtin_variable ("eps", tmp, 1, 1); |
1
|
910 |
|
911 tmp = new tree_constant (10.0); |
195
|
912 bind_builtin_variable ("output_max_field_width", tmp, 0, 1); |
1
|
913 |
|
914 tmp = new tree_constant (5.0); |
195
|
915 bind_builtin_variable ("output_precision", tmp, 0, 1); |
1
|
916 |
|
917 tmp = new tree_constant (4.0 * atan (1.0)); |
195
|
918 bind_builtin_variable ("pi", tmp, 1, 1); |
1
|
919 |
275
|
920 tmp = new tree_constant (17.0); |
|
921 bind_builtin_variable ("save_precision", tmp, 0, 1); |
|
922 |
1
|
923 tmp = new tree_constant (0.0); |
195
|
924 bind_builtin_variable ("stdin", tmp, 1, 1); |
1
|
925 |
|
926 tmp = new tree_constant (1.0); |
195
|
927 bind_builtin_variable ("stdout", tmp, 1, 1); |
1
|
928 |
|
929 tmp = new tree_constant (2.0); |
195
|
930 bind_builtin_variable ("stderr", tmp, 1, 1); |
1
|
931 |
444
|
932 tmp = new tree_constant (octave_Inf); |
195
|
933 bind_builtin_variable ("Inf", tmp, 1, 1); |
1
|
934 |
444
|
935 tmp = new tree_constant (octave_Inf); |
195
|
936 bind_builtin_variable ("inf", tmp, 1, 1); |
1
|
937 |
444
|
938 tmp = new tree_constant (octave_NaN); |
195
|
939 bind_builtin_variable ("NaN", tmp, 1, 1); |
1
|
940 |
444
|
941 tmp = new tree_constant (octave_NaN); |
195
|
942 bind_builtin_variable ("nan", tmp, 1, 1); |
1
|
943 } |
|
944 |
|
945 int |
164
|
946 is_text_function_name (const char *s) |
1
|
947 { |
|
948 int retval = 0; |
|
949 |
|
950 builtin_text_functions *tfptr = text_functions; |
|
951 while (tfptr->name != (char *) NULL) |
|
952 { |
|
953 if (strcmp (tfptr->name, s) == 0) |
|
954 { |
|
955 retval = 1; |
|
956 break; |
|
957 } |
|
958 tfptr++; |
|
959 } |
|
960 |
|
961 return retval; |
|
962 } |
|
963 |
|
964 help_list * |
|
965 builtin_mapper_functions_help (void) |
|
966 { |
|
967 int count = 0; |
|
968 builtin_mapper_functions *mfptr; |
|
969 |
|
970 mfptr = mapper_functions; |
|
971 while (mfptr->name != (char *) NULL) |
|
972 { |
|
973 count++; |
|
974 mfptr++; |
|
975 } |
|
976 |
|
977 if (count == 0) |
|
978 return (help_list *) NULL; |
|
979 |
|
980 help_list *hl = new help_list [count+1]; |
|
981 |
|
982 int i = 0; |
|
983 mfptr = mapper_functions; |
|
984 while (mfptr->name != (char *) NULL) |
|
985 { |
|
986 hl[i].name = mfptr->name; |
|
987 hl[i].help = mfptr->help_string; |
|
988 i++; |
|
989 mfptr++; |
|
990 } |
|
991 |
|
992 hl[count].name = (char *) NULL; |
|
993 hl[count].help = (char *) NULL; |
|
994 |
|
995 return hl; |
|
996 } |
|
997 |
|
998 help_list * |
|
999 builtin_general_functions_help (void) |
|
1000 { |
|
1001 int count = 0; |
|
1002 builtin_general_functions *gfptr; |
|
1003 |
|
1004 gfptr = general_functions; |
|
1005 while (gfptr->name != (char *) NULL) |
|
1006 { |
|
1007 count++; |
|
1008 gfptr++; |
|
1009 } |
|
1010 |
|
1011 if (count == 0) |
|
1012 return (help_list *) NULL; |
|
1013 |
|
1014 help_list *hl = new help_list [count+1]; |
|
1015 |
|
1016 int i = 0; |
|
1017 gfptr = general_functions; |
|
1018 while (gfptr->name != (char *) NULL) |
|
1019 { |
|
1020 hl[i].name = gfptr->name; |
|
1021 hl[i].help = gfptr->help_string; |
|
1022 i++; |
|
1023 gfptr++; |
|
1024 } |
|
1025 |
|
1026 hl[count].name = (char *) NULL; |
|
1027 hl[count].help = (char *) NULL; |
|
1028 |
|
1029 return hl; |
|
1030 } |
|
1031 |
|
1032 help_list * |
|
1033 builtin_text_functions_help (void) |
|
1034 { |
|
1035 int count = 0; |
|
1036 builtin_text_functions *tfptr; |
|
1037 |
|
1038 tfptr = text_functions; |
|
1039 while (tfptr->name != (char *) NULL) |
|
1040 { |
|
1041 count++; |
|
1042 tfptr++; |
|
1043 } |
|
1044 |
|
1045 if (count == 0) |
|
1046 return (help_list *) NULL; |
|
1047 |
|
1048 help_list *hl = new help_list [count+1]; |
|
1049 |
|
1050 int i = 0; |
|
1051 tfptr = text_functions; |
|
1052 while (tfptr->name != (char *) NULL) |
|
1053 { |
|
1054 hl[i].name = tfptr->name; |
|
1055 hl[i].help = tfptr->help_string; |
|
1056 i++; |
|
1057 tfptr++; |
|
1058 } |
|
1059 |
|
1060 hl[count].name = (char *) NULL; |
|
1061 hl[count].help = (char *) NULL; |
|
1062 |
|
1063 return hl; |
|
1064 } |
|
1065 |
|
1066 help_list * |
|
1067 builtin_variables_help (void) |
|
1068 { |
|
1069 int count = 0; |
|
1070 builtin_string_variables *svptr; |
|
1071 |
|
1072 svptr = string_variables; |
|
1073 while (svptr->name != (char *) NULL) |
|
1074 { |
|
1075 count++; |
|
1076 svptr++; |
|
1077 } |
|
1078 |
|
1079 if (count == 0) |
|
1080 return (help_list *) NULL; |
|
1081 |
|
1082 help_list *hl = new help_list [count+1]; |
|
1083 |
|
1084 int i = 0; |
|
1085 svptr = string_variables; |
|
1086 while (svptr->name != (char *) NULL) |
|
1087 { |
|
1088 hl[i].name = svptr->name; |
|
1089 hl[i].help = svptr->help_string; |
|
1090 i++; |
|
1091 svptr++; |
|
1092 } |
|
1093 |
|
1094 hl[count].name = (char *) NULL; |
|
1095 hl[count].help = (char *) NULL; |
|
1096 |
|
1097 return hl; |
|
1098 } |
|
1099 |
181
|
1100 int |
|
1101 help_from_list (ostrstream& output_buf, const help_list *list, |
|
1102 const char *string, int usage) |
|
1103 { |
|
1104 char *name; |
|
1105 while ((name = list->name) != (char *) NULL) |
|
1106 { |
|
1107 if (strcmp (name, string) == 0) |
|
1108 { |
|
1109 if (usage) |
|
1110 output_buf << "\nusage: "; |
|
1111 else |
|
1112 { |
|
1113 output_buf << "\n*** " << string << ":\n\n"; |
|
1114 } |
|
1115 |
|
1116 output_buf << list->help << "\n"; |
|
1117 |
|
1118 return 1; |
|
1119 } |
|
1120 list++; |
|
1121 } |
|
1122 return 0; |
|
1123 } |
|
1124 |
|
1125 void |
|
1126 additional_help_message (ostrstream& output_buf) |
|
1127 { |
|
1128 output_buf |
|
1129 << "\n" |
|
1130 << "Additional help for builtin functions, operators, and variables\n" |
|
1131 << "is available in the on-line version of the manual.\n" |
|
1132 << "\n" |
|
1133 << "Use the command `help -i <topic>' to search the manual index.\n"; |
|
1134 } |
|
1135 |
|
1136 void |
287
|
1137 print_usage (const char *string, int just_usage = 0) |
181
|
1138 { |
|
1139 ostrstream output_buf; |
|
1140 |
|
1141 help_list *gf_help_list = builtin_general_functions_help (); |
|
1142 help_list *tf_help_list = builtin_text_functions_help (); |
|
1143 help_list *mf_help_list = builtin_mapper_functions_help (); |
|
1144 |
|
1145 if (help_from_list (output_buf, gf_help_list, string, 1) |
|
1146 || help_from_list (output_buf, tf_help_list, string, 1) |
|
1147 || help_from_list (output_buf, mf_help_list, string, 1)) |
|
1148 { |
287
|
1149 if (! just_usage) |
|
1150 additional_help_message (output_buf); |
181
|
1151 output_buf << ends; |
|
1152 maybe_page_output (output_buf); |
|
1153 } |
|
1154 } |
|
1155 |
1
|
1156 /* |
|
1157 ;;; Local Variables: *** |
|
1158 ;;; mode: C++ *** |
|
1159 ;;; page-delimiter: "^/\\*" *** |
|
1160 ;;; End: *** |
|
1161 */ |