You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/04/09 14:12:30 UTC
[mynewt-core] branch master updated: console: Fix internals console history
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 04da7ac65 console: Fix internals console history
04da7ac65 is described below
commit 04da7ac65de8a0f88da601077803e33a1ed2cfbc
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Mar 22 22:42:04 2022 +0100
console: Fix internals console history
history_handle_t type was used to store pointer or result.
Code assumed that pointer will always be positive and error code
would be SYS_xxx so they would be negative.
For PIC32 RAM addresses start from 0x80000000 sot they were always
negative.
This removes double meaning of history_handle_t and some functions return
error codes separately from found history entries.
---
sys/console/full/history_log/pkg.yml | 1 +
sys/console/full/history_log/src/history_log.c | 23 +++++++++++++----------
sys/console/full/history_ram/src/history_ram.c | 14 +++++++++-----
sys/console/full/include/console/history.h | 5 +++--
sys/console/full/src/console.c | 2 +-
5 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/sys/console/full/history_log/pkg.yml b/sys/console/full/history_log/pkg.yml
index 0b4f9045f..7c323e0e5 100644
--- a/sys/console/full/history_log/pkg.yml
+++ b/sys/console/full/history_log/pkg.yml
@@ -27,6 +27,7 @@ pkg.deps:
- "@apache-mynewt-core/hw/hal"
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/sys/console/full"
+ - "@apache-mynewt-core/sys/log/full"
pkg.init:
console_history_pkg_init: 'MYNEWT_VAL(CONSOLE_HISTORY_LOG_SYSINIT_STAGE)'
diff --git a/sys/console/full/history_log/src/history_log.c b/sys/console/full/history_log/src/history_log.c
index 531bffd18..9a0428df2 100644
--- a/sys/console/full/history_log/src/history_log.c
+++ b/sys/console/full/history_log/src/history_log.c
@@ -123,8 +123,8 @@ move(const char *p, history_find_type_t search_type)
}
}
-static history_handle_t
-console_history_add_to_cache(const char *line)
+static int
+console_history_add_to_cache(const char *line, history_handle_t *entry)
{
char *cache_end = history_cache + history_ptr;
/* Let p1 point to last null-terminator */
@@ -227,7 +227,10 @@ console_history_add_to_cache(const char *line)
p1 = NEXT_PTR(p1);
}
- return result;
+ if (entry) {
+ *entry = result;
+ }
+ return 0;
}
/*
@@ -246,24 +249,24 @@ history_cache_from_log(struct log *log, struct log_offset *log_offset,
if (hdr->ue_module == MYNEWT_VAL(CONSOLE_HISTORY_LOG_MODULE)) {
log_read_body(log, dptr, line, 0, len);
line[len] = '\0';
- (void)console_history_add_to_cache(line);
+ (void)console_history_add_to_cache(line, NULL);
}
return 0;
}
-history_handle_t
-console_history_add(const char *line)
+int
+console_history_add(const char *line, history_handle_t *entry)
{
- history_handle_t added_line;
+ int rc;
- added_line = console_history_add_to_cache(line);
+ rc = console_history_add_to_cache(line, entry);
- if (added_line > 0 && history_log) {
+ if (rc == 0 && history_log) {
log_printf(history_log, MYNEWT_VAL(CONSOLE_HISTORY_LOG_MODULE),
LOG_LEVEL_MAX, line);
}
- return added_line;
+ return rc;
}
int
diff --git a/sys/console/full/history_ram/src/history_ram.c b/sys/console/full/history_ram/src/history_ram.c
index 348599ef1..41e2398a3 100644
--- a/sys/console/full/history_ram/src/history_ram.c
+++ b/sys/console/full/history_ram/src/history_ram.c
@@ -133,8 +133,8 @@ console_hist_move_to_head(char *line)
return true;
}
-history_handle_t
-console_history_add(const char *line)
+int
+console_history_add(const char *line, history_handle_t *entry)
{
struct console_hist *sh = &console_hist;
char buf[MYNEWT_VAL(CONSOLE_MAX_INPUT_LEN)];
@@ -142,11 +142,15 @@ console_history_add(const char *line)
len = trim_whitespace(line, buf, sizeof(buf));
if (len == 0) {
- return 0;
+ return SYS_EINVAL;
+ }
+
+ if (entry) {
+ *entry = 0;
}
if (console_hist_move_to_head(buf)) {
- return 1;
+ return SYS_EALREADY;
}
strcpy(sh->lines[sh->head], buf);
@@ -154,7 +158,7 @@ console_history_add(const char *line)
if (!console_hist_is_full()) {
sh->count++;
}
- return 1;
+ return SYS_EOK;
}
/**
diff --git a/sys/console/full/include/console/history.h b/sys/console/full/include/console/history.h
index 37f13a7c0..d5708038e 100644
--- a/sys/console/full/include/console/history.h
+++ b/sys/console/full/include/console/history.h
@@ -44,12 +44,13 @@ typedef intptr_t history_handle_t;
* Implemented by history provider.
*
* @param line text to add to history
+ * @param entry pointer to variable that will receive history entry
*
- * @return handle to new entry added to history
+ * @return SYS_EOK - if line was added
* SYS_EINVAL - line was empty or null
* SYS_EALREADY - line was already at the end of history
*/
-history_handle_t console_history_add(const char *line);
+int console_history_add(const char *line, history_handle_t *entry);
/**
* Finds element in history.
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index f9df03c24..a147c6a1d 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -1187,7 +1187,7 @@ console_handle_char(uint8_t byte)
console_filter_out('\n');
}
if (!MYNEWT_VAL_CHOICE(CONSOLE_HISTORY, none)) {
- console_history_add(input->line);
+ console_history_add(input->line, NULL);
history_line = 0;
if (MYNEWT_VAL(CONSOLE_HISTORY_AUTO_SEARCH)) {
trailing_selection = 0;