2023-08-04 13:12:06 -04:00
|
|
|
#include <stdio.h>
|
2023-08-01 13:36:53 -04:00
|
|
|
#include <readline/readline.h>
|
|
|
|
#include "global.h"
|
2023-08-04 13:12:06 -04:00
|
|
|
#include "build.h"
|
2023-08-04 16:35:56 -04:00
|
|
|
#include <ncurses.h>
|
2023-08-01 13:36:53 -04:00
|
|
|
|
2023-08-04 13:12:06 -04:00
|
|
|
static int input_available = 0;
|
|
|
|
static char input_char;
|
|
|
|
char input_line[PATLEN + 1];
|
|
|
|
|
2023-08-04 15:09:58 -04:00
|
|
|
bool interpret(int c){
|
2023-08-04 13:49:03 -04:00
|
|
|
input_char = c;
|
|
|
|
input_available = 1;
|
|
|
|
rl_callback_read_char();
|
2023-08-04 13:12:06 -04:00
|
|
|
|
2023-08-09 07:49:11 -04:00
|
|
|
return 0;
|
2023-08-04 13:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int getc_function(FILE* ignore){
|
2023-08-09 07:49:11 -04:00
|
|
|
UNUSED(ignore);
|
|
|
|
|
2023-08-04 13:49:03 -04:00
|
|
|
input_available = 0;
|
|
|
|
return (int)input_char;
|
2023-08-01 13:36:53 -04:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:12:06 -04:00
|
|
|
static int input_available_hook(){
|
2023-08-04 13:49:03 -04:00
|
|
|
return input_available;
|
2023-08-01 13:36:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void redisplay_function(){
|
2023-08-04 13:49:03 -04:00
|
|
|
window_change |= CH_INPUT;
|
2023-08-01 13:36:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void callback_handler(char* line){
|
2023-08-05 05:30:18 -04:00
|
|
|
if(!line){ return; }
|
2023-08-04 13:49:03 -04:00
|
|
|
strncpy(input_line, line, PATLEN);
|
2023-08-08 14:34:15 -04:00
|
|
|
|
2023-08-10 08:36:16 -04:00
|
|
|
switch(input_mode){
|
|
|
|
case INPUT_NORMAL:
|
|
|
|
search();
|
|
|
|
break;
|
|
|
|
case INPUT_CHANGE:
|
|
|
|
changestring();
|
|
|
|
input_mode = INPUT_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
2023-08-09 07:49:11 -04:00
|
|
|
|
2023-08-10 08:36:16 -04:00
|
|
|
switch(field){
|
|
|
|
case CHANGE:
|
|
|
|
input_mode = INPUT_CHANGE;
|
|
|
|
break;
|
|
|
|
case DEFINITION:
|
|
|
|
case FILENAME:
|
|
|
|
if(totallines == 1){ editref(0); }
|
|
|
|
break;
|
2023-08-09 07:49:11 -04:00
|
|
|
}
|
2023-08-08 14:34:15 -04:00
|
|
|
|
|
|
|
curdispline = 0;
|
|
|
|
PCS_reset();
|
|
|
|
current_page = 0;
|
2023-08-01 13:36:53 -04:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:12:06 -04:00
|
|
|
static int ctrl_z(){
|
2023-08-04 13:49:03 -04:00
|
|
|
kill(0, SIGTSTP);
|
2023-08-05 05:30:18 -04:00
|
|
|
return 0;
|
2023-08-04 13:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int toggle_caseless(){
|
2023-08-04 15:09:58 -04:00
|
|
|
if (caseless == false) {
|
|
|
|
caseless = true;
|
2023-08-04 13:49:03 -04:00
|
|
|
postmsg2("Caseless mode is now ON");
|
|
|
|
} else {
|
2023-08-04 15:09:58 -04:00
|
|
|
caseless = false;
|
2023-08-04 13:49:03 -04:00
|
|
|
postmsg2("Caseless mode is now OFF");
|
|
|
|
}
|
|
|
|
egrepcaseless(caseless); /* turn on/off -i flag */
|
2023-08-05 05:30:18 -04:00
|
|
|
return 0;
|
2023-08-04 13:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rebuild_reference(){
|
2023-08-04 15:09:58 -04:00
|
|
|
if (isuptodate == true) {
|
2023-08-04 13:49:03 -04:00
|
|
|
postmsg("The -d option prevents rebuilding the symbol database");
|
2023-08-04 15:09:58 -04:00
|
|
|
return(false);
|
2023-08-04 13:49:03 -04:00
|
|
|
}
|
|
|
|
exitcurses();
|
2023-08-04 14:05:31 -04:00
|
|
|
freefilelist(); /* remake the source file list */
|
2023-08-04 13:49:03 -04:00
|
|
|
makefilelist();
|
|
|
|
rebuild();
|
2023-08-04 15:09:58 -04:00
|
|
|
if (errorsfound == true) {
|
|
|
|
errorsfound = false;
|
2023-08-04 13:49:03 -04:00
|
|
|
askforreturn();
|
2023-08-04 14:34:51 -04:00
|
|
|
}
|
2023-08-04 13:49:03 -04:00
|
|
|
entercurses();
|
2023-08-09 07:49:11 -04:00
|
|
|
postmsg(""); /* clear any previous message */
|
2023-08-04 13:49:03 -04:00
|
|
|
totallines = 0;
|
2023-08-04 14:34:51 -04:00
|
|
|
disprefs = 0;
|
2023-08-04 15:09:58 -04:00
|
|
|
return(true);
|
2023-08-04 13:12:06 -04:00
|
|
|
}
|
|
|
|
|
2023-08-01 13:36:53 -04:00
|
|
|
void rlinit(){
|
2023-08-04 13:49:03 -04:00
|
|
|
rl_catch_signals = 0;
|
|
|
|
rl_catch_sigwinch = 0;
|
|
|
|
rl_prep_term_function = NULL;
|
|
|
|
rl_deprep_term_function = NULL;
|
|
|
|
rl_change_environment = 0;
|
|
|
|
|
|
|
|
rl_getc_function = getc_function;
|
|
|
|
rl_input_available_hook = input_available_hook;
|
|
|
|
rl_redisplay_function = redisplay_function;
|
|
|
|
rl_callback_handler_install("", callback_handler);
|
|
|
|
|
2023-08-04 16:35:56 -04:00
|
|
|
rl_bind_key(7, rl_rubout); // XXX: 7 is backspace for some reason (on my system anyways?)
|
|
|
|
rl_bind_key(KEY_BACKSPACE, rl_rubout);
|
|
|
|
|
|
|
|
rl_bind_key(EOF, exit);
|
2023-08-04 13:49:03 -04:00
|
|
|
rl_bind_key(ctrl('Z'), ctrl_z);
|
|
|
|
rl_bind_key(ctrl('Z'), toggle_caseless);
|
|
|
|
rl_bind_key(ctrl('R'), rebuild_reference);
|
2023-08-04 14:05:31 -04:00
|
|
|
rl_bind_key(ESC, process_mouse); /* possible unixpc mouse selection */
|
2023-08-04 13:49:03 -04:00
|
|
|
rl_bind_key(ctrl('X'), process_mouse); /* mouse selection */
|
|
|
|
|
2023-08-04 14:05:31 -04:00
|
|
|
//rl_bind_key(ctrl('\\'), /**/); /* bypass bindings */
|
2023-08-01 13:36:53 -04:00
|
|
|
}
|