This commit is contained in:
anon 2023-08-09 13:49:11 +02:00
parent a7331159b8
commit 30dd761054
11 changed files with 281 additions and 259 deletions

View File

@ -63,7 +63,6 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
+ recursive macro function to assign KEY_\* default values; look for a new and shiny preprocessor?
+ sort out constants.h
+ scrollbar() uses magic int literals?
+ Handle unused parameters gracefully (#define UNUSED(x) (void)(x))
+ Ordering function declarations in global.h by alpha order is not smart
+ lineflagafterfile is stupid
+ library.h...; "private library", in a program using 90 globals; ffs

View File

@ -44,3 +44,22 @@ basename(char *path)
}
return(path);
}
/* get the requested path components */
char *
pathcomponents(char *path, int components)
{
int i;
char *s;
s = path + strlen(path) - 1;
for (i = 0; i < components; ++i) {
while (s > path && *--s != '/') {
;
}
}
if (s > path && *s == '/') {
++s;
}
return(s);
}

View File

@ -57,7 +57,6 @@
this macro will always be in a statement by itself */
#define skiprefchar() if (*(++blockp + 1) == '\0') (void) read_block()
#define DEL '\177' /* delete character */
#define DUMMYCHAR ' ' /* use space as a dummy character */
#define MSGLEN ((PATLEN) + 80) /* displayed message length */
#define NUMLEN 10 /* line number length */
@ -81,8 +80,6 @@
#define TEMPSTRING_LEN_STR STRINGIZE(TEMPSTRING_LEN)
/* screen lines */
#define FLDLINE (LINES - FIELDS - 1 - 1) /* first input field line */
#define MSGLINE 0 /* message line */
#define PRLINE (LINES - 1) /* input prompt line */
/* input fields (value matches field order on screen) */

View File

