tweaks: condense two comments, and rename two parameters
Also use 'while' instead of 'for'.master
parent
094758be15
commit
ba79602281
|
@ -414,7 +414,7 @@ void load_poshistory(void)
|
||||||
|
|
||||||
/* Read and parse each line, and store the extracted data. */
|
/* Read and parse each line, and store the extracted data. */
|
||||||
while ((read = getline(&line, &buf_len, hisfile)) > 5) {
|
while ((read = getline(&line, &buf_len, hisfile)) > 5) {
|
||||||
/* Decode nulls as embedded newlines. */
|
/* Decode NULs as embedded newlines. */
|
||||||
unsunder(line, read);
|
unsunder(line, read);
|
||||||
|
|
||||||
/* Find where the x index and line number are in the line. */
|
/* 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);
|
posptr->filename, posptr->lineno, posptr->xno);
|
||||||
length = strlen(path_and_place);
|
length = strlen(path_and_place);
|
||||||
|
|
||||||
/* Encode newlines in filenames as nulls. */
|
/* Encode newlines in filenames as NULs. */
|
||||||
sunder(path_and_place);
|
sunder(path_and_place);
|
||||||
/* Restore the terminating newline. */
|
/* Restore the terminating newline. */
|
||||||
path_and_place[length - 1] = '\n';
|
path_and_place[length - 1] = '\n';
|
||||||
|
|
|
@ -567,8 +567,8 @@ int digits(ssize_t n);
|
||||||
#endif
|
#endif
|
||||||
bool parse_num(const char *str, ssize_t *val);
|
bool parse_num(const char *str, ssize_t *val);
|
||||||
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);
|
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);
|
||||||
void unsunder(char *str, size_t true_len);
|
void unsunder(char *string, size_t length);
|
||||||
void sunder(char *str);
|
void sunder(char *string);
|
||||||
#if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
|
#if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
|
||||||
void free_chararray(char **array, size_t len);
|
void free_chararray(char **array, size_t len);
|
||||||
#endif
|
#endif
|
||||||
|
|
25
src/utils.c
25
src/utils.c
|
@ -159,23 +159,24 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For non-null-terminated lines. A line, by definition, shouldn't
|
/* In the given string, recode each embedded NUL as a newline. */
|
||||||
* normally have newlines in it, so encode its nulls as newlines. */
|
void unsunder(char *string, size_t length)
|
||||||
void unsunder(char *str, size_t true_len)
|
|
||||||
{
|
{
|
||||||
for (; true_len > 0; true_len--, str++) {
|
while (length > 0) {
|
||||||
if (*str == '\0')
|
if (*string == '\0')
|
||||||
*str = '\n';
|
*string = '\n';
|
||||||
|
length--;
|
||||||
|
string++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For non-null-terminated lines. A line, by definition, shouldn't
|
/* In the given string, recode each embedded newline as a NUL. */
|
||||||
* normally have newlines in it, so decode its newlines as nulls. */
|
void sunder(char *string)
|
||||||
void sunder(char *str)
|
|
||||||
{
|
{
|
||||||
for (; *str != '\0'; str++) {
|
while (*string != '\0') {
|
||||||
if (*str == '\n')
|
if (*string == '\n')
|
||||||
*str = '\0';
|
*string = '\0';
|
||||||
|
string++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue