瀏覽代碼

bah

agvxov
anon 10 月之前
父節點
當前提交
6fd36549f4
共有 12 個文件被更改,包括 169 次插入179 次删除
  1. +13
    -0
      .gdb_history
  2. +4
    -2
      Makefile
  3. +11
    -11
      README.md
  4. +19
    -6
      src/display.c
  5. +1
    -1
      src/edit.c
  6. +1
    -5
      src/exec.c
  7. +6
    -5
      src/global.h
  8. +79
    -92
      src/help.c
  9. +11
    -39
      src/input.c
  10. +7
    -4
      src/main.c
  11. +13
    -13
      src/mouse.c
  12. +4
    -1
      src/readline.c

+ 13
- 0
.gdb_history 查看文件

@@ -15,3 +15,16 @@ r
help handle
handle SIGINT stop
r
info signal-dispositions
s
start
info signal-dispositions
c
where
s
where
frame 0
l
b rl_complete
c
where

+ 4
- 2
Makefile 查看文件

@@ -1,4 +1,6 @@
# CC=gcc
DEBUG:=1

CC=gcc
CFLAGS:=-Wall -Wextra -Wpedantic
CPPFLAGS:=${shell pkg-config --cflags ncurses readline}
LDLIBS=-I ${CHDRD} ${shell pkg-config --libs ncurses readline}
@@ -21,7 +23,7 @@ CHDR:=$(addsuffix .gch,$(subst ${HDRD},${CHDRD},${HDR}))
OUTPUT:=csope

ifeq (${DEBUG},1)
CFLAGS += -Og -ggdb
CFLAGS += -O0 -ggdb
else
CFLAGS += -O3 -flto=auto -fomit-frame-pointer
endif


+ 11
- 11
README.md 查看文件

@@ -16,14 +16,14 @@ Fork of Cscope, with various improvements, because cscope is good and shall not

# Interface
<-- Tab -->
+------------Message-------------+ +--------------------------------+
A |+--------------+---------------+| |+------------------------------+|
| || Input Window | Result window || || ||
| |+--------------+ || ? || ||
|| Mode Window | || ---> || Help ||
% || | || <--- || ||
|| | || ESC || ||
| || | || || ||
| || | || || ||
V |+--------------+---------------+| |+------------------------------+|
+-----------Tool Tips------------+ +--------------------------------+
+------------Message-------------+ +--------------------------------+
A |+--------------+---------------+| |+------------------------------+|
| || Input Window | Result window || || ||
| |+--------------+ || ? || ||
|| Mode Window | || ----> || Help ||
% || | || <---- || ||
|| | || ... || ||
| || | || || ||
| || | || || ||
V |+--------------+---------------+| |+------------------------------+|
+-----------Tool Tips------------+ +--------------------------------+

+ 19
- 6
src/display.c 查看文件

@@ -80,6 +80,7 @@ unsigned int curdispline = 0;
WINDOW* winput;
WINDOW* wmode;
WINDOW* wresult;
WINDOW* whelp;
WINDOW** current_window;
static WINDOW** last_window;

@@ -132,11 +133,6 @@ dispinit(void)
/* initialize the curses display package */
initscr(); /* initialize the screen */
entercurses();
keypad(stdscr, TRUE); /* enable the keypad */
//fixkeypad(); /* fix for getch() intermittently returning garbage */
standend(); /* turn off reverse video */
curs_set(0);
noecho();

/* Calculate section sizes */
result_window_height = LINES - 2;
@@ -164,11 +160,21 @@ dispinit(void)
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);
refresh();

current_window = &winput;
}

static inline void display_help(){
werase(whelp);
wmove(whelp, 0, 0);
waddstr(whelp, help());
wrefresh(whelp);
do_press_any_key = true;
window_change = CH_ALL;
}

static inline void display_frame(){
box(stdscr, 0, 0);
/* Vertical line */
@@ -452,6 +458,13 @@ display(void)
//drawscrollbar(topline, nextline); /* display the scrollbar */

if(window_change){
if(window_change == CH_HELP){
display_help();
/* Do not display over the help msg and */
/* rely on display_help() setting CH_ALL */
return;
}
/**/
if(window_change == CH_ALL){
display_frame();
}
@@ -476,7 +489,7 @@ display(void)
wrefresh(wresult);
}

window_change = CH_falseNE;
window_change = CH_NONE;
}

void


+ 1
- 1
src/edit.c 查看文件

@@ -85,7 +85,7 @@ editall(void)
edit(file, linenum); /* edit it */
if (editallprompt == true) {
addstr("Type ^D to stop editing all lines, or any other character to continue: ");
if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
if ((c = getch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
break;
}
}


+ 1
- 5
src/exec.c 查看文件

@@ -43,11 +43,7 @@
#ifdef __DJGPP__
#include <process.h>
#endif
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
#else
#include <curses.h>
#endif

static sighandler_t oldsigquit; /* old value of quit signal */
static sighandler_t oldsighup; /* old value of hangup signal */
@@ -97,7 +93,7 @@ execute(char *a, ...) /* note: "exec" is already defined on u370 */
# ifndef __DJGPP__ /* leave CRLF handling as is */
nonl();
# endif
raw(); /* endwin() turns off cbreak mode so restore it */
cbreak(); /* endwin() turns off cbreak mode so restore it */
noecho();
#endif
mousemenu();


+ 6
- 5
src/global.h 查看文件

@@ -82,10 +82,11 @@ struct cmd { /* command history struct */
};

enum {
CH_falseNE = 0x0000,
CH_NONE = 0x0000,
CH_RESULT = 0x0001 << 0,
CH_INPUT = 0x0001 << 1,
CH_MODE = 0x0001 << 2,
CH_HELP = 0x0001 << 3, /* do NOT add to CH_ALL */
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
};

@@ -235,8 +236,9 @@ void error_usage(void);
void longusage(void);
void usage(void);
extern bool remove_symfile_onexit;
extern bool onesearch; /* one search only in line mode */
extern char *reflines; /* symbol reference lines file */
extern bool onesearch; /* one search only in line mode */
extern char *reflines; /* symbol reference lines file */
extern bool do_press_any_key; /* wait for any key to continue */
void verswp_field(void);
void horswp_field(void);
bool interpret(int c); // XXX: probably rename
@@ -267,7 +269,7 @@ void freesrclist(void);
void freeinclist(void);
void freecrossref(void);
void freefilelist(void);
void help(void);
const char* help(void);
void incfile(char *file, char *type);
void includedir(char *_dirname);
void initsymtab(void);
@@ -308,7 +310,6 @@ struct cmd *nextcmd(void);

int egrep(char *file, FILE *output, char *format);
int mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless);
int mygetch(void);
int hash(char *ss);
int execute(char *a, ...);
long dbseek(long offset);


+ 79
- 92
src/help.c 查看文件

@@ -48,104 +48,91 @@
*/
#define MAXHELP 50 /* maximum number of help strings */

void
static char help_msg[] =
"Press the RETURN key repeatedly to move to the desired input field, type the\n"
"pattern to search for, and then press the RETURN key. For the first 4 and\n"
"last 2 input fields, the pattern can be a regcomp(3) regular expression.\n"
"If the search is successful, you can use these single-character commands:\n\n"
"0-9a-zA-Z\tEdit the file containing the displayed line.\n"
"space bar\tDisplay next set of matching lines.\n"
"+\t\tDisplay next set of matching lines.\n"
"^V\t\tDisplay next set of matching lines.\n"
"-\t\tDisplay previous set of matching lines.\n"
"^E\t\tEdit all lines.\n"
">\t\tWrite the list of lines being displayed to a file.\n"
">>\t\tAppend the list of lines being displayed to a file.\n"
"<\t\tRead lines from a file.\n"
"^\t\tFilter all lines through a shell command.\n"
"|\t\tPipe all lines to a shell command.\n"
"\nAt any time you can use these single-character commands:\n\n"
"TAB\t\tSwap positions between input and output areas.\n"
"RETURN\t\tMove to the next input field.\n"
"^N\t\tMove to the next input field.\n"
"^P\t\tMove to the previous input field.\n"
"^Y / ^A\t\tSearch with the last pattern typed.\n"
"^B\t\tRecall previous input field and search pattern.\n"
"^F\t\tRecall next input field and search pattern.\n"
"^C\t\tToggle ignore/use letter case when searching.\n"
"^R\t\tRebuild the cross-reference.\n"
"!\t\tStart an interactive shell (type ^D to return to cscope).\n"
"^L\t\tRedraw the screen.\n"
"?\t\tDisplay this list of commands.\n"
"^D\t\tExit cscope.\n"
"\nNote: If the first character of the pattern you want to search for matches\n"
"a command, type a \\ character first.\n"
"Note: Some ctrl keys may be occupied by your terminal configuration.\n"
;