@ -45,13 +45,16 @@
#endif
#include <ncurses.h>
#include <setjmp.h> /* jmp_buf */
#include <stdarg.h> /* va_list stuff */
#include <time.h>
#include <errno.h>
#include <stdarg.h>
#include <assert.h>
/* XXX */
#define MSGLINE 0 /* message line */
#define MSGCOL 0 /* message column */
static const char appendprompt[] = "Append to file: ";
static const char pipeprompt[] = "Pipe to shell command: ";
static const char readprompt[] = "Read from file: ";
@ -78,10 +81,12 @@ unsigned fldcolumn; /* input field column */
unsigned int curdispline = 0;
int current_page = 0;
/* Selectable windows */
WINDOW* winput;
WINDOW* wmode;
WINDOW* wresult;
WINDOW* whelp;
/* Selected window pointer */
WINDOW** current_window;
static WINDOW** last_window;
@ -109,19 +114,16 @@ int dispchar2int(const char c){
return r;
}
static sigjmp_buf env; /* setjmp/longjmp buffer */
static char lastmsg[MSGLEN + 1]; /* last message displayed */
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): ";
typedef char * (*FP)(char *); /* pointer to function returning a character pointer */
static struct { /* text of input fields */
struct { /* text of input fields */
char *text1;
char *text2;
FP findfcn;
} fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope display */
} /* Paralel array to "field_searchers", indexed by "field" */
fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope display */
{"Find this", "C symbol", findsymbol},
{"Find this", "global definition", finddef},
{"Find", "functions called by this function", findcalledby},
@ -135,9 +137,6 @@ static struct { /* text of input fields */
{"Find all", "function definitions", findallfcns}, /* samuel only */
};
/* Internal prototypes: */
static void jumpback(int sig);
/* initialize display parameters */
void
dispinit(void)
@ -257,6 +256,8 @@ static inline void display_frame(){
}
static inline void display_mode(){
werase(wmode);
for(int i = 0; i < FIELDS; ++i){
if(i == field){
wattron(wmode, A_REVERSE);
@ -284,22 +285,23 @@ static inline void display_results(){
char function[PATLEN + 1]; /* function name */
char linenum[NUMLEN + 1]; /* line number */
if (totallines == 0) {
/* if no references were found */
/* redisplay the last message */
werase(wresult);
/* --- Display the message --- */
if (totallines == 0) { // Its a real message
wmove(wresult, MSGLINE, 0);
wclrtoeol(wresult);
waddstr(wresult, lastmsg);
return;
/* NOTREACHED */
}
/* --- Display the pattern --- */
if (changing == true) {
wprintw(wresult, "Change \"%s\" to \"%s\"", input_line, newpat);
if (changing == true) { // Its a pattern
snprintf(lastmsg, MSGLEN, "Change \"%s\" to \"%s\"", input_line, newpat);
} else {
wprintw(wresult, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
snprintf(lastmsg, MSGLEN, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1, input_line);
}
waddstr(wresult, lastmsg);
/* --- Display the column headings --- */
wmove(wresult, 2, 2);
if (ogs == true && field != FILENAME) {
@ -527,11 +529,9 @@ display(void)
display_command_field();
}
if(window_change & CH_RESULT){
werase(wresult);
display_results();
}
if(window_change & CH_MODE){
werase(wmode);
display_mode();
}
@ -569,117 +569,12 @@ verswp_field(void){
window_change |= CH_INPUT | CH_MODE;
}
/*ARGSUSED*/
static void
jumpback(int sig)
{
signal(sig, jumpback);
siglongjmp(env, 1);
}
bool
search(void)
{
char *findresult = NULL; /* find function output */
bool funcexist = true; /* find "function" error */
FINDINIT rc = falseERROR; /* findinit return code */
sighandler_t savesig; /* old value of signal */
FP f; /* searching function */
int c;
/* open the references found file for writing */
if (writerefsfound() == false) {
return(false);
}
/* find the pattern - stop on an interrupt */
if (linemode == false) {
postmsg("Searching");
}
searchcount = 0;
savesig = signal(SIGINT, jumpback);
if (sigsetjmp(env, 1) == 0) {
f = fields[field].findfcn;
if (f == findregexp || f == findstring) {
findresult = (*f)(input_line);
} else {
if ((nonglobalrefs = myfopen(temp2, "wb")) == NULL) {
cannotopen(temp2);
return(false);
}
if ((rc = findinit(input_line)) == falseERROR) {
(void) dbseek(0L); /* read the first block */
findresult = (*f)(input_line);
if (f == findcalledby)
funcexist = (*findresult == 'y');
findcleanup();
/* append the non-global references */
(void) fclose(nonglobalrefs);
if ((nonglobalrefs = myfopen(temp2, "rb"))
== NULL) {
cannotopen(temp2);
return(false);
}
while ((c = getc(nonglobalrefs)) != EOF) {
(void) putc(c, refsfound);
}
}
(void) fclose(nonglobalrefs);
}
}
signal(SIGINT, savesig);
/* rewind the cross-reference file */
(void) lseek(symrefs, (long) 0, 0);
/* reopen the references found file for reading */
(void) fclose(refsfound);
if ((refsfound = myfopen(temp1, "rb")) == NULL) {
cannotopen(temp1);
return(false);
}
nextline = 1;
totallines = 0;
disprefs = 0;
/* see if it is empty */
if ((c = getc(refsfound)) == EOF) {
if (findresult != NULL) {
(void) snprintf(lastmsg, sizeof(lastmsg), "Egrep %s in this pattern: %s",
findresult, input_line);
} else if (rc == falseTSYMBOL) {
(void) snprintf(lastmsg, sizeof(lastmsg), "This is not a C symbol: %s",
input_line);
} else if (rc == REGCMPERROR) {
(void) snprintf(lastmsg, sizeof(lastmsg), "Error in this regcomp(3) regular expression: %s",
input_line);
} else if (funcexist == false) {
(void) snprintf(lastmsg, sizeof(lastmsg), "Function definition does not exist: %s",
input_line);
} else {
(void) snprintf(lastmsg, sizeof(lastmsg), "Could not find the %s: %s",
fields[field].text2, input_line);
}
return(false);
}
/* put back the character read */
(void) ungetc(c, refsfound);
countrefs();
window_change |= CH_RESULT;
return(true);
}
/* display search progress with default custom format */
void
progress(char *what, long current, long max)
{
static long start;
long now;
char msg[MSGLEN + 1];
int i;
/* save the start time */
@ -690,26 +585,26 @@ progress(char *what, long current, long max)
{
if (linemode == false)
{
wmove(wresult, MSGLINE, 0);
wmove(wresult, MSGLINE, MSGCOL);
wclrtoeol(wresult);
waddstr(wresult, what);
snprintf(msg, sizeof(msg), "%ld", current);
wmove(wresult, MSGLINE, (COLS / 2) - (strlen(msg) / 2));
waddstr(wresult, msg);
snprintf(msg, sizeof(msg), "%ld", max);
wmove(wresult, MSGLINE, COLS - strlen(msg));
waddstr(wresult, msg);
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(msg, sizeof(msg), "> %s %ld of %ld", what, current, max);
snprintf(lastmsg, sizeof(lastmsg), "> %s %ld of %ld", what, current, max);
}
start = now;
if ((linemode == false) && (incurses == true))
{
wmove(wresult, MSGLINE, 0);
wmove(wresult, MSGLINE, MSGCOL);
i = (float)COLS * (float)current / (float)max;
standout();
@ -719,8 +614,9 @@ progress(char *what, long current, long max)
refresh();
}
else
if (linemode == false || verbosemode == true)
postmsg(msg);
if(linemode == false || verbosemode == true){
postmsg(lastmsg);
}
}
++searchcount;
}
@ -729,13 +625,12 @@ progress(char *what, long current, long max)
void
myperror(char *text)
{
char msg[MSGLEN + 1]; /* message */
char *s;
s = strerror(errno);
(void) snprintf(msg, sizeof(msg), "%s: %s", text, s);
postmsg(msg);
(void) snprintf(lastmsg, sizeof(lastmsg), "%s: %s", text, s);
postmsg(lastmsg);
}
/* postmsg clears the message line and prints the message */
@ -744,24 +639,13 @@ void
postmsg(char *msg)
{
if (linemode == true || incurses == false) {
(void) printf("%s\n", msg);
printf("%s\n", msg);
fflush(stdout);
}
else {
clearmsg();
waddstr(wresult, msg);
wrefresh(wresult);
window_change |= CH_RESULT;
}
(void) strncpy(lastmsg, msg, sizeof(lastmsg) - 1);
}
/* clearmsg clears the first message line */
void
clearmsg(void)
{
wmove(wresult, MSGLINE, 0);
wclrtoeol(wresult);
UNUSED(strncpy(lastmsg, msg, sizeof(lastmsg) - 1));
}
/* clearmsg2 clears the second message line */
@ -855,41 +739,3 @@ ogsnames(char *file, char **subsystem, char **book)
s = slash + 1;
}
}
/* get the requested path components */
char *
pathcomponents(char *path, int components)
{
int i;
char *s;
s = path + strlen(path) - 1;
for (i = 0; i < components; ++i) {
while (s > path && *--s != '/') {
;
}
}
if (s > path && *s == '/') {
++s;
}
return(s);
}
/* open the references found file for writing */
bool
writerefsfound(void)
{
if (refsfound == NULL) {
if ((refsfound = myfopen(temp1, "wb")) == NULL) {
cannotopen(temp1);
return(false);
}
} else {
(void) fclose(refsfound);
if ( (refsfound = myfopen(temp1, "wb")) == NULL) {
postmsg("Cannot reopen temporary file");
return(false);
}
}
return(true);
}

View File

@ -41,12 +41,9 @@
#include "scanner.h" /* for token definitions */
#include <assert.h>
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
#else
#include <curses.h>
#endif
#include <regex.h>
#include <setjmp.h> /* jmp_buf */
/* most of these functions have been optimized so their innermost loops have
* only one test for the desired character by putting the char and
@ -83,15 +80,49 @@ static void putpostingref(POSTING *p, char *pat);
static void putref(int seemore, char *file, char *func);
static void putsource(int seemore, FILE *output);
/* find the symbol in the cross-reference */
static sigjmp_buf env; /* setjmp/longjmp buffer */
typedef char * (*FP)(char *); /* pointer to function returning a character pointer */
/* Paralel array to "fields", indexed by "field" */
FP field_searchers[FIELDS + 1] = {
findsymbol,
finddef,
findcalledby,
findcalling,
findstring,
findstring,
findregexp,
findfile,
findinclude,
findassign,
findallfcns /* samuel only */
};
/**/
struct TI {
char *text1;
char *text2;
};
extern struct TI fields[FIELDS + 1];
/* Internal prototypes: */
static void jumpback(int sig);
static void
jumpback(int sig)
{
signal(sig, jumpback);
siglongjmp(env, 1);
}
/* find the symbol in the cross-reference */
char *
findsymbol(char *pattern)
{
return find_symbol_or_assignment(pattern, false);
}
/* find the symbol in the cross-reference, and look for assignments */
/* find the symbol in the cross-reference, and look for assignments */
char *
findassign(char *pattern)
{
@ -1299,3 +1330,121 @@ findcalledbysub(char *file, bool macro)
}
}
}
/* open the references found file for writing */
bool
writerefsfound(void)
{
if (refsfound == NULL) {
if ((refsfound = myfopen(temp1, "wb")) == NULL) {
cannotopen(temp1);
return(false);
}
} else {
(void) fclose(refsfound);
if ( (refsfound = myfopen(temp1, "wb")) == NULL) {
postmsg("Cannot reopen temporary file");
return(false);
}
}
return(true);
}
/* Perform token search based on "field" */
bool
search(void)
{
char msg[MSGLEN+1];
char *findresult = NULL; /* find function output */
bool funcexist = true; /* find "function" error */
FINDINIT rc = falseERROR; /* findinit return code */
sighandler_t savesig; /* old value of signal */
FP f; /* searching function */
int c;
/* open the references found file for writing */
if (writerefsfound() == false) {
return(false);
}
/* find the pattern - stop on an interrupt */
if (linemode == false) {
postmsg("Searching");
}
searchcount = 0;
savesig = signal(SIGINT, jumpback);
if (sigsetjmp(env, 1) == 0) {
f = field_searchers[field];
if (f == findregexp || f == findstring) {
findresult = (*f)(input_line);
} else {
if ((nonglobalrefs = myfopen(temp2, "wb")) == NULL) {
cannotopen(temp2);
return(false);
}
if ((rc = findinit(input_line)) == falseERROR) {
(void) dbseek(0L); /* read the first block */
findresult = (*f)(input_line);
if (f == findcalledby)
funcexist = (*findresult == 'y');
findcleanup();
/* append the non-global references */
(void) fclose(nonglobalrefs);
if ((nonglobalrefs = myfopen(temp2, "rb"))
== NULL) {
cannotopen(temp2);
return(false);
}
while ((c = getc(nonglobalrefs)) != EOF) {
(void) putc(c, refsfound);
}
}
(void) fclose(nonglobalrefs);
}
}
signal(SIGINT, savesig);
/* rewind the cross-reference file */
(void) lseek(symrefs, (long) 0, 0);
/* reopen the references found file for reading */
(void) fclose(refsfound);
if ((refsfound = myfopen(temp1, "rb")) == NULL) {
cannotopen(temp1);
return(false);
}
nextline = 1;
totallines = 0;
disprefs = 0;
/* see if it is empty */
if ((c = getc(refsfound)) == EOF) {
if (findresult != NULL) {
(void) snprintf(msg, sizeof(msg), "Egrep %s in this pattern: %s",
findresult, input_line);
} else if (rc == falseTSYMBOL) {
(void) snprintf(msg, sizeof(msg), "This is not a C symbol: %s",
input_line);
} else if (rc == REGCMPERROR) {
(void) snprintf(msg, sizeof(msg), "Error in this regcomp(3) regular expression: %s",
input_line);
} else if (funcexist == false) {
(void) snprintf(msg, sizeof(msg), "Function definition does not exist: %s",
input_line);
} else {
(void) snprintf(msg, sizeof(msg), "Could not find the %s: %s",
fields[field].text2, input_line);
}
postmsg(msg);
return(false);
}
/* put back the character read */
(void) ungetc(c, refsfound);
countrefs();
window_change |= CH_RESULT;
return(true);
}

View File

@ -38,6 +38,8 @@
#ifndef CSCOPE_GLOBAL_H
#define CSCOPE_GLOBAL_H
#define UNUSED(x) (void)(x)
//#include "config.h"
#include <unistd.h>
#include <sys/types.h>
@ -246,6 +248,7 @@ void horswp_field(void);
bool interpret(int c); // XXX: probably rename
int handle_input(const int c);
int dispchar2int(const char c);
int process_mouse();
long seekpage(size_t i);
long seekrelline(unsigned i);

View File

@ -59,6 +59,8 @@ static void catchint(int sig);
static void
catchint(int sig)
{
UNUSED(sig);
signal(SIGINT, catchint);
longjmp(env, 1);
}

View File

@ -45,9 +45,13 @@
# define KEY_RESIZE KEY_UNDEF_BASE-11
#endif
/* Always define ESC */
/* Always define these keys */
#ifndef ESC
# define ESC '\033' /* escape character */
#endif
#ifndef DEL
# define DEL '\177' /* delete character */
#endif
#endif /* KEYS_H*/

View File

@ -112,6 +112,10 @@ static inline void screenmode_event_loop(void);
void
sigwinch_handler(int sig, siginfo_t *info, void *unused)
{
UNUSED(sig);
UNUSED(info);
UNUSED(unused);
if(incurses == true){
ungetch(KEY_RESIZE);
}
@ -438,7 +442,7 @@ main(int argc, char **argv)
if (linemode == false) {
dispinit(); /* initialize display parameters */
clearmsg(); /* clear any build progress message */
postmsg(""); /* clear any build progress message */
display(); /* display the version number and input fields */
}
@ -604,7 +608,7 @@ main(int argc, char **argv)
}
build();
if (linemode == false ) {
clearmsg(); /* clear any build progress message */
postmsg(""); /* clear any build progress message */
}
if (buildonly == true) {
myexit(0);

View File

@ -35,6 +35,10 @@
* mouse functions
*/
extern int LINES;
#define FLDLINE (LINES - FIELDS - 1 - 1) /* first input field line */
#include "global.h"
bool mouse = false; /* mouse interface */
@ -429,3 +433,43 @@ getpercent(void)
}
return(c - 16);
}
int process_mouse(){
int i;
MOUSE* p;
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
return(false); /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
//scrollbar(p); // XXX
return(false);
}
/* ignore a sweep */
if (p->x2 >= 0) {
return(false);
}
/* if this is a line selection */
if (p->y1 > FLDLINE) {
/* find the selected line */
/* note: the selection is forced into range */
for (i = disprefs - 1; i > 0; --i) {
if (p->y1 >= displine[i]) {
return(false);
}
}
/* display it in the file with the editor */
editref(i);
} else { /* this is an input field selection */
field = p->y1 - FLDLINE;
/* force it into range */
if (field >= FIELDS) {
field = FIELDS - 1;
}
resetcmd();
return(false);
}
return false;
}

View File

@ -4,23 +4,21 @@
#include "build.h"
#include <ncurses.h>
extern int LINES; // XXX
static int input_available = 0;
static char input_char;
char input_line[PATLEN + 1];
bool do_terminate = false;
bool interpret(int c){
input_char = c;
input_available = 1;
rl_callback_read_char();
return do_terminate;
return 0;
}
static int getc_function(FILE* ignore){
UNUSED(ignore);
input_available = 0;
return (int)input_char;
}
@ -37,18 +35,15 @@ static void callback_handler(char* line){
if(!line){ return; }
strncpy(input_line, line, PATLEN);
search();
if(!search()){
}
curdispline = 0;
PCS_reset();
current_page = 0;
}
static int interpret_break(){
do_terminate = true;
return 0;
}
static int ctrl_z(){
kill(0, SIGTSTP);
return 0;
@ -80,53 +75,13 @@ static int rebuild_reference(){
askforreturn();
}
entercurses();
clearmsg(); /* clear any previous message */
postmsg(""); /* clear any previous message */
totallines = 0;
disprefs = 0;
topline = nextline = 1;
return(true);
}
static int process_mouse(){
int i;
MOUSE* p;
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
return(false); /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
//scrollbar(p); // XXX
return(false);
}
/* ignore a sweep */
if (p->x2 >= 0) {
return(false);
}
/* if this is a line selection */
if (p->y1 > FLDLINE) {
/* find the selected line */
/* note: the selection is forced into range */
for (i = disprefs - 1; i > 0; --i) {
if (p->y1 >= displine[i]) {
return(false);
}
}
/* display it in the file with the editor */
editref(i);
} else { /* this is an input field selection */
field = p->y1 - FLDLINE;
/* force it into range */
if (field >= FIELDS) {
field = FIELDS - 1;
}
resetcmd();
return(false);
}
return false;
}
void rlinit(){
rl_catch_signals = 0;
rl_catch_sigwinch = 0;