anon pirms 9 mēnešiem
vecāks
revīzija
00e707993c
6 mainītis faili ar 203 papildinājumiem un 69 dzēšanām
  1. +11
    -15
      Makefile
  2. +92
    -0
      config/colors.h
  3. +85
    -34
      src/display.c
  4. +2
    -2
      src/edit.c
  5. +11
    -13
      src/global.h
  6. +2
    -5
      src/main.c

+ 11
- 15
Makefile Parādīt failu

@@ -1,22 +1,14 @@
DEBUG:=1
GCC:=0

CC=gcc
CC:=gcc
CFLAGS:=-Wall -Wextra -Wpedantic
CPPFLAGS:=${shell pkg-config --cflags ncurses readline}
LDLIBS=-I ${CHDRD} ${shell pkg-config --libs ncurses readline}
CFLAGS +=$(if $(DEBUG),-O0 -ggdb,-O3 -flto=auto -fomit-frame-pointer)
CFLAGS +=$(if $(SAN),-fsanitize=${SAN})
CPPFLAGS:=-I config/ -I ${CHDRD} ${shell pkg-config --cflags ncurses readline}
LDLIBS=${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})
@@ -27,9 +19,10 @@ SRC:=$(shell find ${SRCD} -iname '*.c') ${GENLEX}
OBJ:=$(subst .c,.o,$(subst ${SRCD},${OBJD},${SRC}))

HDRD:=${SRCD}
CONFD:=config/
CHDRD:=${OBJD}
HDR:=$(shell find ${HDRD} -iname '*.h')
CHDR:=$(addsuffix .gch,$(subst ${HDRD},${CHDRD},${HDR}))
HDR:=$(shell find ${HDRD} ${CONFD} -iname '*.h')
CHDR:=$(addsuffix .gch,$(subst ${HDRD},${CHDRD},$(subst ${CONFD}, ${CHDRD}, ${HDR})))

OUTPUT:=csope

@@ -45,6 +38,9 @@ src/%.c: src/%.l
obj/%.h.gch: src/%.h
${CC} $< -o $@

obj/%.h.gch: config/%.h
${CC} $< -o $@

clean:
-rm ${CHDR}
-rm ${GENLEX}


+ 92
- 0
config/colors.h Parādīt failu

@@ -0,0 +1,92 @@
#ifndef CONFIG_H
#define CONFIG_H

/* List of color options:
COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_YELLOW
COLOR_BLUE
COLOR_MAGENTA
COLOR_CYAN
COLOR_WHITE
-1 // for transparent (only works if that is your default terminal background)
*/

/* --- Valid presets --- */
#define STD_PRESET 1
#define COLORFUL_PRESET 2

/* --- Preset selection --- */
#define COLOR_PRESET 2

#if COLOR_PRESET == 1
#elif COLOR_PRESET == 2
# define COLOR_FRAME_FG COLOR_GREEN
# define COLOR_FRAME_BG -1
# define COLOR_PROMPT_FG COLOR_BLUE
# define COLOR_PROMPT_BG -1
# define COLOR_CURSOR COLOR_WHITE
# define COLOR_FIELD_FG COLOR_WHITE
# define COLOR_FIELD_BG -1
# define COLOR_FIELD_SELECTED_FG COLOR_BLACK
# define COLOR_FIELD_SELECTED_BG COLOR_WHITE
# define COLOR_HELP_FG COLOR_YELLOW
# define COLOR_HELP_BG -1
# define COLOR_TOOLTIP_FG COLOR_BLACK
# define COLOR_TOOLTIP_BG COLOR_WHITE
# define COLOR_MESSAGE_FG COLOR_WHITE
# define COLOR_MESSAGE_BG COLOR_BLACK
# define COLOR_PATTERN_FG COLOR_WHITE
# define COLOR_PATTERN_BG -1
# define COLOR_TABLE_HEADER_FG COLOR_YELLOW
# define COLOR_TABLE_HEADER_BG -1
# define COLOR_TABLE_ID_FG COLOR_CYAN
# define COLOR_TABLE_ID_BG -1
# define COLOR_TABLE_COL_FILE_FG COLOR_MAGENTA
# define COLOR_TABLE_COL_FILE_BG -1
# define COLOR_TABLE_COL_FUNCTION_FG COLOR_RED
# define COLOR_TABLE_COL_FUNCTION_BG -1
# define COLOR_TABLE_COL_LINE_FG COLOR_CYAN
# define COLOR_TABLE_COL_LINE_BG -1
# define COLOR_TABLE_COL_TEXT_FG COLOR_GREEN
# define COLOR_TABLE_COL_TEXT_BG -1
# define COLOR_PAGER_MSG_FG COLOR_YELLOW
# define COLOR_PAGER_MSG_BG -1
#else
# error "Color profile not valid"
#endif

enum color_pairs{
COLOR_PAIR_FRAME = 1,
COLOR_PAIR_PROMPT,
COLOR_PAIR_FIELD,
COLOR_PAIR_FIELD_SELECTED,
COLOR_PAIR_HELP,
COLOR_PAIR_TOOLTIP,
COLOR_PAIR_PATTERN,
COLOR_PAIR_MESSAGE,
COLOR_PAIR_TABLE_HEADER,
COLOR_PAIR_TABLE_ID,
COLOR_PAIR_TABLE_COL_FILE,
COLOR_PAIR_TABLE_COL_FUNCTION,
COLOR_PAIR_TABLE_COL_LINE,
COLOR_PAIR_TABLE_COL_TEXT,
COLOR_PAIR_PAGER_MSG
};

#define easy_init_pair(x) init_pair(COLOR_PAIR_ ## x, COLOR_ ## x ## _FG, COLOR_ ## x ## _BG)

/* Other options:
A_NORMAL : Normal display (no highlight)
A_UNDERLINE : Underlining
A_REVERSE : Reverse video
A_BLINK : Blinking
A_BOLD : Extra bright or bold
A_STANDOUT : Best highlighting mode of the terminal.
NOTE: you can specify more than one by separating the options by a '|' sign.
{ A_BLINK | A_BOLD }
*/
#define ATTRIBUTE_FIELD_SELECTED A_BOLD

#endif

+ 85
- 34
src/display.c Parādīt failu

@@ -37,6 +37,7 @@

#include "global.h"
#include "build.h"
#include "colors.h"

#ifdef CCS
#include "sgs.h" /* ESG_PKG and ESG_REL */
@@ -144,6 +145,23 @@ dispinit(void)
{
/* initialize the curses display package */
initscr(); /* initialize the screen */
start_color();
use_default_colors();
easy_init_pair(FRAME);
easy_init_pair(PROMPT);
easy_init_pair(FIELD);
easy_init_pair(FIELD_SELECTED);
easy_init_pair(HELP);
easy_init_pair(TOOLTIP);
easy_init_pair(MESSAGE);
easy_init_pair(PATTERN);
easy_init_pair(TABLE_HEADER);
easy_init_pair(TABLE_ID);
easy_init_pair(TABLE_COL_LINE);
easy_init_pair(TABLE_COL_FILE);
easy_init_pair(TABLE_COL_FUNCTION);
easy_init_pair(TABLE_COL_TEXT);
easy_init_pair(PAGER_MSG);
entercurses();

/* Calculate section sizes */
@@ -152,7 +170,7 @@ dispinit(void)
mode_window_height = LINES - input_window_height - 2 - 1;
first_col_width = 48; // (((COLS - 2)%2 == 0) ? ((COLS-2)/2) : (((COLS-2)/2)+1));
second_col_width = COLS - 2 - 1 - first_col_width; //((COLS - 2) / 2) - 1;
mdisprefs = result_window_height - WRESULT_TABLE_BODY_START - 1 - 1;
mdisprefs = result_window_height - WRESULT_TABLE_BODY_START - 1 - 1 - 1;

if (mdisprefs <= 0) {
postfatal("%s: screen too small\n", argv0);
@@ -216,44 +234,51 @@ exitcurses(void)
}

static inline void display_help(){
// XXX: this could be optimized by only overriding the buffer if theres an actual change
werase(whelp);
wmove(whelp, 0, 0);
wattron(whelp, COLOR_PAIR(COLOR_PAIR_HELP));
waddstr(whelp, help());
wattroff(whelp, COLOR_PAIR(COLOR_PAIR_HELP));

refresh();
wrefresh(whelp);

do_press_any_key = true;
window_change = CH_ALL;
}

static inline void display_frame(){
static inline void display_frame(const bool border_only){
wattron(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));

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*/
const int LEFT_PADDING = 5;
wmove(stdscr, 0, LEFT_PADDING);
#if CCS
if (displayversion == true) {
wprintw(stdscr, "cscope %s", ESG_REL);
}
else {
waddstr(stdscr, "cscope");
}
wprintw(stdscr, "cscope %s", ESG_REL);
#else
wprintw(stdscr, "Cscope version %d%s", FILEVERSION, FIXVERSION);
#endif
wmove(stdscr, 0, COLS - (int)sizeof(helpstring) - 3);
waddstr(stdscr, helpstring);
/* --- */
if(!border_only){
/* 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);
}

wattroff(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));
}

static inline void display_mode(){
@@ -261,18 +286,22 @@ static inline void display_mode(){

for(int i = 0; i < FIELDS; ++i){
if(i == field){
wattron(wmode, A_REVERSE);
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
wattroff(wmode, A_REVERSE);
wattroff(wmode, COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
}else{
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
wattroff(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
}
}
}

static inline void display_command_field(){
werase(winput);
wattron(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
mvwaddstr(winput, 0, 0, prompts[input_mode]);
wattroff(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
waddstr(winput, rl_line_buffer);
}
static inline void display_results(){
@@ -293,7 +322,9 @@ static inline void display_results(){
if (totallines == 0) { // Its a real message
wmove(wresult, MSGLINE, 0);
wclrtoeol(wresult);
wattron(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
waddstr(wresult, lastmsg);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
return;
}
if (input_mode == INPUT_CHANGE) { // Its a pattern
@@ -302,9 +333,12 @@ static inline void display_results(){
snprintf(lastmsg, MSGLEN, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1, input_line);
}
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PATTERN));
waddstr(wresult, lastmsg);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PATTERN));

/* --- Display the column headings --- */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));
wmove(wresult, 2, 2);
if (ogs == true && field != FILENAME) {
wprintw(wresult, "%-*s ", subsystemlen, "Subsystem");
@@ -319,6 +353,7 @@ static inline void display_results(){
if (field != FILENAME) {
waddstr(wresult, "Line");
}
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));

/* --- Display table entries --- */
wmove(wresult, WRESULT_TABLE_BODY_START, 0);
@@ -367,7 +402,9 @@ static inline void display_results(){
++nextline;
displine[disprefs] = screenline;

wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_ID));
wprintw(wresult, "%c", dispchars[disprefs]);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_ID));

/* display any change mark */
if (input_mode == INPUT_CHANGE && change[topref + disprefs]) {
@@ -377,6 +414,7 @@ static inline void display_results(){
}

/* display the file name */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FILE));
if (field == FILENAME) {
wprintw(wresult, "%-*s ", filelen, file);
} else {
@@ -392,24 +430,30 @@ static inline void display_results(){
pathcomponents(file, dispcomponents));
}
} /* else(field == FILENAME) */
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FILE));

/* display the function name */
if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
if(field == SYMBOL || field == CALLEDBY || field == CALLING){
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FUNCTION));
wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_FUNCTION));
}
if (field == FILENAME) {
waddch(wresult, '\n'); /* go to next line */
continue;
if(field == FILENAME){
waddch(wresult, '\n'); /* go to next line */
continue;
}

/* display the line number */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_LINE));
wprintw(wresult, "%*s ", numlen, linenum);
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_LINE));
/* there may be tabs in egrep output */
while ((s = strchr(tempstring, '\t')) != NULL) {
*s = ' ';
while((s = strchr(tempstring, '\t')) != NULL){
*s = ' ';
}

/* display the source line */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_TEXT));
s = tempstring;
for (;;) {
/* if the source line does not fit */
@@ -467,6 +511,7 @@ static inline void display_results(){
wmove(wresult, screenline, second_col_width - srctxtw);
} /* for(ever) */
} /* for(reference output lines) */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_COL_TEXT));

endrefs:
/* position the screen cursor for the message */
@@ -477,6 +522,8 @@ endrefs:
else {
wmove(wresult, i, 0);
}
/* --- display pager message --- */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
/* check for more references */
i = totallines - nextline + 1;
bottomline = nextline;
@@ -487,6 +534,7 @@ endrefs:
else if (current_page > 0 && nextline > totallines) {
waddstr(wresult, "* Press the space bar to display the first lines again *");
}
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
}

