mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-02-06 08:30:02 +00:00
Refactored search and replace in preparation for aux memory implementation
This commit is contained in:
parent
4ca1eeb472
commit
a09fa8a26a
80
apps/edit.c
80
apps/edit.c
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
// TODO: Finish off auxmem support. See TODOs below
|
// TODO: Finish off auxmem support. See TODOs below
|
||||||
|
|
||||||
#define AUXMEM // HIGHLY EXPERIMENTAL
|
#undef AUXMEM // HIGHLY EXPERIMENTAL
|
||||||
|
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -87,6 +87,8 @@ char openapple[] = "\x0f\x1b""A\x18\x0e";
|
|||||||
/*
|
/*
|
||||||
* Obtain one byte from the gapbuf[] in aux memory
|
* Obtain one byte from the gapbuf[] in aux memory
|
||||||
* Must be in LC
|
* Must be in LC
|
||||||
|
* i - Index into gapbuf[]
|
||||||
|
* Returns value at gapbuf[i]
|
||||||
*/
|
*/
|
||||||
#pragma code-name (push, "LC")
|
#pragma code-name (push, "LC")
|
||||||
char get_gapbuf(uint16_t i) {
|
char get_gapbuf(uint16_t i) {
|
||||||
@ -106,6 +108,8 @@ char get_gapbuf(uint16_t i) {
|
|||||||
/*
|
/*
|
||||||
* Set one byte in the gapbuf[] in aux memory
|
* Set one byte in the gapbuf[] in aux memory
|
||||||
* Must be in LC
|
* Must be in LC
|
||||||
|
* i - Index into gapbuf
|
||||||
|
* c - Byte value to set
|
||||||
*/
|
*/
|
||||||
#pragma code-name (push, "LC")
|
#pragma code-name (push, "LC")
|
||||||
void set_gapbuf(uint16_t i, char c) {
|
void set_gapbuf(uint16_t i, char c) {
|
||||||
@ -122,6 +126,9 @@ void set_gapbuf(uint16_t i, char c) {
|
|||||||
/*
|
/*
|
||||||
* Do a memmove() on aux memory. Uses indices into gapbuf[].
|
* Do a memmove() on aux memory. Uses indices into gapbuf[].
|
||||||
* Must be in LC
|
* Must be in LC
|
||||||
|
* dst - Destination index into gapbuf[]
|
||||||
|
* src - Source index into gapbuf[]
|
||||||
|
* n - Length in bytes
|
||||||
*/
|
*/
|
||||||
#pragma code-name (push, "LC")
|
#pragma code-name (push, "LC")
|
||||||
void move_in_gapbuf(uint16_t dst, uint16_t src, size_t n) {
|
void move_in_gapbuf(uint16_t dst, uint16_t src, size_t n) {
|
||||||
@ -205,6 +212,28 @@ as3:
|
|||||||
}
|
}
|
||||||
#pragma code-name (pop)
|
#pragma code-name (pop)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do a strstr() on aux memory. Uses index into gapbuf[].
|
||||||
|
* Must be in LC
|
||||||
|
* i - Index into gapbuf[]
|
||||||
|
* needle - String to search for
|
||||||
|
* loc - Location where string found (index into gapbuf[]) returned here
|
||||||
|
* Returns 1 if found, 0 otherwise
|
||||||
|
*/
|
||||||
|
#pragma code-name (push, "LC")
|
||||||
|
uint8_t search_in_gapbuf(uint16_t i, char *needle, uint16_t *loc) {
|
||||||
|
#ifdef AUXMEM
|
||||||
|
#else
|
||||||
|
char *p = strstr(gapbuf + i, needle);
|
||||||
|
if (p) {
|
||||||
|
*loc = p - gapbuf;
|
||||||
|
return 1;
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#pragma code-name (pop)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Annoying beep
|
* Annoying beep
|
||||||
*/
|
*/
|
||||||
@ -593,7 +622,9 @@ uint8_t save_file(char *filename) {
|
|||||||
uint8_t retval = 1;
|
uint8_t retval = 1;
|
||||||
char *p;
|
char *p;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
#ifdef AUXMEM
|
||||||
uint16_t j;
|
uint16_t j;
|
||||||
|
#endif
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
_filetype = PRODOS_T_TXT;
|
_filetype = PRODOS_T_TXT;
|
||||||
_auxtype = 0;
|
_auxtype = 0;
|
||||||
@ -1277,8 +1308,8 @@ void save(void) {
|
|||||||
* Main editor routine
|
* Main editor routine
|
||||||
*/
|
*/
|
||||||
int edit(char *fname) {
|
int edit(char *fname) {
|
||||||
char c, *p;
|
char c;
|
||||||
uint16_t pos, tmp;
|
uint16_t pos, tmp, foundpos;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
videomode(VIDEOMODE_80COL);
|
videomode(VIDEOMODE_80COL);
|
||||||
if (fname) {
|
if (fname) {
|
||||||
@ -1418,58 +1449,33 @@ int edit(char *fname) {
|
|||||||
}
|
}
|
||||||
mode = SRCH1;
|
mode = SRCH1;
|
||||||
update_status_line();
|
update_status_line();
|
||||||
#ifdef AUXMEM
|
if (search_in_gapbuf(gapend + 1, search, &foundpos) == 0) {
|
||||||
// TODO
|
|
||||||
#else
|
|
||||||
p = strstr(gapbuf + gapend + 1, search);
|
|
||||||
#endif
|
|
||||||
if (!p) {
|
|
||||||
mode = SRCH2;
|
mode = SRCH2;
|
||||||
update_status_line();
|
update_status_line();
|
||||||
set_gapbuf(gapbegin, '\0');
|
set_gapbuf(gapbegin, '\0');
|
||||||
#ifdef AUXMEM
|
if (search_in_gapbuf(0, search, &foundpos) == 0) {
|
||||||
// TODO
|
|
||||||
#else
|
|
||||||
p = strstr(gapbuf, search);
|
|
||||||
#endif
|
|
||||||
mode = SEL_NONE;
|
|
||||||
if (!p) {
|
|
||||||
mode = SRCH3;
|
mode = SRCH3;
|
||||||
update_status_line();
|
update_status_line();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef AUXMEM
|
mode = SEL_NONE;
|
||||||
// TODO
|
jump_pos(foundpos);
|
||||||
#else
|
|
||||||
jump_pos(p - gapbuf);
|
|
||||||
#endif
|
|
||||||
if (tmp == 0) { // Replace mode
|
if (tmp == 0) { // Replace mode
|
||||||
for (i = 0; i < strlen(search); ++i)
|
for (i = 0; i < strlen(search); ++i)
|
||||||
delete_char_right();
|
delete_char_right();
|
||||||
#ifdef AUXMEM
|
for (i = 0; i < strlen(replace); ++i)
|
||||||
// TODO
|
insert_char(replace[i]);
|
||||||
#else
|
|
||||||
memcpy(gapbuf + gapbegin, replace, strlen(userentry));
|
|
||||||
gapbegin += strlen(replace);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mode = SEL_NONE;
|
mode = SEL_NONE;
|
||||||
#ifdef AUXMEM
|
jump_pos(gapbegin + foundpos - (gapend + 1));
|
||||||
// TODO
|
|
||||||
#else
|
|
||||||
jump_pos(gapbegin + p - (gapbuf + gapend + 1));
|
|
||||||
#endif
|
|
||||||
if (tmp == 0) { // Replace mode
|
if (tmp == 0) { // Replace mode
|
||||||
for (i = 0; i < strlen(search); ++i)
|
for (i = 0; i < strlen(search); ++i)
|
||||||
delete_char_right();
|
delete_char_right();
|
||||||
#ifdef AUXMEM
|
for (i = 0; i < strlen(replace); ++i)
|
||||||
#else
|
insert_char(replace[i]);
|
||||||
memcpy(gapbuf + gapbegin, replace, strlen(userentry));
|
|
||||||
gapbegin += strlen(replace);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user