editting works again!
This commit is contained in:
parent
73956d102f
commit
6eda9b632c
@ -71,6 +71,7 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
|
|||||||
+ Changing text double frees:
|
+ Changing text double frees:
|
||||||
free(): double free detected in tcache 2
|
free(): double free detected in tcache 2
|
||||||
Aborted
|
Aborted
|
||||||
|
+ Changing text can crash without replacing text and leaving the console ncursed
|
||||||
|
|
||||||
# Future features / contributor wishlist
|
# Future features / contributor wishlist
|
||||||
+ providing support for other languages by integrating new lexers (e.g. ctag's)
|
+ providing support for other languages by integrating new lexers (e.g. ctag's)
|
||||||
|
@ -170,7 +170,7 @@ scrollbar(MOUSE *p)
|
|||||||
default:
|
default:
|
||||||
nextline = p->percent * totallines / 100;
|
nextline = p->percent * totallines / 100;
|
||||||
}
|
}
|
||||||
seekline(nextline);
|
//seekline(nextline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,10 +76,7 @@ long searchcount; /* count of files searched */
|
|||||||
unsigned int totallines; /* total reference lines */
|
unsigned int totallines; /* total reference lines */
|
||||||
unsigned fldcolumn; /* input field column */
|
unsigned fldcolumn; /* input field column */
|
||||||
unsigned int curdispline = 0;
|
unsigned int curdispline = 0;
|
||||||
static bool do_turn = false;
|
int current_page = 0;
|
||||||
void set_do_turn(){
|
|
||||||
do_turn = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
WINDOW* winput;
|
WINDOW* winput;
|
||||||
WINDOW* wmode;
|
WINDOW* wmode;
|
||||||
@ -98,9 +95,20 @@ static int mode_window_height;
|
|||||||
|
|
||||||
int window_change;
|
int window_change;
|
||||||
|
|
||||||
const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMfalsePQRSTUVWXYZ";
|
/* NOTE: It's declared like this because we dont need a terminating '\00'. */
|
||||||
|
static const char dispchars[] = {
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||||
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||||
|
};
|
||||||
|
int dispchar2int(const char c){
|
||||||
|
const char fst = dispchars[0];
|
||||||
|
const char lst = dispchars[sizeof(dispchars)-1];
|
||||||
|
int r = c - fst;
|
||||||
|
if(r < 0 || lst < r){ return -1; }
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static int fldline; /* input field line */
|
|
||||||
static sigjmp_buf env; /* setjmp/longjmp buffer */
|
static sigjmp_buf env; /* setjmp/longjmp buffer */
|
||||||
static char lastmsg[MSGLEN + 1]; /* last message displayed */
|
static char lastmsg[MSGLEN + 1]; /* last message displayed */
|
||||||
static const char helpstring[] = "Press the ? key for help";
|
static const char helpstring[] = "Press the ? key for help";
|
||||||
@ -148,10 +156,10 @@ dispinit(void)
|
|||||||
|
|
||||||
if (mdisprefs <= 0) {
|
if (mdisprefs <= 0) {
|
||||||
postfatal("%s: screen too small\n", argv0);
|
postfatal("%s: screen too small\n", argv0);
|
||||||
/* falseTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
if(mdisprefs > strlen(dispchars)){
|
if(mdisprefs > sizeof(dispchars)){
|
||||||
mdisprefs = strlen(dispchars);
|
mdisprefs = sizeof(dispchars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate the displayed line array */
|
/* allocate the displayed line array */
|
||||||
@ -264,14 +272,11 @@ static inline void display_command_field(){
|
|||||||
mvwaddstr(winput, 0, 0, inputprompt);
|
mvwaddstr(winput, 0, 0, inputprompt);
|
||||||
waddstr(winput, rl_line_buffer);
|
waddstr(winput, rl_line_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long page_cursor = 0; /* signals where to output from */
|
|
||||||
static long next_page_cursor = 0;
|
|
||||||
static inline void display_results(){
|
static inline void display_results(){
|
||||||
int screenline; /* screen line number */
|
|
||||||
int srctxtw; /* source line display width */
|
|
||||||
int i;
|
int i;
|
||||||
char *s;
|
char *s;
|
||||||
|
int screenline; /* screen line number */
|
||||||
|
int srctxtw; /* source line display width */
|
||||||
/* column headings */
|
/* column headings */
|
||||||
char *subsystem; /* OGS subsystem name */
|
char *subsystem; /* OGS subsystem name */
|
||||||
char *book; /* OGS book name */
|
char *book; /* OGS book name */
|
||||||
@ -332,9 +337,7 @@ static inline void display_results(){
|
|||||||
srctxtw -= numlen+1;
|
srctxtw -= numlen+1;
|
||||||
|
|
||||||
/* decide where to list from */
|
/* decide where to list from */
|
||||||
if(do_turn){
|
fseek(refsfound, seekpage(current_page), SEEK_SET);
|
||||||
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 */
|
||||||
@ -450,7 +453,7 @@ static inline void display_results(){
|
|||||||
|
|
||||||
/* go back to the beginning of this reference */
|
/* go back to the beginning of this reference */
|
||||||
--nextline;
|
--nextline;
|
||||||
seekline(nextline);
|
fseek(refsfound, 0, SEEK_SET);
|
||||||
goto endrefs;
|
goto endrefs;
|
||||||
}
|
}
|
||||||
/* indent the continued source line */
|
/* indent the continued source line */
|
||||||
@ -459,9 +462,6 @@ static inline void display_results(){
|
|||||||
} /* for(reference output lines) */
|
} /* for(reference output lines) */
|
||||||
|
|
||||||
endrefs:
|
endrefs:
|
||||||
/* reset file cursor */
|
|
||||||
next_page_cursor = ftell(refsfound);
|
|
||||||
fseek(refsfound, page_cursor, SEEK_SET);
|
|
||||||
/* position the screen cursor for the message */
|
/* position the screen cursor for the message */
|
||||||
i = result_window_height - 1;
|
i = result_window_height - 1;
|
||||||
if (screenline < i) {
|
if (screenline < i) {
|
||||||
@ -480,8 +480,6 @@ endrefs:
|
|||||||
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 *");
|
||||||
}
|
}
|
||||||
|
|
||||||
do_turn = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_cursor(void){
|
void display_cursor(void){
|
||||||
@ -827,39 +825,6 @@ postfatal(const char *msg, ...)
|
|||||||
myexit(1);
|
myexit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* position references found file at specified line */
|
|
||||||
void
|
|
||||||
seekline(unsigned int line)
|
|
||||||
{
|
|
||||||
/* 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;
|
|
||||||
while (nextline < line && (c = getc(refsfound)) != EOF) {
|
|
||||||
if (c == '\n') {
|
|
||||||
nextline++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the OGS subsystem and book names */
|
/* get the OGS subsystem and book names */
|
||||||
void
|
void
|
||||||
ogsnames(char *file, char **subsystem, char **book)
|
ogsnames(char *file, char **subsystem, char **book)
|
||||||
|
@ -61,7 +61,6 @@ editref(int i)
|
|||||||
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(file, linenum);
|
||||||
}
|
}
|
||||||
seekline(topline); /* restore the line pointer */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* edit all references */
|
/* edit all references */
|
||||||
@ -78,7 +77,7 @@ editall(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* get the first line */
|
/* get the first line */
|
||||||
seekline(1);
|
fseek(refsfound, 0, SEEK_SET);
|
||||||
|
|
||||||
/* get each file name and line number */
|
/* get each file name and line number */
|
||||||
while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
|
while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
|
||||||
@ -90,7 +89,6 @@ editall(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seekline(topline);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call the editor */
|
/* call the editor */
|
||||||
|
22
src/global.h
22
src/global.h
@ -41,6 +41,7 @@
|
|||||||
//#include "config.h"
|
//#include "config.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <ctype.h> /* isalpha, isdigit, etc. */
|
#include <ctype.h> /* isalpha, isdigit, etc. */
|
||||||
#include <signal.h> /* SIGINT and SIGQUIT */
|
#include <signal.h> /* SIGINT and SIGQUIT */
|
||||||
#include <stdio.h> /* standard I/O package */
|
#include <stdio.h> /* standard I/O package */
|
||||||
@ -51,6 +52,7 @@
|
|||||||
#include "constants.h" /* misc. constants */
|
#include "constants.h" /* misc. constants */
|
||||||
#include "invlib.h" /* inverted index library */
|
#include "invlib.h" /* inverted index library */
|
||||||
#include "library.h" /* library function return values */
|
#include "library.h" /* library function return values */
|
||||||
|
#include "stddef.h" /* size_t */
|
||||||
|
|
||||||
typedef void (*sighandler_t)(int);
|
typedef void (*sighandler_t)(int);
|
||||||
|
|
||||||
@ -183,7 +185,6 @@ extern FILE *nonglobalrefs; /* non-global references file */
|
|||||||
extern unsigned int topline; /* top line of page */
|
extern unsigned int topline; /* top line of page */
|
||||||
extern long searchcount; /* count of files searched */
|
extern long searchcount; /* count of files searched */
|
||||||
extern unsigned int totallines; /* total reference lines */
|
extern unsigned int totallines; /* total reference lines */
|
||||||
extern const char dispchars[]; /* display chars for jumping to lines */
|
|
||||||
extern int window_change;
|
extern int window_change;
|
||||||
|
|
||||||
/* find.c global data */
|
/* find.c global data */
|
||||||
@ -238,12 +239,17 @@ void usage(void);
|
|||||||
extern bool remove_symfile_onexit;
|
extern bool remove_symfile_onexit;
|
||||||
extern bool onesearch; /* one search only in line mode */
|
extern bool onesearch; /* one search only in line mode */
|
||||||
extern char *reflines; /* symbol reference lines file */
|
extern char *reflines; /* symbol reference lines file */
|
||||||
extern bool do_press_any_key; /* wait for any key to continue */
|
extern bool do_press_any_key; /* wait for any key to continue */
|
||||||
void verswp_field(void);
|
extern int current_page;
|
||||||
void horswp_field(void);
|
void verswp_field(void);
|
||||||
bool interpret(int c); // XXX: probably rename
|
void horswp_field(void);
|
||||||
int handle_input(const char c);
|
bool interpret(int c); // XXX: probably rename
|
||||||
void set_do_turn(void); /* initiate turning to the next result page */
|
int handle_input(const char c);
|
||||||
|
int dispchar2int(const char c);
|
||||||
|
|
||||||
|
long seekpage(size_t i);
|
||||||
|
long seekrelline(unsigned i);
|
||||||
|
void PCS_reset(void);
|
||||||
|
|
||||||
void rlinit(void);
|
void rlinit(void);
|
||||||
|
|
||||||
@ -291,8 +297,6 @@ void postfatal(const char *msg,...);
|
|||||||
void putposting(char *term, int type);
|
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 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);
|
||||||
|
39
src/input.c
39
src/input.c
@ -363,9 +363,9 @@ wresult_input(const int c){
|
|||||||
resetcmd();
|
resetcmd();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
char *e;
|
if(c > mdisprefs){ goto noredisp; }
|
||||||
if ((e = strchr(dispchars, c)))
|
const int pos = dispchar2int(c);
|
||||||
editref(e - dispchars);
|
if(pos > -1){ editref(pos); }
|
||||||
goto noredisp;
|
goto noredisp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ global_input(const int c){
|
|||||||
case KEY_NPAGE:
|
case KEY_NPAGE:
|
||||||
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
||||||
curdispline = 0;
|
curdispline = 0;
|
||||||
set_do_turn();
|
++current_page;
|
||||||
window_change |= CH_RESULT;
|
window_change |= CH_RESULT;
|
||||||
break;
|
break;
|
||||||
case ctrl('H'): /* display previous page */
|
case ctrl('H'): /* display previous page */
|
||||||
@ -397,20 +397,21 @@ global_input(const int c){
|
|||||||
case KEY_PPAGE:
|
case KEY_PPAGE:
|
||||||
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
||||||
curdispline = 0;
|
curdispline = 0;
|
||||||
/* if on first page but not at beginning, go to beginning */
|
--current_page;
|
||||||
nextline -= mdisprefs; /* already at next page */
|
///* if on first page but not at beginning, go to beginning */
|
||||||
if (nextline > 1 && nextline <= mdisprefs) {
|
//nextline -= mdisprefs; /* already at next page */
|
||||||
nextline = 1;
|
//if (nextline > 1 && nextline <= mdisprefs) {
|
||||||
} else {
|
// nextline = 1;
|
||||||
nextline -= mdisprefs;
|
//} else {
|
||||||
if (nextline < 1) {
|
// nextline -= mdisprefs;
|
||||||
nextline = totallines - mdisprefs + 1;
|
// if (nextline < 1) {
|
||||||
if (nextline < 1) {
|
// nextline = totallines - mdisprefs + 1;
|
||||||
nextline = 1;
|
// if (nextline < 1) {
|
||||||
}
|
// nextline = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
seekline(nextline);
|
//}
|
||||||
|
//seekline(nextline);
|
||||||
break;
|
break;
|
||||||
case '>': /* write or append the lines to a file */
|
case '>': /* write or append the lines to a file */
|
||||||
break; // XXX
|
break; // XXX
|
||||||
@ -507,7 +508,7 @@ global_input(const int c){
|
|||||||
break;
|
break;
|
||||||
case '!': /* shell escape */
|
case '!': /* shell escape */
|
||||||
execute(shell, shell, NULL);
|
execute(shell, shell, NULL);
|
||||||
seekline(topline);
|
current_page = 0;
|
||||||
break;
|
break;
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
/* XXX: fill in*/
|
/* XXX: fill in*/
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "build.h"
|
#include "build.h"
|
||||||
#include "vp.h"
|
#include "vp.h"
|
||||||
#include "version.h" /* FILEVERSION and FIXVERSION */
|
#include "version.h" /* FILEVERSION and FIXVERSION */
|
||||||
#include "scanner.h"
|
|
||||||
|
|
||||||
#include <stdlib.h> /* atoi */
|
#include <stdlib.h> /* atoi */
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
75
src/refsfound.c
Normal file
75
src/refsfound.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "global.h"
|
||||||
|
/* Possibly rename */
|
||||||
|
|
||||||
|
struct FILE;
|
||||||
|
|
||||||
|
/* Page cursor stack */
|
||||||
|
static FILE** hto_page = &refsfound;
|
||||||
|
#define PCS_MAXPAGE 16
|
||||||
|
static long PCS_pos[PCS_MAXPAGE] = {0};
|
||||||
|
static int PCS_top = 0;
|
||||||
|
|
||||||
|
long seekpage(size_t i){
|
||||||
|
if(i > PCS_MAXPAGE-1){ return -1; }
|
||||||
|
|
||||||
|
fseek(*hto_page, PCS_pos[PCS_top], SEEK_SET);
|
||||||
|
|
||||||
|
size_t lc = 0;
|
||||||
|
while(PCS_top < i){
|
||||||
|
const char c = getc(*hto_page);
|
||||||
|
if(c == '\n'){ ++lc; }
|
||||||
|
if(lc == mdisprefs){
|
||||||
|
PCS_pos[++PCS_top] = ftell(*hto_page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PCS_pos[PCS_top];
|
||||||
|
}
|
||||||
|
|
||||||
|
long seekrelline(unsigned i){
|
||||||
|
seekpage(current_page);
|
||||||
|
size_t lc = 0;
|
||||||
|
while(lc < i){
|
||||||
|
const char c = getc(*hto_page);
|
||||||
|
assert(("seekrelline() tried to read past the reference file", !(c == EOF)));
|
||||||
|
if(c == '\n'){ ++lc; }
|
||||||
|
}
|
||||||
|
return ftell(*hto_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PCS_reset(void){
|
||||||
|
PCS_top = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
///* position references found file at specified line */
|
||||||
|
//void
|
||||||
|
//seekline(unsigned int line)
|
||||||
|
//{
|
||||||
|
// /* 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;
|
||||||
|
// while (nextline < line && (c = getc(refsfound)) != EOF) {
|
||||||
|
// if (c == '\n') {
|
||||||
|
// nextline++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user