This commit is contained in:
anon 2023-08-12 16:01:26 +02:00
parent 8f7579ce04
commit dc314f734d
7 changed files with 240 additions and 265 deletions

View File

@ -129,3 +129,9 @@ p page_cursor
c
p page_cursor
c
r
where
frame 1
p wtooltip
r
p tooltip_width

View File

@ -50,7 +50,7 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
# Improvements/Changes
## User side
+ renamed the program, because "cscope" is annoying to type
+ improved gui /*pending*/
+ improved gui
+ GNU Readline integration (ie. VI/EMACS mode, command history) /*pending*/
## To the code
+ nuked autoconf, replaced with single Makefile
@ -68,7 +68,7 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
# Project structure /*probably move to documentation*/
| Component | Purpose |
| :-------: | :-----: |
| main.c | generic init functions, main() and primary event loops (and junk)
| main.c | generic init functions, main() and primary event loops (and junk) |
| display.c | all functions directly dealing with NCurses |
| input.c | top layer of functions dealing with user input; migth dispatch to readline |
| find.c | searching functions |
@ -95,7 +95,6 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
free(): double free detected in tcache 2
Aborted
+ Changing text can crash without replacing text and leaving the console ncursed
+ The wrong number of lines are bing printed
# Future features / contributor wishlist
+ providing support for other languages by integrating new lexers (e.g. ctag's)

View File

@ -22,37 +22,51 @@
#if COLOR_PRESET == 1
#elif COLOR_PRESET == 2
# define COLOR_FRAME_FG COLOR_GREEN
# define COLOR_FRAME_BG -1
# define COLOR_PROMPT_FG COLOR_BLUE
# define COLOR_PROMPT_BG -1
# define COLOR_CURSOR COLOR_WHITE
# define COLOR_FIELD_FG COLOR_WHITE
# define COLOR_FIELD_BG -1
# define COLOR_FIELD_SELECTED_FG COLOR_BLACK
# define COLOR_FIELD_SELECTED_BG COLOR_WHITE
# define COLOR_HELP_FG COLOR_YELLOW
# define COLOR_HELP_BG -1
# define COLOR_TOOLTIP_FG COLOR_BLACK
# define COLOR_TOOLTIP_BG COLOR_WHITE
# define COLOR_MESSAGE_FG COLOR_WHITE
# define COLOR_MESSAGE_BG COLOR_BLACK
# define COLOR_PATTERN_FG COLOR_WHITE
# define COLOR_PATTERN_BG -1
# define COLOR_TABLE_HEADER_FG COLOR_YELLOW
# define COLOR_TABLE_HEADER_BG -1
# define COLOR_TABLE_ID_FG COLOR_CYAN
# define COLOR_TABLE_ID_BG -1
# define COLOR_TABLE_COL_FILE_FG COLOR_MAGENTA
# define COLOR_TABLE_COL_FILE_BG -1
# define COLOR_TABLE_COL_FUNCTION_FG COLOR_RED
# define COLOR_TABLE_COL_FUNCTION_BG -1
# define COLOR_TABLE_COL_LINE_FG COLOR_CYAN
# define COLOR_TABLE_COL_LINE_BG -1
# define COLOR_TABLE_COL_TEXT_FG COLOR_GREEN
# define COLOR_TABLE_COL_TEXT_BG -1
# define COLOR_PAGER_MSG_FG COLOR_YELLOW
# define COLOR_PAGER_MSG_BG -1
# define COLOR_FRAME_FG COLOR_GREEN
# define COLOR_FRAME_BG -1
# define COLOR_PROMPT_FG COLOR_BLUE
# define COLOR_PROMPT_BG -1
# define COLOR_CURSOR COLOR_WHITE
# define COLOR_FIELD_FG COLOR_WHITE
# define COLOR_FIELD_BG -1
# define COLOR_FIELD_SELECTED_FG COLOR_BLACK
# define COLOR_FIELD_SELECTED_BG COLOR_WHITE
# define COLOR_HELP_FG COLOR_YELLOW
# define COLOR_HELP_BG -1
# define COLOR_TOOLTIP_FG COLOR_WHITE
# define COLOR_TOOLTIP_BG COLOR_GREEN
# define COLOR_MESSAGE_FG COLOR_WHITE
# define COLOR_MESSAGE_BG COLOR_BLACK
# define COLOR_PATTERN_FG COLOR_WHITE
# define COLOR_PATTERN_BG -1
# define COLOR_TABLE_HEADER_FG COLOR_YELLOW
# define COLOR_TABLE_HEADER_BG -1
# define COLOR_TABLE_ID_FG COLOR_CYAN
# define COLOR_TABLE_ID_BG -1
# define COLOR_TABLE_MARK_FG COLOR_WHITE
# define COLOR_TABLE_MARK_BG -1
# define COLOR_TABLE_COL_FILE_FG COLOR_MAGENTA
# define COLOR_TABLE_COL_FILE_BG -1
# define COLOR_TABLE_COL_FUNCTION_FG COLOR_RED
# define COLOR_TABLE_COL_FUNCTION_BG -1
# define COLOR_TABLE_COL_LINE_FG COLOR_CYAN
# define COLOR_TABLE_COL_LINE_BG -1
# define COLOR_TABLE_COL_TEXT_FG COLOR_GREEN
# define COLOR_TABLE_COL_TEXT_BG -1
# define COLOR_TABLE_SELECTED_ID_FG COLOR_CYAN
# define COLOR_TABLE_SELECTED_ID_BG COLOR_WHITE
# define COLOR_TABLE_SELECTED_MARK_FG COLOR_BLACK
# define COLOR_TABLE_SELECTED_MARK_BG COLOR_WHITE
# define COLOR_TABLE_COL_SELECTED_FILE_FG COLOR_MAGENTA
# define COLOR_TABLE_COL_SELECTED_FILE_BG COLOR_WHITE
# define COLOR_TABLE_COL_SELECTED_FUNCTION_FG COLOR_RED
# define COLOR_TABLE_COL_SELECTED_FUNCTION_BG COLOR_WHITE
# define COLOR_TABLE_COL_SELECTED_LINE_FG COLOR_CYAN
# define COLOR_TABLE_COL_SELECTED_LINE_BG COLOR_WHITE
# define COLOR_TABLE_COL_SELECTED_TEXT_FG COLOR_GREEN
# define COLOR_TABLE_COL_SELECTED_TEXT_BG COLOR_WHITE
# define COLOR_PAGER_MSG_FG COLOR_YELLOW
# define COLOR_PAGER_MSG_BG COLOR_WHITE
#else
# error "Color profile not valid"
#endif
@ -68,10 +82,17 @@ enum color_pairs{
COLOR_PAIR_MESSAGE,
COLOR_PAIR_TABLE_HEADER,
COLOR_PAIR_TABLE_ID,
COLOR_PAIR_TABLE_MARK,
COLOR_PAIR_TABLE_COL_FILE,
COLOR_PAIR_TABLE_COL_FUNCTION,
COLOR_PAIR_TABLE_COL_LINE,
COLOR_PAIR_TABLE_COL_TEXT,
COLOR_PAIR_TABLE_SELECTED_ID,
COLOR_PAIR_TABLE_SELECTED_MARK,
COLOR_PAIR_TABLE_COL_SELECTED_FILE,
COLOR_PAIR_TABLE_COL_SELECTED_FUNCTION,
COLOR_PAIR_TABLE_COL_SELECTED_LINE,
COLOR_PAIR_TABLE_COL_SELECTED_TEXT,
COLOR_PAIR_PAGER_MSG
};
@ -88,5 +109,6 @@ enum color_pairs{
{ A_BLINK | A_BOLD }
*/
#define ATTRIBUTE_FIELD_SELECTED A_BOLD
#define ATTRIBUTE_RESULT_SELECTED A_BOLD
#endif

View File

@ -83,11 +83,19 @@ const char* prompts[] = {
unsigned int topline = 1; /* top line of page */
extern const char tooltip_winput[];
extern const char tooltip_wmode[];
extern const char tooltip_wresult[];
#define MAX(a, b) ((a) > (b) ? (a) : (b))
/* Selectable windows */
WINDOW* winput;
WINDOW* wmode;
WINDOW* wresult;
WINDOW* whelp;
/* Non-Selectable windows */
WINDOW* wtooltip;
/* Selected window pointer */
WINDOW** current_window;
static WINDOW** last_window;
@ -97,11 +105,20 @@ static int second_col_width;
static int first_col_width;
static int input_window_height;
static int mode_window_height;
static int tooltip_width;
#define WRESULT_TABLE_BODY_START 4
int window_change;
static inline void display_cursor(void);
static inline void display_help(void);
static inline void display_frame(const bool border_only);
static inline void display_mode(void);
static inline void display_command_field(void);
static inline void display_results(void);
static inline void display_tooltip(void);
/* NOTE: It's declared like this because we dont need a terminating '\00'. */
static const char dispchars[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
@ -117,9 +134,6 @@ int dispchar2int(const char c){
}
char lastmsg[MSGLEN + 1]; /* last message displayed */
static const char helpstring[] = "Press the ? key for help";
static const char selprompt[] =
"Select lines to change (press the ? key for help): ";
struct { /* text of input fields */
char *text1;
@ -157,10 +171,18 @@ dispinit(void)
easy_init_pair(PATTERN);
easy_init_pair(TABLE_HEADER);
easy_init_pair(TABLE_ID);
easy_init_pair(TABLE_MARK);
easy_init_pair(TABLE_COL_LINE);
easy_init_pair(TABLE_COL_FILE);
easy_init_pair(TABLE_COL_FUNCTION);
easy_init_pair(TABLE_COL_TEXT);
easy_init_pair(TABLE_ID);
easy_init_pair(TABLE_SELECTED_ID);
easy_init_pair(TABLE_SELECTED_MARK);
easy_init_pair(TABLE_COL_SELECTED_LINE);
easy_init_pair(TABLE_COL_SELECTED_FILE);
easy_init_pair(TABLE_COL_SELECTED_FUNCTION);
easy_init_pair(TABLE_COL_SELECTED_TEXT);
easy_init_pair(PAGER_MSG);
entercurses();
@ -171,6 +193,7 @@ dispinit(void)
first_col_width = 48; // (((COLS - 2)%2 == 0) ? ((COLS-2)/2) : (((COLS-2)/2)+1));
second_col_width = COLS - 2 - 1 - first_col_width; //((COLS - 2) / 2) - 1;
mdisprefs = result_window_height - (WRESULT_TABLE_BODY_START + 1);
tooltip_width = MAX(MAX(strlen(tooltip_winput), strlen(tooltip_wmode)), strlen(tooltip_wresult));
if (mdisprefs <= 0) {
postfatal(PROGRAM_NAME ": screen too small\n");
@ -187,10 +210,11 @@ dispinit(void)
rlinit();
/* initialize windows */
winput = newwin(input_window_height, first_col_width, 1, 1);
wmode = newwin(mode_window_height, first_col_width, input_window_height+1 + 1, 1);
wresult = newwin(result_window_height, second_col_width, 1, first_col_width + 1 + 1);
whelp = newwin(LINES-2, COLS-2, 1, 1);
winput = newwin(input_window_height, first_col_width, 1, 1);
wmode = newwin(mode_window_height, first_col_width, input_window_height+1 + 1, 1);
wresult = newwin(result_window_height, second_col_width, 1, first_col_width + 1 + 1);
whelp = newwin(LINES-2, COLS-2, 1, 1);
wtooltip = newwin(1, tooltip_width, LINES-1, COLS - (tooltip_width+4));
refresh();
current_window = &winput;
@ -259,9 +283,7 @@ static inline void display_frame(const bool border_only){
#else
wprintw(stdscr, PROGRAM_NAME " version %d%s", FILEVERSION, FIXVERSION);
#endif
wmove(stdscr, 0, COLS - (int)sizeof(helpstring) - 3);
waddstr(stdscr, helpstring);
wmove(stdscr, LINES-1, 4);
wmove(stdscr, 0, COLS - (int)sizeof("Case: XXX") - 4);
if(caseless){
waddstr(stdscr, "Case: ON");
}else{
@ -309,12 +331,24 @@ static inline void display_command_field(){
mvwaddstr(winput, 0, 0, prompts[input_mode]);
wattroff(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
waddstr(winput, rl_line_buffer);
display_cursor();
}
static inline void display_results(){
int i;
char *s;
int screenline; /* screen line number */
int srctxtw; /* source line display width */
int color_swp; /* holds the rigth ncurses color value,
* so we dont have to branch twice
* (at attron & attroff)
* because of selections
*/
int attr_swp; /* holds the rigth ncurses attribute value,
* so we dont have to branch twice
* (at attron & attroff)
* because of selections
*/
/* column headings */
char *subsystem; /* OGS subsystem name */
char *book; /* OGS book name */
@ -393,6 +427,8 @@ static inline void display_results(){
disprefs < mdisprefs && screenline < (result_window_height-1);
++disprefs, ++screenline)
{
attr_swp = (disprefs != curdispline) ? A_NORMAL : ATTRIBUTE_RESULT_SELECTED;
wattron(wresult, attr_swp);
/* read the reference line */
if (
fscanf(refsfound, "%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
@ -404,22 +440,28 @@ static inline void display_results(){
<
4
){ break; }
++nextline;
displine[disprefs] = screenline;
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_ID));
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_ID : COLOR_PAIR_TABLE_SELECTED_ID;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%c", dispchars[disprefs]);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_ID));
wattroff(wresult, COLOR_PAIR(color_swp));
/* display any change mark */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_MARK : COLOR_PAIR_TABLE_SELECTED_MARK;
wattron(wresult, COLOR_PAIR(color_swp));
if (input_mode == INPUT_CHANGE && change[topref + disprefs]) {
waddch(wresult, '>');
} else {
waddch(wresult, ' ');
}
wattroff(wresult, COLOR_PAIR(color_swp));
/* display the file name */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FILE));
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FILE : COLOR_PAIR_TABLE_COL_SELECTED_FILE;
wattron(wresult, COLOR_PAIR(color_swp));
if (field == FILENAME) {
wprintw(wresult, "%-*s ", filelen, file);
} else {
@ -435,13 +477,14 @@ static inline void display_results(){
pathcomponents(file, dispcomponents));
}
} /* else(field == FILENAME) */
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FILE));
wattroff(wresult, COLOR_PAIR(color_swp));
/* display the function name */
if(field == SYMBOL || field == CALLEDBY || field == CALLING){
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FUNCTION));
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FUNCTION : COLOR_PAIR_TABLE_COL_SELECTED_FUNCTION;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FUNCTION));
wattroff(wresult, COLOR_PAIR(color_swp));
}
if(field == FILENAME){
waddch(wresult, '\n'); /* go to next line */
@ -449,77 +492,82 @@ static inline void display_results(){
}
/* display the line number */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_LINE));
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_LINE : COLOR_PAIR_TABLE_COL_SELECTED_LINE;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%*s ", numlen, linenum);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_LINE));
wattroff(wresult, COLOR_PAIR(color_swp));
/* there may be tabs in egrep output */
while((s = strchr(tempstring, '\t')) != NULL){
*s = ' ';
}
/* display the source line */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_TEXT));
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_TEXT : COLOR_PAIR_TABLE_COL_SELECTED_TEXT;
wattron(wresult, COLOR_PAIR(color_swp));
s = tempstring;
for (;;) {
/* if the source line does not fit */
if ((i = strlen(s)) > srctxtw) {
/* if the source line does not fit */
if ((i = strlen(s)) > srctxtw) {
/* find the nearest blank */
for (i = srctxtw; s[i] != ' ' && i > 0; --i) {
;
}
/* find the nearest blank */
for (i = srctxtw; s[i] != ' ' && i > 0; --i) {
;
}
if (i == 0) {
i = srctxtw; /* no blank */
}
}
/* print up to this point */
wprintw(wresult, "%.*s", i, s);
s += i;
if (i == 0) {
i = srctxtw; /* no blank */
}
}
/* print up to this point */
wprintw(wresult, "%.*s", i, s);
s += i;
/* if line didn't wrap around */
if (i < srctxtw) {
waddch(wresult, '\n'); /* go to next line */
}
/* skip blanks */
while (*s == ' ') {
++s;
}
/* see if there is more text */
if (*s == '\0') {
break;
}
/* if the source line is too long */
if (++screenline > result_window_height) {
/* if line didn't wrap around */
if (i < srctxtw) {
waddch(wresult, '\n'); /* go to next line */
}
/* skip blanks */
while (*s == ' ') {
++s;
}
/* see if there is more text */
if (*s == '\0') {
break;
}
/* if the source line is too long */
if (++screenline > result_window_height) {
/* if this is the first displayed line,
display what will fit on the screen */
if (topref == nextline-1) {
disprefs++;
/* break out of two loops */
/* if this is the first displayed line,
display what will fit on the screen */
if (topref == nextline-1) {
disprefs++;
/* break out of two loops */
goto endrefs;
}
/* erase the reference */
while (--screenline >= displine[disprefs]) {
wmove(wresult, screenline, 0);
wclrtoeol(wresult);
}
++screenline;
/* go back to the beginning of this reference */
--nextline;
fseek(refsfound, 0, SEEK_SET);
goto endrefs;
}
/* erase the reference */
while (--screenline >= displine[disprefs]) {
wmove(wresult, screenline, 0);
wclrtoeol(wresult);
}
++screenline;
/* go back to the beginning of this reference */
--nextline;
fseek(refsfound, 0, SEEK_SET);
goto endrefs;
}
/* indent the continued source line */
wmove(wresult, screenline, second_col_width - srctxtw);
}
/* indent the continued source line */
wmove(wresult, screenline, second_col_width - srctxtw);
} /* for(ever) */
wattroff(wresult, COLOR_PAIR(color_swp));
wattroff(wresult, attr_swp);
} /* for(reference output lines) */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_TEXT));
endrefs:
/* position the screen cursor for the message */
wattroff(wresult, attr_swp);
/* --- display pager message --- */
/* position cursor */
i = result_window_height - 1;
if (screenline < i) {
waddch(wresult, '\n');
@ -527,34 +575,26 @@ endrefs:
else {
wmove(wresult, i, 0);
}
/* --- display pager message --- */
/**/
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
/* check for more references */
i = totallines - nextline + 1;
bottomline = nextline;
if (i > 0) {
wprintw(wresult, "* Lines %d-%d of %d, %d more - press the space bar to display more *", topref, bottomline, totallines, i);
wprintw(wresult, "* Lines %d-%d of %d, %d more. *", topref, bottomline, totallines, i);
}
/* if this is the last page of references */
else if (current_page > 0 && nextline > totallines) {
waddstr(wresult, "* Press the space bar to display the first lines again *");
waddstr(wresult, "* End of results. *");
}
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
}
void display_cursor(void){
static inline void display_cursor(void){
chtype i;
int yoffset = 0, xoffset = 0;
if(current_window == &winput){
xoffset = strlen(prompts[input_mode]) + rl_point;
}else if(current_window == &wmode){
yoffset = field;
}else if(current_window == &wresult){
yoffset = displine[curdispline];
}else{
assert("No window selected.");
}
xoffset = strlen(prompts[input_mode]) + rl_point;
wmove(*current_window, yoffset, xoffset);
@ -565,6 +605,7 @@ void display_cursor(void){
void
horswp_field(void){
if(current_window != &wresult){
if(totallines == 0){ return; }
if(current_window == &winput){
window_change |= CH_INPUT;
}else{
@ -574,6 +615,9 @@ horswp_field(void){
current_window = &wresult;
}else{
current_window = last_window;
if(current_window == &winput){
window_change |= CH_INPUT;
}
}
window_change |= CH_RESULT;
}
@ -756,10 +800,30 @@ ogsnames(char *file, char **subsystem, char **book)
}
}
static inline void display_tooltip(void){
wmove(wtooltip, 0, 0);
const char* tooltip;
if(*current_window == winput){
tooltip = tooltip_winput;
}else if(*current_window == wmode){
tooltip = tooltip_wmode;
}else if(*current_window == wresult){
tooltip = tooltip_wresult;
}
wattron(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
waddstr(wtooltip, tooltip);
// XXX: cheap hack
for(int i = 0; i < (tooltip_width-strlen(tooltip)); i++){
waddch(wtooltip, ' ');
}
wattroff(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
}
void
display(void)
{
//drawscrollbar(topline, nextline); /* display the scrollbar */
static void* lstwin = NULL; /* for the tooltip (see below) */
if(window_change){
if(window_change == CH_HELP){
@ -771,10 +835,16 @@ display(void)
window_change = CH_ALL;
return;
}
/**/
if(window_change == CH_ALL){
display_frame(false);
}
/* As it stands the tooltip has to be redisplayed
* on every window change.
*/
if(lstwin != *current_window){
lstwin = *current_window;
display_tooltip();
}
if(window_change & CH_INPUT){
display_command_field();
}
@ -785,12 +855,11 @@ display(void)
display_mode();
}
display_cursor();
refresh();
wrefresh(winput);
wrefresh(wmode);
wrefresh(wresult);
wrefresh(wtooltip);
}
window_change = CH_NONE;

View File

@ -47,6 +47,9 @@
#include <signal.h> /* SIGINT and SIGQUIT */
#include <stdio.h> /* standard I/O package */
#include <stdlib.h> /* standard library functions */
#include <stdarg.h>
#include <fcntl.h>
#include <stdbool.h>
#include <string.h> /* string functions */
@ -57,12 +60,6 @@
typedef void (*sighandler_t)(int);
#include <stdarg.h>
#include <fcntl.h>
#include <stdbool.h>
typedef struct { /* mouse action */
int button;
int percent;
@ -315,7 +312,6 @@ struct cmd *prevcmd(void);
struct cmd *nextcmd(void);
int egrep(char *file, FILE *output, char *format);
int mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless);
int hash(char *ss);
int execute(char *a, ...);
long dbseek(long offset);

View File

@ -37,16 +37,15 @@
*/
#include "global.h"
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
#else
#include <curses.h>
#endif
/*
max num of lines of help screen -
this number needs to be increased if more than n help items are needed
*/
#define MAXHELP 50 /* maximum number of help strings */
const char tooltip_winput[] = "Search [Enter] -Mode [^k] +Mode [^j] Right [Tab] Down [%]";
const char tooltip_wmode[] = "-Mode [Up] +Mode [Down] Right [Tab] Up [%]";
const char tooltip_wresult[] = "Edit [Enter] Up [Up] Down [Down] Left [Tab] Previous [-] Next [+]";
static char help_msg[] =
"Press the RETURN key repeatedly to move to the desired input field, type the\n"

View File

@ -70,130 +70,7 @@ myungetch(int c)
{
prevchar = c;
}
/* get a line from the terminal in non-canonical mode */
int
mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless){
int c;
unsigned int i = 0, j;
char *sright; /* substring to the right of the cursor */
unsigned int ri = 0; /* position in right-string */
/* Inserts and deletes are always performed on the left-string,
* but we'll also have a right-string 'sright' to hold characters
* which are on the right of the cursor [insertion point].
*
* Think of 'sright' as a stack -- we push chars into it when the cursor
* moves left, and we pop chars off it when the cursor moves right again.
* At the end of the function, we'll pop off any remaining characters
* onto the end of 's'
*/
sright = calloc(size, sizeof(*sright));
strcpy ( s, p);
i += strlen(p);
/* if a character already has been typed */
if (firstchar != '\0') {
if(iscaseless == true) {
firstchar = tolower(firstchar);
}
addch(firstchar); /* display it */
s[i++] = firstchar; /* save it */
}
/* until the end of the line is reached */
while ((c = getch()) != '\r' && c != '\n' && c != KEY_ENTER) {
if (c == KEY_LEFT || c == ctrl('B')) { /* left */
if (i > 0) {
addch('\b');
/* move this char into the second (rhs) string */
sright[ri++] = s[--i];
}
} else if (c == KEY_RIGHT || c == ctrl('F')) { /* right */
if (i < size && ri > 0) {
/* move this char to the left of the cursor */
s[i++] = sright[--ri];
addch(s[i-1]);
}
} else if (c == KEY_HOME || c == ctrl('A') ) {
while (i > 0) {
sright[ri++] = s[--i];
addch('\b');
addch(s[i]);
addch('\b');
}
} else if (c == KEY_END || c == ctrl('E') ) {
while (ri > 0) {
s[i++] = sright[--ri];
addch(s[i-1]);
}
} else if (c == erasechar() || c == KEY_BACKSPACE
|| c == DEL || c == ctrl('H') ) {
/* erase */
if (i > 0) {
if (ri == 0) {
addstr("\b \b");
} else {
addch('\b');
delch();
}
s[i] = '\0';
--i;
}
} else if (c == killchar() || c == KEY_BREAK) {
/* kill */
for (j = 0; j < i; ++j) {
addch('\b');
}
for (j = 0; j < i; ++j) {
addch(' ');
}
for (j = 0; j < i; ++j) {
addch('\b');
}
i = 0;
} else if (isprint(c) || c == '\t') {
/* printable */
if(iscaseless == true) {
c = tolower(c);
}
/* if it will fit on the line */
if (i < size) {
s[i++] = c; /* save it */
if (ri == 0) {
addch(c); /* display it */
} else {
insch(c); /* display it */
addch(c); /* advance cursor */
}
}
} else if (/*unixpcmouse == true && */c == ESC) { /* mouse */
getmouseaction(ESC); /* ignore it */
} else if (mouse == true && c == ctrl('X')) {
getmouseaction(ctrl('X')); /* ignore it */
} else if (c == EOF) { /* end-of-file */
break;
}
/* return on an empty line to allow a command to be entered */
if (firstchar != '\0' && (i+ri) == 0) {
break;
}
}
/* move any remaining chars on the rhs of the cursor
* onto the end of our string
*/
while (ri > 0) {
s[i++] = sright[--ri];
}
free(sright);
s[i] = '\0';
return(i);
}
/* ask user to enter a character after reading the message */
void
askforchar(void){
addstr("Type any character to continue: ");
@ -201,7 +78,6 @@ askforchar(void){
}
/* ask user to press the RETURN key after reading the message */
void
askforreturn(void){
fprintf(stderr, "Press the RETURN key to continue: ");
@ -213,7 +89,6 @@ askforreturn(void){
}
/* expand the ~ and $ shell meta characters in a path */
void
shellpath(char *out, int limit, char *in){
char *lastchar;
@ -368,14 +243,15 @@ global_input(const int c){
case '%':
verswp_field();
break;
case ' ': /* display next page */
case '+':
case ctrl('V'):
case KEY_NPAGE:
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
curdispline = 0;
++current_page;
window_change |= CH_RESULT;
case ctrl('K'):
field = (field + (FIELDS - 1)) % FIELDS;
resetcmd();
window_change |= CH_MODE;
break;
case ctrl('J'):
field = (field + 1) % FIELDS;
resetcmd();
window_change |= CH_MODE;
break;
case ctrl('H'): /* display previous page */
case '-':
@ -387,6 +263,14 @@ global_input(const int c){
window_change |= CH_RESULT;
}
break;
case '+':
case ctrl('L'):
case KEY_NPAGE:
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
curdispline = 0;
++current_page;
window_change |= CH_RESULT;
break;
case '>': /* write or append the lines to a file */
break; // XXX
//char filename[PATHLEN + 1];
@ -487,7 +371,7 @@ global_input(const int c){
case KEY_RESIZE:
/* XXX: fill in*/
break;
case ctrl('L'): /* redraw screen */
case ctrl('U'): /* redraw screen */
case KEY_CLEAR:
window_change = CH_ALL;
break;