diff --git a/.gdb_history b/.gdb_history index bf68d9d..d4b7082 100644 --- a/.gdb_history +++ b/.gdb_history @@ -71,3 +71,20 @@ c n p i 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 diff --git a/README.md b/README.md index bbe3a06..5343713 100644 --- a/README.md +++ b/README.md @@ -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 + use stdbool instead of YES/NO macros + 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*/ | Component | Purpose | diff --git a/TODO b/TODO index fac694e..be8dd4f 100644 --- a/TODO +++ b/TODO @@ -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 + Changing text double frees: free(): double free detected in tcache 2 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 diff --git a/src/a.c b/src/a.c new file mode 100644 index 0000000..cb23089 --- /dev/null +++ b/src/a.c @@ -0,0 +1 @@ +int asd; diff --git a/src/display.c b/src/display.c index 6be7425..373866c 100644 --- a/src/display.c +++ b/src/display.c @@ -96,7 +96,7 @@ static int mode_window_height; #define WRESULT_TABLE_BODY_START 4 -int window_change = CH_ALL; +int window_change; const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMfalsePQRSTUVWXYZ"; @@ -170,6 +170,43 @@ dispinit(void) 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(){ werase(whelp); wmove(whelp, 0, 0); @@ -229,8 +266,8 @@ static inline void display_command_field(){ } 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 next_page_cursor = 0; int screenline; /* screen line number */ int srctxtw; /* source line display width */ int i; @@ -295,7 +332,9 @@ static inline void display_results(){ srctxtw -= numlen+1; /* 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 there is no more room */ @@ -314,10 +353,7 @@ static inline void display_results(){ ) < 4 - ) - { - break; - } + ){ break; } ++nextline; displine[disprefs] = screenline; @@ -423,7 +459,10 @@ static inline void display_results(){ } /* for(reference output lines) */ 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; if (screenline < i) { 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); } /* 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 *"); } @@ -792,14 +831,25 @@ postfatal(const char *msg, ...) void seekline(unsigned int line) { - int c; - /* verify that there is a references found file */ if (refsfound == NULL) { return; } /* go to the beginning of the file */ 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 */ nextline = 1; diff --git a/src/edit.c b/src/edit.c index b70943e..14b5ebf 100644 --- a/src/edit.c +++ b/src/edit.c @@ -55,11 +55,11 @@ editref(int i) return; } /* get the selected line */ - seekline(i + topline); + seekrelline(i); /* get the file name and line number */ 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 */ } @@ -94,31 +94,43 @@ editall(void) } /* call the editor */ - void edit(char *file, char *linenum) { + const char *const editor_basename = basename(editor); char msg[MSGLEN + 1]; /* message */ char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */ - char *s; 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); - (void) 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) { + snprintf(plusnum, sizeof(plusnum), lineflag, linenum); - /* get it to pause after displaying a file smaller than the screen - length */ - (void) execute(editor, editor, plusnum, file, "/dev/null", NULL); - } - else if (lineflagafterfile) { - (void) execute(editor, editor, file, plusnum, NULL); + /* Some pagers will not start paging, unless the input + * file has more lines thant the screen does. + * 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; + } + } + + if (lineflagafterfile) { + execute(editor, editor, file, plusnum, NULL); } else { - (void) execute(editor, editor, plusnum, file, NULL); + execute(editor, editor, plusnum, file, NULL); } + + end: clear(); /* redisplay screen */ } diff --git a/src/exec.c b/src/exec.c index e8ef2cc..3e28bdb 100644 --- a/src/exec.c +++ b/src/exec.c @@ -61,10 +61,10 @@ static pid_t myfork(void); /*VARARGS1*/ int -execute(char *a, ...) /* note: "exec" is already defined on u370 */ +execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */ { va_list ap; - int exitcode = -1; /* initialize, to avoid warning */ + int exitcode = -1; char *argv[BUFSIZ]; pid_t p; @@ -73,8 +73,9 @@ execute(char *a, ...) /* note: "exec" is already defined on u370 */ mousecleanup(); fflush(stdout); 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__ /* HBB 20010313: in MSDOG, everything is completely different. * 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 */ - /* the menu and scrollbar may be changed by the command executed */ -#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); + entercurses(); + va_end(ap); return(exitcode); } diff --git a/src/global.h b/src/global.h index 1e1f539..8d0d276 100644 --- a/src/global.h +++ b/src/global.h @@ -292,6 +292,7 @@ void putposting(char *term, int type); void fetch_string_from_dbase(char *, size_t); void resetcmd(void); void seekline(unsigned int line); +void seekrelline(unsigned int line); void shellpath(char *out, int limit, char *in); void sourcedir(char *dirlist); void myungetch(int c); diff --git a/src/main.c b/src/main.c index 34e4e3c..cc8d669 100644 --- a/src/main.c +++ b/src/main.c @@ -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 */ void myexit(int sig)