This commit is contained in:
anon 2023-08-06 13:09:48 +02:00
parent 8cc5a5d761
commit 80b1edadc2
9 changed files with 123 additions and 86 deletions

View File

@ -71,3 +71,20 @@ c
n n
p i p i
p topline p topline
b edit
c
where
b input
b handle_input
c
n
n
s
n
s
n
p i
c
c
where
frame 1

View File

@ -46,6 +46,7 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
+ removed random commets giving tips for and refering to specific issues + removed random commets giving tips for and refering to specific issues
+ use stdbool instead of YES/NO macros + use stdbool instead of YES/NO macros
+ saved kilobytes by stripping trailing whitespace + saved kilobytes by stripping trailing whitespace
+ FILE\* refsfound used to be rewind()-ed everytime the reads were not sequencial
# Project structure /*probably move to documentation*/ # Project structure /*probably move to documentation*/
| Component | Purpose | | Component | Purpose |

16
TODO
View File

@ -1,12 +1,12 @@
# TODO
+ 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
# BUGS # BUGS
+ Changing text double frees: + Changing text double frees:
free(): double free detected in tcache 2 free(): double free detected in tcache 2
Aborted Aborted
+ Ordering function declarations in global.h by alpha order is not smart
+ Handle unused parameters gracefully (#define UNUSED(x) (void)(x))
+ scrollbar() uses int literals?
+ tab scrolls the results
# Misc
+ recursive macro function to assign KEY_* default values; look for a new and shiny preprocessor?
+ sort out constants.h

1
src/a.c Normal file
View File

@ -0,0 +1 @@
int asd;

View File

@ -96,7 +96,7 @@ static int mode_window_height;
#define WRESULT_TABLE_BODY_START 4 #define WRESULT_TABLE_BODY_START 4
int window_change = CH_ALL; int window_change;
const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMfalsePQRSTUVWXYZ"; const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMfalsePQRSTUVWXYZ";
@ -170,6 +170,43 @@ dispinit(void)
current_window = &winput; current_window = &winput;
} }
/* enter curses mode */
void
entercurses(void)
{
incurses = true;
window_change = CH_ALL;
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 */
}
/* exit curses mode */
void
exitcurses(void)
{
/* clear the bottom line */
move(LINES - 1, 0);
clrtoeol();
refresh();
/* exit curses and restore the terminal modes */
endwin();
incurses = false;
/* restore the mouse */
mousecleanup();
fflush(stdout);
}
static inline void display_help(){ static inline void display_help(){
werase(whelp); werase(whelp);
wmove(whelp, 0, 0); wmove(whelp, 0, 0);
@ -229,8 +266,8 @@ static inline void display_command_field(){
} }
static inline void display_results(){ static inline void display_results(){
static long prev_cursor = 0; /* signals where to possibly rewind page_cursor to */
static long page_cursor = 0; /* signals where to output from */ static long page_cursor = 0; /* signals where to output from */
static long next_page_cursor = 0;
int screenline; /* screen line number */ int screenline; /* screen line number */
int srctxtw; /* source line display width */ int srctxtw; /* source line display width */
int i; int i;
@ -295,7 +332,9 @@ static inline void display_results(){
srctxtw -= numlen+1; srctxtw -= numlen+1;
/* decide where to list from */ /* decide where to list from */
do_turn ? (page_cursor = ftell(refsfound)) : fseek(refsfound, page_cursor, SEEK_SET) ; if(do_turn){
page_cursor = next_page_cursor;
}
/* 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 */
@ -314,10 +353,7 @@ static inline void display_results(){
) )
< <
4 4
) ){ break; }
{
break;
}
++nextline; ++nextline;
displine[disprefs] = screenline; displine[disprefs] = screenline;
@ -423,7 +459,10 @@ static inline void display_results(){
} /* for(reference output lines) */ } /* for(reference output lines) */
endrefs: endrefs:
/* position the cursor for the message */ /* reset file cursor */
next_page_cursor = ftell(refsfound);
fseek(refsfound, page_cursor, SEEK_SET);
/* position the screen cursor for the message */
i = result_window_height - 1; i = result_window_height - 1;
if (screenline < i) { if (screenline < i) {
waddch(wresult, '\n'); waddch(wresult, '\n');
@ -438,7 +477,7 @@ endrefs:
wprintw(wresult, "* 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(wresult, "* Press the space bar to display the first lines again *"); waddstr(wresult, "* Press the space bar to display the first lines again *");
} }
@ -792,14 +831,25 @@ postfatal(const char *msg, ...)
void void
seekline(unsigned int line) seekline(unsigned int line)
{ {
int c;
/* verify that there is a references found file */ /* verify that there is a references found file */
if (refsfound == NULL) { if (refsfound == NULL) {
return; return;
} }
/* go to the beginning of the file */ /* go to the beginning of the file */
rewind(refsfound); rewind(refsfound);
/**/
seekrelline(line);
}
/* XXX: this is just dodging the problem */
void
seekrelline(unsigned int line){
int c;
/* verify that there is a references found file */
if (refsfound == NULL) {
return;
}
/* find the requested line */ /* find the requested line */
nextline = 1; nextline = 1;

View File

@ -55,11 +55,11 @@ editref(int i)
return; return;
} }
/* get the selected line */ /* get the selected line */
seekline(i + topline); seekrelline(i);
/* get the file name and line number */ /* get the file name and line number */
if (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s", file, linenum) == 2) { if (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s", file, linenum) == 2) {
edit(file, linenum); /* edit it */ edit(file, linenum);
} }
seekline(topline); /* restore the line pointer */ seekline(topline); /* restore the line pointer */
} }
@ -94,31 +94,43 @@ editall(void)
} }
/* call the editor */ /* call the editor */
void void
edit(char *file, char *linenum) edit(char *file, char *linenum)
{ {
const char *const editor_basename = basename(editor);
char msg[MSGLEN + 1]; /* message */ char msg[MSGLEN + 1]; /* message */
char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */ char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */
char *s;
file = filepath(file); file = filepath(file);
(void) snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, file); snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, file);
postmsg(msg); postmsg(msg);
(void) snprintf(plusnum, sizeof(plusnum), lineflag, linenum); snprintf(plusnum, sizeof(plusnum), lineflag, linenum);
/* if this is the more or page commands */
if (strcmp(s = basename(editor), "more") == 0 || strcmp(s, "page") == 0) {
/* get it to pause after displaying a file smaller than the screen /* Some pagers will not start paging, unless the input
length */ * file has more lines thant the screen does.
(void) execute(editor, editor, plusnum, file, "/dev/null", NULL); * The way to get them to pause, is to pass in /dev/null too,
* imatating endless blank lines.
*/
const char* const shit_pagers[] = {
"page",
"more",
NULL
};
for(const char *const *sp = shit_pagers; *sp != NULL; sp++){
if(!strcmp(editor_basename, *sp)){
execute(editor, editor, plusnum, file, "/dev/null", NULL);
goto end;
} }
else if (lineflagafterfile) { }
(void) execute(editor, editor, file, plusnum, NULL);
if (lineflagafterfile) {
execute(editor, editor, file, plusnum, NULL);
} }
else { else {
(void) execute(editor, editor, plusnum, file, NULL); execute(editor, editor, plusnum, file, NULL);
} }
end:
clear(); /* redisplay screen */ clear(); /* redisplay screen */
} }

