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