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];
|
char onechar[MAXCHARLEN];
|
||||||
int charlen;
|
int charlen;
|
||||||
size_t current_len = strlen(openfile->current->data);
|
size_t current_len = strlen(openfile->current->data);
|
||||||
size_t i = 0;
|
size_t index = 0;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
size_t original_row = 0, old_amount = 0;
|
size_t original_row = 0, old_amount = 0;
|
||||||
|
|
||||||
|
@ -1652,15 +1652,13 @@ void inject(char *output, size_t output_len)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (i < output_len) {
|
while (index < output_len) {
|
||||||
/* Encode an embedded NUL byte as 0x0A. */
|
/* Encode an embedded NUL byte as 0x0A. */
|
||||||
if (output[i] == '\0')
|
if (output[index] == '\0')
|
||||||
output[i] = '\n';
|
output[index] = '\n';
|
||||||
|
|
||||||
/* Get the next multibyte character. */
|
/* Get the next multibyte character. */
|
||||||
charlen = collect_char(output + i, onechar);
|
charlen = collect_char(output + index, onechar);
|
||||||
|
|
||||||
i += charlen;
|
|
||||||
|
|
||||||
/* Make room for the new character and copy it into the line. */
|
/* Make room for the new character and copy it into the line. */
|
||||||
openfile->current->data = charealloc(openfile->current->data,
|
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,
|
memmove(openfile->current->data + openfile->current_x + charlen,
|
||||||
openfile->current->data + openfile->current_x,
|
openfile->current->data + openfile->current_x,
|
||||||
current_len - openfile->current_x + 1);
|
current_len - openfile->current_x + 1);
|
||||||
strncpy(openfile->current->data + openfile->current_x, onechar,
|
strncpy(openfile->current->data + openfile->current_x, onechar, charlen);
|
||||||
charlen);
|
|
||||||
current_len += charlen;
|
current_len += charlen;
|
||||||
|
index += charlen;
|
||||||
|
|
||||||
openfile->totsize++;
|
openfile->totsize++;
|
||||||
set_modified();
|
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 *output = charalloc(input_len + 1);
|
||||||
char onechar[MAXCHARLEN];
|
char onechar[MAXCHARLEN];
|
||||||
size_t charlen, i, j = 0;
|
size_t charlen, index = 0;
|
||||||
|
|
||||||
/* Copy the typed stuff so it can be treated. */
|
/* 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] = (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. */
|
/* Encode any NUL byte as 0x0A. */
|
||||||
if (output[j] == '\0')
|
if (output[index] == '\0')
|
||||||
output[j] = '\n';
|
output[index] = '\n';
|
||||||
|
|
||||||
/* Interpret the next multibyte character. */
|
/* Interpret the next multibyte character. */
|
||||||
charlen = collect_char(output + j, onechar);
|
charlen = collect_char(output + index, onechar);
|
||||||
|
|
||||||
j += charlen;
|
|
||||||
|
|
||||||
/* Insert the typed character into the existing answer string. */
|
/* Insert the typed character into the existing answer string. */
|
||||||
answer = charealloc(answer, strlen(answer) + charlen + 1);
|
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);
|
strncpy(answer + typing_x, onechar, charlen);
|
||||||
|
|
||||||
typing_x += charlen;
|
typing_x += charlen;
|
||||||
|
index += charlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
|
|
Loading…
Reference in New Issue