From a83c6632c3e678d2fc34c433c8690ad39869cbcb Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 10 Aug 2023 15:52:28 +0200 Subject: [PATCH] bak --- README.md | 1 + src/display.c | 8 ++++---- src/global.h | 2 +- src/input.c | 63 +++++++++++++++++++++++++++++----------------------------- src/readline.c | 2 +- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 0fa2876..d32c749 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no + library.h...; "private library", in a program using 90 globals; ffs + sort out the global hell + changestring() forks sh to execute an ed script... + + was there really ever a scrollbar? ## Original + Display the current case mode (^C) onscreen + emacs like key bindings diff --git a/src/display.c b/src/display.c index 51162e9..191ae72 100644 --- a/src/display.c +++ b/src/display.c @@ -79,7 +79,7 @@ const char* prompts[] = { [INPUT_CHANGE] = "To: " }; -static unsigned int topline = 1; /* top line of page */ +unsigned int topline = 1; /* top line of page */ /* Selectable windows */ WINDOW* winput; @@ -444,9 +444,9 @@ static inline void display_results(){ /* if this is the first displayed line, display what will fit on the screen */ if (topline == nextline-1) { - disprefs++; - /* break out of two loops */ - goto endrefs; + disprefs++; + /* break out of two loops */ + goto endrefs; } /* erase the reference */ diff --git a/src/global.h b/src/global.h index 32c01e5..1bbe8b0 100644 --- a/src/global.h +++ b/src/global.h @@ -254,7 +254,7 @@ int handle_input(const int c); int dispchar2int(const char c); int process_mouse(); extern int input_mode; -int changestring(bool *change); +int changestring(const char* from, const char* to, bool *change); long seekpage(size_t i); long seekrelline(unsigned i); diff --git a/src/input.c b/src/input.c index 17fc780..cacf085 100644 --- a/src/input.c +++ b/src/input.c @@ -529,24 +529,23 @@ extern const void *const winput; extern const void *const wmode; extern const void *const wresult; extern const void *const *const current_window; +extern const int topline; -static int +int change_input(const int c){ MOUSE *p; /* mouse data */ change = calloc(totallines, sizeof(*change)); switch(c){ - case '*': /* invert selection */ - //for(int i = 0; topline + i < nextline; ++i){ - // change[i] = !change[i]; - //} + case '*': /* invert page */ + for(int i = 0; topline + i < nextline; i++){ + change[topline + i] = !change[topline + i]; + } break; - case ctrl('A'): /* mark/unmark all lines */ - for(unsigned i = 0; i < totallines; ++i) { + case ctrl('A'): /* invert all lines */ + for(unsigned i = 0; i < totallines; i++) { change[i] = !change[i]; } - /* show that all have been marked */ - //seekline(totallines); // ?! break; case ctrl('X'): /* mouse selection */ if ((p = getmouseaction(DUMMYCHAR)) == NULL) { @@ -570,7 +569,7 @@ change_input(const int c){ } break; case ctrl('D'): - changestring(change); + changestring(input_line, newpat, change); break; default: { @@ -586,7 +585,7 @@ change_input(const int c){ } int -changestring(bool *change){ +changestring(const char* from, const char* to, bool *change){ char newfile[PATHLEN + 1]; /* new file name */ char oldfile[PATHLEN + 1]; /* old file name */ char linenum[NUMLEN + 1]; /* file line number */ @@ -632,27 +631,27 @@ changestring(bool *change){ } /* output substitute command */ fprintf(script, "%ss/", linenum); /* change */ - //for (char *s = Pattern; *s != '\0'; ++s) { - // /* old text */ - // if (strchr("/\\[.^*", *s) != NULL) { - // putc('\\', script); - // } - // if (caseless == true && isalpha((unsigned char)*s)) { - // putc('[', script); - // if(islower((unsigned char)*s)) { - // putc(toupper((unsigned char)*s), script); - // putc(*s, script); - // } else { - // putc(*s, script); - // putc(tolower((unsigned char)*s), script); - // } - // putc(']', script); - // } else { - // putc(*s, script); - // } - //} + for(const char *s = from; *s != '\0'; ++s) { + /* old text */ + if (strchr("/\\[.^*", *s) != NULL) { + putc('\\', script); + } + if (caseless == true && isalpha((unsigned char)*s)) { + putc('[', script); + if(islower((unsigned char)*s)) { + putc(toupper((unsigned char)*s), script); + putc(*s, script); + } else { + putc(*s, script); + putc(tolower((unsigned char)*s), script); + } + putc(']', script); + } else { + putc(*s, script); + } + } putc('/', script); /* to */ - for (char *s = newpat; *s != '\0'; ++s) { /* new text */ + for(const char *s = to; *s != '\0'; ++s) { /* new text */ if (strchr("/\\&", *s) != NULL) { putc('\\', script); } @@ -661,7 +660,6 @@ changestring(bool *change){ fprintf(script, "/gp\n"); /* and print */ } fprintf(script, "w\nq\n!\n"); /* write and quit */ - fclose(script); /* if any line was marked */ if (anymarked == true) { @@ -670,6 +668,7 @@ changestring(bool *change){ execute("sh", "sh", temp2, NULL); askforchar(); } + changing = false; mousemenu(); fclose(script); diff --git a/src/readline.c b/src/readline.c index ca19559..278cc5c 100644 --- a/src/readline.c +++ b/src/readline.c @@ -40,7 +40,7 @@ static void callback_handler(char* line){ search(); break; case INPUT_CHANGE: - changestring(NULL); + changestring(change); input_mode = INPUT_NORMAL; break; }