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>
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
# include <ncurses.h>
#else
# include <curses.h>
#endif
#include <ncurses.h>
#include <ctype.h>
/* 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
* to perform with the user input.
* 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 wmode;
@ -71,13 +67,13 @@ bool readrefs(char *filename) {
FILE *file;
int c;
if((file = myfopen(filename, "rb")) == NULL) {
if((file = myfopen(filename, "r")) == NULL) {
cannotopen(filename);
return (false);
return false;
}
if((c = getc(file)) == EOF) { /* if file is empty */
fclose(file);
return (false);
return false;
}
totallines = 0;
disprefs = 0;
@ -94,13 +90,15 @@ bool readrefs(char *filename) {
return (false);
}
countrefs();
} else
} else {
fclose(file);
}
return (true);
}
/* scrollbar actions */
static void scrollbar(MOUSE *p) {
// XXX
///* reposition list if it makes sense */
// if (totallines == 0) {
// return;

View File

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

View File

@ -85,20 +85,20 @@ static void callback_handler(char *line) {
add_history(line);
switch(input_mode) {
case INPUT_NORMAL:
case INPUT_NORMAL: {
strncpy(input_line, line, PATLEN);
search(input_line);
horswp_window();
curdispline = 0;
current_page = 0;
PCS_reset();
break;
case INPUT_CHANGE_TO:
} break;
case INPUT_CHANGE_TO: {
strncpy(newpat, line, PATLEN);
change = calloc(totallines, sizeof(*change));
input_mode = INPUT_CHANGE;
force_window();
return;
} return;
case INPUT_APPEND: {
char filename[PATHLEN + 1];
FILE* file;
@ -111,8 +111,16 @@ static void callback_handler(char *line) {
}
fclose(file);
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) {