reading results from a file works again

This commit is contained in:
anon 2023-09-02 19:40:35 +02:00
parent 8fc2e971c3
commit e0e58c2d81
3 changed files with 31 additions and 34 deletions

View File

@ -40,11 +40,7 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h> #include <ncurses.h>
#else
# include <curses.h>
#endif
#include <ctype.h> #include <ctype.h>
/* These are strictly used to test how keys are suppose to behave. /* These are strictly used to test how keys are suppose to behave.
@ -52,7 +48,7 @@
* with the history, while in _mode mode_ it selects what operation * with the history, while in _mode mode_ it selects what operation
* to perform with the user input. * to perform with the user input.
* In the original version this was handled by * In the original version this was handled by
* "int selecting // whether the (upper) symbol list is being browsed". * `int selecting // whether the (upper) symbol list is being browsed`.
*/ */
extern const void *const winput; extern const void *const winput;
extern const void *const wmode; extern const void *const wmode;
@ -71,13 +67,13 @@ bool readrefs(char *filename) {
FILE *file; FILE *file;
int c; int c;
if((file = myfopen(filename, "rb")) == NULL) { if((file = myfopen(filename, "r")) == NULL) {
cannotopen(filename); cannotopen(filename);
return (false); return false;
} }
if((c = getc(file)) == EOF) { /* if file is empty */ if((c = getc(file)) == EOF) { /* if file is empty */
fclose(file); fclose(file);
return (false); return false;
} }
totallines = 0; totallines = 0;
disprefs = 0; disprefs = 0;
@ -94,13 +90,15 @@ bool readrefs(char *filename) {
return (false); return (false);
} }
countrefs(); countrefs();
} else } else {
fclose(file); fclose(file);
}
return (true); return (true);
} }
/* scrollbar actions */ /* scrollbar actions */
static void scrollbar(MOUSE *p) { static void scrollbar(MOUSE *p) {
// XXX
///* reposition list if it makes sense */ ///* reposition list if it makes sense */
// if (totallines == 0) { // if (totallines == 0) {
// return; // return;

View File

@ -265,21 +265,10 @@ static int global_input(const int c) {
force_window(); force_window();
break; break;
case '<': /* read lines from a file */ case '<': /* read lines from a file */
break; // XXX input_mode = INPUT_READ;
// move(PRLINE, 0); window_change |= CH_INPUT;
// addstr(readprompt); // XXX fix force_window();
// if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) { break;
// clearprompt();
// shellpath(filename, sizeof(filename), newpat);
// if (readrefs(filename) == NO) {
// postmsg2("Ignoring an empty file");
// return(NO);
// }
// window_change |= CH_INPUT;
// return(YES);
// }
// clearprompt();
return 0;
case '|': /* pipe the lines to a shell command */ case '|': /* pipe the lines to a shell command */
case '^': case '^':
break; // XXX fix break; // XXX fix
@ -503,9 +492,10 @@ int handle_input(const int c) {
return 0; return 0;
} }
/* - Resize - */ /* - Resize - */
/* it's treated specially because curses treat it specially. /* it's treated specially because curses treat it specially:
as far as i can tell this is the only key that does not + its valid without keypad()
flush after itself. + as far as i can tell this is the only key that does not
flush after itself
*/ */
if(c == KEY_RESIZE) { if(c == KEY_RESIZE) {
redisplay(); redisplay();
@ -530,6 +520,7 @@ int handle_input(const int c) {
break; /* NOTREACHED */ break; /* NOTREACHED */
case INPUT_CHANGE_TO: case INPUT_CHANGE_TO:
case INPUT_APPEND: case INPUT_APPEND:
case INPUT_READ:
return interpret(c); return interpret(c);
case INPUT_CHANGE: case INPUT_CHANGE:
return change_input(c); return change_input(c);

View File

@ -85,20 +85,20 @@ static void callback_handler(char *line) {
add_history(line); add_history(line);
switch(input_mode) { switch(input_mode) {
case INPUT_NORMAL: case INPUT_NORMAL: {
strncpy(input_line, line, PATLEN); strncpy(input_line, line, PATLEN);
search(input_line); search(input_line);
horswp_window(); horswp_window();
curdispline = 0; curdispline = 0;
current_page = 0; current_page = 0;
PCS_reset(); PCS_reset();
break; } break;
case INPUT_CHANGE_TO: case INPUT_CHANGE_TO: {
strncpy(newpat, line, PATLEN); strncpy(newpat, line, PATLEN);
change = calloc(totallines, sizeof(*change)); change = calloc(totallines, sizeof(*change));
input_mode = INPUT_CHANGE; input_mode = INPUT_CHANGE;
force_window(); force_window();
return; } return;
case INPUT_APPEND: { case INPUT_APPEND: {
char filename[PATHLEN + 1]; char filename[PATHLEN + 1];
FILE* file; FILE* file;
@ -111,8 +111,16 @@ static void callback_handler(char *line) {
} }
fclose(file); fclose(file);
input_mode = INPUT_NORMAL; input_mode = INPUT_NORMAL;
return; } return;
case INPUT_READ: {
char filename[PATHLEN + 1];
shellpath(filename, sizeof(filename), line);
if (!readrefs(filename)) {
postmsg("Ignoring an empty file");
} }
window_change |= CH_INPUT | CH_RESULT;
input_mode = INPUT_NORMAL;
} return;
} }
switch(field) { switch(field) {