This commit is contained in:
anon 2023-07-29 15:40:48 +02:00
parent a56c9e6818
commit 787aa3279e
10 changed files with 545 additions and 430 deletions

17
.gdb_history Normal file
View File

@ -0,0 +1,17 @@
b dispinit
r
n
p first_col_width
b display_frame
c
p first_col_width
l
d 1
d 2
wa first_col_width
r
r
r
help handle
handle SIGINT stop
r

View File

@ -1,5 +1,5 @@
CC=gcc CC=gcc
CCFLAGS:=-ggdb #-D PRODUCTION CFLAGS:=-ggdb
LDLIBS=-I ${CHDRD} $$(pkg-config --libs ncurses) LDLIBS=-I ${CHDRD} $$(pkg-config --libs ncurses)
LEX:=flex LEX:=flex

View File

@ -3,10 +3,26 @@ Fork of Cscope, with various improvements, because cscope is good and shall not
# Improvements/Changes # Improvements/Changes
## User side ## User side
+ renamed the program, because "cscope" is annoying to type
+ improved gui /*pending*/ + improved gui /*pending*/
+ GNU Readline integration (ie. VI/EMACS mode, command history) /*pending*/ + GNU Readline integration (ie. VI/EMACS mode, command history) /*pending*/
## To the code ## To the code
+ nuked autoconf, replaced with single Makefile + nuked autoconf, replaced with single Makefile
+ removed + removed "scanner.l" which seems to be an anchient version (and redundant copy) of "fscanner.l" forgotten by all
+ encapsulated changes to the TUI into display.c + encapsulated changes to the TUI into display.c
+ removed macros hell put in place to allow compiling on a dead badger + removed macro hell put in place to allow compiling on a dead badger
+ replaced repeated inline #ifdef KEY_\*-s with guaranteed definitions
+ removed random commets giving tips for and refering to specific issues
# Interface
<-- Tab -->
+------------Message-------------+ +--------------------------------+
A |+--------------+---------------+| |+------------------------------+|
| || Input Window | Result window || || ||
|+--------------+ || ? || ||
? || Mode Window | || ---> || Help ||
? || | || <--- || ||
|| | || ESC || ||
| || | || || ||
V |+--------------+---------------+| |+------------------------------+|
+-----------Tool Tips------------+ +--------------------------------+

4
TODO
View File

