From db22e07d0720f6045f5bf203e115511499fbdcbc Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 22 Feb 2023 21:05:07 +0800 Subject: [PATCH] stdio: Remove CONFIG_EOL_IS_XXX Signed-off-by: Huang Qi --- interpreters/bas/bas_fs.c | 73 +++++-------- system/cle/cle.c | 40 ------- system/readline/readline.h | 28 ----- system/readline/readline_common.c | 6 -- system/vi/vi.c | 169 ------------------------------ 5 files changed, 26 insertions(+), 290 deletions(-) diff --git a/interpreters/bas/bas_fs.c b/interpreters/bas/bas_fs.c index a959c407c..a34d2ac05 100644 --- a/interpreters/bas/bas_fs.c +++ b/interpreters/bas/bas_fs.c @@ -294,64 +294,43 @@ static int edit(int chn, int nl) } else if ((f->inCapacity + 1) < sizeof(f->inBuf)) { -#ifdef CONFIG_EOL_IS_BOTH_CRLF - /* Ignore carriage returns that may accompany a CRLF sequence. */ + /* Is this a new line character */ - if (ch != '\r') -#endif + if (ch != '\n') { - /* Is this a new line character */ + /* No.. escape control characters other than newline and + * carriage return + */ -#ifdef CONFIG_EOL_IS_CR - if (ch != '\r') -#elif defined(CONFIG_EOL_IS_LF) - if (ch != '\n') -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) - if (ch != '\n' && ch != '\r') -#endif + if (ch >= '\0' && ch < ' ') { - /* No.. escape control characters other than newline and - * carriage return - */ - - if (ch >= '\0' && ch < ' ') - { - FS_putChar(chn, '^'); - FS_putChar(chn, ch ? (ch + 'a' - 1) : '@'); - } - - /* Output normal, printable characters */ - - else - { - FS_putChar(chn, ch); - } + FS_putChar(chn, '^'); + FS_putChar(chn, ch ? (ch + 'a' - 1) : '@'); } - /* It is a newline */ + /* Output normal, printable characters */ else { - /* Echo the newline (or not). We always use newline - * termination when talking to the host. - */ - - if (nl) - { - FS_putChar(chn, '\n'); - } - -#if defined(CONFIG_EOL_IS_CR) || defined(CONFIG_EOL_IS_EITHER_CRLF) - /* If the host is talking to us with CR line terminations, - * switch to use LF internally. - */ - - ch = '\n'; -#endif + FS_putChar(chn, ch); } - - f->inBuf[f->inCapacity++] = ch; } + + /* It is a newline */ + + else + { + /* Echo the newline (or not). We always use newline + * termination when talking to the host. + */ + + if (nl) + { + FS_putChar(chn, '\n'); + } + } + + f->inBuf[f->inCapacity++] = ch; } } while (ch != '\n'); diff --git a/system/cle/cle.c b/system/cle/cle.c index 0bcff8d6c..993f9d92f 100644 --- a/system/cle/cle.c +++ b/system/cle/cle.c @@ -45,34 +45,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - /* Control characters */ #undef CTRL @@ -1077,14 +1049,7 @@ static int cle_editloop(FAR struct cle_s *priv) /* Newline terminates editing. But what is a newline? */ -#if defined(CONFIG_EOL_IS_EITHER_CRLF) - case '\r': /* CR terminates line */ case '\n': /* LF terminates line */ -#elif defined(CONFIG_EOL_IS_CR) - case '\r': /* CR terminates line */ -#elif defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\n': /* LF terminates line */ -#endif { /* Add the newline to the buffer at the end of the line */ @@ -1095,11 +1060,6 @@ static int cle_editloop(FAR struct cle_s *priv) } break; -#if defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - /* Text to insert or unimplemented/invalid keypresses */ default: diff --git a/system/readline/readline.h b/system/readline/readline.h index 571a8a4b4..58ebc1caa 100644 --- a/system/readline/readline.h +++ b/system/readline/readline.h @@ -31,34 +31,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - /* Helper macros */ #define RL_GETC(v) ((v)->rl_getc(v)) diff --git a/system/readline/readline_common.c b/system/readline/readline_common.c index 0dc79d414..15ed36880 100644 --- a/system/readline/readline_common.c +++ b/system/readline/readline_common.c @@ -667,13 +667,7 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, * others both. */ -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) else if (ch == '\n') -#elif defined(CONFIG_EOL_IS_CR) - else if (ch == '\r') -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) - else if (ch == '\n' || ch == '\r') -#endif { #ifdef CONFIG_READLINE_CMD_HISTORY /* Save history of command, only if there was something diff --git a/system/vi/vi.c b/system/vi/vi.c index 95f20b724..b6b09f2ad 100644 --- a/system/vi/vi.c +++ b/system/vi/vi.c @@ -57,34 +57,6 @@ # define CONFIG_SYSTEM_VI_COLS 64 #endif -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - #ifndef CONFIG_SYSTEM_VI_YANK_THRESHOLD #define CONFIG_SYSTEM_VI_YANK_THRESHOLD 128 #endif @@ -4099,21 +4071,6 @@ static void vi_cmd_mode(FAR struct vi_s *vi) } break; -#if defined(CONFIG_EOL_IS_CR) - case KEY_CMDMODE_NEXTLINE: - case '\r': /* CR terminates line */ - { - vi->curpos = vi_nextline(vi, vi->curpos); - vi_gotofirstnonwhite(vi); - } - break; - -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) case KEY_CMDMODE_NEXTLINE: case '\n': /* LF terminates line */ { @@ -4121,18 +4078,6 @@ static void vi_cmd_mode(FAR struct vi_s *vi) vi_gotofirstnonwhite(vi); } break; -#endif - -#ifdef CONFIG_EOL_IS_EITHER_CRLF - case KEY_CMDMODE_NEXTLINE: - case '\r': /* Either CR or LF terminates line */ - case '\n': - { - vi->curpos = vi_nextline(vi, vi->curpos); - vi_gotofirstnonwhite(vi); - } - break; -#endif case KEY_CMDMODE_PREVLINE: { @@ -4639,34 +4584,11 @@ static void vi_cmd_submode(FAR struct vi_s *vi) /* What do we do with carriage returns? line feeds? */ -#if defined(CONFIG_EOL_IS_CR) - case '\r': /* CR terminates line */ - { - vi_parsecolon(vi); - } - break; - -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) case '\n': /* LF terminates line */ { vi_parsecolon(vi); } break; -#endif - -#ifdef CONFIG_EOL_IS_EITHER_CRLF - case '\r': /* Either CR or LF terminates line */ - case '\n': - { - vi_parsecolon(vi); - } - break; -#endif default: { @@ -4941,34 +4863,11 @@ static void vi_find_submode(FAR struct vi_s *vi, bool revfind) /* What do we do with carriage returns? line feeds? */ -#if defined(CONFIG_EOL_IS_CR) - case '\r': /* CR terminates line */ - { - vi_parsefind(vi, revfind); - } - break; - -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) case '\n': /* LF terminates line */ { vi_parsefind(vi, revfind); } break; -#endif - -#ifdef CONFIG_EOL_IS_EITHER_CRLF - case '\r': /* Either CR or LF terminates line */ - case '\n': - { - vi_parsefind(vi, revfind); - } - break; -#endif default: { @@ -5089,36 +4988,11 @@ static void vi_replacech_submode(FAR struct vi_s *vi) /* What do we do with carriage returns? line feeds? */ -#if defined(CONFIG_EOL_IS_CR) - case '\r': /* CR terminates line */ - { - ch = '\n'; - found = true; - } - break; - -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) case '\n': /* LF terminates line */ { found = true; } break; -#endif - -#ifdef CONFIG_EOL_IS_EITHER_CRLF - case '\r': /* Either CR or LF terminates line */ - case '\n': - { - ch = '\n'; - found = true; - } - break; -#endif default: { @@ -5487,28 +5361,6 @@ static void vi_insert_mode(FAR struct vi_s *vi) /* What do we do with carriage returns? */ -#if defined(CONFIG_EOL_IS_CR) - case '\r': /* CR terminates line */ - { - if (vi->mode == MODE_INSERT) - { - vi_insertch(vi, '\n'); - } - else - { - vi_replacech(vi, '\n'); - } - - vi->drawtoeos = true; - } - break; - -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) - case '\r': /* Wait for the LF */ - break; -#endif - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) case '\n': /* LF terminates line */ { if (vi->mode == MODE_INSERT) @@ -5523,27 +5375,6 @@ static void vi_insert_mode(FAR struct vi_s *vi) vi->drawtoeos = true; } break; -#endif - -#ifdef CONFIG_EOL_IS_EITHER_CRLF - case '\r': /* Either CR or LF terminates line */ - case '\n': - { - if (vi->mode == MODE_INSERT) - { - vi_insertch(vi, '\n'); - } - else - { - vi_replacech(vi, '\n'); - } - - vi_putch(vi, ' '); - vi_clrtoeol(vi); - vi->drawtoeos = true; - } - break; -#endif case KEY_UP: /* Move the cursor up one line */ {