void display_cursor(void){
@@ -710,14 +758,17 @@ display(void)

if(window_change){
if(window_change == CH_HELP){
display_frame(true);
display_help();
/* Do not display over the help msg and */
/* rely on display_help() setting CH_ALL */
/* Do not display over the help msg and
* rely on setting CH_ALL for the next display
*/
window_change = CH_ALL;
return;
}
/**/
if(window_change == CH_ALL){
display_frame();
display_frame(false);
}
if(window_change & CH_INPUT){
display_command_field();


+ 2
- 2
src/edit.c Parādīt failu

@@ -93,7 +93,7 @@ editall(void)

/* call the editor */
void
edit(char *file, char *linenum)
edit(char *file, const char *const linenum)
{
const char *const editor_basename = basename(editor);
char msg[MSGLEN + 1]; /* message */
@@ -135,7 +135,7 @@ edit(char *file, char *linenum)
/* if requested, prepend a path to a relative file name */

char *
filepath(const char *file)
filepath(char *file)
{
static char path[PATHLEN + 1];



+ 11
- 13
src/global.h Parādīt failu

@@ -124,9 +124,6 @@ extern char *argv0; /* command name */
extern bool compress; /* compress the characters in the crossref */
extern bool dbtruncated; /* database symbols truncated to 8 chars */
extern int dispcomponents; /* file path components to display */
#if CCS
extern bool displayversion; /* display the C Compilation System version */
#endif
extern bool editallprompt; /* prompt between editing files */
extern unsigned int fileargc; /* file argument count */
extern char **fileargv; /* file argument values */
@@ -142,12 +139,13 @@ extern char *namefile; /* file of file names */
extern bool ogs; /* display OGS book and subsystem names */
extern char *prependpath; /* prepend path to file names */
extern FILE *refsfound; /* references found file */
extern char temp1[]; /* temporary file name */
extern char temp2[]; /* temporary file name */
extern long totalterms; /* total inverted index terms */
extern bool trun_syms; /* truncate symbols to 8 characters */
extern char tempstring[TEMPSTRING_LEN + 1]; /* global dummy string buffer */

extern char *tmpdir; /* temporary directory */
extern char temp1[]; /* temporary file name */
extern char temp2[]; /* temporary file name */

/* command.c global data */
extern bool caseless; /* ignore letter case when searching */
@@ -167,10 +165,10 @@ extern char currentdir[]; /* current directory */
extern char **incdirs; /* #include directories */
extern char **srcdirs; /* source directories */
extern char **srcfiles; /* source files */
extern unsigned long nincdirs; /* number of #include directories */
extern unsigned long nsrcdirs; /* number of source directories */
extern unsigned long nsrcfiles; /* number of source files */
extern unsigned long msrcfiles; /* maximum number of source files */
extern size_t nincdirs; /* number of #include directories */
extern size_t nsrcdirs; /* number of source directories */
extern size_t nsrcfiles; /* number of source files */
extern size_t msrcfiles; /* maximum number of source files */

/* display.c global data */
extern int subsystemlen; /* OGS subsystem name display field length */
@@ -215,7 +213,7 @@ extern bool unixpcmouse; /* UNIX PC mouse interface */

/* cscope functions called from more than one function or between files */

char *filepath(const char *file);
char *filepath(char *file);
char *findsymbol(const char *pattern);
char *finddef(const char *pattern);
char *findcalledby(const char *pattern);
@@ -261,8 +259,8 @@ void addcmd(int f, char *s);
void addsrcfile(char *path);
void askforchar(void);
void askforreturn(void);
void cannotwrite(char *file);
void cannotopen(char *file);
void cannotwrite(const char *const file);
void cannotopen(const char *const file);
void clearmsg(void);
void clearmsg2(void);
void countrefs(void);
@@ -270,7 +268,7 @@ void crossref(char *srcfile);
void dispinit(void);
void display(void);
void drawscrollbar(int top, int bot);
void edit(char *file, char *linenum);
void edit(char *file, const char *const linenum);
void editall(void);
void editref(int);
void entercurses(void);


+ 2
- 5
src/main.c Parādīt failu

@@ -72,9 +72,6 @@ char *argv0; /* command name */
bool compress = true; /* compress the characters in the crossref */
bool dbtruncated; /* database symbols are truncated to 8 chars */
int dispcomponents = 1; /* file path components to display */
#if CCS
bool displayversion; /* display the C Compilation System version */
#endif
bool editallprompt = true; /* prompt between editing files */
unsigned int fileargc; /* file argument count */
char **fileargv; /* file argument values */
@@ -150,14 +147,14 @@ siginit(void){
}

void
cannotopen(char *file)
cannotopen(const char *const file)
{
posterr("Cannot open file %s", file);
}

/* FIXME MTE - should use postfatal here */
void
cannotwrite(char *file)
cannotwrite(const char *const file)
{
char msg[MSGLEN + 1];



Notiek ielāde…
Atcelt
Saglabāt