nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit ba79602281a1a901867472f218cf10eb1d60cff9
parent 094758be150db889228960b69ea7fe38359ab1c4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun, 13 Oct 2019 16:42:45 +0200

tweaks: condense two comments, and rename two parameters

Also use 'while' instead of 'for'.

Diffstat:
Msrc/history.c | 4++--
Msrc/proto.h | 4++--
Msrc/utils.c | 25+++++++++++++------------
3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/history.c b/src/history.c @@ -414,7 +414,7 @@ void load_poshistory(void) /* Read and parse each line, and store the extracted data. */ while ((read = getline(&line, &buf_len, hisfile)) > 5) { - /* Decode nulls as embedded newlines. */ + /* Decode NULs as embedded newlines. */ unsunder(line, read); /* Find where the x index and line number are in the line. */ @@ -484,7 +484,7 @@ void save_poshistory(void) posptr->filename, posptr->lineno, posptr->xno); length = strlen(path_and_place); - /* Encode newlines in filenames as nulls. */ + /* Encode newlines in filenames as NULs. */ sunder(path_and_place); /* Restore the terminating newline. */ path_and_place[length - 1] = '\n'; diff --git a/src/proto.h b/src/proto.h @@ -567,8 +567,8 @@ int digits(ssize_t n); #endif bool parse_num(const char *str, ssize_t *val); bool parse_line_column(const char *str, ssize_t *line, ssize_t *column); -void unsunder(char *str, size_t true_len); -void sunder(char *str); +void unsunder(char *string, size_t length); +void sunder(char *string); #if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER) void free_chararray(char **array, size_t len); #endif diff --git a/src/utils.c b/src/utils.c @@ -159,23 +159,24 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column) return retval; } -/* For non-null-terminated lines. A line, by definition, shouldn't - * normally have newlines in it, so encode its nulls as newlines. */ -void unsunder(char *str, size_t true_len) +/* In the given string, recode each embedded NUL as a newline. */ +void unsunder(char *string, size_t length) { - for (; true_len > 0; true_len--, str++) { - if (*str == '\0') - *str = '\n'; + while (length > 0) { + if (*string == '\0') + *string = '\n'; + length--; + string++; } } -/* For non-null-terminated lines. A line, by definition, shouldn't - * normally have newlines in it, so decode its newlines as nulls. */ -void sunder(char *str) +/* In the given string, recode each embedded newline as a NUL. */ +void sunder(char *string) { - for (; *str != '\0'; str++) { - if (*str == '\n') - *str = '\0'; + while (*string != '\0') { + if (*string == '\n') + *string = '\0'; + string++; } }