static char changeing_help_msg[] =
"When changing text, you can use these single-character commands:\n\n"
"0-9a-zA-Z\tMark or unmark the line to be changed.\n"
"*\t\tMark or unmark all displayed lines to be changed.\n"
"space bar\tDisplay next set of lines.\n"
"+\t\tDisplay next set of lines.\n"
"-\t\tDisplay previous set of lines.\n"
"^A\t\tMark or unmark all lines to be changed.\n"
"^D\t\tChange the marked lines and exit.\n"
"ESC\t\tExit without changing the marked lines.\n"
"!\t\tStart an interactive shell (type ^D to return to cscope).\n"
"^L\t\tRedraw the screen.\n"
"?\t\tDisplay this list of commands.\n"
;

const char*
help(void)
{
char **ep, *s, **tp, *text[MAXHELP];
int ln;
//char **ep, *s, **tp, *text[MAXHELP];
//int ln;

tp = text;
//tp = text;
if (changing == false) {
if (mouse) {
*tp++ = "Point with the mouse and click button 1 to move to the desired input field,\n";
*tp++ = "type the pattern to search for, and then press the RETURN key. For the first 4\n";
*tp++ = "and last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
*tp++ = "If the search is successful, you can edit the file containing a displayed line\n";
*tp++ = "by pointing with the mouse and clicking button 1.\n";
*tp++ = "\nYou can either use the button 2 menu or these single-character commands:\n\n";
} else {
*tp++ = "Press the RETURN key repeatedly to move to the desired input field, type the\n";
*tp++ = "pattern to search for, and then press the RETURN key. For the first 4 and\n";
*tp++ = "last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
*tp++ = "If the search is successful, you can use these single-character commands:\n\n";
*tp++ = "0-9a-zA-Z\tEdit the file containing the displayed line.\n";
}
*tp++ = "space bar\tDisplay next set of matching lines.\n";
*tp++ = "+\t\tDisplay next set of matching lines.\n";
*tp++ = "^V\t\tDisplay next set of matching lines.\n";
*tp++ = "-\t\tDisplay previous set of matching lines.\n";
*tp++ = "^E\t\tEdit all lines.\n";
*tp++ = ">\t\tWrite the list of lines being displayed to a file.\n";
*tp++ = ">>\t\tAppend the list of lines being displayed to a file.\n";
*tp++ = "<\t\tRead lines from a file.\n";
*tp++ = "^\t\tFilter all lines through a shell command.\n";
*tp++ = "|\t\tPipe all lines to a shell command.\n";
if (!mouse) {
*tp++ = "\nAt any time you can use these single-character commands:\n\n";
*tp++ = "TAB\t\tSwap positions between input and output areas.\n";
*tp++ = "RETURN\t\tMove to the next input field.\n";
*tp++ = "^N\t\tMove to the next input field.\n";
*tp++ = "^P\t\tMove to the previous input field.\n";
}
*tp++ = "^Y / ^A\t\tSearch with the last pattern typed.\n";
*tp++ = "^B\t\tRecall previous input field and search pattern.\n";
*tp++ = "^F\t\tRecall next input field and search pattern.\n";
if(caseless)
*tp++ = "^C\t\tToggle ignore/use letter case when searching (IGfalseRE).\n";
else
*tp++ = "^C\t\tToggle ignore/use letter case when searching (USE).\n";
*tp++ = "^R\t\tRebuild the cross-reference.\n";
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
*tp++ = "^L\t\tRedraw the screen.\n";
*tp++ = "?\t\tDisplay this list of commands.\n";
*tp++ = "^D\t\tExit cscope.\n";
*tp++ = "\nNote: If the first character of the pattern you want to search for matches\n";
*tp++ = "a command, type a \\ character first.\n";
*tp++ = "Note: Some ctrl keys may be occupied by your terminal configuration.\n";
return help_msg;
} else {
if (mouse) {
*tp++ = "Point with the mouse and click button 1 to mark or unmark the line to be\n";
*tp++ = "changed. You can also use the button 2 menu or these single-character\n";
*tp++ = "commands:\n\n";
}
else {
*tp++ = "When changing text, you can use these single-character commands:\n\n";
*tp++ = "0-9a-zA-Z\tMark or unmark the line to be changed.\n";
}
*tp++ = "*\t\tMark or unmark all displayed lines to be changed.\n";
*tp++ = "space bar\tDisplay next set of lines.\n";
*tp++ = "+\t\tDisplay next set of lines.\n";
*tp++ = "-\t\tDisplay previous set of lines.\n";
*tp++ = "^A\t\tMark or unmark all lines to be changed.\n";
*tp++ = "^D\t\tChange the marked lines and exit.\n";
*tp++ = "ESC\t\tExit without changing the marked lines.\n";
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
*tp++ = "^L\t\tRedraw the screen.\n";
*tp++ = "?\t\tDisplay this list of commands.\n";
}
/* print help, a screen at a time */
ep = tp;
ln = 0;
for (tp = text; tp < ep; ) {
if (ln < LINES - 1) {
for (s = *tp; *s != '\0'; ++s) {
if (*s == '\n') {
++ln;
}
}
(void) addstr(*tp++);
}
else {
(void) addstr("\n");
askforchar();
(void) clear();
ln = 0;
}
}
if (ln) {
(void) addstr("\n");
askforchar();
return changeing_help_msg;
}
///* print help, a screen at a time */
//ep = tp;
//ln = 0;
//for (tp = text; tp < ep; ) {
// if (ln < LINES - 1) {
// for (s = *tp; *s != '\0'; ++s) {
// if (*s == '\n') {
// ++ln;
// }
// }
// (void) addstr(*tp++);
// }
// else {
// (void) addstr("\n");
// askforchar();
// (void) clear();
// ln = 0;
// }
//}
//if (ln) {
// (void) addstr("\n");
// askforchar();
//}
}

