From 6a7483532c1f544d40fb56db16eb1a95f34b95a3 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 08:17:03 +0100 Subject: [PATCH 1/8] Travis-CI: Disable CLANG temporarily for Coverity Scan Signed-off-by: Joachim Nilsson --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a878a38..7a1d93f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ language: c sudo: false # Test build with both GCC and Clang (LLVM) +# - clang compiler: - gcc - - clang env: global: From 2ce0be942ee69f8a3ad1f4e28bced1dc7804282a Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 08:38:04 +0100 Subject: [PATCH 2/8] Minor, reorder functions Signed-off-by: Joachim Nilsson --- src/editline.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/editline.c b/src/editline.c index 627c532..e48602c 100644 --- a/src/editline.c +++ b/src/editline.c @@ -892,6 +892,31 @@ el_status_t el_del_char(void) return del_char(); } +static el_status_t fd_word(void) +{ + return do_forward(CSmove); +} + +static el_status_t bk_word(void) +{ + int i; + char *p; + + i = 0; + do { + for (p = &rl_line_buffer[rl_point]; p > rl_line_buffer && !is_alpha_num(p[-1]); p--) + left(CSmove); + + for (; p > rl_line_buffer && !isblank(p[-1]) && is_alpha_num(p[-1]); p--) + left(CSmove); + + if (rl_point == 0) + break; + } while (++i < Repeat); + + return CSstay; +} + static el_status_t meta(void) { int c; @@ -1689,11 +1714,6 @@ static el_status_t move_to_char(void) return CSstay; } -static el_status_t fd_word(void) -{ - return do_forward(CSmove); -} - static el_status_t fd_kill_word(void) { int i; @@ -1708,26 +1728,6 @@ static el_status_t fd_kill_word(void) return CSstay; } -static el_status_t bk_word(void) -{ - int i; - char *p; - - i = 0; - do { - for (p = &rl_line_buffer[rl_point]; p > rl_line_buffer && !is_alpha_num(p[-1]); p--) - left(CSmove); - - for (; p > rl_line_buffer && !isblank(p[-1]) && is_alpha_num(p[-1]); p--) - left(CSmove); - - if (rl_point == 0) - break; - } while (++i < Repeat); - - return CSstay; -} - static el_status_t bk_kill_word(void) { bk_word(); From 0bfaf351aa425c6cd820a94edc58796f0769cab2 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 08:42:32 +0100 Subject: [PATCH 3/8] Add support for Ctrl+Right and Ctrl+Left, forward/back word Signed-off-by: Joachim Nilsson --- src/editline.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/editline.c b/src/editline.c index e48602c..6d82b84 100644 --- a/src/editline.c +++ b/src/editline.c @@ -930,6 +930,20 @@ static el_status_t meta(void) if (c == '[' || c == 'O') { switch (tty_get()) { case EOF: return CSeof; + case '1': + { + char seq[4] = { 0 }; + + for (c = 0; c < 3; c++) + seq[c] = tty_get(); + + if (!strncmp(seq, ";5C", 3)) + return fd_word(); /* Ctrl+Right */ + if (!strncmp(seq, ";5D", 3)) + return bk_word(); /* Ctrl+Left */ + + break; + } case '2': tty_get(); return CSstay; /* Insert */ case '3': tty_get(); return del_char(); /* Delete */ case '5': tty_get(); return CSstay; /* PgUp */ From 9e9f8b03d8a4ce52119a3583a522bd7b7ee383c3 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 10:31:50 +0100 Subject: [PATCH 4/8] Fix Coverity Scan findings, missing return and bad strcpy() Signed-off-by: Joachim Nilsson --- examples/excallback.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/excallback.c b/examples/excallback.c index 4053246..015132a 100644 --- a/examples/excallback.c +++ b/examples/excallback.c @@ -134,6 +134,8 @@ main() rl_callback_read_char(); } } + + return 0; } void @@ -168,7 +170,8 @@ change_prompt(void) prompt = !prompt; /* save away the current contents of the line */ - strcpy(line_buf, rl_line_buffer); + strncpy(line_buf, rl_line_buffer, sizeof(line_buf)); + line_buf[sizeof(line_buf) - 1] = 0; /* install a new handler which will change the prompt and erase the current line */ rl_callback_handler_install(get_prompt(), process_line); @@ -179,7 +182,7 @@ change_prompt(void) /* redraw the current line - this is an undocumented function. It invokes the * redraw-current-line command. */ - rl_refresh_line(0, 0); + return rl_refresh_line(0, 0); } char * From f8c6b7f208d880a09b092cd756ae69dd777cd3b9 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 10:49:39 +0100 Subject: [PATCH 5/8] Update .gitignore Signed-off-by: Joachim Nilsson --- examples/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/.gitignore b/examples/.gitignore index 2e858a7..23a58dd 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,3 +1,4 @@ *.o cli testit +excallback \ No newline at end of file From fdda4f5cae3f00fd84ad05f42900a361219ad417 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 10:49:49 +0100 Subject: [PATCH 6/8] README: Add license badge and add Wikipedia link to C News The C News sources are referenced in the Wikipedia article, which is useful to follow-up the license origins. Signed-off-by: Joachim Nilsson --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5be8090..a398bb7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Editline ======== -[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan] +[![License Badge][]][License] [![Travis Status]][Travis] [![Coverity Status]][Coverity Scan] Table of Contents @@ -20,7 +20,7 @@ This is a small [line editing][] library. It can be linked into almost any program to provide command line editing and history functions. It is call compatible with the [FSF readline][] library, but at a fraction of the size, and as a result fewer features. It is also distributed -under a much more liberal [LICENSE][]. +under a much more liberal [License][]. The small size (<30k), lack of dependencies (ncurses not needed!), and the free license should make this library interesting to many embedded @@ -216,10 +216,10 @@ Origin & References -------------------- This [line editing][] library was created by [Rich Salz][] and Simmule -Turner and in 1992. It is distributed under a “C News-like” license, -similar to the [BSD license][]. Rich's latest version is however under +Turner and in 1992. It is distributed with a “[C News][]-like” license, +similar to the [BSD license][]. Rich's current version is however under the Apache license. For details on the licensing terms of this version -of the software, see [LICENSE][]. +of the software, see [License][]. This version of the editline library was forked from the [Minix 3][] source tree and is *not* related to the similarily named NetBSD version @@ -249,7 +249,7 @@ Outstanding issues are listed in the [TODO.md][] file. [line editing]: https://github.com/troglobit/editline/blob/master/doc/README [release tarball]: https://github.com/troglobit/editline/releases [maintainer]: http://troglobit.com -[LICENSE]: https://github.com/troglobit/editline/blob/master/LICENSE +[C News]: https://en.wikipedia.org/wiki/C_News [TODO.md]: https://github.com/troglobit/editline/blob/master/TODO.md [ChangeLog.md]: https://github.com/troglobit/editline/blob/master/ChangeLog.md [FSF readline]: http://www.gnu.org/software/readline/ @@ -262,6 +262,8 @@ Outstanding issues are listed in the [TODO.md][] file. [Heimdal]: http://www.h5l.org [Festival]: http://festvox.org/festival/ [Steve Tell]: http://www.cs.unc.edu/~tell/dist.html +[License]: https://github.com/troglobit/editline/blob/master/LICENSE +[License Badge]: https://img.shields.io/badge/License-C%20News-orange.svg [Travis]: https://travis-ci.org/troglobit/editline [Travis Status]: https://travis-ci.org/troglobit/editline.png?branch=master [Coverity Scan]: https://scan.coverity.com/projects/2982 From 1657da4f2eec69da9b99c1cd21b1f3389408067c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 13:16:07 +0100 Subject: [PATCH 7/8] README: Minor whitespace changes Signed-off-by: Joachim Nilsson --- README.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a398bb7..c4d1e1f 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ availble in the source tree. #include #include - int main (void) + int main(void) { char *p; @@ -130,17 +130,17 @@ to [FSF readline][], which may not be entirely up-to-date. int el_hist_size; /* Size of history scrollback buffer, default: 15 */ /* Editline specific functions. */ - char * el_find_word(void); - void el_print_columns(int ac, char **av); - el_status_t el_ring_bell(void); - el_status_t el_del_char(void); + char * el_find_word (void); + void el_print_columns (int ac, char **av); + el_status_t el_ring_bell (void); + el_status_t el_del_char (void); /* Callback function for key binding */ typedef el_status_t el_keymap_func_t(void); /* Bind key to a callback, use CTL('f') to change Ctrl-F, for example */ - el_status_t el_bind_key(int key, el_keymap_func_t function); - el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function); + el_status_t el_bind_key (int key, el_keymap_func_t function); + el_status_t el_bind_key_in_metamap (int key, el_keymap_func_t function); /* For compatibility with FSF readline. */ int rl_point; @@ -151,32 +151,32 @@ to [FSF readline][], which may not be entirely up-to-date. const char *rl_readline_name; void (*rl_deprep_term_function)(void); - void rl_deprep_terminal(void); - void rl_reset_terminal(const char *terminal_name); + void rl_deprep_terminal (void); + void rl_reset_terminal (const char *terminal_name); - void rl_initialize(void); - void rl_uninitialize(void); /* Free all internal memory */ + void rl_initialize (void); + void rl_uninitialize (void); /* Free all internal memory */ - void rl_save_prompt(void); - void rl_restore_prompt(void); - void rl_set_prompt(const char *prompt); + void rl_save_prompt (void); + void rl_restore_prompt (void); + void rl_set_prompt (const char *prompt); - void rl_clear_message(void); - void rl_forced_update_display(void); + void rl_clear_message (void); + void rl_forced_update_display (void); /* Main function to use, saves history by default */ - char *readline(const char *prompt); + char *readline (const char *prompt); /* Use to save a read line to history, when el_no_hist is set */ - void add_history(const char *line); + void add_history (const char *line); /* Load and save editline history from/to a file. */ - int read_history(const char *filename); - int write_history(const char *filename); + int read_history (const char *filename); + int write_history (const char *filename); /* Magic completion API, see examples/cli.c for more info */ - rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func); - rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func); + rl_complete_func_t *rl_set_complete_func (rl_complete_func_t *func); + rl_list_possib_func_t *rl_set_list_possib_func (rl_list_possib_func_t *func); /* Alternate interface to plain readline(), for event loops */ void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler); From 5b43c028c9bfdc19eee85b8276466b1f8dd3549d Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 22 Mar 2018 16:06:04 +0100 Subject: [PATCH 8/8] Revert "Travis-CI: Disable CLANG temporarily for Coverity Scan" This reverts commit 6a7483532c1f544d40fb56db16eb1a95f34b95a3. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a1d93f..a878a38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ language: c sudo: false # Test build with both GCC and Clang (LLVM) -# - clang compiler: - gcc + - clang env: global: