Typedefs | Functions | Variables

input.cc File Reference

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include "cmd-edit.h"
#include "file-ops.h"
#include "quit.h"
#include "str-vec.h"
#include "debug.h"
#include "defun.h"
#include "dirfns.h"
#include "error.h"
#include "gripes.h"
#include "help.h"
#include "input.h"
#include "lex.h"
#include "load-path.h"
#include "oct-map.h"
#include "oct-hist.h"
#include "toplev.h"
#include "oct-obj.h"
#include "pager.h"
#include "parse.h"
#include "pathlen.h"
#include "pt.h"
#include "pt-const.h"
#include "pt-eval.h"
#include "pt-stmt.h"
#include "sighandlers.h"
#include "sysdep.h"
#include "unwind-prot.h"
#include "utils.h"
#include "variables.h"
Include dependency graph for input.cc:

Go to the source code of this file.

Typedefs

typedef std::map< std::string,
octave_value
hook_fcn_map_type

Functions

 DEFUN (input, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} input (@var{prompt})\n\ @deftypefnx {Built-in Function} {} input (@var{prompt}, \"s\")\n\ Print a prompt and wait for user input. For example,\n\ \n\ @example\n\ input (\"Pick a number, any number! \")\n\ @end example\n\ \n\ @noindent\n\ prints the prompt\n\ \n\ @example\n\ Pick a number, any number!\n\ @end example\n\ \n\ @noindent\n\ and waits for the user to enter a value. The string entered by the user\n\ is evaluated as an expression, so it may be a literal constant, a\n\ variable name, or any other valid expression.\n\ \n\ Currently, @code{input} only returns one value, regardless of the number\n\ of values produced by the evaluation of the expression.\n\ \n\ If you are only interested in getting a literal string value, you can\n\ call @code{input} with the character string @code{\"s\"} as the second\n\ argument. This tells Octave to return the string entered by the user\n\ directly, without evaluating it first.\n\ \n\ Because there may be output waiting to be displayed by the pager, it is\n\ a good idea to always call @code{fflush (stdout)} before calling\n\ @code{input}. This will ensure that all pending output is written to\n\ the screen before your prompt. @xref{Input and Output}.\n\ @end deftypefn")
 DEFUN (filemarker, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} filemarker ()\n\ @deftypefnx {Built-in Function} {} filemarker (@var{new_val})\n\ @deftypefnx {Built-in Function} {} filemarker (@var{new_val}, \"local\")\n\ Query or set the character used to separate filename from the\n\ the subfunction names contained within the file. This can be used in\n\ a generic manner to interact with subfunctions. For example,\n\ \n\ @example\n\ help ([\"myfunc\", filemarker, \"mysubfunc\"])\n\ @end example\n\ \n\ @noindent\n\ returns the help string associated with the sub-function @code{mysubfunc}\n\ of the function @code{myfunc}. Another use of @code{filemarker} is when\n\ debugging it allows easier placement of breakpoints within sub-functions.\n\ For example,\n\ \n\ @example\n\ dbstop ([\"myfunc\", filemarker, \"mysubfunc\"])\n\ @end example\n\ \n\ @noindent\n\ will set a breakpoint at the first line of the subfunction @code{mysubfunc}.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @end deftypefn")
 DEFUN (yes_or_no, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} yes_or_no (@var{prompt})\n\ Ask the user a yes-or-no question. Return 1 if the answer is yes.\n\ Takes one argument, which is the string to display to ask the\n\ question. It should end in a space; @samp{yes-or-no-p} adds\n\ @samp{(yes or no) } to it. The user must confirm the answer with\n\ RET and can edit it until it has been confirmed.\n\ @end deftypefn")
 DEFUN (echo_executing_commands, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} echo_executing_commands ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\ @deftypefnx {Built-in Function} {} echo_executing_commands (@var{new_val}, \"local\")\n\ Query or set the internal variable that controls the echo state.\n\ It may be the sum of the following values:\n\ \n\ @table @asis\n\ @item 1\n\ Echo commands read from script files.\n\ \n\ @item 2\n\ Echo commands from functions.\n\ \n\ @item 4\n\ Echo commands read from command line.\n\ @end table\n\ \n\ More than one state can be active at once. For example, a value of 3 is\n\ equivalent to the command @kbd{echo on all}.\n\ \n\ The value of @code{echo_executing_commands} may be set by the @kbd{echo}\n\ command or the command line option @option{--echo-commands}.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @end deftypefn")
 DEFUN (__request_drawnow__, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\ @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\ Undocumented internal function.\n\ @end deftypefn")
 DEFUN (completion_append_char, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} completion_append_char ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\ @deftypefnx {Built-in Function} {} completion_append_char (@var{new_val}, \"local\")\n\ Query or set the internal character variable that is appended to\n\ successful command-line completion attempts. The default\n\ value is @code{\" \"} (a single space).\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @end deftypefn")
 DEFUN (__gud_mode__, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __gud_mode__ ()\n\ Undocumented internal function.\n\ @end deftypefn")
 DEFUN (keyboard, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} keyboard ()\n\ @deftypefnx {Built-in Function} {} keyboard (@var{prompt})\n\ This function is normally used for simple debugging. When the\n\ @code{keyboard} function is executed, Octave prints a prompt and waits\n\ for user input. The input strings are then evaluated and the results\n\ are printed. This makes it possible to examine the values of variables\n\ within a function, and to assign new values if necessary. To leave the\n\ prompt and return to normal execution type @samp{return} or @samp{dbcont}.\n\ The @code{keyboard} function does not return an exit status.\n\ \n\ If @code{keyboard} is invoked without arguments, a default prompt of\n\ @samp{debug> } is used.\n\ @seealso{dbcont, dbquit}\n\ @end deftypefn")
 DEFUN (echo, args,,"-*- texinfo -*-\n\ @deftypefn {Command} {} echo options\n\ Control whether commands are displayed as they are executed. Valid\n\ options are:\n\ \n\ @table @code\n\ @item on\n\ Enable echoing of commands as they are executed in script files.\n\ \n\ @item off\n\ Disable echoing of commands as they are executed in script files.\n\ \n\ @item on all\n\ Enable echoing of commands as they are executed in script files and\n\ functions.\n\ \n\ @item off all\n\ Disable echoing of commands as they are executed in script files and\n\ functions.\n\ @end table\n\ \n\ @noindent\n\ With no arguments, @code{echo} toggles the current echo state.\n\ @end deftypefn")
 DEFUN (completion_matches, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} completion_matches (@var{hint})\n\ Generate possible completions given @var{hint}.\n\ \n\ This function is provided for the benefit of programs like Emacs which\n\ might be controlling Octave and handling user input. The current\n\ command number is not incremented when this function is called. This is\n\ a feature, not a bug.\n\ @end deftypefn")
 DEFUN (read_readline_init_file, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} read_readline_init_file (@var{file})\n\ Read the readline library initialization file @var{file}. If\n\ @var{file} is omitted, read the default initialization file (normally\n\ @file{~/.inputrc}).\n\ \n\ @xref{Readline Init File, , , readline, GNU Readline Library},\n\ for details.\n\ @end deftypefn")
 DEFUN (re_read_readline_init_file, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} re_read_readline_init_file ()\n\ Re-read the last readline library initialization file that was read.\n\ @xref{Readline Init File, , , readline, GNU Readline Library},\n\ for details.\n\ @end deftypefn")
 DEFUN (add_input_event_hook, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} add_input_event_hook (@var{fcn})\n\ @deftypefnx {Built-in Function} {} add_input_event_hook (@var{fcn}, @var{data})\n\ Add the named function @var{fcn} to the list of functions to call\n\ periodically when Octave is waiting for input. The function should\n\ have the form\n\ \n\ @example\n\ @var{fcn} (@var{data})\n\ @end example\n\ \n\ If @var{data} is omitted, Octave calls the function without any\n\ arguments.\n\ @seealso{remove_input_event_hook}\n\ @end deftypefn")
 DEFUN (remove_input_event_hook, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} remove_input_event_hook (@var{fcn})\n\ Remove the named function @var{fcn} from the list of functions to call\n\ periodically when Octave is waiting for input.\n\ @seealso{add_input_event_hook}\n\ @end deftypefn")
 DEFUN (PS1, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} PS1 ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\ @deftypefnx {Built-in Function} {} PS1 (@var{new_val}, \"local\")\n\ Query or set the primary prompt string. When executing interactively,\n\ Octave displays the primary prompt when it is ready to read a command.\n\ \n\ The default value of the primary prompt string is @code{\"\\s:\\#> \"}.\n\ To change it, use a command like\n\ \n\ @example\n\ PS1 (\"\\\\u@@\\\\H> \")\n\ @end example\n\ \n\ @noindent\n\ which will result in the prompt @samp{boris@@kremvax> } for the user\n\ @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two\n\ backslashes are required to enter a backslash into a double-quoted\n\ character string. @xref{Strings}.\n\ \n\ You can also use ANSI escape sequences if your terminal supports them.\n\ This can be useful for coloring the prompt. For example,\n\ \n\ @example\n\ PS1 (\"\\\\[\\\\033[01;31m\\\\]\\\\s:\\\\#> \\\\[\\\\033[0m\\\\]\")\n\ @end example\n\ \n\ @noindent\n\ will give the default Octave prompt a red coloring.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{PS2, PS4}\n\ @end deftypefn")
 DEFUN (PS2, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} PS2 ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\ @deftypefnx {Built-in Function} {} PS2 (@var{new_val}, \"local\")\n\ Query or set the secondary prompt string. The secondary prompt is\n\ printed when Octave is expecting additional input to complete a\n\ command. For example, if you are typing a @code{for} loop that spans several\n\ lines, Octave will print the secondary prompt at the beginning of\n\ each line after the first. The default value of the secondary prompt\n\ string is @code{\"> \"}.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{PS1, PS4}\n\ @end deftypefn")
 DEFUN (PS4, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} PS4 ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\ @deftypefnx {Built-in Function} {} PS4 (@var{new_val}, \"local\")\n\ Query or set the character string used to prefix output produced\n\ when echoing commands is enabled.\n\ The default value is @code{\"+ \"}.\n\ @xref{Diary and Echo Commands}, for a description of echoing commands.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{echo, echo_executing_commands, PS1, PS2}\n\ @end deftypefn")
static void do_input_echo (const std::string &input_string)
octave_value do_keyboard (const octave_value_list &args)
static std::string generate_completion (const std::string &text, int state)
static string_vector generate_possible_completions (const std::string &text, std::string &prefix, std::string &hint)
static void get_debug_input (const std::string &prompt)
FILE * get_input_from_file (const std::string &name, int warn)
FILE * get_input_from_stdin (void)
static std::string get_user_input (void)
static octave_value_list get_user_input (const octave_value_list &args, int nargout)
std::string gnu_readline (const std::string &s, bool force_readline)
void initialize_command_input (void)
static int input_event_hook (void)
static std::string interactive_input (const std::string &s, bool force_readline=false)
static bool is_completing_dirfns (void)
static std::string octave_gets (void)
int octave_read (char *buf, unsigned max_size)
bool octave_yes_or_no (const std::string &prompt)
static std::string quoting_filename (const std::string &text, int, char quote)

Variables

std::string curr_fcn_file_full_name
std::string curr_fcn_file_name
std::string current_eval_string
std::string current_input_line
FILE * ff_instream = 0
bool forced_interactive = false
bool get_input_from_eval_string = false
static hook_fcn_map_type hook_fcn_map
bool input_from_command_line_file = false
bool input_from_eval_string_pending = false
bool interactive = false
static std::string last_debugging_command
bool octave_completion_matches_called = false
int promptflag = 1
bool reading_classdef_file = false
bool reading_fcn_file = false
bool reading_script_file = false
bool stdin_is_tty = false
static char Vcompletion_append_char = ' '
bool Vdebugging = false
bool Vdrawnow_requested = false
int Vecho_executing_commands = ECHO_OFF
char Vfilemarker = '>'
static bool Vgud_mode = false
octave_time Vlast_prompt_time = 0.0
static std::string VPS1 = "\\s:\\#> "
static std::string VPS2 = "> "
std::string VPS4 = "+ "

Typedef Documentation

typedef std::map<std::string, octave_value> hook_fcn_map_type

Definition at line 1237 of file input.cc.


Function Documentation

DEFUN ( input  ,
args  ,
nargout   
)

Definition at line 844 of file input.cc.

References get_user_input(), and print_usage().

DEFUN ( filemarker  ,
args  ,
nargout   
)

Definition at line 1528 of file input.cc.

References error(), error_state, and SET_INTERNAL_VARIABLE.

DEFUN ( yes_or_no  ,
args   
)

Definition at line 910 of file input.cc.

References error(), error_state, octave_yes_or_no(), and print_usage().

DEFUN ( echo_executing_commands  ,
args  ,
nargout   
)

Definition at line 1454 of file input.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( __request_drawnow__  ,
args   
)

Definition at line 1487 of file input.cc.

References print_usage(), and Vdrawnow_requested.

DEFUN ( completion_append_char  ,
args  ,
nargout   
)

Definition at line 1437 of file input.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( __gud_mode__  ,
args   
)

Definition at line 1508 of file input.cc.

References print_usage(), and Vgud_mode.

DEFUN ( keyboard  ,
args   
)
DEFUN ( echo  ,
args   
)

Definition at line 1029 of file input.cc.

References arg(), ECHO_FUNCTIONS, ECHO_SCRIPTS, error_state, and print_usage().

DEFUN ( completion_matches  ,
args  ,
nargout   
)
DEFUN ( read_readline_init_file  ,
args   
)

Definition at line 1189 of file input.cc.

References error_state, print_usage(), and command_editor::read_init_file().

DEFUN ( re_read_readline_init_file  ,
args   
)

Definition at line 1219 of file input.cc.

References print_usage(), and command_editor::re_read_init_file().

DEFUN ( add_input_event_hook  ,
args   
)
DEFUN ( remove_input_event_hook  ,
args   
)
DEFUN ( PS1  ,
args  ,
nargout   
)

Definition at line 1357 of file input.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( PS2  ,
args  ,
nargout   
)

Definition at line 1397 of file input.cc.

References SET_INTERNAL_VARIABLE.

DEFUN ( PS4  ,
args  ,
nargout   
)

Definition at line 1418 of file input.cc.

References SET_INTERNAL_VARIABLE.

static void do_input_echo ( const std::string &  input_string  )  [static]
octave_value do_keyboard ( const octave_value_list args  ) 
static std::string generate_completion ( const std::string &  text,
int  state 
) [static]
static string_vector generate_possible_completions ( const std::string &  text,
std::string &  prefix,
std::string &  hint 
) [static]
static void get_debug_input ( const std::string &  prompt  )  [static]
FILE* get_input_from_file ( const std::string &  name,
int  warn 
)
FILE* get_input_from_stdin ( void   ) 
static std::string get_user_input ( void   )  [static]
static octave_value_list get_user_input ( const octave_value_list args,
int  nargout 
) [static]
std::string gnu_readline ( const std::string &  s,
bool  force_readline 
)
void initialize_command_input ( void   ) 
static int input_event_hook ( void   )  [static]
static std::string interactive_input ( const std::string &  s,
bool  force_readline = false 
) [inline, static]
static bool is_completing_dirfns ( void   )  [static]
static std::string octave_gets ( void   )  [static]
int octave_read ( char buf,
unsigned  max_size 
)

Definition at line 362 of file input.cc.

References get_user_input().

bool octave_yes_or_no ( const std::string &  prompt  ) 

Definition at line 893 of file input.cc.

References interactive_input(), and message().

Referenced by DEFUN(), and DEFUNX().

static std::string quoting_filename ( const std::string &  text,
int  ,
char  quote 
) [static]

Definition at line 593 of file input.cc.

Referenced by initialize_command_input().


Variable Documentation

Definition at line 124 of file input.cc.

Referenced by execute_command_line_file().

std::string curr_fcn_file_name

Definition at line 121 of file input.cc.

Referenced by execute_command_line_file(), and tree_checker::gripe().

std::string current_eval_string

Definition at line 98 of file input.cc.

Referenced by get_user_input().

std::string current_input_line

Definition at line 142 of file input.cc.

Referenced by get_user_input(), and octave_gets().

FILE* ff_instream = 0

Definition at line 130 of file input.cc.

Referenced by get_input_from_file(), and gnu_readline().

Definition at line 101 of file input.cc.

Referenced by get_debug_input(), get_user_input(), and octave_gets().

Definition at line 1239 of file input.cc.

Referenced by DEFUN(), and input_event_hook().

Definition at line 109 of file input.cc.

Referenced by execute_command_line_file(), get_debug_input(), and octave_gets().

Definition at line 105 of file input.cc.

Referenced by get_user_input().

bool interactive = false
std::string last_debugging_command [static]

Definition at line 156 of file input.cc.

Referenced by octave_gets().

Definition at line 145 of file input.cc.

Referenced by DEFUN(), get_debug_input(), and main_loop().

Definition at line 139 of file input.cc.

Definition at line 118 of file input.cc.

Referenced by get_debug_input(), get_input_from_file(), gnu_readline(), and octave_gets().

Definition at line 115 of file input.cc.

Referenced by get_debug_input(), get_input_from_file(), gnu_readline(), and octave_gets().

bool stdin_is_tty = false

Definition at line 112 of file input.cc.

Referenced by octave_main().

char Vcompletion_append_char = ' ' [static]

Definition at line 95 of file input.cc.

bool Vdebugging = false

Definition at line 149 of file input.cc.

Referenced by DEFUN(), delete_graphics_object(), interactive_input(), and make_graphics_object().

bool Vgud_mode = false [static]

Definition at line 159 of file input.cc.

Referenced by DEFUN(), and get_debug_input().

Definition at line 92 of file input.cc.

Referenced by out_of_date_check(), and rehash_internal().

std::string VPS1 = "\\s:\\#> " [static]

Definition at line 74 of file input.cc.

Referenced by do_input_echo(), get_debug_input(), and octave_gets().

std::string VPS2 = "> " [static]

Definition at line 77 of file input.cc.

Referenced by do_input_echo(), and octave_gets().

std::string VPS4 = "+ "
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines