From 38e721a74a30bad0885a0edbdd35f0e6378fe475 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Wed, 16 Dec 2009 11:50:47 +0100 Subject: [PATCH] Use read_stdin_line() for selections from a pipe. This makes it possible to log all selection input from stdin within this single function (necessary for history). --- src/gmxlib/selection/parsetree.c | 6 ++---- src/gmxlib/selection/scanner_internal.c | 14 ++++++++++---- src/gmxlib/selection/scanner_internal.h | 6 ------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/gmxlib/selection/parsetree.c b/src/gmxlib/selection/parsetree.c index 26b8f007cc..3e5c6e0b21 100644 --- a/src/gmxlib/selection/parsetree.c +++ b/src/gmxlib/selection/parsetree.c @@ -1364,10 +1364,8 @@ gmx_ana_selcollection_parse_stdin(gmx_ana_selcollection_t *sc, int nr, { return rc; } - if (!bInteractive) - { - _gmx_sel_set_lex_input_file(scanner, stdin); - } + /* We don't set the lexer input here, which causes it to use a special + * internal implementation for reading from stdin. */ return run_parser(nr, scanner); } diff --git a/src/gmxlib/selection/scanner_internal.c b/src/gmxlib/selection/scanner_internal.c index 76dffa05f2..7141cd42fa 100644 --- a/src/gmxlib/selection/scanner_internal.c +++ b/src/gmxlib/selection/scanner_internal.c @@ -93,7 +93,10 @@ read_stdin_line(gmx_sel_lexer_t *state) totlen += len; if (len >= 2 && ptr[len - 1] == '\n' && ptr[len - 2] == '\\') { - fprintf(stderr, "... "); + if (state->bInteractive) + { + fprintf(stderr, "... "); + } } else if (len >= 1 && ptr[len - 1] == '\n') { @@ -101,7 +104,10 @@ read_stdin_line(gmx_sel_lexer_t *state) } else if (len < max_len - 1) { - fprintf(stderr, "\n"); + if (state->bInteractive) + { + fprintf(stderr, "\n"); + } break; } ptr += len; @@ -128,7 +134,7 @@ _gmx_sel_yyblex(YYSTYPE *yylval, yyscan_t yyscanner) gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(yyscanner); int token; - if (state->bInteractive && !state->inputstr) + if (!state->bBuffer && !state->inputstr) { state->nalloc_input = 1024; snew(state->inputstr, state->nalloc_input); @@ -136,7 +142,7 @@ _gmx_sel_yyblex(YYSTYPE *yylval, yyscan_t yyscanner) _gmx_sel_set_lex_input_str(yyscanner, state->inputstr); } token = _gmx_sel_yylex(yylval, yyscanner); - while (state->bInteractive && token == 0 && read_stdin_line(state)) + while (state->inputstr && token == 0 && read_stdin_line(state)) { _gmx_sel_set_lex_input_str(yyscanner, state->inputstr); token = _gmx_sel_yylex(yylval, yyscanner); diff --git a/src/gmxlib/selection/scanner_internal.h b/src/gmxlib/selection/scanner_internal.h index b9d91c398c..5b74ec9f2a 100644 --- a/src/gmxlib/selection/scanner_internal.h +++ b/src/gmxlib/selection/scanner_internal.h @@ -100,12 +100,6 @@ _gmx_sel_lexer_process_pending(YYSTYPE *, gmx_sel_lexer_t *state); int _gmx_sel_lexer_process_identifier(YYSTYPE *, char *, size_t, gmx_sel_lexer_t *state); -/** Internal helper function that prints a prompt if appropriate. */ -void -_gmx_sel_lexer_prompt_print(gmx_sel_lexer_t *state); -/** Internal helper function that updates the prompt after a newline. */ -void -_gmx_sel_lexer_prompt_newline(bool bContinue, gmx_sel_lexer_t *state); /** Internal function to add a token to the pretty-printed selection text. */ void _gmx_sel_lexer_add_token(const char *str, int len, gmx_sel_lexer_t *state); -- 2.11.4.GIT