/* error exit including short usage information */


+ 11
- 39
src/input.c 查看文件

@@ -48,6 +48,8 @@
#include <sys/termios.h>
#endif

bool do_press_any_key = false;

static jmp_buf env; /* setjmp/longjmp buffer */
static int prevchar; /* previous, ungotten character */

@@ -70,38 +72,6 @@ myungetch(int c)
prevchar = c;
}

/* get a character from the terminal */
int
mygetch(void)
{
sighandler_t savesig = 0; /* old value of signal */
int c;

/* change an interrupt signal to a break key character */
if (setjmp(env) == 0) {
savesig = signal(SIGINT, catchint);
refresh(); /* update the display */
mousereinit(); /* curses can change the menu number */
if(prevchar) {
c = prevchar;
prevchar = 0;
} else {
c = -1;
while (c == -1) {
/* get a character from the terminal */
c = getch();
if ((c == -1) && (errno != EINTR))
break;
}
}
} else { /* longjmp to here from signal handler */
c = KEY_BREAK;
}
signal(SIGINT, savesig);
return(c);
}


/* get a line from the terminal in non-canonical mode */
int
mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless)
@@ -133,7 +103,7 @@ mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless)
s[i++] = firstchar; /* save it */
}
/* until the end of the line is reached */
while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER) {
while ((c = getch()) != '\r' && c != '\n' && c != KEY_ENTER) {
if (c == KEY_LEFT || c == ctrl('B')) { /* left */
if (i > 0) {
addch('\b');
@@ -240,7 +210,7 @@ void
askforchar(void)
{
addstr("Type any character to continue: ");
mygetch();
getch();
}

/* ask user to press the RETURN key after reading the message */
@@ -462,7 +432,7 @@ global_input(const int c){
//move(PRLINE, 0);
////addstr("Write to file: "); // XXX
//s = "w";
//if ((ch = mygetch()) == '>') {
//if ((ch = getch()) == '>') {
//move(PRLINE, 0);
////addstr(appendprompt); // XXX fix
////ch = '\0';
@@ -554,10 +524,7 @@ global_input(const int c){
window_change = CH_ALL;
break;
case '?': /* help */
clear();
help();
clear();
seekline(topline);
window_change = CH_HELP;
break;
case ctrl('E'): /* edit all lines */
editall();
@@ -576,6 +543,11 @@ extern const void const* const* current_window;

int
handle_input(const char c){
/* - was wating for any input - */
if(do_press_any_key){
do_press_any_key = false;
return 0;
}
/* --- global --- */
const int r = global_input(c);
if(r){ return 0; }


+ 7
- 4
src/main.c 查看文件

@@ -215,14 +215,17 @@ void
entercurses(void)
{
incurses = true;
#ifndef __MSDOS__ /* HBB 20010313 */
nonl(); /* don't translate an output \n to \n\r */
#endif
raw(); /* single character input */

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 */
}




+ 13
- 13
src/mouse.c 查看文件

@@ -288,13 +288,13 @@ getmouseaction(char leading_char)
*/

/* Check for "[?" being next 2 chars */
if(((i = mygetch()) != '[') || ((i = mygetch()) != '?')) {
if(((i = getch()) != '[') || ((i = getch()) != '?')) {
myungetch(i);
return(NULL);
}

/* Grab the X position (in pixels) */
while(isdigit(i = mygetch())) {
while(isdigit(i = getch())) {
x = (x*10) + (i - '0');
}
if(i != ';') {
@@ -303,7 +303,7 @@ getmouseaction(char leading_char)
}

/* Grab the Y position (in pixels) */
while(isdigit(i = mygetch())) {
while(isdigit(i = getch())) {
y = (y*10) + (i - '0');
}
if(i != ';') {
@@ -312,23 +312,23 @@ getmouseaction(char leading_char)
}

/* Get which button */
if((button = mygetch()) > '4') {
if((button = getch()) > '4') {
myungetch(button);
return(NULL);
}
if((i = mygetch()) != ';') {
if((i = getch()) != ';') {
myungetch(i);
return(NULL);
}

/* Get the reason for this mouse report */
if((reason = mygetch()) > '8') {
if((reason = getch()) > '8') {
myungetch(reason);
return(NULL);
}

/* sequence should terminate with an 'M' */
if((i = mygetch()) != 'M') {
if((i = getch()) != 'M') {
myungetch(i);
return(NULL);
}
@@ -366,9 +366,9 @@ getmouseaction(char leading_char)

if (mouse == true && leading_char == ctrl('X')) {

switch (mygetch()) {
switch (getch()) {
case ctrl('_'): /* click */
if ((m.button = mygetch()) == '0') { /* if scrollbar */
if ((m.button = getch()) == '0') { /* if scrollbar */
m.percent = getpercent();
}
else {
@@ -379,7 +379,7 @@ getmouseaction(char leading_char)
break;

case ctrl(']'): /* sweep */
m.button = mygetch();
m.button = getch();
m.x1 = getcoordinate();
m.y1 = getcoordinate();
m.x2 = getcoordinate();
@@ -401,11 +401,11 @@ getcoordinate(void)
{
int c, next;

c = mygetch();
c = getch();
next = 0;
if (c == ctrl('A')) {
next = 95;
c = mygetch();
c = getch();
}
if (c < ' ') {
return (0);
@@ -420,7 +420,7 @@ getpercent(void)
{
int c;

c = mygetch();
c = getch();
if (c < 16) {
return(0);
}


+ 4
- 1
src/readline.c 查看文件

@@ -34,16 +34,19 @@ static void redisplay_function(){
}

static void callback_handler(char* line){
if(!line){ return; }
strncpy(input_line, line, PATLEN);
search();
}

static int interpret_break(){
do_terminate = true;
return 0;
}

static int ctrl_z(){
kill(0, SIGTSTP);
return 0;
}

static int toggle_caseless(){
@@ -55,6 +58,7 @@ static int toggle_caseless(){
postmsg2("Caseless mode is now OFF");
}
egrepcaseless(caseless); /* turn on/off -i flag */
return 0;
}

static int rebuild_reference(){
@@ -132,7 +136,6 @@ void rlinit(){
rl_bind_key(KEY_BACKSPACE, rl_rubout);

rl_bind_key(EOF, exit);
rl_bind_key(ctrl('D'), interpret_break); //XXX: why the fuck does it not work if its the first char?
rl_bind_key(ctrl('Z'), ctrl_z);
rl_bind_key(ctrl('Z'), toggle_caseless);
rl_bind_key(ctrl('R'), rebuild_reference);


Loading…
取消
儲存