@ -5,3 +5,7 @@
+ Normalize tabs and spaces + Normalize tabs and spaces
+ Ordering function declarations in global.h by alpha order is not smart + Ordering function declarations in global.h by alpha order is not smart
+ Handle unused parameters gracefully (#define UNUSED(x) (void)(x)) + Handle unused parameters gracefully (#define UNUSED(x) (void)(x))
+ Figure out what the deal is with changestring()
+ scollbar() uses int literals?
+ recursive macro function to assign KEY_* default values; look for a new and shiny preprocessor?

View File

@ -47,22 +47,28 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
int selecting; /* whether the (upper) symbol list is being browsed */ /* These are strictly used to test how keys are suppose to behave.
unsigned int curdispline = 0; * Think of it as modes: in _input mode_ the up arrow interacts
* 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".
*/
extern const void const* winput;
extern const void const* wmode;
extern const void const* wresult;
extern const void const* const* current_window;
BOOL caseless; /* ignore letter case when searching */ BOOL caseless; /* ignore letter case when searching */
BOOL *change; /* change this line */ BOOL *change; /* change this line */
BOOL changing; /* changing text */ BOOL changing; /* changing text */
char newpat[PATLEN + 1]; /* new pattern */ char newpat[PATLEN + 1]; /* new pattern */
/* HBB 20040430: renamed to avoid lots of clashes with function arguments
* also named 'pattern' */
char Pattern[PATLEN + 1]; /* symbol or text pattern */ char Pattern[PATLEN + 1]; /* symbol or text pattern */
/* HBB FIXME 20060419: these should almost certainly be const */ static const char appendprompt[] = "Append to file: ";
static char appendprompt[] = "Append to file: "; static const char pipeprompt[] = "Pipe to shell command: ";
static char pipeprompt[] = "Pipe to shell command: "; static const char readprompt[] = "Read from file: ";
static char readprompt[] = "Read from file: "; static const char toprompt[] = "To: ";
static char toprompt[] = "To: ";
/* Internal prototypes: */ /* Internal prototypes: */
@ -113,12 +119,9 @@ command(int commandc)
totallines = 0; totallines = 0;
disprefs = 0; disprefs = 0;
topline = nextline = 1; topline = nextline = 1;
selecting = 0;
break; break;
#if UNIXPC
case ESC: /* possible unixpc mouse selection */ case ESC: /* possible unixpc mouse selection */
#endif
case ctrl('X'): /* mouse selection */ case ctrl('X'): /* mouse selection */
if ((p = getmouseaction(DUMMYCHAR)) == NULL) { if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
return(NO); /* unknown control sequence */ return(NO); /* unknown control sequence */
@ -150,7 +153,6 @@ command(int commandc)
if (field >= FIELDS) { if (field >= FIELDS) {
field = FIELDS - 1; field = FIELDS - 1;
} }
setfield();
resetcmd(); resetcmd();
return(NO); return(NO);
} }
@ -158,107 +160,76 @@ command(int commandc)
case '\t': /* go to next input field */ case '\t': /* go to next input field */
if (disprefs) { if (disprefs) {
selecting = !selecting; horswp_field();
if (selecting) {
move(displine[curdispline], 0);
refresh();
} else {
atfield();
resetcmd();
}
} }
return(NO); return(NO);
#ifdef KEY_ENTER case '%':
verswp_field();
return(NO);
case KEY_ENTER: case KEY_ENTER:
#endif
case '\r': case '\r':
case '\n': /* go to reference */ case '\n': /* go to reference */
if (selecting) { if (current_window == &wresult) {
editref(curdispline); editref(curdispline);
return(YES); return(YES);
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case ctrl('N'): case ctrl('N'):
#ifdef KEY_DOWN
case KEY_DOWN: case KEY_DOWN:
#endif
#ifdef KEY_RIGHT
case KEY_RIGHT: case KEY_RIGHT:
#endif if (current_window == &wresult) {
if (selecting) {
if ((curdispline + 1) < disprefs) { if ((curdispline + 1) < disprefs) {
move(displine[++curdispline], 0); ++curdispline;
refresh();
} }
} else { } else {
field = (field + 1) % FIELDS; field = (field + 1) % FIELDS;
setfield();
atfield();
resetcmd(); resetcmd();
} }
return(NO); return(NO);
case ctrl('P'): /* go to previous input field */ case ctrl('P'): /* go to previous input field */
#ifdef KEY_UP
case KEY_UP: case KEY_UP:
#endif
#ifdef KEY_LEFT
case KEY_LEFT: case KEY_LEFT:
#endif if (current_window == &wresult) {
if (selecting) {
if (curdispline) { if (curdispline) {
move(displine[--curdispline], 0); --curdispline;
refresh();
} }
} else { } else {
field = (field + (FIELDS - 1)) % FIELDS; field = (field + (FIELDS - 1)) % FIELDS;
setfield();
atfield();
resetcmd(); resetcmd();
} }
return(NO); return(NO);
#ifdef KEY_HOME
case KEY_HOME: /* go to first input field */ case KEY_HOME: /* go to first input field */
if (selecting) { if (current_window == &wresult) {
curdispline = 0; curdispline = 0;
move(REFLINE, 0);
refresh();
} else { } else {
field = 0; field = 0;
setfield();
atfield();
resetcmd(); resetcmd();
} }
return(NO); return(NO);
#endif
#ifdef KEY_LL
case KEY_LL: /* go to last input field */ case KEY_LL: /* go to last input field */
if (selecting) { if (current_window == &wresult) {
move(displine[disprefs - 1], 0); curdispline = disprefs;
refresh(); refresh();
} else { } else {
field = FIELDS - 1; field = FIELDS - 1;
setfield();
atfield();
resetcmd(); resetcmd();
} }
return(NO); return(NO);
#endif /* def(KEY_LL) */
case ' ': /* display next page */ case ' ': /* display next page */
case '+': case '+':
case ctrl('V'): case ctrl('V'):
#ifdef KEY_NPAGE
case KEY_NPAGE: case KEY_NPAGE:
#endif
/* don't redisplay if there are no lines */ /* don't redisplay if there are no lines */
if (totallines == 0) { if (totallines == 0) {
return(NO); return(NO);
} }
/* note: seekline() is not used to move to the next /* NOTE: seekline() is not used to move to the next
* page because display() leaves the file pointer at * page because display() leaves the file pointer at
* the next page to optimize paging forward * the next page to optimize paging forward
*/ */
@ -267,9 +238,7 @@ command(int commandc)
case ctrl('H'): case ctrl('H'):
case '-': /* display previous page */ case '-': /* display previous page */
#ifdef KEY_PPAGE
case KEY_PPAGE: case KEY_PPAGE:
#endif
/* don't redisplay if there are no lines */ /* don't redisplay if there are no lines */
if (totallines == 0) { if (totallines == 0) {
return(NO); return(NO);
@ -392,13 +361,12 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
break; break;
#endif #endif
case ctrl('L'): /* redraw screen */ case ctrl('L'): /* redraw screen */
#ifdef KEY_CLEAR
case KEY_CLEAR: case KEY_CLEAR:
#endif /* XXX: no */
clearmsg2(); //clearmsg2();
clearok(curscr, TRUE); //clearok(curscr, TRUE);
wrefresh(curscr); //wrefresh(curscr);
drawscrollbar(topline, bottomline); //drawscrollbar(topline, bottomline);
return(NO); return(NO);
case '!': /* shell escape */ case '!': /* shell escape */
@ -417,7 +385,7 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
editall(); editall();
break; break;
case ctrl('A'): /* HBB 20050428: added alt. keymapping */ case ctrl('A'):
case ctrl('Y'): /* repeat last pattern */ case ctrl('Y'): /* repeat last pattern */
if (*Pattern != '\0') { if (*Pattern != '\0') {
addstr(Pattern); addstr(Pattern);
@ -427,8 +395,8 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
case ctrl('B'): /* cmd history back */ case ctrl('B'): /* cmd history back */
case ctrl('F'): /* cmd history fwd */ case ctrl('F'): /* cmd history fwd */
if (selecting) { if (current_window == &wresult) {
selecting = 0; horswp_field();
} }
curritem = currentcmd(); curritem = currentcmd();
@ -439,8 +407,6 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
} }
if (item) { if (item) {
field = item->field; field = item->field;
setfield();
atfield();
addstr(item->text); addstr(item->text);
strcpy(Pattern, item->text); strcpy(Pattern, item->text);
switch (c = mygetch()) { switch (c = mygetch()) {
@ -450,7 +416,6 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
case ctrl('F'): case ctrl('F'):
case ctrl('B'): case ctrl('B'):
myungetch(c); myungetch(c);
atfield();
clrtoeol(); /* clear current field */ clrtoeol(); /* clear current field */
break; break;
default: default:
@ -477,10 +442,9 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
case '.': case '.':
postmsg("The . command has been replaced by ^Y"); postmsg("The . command has been replaced by ^Y");
atfield(); /* move back to the input field */
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
if (selecting && !mouse) { if (current_window == &wresult && !mouse) {
char *c; char *c;
if ((c = strchr(dispchars, commandc))) if ((c = strchr(dispchars, commandc)))
@ -506,7 +470,9 @@ cscope: cannot open pipe to shell command: %s\n", newpat);
/* search for the pattern */ /* search for the pattern */
if (search() == YES) { if (search() == YES) {
curdispline = 0; curdispline = 0;
++selecting; if(current_window != &wresult){
horswp_field();
}
switch (field) { switch (field) {
case DEFINITION: case DEFINITION:
@ -582,7 +548,6 @@ readrefs(char *filename)
} }
/* change one text string to another */ /* change one text string to another */
static BOOL static BOOL
changestring(void) changestring(void)
{ {
@ -612,7 +577,7 @@ changestring(void)
/* display the current page of lines */ /* display the current page of lines */
display(); display();
same: same:
atchange(); //atchange();
/* get a character from the terminal */ /* get a character from the terminal */
if ((c = mygetch()) == EOF || c == ctrl('D')) { if ((c = mygetch()) == EOF || c == ctrl('D')) {
@ -627,26 +592,21 @@ changestring(void)
#endif #endif
} }
/* see if the input character is a command */ /* see if the input character is a command */
// wtf is this? ?!
switch (c) { switch (c) {
case ' ': /* display next page */ case ' ': /* display next page */
case '+': case '+':
case ctrl('V'): case ctrl('V'):
#ifdef KEY_NPAGE
case KEY_NPAGE: case KEY_NPAGE:
#endif
case '-': /* display previous page */ case '-': /* display previous page */
#ifdef KEY_PPAGE
case KEY_PPAGE: case KEY_PPAGE:
#endif
case '!': /* shell escape */ case '!': /* shell escape */
case '?': /* help */ case '?': /* help */
command(c); command(c);
break; break;
case ctrl('L'): /* redraw screen */ case ctrl('L'): /* redraw screen */
#ifdef KEY_CLEAR
case KEY_CLEAR: case KEY_CLEAR:
#endif
command(c); command(c);
goto same; goto same;
@ -774,7 +734,6 @@ changestring(void)
/* if any line was marked */ /* if any line was marked */
if (anymarked == YES) { if (anymarked == YES) {
/* edit the files */ /* edit the files */
clearprompt(); clearprompt();
refresh(); refresh();
@ -867,11 +826,7 @@ countrefs(void)
/* count the references found and find the length of the file, /* count the references found and find the length of the file,
function, and line number display fields */ function, and line number display fields */
subsystemlen = 9; /* strlen("Subsystem") */
booklen = 4; /* strlen("Book") */
filelen = 4; /* strlen("File") */
fcnlen = 8; /* strlen("Function") */
numlen = 0;
/* HBB NOTE 2012-04-07: it may look like we shouldn't assing tempstring here, /* HBB NOTE 2012-04-07: it may look like we shouldn't assing tempstring here,
* since it's not used. But it has to be assigned just so the return value * since it's not used. But it has to be assigned just so the return value
* of fscanf will actually reach 4. */ * of fscanf will actually reach 4. */

View File

@ -99,6 +99,61 @@
#define INCLUDES 8 #define INCLUDES 8
#define FIELDS 10 #define FIELDS 10
/* file open modes */
#ifndef R_OK
# define READ R_OK
#else
# define READ 4
#endif
#ifdef W_OK
# define WRITE W_OK
#else
# define WRITE 2
#endif
#define O_TEXT 0x00
#define O_BINARY 0x00
/* Key macros */
/* These macros are not guaranteed to be defined,
* however we wish to test for these anyways while
* interpretting user commands.
* Input values are guaranteed to be postive,
* so setting them to -1 means the test always just silently fail,
* but compile when the they are not supported means of input.
*/
#ifndef KEY_DOWN
# define KEY_DOWN KEY_UNDEF_BASE-1
#endif
#ifndef KEY_UP
# define KEY_UP KEY_UNDEF_BASE-2
#endif
#ifndef KEY_LEFT
# define KEY_LEFT KEY_UNDEF_BASE-3
#endif
#ifndef KEY_RIGHT
# define KEY_RIGHT KEY_UNDEF_BASE-4
#endif
#ifndef KEY_HOME
# define KEY_HOME _KEY_UNDEF_BASE-5
#endif
#ifndef KEY_LL
# define KEY_LL KEY_UNDEF_BASE-6
#endif
#ifndef KEY_PPAGE
# define KEY_PPAGE KEY_UNDEF_BASE-7
#endif
#ifndef KEY_NPAGE
# define KEY_NPAGE KEY_UNDEF_BASE-8
#endif
#ifdef KEY_ENTER
# define KEY_ENTER KEY_UNDEF_BASE-9
#endif
#ifndef KEY_CLEAR
# define KEY_CLEAR KEY_UNDEF_BASE-10
#endif
/**/
#if (BSD || V9) && !__NetBSD__ && !__FreeBSD__ && !__APPLE__ #if (BSD || V9) && !__NetBSD__ && !__FreeBSD__ && !__APPLE__
# define TERMINFO 0 /* no terminfo curses */ # define TERMINFO 0 /* no terminfo curses */
#else #else
@ -130,4 +185,6 @@
# endif /* if UNIXPC */ # endif /* if UNIXPC */
#endif /* if !TERMINFO */ #endif /* if !TERMINFO */
#define INPUT_PROMPT "$ "
#endif /* CSCOPE_CONSTANTS_H */ #endif /* CSCOPE_CONSTANTS_H */

View File

@ -50,38 +50,52 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
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 booklen; /* OGS book name display field length */
int *displine; /* screen line of displayed reference */ int *displine; /* screen line of displayed reference */
unsigned int disprefs; /* displayed references */ unsigned int disprefs; /* displayed references */
int field; /* input field */ int field; /* input field */
int filelen; /* file name display field length */
int fcnlen; /* function name display field length */
unsigned int mdisprefs; /* maximum displayed references */ unsigned int mdisprefs; /* maximum displayed references */
unsigned int nextline; /* next line to be shown */ unsigned int nextline; /* next line to be shown */
FILE *nonglobalrefs; /* non-global references file */ FILE *nonglobalrefs; /* non-global references file */
int numlen; /* line number display field length */
unsigned int topline = 1; /* top line of page */ unsigned int topline = 1; /* top line of page */
int bottomline; /* bottom line of page */ static int bottomline; /* bottom line of page */
long searchcount; /* count of files searched */ long searchcount; /* count of files searched */
int subsystemlen; /* OGS subsystem name display field length */
unsigned int totallines; /* total reference lines */ unsigned int totallines; /* total reference lines */
unsigned fldcolumn; /* input field column */ unsigned fldcolumn; /* input field column */
WINDOW* body; unsigned int curdispline = 0;
WINDOW* input_fields;
WINDOW* winput;
WINDOW* wmode;
WINDOW* wresult;
WINDOW** current_window;
static WINDOW** last_window;
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;
#define WRESULT_TABLE_BODY_START 4
static enum { static enum {
CH_BODY = 0x0001, CH_RESULT = 0x0001,
CH_INPUT_FIELDS = CH_BODY << 1, CH_INPUT = CH_RESULT << 1,
CH_COMMAND_FIELD = CH_BODY << 2, CH_MODE = CH_RESULT << 2,
CH_ALL = CH_BODY | CH_INPUT_FIELDS | CH_COMMAND_FIELD CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
}; };
const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static int fldline; /* input field line */ static int fldline; /* input field line */
static sigjmp_buf env; /* setjmp/longjmp buffer */ static sigjmp_buf env; /* setjmp/longjmp buffer */
static int lastdispline; /* last displayed reference line */
static char lastmsg[MSGLEN + 1]; /* last message displayed */ static char lastmsg[MSGLEN + 1]; /* last message displayed */
static const char helpstring[] = "Press the ? key for help"; static const char helpstring[] = "Press the ? key for help";
static const char selprompt[] = static const char selprompt[] =
@ -89,11 +103,6 @@ static const char selprompt[] =
typedef char * (*FP)(char *); /* pointer to function returning a character pointer */ typedef char * (*FP)(char *); /* pointer to function returning a character pointer */
/* HBB 2000/05/05: I removed the casts to function pointer type. It is
* fundamentally unsafe to call a function through a pointer of a
* different type ('undefined behaviour' in the words of the ANSI/ISO
* C standard). Instead, I made all the find...() functions adhere to
* the same function type, by changing argument passing a bit. */
static struct { /* text of input fields */ static struct { /* text of input fields */
char *text1; char *text1;
char *text2; char *text2;
@ -116,7 +125,6 @@ static struct { /* text of input fields */
static void jumpback(int sig); static void jumpback(int sig);
/* initialize display parameters */ /* initialize display parameters */
void void
dispinit(void) dispinit(void)
{ {
@ -126,32 +134,52 @@ dispinit(void)
keypad(stdscr, TRUE); /* enable the keypad */ keypad(stdscr, TRUE); /* enable the keypad */
//fixkeypad(); /* fix for getch() intermittently returning garbage */ //fixkeypad(); /* fix for getch() intermittently returning garbage */
standend(); /* turn off reverse video */ standend(); /* turn off reverse video */
curs_set(0);
noecho();
/* calculate the maximum displayed reference lines */ /* Calculate section sizes */
lastdispline = FLDLINE - 3; result_window_height = LINES - 2;
mdisprefs = lastdispline - REFLINE + 1; 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 - 1;
if (mdisprefs <= 0) { if (mdisprefs <= 0) {
postfatal("%s: screen too small\n", argv0); postfatal("%s: screen too small\n", argv0);
/* NOTREACHED */ /* NOTREACHED */
} }
if(mdisprefs > strlen(dispchars)){
if (mouse == NO && mdisprefs > strlen(dispchars))
mdisprefs = strlen(dispchars); mdisprefs = strlen(dispchars);
}
/* allocate the displayed line array */ /* allocate the displayed line array */
displine = malloc(mdisprefs * sizeof(*displine)); displine = malloc(mdisprefs * sizeof(*displine));
/* initialize windows */ /* initialize windows */
body = newwin(LINES-2-FIELDS, COLS-2, 1, 1); winput = newwin(input_window_height, first_col_width, 1, 1);
input_fields = newwin(FIELDS, COLS-2, FLDLINE, 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);
refresh(); refresh();
current_window = &winput;
} }
static inline void display_frame(){ static inline void display_frame(){
box(stdscr, 0, 0); box(stdscr, 0, 0);
/* Vertical line */
mvaddch(0, first_col_width + 1, ACS_TTEE);
for(int i = 0; i < LINES-2; i++){
mvaddch(i+1, first_col_width + 1, ACS_VLINE);
}
mvaddch(LINES-1, first_col_width + 1, ACS_BTEE);
/* Horizontal line */
wmove(stdscr, input_window_height + 1, 0);
addch(ACS_LTEE);
for(int i = 0; i < first_col_width; i++){
addch(ACS_HLINE);
}
addch(ACS_RTEE);
/* Title*/ /* Title*/
const int LEFT_PADDING = 5; const int LEFT_PADDING = 5;
wmove(stdscr, 0, LEFT_PADDING); wmove(stdscr, 0, LEFT_PADDING);
@ -165,146 +193,142 @@ static inline void display_frame(){
#else #else
wprintw(stdscr, "Cscope version %d%s", FILEVERSION, FIXVERSION); wprintw(stdscr, "Cscope version %d%s", FILEVERSION, FIXVERSION);
#endif #endif
wmove(stdscr, 0, COLS - (int) sizeof(helpstring)); wmove(stdscr, 0, COLS - (int)sizeof(helpstring) - 3);
waddstr(stdscr, helpstring); waddstr(stdscr, helpstring);
wmove(input_fields, 0, 0);
for(int i = 0; i < COLS-2; i++){
waddch(input_fields, ACS_HLINE);
}
} }
static inline void display_input_fields(){ static inline void display_input_fields(){
/* display the input fields */
wmove(input_fields, 1, 0);
for(int i = 0; i < FIELDS; ++i){ for(int i = 0; i < FIELDS; ++i){
wprintw(input_fields, "%s %s:\n", fields[i].text1, fields[i].text2); mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
} }
} }
static inline void display_command_field(){ static inline void display_command_field(){
mvwprintw(winput, 0, 0, INPUT_PROMPT);
} }
void static inline void display_results(){
display(void)
{
char *subsystem; /* OGS subsystem name */ char *subsystem; /* OGS subsystem name */
char *book; /* OGS book name */ char *book; /* OGS book name */
char file[PATHLEN + 1]; /* file name */ char file[PATHLEN + 1]; /* file name */
char function[PATLEN + 1]; /* function name */ char function[PATLEN + 1]; /* function name */
char linenum[NUMLEN + 1]; /* line number */ char linenum[NUMLEN + 1]; /* line number */
int screenline; /* screen line number */ int screenline; /* screen line number */
int width; /* source line display width */ int srctxtw; /* source line display width */
int i; int i;
char *s; char *s;
erase(); werase(wresult);
display_frame();
if (totallines == 0) { if (totallines == 0) {
/* if no references were found */ /* if no references were found */
/* redisplay the last message */ /* redisplay the last message */
waddstr(body, lastmsg); waddstr(wresult, lastmsg);
} else { return;
/* NOTREACHED */
}
/* display the pattern */ /* display the pattern */
if (changing == YES) { if (changing == YES) {
wprintw(body, "Change \"%s\" to \"%s\"", Pattern, newpat); wprintw(wresult, "Change \"%s\" to \"%s\"", Pattern, newpat);
} else { } else {
wprintw(body, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]), wprintw(wresult, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1, Pattern); fields[field].text2 + 1, Pattern);
} }
/* display the column headings */ /* display the column headings */
wmove(body, 2, 2); wmove(wresult, 2, 2);
if (ogs == YES && field != FILENAME) { if (ogs == YES && field != FILENAME) {
wprintw(body, "%-*s ", subsystemlen, "Subsystem"); wprintw(wresult, "%-*s ", subsystemlen, "Subsystem");
wprintw(body, "%-*s ", booklen, "Book"); wprintw(wresult, "%-*s ", booklen, "Book");
} }
if (dispcomponents > 0) if (dispcomponents > 0)
wprintw(body, "%-*s ", filelen, "File"); wprintw(wresult, "%-*s ", filelen, "File");
if (field == SYMBOL || field == CALLEDBY || field == CALLING) { if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
wprintw(body, "%-*s ", fcnlen, "Function"); wprintw(wresult, "%-*s ", fcnlen, "Function");
} }
if (field != FILENAME) { if (field != FILENAME) {
waddstr(body, "Line"); waddstr(wresult, "Line");
} }
waddch(body, '\n');
/* if at end of file go back to beginning */ wmove(wresult, WRESULT_TABLE_BODY_START, 0);
if (nextline > totallines) {
seekline(1);
}
/* calculate the source text column */ /* calculate the source text column */
/* NOTE: the +1s are column gaps */
width = COLS - numlen - 3; srctxtw = second_col_width;
srctxtw -= 1+1; // dispchars
if (ogs == YES) { if (ogs == YES) {
width -= subsystemlen + booklen + 2; srctxtw -= subsystemlen+1 + booklen+1;
} }
if (dispcomponents > 0) { if (dispcomponents > 0) {
width -= filelen + 1; srctxtw -= filelen+1;
} }
if (field == SYMBOL || field == CALLEDBY || field == CALLING) { if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
width -= fcnlen + 1; srctxtw -= fcnlen+1;
} }
srctxtw -= numlen+1;
/* until the max references have been displayed or /* until the max references have been displayed or
there is no more room */ there is no more room */
topline = nextline; topline = nextline;
for (disprefs = 0, screenline = REFLINE; for (disprefs = 0, screenline = REFLINE;
disprefs < mdisprefs && screenline <= lastdispline; disprefs < mdisprefs && screenline <= result_window_height;
++disprefs, ++screenline) { ++disprefs, ++screenline)
{
/* read the reference line */ /* read the reference line */
if (fscanf(refsfound, "%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]", file, function, if (
linenum, tempstring) < 4) { fscanf(refsfound, "%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
file,
function,
linenum,
tempstring
)
<
4
)
{
break; break;
} }
++nextline; ++nextline;
displine[disprefs] = screenline; displine[disprefs] = screenline;
/* if no mouse, display the selection number */ wprintw(wresult, "%c", dispchars[disprefs]);
if (mouse == YES) {
waddch(body, ' ');
} else {
wprintw(body, "%c", dispchars[disprefs]);
}
/* display any change mark */ /* display any change mark */
if (changing == YES && if (changing == YES && change[topline + disprefs - 1] == YES) {
change[topline + disprefs - 1] == YES) { waddch(wresult, '>');
waddch(body, '>');
} else { } else {
waddch(body, ' '); waddch(wresult, ' ');
} }
/* display the file name */ /* display the file name */
if (field == FILENAME) { if (field == FILENAME) {
wprintw(body, "%-*s ", filelen, file); wprintw(wresult, "%-*s ", filelen, file);
} else { } else {
/* if OGS, display the subsystem and book names */ /* if OGS, display the subsystem and book names */
if (ogs == YES) { if (ogs == YES) {
ogsnames(file, &subsystem, &book); ogsnames(file, &subsystem, &book);
wprintw(body, "%-*.*s ", subsystemlen, subsystemlen, subsystem); wprintw(wresult, "%-*.*s ", subsystemlen, subsystemlen, subsystem);
wprintw(body, "%-*.*s ", booklen, booklen, book); wprintw(wresult, "%-*.*s ", booklen, booklen, book);
} }
/* display the requested path components */ /* display the requested path components */
if (dispcomponents > 0) { if (dispcomponents > 0) {
wprintw(body, "%-*.*s ", filelen, filelen, wprintw(wresult, "%-*.*s ", filelen, filelen,
pathcomponents(file, dispcomponents)); pathcomponents(file, dispcomponents));
} }
} /* else(field == FILENAME) */ } /* else(field == FILENAME) */
/* display the function name */ /* display the function name */
if (field == SYMBOL || field == CALLEDBY || field == CALLING) { if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
wprintw(body, "%-*.*s ", fcnlen, fcnlen, function); wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
} }
if (field == FILENAME) { if (field == FILENAME) {
waddch(body, '\n'); /* go to next line */ waddch(wresult, '\n'); /* go to next line */
continue; continue;
} }
/* display the line number */ /* display the line number */
wprintw(body, "%*s ", numlen, linenum); wprintw(wresult, "%*s ", numlen, linenum);
/* there may be tabs in egrep output */ /* there may be tabs in egrep output */
while ((s = strchr(tempstring, '\t')) != NULL) { while ((s = strchr(tempstring, '\t')) != NULL) {
*s = ' '; *s = ' ';
@ -313,24 +337,25 @@ display(void)
/* display the source line */ /* display the source line */
s = tempstring; s = tempstring;
for (;;) { for (;;) {
/* see if the source line will fit */ /* if the source line does not fit */
if ((i = strlen(s)) > width) { if ((i = strlen(s)) > srctxtw) {
/* find the nearest blank */ /* find the nearest blank */
for (i = width; s[i] != ' ' && i > 0; --i) { for (i = srctxtw; s[i] != ' ' && i > 0; --i) {
; ;
} }
if (i == 0) { if (i == 0) {
i = width; /* no blank */ i = srctxtw; /* no blank */
} }
} }
/* print up to this point */ /* print up to this point */
wprintw(body, "%.*s", i, s); wprintw(wresult, "%.*s", i, s);
s += i; s += i;
/* if line didn't wrap around */ /* if line didn't wrap around */
if (i < width) { if (i < srctxtw) {
waddch(body, '\n'); /* go to next line */ waddch(wresult, '\n'); /* go to next line */
} }
/* skip blanks */ /* skip blanks */
while (*s == ' ') { while (*s == ' ') {
@ -341,7 +366,7 @@ display(void)
break; break;
} }
/* if the source line is too long */ /* if the source line is too long */
if (++screenline > lastdispline) { if (++screenline > result_window_height) {
/* if this is the first displayed line, /* if this is the first displayed line,
display what will fit on the screen */ display what will fit on the screen */
@ -353,8 +378,8 @@ display(void)
/* erase the reference */ /* erase the reference */
while (--screenline >= displine[disprefs]) { while (--screenline >= displine[disprefs]) {
wmove(body, screenline, 0); wmove(wresult, screenline, 0);
clrtoeol(); wclrtoeol(wresult);
} }
++screenline; ++screenline;
@ -364,39 +389,83 @@ display(void)
goto endrefs; goto endrefs;
} }
/* indent the continued source line */ /* indent the continued source line */
wmove(body, screenline, COLS - width); wmove(wresult, screenline, second_col_width - srctxtw);
} /* for(ever) */ } /* for(ever) */
} /* for(reference output lines) */ } /* for(reference output lines) */
endrefs: endrefs:
/* position the cursor for the message */ /* position the cursor for the message */
i = FLDLINE - 1; i = FLDLINE - 1;
if (screenline < i) { if (screenline < i) {
waddch(body, '\n'); waddch(wresult, '\n');
} }
else { else {
wmove(body, i, 0); wmove(wresult, i, 0);
} }
/* check for more references */ /* check for more references */
i = totallines - nextline + 1; i = totallines - nextline + 1;
bottomline = nextline; bottomline = nextline;
if (i > 0) { if (i > 0) {
wprintw(body, "* Lines %d-%d of %d, %d more - press the space bar to display more *", topline, bottomline, totallines, i); wprintw(wresult, "* Lines %d-%d of %d, %d more - press the space bar to display more *", topline, bottomline, totallines, i);
} }
/* if this is the last page of references */ /* if this is the last page of references */
else if (topline > 1 && nextline > totallines) { else if (topline > 1 && nextline > totallines) {
waddstr(body, "* Press the space bar to display the first lines again *"); waddstr(wresult, "* Press the space bar to display the first lines again *");
} }
} }
drawscrollbar(topline, nextline); /* display the scrollbar */
atfield(); void display_cursor(void){
chtype i;
int yoffset = 0, xoffset = 0;
if(current_window == &winput){
xoffset = sizeof(INPUT_PROMPT)-1;
}else if(current_window == &wmode){
yoffset = field;
}else if(current_window == &wresult){
yoffset = WRESULT_TABLE_BODY_START + curdispline;
}else{
assert(("No window selected.", true));
}
wmove(*current_window, yoffset, xoffset);
i = winch(*current_window);
i |= A_REVERSE;
waddch(*current_window, i);
}
void
display(void)
{
//drawscrollbar(topline, nextline); /* display the scrollbar */
display_frame();
display_command_field();
display_input_fields(); display_input_fields();
display_prompt(); display_results();
display_cursor();
refresh(); refresh();
wrefresh(body); wrefresh(winput);
wrefresh(input_fields); wrefresh(wmode);
wrefresh(wresult);
}
void
horswp_field(void){
if(current_window != &wresult){
last_window = current_window;
current_window = &wresult;
}else{
current_window = last_window;
}
}
void
verswp_field(void){
if(current_window == &wresult){ return; }
current_window = (current_window == &winput) ? &wmode : &winput;
} }
/* set the cursor position for the field */ /* set the cursor position for the field */
@ -420,7 +489,7 @@ display(void)
//void //void
//atchange(void) //atchange(void)
//{ //{
// wmove(body, PRLINE, (int) sizeof(selprompt) - 1); // wmove(wresult, PRLINE, (int) sizeof(selprompt) - 1);
//} //}
/* search for the symbol or text pattern */ /* search for the symbol or text pattern */
@ -530,7 +599,6 @@ search(void)
} }
/* display search progress with default custom format */ /* display search progress with default custom format */
void void
progress(char *what, long current, long max) progress(char *what, long current, long max)
{ {
@ -547,15 +615,15 @@ progress(char *what, long current, long max)
{ {
if (linemode == NO) if (linemode == NO)
{ {
wmove(body, MSGLINE, 0); wmove(wresult, MSGLINE, 0);
clrtoeol(); wclrtoeol(wresult);
waddstr(body, what); waddstr(wresult, what);
snprintf(msg, sizeof(msg), "%ld", current); snprintf(msg, sizeof(msg), "%ld", current);
wmove(body, MSGLINE, (COLS / 2) - (strlen(msg) / 2)); wmove(wresult, MSGLINE, (COLS / 2) - (strlen(msg) / 2));
waddstr(body, msg); waddstr(wresult, msg);
snprintf(msg, sizeof(msg), "%ld", max); snprintf(msg, sizeof(msg), "%ld", max);
wmove(body, MSGLINE, COLS - strlen(msg)); wmove(wresult, MSGLINE, COLS - strlen(msg));
waddstr(body, msg); waddstr(wresult, msg);
refresh(); refresh();
} }
else if (verbosemode == YES) else if (verbosemode == YES)
@ -566,12 +634,12 @@ progress(char *what, long current, long max)
start = now; start = now;
if ((linemode == NO) && (incurses == YES)) if ((linemode == NO) && (incurses == YES))
{ {
wmove(body, MSGLINE, 0); wmove(wresult, MSGLINE, 0);
i = (float)COLS * (float)current / (float)max; i = (float)COLS * (float)current / (float)max;
standout(); standout();
for (; i > 0; i--) for (; i > 0; i--)
waddch(body, inch()); waddch(wresult, inch());
standend(); standend();
refresh(); refresh();
} }
@ -583,7 +651,6 @@ progress(char *what, long current, long max)
} }
/* print error message on system call failure */ /* print error message on system call failure */
void void
myperror(char *text) myperror(char *text)
{ {
@ -598,7 +665,6 @@ myperror(char *text)
/* postmsg clears the message line and prints the message */ /* postmsg clears the message line and prints the message */
/* VARARGS */
void void
postmsg(char *msg) postmsg(char *msg)
{ {
@ -608,8 +674,8 @@ postmsg(char *msg)
} }
else { else {
clearmsg(); clearmsg();
waddstr(body, msg); waddstr(wresult, msg);
refresh(); wrefresh(wresult);
} }
(void) strncpy(lastmsg, msg, sizeof(lastmsg) - 1); (void) strncpy(lastmsg, msg, sizeof(lastmsg) - 1);
} }
@ -619,25 +685,21 @@ postmsg(char *msg)
void void
clearmsg(void) clearmsg(void)
{ {
if (linemode == NO) { wmove(wresult, MSGLINE, 0);
wmove(body, MSGLINE, 0); wclrtoeol(wresult);
clrtoeol();
}
} }
/* clearmsg2 clears the second message line */ /* clearmsg2 clears the second message line */
void void
clearmsg2(void) clearmsg2(void)
{ {
if (linemode == NO) { if (linemode == NO) {
wmove(body, MSGLINE + 1, 0); wmove(wresult, MSGLINE + 1, 0);
clrtoeol(); wclrtoeol(wresult);
} }
} }
/* postmsg2 clears the second message line and prints the message */ /* postmsg2 clears the second message line and prints the message */
void void
postmsg2(char *msg) postmsg2(char *msg)
{ {
@ -646,7 +708,7 @@ postmsg2(char *msg)
} }
else { else {
clearmsg2(); clearmsg2();
waddstr(body, msg); waddstr(wresult, msg);
refresh(); refresh();
} }
} }
@ -692,7 +754,6 @@ postfatal(const char *msg, ...)
} }
/* position references found file at specified line */ /* position references found file at specified line */
void void
seekline(unsigned int line) seekline(unsigned int line)
{ {
@ -715,7 +776,6 @@ seekline(unsigned int line)
} }
/* get the OGS subsystem and book names */ /* get the OGS subsystem and book names */
void void
ogsnames(char *file, char **subsystem, char **book) ogsnames(char *file, char **subsystem, char **book)
{ {
@ -744,7 +804,6 @@ ogsnames(char *file, char **subsystem, char **book)
} }
/* get the requested path components */ /* get the requested path components */
char * char *
pathcomponents(char *path, int components) pathcomponents(char *path, int components)
{ {
@ -764,7 +823,6 @@ pathcomponents(char *path, int components)
} }
/* open the references found file for writing */ /* open the references found file for writing */
BOOL BOOL
writerefsfound(void) writerefsfound(void)
{ {

View File

@ -84,24 +84,12 @@ struct cmd { /* command history struct */
char *text; /* input field text */ char *text; /* input field text */
}; };
#ifndef R_OK
# define READ R_OK
#else
# define READ 4
#endif
#ifdef W_OK
# define WRITE W_OK
#else
# define WRITE 2
#endif
#define O_TEXT 0x00
#define O_BINARY 0x00
#ifndef DFLT_INCDIR #ifndef DFLT_INCDIR
# define DFLT_INCDIR "/usr/include" # define DFLT_INCDIR "/usr/include"
#endif #endif
/* digraph data for text compression */ /* digraph data for text compression */
extern char dichar1[]; /* 16 most frequent first chars */ extern char dichar1[]; /* 16 most frequent first chars */
extern char dichar2[]; /* 8 most frequent second chars extern char dichar2[]; /* 8 most frequent second chars
@ -155,7 +143,6 @@ extern char *tmpdir; /* temporary directory */
extern BOOL caseless; /* ignore letter case when searching */ extern BOOL caseless; /* ignore letter case when searching */
extern BOOL *change; /* change this line */ extern BOOL *change; /* change this line */
extern BOOL changing; /* changing text */ extern BOOL changing; /* changing text */
extern int selecting;
extern unsigned int curdispline; extern unsigned int curdispline;
extern char newpat[]; /* new pattern */ extern char newpat[]; /* new pattern */
extern char Pattern[]; /* symbol or text pattern */ extern char Pattern[]; /* symbol or text pattern */
@ -178,21 +165,20 @@ extern unsigned long nsrcfiles; /* number of source files */
extern unsigned long msrcfiles; /* maximum number of source files */ extern unsigned long msrcfiles; /* maximum number of source files */
/* display.c global data */ /* display.c global data */
extern int subsystemlen; /* OGS subsystem name display field length */
extern int booklen; /* OGS book name display field length */ extern int booklen; /* OGS book name display field length */
extern int filelen; /* file name display field length */
extern int fcnlen; /* function name display field length */
extern int numlen; /* line number display field length */
extern int *displine; /* screen line of displayed reference */ extern int *displine; /* screen line of displayed reference */
extern unsigned int disprefs; /* displayed references */ extern unsigned int disprefs; /* displayed references */
extern int fcnlen; /* function name display field length */
extern int field; /* input field */ extern int field; /* input field */
extern int filelen; /* file name display field length */
extern unsigned fldcolumn; /* input field column */ extern unsigned fldcolumn; /* input field column */
extern unsigned int mdisprefs; /* maximum displayed references */ extern unsigned int mdisprefs; /* maximum displayed references */
extern unsigned int nextline; /* next line to be shown */ extern unsigned int nextline; /* next line to be shown */
extern FILE *nonglobalrefs; /* non-global references file */ extern FILE *nonglobalrefs; /* non-global references file */
extern int numlen; /* line number display field length */
extern unsigned int topline; /* top line of page */ extern unsigned int topline; /* top line of page */
extern int bottomline; /* bottom line of page */
extern long searchcount; /* count of files searched */ extern long searchcount; /* count of files searched */
extern int subsystemlen; /* OGS subsystem name display field length */
extern unsigned int totallines; /* total reference lines */ extern unsigned int totallines; /* total reference lines */
extern const char dispchars[]; /* display chars for jumping to lines */ extern const char dispchars[]; /* display chars for jumping to lines */
@ -243,13 +229,13 @@ void usage(void);
extern BOOL remove_symfile_onexit; extern BOOL remove_symfile_onexit;
extern BOOL onesearch; /* one search only in line mode */ extern BOOL onesearch; /* one search only in line mode */
extern char *reflines; /* symbol reference lines file */ extern char *reflines; /* symbol reference lines file */
void verswp_field(void);
void horswp_field(void);
void addcmd(int f, char *s); void addcmd(int f, char *s);
void addsrcfile(char *path); void addsrcfile(char *path);
void askforchar(void); void askforchar(void);
void askforreturn(void); void askforreturn(void);
void atchange(void);
void atfield(void);
void cannotwrite(char *file); void cannotwrite(char *file);
void cannotopen(char *file); void cannotopen(char *file);
void clearmsg(void); void clearmsg(void);
@ -291,7 +277,6 @@ void putposting(char *term, int type);
void fetch_string_from_dbase(char *, size_t); void fetch_string_from_dbase(char *, size_t);
void resetcmd(void); void resetcmd(void);
void seekline(unsigned int line); void seekline(unsigned int line);
void setfield(void);
void shellpath(char *out, int limit, char *in); void shellpath(char *out, int limit, char *in);
void sourcedir(char *dirlist); void sourcedir(char *dirlist);
void myungetch(int c); void myungetch(int c);

View File

@ -89,6 +89,7 @@ nextcmd(void)
} else } else
return NULL; return NULL;
} }
/* reset current to tail */ /* reset current to tail */
void void
resetcmd(void) resetcmd(void)

View File

@ -87,7 +87,7 @@ BOOL linemode = NO; /* use line oriented user interface */
BOOL verbosemode = NO; /* print extra information on line mode */ BOOL verbosemode = NO; /* print extra information on line mode */
BOOL recurse_dir = NO; /* recurse dirs when searching for src files */ BOOL recurse_dir = NO; /* recurse dirs when searching for src files */
char *namefile; /* file of file names */ char *namefile; /* file of file names */
BOOL ogs; /* display OGS book and subsystem names */ BOOL ogs = NO; /* display OGS book and subsystem names */
char *prependpath; /* prepend path to file names */ char *prependpath; /* prepend path to file names */
FILE *refsfound; /* references found file */ FILE *refsfound; /* references found file */
char temp1[PATHLEN + 1]; /* temporary file name */ char temp1[PATHLEN + 1]; /* temporary file name */
@ -99,11 +99,14 @@ char tempstring[TEMPSTRING_LEN + 1]; /* use this as a buffer, instead of 'yytext
* which had better be left alone */ * which had better be left alone */
char *tmpdir; /* temporary directory */ char *tmpdir; /* temporary directory */
static char path[PATHLEN + 1]; /* file path */
/* Internal prototypes: */ /* Internal prototypes: */
static void skiplist(FILE *oldrefs); static void skiplist(FILE *oldrefs);
static void initcompress(void); static void initcompress(void);
static inline void readenv(void); static inline void readenv(void);
static inline void linemode_event_loop(void);
static inline void screenmode_event_loop(void);
#if defined(KEY_RESIZE) && !defined(__DJGPP__) #if defined(KEY_RESIZE) && !defined(__DJGPP__)
void void
@ -115,21 +118,51 @@ sigwinch_handler(int sig, siginfo_t *info, void *unused)
} }
#endif #endif
static
inline
void
siginit(void){
/* if running in the foreground */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
/* cleanup on the interrupt and quit signals */
signal(SIGINT, myexit);
signal(SIGQUIT, myexit);
}
/* cleanup on the hangup signal */
signal(SIGHUP, myexit);
/* ditto the TERM signal */
signal(SIGTERM, myexit);
/* ignore PIPE signal, so myexit() will have a chance to clean up in
* linemode, while in curses mode the "|" command can cause a pipe signal
* too
*/
signal(SIGPIPE, SIG_IGN);
if (linemode == NO) {
signal(SIGINT, SIG_IGN); /* ignore interrupts */
#if defined(KEY_RESIZE) && !defined(__DJGPP__)
struct sigaction winch_action;
winch_action.sa_sigaction = sigwinch_handler;
sigemptyset(&winch_action.sa_mask);
winch_action.sa_flags = SA_SIGINFO;
sigaction(SIGWINCH,&winch_action,NULL);
#endif
}
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
FILE *names; /* name file pointer */ FILE *names; /* name file pointer */
int oldnum; /* number in old cross-ref */ int oldnum; /* number in old cross-ref */
char path[PATHLEN + 1]; /* file path */
FILE *oldrefs; /* old cross-reference file */ FILE *oldrefs; /* old cross-reference file */
char *s; char *s;
int c;
unsigned int i; unsigned int i;
pid_t pid; pid_t pid;
struct stat stat_buf; struct stat stat_buf;
#if defined(KEY_RESIZE) && !defined(__DJGPP__)
struct sigaction winch_action;
#endif
mode_t orig_umask; mode_t orig_umask;
yyin = stdin; yyin = stdin;
@ -175,24 +208,6 @@ main(int argc, char **argv)
snprintf(temp1, sizeof(temp1), "%s/cscope.1", tempdirpv); snprintf(temp1, sizeof(temp1), "%s/cscope.1", tempdirpv);
snprintf(temp2, sizeof(temp2), "%s/cscope.2", tempdirpv); snprintf(temp2, sizeof(temp2), "%s/cscope.2", tempdirpv);
/* if running in the foreground */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
/* cleanup on the interrupt and quit signals */
signal(SIGINT, myexit);
signal(SIGQUIT, myexit);
}
/* cleanup on the hangup signal */
signal(SIGHUP, myexit);
/* ditto the TERM signal */
signal(SIGTERM, myexit);
/* ignore PIPE signal, so myexit() will have a chance to clean up in
* linemode, while in curses mode the "|" command can cause a pipe signal
* too
*/
signal(SIGPIPE, SIG_IGN);
/* if the database path is relative and it can't be created */ /* if the database path is relative and it can't be created */
if (reffile[0] != '/' && access(".", WRITE) != 0) { if (reffile[0] != '/' && access(".", WRITE) != 0) {
@ -212,18 +227,10 @@ main(int argc, char **argv)
} }
} }
siginit();
if (linemode == NO) { if (linemode == NO) {
signal(SIGINT, SIG_IGN); /* ignore interrupts */
#if defined(KEY_RESIZE) && !defined(__DJGPP__)
winch_action.sa_sigaction = sigwinch_handler;
sigemptyset(&winch_action.sa_mask);
winch_action.sa_flags = SA_SIGINFO;
sigaction(SIGWINCH,&winch_action,NULL);
#endif
dispinit(); /* initialize display parameters */ dispinit(); /* initialize display parameters */
setfield(); /* set the initial cursor position */
clearmsg(); /* clear any build progress message */ clearmsg(); /* clear any build progress message */
display(); /* display the version number and input fields */ display(); /* display the version number and input fields */
} }
@ -248,7 +255,7 @@ main(int argc, char **argv)
invertedindex = NO; invertedindex = NO;
/* see if there are options in the database */ /* see if there are options in the database */
for (;;) { for (int c;;) {
getc(oldrefs); /* skip the blank */ getc(oldrefs); /* skip the blank */
if ((c = getc(oldrefs)) != '-') { if ((c = getc(oldrefs)) != '-') {
ungetc(c, oldrefs); ungetc(c, oldrefs);
@ -385,13 +392,16 @@ main(int argc, char **argv)
/* build the cross-reference */ /* build the cross-reference */
initcompress(); initcompress();
if (linemode == NO || verbosemode == YES) /* display if verbose as well */ if (linemode == NO || verbosemode == YES) { /* display if verbose as well */
postmsg("Building cross-reference..."); postmsg("Building cross-reference...");
}
build(); build();
if (linemode == NO ) if (linemode == NO ) {
clearmsg(); /* clear any build progress message */ clearmsg(); /* clear any build progress message */
}
if (buildonly == YES) { if (buildonly == YES) {
myexit(0); myexit(0);
/* NOTREACHED */
} }
} }
opendatabase(); opendatabase();
@ -399,102 +409,7 @@ main(int argc, char **argv)
/* if using the line oriented user interface so cscope can be a /* if using the line oriented user interface so cscope can be a
subprocess to emacs or samuel */ subprocess to emacs or samuel */
if (linemode == YES) { if (linemode == YES) {
if (*Pattern != '\0') { /* do any optional search */ linemode_event_loop();
if (search() == YES) {
/* print the total number of lines in
* verbose mode */
if (verbosemode == YES)
printf("cscope: %d lines\n",
totallines);
while ((c = getc(refsfound)) != EOF)
putchar(c);
}
}
if (onesearch == YES)
myexit(0);
for (;;) {
char buf[PATLEN + 2];
printf(">> ");
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
myexit(0);
}
/* remove any trailing newline character */
if (*(s = buf + strlen(buf) - 1) == '\n') {
*s = '\0';
}
switch (*buf) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': /* samuel only */
field = *buf - '0';
strcpy(Pattern, buf + 1);
if (search() == NO) {
printf("Unable to search database\n");
} else {
printf("cscope: %d lines\n", totallines);
while ((c = getc(refsfound)) != EOF) {
putchar(c);
}
}
break;
case 'c': /* toggle caseless mode */
case ctrl('C'):
if (caseless == NO) {
caseless = YES;
} else {
caseless = NO;
}
egrepcaseless(caseless);
break;
case 'r': /* rebuild database cscope style */
case ctrl('R'):
freefilelist();
makefilelist();
/* FALLTHROUGH */
case 'R': /* rebuild database samuel style */
rebuild();
putchar('\n');
break;
case 'C': /* clear file names */
freefilelist();
putchar('\n');
break;
case 'F': /* add a file name */
strcpy(path, buf + 1);
if (infilelist(path) == NO &&
(s = inviewpath(path)) != NULL) {
addsrcfile(s);
}
putchar('\n');
break;
case 'q': /* quit */
case ctrl('D'):
case ctrl('Z'):
myexit(0);
default:
fprintf(stderr, "cscope: unknown command '%s'\n", buf);
break;
}
}
/* NOTREACHED */
} }
/* pause before clearing the screen if there have been error messages */ /* pause before clearing the screen if there have been error messages */
if (errorsfound == YES) { if (errorsfound == YES) {
@ -503,29 +418,13 @@ main(int argc, char **argv)
} }
/* do any optional search */ /* do any optional search */
if (*Pattern != '\0') { if (*Pattern != '\0') {
atfield(); /* move to the input field */
command(ctrl('Y')); /* search */ command(ctrl('Y')); /* search */
} else if (reflines != NULL) { } else if (reflines != NULL) {
/* read any symbol reference lines file */ /* read any symbol reference lines file */
readrefs(reflines); readrefs(reflines);
} }
display(); /* update the display */
for (;;) { screenmode_event_loop();
c = mygetch();
/* exit if the quit command is entered */
if (c == EOF || c == ctrl('D')) {
break;
}
if (c == ctrl('Z')) {
kill(0, SIGTSTP);
continue;
}
command(c);
display();
}
/* cleanup and exit */ /* cleanup and exit */
myexit(0); myexit(0);
/* NOTREACHED */ /* NOTREACHED */
@ -672,3 +571,126 @@ static inline void readenv(void){
lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE") ? 1 : 0; lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE") ? 1 : 0;
tmpdir = mygetenv("TMPDIR", TMPDIR); tmpdir = mygetenv("TMPDIR", TMPDIR);
} }
static inline void linemode_event_loop(void){
int c;
if (*Pattern != '\0') { /* do any optional search */
if (search() == YES) {
/* print the total number of lines in
* verbose mode */
if (verbosemode == YES)
printf("cscope: %d lines\n",
totallines);
while ((c = getc(refsfound)) != EOF)
putchar(c);
}
}
if (onesearch == YES) {
myexit(0);
/* NOTREACHED */
}
for (char *s;;) {
char buf[PATLEN + 2];
printf(">> ");
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
myexit(0);
}
/* remove any trailing newline character */
if (*(s = buf + strlen(buf) - 1) == '\n') {
*s = '\0';
}
switch (*buf) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': /* samuel only */
field = *buf - '0';
strcpy(Pattern, buf + 1);
if (search() == NO) {
printf("Unable to search database\n");
} else {
printf("cscope: %d lines\n", totallines);
while ((c = getc(refsfound)) != EOF) {
putchar(c);
}
}
break;
case 'c': /* toggle caseless mode */
case ctrl('C'):
if (caseless == NO) {
caseless = YES;
} else {
caseless = NO;
}
egrepcaseless(caseless);
break;
case 'r': /* rebuild database cscope style */
case ctrl('R'):
freefilelist();
makefilelist();
/* FALLTHROUGH */
case 'R': /* rebuild database samuel style */
rebuild();
putchar('\n');
break;
case 'C': /* clear file names */
freefilelist();
putchar('\n');
break;
case 'F': /* add a file name */
strcpy(path, buf + 1);
if (infilelist(path) == NO &&
(s = inviewpath(path)) != NULL) {
addsrcfile(s);
}
putchar('\n');
break;
case 'q': /* quit */
case ctrl('D'):
case ctrl('Z'):
myexit(0);
default:
fprintf(stderr, "cscope: unknown command '%s'\n", buf);
break;
}
}
}
static inline void screenmode_event_loop(void){
int c;
for (;;) {
display();
c = mygetch();
/* exit if the quit command is entered */
if (c == EOF || c == ctrl('D')) {
break;
}
if (c == ctrl('Z')) {
kill(0, SIGTSTP);
continue;
}
command(c);
}
}