tweaks: rename two variables, and reshuffle a few things
parent
8e4b68917c
commit
070ccf4a5b
18
src/nano.c
18
src/nano.c
|
@ -1641,7 +1641,7 @@ void inject(char *output, size_t output_len)
|
|||
char onechar[MAXCHARLEN];
|
||||
int charlen;
|
||||
size_t current_len = strlen(openfile->current->data);
|
||||
size_t i = 0;
|
||||
size_t index = 0;
|
||||
#ifndef NANO_TINY
|
||||
size_t original_row = 0, old_amount = 0;
|
||||
|
||||
|
@ -1652,15 +1652,13 @@ void inject(char *output, size_t output_len)
|
|||
}
|
||||
#endif
|
||||
|
||||
while (i < output_len) {
|
||||
while (index < output_len) {
|
||||
/* Encode an embedded NUL byte as 0x0A. */
|
||||
if (output[i] == '\0')
|
||||
output[i] = '\n';
|
||||
if (output[index] == '\0')
|
||||
output[index] = '\n';
|
||||
|
||||
/* Get the next multibyte character. */
|
||||
charlen = collect_char(output + i, onechar);
|
||||
|
||||
i += charlen;
|
||||
charlen = collect_char(output + index, onechar);
|
||||
|
||||
/* Make room for the new character and copy it into the line. */
|
||||
openfile->current->data = charealloc(openfile->current->data,
|
||||
|
@ -1668,9 +1666,11 @@ void inject(char *output, size_t output_len)
|
|||
memmove(openfile->current->data + openfile->current_x + charlen,
|
||||
openfile->current->data + openfile->current_x,
|
||||
current_len - openfile->current_x + 1);
|
||||
strncpy(openfile->current->data + openfile->current_x, onechar,
|
||||
charlen);
|
||||
strncpy(openfile->current->data + openfile->current_x, onechar, charlen);
|
||||
|
||||
current_len += charlen;
|
||||
index += charlen;
|
||||
|
||||
openfile->totsize++;
|
||||
set_modified();
|
||||
|
||||
|
|
17
src/prompt.c
17
src/prompt.c
|
@ -176,22 +176,20 @@ void inject_into_answer(int *the_input, size_t input_len)
|
|||
{
|
||||
char *output = charalloc(input_len + 1);
|
||||
char onechar[MAXCHARLEN];
|
||||
size_t charlen, i, j = 0;
|
||||
size_t charlen, index = 0;
|
||||
|
||||
/* Copy the typed stuff so it can be treated. */
|
||||
for (i = 0; i < input_len; i++)
|
||||
for (size_t i = 0; i < input_len; i++)
|
||||
output[i] = (char)the_input[i];
|
||||
output[i] = '\0';
|
||||
output[input_len] = '\0';
|
||||
|
||||
while (j < input_len) {
|
||||
while (index < input_len) {
|
||||
/* Encode any NUL byte as 0x0A. */
|
||||
if (output[j] == '\0')
|
||||
output[j] = '\n';
|
||||
if (output[index] == '\0')
|
||||
output[index] = '\n';
|
||||
|
||||
/* Interpret the next multibyte character. */
|
||||
charlen = collect_char(output + j, onechar);
|
||||
|
||||
j += charlen;
|
||||
charlen = collect_char(output + index, onechar);
|
||||
|
||||
/* Insert the typed character into the existing answer string. */
|
||||
answer = charealloc(answer, strlen(answer) + charlen + 1);
|
||||
|
@ -200,6 +198,7 @@ void inject_into_answer(int *the_input, size_t input_len)
|
|||
strncpy(answer + typing_x, onechar, charlen);
|
||||
|
||||
typing_x += charlen;
|
||||
index += charlen;
|
||||
}
|
||||
|
||||
free(output);
|
||||
|
|
Loading…
Reference in New Issue