tweaks: condense two comments, and rename two parameters

Also use 'while' instead of 'for'.
master
Benno Schulenberg 2019-10-13 16:42:45 +02:00
parent 094758be15
commit ba79602281
3 changed files with 17 additions and 16 deletions

View File

@ -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';

View File

@ -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

View File

@ -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++;
}
}