00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <cstdlib>
00028 #include <cstring>
00029
00030 #include <algorithm>
00031 #include <iostream>
00032 #include <fstream>
00033 #include <sstream>
00034 #include <string>
00035
00036 #include <sys/types.h>
00037 #include <unistd.h>
00038
00039 #include "cmd-edit.h"
00040 #include "file-ops.h"
00041 #include "file-stat.h"
00042 #include "oct-env.h"
00043 #include "str-vec.h"
00044
00045 #include <defaults.h>
00046 #include "defun.h"
00047 #include "dirfns.h"
00048 #include "error.h"
00049 #include "gripes.h"
00050 #include "help.h"
00051 #include "input.h"
00052 #include "load-path.h"
00053 #include "oct-obj.h"
00054 #include "ov-usr-fcn.h"
00055 #include "pager.h"
00056 #include "parse.h"
00057 #include "pathsearch.h"
00058 #include "procstream.h"
00059 #include "pt-pr-code.h"
00060 #include "sighandlers.h"
00061 #include "symtab.h"
00062 #include "syswait.h"
00063 #include "toplev.h"
00064 #include "unwind-prot.h"
00065 #include "utils.h"
00066 #include "variables.h"
00067 #include "version.h"
00068 #include "quit.h"
00069
00070
00071
00072 std::string Vdoc_cache_file;
00073
00074
00075
00076 std::string Vinfo_file;
00077
00078
00079
00080 std::string Vinfo_program;
00081
00082
00083 static std::string Vmakeinfo_program = "makeinfo";
00084
00085
00086
00087 static bool Vsuppress_verbose_help_message = false;
00088
00089 #include <map>
00090
00091 typedef std::map<std::string, std::string> map_type;
00092 typedef map_type::value_type pair_type;
00093 typedef map_type::const_iterator map_iter;
00094
00095 template<typename T, std::size_t z>
00096 std::size_t
00097 size (T const (&)[z])
00098 {
00099 return z;
00100 }
00101
00102 const static pair_type operators[] =
00103 {
00104 pair_type ("!",
00105 "-*- texinfo -*-\n\
00106 @deftypefn {Operator} {} !\n\
00107 Logical 'not' operator.\n\
00108 @seealso{~, not}\n\
00109 @end deftypefn"),
00110
00111 pair_type ("~",
00112 "-*- texinfo -*-\n\
00113 @deftypefn {Operator} {} ~\n\
00114 Logical 'not' operator.\n\
00115 @seealso{!, not}\n\
00116 @end deftypefn"),
00117
00118 pair_type ("!=",
00119 "-*- texinfo -*-\n\
00120 @deftypefn {Operator} {} !=\n\
00121 Logical 'not equals' operator.\n\
00122 @seealso{~=, ne}\n\
00123 @end deftypefn"),
00124
00125 pair_type ("~=",
00126 "-*- texinfo -*-\n\
00127 @deftypefn {Operator} {} ~=\n\
00128 Logical 'not equals' operator.\n\
00129 @seealso{!=, ne}\n\
00130 @end deftypefn"),
00131
00132 pair_type ("\"",
00133 "-*- texinfo -*-\n\
00134 @deftypefn {Operator} {} \"\n\
00135 String delimiter.\n\
00136 @end deftypefn"),
00137
00138 pair_type ("#",
00139 "-*- texinfo -*-\n\
00140 @deftypefn {Operator} {} #\n\
00141 Begin comment character.\n\
00142 @seealso{%, #@{}\n\
00143 @end deftypefn"),
00144
00145 pair_type ("%",
00146 "-*- texinfo -*-\n\
00147 @deftypefn {Operator} {} %\n\
00148 Begin comment character.\n\
00149 @seealso{#, %@{}\n\
00150 @end deftypefn"),
00151
00152 pair_type ("#{",
00153 "-*- texinfo -*-\n\
00154 @deftypefn {Operator} {} #@{\n\
00155 Begin block comment. There must be nothing else, other than\n\
00156 whitespace, in the line both before and after @code{#@{}.\n\
00157 It is possible to nest block comments.\n\
00158 @seealso{%@{, #@}, #}\n\
00159 @end deftypefn"),
00160
00161 pair_type ("%{",
00162 "-*- texinfo -*-\n\
00163 @deftypefn {Operator} {} %@{\n\
00164 Begin block comment. There must be nothing else, other than\n\
00165 whitespace, in the line both before and after @code{%@{}.\n\
00166 It is possible to nest block comments.\n\
00167 @seealso{#@{, %@}, %}\n\
00168 @end deftypefn"),
00169
00170 pair_type ("#}",
00171 "-*- texinfo -*-\n\
00172 @deftypefn {Operator} {} #@}\n\
00173 Close block comment. There must be nothing else, other than\n\
00174 whitespace, in the line both before and after @code{#@}}.\n\
00175 It is possible to nest block comments.\n\
00176 @seealso{%@}, #@{, #}\n\
00177 @end deftypefn"),
00178
00179 pair_type ("%}",
00180 "-*- texinfo -*-\n\
00181 @deftypefn {Operator} {} %@}\n\
00182 Close block comment. There must be nothing else, other than\n\
00183 whitespace, in the line both before and after @code{%@}}.\n\
00184 It is possible to nest block comments.\n\
00185 @seealso{#@}, %@{, %}\n\
00186 @end deftypefn"),
00187
00188 pair_type ("...",
00189 "-*- texinfo -*-\n\
00190 @deftypefn {Operator} {} ...\n\
00191 Continuation marker. Joins current line with following line.\n\
00192 @end deftypefn"),
00193
00194 pair_type ("&",
00195 "-*- texinfo -*-\n\
00196 @deftypefn {Operator} {} &\n\
00197 Element by element logical 'and' operator.\n\
00198 @seealso{&&, and}\n\
00199 @end deftypefn"),
00200
00201 pair_type ("&&",
00202 "-*- texinfo -*-\n\
00203 @deftypefn {Operator} {} &&\n\
00204 Logical 'and' operator (with short-circuit evaluation).\n\
00205 @seealso{&, and}\n\
00206 @end deftypefn"),
00207
00208 pair_type ("'",
00209 "-*- texinfo -*-\n\
00210 @deftypefn {Operator} {} '\n\
00211 Matrix transpose operator. For complex matrices, computes the\n\
00212 complex conjugate (Hermitian) transpose.\n\
00213 \n\
00214 The single quote character may also be used to delimit strings, but\n\
00215 it is better to use the double quote character, since that is never\n\
00216 ambiguous.\n\
00217 @seealso{.', transpose}\n\
00218 @end deftypefn"),
00219
00220 pair_type ("(",
00221 "-*- texinfo -*-\n\
00222 @deftypefn {Operator} {} (\n\
00223 Array index or function argument delimiter.\n\
00224 @end deftypefn"),
00225
00226 pair_type (")",
00227 "-*- texinfo -*-\n\
00228 @deftypefn {Operator} {} )\n\
00229 Array index or function argument delimiter.\n\
00230 @end deftypefn"),
00231
00232 pair_type ("*",
00233 "-*- texinfo -*-\n\
00234 @deftypefn {Operator} {} *\n\
00235 Multiplication operator.\n\
00236 @seealso{.*, times}\n\
00237 @end deftypefn"),
00238
00239 pair_type ("**",
00240 "-*- texinfo -*-\n\
00241 @deftypefn {Operator} {} **\n\
00242 Power operator. This may return complex results for real inputs. Use\n\
00243 @code{realsqrt}, @code{cbrt}, @code{nthroot}, or @code{realroot} to obtain\n\
00244 real results when possible.\n\
00245 @seealso{power, ^, .**, .^, realpow, realsqrt, cbrt, nthroot}\n\
00246 @end deftypefn"),
00247
00248 pair_type ("^",
00249 "-*- texinfo -*-\n\
00250 @deftypefn {Operator} {} ^\n\
00251 Power operator. This may return complex results for real inputs. Use\n\
00252 @code{realsqrt}, @code{cbrt}, @code{nthroot}, or @code{realroot} to obtain\n\
00253 real results when possible.\n\
00254 @seealso{power, **, .^, .**, realpow, realsqrt, cbrt, nthroot}\n\
00255 @end deftypefn"),
00256
00257 pair_type ("+",
00258 "-*- texinfo -*-\n\
00259 @deftypefn {Operator} {} +\n\
00260 Addition operator.\n\
00261 @seealso{plus}\n\
00262 @end deftypefn"),
00263
00264 pair_type ("++",
00265 "-*- texinfo -*-\n\
00266 @deftypefn {Operator} {} ++\n\
00267 Increment operator. As in C, may be applied as a prefix or postfix\n\
00268 operator.\n\
00269 @seealso{--}\n\
00270 @end deftypefn"),
00271
00272 pair_type (",",
00273 "-*- texinfo -*-\n\
00274 @deftypefn {Operator} {} ,\n\
00275 Array index, function argument, or command separator.\n\
00276 @end deftypefn"),
00277
00278 pair_type ("-",
00279 "-*- texinfo -*-\n\
00280 @deftypefn {Operator} {} -\n\
00281 Subtraction or unary negation operator.\n\
00282 @seealso{minus}\n\
00283 @end deftypefn"),
00284
00285 pair_type ("--",
00286 "-*- texinfo -*-\n\
00287 @deftypefn {Operator} {} --\n\
00288 Decrement operator. As in C, may be applied as a prefix or postfix\n\
00289 operator.\n\
00290 @seealso{++}\n\
00291 @end deftypefn"),
00292
00293 pair_type (".'",
00294 "-*- texinfo -*-\n\
00295 @deftypefn {Operator} {} .'\n\
00296 Matrix transpose operator. For complex matrices, computes the\n\
00297 transpose, @emph{not} the complex conjugate transpose.\n\
00298 @seealso{', transpose}\n\
00299 @end deftypefn"),
00300
00301 pair_type (".*",
00302 "-*- texinfo -*-\n\
00303 @deftypefn {Operator} {} .*\n\
00304 Element by element multiplication operator.\n\
00305 @seealso{*, times}\n\
00306 @end deftypefn"),
00307
00308 pair_type (".**",
00309 "-*- texinfo -*-\n\
00310 @deftypefn {Operator} {} .*\n\
00311 Element by element power operator. If several complex results are possible,\n\
00312 returns the one with smallest non-negative argument (angle). Use\n\
00313 @code{realpow}, @code{realsqrt}, @code{cbrt}, or @code{nthroot} if a\n\
00314 real result is preferred.\n\
00315 @seealso{**, ^, .^, power, realpow, realsqrt, cbrt, nthroot}\n\
00316 @end deftypefn"),
00317
00318 pair_type (".^",
00319 "-*- texinfo -*-\n\
00320 @deftypefn {Operator} {} .^\n\
00321 Element by element power operator. If several complex results are possible,\n\
00322 returns the one with smallest non-negative argument (angle). Use\n\
00323 @code{realpow}, @code{realsqrt}, @code{cbrt}, or @code{nthroot} if a\n\
00324 real result is preferred.\n\
00325 @seealso{.**, ^, **, power, realpow, realsqrt, cbrt, nthroot}\n\
00326 @end deftypefn"),
00327
00328 pair_type ("./",
00329 "-*- texinfo -*-\n\
00330 @deftypefn {Operator} {} ./\n\
00331 Element by element right division operator.\n\
00332 @seealso{/, .\\, rdivide, mrdivide}\n\
00333 @end deftypefn"),
00334
00335 pair_type ("/",
00336 "-*- texinfo -*-\n\
00337 @deftypefn {Operator} {} /\n\
00338 Right division operator.\n\
00339 @seealso{./, \\, rdivide, mrdivide}\n\
00340 @end deftypefn"),
00341
00342 pair_type (".\\",
00343 "-*- texinfo -*-\n\
00344 @deftypefn {Operator} {} .\\\n\
00345 Element by element left division operator.\n\
00346 @seealso{\\, ./, rdivide, mrdivide}\n\
00347 @end deftypefn"),
00348
00349 pair_type ("\\",
00350 "-*- texinfo -*-\n\
00351 @deftypefn {Operator} {} \\\n\
00352 Left division operator.\n\
00353 @seealso{.\\, /, ldivide, mldivide}\n\
00354 @end deftypefn"),
00355
00356 pair_type (":",
00357 "-*- texinfo -*-\n\
00358 @deftypefn {Operator} {} :\n\
00359 Select entire rows or columns of matrices.\n\
00360 @end deftypefn"),
00361
00362 pair_type (";",
00363 "-*- texinfo -*-\n\
00364 @deftypefn {Operator} {} ;\n\
00365 Array row or command separator.\n\
00366 @seealso{,}\n\
00367 @end deftypefn"),
00368
00369 pair_type ("<",
00370 "-*- texinfo -*-\n\
00371 @deftypefn {Operator} {} <\n\
00372 'Less than' operator.\n\
00373 @seealso{lt}\n\
00374 @end deftypefn"),
00375
00376 pair_type ("<=",
00377 "-*- texinfo -*-\n\
00378 @deftypefn {Operator} {} <=\n\
00379 'Less than' or 'equals' operator.\n\
00380 @seealso{le}\n\
00381 @end deftypefn"),
00382
00383 pair_type ("=",
00384 "-*- texinfo -*-\n\
00385 @deftypefn {Operator} {} =\n\
00386 Assignment operator.\n\
00387 @end deftypefn"),
00388
00389 pair_type ("==",
00390 "-*- texinfo -*-\n\
00391 @deftypefn {Operator} {} ==\n\
00392 Equality test operator.\n\
00393 @seealso{eq}\n\
00394 @end deftypefn"),
00395
00396 pair_type (">",
00397 "-*- texinfo -*-\n\
00398 @deftypefn {Operator} {} >\n\
00399 'Greater than' operator.\n\
00400 @seealso{gt}\n\
00401 @end deftypefn"),
00402
00403 pair_type (">=",
00404 "-*- texinfo -*-\n\
00405 @deftypefn {Operator} {} >=\n\
00406 'Greater than' or 'equals' operator.\n\
00407 @seealso{ge}\n\
00408 @end deftypefn"),
00409
00410 pair_type ("[",
00411 "-*- texinfo -*-\n\
00412 @deftypefn {Operator} {} [\n\
00413 Return list delimiter.\n\
00414 @seealso{]}\n\
00415 @end deftypefn"),
00416
00417 pair_type ("]",
00418 "-*- texinfo -*-\n\
00419 @deftypefn {Operator} {} ]\n\
00420 Return list delimiter.\n\
00421 @seealso{[}\n\
00422 @end deftypefn"),
00423
00424 pair_type ("|",
00425 "-*- texinfo -*-\n\
00426 @deftypefn {Operator} {} |\n\
00427 Element by element logical 'or' operator.\n\
00428 @seealso{||, or}\n\
00429 @end deftypefn"),
00430
00431 pair_type ("||",
00432 "-*- texinfo -*-\n\
00433 @deftypefn {Operator} {} ||\n\
00434 Logical 'or' (with short-circuit evaluation) operator.\n\
00435 @seealso{|, or}\n\
00436 @end deftypefn"),
00437 };
00438
00439 const static pair_type keywords[] =
00440 {
00441 pair_type ("break",
00442 "-*- texinfo -*-\n\
00443 @deftypefn {Keyword} {} break\n\
00444 Exit the innermost enclosing do, while or for loop.\n\
00445 @seealso{do, while, for, parfor, continue}\n\
00446 @end deftypefn"),
00447
00448 pair_type ("case",
00449 "-*- texinfo -*-\n\
00450 @deftypefn {Keyword} {} case @{@var{value}@}\n\
00451 A case statement in an switch. Octave cases are exclusive and do not\n\
00452 fall-through as do C-language cases. A switch statement must have at least\n\
00453 one case. See @code{switch} for an example.\n\
00454 @seealso{switch}\n\
00455 @end deftypefn"),
00456
00457 pair_type ("catch",
00458 "-*- texinfo -*-\n\
00459 @deftypefn {Keyword} {} catch\n\
00460 Begin the cleanup part of a try-catch block.\n\
00461 @seealso{try}\n\
00462 @end deftypefn"),
00463
00464 pair_type ("continue",
00465 "-*- texinfo -*-\n\
00466 @deftypefn {Keyword} {} continue\n\
00467 Jump to the end of the innermost enclosing do, while or for loop.\n\
00468 @seealso{do, while, for, parfor, break}\n\
00469 @end deftypefn"),
00470
00471 pair_type ("do",
00472 "-*- texinfo -*-\n\
00473 @deftypefn {Keyword} {} do\n\
00474 Begin a do-until loop. This differs from a do-while loop in that the\n\
00475 body of the loop is executed at least once.\n\
00476 @seealso{while}\n\
00477 @end deftypefn"),
00478
00479 pair_type ("else",
00480 "-*- texinfo -*-\n\
00481 @deftypefn {Keyword} {} else\n\
00482 Alternate action for an if block. See @code{if} for an example.\n\
00483 @seealso{if}\n\
00484 @end deftypefn"),
00485
00486 pair_type ("elseif",
00487 "-*- texinfo -*-\n\
00488 @deftypefn {Keyword} {} elseif (@var{condition})\n\
00489 Alternate conditional test for an if block. See @code{if} for an example.\n\
00490 @seealso{if}\n\
00491 @end deftypefn"),
00492
00493 pair_type ("end",
00494 "-*- texinfo -*-\n\
00495 @deftypefn {Keyword} {} end\n\
00496 Mark the end of any @code{for}, @code{if}, @code{do}, @code{while}, or\n\
00497 @code{function} block.\n\
00498 @seealso{for, parfor, if, do, while, function}\n\
00499 @end deftypefn"),
00500
00501 pair_type ("end_try_catch",
00502 "-*- texinfo -*-\n\
00503 @deftypefn {Keyword} {} end_try_catch\n\
00504 Mark the end of an @code{try-catch} block.\n\
00505 @seealso{try, catch}\n\
00506 @end deftypefn"),
00507
00508 pair_type ("end_unwind_protect",
00509 "-*- texinfo -*-\n\
00510 @deftypefn {Keyword} {} end_unwind_protect\n\
00511 Mark the end of an unwind_protect block.\n\
00512 @seealso{unwind_protect}\n\
00513 @end deftypefn"),
00514
00515 pair_type ("endfor",
00516 "-*- texinfo -*-\n\
00517 @deftypefn {Keyword} {} endfor\n\
00518 Mark the end of a for loop. See @code{for} for an example.\n\
00519 @seealso{for}\n\
00520 @end deftypefn"),
00521
00522 pair_type ("endfunction",
00523 "-*- texinfo -*-\n\
00524 @deftypefn {Keyword} {} endfunction\n\
00525 Mark the end of a function.\n\
00526 @seealso{function}\n\
00527 @end deftypefn"),
00528
00529 pair_type ("endif",
00530 "-*- texinfo -*-\n\
00531 @deftypefn {Keyword} {} endif\n\
00532 Mark the end of an if block. See @code{if} for an example.\n\
00533 @seealso{if}\n\
00534 @end deftypefn"),
00535
00536 pair_type ("endparfor",
00537 "-*- texinfo -*-\n\
00538 @deftypefn {Keyword} {} endparfor\n\
00539 Mark the end of a parfor loop. See @code{parfor} for an example.\n\
00540 @seealso{parfor}\n\
00541 @end deftypefn"),
00542
00543 pair_type ("endswitch",
00544 "-*- texinfo -*-\n\
00545 @deftypefn {Keyword} {} endswitch\n\
00546 Mark the end of a switch block. See @code{switch} for an example.\n\
00547 @seealso{switch}\n\
00548 @end deftypefn"),
00549
00550 pair_type ("endwhile",
00551 "-*- texinfo -*-\n\
00552 @deftypefn {Keyword} {} endwhile\n\
00553 Mark the end of a while loop. See @code{while} for an example.\n\
00554 @seealso{do, while}\n\
00555 @end deftypefn"),
00556
00557 pair_type ("for",
00558 "-*- texinfo -*-\n\
00559 @deftypefn {Keyword} {} for @var{i} = @var{range}\n\
00560 Begin a for loop.\n\
00561 \n\
00562 @example\n\
00563 @group\n\
00564 for i = 1:10\n\
00565 i\n\
00566 endfor\n\
00567 @end group\n\
00568 @end example\n\
00569 @seealso{do, parfor, while}\n\
00570 @end deftypefn"),
00571
00572 pair_type ("function",
00573 "-*- texinfo -*-\n\
00574 @deftypefn {Keyword} {} function @var{outputs} = function (@var{input}, @dots{})\n\
00575 @deftypefnx {Keyword} {} function {} function (@var{input}, @dots{})\n\
00576 @deftypefnx {Keyword} {} function @var{outputs} = function\n\
00577 Begin a function body with @var{outputs} as results and @var{inputs} as\n\
00578 parameters.\n\
00579 @seealso{return}\n\
00580 @end deftypefn"),
00581
00582 pair_type ("global",
00583 "-*- texinfo -*-\n\
00584 @deftypefn {Keyword} {} global\n\
00585 Declare variables to have global scope.\n\
00586 \n\
00587 @example\n\
00588 @group\n\
00589 global @var{x};\n\
00590 if isempty (@var{x})\n\
00591 x = 1;\n\
00592 endif\n\
00593 @end group\n\
00594 @end example\n\
00595 @seealso{persistent}\n\
00596 @end deftypefn"),
00597
00598 pair_type ("if",
00599 "-*- texinfo -*-\n\
00600 @deftypefn {Keyword} {} if (@var{cond}) @dots{} endif\n\
00601 @deftypefnx {Keyword} {} if (@var{cond}) @dots{} else @dots{} endif\n\
00602 @deftypefnx {Keyword} {} if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} endif\n\
00603 @deftypefnx {Keyword} {} if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} else @dots{} endif\n\
00604 Begin an if block.\n\
00605 \n\
00606 @example\n\
00607 @group\n\
00608 x = 1;\n\
00609 if (x == 1)\n\
00610 disp (\"one\");\n\
00611 elseif (x == 2)\n\
00612 disp (\"two\");\n\
00613 else\n\
00614 disp (\"not one or two\");\n\
00615 endif\n\
00616 @end group\n\
00617 @end example\n\
00618 @seealso{switch}\n\
00619 @end deftypefn"),
00620
00621 pair_type ("otherwise",
00622 "-*- texinfo -*-\n\
00623 @deftypefn {Keyword} {} otherwise\n\
00624 The default statement in a switch block (similar to else in an if block).\n\
00625 @seealso{switch}\n\
00626 @end deftypefn"),
00627
00628 pair_type ("parfor",
00629 "-*- texinfo -*-\n\
00630 @deftypefn {Keyword} {} for @var{i} = @var{range}\n\
00631 @deftypefnx {Keyword} {} for (@var{i} = @var{range}, @var{maxproc})\n\
00632 Begin a for loop that may execute in parallel.\n\
00633 \n\
00634 @example\n\
00635 @group\n\
00636 parfor i = 1:10\n\
00637 i\n\
00638 endparfor\n\
00639 @end group\n\
00640 @end example\n\
00641 @seealso{for, do, while}\n\
00642 @end deftypefn"),
00643
00644 pair_type ("persistent",
00645 "-*- texinfo -*-\n\
00646 @deftypefn {Keyword} {} persistent @var{var}\n\
00647 Declare variables as persistent. A variable that has been declared\n\
00648 persistent within a function will retain its contents in memory between\n\
00649 subsequent calls to the same function. The difference between persistent\n\
00650 variables and global variables is that persistent variables are local in \n\
00651 scope to a particular function and are not visible elsewhere.\n\
00652 @seealso{global}\n\
00653 @end deftypefn"),
00654
00655 pair_type ("return",
00656 "-*- texinfo -*-\n\
00657 @deftypefn {Keyword} {} return\n\
00658 Return from a function.\n\
00659 @seealso{function}\n\
00660 @end deftypefn"),
00661
00662 pair_type ("static",
00663 "-*- texinfo -*-\n\
00664 @deftypefn {Keyword} {} static\n\
00665 This function has been deprecated in favor of persistent.\n\
00666 @seealso{persistent}\n\
00667 @end deftypefn"),
00668
00669 pair_type ("switch",
00670 "-*- texinfo -*-\n\
00671 @deftypefn {Keyword} {} switch @var{statement}\n\
00672 Begin a switch block.\n\
00673 \n\
00674 @example\n\
00675 @group\n\
00676 yesno = \"yes\"\n\
00677 \n\
00678 switch yesno\n\
00679 case @{\"Yes\" \"yes\" \"YES\" \"y\" \"Y\"@}\n\
00680 value = 1;\n\
00681 case @{\"No\" \"no\" \"NO\" \"n\" \"N\"@}\n\
00682 value = 0;\n\
00683 otherwise\n\
00684 error (\"invalid value\");\n\
00685 endswitch\n\
00686 @end group\n\
00687 @end example\n\
00688 @seealso{if, case, otherwise}\n\
00689 @end deftypefn"),
00690
00691 pair_type ("try",
00692 "-*- texinfo -*-\n\
00693 @deftypefn {Keyword} {} try\n\
00694 Begin a try-catch block.\n\
00695 \n\
00696 If an error occurs within a try block, then the catch code will be run and\n\
00697 execution will proceed after the catch block (though it is often\n\
00698 recommended to use the lasterr function to re-throw the error after cleanup\n\
00699 is completed).\n\
00700 @seealso{catch, unwind_protect}\n\
00701 @end deftypefn"),
00702
00703 pair_type ("until",
00704 "-*- texinfo -*-\n\
00705 @deftypefn {Keyword} {} until\n\
00706 End a do-until loop.\n\
00707 @seealso{do}\n\
00708 @end deftypefn"),
00709
00710 pair_type ("unwind_protect",
00711 "-*- texinfo -*-\n\
00712 @deftypefn {Keyword} {} unwind_protect\n\
00713 Begin an unwind_protect block.\n\
00714 \n\
00715 If an error occurs within the first part of an unwind_protect block\n\
00716 the commands within the unwind_protect_cleanup block are executed before\n\
00717 the error is thrown. If an error is not thrown, then the\n\
00718 unwind_protect_cleanup block is still executed (in other words, the\n\
00719 unwind_protect_cleanup will be run with or without an error in the\n\
00720 unwind_protect block).\n\
00721 @seealso{unwind_protect_cleanup, try}\n\
00722 @end deftypefn"),
00723
00724 pair_type ("unwind_protect_cleanup",
00725 "-*- texinfo -*-\n\
00726 @deftypefn {Keyword} {} unwind_protect_cleanup\n\
00727 Begin the cleanup section of an unwind_protect block.\n\
00728 @seealso{unwind_protect}\n\
00729 @end deftypefn"),
00730
00731 pair_type ("varargin",
00732 "-*- texinfo -*-\n\
00733 @deftypefn {Keyword} {} varargin\n\
00734 Pass an arbitrary number of arguments into a function.\n\
00735 @seealso{varargout, nargin, isargout, nargout, nthargout}\n\
00736 @end deftypefn"),
00737
00738 pair_type ("varargout",
00739 "-*- texinfo -*-\n\
00740 @deftypefn {Keyword} {} varargout\n\
00741 Pass an arbitrary number of arguments out of a function.\n\
00742 @seealso{varargin, nargin, isargout, nargout, nthargout}\n\
00743 @end deftypefn"),
00744
00745 pair_type ("while",
00746 "-*- texinfo -*-\n\
00747 @deftypefn {Keyword} {} while\n\
00748 Begin a while loop.\n\
00749 @seealso{do}\n\
00750 @end deftypefn"),
00751 };
00752
00753
00754 static string_vector
00755 names (const map_type& lst)
00756 {
00757 string_vector retval (lst.size ());
00758 int j = 0;
00759 for (map_iter iter = lst.begin (); iter != lst.end (); iter ++)
00760 retval [j++] = iter->first;
00761 return retval;
00762 }
00763
00764 const static map_type operators_map (operators, operators + size (operators));
00765 const static map_type keywords_map (keywords, keywords + size (keywords));
00766 const static string_vector keyword_names = names (keywords_map);
00767
00768
00769
00770 string_vector
00771 make_name_list (void)
00772 {
00773 const int key_len = keyword_names.length ();
00774
00775 const string_vector bif = symbol_table::built_in_function_names ();
00776 const int bif_len = bif.length ();
00777
00778 const string_vector cfl = symbol_table::cmdline_function_names ();
00779 const int cfl_len = cfl.length ();
00780
00781 const string_vector lcl = symbol_table::variable_names ();
00782 const int lcl_len = lcl.length ();
00783
00784 const string_vector ffl = load_path::fcn_names ();
00785 const int ffl_len = ffl.length ();
00786
00787 const string_vector afl = autoloaded_functions ();
00788 const int afl_len = afl.length ();
00789
00790 const int total_len
00791 = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len;
00792
00793 string_vector list (total_len);
00794
00795
00796
00797 int j = 0;
00798 int i = 0;
00799 for (i = 0; i < key_len; i++)
00800 list[j++] = keyword_names[i];
00801
00802 for (i = 0; i < bif_len; i++)
00803 list[j++] = bif[i];
00804
00805 for (i = 0; i < cfl_len; i++)
00806 list[j++] = cfl[i];
00807
00808 for (i = 0; i < lcl_len; i++)
00809 list[j++] = lcl[i];
00810
00811 for (i = 0; i < ffl_len; i++)
00812 list[j++] = ffl[i];
00813
00814 for (i = 0; i < afl_len; i++)
00815 list[j++] = afl[i];
00816
00817 return list;
00818 }
00819
00820 static bool
00821 looks_like_html (const std::string& msg)
00822 {
00823 const size_t p1 = msg.find ('\n');
00824 std::string t = msg.substr (0, p1);
00825 const size_t p2 = t.find ("<html");
00826
00827 return (p2 != std::string::npos);
00828 }
00829
00830 static bool
00831 looks_like_texinfo (const std::string& msg, size_t& p1)
00832 {
00833 p1 = msg.find ('\n');
00834
00835 std::string t = msg.substr (0, p1);
00836
00837 if (p1 == std::string::npos)
00838 p1 = 0;
00839
00840 size_t p2 = t.find ("-*- texinfo -*-");
00841
00842 return (p2 != std::string::npos);
00843 }
00844
00845 static bool
00846 raw_help_from_symbol_table (const std::string& nm, std::string& h,
00847 std::string& w, bool& symbol_found)
00848 {
00849 bool retval = false;
00850
00851 octave_value val = symbol_table::find_function (nm);
00852
00853 if (val.is_defined ())
00854 {
00855 octave_function *fcn = val.function_value ();
00856
00857 if (fcn)
00858 {
00859 symbol_found = true;
00860
00861 h = fcn->doc_string ();
00862
00863 retval = true;
00864
00865 w = fcn->fcn_file_name ();
00866
00867 if (w.empty ())
00868 w = fcn->is_user_function ()
00869 ? "command-line function" : "built-in function";
00870 }
00871 }
00872
00873 return retval;
00874 }
00875
00876 static bool
00877 raw_help_from_file (const std::string& nm, std::string& h,
00878 std::string& file, bool& symbol_found)
00879 {
00880 bool retval = false;
00881
00882
00883 unwind_protect frame;
00884 frame.protect_var (reading_script_file);
00885 reading_script_file = true;
00886
00887 h = get_help_from_file (nm, symbol_found, file);
00888
00889 if (h.length () > 0)
00890 retval = true;
00891
00892 return retval;
00893 }
00894
00895 static bool
00896 raw_help_from_map (const std::string& nm, std::string& h,
00897 const map_type& map, bool& symbol_found)
00898 {
00899 map_iter idx = map.find (nm);
00900 symbol_found = (idx != map.end ());
00901 h = (symbol_found) ? idx->second : "";
00902 return symbol_found;
00903 }
00904
00905 std::string
00906 raw_help (const std::string& nm, bool& symbol_found)
00907 {
00908 std::string h;
00909 std::string w;
00910 std::string f;
00911
00912 (raw_help_from_symbol_table (nm, h, w, symbol_found)
00913 || raw_help_from_file (nm, h, f, symbol_found)
00914 || raw_help_from_map (nm, h, operators_map, symbol_found)
00915 || raw_help_from_map (nm, h, keywords_map, symbol_found));
00916
00917 return h;
00918 }
00919
00920 static void
00921 do_get_help_text (const std::string& name, std::string& text,
00922 std::string& format)
00923 {
00924 bool symbol_found = false;
00925 text = raw_help (name, symbol_found);
00926
00927 format = "Not found";
00928 if (symbol_found)
00929 {
00930 size_t idx = -1;
00931 if (text.empty ())
00932 {
00933 format = "Not documented";
00934 }
00935 else if (looks_like_texinfo (text, idx))
00936 {
00937 format = "texinfo";
00938 text.erase (0, idx);
00939 }
00940 else if (looks_like_html (text))
00941 {
00942 format = "html";
00943 }
00944 else
00945 {
00946 format = "plain text";
00947 }
00948 }
00949 }
00950
00951 DEFUN (get_help_text, args, , "-*- texinfo -*-\n\
00952 @deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text (@var{name})\n\
00953 Return the raw help text of function @var{name}.\n\
00954 \n\
00955 The raw help text is returned in @var{text} and the format in @var{format}\n\
00956 The format is a string which is one of @t{\"texinfo\"}, @t{\"html\"}, or\n\
00957 @t{\"plain text\"}.\n\
00958 @end deftypefn")
00959 {
00960 octave_value_list retval;
00961
00962 if (args.length () == 1)
00963 {
00964 const std::string name = args (0).string_value ();
00965
00966 if (! error_state)
00967 {
00968 std::string text;
00969 std::string format;
00970
00971 do_get_help_text (name, text, format);
00972
00973 retval(1) = format;
00974 retval(0) = text;
00975 }
00976 else
00977 error ("get_help_text: invalid input");
00978 }
00979 else
00980 print_usage ();
00981
00982 return retval;
00983 }
00984
00985 static void
00986 do_get_help_text_from_file (const std::string& fname, std::string& text,
00987 std::string& format)
00988 {
00989 bool symbol_found = false;
00990
00991 std::string f;
00992
00993 raw_help_from_file (fname, text, f, symbol_found);
00994
00995 format = "Not found";
00996 if (symbol_found)
00997 {
00998 size_t idx = -1;
00999 if (text.empty ())
01000 {
01001 format = "Not documented";
01002 }
01003 else if (looks_like_texinfo (text, idx))
01004 {
01005 format = "texinfo";
01006 text.erase (0, idx);
01007 }
01008 else if (looks_like_html (text))
01009 {
01010 format = "html";
01011 }
01012 else
01013 {
01014 format = "plain text";
01015 }
01016 }
01017 }
01018
01019 DEFUN (get_help_text_from_file, args, ,
01020 "-*- texinfo -*-\n\
01021 @deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text_from_file (@var{fname})\n\
01022 Return the raw help text from the file @var{fname}.\n\
01023 \n\
01024 The raw help text is returned in @var{text} and the format in @var{format}\n\
01025 The format is a string which is one of @t{\"texinfo\"}, @t{\"html\"}, or\n\
01026 @t{\"plain text\"}.\n\
01027 @end deftypefn")
01028 {
01029 octave_value_list retval;
01030
01031 if (args.length () == 1)
01032 {
01033 const std::string fname = args(0).string_value ();
01034
01035 if (! error_state)
01036 {
01037 std::string text;
01038 std::string format;
01039
01040 do_get_help_text_from_file (fname, text, format);
01041
01042 retval(1) = format;
01043 retval(0) = text;
01044 }
01045 else
01046 error ("get_help_text_from_file: invalid input");
01047 }
01048 else
01049 print_usage ();
01050
01051 return retval;
01052 }
01053
01054
01055
01056
01057 DEFUN (__operators__, , ,
01058 "-*- texinfo -*-\n\
01059 @deftypefn {Function File} __operators__ ()\n\
01060 Undocumented internal function.\n\
01061 @end deftypefn")
01062 {
01063 return octave_value (Cell (names (operators_map)));
01064 }
01065
01066
01067
01068
01069 DEFUN (__keywords__, , ,
01070 "-*- texinfo -*-\n\
01071 @deftypefn {Function File} __keywords__ ()\n\
01072 Undocumented internal function.\n\
01073 @end deftypefn")
01074 {
01075 return octave_value (Cell (names (keywords_map)));
01076 }
01077
01078
01079
01080
01081 DEFUN (__builtins__, , ,
01082 "-*- texinfo -*-\n\
01083 @deftypefn {Function File} __builtins__ ()\n\
01084 Undocumented internal function.\n\
01085 @end deftypefn")
01086 {
01087 const string_vector bif = symbol_table::built_in_function_names ();
01088
01089 return octave_value (Cell (bif));
01090 }
01091
01092 static std::string
01093 do_which (const std::string& name, std::string& type)
01094 {
01095 std::string file;
01096
01097 type = std::string ();
01098
01099 octave_value val = symbol_table::find_function (name);
01100
01101 if (name.find_first_of ('.') == std::string::npos)
01102 {
01103 if (val.is_defined ())
01104 {
01105 octave_function *fcn = val.function_value ();
01106
01107 if (fcn)
01108 {
01109 file = fcn->fcn_file_name ();
01110
01111 if (file.empty ())
01112 {
01113 if (fcn->is_user_function ())
01114 type = "command-line function";
01115 else
01116 type = "built-in function";
01117 }
01118 else
01119 type = val.is_user_script ()
01120 ? std::string ("script") : std::string ("function");
01121 }
01122 }
01123 else
01124 {
01125
01126
01127 file = load_path::find_fcn_file (name);
01128 }
01129 }
01130 else
01131 {
01132
01133
01134
01135 if (name.size () > 1 && name[name.size () - 1] == '.')
01136 file = load_path::find_file (name.substr (0, name.size () - 1));
01137 else
01138 file = load_path::find_file (name);
01139 }
01140
01141
01142 return file;
01143 }
01144
01145 std::string
01146 do_which (const std::string& name)
01147 {
01148 std::string retval;
01149
01150 std::string type;
01151
01152 retval = do_which (name, type);
01153
01154 return retval;
01155 }
01156
01157 DEFUN (__which__, args, ,
01158 "-*- texinfo -*-\n\
01159 @deftypefn {Built-in Function} {} __which__ (@var{name}, @dots{})\n\
01160 Undocumented internal function.\n\
01161 @end deftypefn")
01162 {
01163 octave_value retval;
01164
01165 string_vector argv = args.make_argv ("which");
01166
01167 if (! error_state)
01168 {
01169 int argc = argv.length ();
01170
01171 if (argc > 1)
01172 {
01173 octave_map m (dim_vector (1, argc-1));
01174
01175 Cell names (1, argc-1);
01176 Cell files (1, argc-1);
01177 Cell types (1, argc-1);
01178
01179 for (int i = 1; i < argc; i++)
01180 {
01181 std::string name = argv[i];
01182
01183 std::string type;
01184
01185 std::string file = do_which (name, type);
01186
01187 names(i-1) = name;
01188 files(i-1) = file;
01189 types(i-1) = type;
01190 }
01191
01192 m.assign ("name", names);
01193 m.assign ("file", files);
01194 m.assign ("type", types);
01195
01196 retval = m;
01197 }
01198 else
01199 print_usage ();
01200 }
01201
01202 return retval;
01203 }
01204
01205
01206 inline bool
01207 file_is_in_dir (const std::string filename, const std::string dir)
01208 {
01209 if (filename.find (dir) == 0)
01210 {
01211 const int dir_len = dir.size ();
01212 const int filename_len = filename.size ();
01213 const int max_allowed_seps = file_ops::is_dir_sep (dir [dir_len-1]) ? 0 : 1;
01214
01215 int num_seps = 0;
01216 for (int i = dir_len; i < filename_len; i++)
01217 if (file_ops::is_dir_sep (filename [i]))
01218 num_seps ++;
01219
01220 return (num_seps <= max_allowed_seps);
01221 }
01222 else
01223 return false;
01224 }
01225
01226
01227
01228
01229
01230 DEFUN (__list_functions__, args, ,
01231 "-*- texinfo -*-\n\
01232 @deftypefn {Function File} {@var{retval} =} __list_functions__ ()\n\
01233 @deftypefnx {Function File} {@var{retval} =} __list_functions__ (@var{directory})\n\
01234 Undocumented internal function.\n\
01235 @end deftypefn")
01236 {
01237 octave_value retval;
01238
01239
01240 string_vector ffl = load_path::fcn_names ();
01241 string_vector afl = autoloaded_functions ();
01242
01243 if (args.length () == 0)
01244 retval = Cell (ffl.append (afl));
01245 else
01246 {
01247 std::string dir = args (0).string_value ();
01248
01249 if (! error_state)
01250 {
01251 string_vector fl = load_path::files (dir, true);
01252
01253 if (! error_state)
01254 {
01255
01256
01257
01258 fl.sort (true);
01259
01260 retval = Cell (fl);
01261 }
01262 }
01263 else
01264 error ("__list_functions__: DIRECTORY argument must be a string");
01265 }
01266
01267 return retval;
01268 }
01269
01270 DEFUN (doc_cache_file, args, nargout,
01271 "-*- texinfo -*-\n\
01272 @deftypefn {Built-in Function} {@var{val} =} doc_cache_file ()\n\
01273 @deftypefnx {Built-in Function} {@var{old_val} =} doc_cache_file (@var{new_val})\n\
01274 @deftypefnx {Built-in Function} {} doc_cache_file (@var{new_val}, \"local\")\n\
01275 Query or set the internal variable that specifies the name of the\n\
01276 Octave documentation cache file. A cache file significantly improves\n\
01277 the performance of the @code{lookfor} command. The default value is \n\
01278 @file{@var{octave-home}/share/octave/@var{version}/etc/doc-cache},\n\
01279 in which @var{octave-home} is the root directory of the Octave installation,\n\
01280 and @var{version} is the Octave version number.\n\
01281 The default value may be overridden by the environment variable\n\
01282 @w{@env{OCTAVE_DOC_CACHE_FILE}}, or the command line argument\n\
01283 @samp{--doc-cache-file NAME}.\n\
01284 \n\
01285 When called from inside a function with the \"local\" option, the variable is\n\
01286 changed locally for the function and any subroutines it calls. The original\n\
01287 variable value is restored when exiting the function.\n\
01288 @seealso{lookfor, info_program, doc, help, makeinfo_program}\n\
01289 @end deftypefn")
01290 {
01291 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (doc_cache_file);
01292 }
01293
01294 DEFUN (info_file, args, nargout,
01295 "-*- texinfo -*-\n\
01296 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\
01297 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\
01298 @deftypefnx {Built-in Function} {} info_file (@var{new_val}, \"local\")\n\
01299 Query or set the internal variable that specifies the name of the\n\
01300 Octave info file. The default value is\n\
01301 @file{@var{octave-home}/info/octave.info}, in\n\
01302 which @var{octave-home} is the root directory of the Octave installation.\n\
01303 The default value may be overridden by the environment variable\n\
01304 @w{@env{OCTAVE_INFO_FILE}}, or the command line argument\n\
01305 @samp{--info-file NAME}.\n\
01306 \n\
01307 When called from inside a function with the \"local\" option, the variable is\n\
01308 changed locally for the function and any subroutines it calls. The original\n\
01309 variable value is restored when exiting the function.\n\
01310 @seealso{info_program, doc, help, makeinfo_program}\n\
01311 @end deftypefn")
01312 {
01313 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file);
01314 }
01315
01316 DEFUN (info_program, args, nargout,
01317 "-*- texinfo -*-\n\
01318 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\
01319 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\
01320 @deftypefnx {Built-in Function} {} info_program (@var{new_val}, \"local\")\n\
01321 Query or set the internal variable that specifies the name of the\n\
01322 info program to run. The default value is\n\
01323 @file{@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info}\n\
01324 in which @var{octave-home} is the root directory of the Octave installation,\n\
01325 @var{version} is the Octave version number, and @var{arch}\n\
01326 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\
01327 default value may be overridden by the environment variable\n\
01328 @w{@env{OCTAVE_INFO_PROGRAM}}, or the command line argument\n\
01329 @samp{--info-program NAME}.\n\
01330 \n\
01331 When called from inside a function with the \"local\" option, the variable is\n\
01332 changed locally for the function and any subroutines it calls. The original\n\
01333 variable value is restored when exiting the function.\n\
01334 @seealso{info_file, doc, help, makeinfo_program}\n\
01335 @end deftypefn")
01336 {
01337 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program);
01338 }
01339
01340 DEFUN (makeinfo_program, args, nargout,
01341 "-*- texinfo -*-\n\
01342 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\
01343 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\
01344 @deftypefnx {Built-in Function} {} makeinfo_program (@var{new_val}, \"local\")\n\
01345 Query or set the internal variable that specifies the name of the\n\
01346 program that Octave runs to format help text containing\n\
01347 Texinfo markup commands. The default value is @code{makeinfo}.\n\
01348 \n\
01349 When called from inside a function with the \"local\" option, the variable is\n\
01350 changed locally for the function and any subroutines it calls. The original\n\
01351 variable value is restored when exiting the function.\n\
01352 @seealso{info_file, info_program, doc, help}\n\
01353 @end deftypefn")
01354 {
01355 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program);
01356 }
01357
01358 DEFUN (suppress_verbose_help_message, args, nargout,
01359 "-*- texinfo -*-\n\
01360 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\
01361 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\
01362 @deftypefnx {Built-in Function} {} suppress_verbose_help_message (@var{new_val}, \"local\")\n\
01363 Query or set the internal variable that controls whether Octave\n\
01364 will add additional help information to the end of the output from\n\
01365 the @code{help} command and usage messages for built-in commands.\n\
01366 \n\
01367 When called from inside a function with the \"local\" option, the variable is\n\
01368 changed locally for the function and any subroutines it calls. The original\n\
01369 variable value is restored when exiting the function.\n\
01370 @end deftypefn")
01371 {
01372 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message);
01373 }