From a7331159b8e928928742d3381f29a0e5c24232a6 Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 8 Aug 2023 20:34:15 +0200 Subject: [PATCH] . --- Makefile | 21 +++++++++++---------- README.md | 15 ++++++++++++++- src/constants.h | 44 -------------------------------------------- src/display.c | 9 ++++++--- src/global.h | 2 +- src/input.c | 10 ++++------ src/keys.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 2 +- src/readline.c | 5 +++++ src/refsfound.c | 1 + 10 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 src/keys.h diff --git a/Makefile b/Makefile index d8f1935..747f5b1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ DEBUG:=1 +GCC:=0 CC=gcc CFLAGS:=-Wall -Wextra -Wpedantic @@ -6,6 +7,16 @@ CPPFLAGS:=${shell pkg-config --cflags ncurses readline} LDLIBS=-I ${CHDRD} ${shell pkg-config --libs ncurses readline} LEX:=flex +ifeq (${DEBUG},1) + CFLAGS += -O0 -ggdb +else + CFLAGS += -O3 -flto=auto -fomit-frame-pointer +endif + +ifdef SAN + CFLAGS += -fsanitize=${SAN} +endif + LEXD:=src/ LEXF:=$(shell find ${LEXD} -iname '*.l') GENLEX:=$(subst .l,.c,${LEXF}) @@ -22,16 +33,6 @@ CHDR:=$(addsuffix .gch,$(subst ${HDRD},${CHDRD},${HDR})) OUTPUT:=csope -ifeq (${DEBUG},1) - CFLAGS += -O0 -ggdb -else - CFLAGS += -O3 -flto=auto -fomit-frame-pointer -endif - -ifdef SAN - CFLAGS += -fsanitize=${SAN} -endif - main: ${CHDR} ${OBJ} ${LINK.c} ${OBJ} -o ${OUTPUT} ${LDLIBS} diff --git a/README.md b/README.md index 1cbfbf6..cdcd5dc 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no + GNU Readline integration (ie. VI/EMACS mode, command history) /*pending*/ ## To the code + nuked autoconf, replaced with single Makefile -+ removed "scanner.l" which seems to be an anchient version (and redundant copy) of "fscanner.l" forgotten by all ++ reorganized main() + encapsulated changes to the TUI into display.c ++ removed "scanner.l" which seems to be an anchient version (and redundant copy) of "fscanner.l" forgotten by all + 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 @@ -66,6 +67,18 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no + 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 +## Original ++ Display the current case mode (^C) onscreen ++ emacs like key bindings + ^S for searching (^Y) + Up/dwn Arrow support Next/Prev field. ?? + Inline editing on Input fields ( ??^B/^F ) + ^X^C to quit ( ^Q ??) + Pagdwn/PageUp/+/- ++ Same capabilities as interactive in non interactive (one shot) mode ++ Provide some how-do-I-use-this-thing doc. ++ Replace invlib.[ch] by real database. Failing that, at least sanitize it. + # BUGS + Changing text double frees: diff --git a/src/constants.h b/src/constants.h index 28e5253..c214625 100644 --- a/src/constants.h +++ b/src/constants.h @@ -57,9 +57,6 @@ this macro will always be in a statement by itself */ #define skiprefchar() if (*(++blockp + 1) == '\0') (void) read_block() -#ifndef ESC -# define ESC '\033' /* escape character */ -#endif #define DEL '\177' /* delete character */ #define DUMMYCHAR ' ' /* use space as a dummy character */ #define MSGLEN ((PATLEN) + 80) /* displayed message length */ @@ -115,46 +112,5 @@ #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 -#ifndef KEY_RESIZE -# define KEY_RESIZE KEY_UNDEF_BASE-11 -#endif #endif /* CSCOPE_CONSTANTS_H */ diff --git a/src/display.c b/src/display.c index 282d795..3d178b2 100644 --- a/src/display.c +++ b/src/display.c @@ -284,8 +284,6 @@ static inline void display_results(){ char function[PATLEN + 1]; /* function name */ char linenum[NUMLEN + 1]; /* line number */ - werase(wresult); - if (totallines == 0) { /* if no references were found */ /* redisplay the last message */ @@ -337,7 +335,11 @@ static inline void display_results(){ srctxtw -= numlen+1; /* decide where to list from */ - fseek(refsfound, seekpage(current_page), SEEK_SET); + /* XXX: this error handling migth be redundant*/ + int seekerr; + do{ + seekerr = seekpage(current_page); + }while(seekerr == -1 && current_page--); /* until the max references have been displayed or there is no more room */ @@ -510,6 +512,7 @@ display(void) if(window_change){ if(window_change == CH_HELP){ + werase(whelp); display_help(); /* Do not display over the help msg and */ /* rely on display_help() setting CH_ALL */ diff --git a/src/global.h b/src/global.h index fa757a6..3e18a6f 100644 --- a/src/global.h +++ b/src/global.h @@ -244,7 +244,7 @@ extern int current_page; void verswp_field(void); void horswp_field(void); bool interpret(int c); // XXX: probably rename -int handle_input(const char c); +int handle_input(const int c); int dispchar2int(const char c); long seekpage(size_t i); diff --git a/src/input.c b/src/input.c index 621d060..56b4e2a 100644 --- a/src/input.c +++ b/src/input.c @@ -36,18 +36,16 @@ */ #include "global.h" -#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES) #include -#else -#include -#endif #include /* jmp_buf */ #include #include #if HAVE_SYS_TERMIOS_H -#include +# include #endif +#include "keys.h" + bool do_press_any_key = false; static jmp_buf env; /* setjmp/longjmp buffer */ @@ -536,7 +534,7 @@ extern const void const* wresult; extern const void const* const* current_window; int -handle_input(const char c){ +handle_input(const int c){ /* - was wating for any input - */ if(do_press_any_key){ do_press_any_key = false; diff --git a/src/keys.h b/src/keys.h new file mode 100644 index 0000000..cfbb28d --- /dev/null +++ b/src/keys.h @@ -0,0 +1,53 @@ +#ifndef KEYS_H +#define KEYS_H + +/* 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. + */ +#define KEY_UNDEF_BASE 0 + +#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 +#ifndef KEY_RESIZE +# define KEY_RESIZE KEY_UNDEF_BASE-11 +#endif + +/* Always define ESC */ +#ifndef ESC +# define ESC '\033' /* escape character */ +#endif + +#endif /* KEYS_H*/ diff --git a/src/main.c b/src/main.c index cc8d669..151bf3c 100644 --- a/src/main.c +++ b/src/main.c @@ -356,7 +356,7 @@ static inline void linemode_event_loop(void){ static inline void screenmode_event_loop(void){ for (;;) { display(); - handle_input(getch()); + handle_input(wgetch(stdscr)); // NOTE: getch() does not return key codes } } diff --git a/src/readline.c b/src/readline.c index fd498d2..b08fa05 100644 --- a/src/readline.c +++ b/src/readline.c @@ -36,7 +36,12 @@ static void redisplay_function(){ static void callback_handler(char* line){ if(!line){ return; } strncpy(input_line, line, PATLEN); + search(); + + curdispline = 0; + PCS_reset(); + current_page = 0; } static int interpret_break(){ diff --git a/src/refsfound.c b/src/refsfound.c index f4123eb..cc5ddee 100644 --- a/src/refsfound.c +++ b/src/refsfound.c @@ -18,6 +18,7 @@ long seekpage(size_t i){ while(PCS_top < i){ const char c = getc(*hto_page); if(c == '\n'){ ++lc; } + if(c == EOF){ return -1; } if(lc == mdisprefs){ PCS_pos[++PCS_top] = ftell(*hto_page); }