"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main.c" between
rlwrap-0.45.tar.gz and rlwrap-0.45.1.tar.gz

About: rlwrap is a "readline wrapper" allowing the editing of keyboard input for any command.

main.c  (rlwrap-0.45):main.c  (rlwrap-0.45.1)
skipping to change at line 72 skipping to change at line 72
int i_am_child = FALSE; /* Am I child or parent? aft er forking, child will set this to TRUE */ int i_am_child = FALSE; /* Am I child or parent? aft er forking, child will set this to TRUE */
int i_am_filter = FALSE; /* After forking, filter will set th is to TRUE */ int i_am_filter = FALSE; /* After forking, filter will set th is to TRUE */
int ignore_queued_input = FALSE; /* read and then ignore all charact ers in input queue until it is empty (i.e. read would block) */ int ignore_queued_input = FALSE; /* read and then ignore all charact ers in input queue until it is empty (i.e. read would block) */
int received_WINCH = FALSE; /* flag set in SIGWINCH signal hand ler: start line edit as soon as possible */ int received_WINCH = FALSE; /* flag set in SIGWINCH signal hand ler: start line edit as soon as possible */
int prompt_is_still_uncooked = TRUE; /* The main loop consults this vari able to determine the select() timeout: when TRUE, it is int prompt_is_still_uncooked = TRUE; /* The main loop consults this vari able to determine the select() timeout: when TRUE, it is
a few millisecs, if FALSE, it is infinite. a few millisecs, if FALSE, it is infinite.
TRUE just after receiving comman d output (when we still don't know whether we have a TRUE just after receiving comman d output (when we still don't know whether we have a
prompt), and, importantly, at st artup (so that substitute prompts get displayed even with prompt), and, importantly, at st artup (so that substitute prompts get displayed even with
programs that don't have a start up message, such as cat) */ programs that don't have a start up message, such as cat) */
int we_just_got_a_signal_or_EOF = FALSE; /* When we got a signal or EOF, and the program sends something that ends in a newline, take it int we_just_got_a_signal_or_EOF = FALSE; /* When we got a signal or EOF, and the program sends something that ends in a newline, take it
as a response to user input - i.e. preserve a cooked prompt and just print the new output after it */ as a response to user input - i.e. preserve a cooked prompt and just print the new output after it */
int rlwrap_already_prompted = FALSE; int rlwrap_already_prompted = FALSE;
int accepted_lines = 0; /* number of lines accepted (used for one-shot rlwrap) int accepted_lines = 0; /* number of lines accepted (used f
*/ or one-shot rlwrap) */
bool user_has_typed_first_NL = FALSE; /* When the *first* user NL is type
d in direct mode, we probably need --always-readline: give a warning, .. */
bool advise_always_readline = FALSE; /* ... which has to be given a bit
later in order to not mess up the screen */
/* private variables */ /* private variables */
static char *history_filename = NULL; static char *history_filename = NULL;
static int histsize = 300; static int histsize = 300;
static int write_histfile = TRUE; static int write_histfile = TRUE;
static char *completion_filename, *default_completion_filename; static char *completion_filename, *default_completion_filename;
static char *full_program_name; static char *full_program_name;
static int last_option_didnt_have_optional_argument = FALSE; static int last_option_didnt_have_optional_argument = FALSE;
static int last_opt = -1; static int last_opt = -1;
static char *client_term_name = NULL; /* we'll set TERM to this before exec'ing client command */ static char *client_term_name = NULL; /* we'll set TERM to this before exec'ing client command */
skipping to change at line 439 skipping to change at line 441
} else { } else {
myerror(FATAL|USE_ERRNO, "read error on master pty"); myerror(FATAL|USE_ERRNO, "read error on master pty");
} }
} }
remove_padding_and_terminate(buf, nread); remove_padding_and_terminate(buf, nread);
completely_mirror_slaves_output_settings(); /* some programs (e.g. joe) n eed this. Gasp!! */ completely_mirror_slaves_output_settings(); /* some programs (e.g. joe) n eed this. Gasp!! */
mirror_args(command_pid); mirror_args(command_pid);
check_cupcodes(buf); check_cupcodes(buf);
if (skip_rlwrap()) { /* Race condition here! The client may just have fi nished an emacs session and if (skip_rlwrap()) { /* Race condition here! The client may just have fi nished an emacs session and
returned to cooked mode, while its ncurses-riddle d output is stil waiting for us to be processed. */ returned to cooked mode, while its ncurses-riddle d output is stil waiting for us to be processed. */
write_patiently(STDOUT_FILENO, buf, nread, "to stdout"); if (advise_always_readline) {
char *newlines = "\n\n";
assert(!always_readline);
write_patiently(STDOUT_FILENO, newlines, strlen(newlines), "to stdou
t"); /* make the following warning stand out ... */
myerror(WARNING|NOERRNO, "rlwrap appears to do nothing for %s, which
asks for\n"
"single keypresses all the time. Don't you
need --always-readline\n"
"and possibly --no-children? (cf. the rlwra
p manpage)\n", command_name);
advise_always_readline = FALSE;
}
write_patiently(STDOUT_FILENO, buf, nread, "to stdout"); /* ... and pr
int it before the clients output */
DPRINTF1(DEBUG_AD_HOC, "advise_always_readline = %d", advise_always_re
adline);
DPRINTF2(DEBUG_TERMIO, "read from pty and wrote to stdout %d bytes in direct mode <%s>", nread, M(buf)); DPRINTF2(DEBUG_TERMIO, "read from pty and wrote to stdout %d bytes in direct mode <%s>", nread, M(buf));
yield(); yield();
continue; continue;
} }
DPRINTF2(DEBUG_TERMIO, "read %d bytes from pty into buffer: %s", nread, M (buf)); DPRINTF2(DEBUG_TERMIO, "read %d bytes from pty into buffer: %s", nread, M (buf));
write_logfile(buf); write_logfile(buf);
if (within_line_edit) /* client output arrives while we're editing keyb oard input: */ if (within_line_edit) /* client output arrives while we're editing keyb oard input: */
save_rl_state(); /* temporarily disable readline and restore the s creen state before readline was called */ save_rl_state(); /* temporarily disable readline and restore the s creen state before readline was called */
skipping to change at line 552 skipping to change at line 563
else if (nread == 0) /* EOF on stdin */ else if (nread == 0) /* EOF on stdin */
cleanup_rlwrap_and_exit(EXIT_SUCCESS); cleanup_rlwrap_and_exit(EXIT_SUCCESS);
else if (ignore_queued_input) else if (ignore_queued_input)
continue; /* do nothing with it*/ continue; /* do nothing with it*/
assert(nread == 1); assert(nread == 1);
DPRINTF2(DEBUG_TERMIO, "read from stdin: byte 0x%02x (%s)", byte_read, ma ngle_char_for_debug_log(byte_read, TRUE)); DPRINTF2(DEBUG_TERMIO, "read from stdin: byte 0x%02x (%s)", byte_read, ma ngle_char_for_debug_log(byte_read, TRUE));
if (skip_rlwrap()) { /* direct mode, just pass it on */ if (skip_rlwrap()) { /* direct mode, just pass it on */
/* remote possibility of a race condition here: w hen the first half of a multi-byte char is read in /* remote possibility of a race condition here: w hen the first half of a multi-byte char is read in
direct mode and the second half in readline mo de. Oh well... */ direct mode and the second half in readline mo de. Oh well... */
DPRINTF0(DEBUG_TERMIO, "passing it on (in transparent mode)"); DPRINTF0(DEBUG_TERMIO, "passing it on (in transparent mode)");
if (!user_has_typed_first_NL && (byte_read == '\r' || byte_read == '\n
')) {
user_has_typed_first_NL = TRUE;
advise_always_readline = TRUE; /* first NL is in direct mode: advise
the user that she probably wants --always-readline */
}
completely_mirror_slaves_terminal_settings(); /* this is of course 1 ke ypress too late: we should completely_mirror_slaves_terminal_settings(); /* this is of course 1 ke ypress too late: we should
mirror the terminal se ttings *before* the user presses a key. mirror the terminal se ttings *before* the user presses a key.
(maybe using rl_event_ hook??) @@@FIXME @@@ HOW?*/ (maybe using rl_event_ hook??) @@@FIXME @@@ HOW?*/
write_patiently(master_pty_fd, &byte_read, 1, "to master pty"); write_patiently(master_pty_fd, &byte_read, 1, "to master pty");
} else { /* hand it over to readline */ } else { /* hand it over to readline */
if (!within_line_edit) { /* start a new line edit */ if (!within_line_edit) { /* start a new line edit */
DPRINTF0(DEBUG_READLINE, "Starting line edit"); DPRINTF0(DEBUG_READLINE, "Starting line edit");
within_line_edit = TRUE; within_line_edit = TRUE;
restore_rl_state(); restore_rl_state();
} }
skipping to change at line 689 skipping to change at line 705
} }
/* /*
* On systems where getopt doens't handle optional argments, warn the user whene ver an * On systems where getopt doens't handle optional argments, warn the user whene ver an
* argument of the form -<letter> is seen, or whenever the argument is the last item on the command line * argument of the form -<letter> is seen, or whenever the argument is the last item on the command line
* (e.g. 'rlwrap -a command', which will be parsed as 'rlwrap --always-readline= command') * (e.g. 'rlwrap -a command', which will be parsed as 'rlwrap --always-readline= command')
*/ */
static char * static char *
check_optarg(char opt, int remaining) check_optarg(char opt, int remaining, bool isdummy, const char *suggestion)
{ {
MAYBE_UNUSED(opt); MAYBE_UNUSED(remaining); MAYBE_UNUSED(opt); MAYBE_UNUSED(remaining); MAYBE_UNUSED(isdummy); MAYBE_UNUSE D(suggestion);
if (!optarg) if (!optarg)
last_option_didnt_have_optional_argument = TRUE; /* if this variable is set, and if command is not found, last_option_didnt_have_optional_argument = TRUE; /* if this variable is set, and if command is not found,
suggest that it may have been meant suggest that it may have been meant
as optional argument (e.g . 'rlwrap -a password sqlplus' will try to as optional argument (e.g . 'rlwrap -a password sqlplus' will try to
execute 'password sqlplus ' ) */ execute 'password sqlplus ' ) */
#ifndef GETOPT_GROKS_OPTIONAL_ARGS #ifndef GETOPT_GROKS_OPTIONAL_ARGS
if (optarg && /* is there an optional arg? have a look at it: */ if (optarg && /* is there an optional arg? have a look at it: */
((optarg[0] == '-' && isalpha(optarg[1])) || /* looks like next option */ ((optarg[0] == '-' && (optarg[1] == '-' || isalpha(optarg[1]))) || /* look
s like next option */
remaining == 0)) /* or is last item on command line */ remaining == 0)) /* or is last item on command line */
myerror(WARNING|NOERRNO, "on this system, the getopt() library function does n't\n" myerror(WARNING|NOERRNO, "on this system, the getopt() library function does n't\n"
"grok optional arguments, so '%s' is taken as an argument to the -%c opti on\n" "grok optional arguments, so '%s' is taken as an argument to the -%c opti on\n"
"Is this what you meant? If not, please provide an argument", optarg, opt ); "Is this what you meant? If not, please provide %s argument like '% s'", optarg, opt, isdummy ? "a dummy" : "an", suggestion);
#endif #endif
return optarg; return optarg;
} }
/* find name of current option /* find name of current option
*/ */
static const char * static const char *
current_option(int opt, int longindex) current_option(int opt, int longindex)
{ {
skipping to change at line 762 skipping to change at line 778
if (c == EOF) if (c == EOF)
break; break;
option_count++; option_count++;
last_option_didnt_have_optional_argument = FALSE; last_option_didnt_have_optional_argument = FALSE;
remaining = argc - optind; remaining = argc - optind;
last_opt = c; last_opt = c;
switch (c) { switch (c) {
case 'a': case 'a':
always_readline = TRUE; always_readline = TRUE;
if (check_optarg('a', remaining)) if (check_optarg('a', remaining, TRUE, "brumbleslurgh"))
password_prompt_search_string = mysavestring(optarg); password_prompt_search_string = mysavestring(optarg);
break; break;
case 'A': case 'A':
ansi_colour_aware = TRUE; ansi_colour_aware = TRUE;
if (check_optarg('A', remaining) && strings_are_equal(optarg, "!")) if (check_optarg('A', remaining, TRUE, "") && strings_are_equal(optarg, "! "))
bleach_the_prompt = TRUE; bleach_the_prompt = TRUE;
break; break;
case 'b': case 'b':
rl_basic_word_break_characters = add3strings("\r\n \t", optarg, ""); rl_basic_word_break_characters = add3strings("\r\n \t", optarg, "");
opt_b = TRUE; opt_b = TRUE;
break; break;
case 'c': complete_filenames = TRUE; case 'c': complete_filenames = TRUE;
#ifndef CAN_FOLLOW_COMMANDS_CWD #ifndef CAN_FOLLOW_COMMANDS_CWD
myerror(WARNING|NOERRNO, "On this system rlwrap cannot follow th e rlwrapped command's working directory:\n" myerror(WARNING|NOERRNO, "On this system rlwrap cannot follow th e rlwrapped command's working directory:\n"
"filename completion will only be relat ive to rlwrap's own working directory "); "filename completion will only be relat ive to rlwrap's own working directory ");
#endif #endif
break; break;
case 'C': opt_C = mysavestring(optarg); break; case 'C': opt_C = mysavestring(optarg); break;
case 'd': case 'd':
#ifdef DEBUG #ifdef DEBUG
if (option_count > 1) if (option_count > 1)
myerror(FATAL|NOERRNO, "-d or --debug option has to be the *first* rlwra p option\n" myerror(FATAL|NOERRNO, "-d or --debug option has to be the *first* rlwra p option\n"
"in order to be able to follow the processing of all subsequent options"); "in order to be able to follow the processing of all subsequent options");
debug = check_optarg('d', remaining) ? my_atoi(optarg) : DEBUG_DEFAULT; debug = check_optarg('d', remaining, FALSE, "7") ? my_atoi(optarg) : DEBUG _DEFAULT;
my_fopen(&debug_fp, DEBUG_FILENAME, "w+", "debug log"); /* w+, not w: both parent and child write to the same logfile, and need to fseek beyond where the other may have written stuff */ my_fopen(&debug_fp, DEBUG_FILENAME, "w+", "debug log"); /* w+, not w: both parent and child write to the same logfile, and need to fseek beyond where the other may have written stuff */
#else #else
myerror(FATAL|NOERRNO, "To use -d( for debugging), configure %s with --ena ble-debug and rebuild",program_name); myerror(FATAL|NOERRNO, "To use -d( for debugging), configure %s with --ena ble-debug and rebuild",program_name);
#endif #endif
break; break;
case 'D': case 'D':
history_duplicate_avoidance_policy=my_atoi(optarg); history_duplicate_avoidance_policy=my_atoi(optarg);
if (history_duplicate_avoidance_policy < 0 || history_duplicate_avoidance_ policy > 2) if (history_duplicate_avoidance_policy < 0 || history_duplicate_avoidance_ policy > 2)
myerror(FATAL|NOERRNO, "%s option with illegal value %d, should be 0, 1 or 2", myerror(FATAL|NOERRNO, "%s option with illegal value %d, should be 0, 1 or 2",
skipping to change at line 828 skipping to change at line 844
myerror(FATAL|NOERRNO, "-i option has to precede -f options"); myerror(FATAL|NOERRNO, "-i option has to precede -f options");
completion_is_case_sensitive = FALSE; completion_is_case_sensitive = FALSE;
break; break;
case 'I': pass_on_sigINT_as_sigTERM = TRUE; break; case 'I': pass_on_sigINT_as_sigTERM = TRUE; break;
case 'l': open_logfile(optarg); break; case 'l': open_logfile(optarg); break;
case 'n': nowarn = TRUE; break; case 'n': nowarn = TRUE; break;
case 'm': case 'm':
#ifndef HAVE_SYSTEM #ifndef HAVE_SYSTEM
myerror(WARNING|NOERRNO, "the -m option doesn't work on this system"); myerror(WARNING|NOERRNO, "the -m option doesn't work on this system");
#endif #endif
multiline_separator = multiline_separator = /* \\\\ will be printed as \\ which is correct if we
(check_optarg('m', remaining) ? mysavestring(optarg) : " \\ "); want ' \ ' to be the multiline separator */
(check_optarg('m', remaining, FALSE, " \\\\ ") ? mysavestring(optarg) :
" \\ ");
break; break;
case 'M': multi_line_tmpfile_ext = mysavestring(optarg); break; case 'M': multi_line_tmpfile_ext = mysavestring(optarg); break;
case 'N': commands_children_not_wrapped = TRUE; break; case 'N': commands_children_not_wrapped = TRUE; break;
case 'o': case 'o':
one_shot_rlwrap = TRUE; break; one_shot_rlwrap = TRUE; break;
case 'O': prompt_regexp = mysavestring(optarg); case 'O': prompt_regexp = mysavestring(optarg);
if (*prompt_regexp == '!') { if (*prompt_regexp == '!') {
regexp_means_prompt = TRUE; regexp_means_prompt = TRUE;
prompt_regexp += 1; prompt_regexp += 1;
} }
match_regexp("complain NOW if regexp is wrong", prompt_regexp, 1); match_regexp("complain NOW if regexp is wrong", prompt_regexp, 1);
break; break;
case 'p': case 'p':
colour_the_prompt = TRUE; colour_the_prompt = TRUE;
initialise_colour_codes(check_optarg('p', remaining) ? initialise_colour_codes(check_optarg('p', remaining, FALSE, "Red") ?
colour_name_to_ansi_code(optarg) : colour_name_to_ansi_code(optarg) :
colour_name_to_ansi_code("Red")); colour_name_to_ansi_code("Red"));
break; break;
case 'P': case 'P':
pre_given = mysavestring(optarg); pre_given = mysavestring(optarg);
always_readline = TRUE; /* pre_given does not work well with transparent m ode */ always_readline = TRUE; /* pre_given does not work well with transparent m ode */
break; break;
case 'q': rl_basic_quote_characters = mysavestring(optarg); break; case 'q': rl_basic_quote_characters = mysavestring(optarg); break;
case 'r': remember_for_completion = TRUE; break; case 'r': remember_for_completion = TRUE; break;
 End of changes. 13 change blocks. 
16 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)