View File

@ -61,10 +61,10 @@ static pid_t myfork(void);
/*VARARGS1*/ /*VARARGS1*/
int int
execute(char *a, ...) /* note: "exec" is already defined on u370 */ execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
{ {
va_list ap; va_list ap;
int exitcode = -1; /* initialize, to avoid warning */ int exitcode = -1;
char *argv[BUFSIZ]; char *argv[BUFSIZ];
pid_t p; pid_t p;
@ -73,8 +73,9 @@ execute(char *a, ...) /* note: "exec" is already defined on u370 */
mousecleanup(); mousecleanup();
fflush(stdout); fflush(stdout);
va_start(ap, a); va_start(ap, a);
for (p = 0; (argv[p] = va_arg(ap, char *)) != 0; p++)
; for (p = 0; (argv[p] = va_arg(ap, char *)) != 0; p++){}
#ifdef __MSDOS__ #ifdef __MSDOS__
/* HBB 20010313: in MSDOG, everything is completely different. /* HBB 20010313: in MSDOG, everything is completely different.
* No fork()/exec()/wait(), but rather a single libc call: */ * No fork()/exec()/wait(), but rather a single libc call: */
@ -88,16 +89,8 @@ execute(char *a, ...) /* note: "exec" is already defined on u370 */
} }
#endif /* MSDOS */ #endif /* MSDOS */
/* the menu and scrollbar may be changed by the command executed */ entercurses();
#if UNIXPC || !TERMINFO
# ifndef __DJGPP__ /* leave CRLF handling as is */
nonl();
# endif
cbreak(); /* endwin() turns off cbreak mode so restore it */
noecho();
#endif
mousemenu();
drawscrollbar(topline, nextline);
va_end(ap); va_end(ap);
return(exitcode); return(exitcode);
} }

View File

@ -292,6 +292,7 @@ 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 seekrelline(unsigned int line);
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

@ -201,44 +201,6 @@ skiplist(FILE *oldrefs)
} }
} }
/* enter curses mode */
void
entercurses(void)
{
incurses = true;
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 */
}
/* exit curses mode */
void
exitcurses(void)
{
/* clear the bottom line */
move(LINES - 1, 0);
clrtoeol();
refresh();
/* exit curses and restore the terminal modes */
endwin();
incurses = false;
/* restore the mouse */
mousecleanup();
fflush(stdout);
}
/* cleanup and exit */ /* cleanup and exit */
void void
myexit(int sig) myexit(int sig)