mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-08-07 07:25:21 +00:00
EDIT: minor refactoring of search/replace. Prompt to save changes before load.
This commit is contained in:
52
apps/edit.c
52
apps/edit.c
@@ -3,6 +3,8 @@
|
|||||||
// Bobbi July-Aug 2020
|
// Bobbi July-Aug 2020
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO: Search options - ignore case, complete word, replace all
|
||||||
|
|
||||||
// Note: Use my fork of cc65 to get a flashing cursor!!
|
// Note: Use my fork of cc65 to get a flashing cursor!!
|
||||||
|
|
||||||
#define AUXMEM // Still somewhat experimental
|
#define AUXMEM // Still somewhat experimental
|
||||||
@@ -719,10 +721,11 @@ done:
|
|||||||
uint8_t save_file(char *filename) {
|
uint8_t save_file(char *filename) {
|
||||||
uint16_t pos = gapbegin;
|
uint16_t pos = gapbegin;
|
||||||
uint8_t retval = 1;
|
uint8_t retval = 1;
|
||||||
char *p;
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
uint16_t j;
|
uint16_t p, j;
|
||||||
|
#else
|
||||||
|
char *p;
|
||||||
#endif
|
#endif
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
_filetype = PRODOS_T_TXT;
|
_filetype = PRODOS_T_TXT;
|
||||||
@@ -1403,6 +1406,25 @@ void save(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform replace part of search/replace
|
||||||
|
* pos - position where search term was found
|
||||||
|
* r - if 0 then perform replace operation
|
||||||
|
*/
|
||||||
|
void finish_search_replace(uint16_t pos, uint8_t r) {
|
||||||
|
uint8_t i;
|
||||||
|
mode = SEL_NONE;
|
||||||
|
jump_pos(pos);
|
||||||
|
if (r == 0) { // Replace mode
|
||||||
|
for (i = 0; i < strlen(search); ++i)
|
||||||
|
delete_char_right();
|
||||||
|
for (i = 0; i < strlen(replace); ++i)
|
||||||
|
insert_char(replace[i]);
|
||||||
|
}
|
||||||
|
set_modified(1);
|
||||||
|
draw_screen();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main editor routine
|
* Main editor routine
|
||||||
*/
|
*/
|
||||||
@@ -1557,28 +1579,10 @@ int edit(char *fname) {
|
|||||||
update_status_line();
|
update_status_line();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mode = SEL_NONE;
|
finish_search_replace(foundpos, tmp);
|
||||||
jump_pos(foundpos);
|
|
||||||
if (tmp == 0) { // Replace mode
|
|
||||||
for (i = 0; i < strlen(search); ++i)
|
|
||||||
delete_char_right();
|
|
||||||
for (i = 0; i < strlen(replace); ++i)
|
|
||||||
insert_char(replace[i]);
|
|
||||||
}
|
|
||||||
set_modified(1);
|
|
||||||
draw_screen();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mode = SEL_NONE;
|
finish_search_replace(gapbegin + foundpos - (gapend + 1), tmp);
|
||||||
jump_pos(gapbegin + foundpos - (gapend + 1));
|
|
||||||
if (tmp == 0) { // Replace mode
|
|
||||||
for (i = 0; i < strlen(search); ++i)
|
|
||||||
delete_char_right();
|
|
||||||
for (i = 0; i < strlen(replace); ++i)
|
|
||||||
insert_char(replace[i]);
|
|
||||||
}
|
|
||||||
set_modified(1);
|
|
||||||
draw_screen();
|
|
||||||
break;
|
break;
|
||||||
case 0x80 + 'I': // OA-I "Insert file"
|
case 0x80 + 'I': // OA-I "Insert file"
|
||||||
case 0x80 + 'i':
|
case 0x80 + 'i':
|
||||||
@@ -1592,6 +1596,8 @@ int edit(char *fname) {
|
|||||||
break;
|
break;
|
||||||
case 0x80 + 'L': // OA-L "Load"
|
case 0x80 + 'L': // OA-L "Load"
|
||||||
case 0x80 + 'l':
|
case 0x80 + 'l':
|
||||||
|
if (modified)
|
||||||
|
save();
|
||||||
if (prompt_for_name("File to load", 1) == 255)
|
if (prompt_for_name("File to load", 1) == 255)
|
||||||
break; // ESC pressed
|
break; // ESC pressed
|
||||||
if (strlen(userentry) == 0)
|
if (strlen(userentry) == 0)
|
||||||
@@ -1783,7 +1789,7 @@ copymove2_cleanup:
|
|||||||
|
|
||||||
void main(int argc, char *argv[]) {
|
void main(int argc, char *argv[]) {
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
char *pad = 0xbfff;
|
char *pad = (char*)0xbfff;
|
||||||
*pad = '\0'; // Null termination for strstr()
|
*pad = '\0'; // Null termination for strstr()
|
||||||
#endif
|
#endif
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
|
Reference in New Issue
Block a user