mirror of
https://github.com/bobbimanners/emailler.git
synced 2024-10-01 06:54:52 +00:00
EDIT: Reworked load_file() to not require memmove()
This commit is contained in:
parent
62874dc477
commit
29acbd680e
25
apps/edit.c
25
apps/edit.c
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
// Note: Use my fork of cc65 to get a flashing cursor!!
|
// Note: Use my fork of cc65 to get a flashing cursor!!
|
||||||
|
|
||||||
// TODO: Maybe rework load_file() again to avoid memmove()
|
|
||||||
// TODO: Adjust beep() sound
|
// TODO: Adjust beep() sound
|
||||||
// TODO: Make use of aux mem
|
// TODO: Make use of aux mem
|
||||||
|
|
||||||
@ -408,7 +407,7 @@ uint8_t load_file(char *filename, uint8_t replace) {
|
|||||||
gapend = BUFSZ - 1;
|
gapend = BUFSZ - 1;
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
p = gapbuf + gapbegin;
|
p = gapbuf + gapend - RDSZ; // Read to just before gapend
|
||||||
do {
|
do {
|
||||||
if (FREESPACE() < RDSZ * 2) {
|
if (FREESPACE() < RDSZ * 2) {
|
||||||
show_error("File truncated");
|
show_error("File truncated");
|
||||||
@ -417,32 +416,28 @@ uint8_t load_file(char *filename, uint8_t replace) {
|
|||||||
cputc('.');
|
cputc('.');
|
||||||
s = fread(p, 1, RDSZ, fp);
|
s = fread(p, 1, RDSZ, fp);
|
||||||
cont = (s == RDSZ ? 1 : 0);
|
cont = (s == RDSZ ? 1 : 0);
|
||||||
|
for (i = 0; i < s; ++i) {
|
||||||
i = 0;
|
switch (p[i]) {
|
||||||
while (i < s) {
|
|
||||||
switch (*(p + i)) {
|
|
||||||
case '\r': // Native Apple2 files
|
case '\r': // Native Apple2 files
|
||||||
case '\n': // UNIX files
|
case '\n': // UNIX files
|
||||||
|
gapbuf[gapbegin++] = '\r';
|
||||||
col = 0;
|
col = 0;
|
||||||
*(p + i) = '\r';
|
|
||||||
++i;
|
|
||||||
break;
|
break;
|
||||||
case '\t':
|
case '\t':
|
||||||
c = next_tabstop(col) - col;
|
c = next_tabstop(col) - col;
|
||||||
memmove(p + i + c - 1, p + i, s - i);
|
|
||||||
for (j = 0; j < c; ++j)
|
for (j = 0; j < c; ++j)
|
||||||
*(p + i + j) = ' ';
|
gapbuf[gapbegin++] = ' ';
|
||||||
col += c;
|
col += c;
|
||||||
i += c;
|
|
||||||
s += c - 1;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
gapbuf[gapbegin++] = p[i];
|
||||||
++col;
|
++col;
|
||||||
++i;
|
}
|
||||||
|
if (FREESPACE() < RDSZ * 2) {
|
||||||
|
show_error("File truncated");
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p += s;
|
|
||||||
gapbegin += s;
|
|
||||||
} while (cont);
|
} while (cont);
|
||||||
--gapbegin; // Eat EOF character
|
--gapbegin; // Eat EOF character
|
||||||
done:
|
done:
|
||||||
|
Loading…
Reference in New Issue
Block a user