csope/src/display.c

829 lines
24 KiB
C
Raw Normal View History

2023-07-27 14:04:50 -04:00
/*===========================================================================
2023-08-04 13:54:19 -04:00
Copyright (c) 1998-2000, The Santa Cruz Operation
2023-07-27 14:04:50 -04:00
All rights reserved.
2023-08-04 13:54:19 -04:00
2023-07-27 14:04:50 -04:00
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
*Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
*Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
*Neither name of The Santa Cruz Operation nor the names of its contributors
may be used to endorse or promote products derived from this software
2023-08-04 13:54:19 -04:00
without specific prior written permission.
2023-07-27 14:04:50 -04:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT falseT LIMITED TO,
2023-07-27 14:04:50 -04:00
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2023-08-04 15:19:25 -04:00
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
2023-07-27 14:04:50 -04:00
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT falseT LIMITED TO, PROCUREMENT OF
2023-07-27 14:04:50 -04:00
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2023-08-04 13:54:19 -04:00
DAMAGE.
2023-07-27 14:04:50 -04:00
=========================================================================*/
2023-08-04 13:49:03 -04:00
/* cscope - interactive C symbol cross-reference
2023-07-27 14:04:50 -04:00
*
2023-08-04 13:49:03 -04:00
* display functions
2023-07-27 14:04:50 -04:00
*/
#include "global.h"
#include "build.h"
2023-08-11 13:20:52 -04:00
#include "colors.h"
2023-07-27 14:04:50 -04:00
#ifdef CCS
2023-08-13 05:21:52 -04:00
# include "sgs.h" /* ESG_PKG and ESG_REL */
2023-07-27 14:04:50 -04:00
#else
2023-08-13 05:21:52 -04:00
# include "version.h" /* FILEVERSION and FIXVERSION */
2023-07-27 14:04:50 -04:00
#endif
#include <ncurses.h>
2023-08-13 05:21:52 -04:00
#include <stdarg.h> /* va_list stuff */
2023-07-27 14:04:50 -04:00
#include <time.h>
#include <errno.h>
#include <stdarg.h>
2023-07-29 09:40:48 -04:00
2023-08-09 07:49:11 -04:00
/* XXX */
2023-08-13 05:21:52 -04:00
#define MSGLINE 0 /* message line */
#define MSGCOL 0 /* message column */
int subsystemlen = sizeof("Subsystem") - 1; /* OGS subsystem name display field length */
int booklen = sizeof("Book") - 1; /* OGS book name display field length */
int filelen = sizeof("File") - 1; /* file name display field length */
int fcnlen = sizeof("Function") - 1; /* function name display field length */
int numlen = 0; /* line number display field length */
int *displine; /* screen line of displayed reference */
unsigned int disprefs; /* displayed references */
int field; /* input field */
unsigned int mdisprefs; /* maximum displayed references */
unsigned int nextline; /* next line to be shown */
static int bottomline; /* bottom line of page */
long searchcount; /* count of files searched */
unsigned int totallines; /* total reference lines */
unsigned int curdispline = 0;
int current_page = 0;
int input_mode = INPUT_NORMAL;
const char *prompts[] = {[INPUT_NORMAL] = "$ ",
[INPUT_APPEND] = "Append to file: ",
[INPUT_PIPE] = "Pipe to shell command: ",
[INPUT_READ] = "Read from file: ",
[INPUT_CHANGE_TO] = "To: ",
[INPUT_CHANGE] = "To: "};
unsigned int topline = 1; /* top line of page */
2023-07-29 09:40:48 -04:00
2023-08-12 10:01:26 -04:00
extern const char tooltip_winput[];
extern const char tooltip_wmode[];
extern const char tooltip_wresult[];
#define MAX(a, b) ((a) > (b) ? (a) : (b))
2023-08-09 07:49:11 -04:00
/* Selectable windows */
2023-08-13 05:21:52 -04:00
WINDOW *winput;
WINDOW *wmode;
WINDOW *wresult;
WINDOW *whelp;
2023-08-12 10:01:26 -04:00
/* Non-Selectable windows */
2023-08-13 05:21:52 -04:00
WINDOW *wtooltip;
2023-08-15 04:56:04 -04:00
WINDOW *wcase;
2023-08-09 07:49:11 -04:00
/* Selected window pointer */
2023-08-13 05:21:52 -04:00
WINDOW **current_window;
static WINDOW **last_window;
2023-07-29 09:40:48 -04:00
static int result_window_height;
static int second_col_width;
static int first_col_width;
static int input_window_height;
static int mode_window_height;
2023-08-12 10:01:26 -04:00
static int tooltip_width;
2023-07-29 09:40:48 -04:00
#define WRESULT_TABLE_BODY_START 4
2023-07-27 14:04:50 -04:00
2023-08-06 07:09:48 -04:00
int window_change;
2023-07-27 14:04:50 -04:00
2023-08-12 10:01:26 -04:00
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);
2023-08-15 04:56:04 -04:00
static inline void display_case(void);
2023-08-12 10:01:26 -04:00
static inline void display_command_field(void);
static inline void display_results(void);
static inline void display_tooltip(void);
2023-08-13 14:44:46 -04:00
static const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
2023-08-13 05:21:52 -04:00
int dispchar2int(const char c) {
2023-08-13 14:44:46 -04:00
int i = 0;
while(dispchars[i] != c){
if(dispchars[i] == '\00'){ return -1; }
++i;
}
return i;
2023-08-08 06:47:02 -04:00
}
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
char lastmsg[MSGLEN + 1]; /* last message displayed */
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
struct { /* text of input fields */
char *text1;
char *text2;
2023-08-09 07:49:11 -04:00
} /* Paralel array to "field_searchers", indexed by "field" */
2023-08-13 05:21:52 -04:00
fields[FIELDS + 1] = {
/* samuel has a search that is not part of the cscope display */
{"Find this", "C symbol" },
{"Find this", "global definition" },
{"Find", "functions called by this function"},
{"Find", "functions calling this function" },
{"Find this", "text string" },
{"Change this", "text string" },
{"Find this", "egrep pattern" },
{"Find this", "file" },
{"Find", "files #including this file" },
{"Find", "assignments to this symbol" },
{"Find all", "function definitions" }, /* samuel only */
2023-07-27 14:04:50 -04:00
};
/* initialize display parameters */
2023-08-13 05:21:52 -04:00
void dispinit(void) {
/* initialize the curses display package */
initscr(); /* initialize the screen */
2023-08-11 13:20:52 -04:00
start_color();
use_default_colors();
easy_init_pair(FRAME);
easy_init_pair(PROMPT);
easy_init_pair(FIELD);
easy_init_pair(FIELD_SELECTED);
easy_init_pair(HELP);
easy_init_pair(TOOLTIP);
2023-08-15 04:56:04 -04:00
easy_init_pair(CASE);
2023-08-11 13:20:52 -04:00
easy_init_pair(MESSAGE);
easy_init_pair(PATTERN);
easy_init_pair(TABLE_HEADER);
easy_init_pair(TABLE_ID);
2023-08-12 10:01:26 -04:00
easy_init_pair(TABLE_MARK);
2023-08-11 13:20:52 -04:00
easy_init_pair(TABLE_COL_LINE);
easy_init_pair(TABLE_COL_FILE);
easy_init_pair(TABLE_COL_FUNCTION);
easy_init_pair(TABLE_COL_TEXT);
2023-08-12 10:01:26 -04:00
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);
2023-08-11 13:20:52 -04:00
easy_init_pair(PAGER_MSG);
2023-08-13 05:21:52 -04:00
entercurses();
/* Calculate section sizes */
result_window_height = LINES - 2;
input_window_height = 1;
mode_window_height = LINES - input_window_height - 2 - 1;
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));
2023-08-15 04:56:04 -04:00
static int case_width = sizeof("Case: XXX")-1;
2023-08-13 05:21:52 -04:00
if(mdisprefs <= 0) {
postfatal(PROGRAM_NAME ": screen too small\n");
/* NOTREACHED */
}
if(mdisprefs > sizeof(dispchars)) { mdisprefs = sizeof(dispchars); }
/* allocate the displayed line array */
displine = malloc(mdisprefs * sizeof(*displine));
/* readline */
rlinit();
/* initialize windows */
2023-08-15 04:56:04 -04:00
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);
2023-08-13 05:21:52 -04:00
wtooltip = newwin(1, tooltip_width, LINES - 1, COLS - (tooltip_width + 4));
2023-08-15 04:56:04 -04:00
wcase = newwin(1, case_width, 0, COLS - case_width - 4);
2023-08-13 05:21:52 -04:00
refresh();
current_window = &winput;
2023-07-27 14:04:50 -04:00
}
2023-08-06 07:09:48 -04:00
/* enter curses mode */
2023-08-13 05:21:52 -04:00
void entercurses(void) {
incurses = true;
2023-08-06 07:09:48 -04:00
window_change = CH_ALL;
2023-08-13 05:21:52 -04:00
nonl(); /* don't translate an output \n to \n\r */
cbreak(); /* single character input */
noecho(); /* don't echo input characters */
curs_set(0);
clear(); /* clear the screen */
mouseinit(); /* initialize any mouse interface */
// drawscrollbar(topline, nextline);
keypad(stdscr, TRUE); /* enable the keypad */
// fixkeypad(); /* fix for getch() intermittently returning garbage */
standend(); /* turn off reverse video */
2023-08-06 07:09:48 -04:00
}
/* exit curses mode */
2023-08-13 05:21:52 -04:00
void exitcurses(void) {
/* clear the bottom line */
move(LINES - 1, 0);
clrtoeol();
refresh();
/* exit curses and restore the terminal modes */
endwin();
incurses = false;
/* restore the mouse */
mousecleanup();
fflush(stdout);
2023-08-06 07:09:48 -04:00
}
2023-08-13 05:21:52 -04:00
static inline void display_help() {
// XXX: this could be optimized by only overriding the buffer if theres an actual
// change
2023-08-05 05:30:18 -04:00
werase(whelp);
wmove(whelp, 0, 0);
2023-08-11 13:20:52 -04:00
wattron(whelp, COLOR_PAIR(COLOR_PAIR_HELP));
2023-08-05 05:30:18 -04:00
waddstr(whelp, help());
2023-08-11 13:20:52 -04:00
wattroff(whelp, COLOR_PAIR(COLOR_PAIR_HELP));
refresh();
2023-08-05 05:30:18 -04:00
wrefresh(whelp);
2023-08-11 13:20:52 -04:00
2023-08-05 05:30:18 -04:00
do_press_any_key = true;
}
2023-08-15 04:56:04 -04:00
static inline void display_case(){
wmove(wcase, 0, 0);
wattron(wcase, COLOR_PAIR(COLOR_PAIR_CASE));
waddstr(wcase, (caseless ? "Case: OFF" : "Case: ON"));
wattroff(wcase, COLOR_PAIR(COLOR_PAIR_CASE));
}
2023-08-13 05:21:52 -04:00
static inline void display_frame(const bool border_only) {
2023-08-11 13:20:52 -04:00
wattron(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));
2023-08-13 05:21:52 -04:00
box(stdscr, 0, 0);
/* Title*/
const int LEFT_PADDING = 5;
wmove(stdscr, 0, LEFT_PADDING);
2023-07-27 14:04:50 -04:00
#if CCS
2023-08-13 05:21:52 -04:00
wprintw(stdscr, PROGRAM_NAME " %s", ESG_REL);
2023-07-27 14:04:50 -04:00
#else
2023-08-13 05:21:52 -04:00
wprintw(stdscr, PROGRAM_NAME " version %d%s", FILEVERSION, FIXVERSION);
2023-07-27 14:04:50 -04:00
#endif
2023-08-11 13:20:52 -04:00
/* --- */
2023-08-13 05:21:52 -04:00
if(!border_only) {
2023-08-11 13:20:52 -04:00
/* Vertical line */
mvaddch(0, first_col_width + 1, ACS_TTEE);
2023-08-13 05:21:52 -04:00
for(int i = 0; i < LINES - 2; i++) {
mvaddch(i + 1, first_col_width + 1, ACS_VLINE);
2023-08-11 13:20:52 -04:00
}
2023-08-13 05:21:52 -04:00
mvaddch(LINES - 1, first_col_width + 1, ACS_BTEE);
2023-08-11 13:20:52 -04:00
/* Horizontal line */
wmove(stdscr, input_window_height + 1, 0);
addch(ACS_LTEE);
2023-08-13 05:21:52 -04:00
for(int i = 0; i < first_col_width; i++) {
2023-08-11 13:20:52 -04:00
addch(ACS_HLINE);
}
addch(ACS_RTEE);
}
wattroff(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));
2023-07-27 14:04:50 -04:00
}
2023-08-13 05:21:52 -04:00
static inline void display_mode() {
2023-08-09 07:49:11 -04:00
werase(wmode);
2023-08-13 05:21:52 -04:00
for(int i = 0; i < FIELDS; ++i) {
if(i == field) {
wattron(wmode,
COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
2023-08-04 14:21:45 -04:00
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
2023-08-13 05:21:52 -04:00
wattroff(wmode,
COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
} else {
2023-08-11 13:20:52 -04:00
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
2023-08-04 14:21:45 -04:00
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
2023-08-11 13:20:52 -04:00
wattroff(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
2023-08-04 14:21:45 -04:00
}
2023-08-13 05:21:52 -04:00
}
2023-07-27 14:04:50 -04:00
}
2023-08-13 05:21:52 -04:00
static inline void display_command_field() {
werase(winput);
2023-08-11 13:20:52 -04:00
wattron(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
2023-08-13 05:21:52 -04:00
mvwaddstr(winput, 0, 0, prompts[input_mode]);
2023-08-11 13:20:52 -04:00
wattroff(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
2023-08-13 05:21:52 -04:00
waddstr(winput, rl_line_buffer);
2023-08-12 10:01:26 -04:00
display_cursor();
2023-07-27 14:04:50 -04:00
}
2023-08-13 05:21:52 -04:00
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 */
char file[PATHLEN + 1]; /* file name */
char function[PATLEN + 1]; /* function name */
char linenum[NUMLEN + 1]; /* line number */
2023-07-27 14:04:50 -04:00
2023-08-09 07:49:11 -04:00
werase(wresult);
/* --- Display the message --- */
2023-08-13 05:21:52 -04:00
if(totallines == 0) { // Its a real message
wmove(wresult, MSGLINE, 0);
wclrtoeol(wresult);
2023-08-11 13:20:52 -04:00
wattron(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
2023-08-13 05:21:52 -04:00
waddstr(wresult, lastmsg);
2023-08-11 13:20:52 -04:00
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
2023-08-13 05:21:52 -04:00
return;
}
if(input_mode == INPUT_CHANGE) { // Its a pattern
2023-08-09 07:49:11 -04:00
snprintf(lastmsg, MSGLEN, "Change \"%s\" to \"%s\"", input_line, newpat);
2023-08-13 05:21:52 -04:00
} else {
snprintf(lastmsg,
MSGLEN,
"%c%s: %s",
toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1,
input_line);
}
2023-08-11 13:20:52 -04:00
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PATTERN));
2023-08-13 05:21:52 -04:00
waddstr(wresult, lastmsg);
2023-08-11 13:20:52 -04:00
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PATTERN));
2023-08-09 07:49:11 -04:00
2023-08-13 05:21:52 -04:00
/* --- Display the column headings --- */
2023-08-11 13:20:52 -04:00
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));
2023-08-13 05:21:52 -04:00
wmove(wresult, 2, 2);
if(ogs == true && field != FILENAME) {
wprintw(wresult, "%-*s ", subsystemlen, "Subsystem");
wprintw(wresult, "%-*s ", booklen, "Book");
}
if(dispcomponents > 0) wprintw(wresult, "%-*s ", filelen, "File");
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
wprintw(wresult, "%-*s ", fcnlen, "Function");
}
if(field != FILENAME) { waddstr(wresult, "Line"); }
2023-08-11 13:20:52 -04:00
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));
2023-08-04 13:49:03 -04:00
2023-08-05 10:30:21 -04:00
/* --- Display table entries --- */
2023-08-13 05:21:52 -04:00
wmove(wresult, WRESULT_TABLE_BODY_START, 0);
/* calculate the source text column */
/* NOTE: the +1s are column gaps */
srctxtw = second_col_width;
srctxtw -= 1 + 1; // dispchars
if(ogs == true) { srctxtw -= subsystemlen + 1 + booklen + 1; }
if(dispcomponents > 0) { srctxtw -= filelen + 1; }
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
srctxtw -= fcnlen + 1;
}
srctxtw -= numlen + 1;
2023-08-04 13:49:03 -04:00
2023-08-05 10:30:21 -04:00
/* decide where to list from */
2023-08-10 15:06:17 -04:00
{
int seekerr;
2023-08-13 05:21:52 -04:00
do {
2023-08-10 15:06:17 -04:00
seekerr = seekpage(current_page);
2023-08-13 05:21:52 -04:00
} while(seekerr == -1 && current_page--);
2023-08-10 15:06:17 -04:00
}
2023-08-05 10:30:21 -04:00
2023-08-13 05:21:52 -04:00
/* until the max references have been displayed or
there is no more room */
for(disprefs = 0, screenline = WRESULT_TABLE_BODY_START;
disprefs < mdisprefs && screenline < (result_window_height - 1);
++disprefs, ++screenline) {
2023-08-12 10:01:26 -04:00
attr_swp = (disprefs != curdispline) ? A_NORMAL : ATTRIBUTE_RESULT_SELECTED;
wattron(wresult, attr_swp);
2023-08-13 05:21:52 -04:00
/* read the reference line */
if(fscanf(refsfound,
"%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR
"[^\n]",
file,
function,
linenum,
tempstring) < 4) {
break;
}
++nextline;
displine[disprefs] = screenline;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_ID :
COLOR_PAIR_TABLE_SELECTED_ID;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
wprintw(wresult, "%c", dispchars[disprefs]);
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
/* display any change mark */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_MARK :
COLOR_PAIR_TABLE_SELECTED_MARK;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
if(input_mode == INPUT_CHANGE && change[topref + disprefs]) {
waddch(wresult, '>');
} else {
waddch(wresult, ' ');
}
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
/* display the file name */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FILE :
COLOR_PAIR_TABLE_COL_SELECTED_FILE;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
if(field == FILENAME) {
2023-08-10 15:06:17 -04:00
wprintw(wresult, "%-*s ", filelen, file);
2023-08-13 05:21:52 -04:00
} else {
2023-08-10 15:06:17 -04:00
/* if OGS, display the subsystem and book names */
2023-08-13 05:21:52 -04:00
if(ogs == true) {
2023-08-10 15:06:17 -04:00
ogsnames(file, &subsystem, &book);
wprintw(wresult, "%-*.*s ", subsystemlen, subsystemlen, subsystem);
wprintw(wresult, "%-*.*s ", booklen, booklen, book);
}
/* display the requested path components */
2023-08-13 05:21:52 -04:00
if(dispcomponents > 0) {
wprintw(wresult,
"%-*.*s ",
filelen,
filelen,
pathcomponents(file, dispcomponents));
2023-08-10 15:06:17 -04:00
}
2023-08-13 05:21:52 -04:00
} /* else(field == FILENAME) */
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
/* display the function name */
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
color_swp = (disprefs != curdispline) ?
COLOR_PAIR_TABLE_COL_FUNCTION :
COLOR_PAIR_TABLE_COL_SELECTED_FUNCTION;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
}
if(field == FILENAME) {
waddch(wresult, '\n'); /* go to next line */
2023-08-11 13:20:52 -04:00
continue;
2023-08-13 05:21:52 -04:00
}
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
/* display the line number */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_LINE :
COLOR_PAIR_TABLE_COL_SELECTED_LINE;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
wprintw(wresult, "%*s ", numlen, linenum);
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
/* there may be tabs in egrep output */
while((s = strchr(tempstring, '\t')) != NULL) {
2023-08-11 13:20:52 -04:00
*s = ' ';
2023-08-13 05:21:52 -04:00
}
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
/* display the source line */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_TEXT :
COLOR_PAIR_TABLE_COL_SELECTED_TEXT;
2023-08-12 10:01:26 -04:00
wattron(wresult, COLOR_PAIR(color_swp));
2023-08-13 05:21:52 -04:00
s = tempstring;
for(;;) {
2023-08-12 10:01:26 -04:00
/* if the source line does not fit */
2023-08-13 05:21:52 -04:00
if((i = strlen(s)) > srctxtw) {
2023-08-04 13:54:19 -04:00
2023-08-12 10:01:26 -04:00
/* find the nearest blank */
2023-08-13 05:21:52 -04:00
for(i = srctxtw; s[i] != ' ' && i > 0; --i) {
2023-08-12 10:01:26 -04:00
;
}
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
if(i == 0) { i = srctxtw; /* no blank */ }
2023-08-12 10:01:26 -04:00
}
/* print up to this point */
wprintw(wresult, "%.*s", i, s);
s += i;
2023-08-04 13:54:19 -04:00
2023-08-12 10:01:26 -04:00
/* if line didn't wrap around */
2023-08-13 05:21:52 -04:00
if(i < srctxtw) { waddch(wresult, '\n'); /* go to next line */ }
2023-08-12 10:01:26 -04:00
/* skip blanks */
2023-08-13 05:21:52 -04:00
while(*s == ' ') {
2023-08-12 10:01:26 -04:00
++s;
}
/* see if there is more text */
2023-08-13 05:21:52 -04:00
if(*s == '\0') { break; }
2023-08-12 10:01:26 -04:00
/* if the source line is too long */
2023-08-13 05:21:52 -04:00
if(++screenline > result_window_height) {
2023-08-12 10:01:26 -04:00
/* if this is the first displayed line,
display what will fit on the screen */
2023-08-13 05:21:52 -04:00
if(topref == nextline - 1) {
2023-08-12 10:01:26 -04:00
disprefs++;
/* break out of two loops */
goto endrefs;
}
/* erase the reference */
2023-08-13 05:21:52 -04:00
while(--screenline >= displine[disprefs]) {
2023-08-12 10:01:26 -04:00
wmove(wresult, screenline, 0);
wclrtoeol(wresult);
}
++screenline;
/* go back to the beginning of this reference */
--nextline;
fseek(refsfound, 0, SEEK_SET);
2023-08-10 09:52:28 -04:00
goto endrefs;
2023-08-12 10:01:26 -04:00
}
/* indent the continued source line */
wmove(wresult, screenline, second_col_width - srctxtw);
2023-08-13 05:21:52 -04:00
} /* for(ever) */
2023-08-12 10:01:26 -04:00
wattroff(wresult, COLOR_PAIR(color_swp));
wattroff(wresult, attr_swp);
2023-08-13 05:21:52 -04:00
} /* for(reference output lines) */
2023-08-01 13:36:53 -04:00
endrefs:
2023-08-12 10:01:26 -04:00
wattroff(wresult, attr_swp);
/* --- display pager message --- */
/* position cursor */
2023-08-13 05:21:52 -04:00
i = result_window_height - 1;
if(screenline < i) {
waddch(wresult, '\n');
} else {
wmove(wresult, i, 0);
}
2023-08-12 10:01:26 -04:00
/**/
2023-08-11 13:20:52 -04:00
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
2023-08-13 05:21:52 -04:00
/* check for more references */
i = totallines - nextline + 1;
bottomline = nextline;
if(i > 0) {
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, "* End of results. *");
}
2023-08-11 13:20:52 -04:00
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
2023-07-29 09:40:48 -04:00
}
2023-08-13 05:21:52 -04:00
static inline void display_cursor(void) {
chtype i;
int yoffset = 0, xoffset = 0;
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
xoffset = strlen(prompts[input_mode]) + rl_point;
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
wmove(*current_window, yoffset, xoffset);
2023-08-04 13:49:03 -04:00
2023-08-13 05:21:52 -04:00
i = winch(*current_window);
i |= A_REVERSE;
waddch(*current_window, i);
2023-07-29 09:40:48 -04:00
}
2023-08-13 05:21:52 -04:00
void horswp_field(void) {
2023-08-13 15:21:38 -04:00
if(input_mode != INPUT_NORMAL){ return; }
2023-08-13 05:21:52 -04:00
if(current_window != &wresult) {
if(totallines == 0) { return; }
if(current_window == &winput) {
window_change |= CH_INPUT;
} else {
window_change |= CH_MODE;
}
last_window = current_window;
current_window = &wresult;
} else {
current_window = last_window;
if(current_window == &winput) { window_change |= CH_INPUT; }
}
2023-08-13 15:21:38 -04:00
2023-08-13 05:21:52 -04:00
window_change |= CH_RESULT;
2023-07-29 09:40:48 -04:00
}
2023-08-13 05:21:52 -04:00
void verswp_field(void) {
if(current_window == &wresult) { return; }
current_window = (current_window == &winput) ? &wmode : &winput;
window_change |= CH_INPUT | CH_MODE;
2023-07-27 14:04:50 -04:00
}
/* display search progress with default custom format */
2023-08-13 05:21:52 -04:00
void progress(char *what, long current, long max) {
static long start;
long now;
int i;
/* save the start time */
if(searchcount == 0) { start = time(NULL); }
if((now = time(NULL)) - start >= 1) {
if(linemode == false) {
wmove(wresult, MSGLINE, MSGCOL);
wclrtoeol(wresult);
waddstr(wresult, what);
snprintf(lastmsg, sizeof(lastmsg), "%ld", current);
wmove(wresult, MSGLINE, (COLS / 2) - (strlen(lastmsg) / 2));
waddstr(wresult, lastmsg);
snprintf(lastmsg, sizeof(lastmsg), "%ld", max);
wmove(wresult, MSGLINE, COLS - strlen(lastmsg));
waddstr(wresult, lastmsg);
refresh();
} else if(verbosemode == true) {
snprintf(lastmsg, sizeof(lastmsg), "> %s %ld of %ld", what, current, max);
}
start = now;
if((linemode == false) && (incurses == true)) {
wmove(wresult, MSGLINE, MSGCOL);
i = (float)COLS * (float)current / (float)max;
standout();
for(; i > 0; i--)
waddch(wresult, inch());
standend();
refresh();
} else if(linemode == false || verbosemode == true) {
postmsg(lastmsg);
}
}
++searchcount;
2023-07-27 14:04:50 -04:00
}
/* print error message on system call failure */
2023-08-13 05:21:52 -04:00
void myperror(char *text) {
char *s;
2023-07-27 14:04:50 -04:00
2023-08-13 05:21:52 -04:00
s = strerror(errno);
2023-07-27 14:04:50 -04:00
2023-08-13 05:21:52 -04:00
(void)snprintf(lastmsg, sizeof(lastmsg), "%s: %s", text, s);
postmsg(lastmsg);
2023-07-27 14:04:50 -04:00
}
/* postmsg clears the message line and prints the message */
2023-08-13 05:21:52 -04:00
void postmsg(char *msg) {
if(linemode == true || incurses == false) {
printf("%s\n", msg);
fflush(stdout);
} else {
2023-08-09 07:49:11 -04:00
window_change |= CH_RESULT;
2023-08-13 05:21:52 -04:00
}
UNUSED(strncpy(lastmsg, msg, sizeof(lastmsg) - 1));
2023-07-27 14:04:50 -04:00
}
/* clearmsg2 clears the second message line */
2023-08-13 05:21:52 -04:00
void clearmsg2(void) {
if(linemode == false) {
wmove(wresult, MSGLINE + 1, 0);
wclrtoeol(wresult);
}
2023-07-27 14:04:50 -04:00
}
/* postmsg2 clears the second message line and prints the message */
2023-08-13 05:21:52 -04:00
void postmsg2(char *msg) {
if(linemode == true) {
(void)printf("%s\n", msg);
} else {
clearmsg2();
waddstr(wresult, msg);
wrefresh(wresult);
}
2023-07-27 14:04:50 -04:00
}
/* display an error mesg - stdout or on second msg line */
2023-08-13 05:21:52 -04:00
void posterr(char *msg, ...) {
va_list ap;
char errbuf[MSGLEN];
va_start(ap, msg);
if(linemode == true || incurses == false) {
(void)vfprintf(stderr, msg, ap);
(void)fputc('\n', stderr);
} else {
vsnprintf(errbuf, sizeof(errbuf), msg, ap);
postmsg2(errbuf);
}
va_end(ap);
2023-07-27 14:04:50 -04:00
}
/* display a fatal error mesg -- stderr *after* shutting down curses */
2023-08-13 05:21:52 -04:00
void postfatal(const char *msg, ...) {
va_list ap;
char errbuf[MSGLEN];
va_start(ap, msg);
vsnprintf(errbuf, sizeof(errbuf), msg, ap);
/* restore the terminal to its original mode */
if(incurses == true) { exitcurses(); }
/* display fatal error messages */
fprintf(stderr, "%s", errbuf);
/* shut down */
myexit(1);
2023-07-27 14:04:50 -04:00
}
/* get the OGS subsystem and book names */
2023-08-13 05:21:52 -04:00
void ogsnames(char *file, char **subsystem, char **book) {
static char buf[PATHLEN + 1];
char *s, *slash;
*subsystem = *book = "";
(void)strcpy(buf, file);
s = buf;
if(*s == '/') { ++s; }
while((slash = strchr(s, '/')) != NULL) {
*slash = '\0';
if((int)strlen(s) >= 3 && strncmp(slash - 3, ".ss", 3) == 0) {
*subsystem = s;
s = slash + 1;
if((slash = strchr(s, '/')) != NULL) {
*book = s;
*slash = '\0';
}
break;
}
s = slash + 1;
}
2023-07-27 14:04:50 -04:00
}
2023-08-10 15:06:17 -04:00
2023-08-13 05:21:52 -04:00
static inline void display_tooltip(void) {
2023-08-12 10:01:26 -04:00
wmove(wtooltip, 0, 0);
2023-08-13 05:21:52 -04:00
const char *tooltip;
if(*current_window == winput) {
2023-08-12 10:01:26 -04:00
tooltip = tooltip_winput;
2023-08-13 05:21:52 -04:00
} else if(*current_window == wmode) {
2023-08-12 10:01:26 -04:00
tooltip = tooltip_wmode;
2023-08-13 05:21:52 -04:00
} else if(*current_window == wresult) {
2023-08-12 10:01:26 -04:00
tooltip = tooltip_wresult;
}
wattron(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
waddstr(wtooltip, tooltip);
// XXX: cheap hack
2023-08-13 05:21:52 -04:00
for(int i = 0; i < (tooltip_width - strlen(tooltip)); i++) {
2023-08-12 10:01:26 -04:00
waddch(wtooltip, ' ');
}
wattroff(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
}
2023-08-13 05:21:52 -04:00
void display(void) {
// drawscrollbar(topline, nextline); /* display the scrollbar */
static void *lstwin = NULL; /* for the tooltip (see below) */
2023-08-10 15:06:17 -04:00
2023-08-13 05:21:52 -04:00
if(window_change) {
if(window_change == CH_HELP) {
2023-08-11 13:20:52 -04:00
display_frame(true);
2023-08-10 15:06:17 -04:00
display_help();
2023-08-11 13:20:52 -04:00
/* Do not display over the help msg and
* rely on setting CH_ALL for the next display
*/
window_change = CH_ALL;
2023-08-10 15:06:17 -04:00
return;
}
2023-08-13 05:21:52 -04:00
if(window_change == CH_ALL) { display_frame(false); }
2023-08-12 10:01:26 -04:00
/* As it stands the tooltip has to be redisplayed
* on every window change.
*/
2023-08-13 05:21:52 -04:00
if(lstwin != *current_window) {
2023-08-12 10:01:26 -04:00
lstwin = *current_window;
display_tooltip();
}
2023-08-15 04:56:04 -04:00
if(window_change & CH_CASE) { display_case(); }
2023-08-13 05:21:52 -04:00
if(window_change & CH_INPUT) { display_command_field(); }
if(window_change & CH_RESULT) { display_results(); }
if(window_change & CH_MODE) { display_mode(); }
refresh();
wrefresh(winput);
wrefresh(wmode);
wrefresh(wresult);
wrefresh(wtooltip);
2023-08-15 04:56:04 -04:00
wrefresh(wcase);
2023-08-13 05:21:52 -04:00
}
window_change = CH_NONE;
2023-08-10 15:06:17 -04:00
}