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:
|
||||
free(): double free detected in tcache 2
|
||||
Aborted
|
||||
+ Changing text can crash without replacing text and leaving the console ncursed
|
||||
|
||||
# Future features / contributor wishlist
|
||||
+ providing support for other languages by integrating new lexers (e.g. ctag's)
|
||||
|
@ -170,7 +170,7 @@ scrollbar(MOUSE *p)
|
||||
default:
|
||||
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 fldcolumn; /* input field column */
|
||||
unsigned int curdispline = 0;
|
||||
static bool do_turn = false;
|
||||
void set_do_turn(){
|
||||
do_turn = true;
|
||||
}
|
||||
int current_page = 0;
|
||||
|
||||
WINDOW* winput;
|
||||
WINDOW* wmode;
|
||||
@ -98,9 +95,20 @@ static int mode_window_height;
|
||||
|
||||
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 char lastmsg[MSGLEN + 1]; /* last message displayed */
|
||||
static const char helpstring[] = "Press the ? key for help";
|
||||
@ -148,10 +156,10 @@ dispinit(void)
|
||||
|
||||
if (mdisprefs <= 0) {
|
||||
postfatal("%s: screen too small\n", argv0);
|
||||
/* falseTREACHED */
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if(mdisprefs > strlen(dispchars)){
|
||||
mdisprefs = strlen(dispchars);
|
||||
if(mdisprefs > sizeof(dispchars)){
|
||||
mdisprefs = sizeof(dispchars);
|
||||
}
|
||||
|
||||
/* allocate the displayed line array */
|
||||
@ -264,14 +272,11 @@ static inline void display_command_field(){
|
||||
mvwaddstr(winput, 0, 0, inputprompt);
|
||||
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(){
|
||||
int screenline; /* screen line number */
|
||||
int srctxtw; /* source line display width */
|
||||
int i;
|
||||
char *s;
|
||||
int screenline; /* screen line number */
|
||||
int srctxtw; /* source line display width */
|
||||
/* column headings */
|
||||
char *subsystem; /* OGS subsystem name */
|
||||
char *book; /* OGS book name */
|
||||
@ -332,9 +337,7 @@ static inline void display_results(){
|
||||
srctxtw -= numlen+1;
|
||||
|
||||
/* decide where to list from */
|
||||
if(do_turn){
|
||||
page_cursor = next_page_cursor;
|
||||
}
|
||||
fseek(refsfound, seekpage(current_page), SEEK_SET);
|
||||
|
||||
/* until the max references have been displayed or
|
||||
there is no more room */
|
||||
@ -450,7 +453,7 @@ static inline void display_results(){
|
||||
|
||||
/* go back to the beginning of this reference */
|
||||
--nextline;
|
||||
seekline(nextline);
|
||||
fseek(refsfound, 0, SEEK_SET);
|
||||
goto endrefs;
|
||||
}
|
||||
/* indent the continued source line */
|
||||
@ -459,9 +462,6 @@ static inline void display_results(){
|
||||
} /* for(reference output lines) */
|
||||
|
||||
endrefs:
|
||||
/* 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) {
|
||||
@ -480,8 +480,6 @@ endrefs:
|
||||
else if (topline > 1 && nextline > totallines) {
|
||||
waddstr(wresult, "* Press the space bar to display the first lines again *");
|
||||
}
|
||||
|
||||
do_turn = false;
|
||||
}
|
||||
|
||||
void display_cursor(void){
|
||||
@ -827,39 +825,6 @@ postfatal(const char *msg, ...)
|
||||
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 */
|
||||
void
|
||||
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) {
|
||||
edit(file, linenum);
|
||||
}
|
||||
seekline(topline); /* restore the line pointer */
|
||||
}
|
||||
|
||||
/* edit all references */
|
||||
@ -78,7 +77,7 @@ editall(void)
|
||||
return;
|
||||
}
|
||||
/* get the first line */
|
||||
seekline(1);
|
||||
fseek(refsfound, 0, SEEK_SET);
|
||||
|
||||
/* get each file name and line number */
|
||||
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 */
|
||||
|
22
src/global.h
22
src/global.h
@ -41,6 +41,7 @@
|
||||
//#include "config.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h> /* isalpha, isdigit, etc. */
|
||||
#include <signal.h> /* SIGINT and SIGQUIT */
|
||||
#include <stdio.h> /* standard I/O package */
|
||||
@ -51,6 +52,7 @@
|
||||
#include "constants.h" /* misc. constants */
|
||||
#include "invlib.h" /* inverted index library */
|
||||
#include "library.h" /* library function return values */
|
||||
#include "stddef.h" /* size_t */
|
||||
|
||||
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 long searchcount; /* count of files searched */
|
||||
extern unsigned int totallines; /* total reference lines */
|
||||
extern const char dispchars[]; /* display chars for jumping to lines */
|
||||
extern int window_change;
|
||||
|
||||
/* find.c global data */
|
||||
@ -238,12 +239,17 @@ 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 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
|
||||
int handle_input(const char c);
|
||||
void set_do_turn(void); /* initiate turning to the next result page */
|
||||
extern bool do_press_any_key; /* wait for any key to continue */
|
||||
extern int current_page;
|
||||
void verswp_field(void);
|
||||
void horswp_field(void);
|
||||
bool interpret(int c); // XXX: probably rename
|
||||
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);
|
||||
|
||||
@ -291,8 +297,6 @@ void postfatal(const char *msg,...);
|
||||
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);
|
||||
|
39
src/input.c
39
src/input.c
@ -363,9 +363,9 @@ wresult_input(const int c){
|
||||
resetcmd();
|
||||
break;
|
||||
default:
|
||||
char *e;
|
||||
if ((e = strchr(dispchars, c)))
|
||||
editref(e - dispchars);
|
||||
if(c > mdisprefs){ goto noredisp; }
|
||||
const int pos = dispchar2int(c);
|
||||
if(pos > -1){ editref(pos); }
|
||||
goto noredisp;
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ global_input(const int c){
|
||||
case KEY_NPAGE:
|
||||
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
||||
curdispline = 0;
|
||||
set_do_turn();
|
||||
++current_page;
|
||||
window_change |= CH_RESULT;
|
||||
break;
|
||||
case ctrl('H'): /* display previous page */
|
||||
@ -397,20 +397,21 @@ global_input(const int c){
|
||||
case KEY_PPAGE:
|
||||
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
|
||||
curdispline = 0;
|
||||
/* if on first page but not at beginning, go to beginning */
|
||||
nextline -= mdisprefs; /* already at next page */
|
||||
if (nextline > 1 && nextline <= mdisprefs) {
|
||||
nextline = 1;
|
||||
} else {
|
||||
nextline -= mdisprefs;
|
||||
if (nextline < 1) {
|
||||
nextline = totallines - mdisprefs + 1;
|
||||
if (nextline < 1) {
|
||||
nextline = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
seekline(nextline);
|
||||
--current_page;
|
||||
///* if on first page but not at beginning, go to beginning */
|
||||
//nextline -= mdisprefs; /* already at next page */
|
||||
//if (nextline > 1 && nextline <= mdisprefs) {
|
||||
// nextline = 1;
|
||||
//} else {
|
||||
// nextline -= mdisprefs;
|
||||
// if (nextline < 1) {
|
||||
// nextline = totallines - mdisprefs + 1;
|
||||
// if (nextline < 1) {
|
||||
// nextline = 1;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//seekline(nextline);
|
||||
break;
|
||||
case '>': /* write or append the lines to a file */
|
||||
break; // XXX
|
||||
@ -507,7 +508,7 @@ global_input(const int c){
|
||||
break;
|
||||
case '!': /* shell escape */
|
||||
execute(shell, shell, NULL);
|
||||
seekline(topline);
|
||||
current_page = 0;
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
/* XXX: fill in*/
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "build.h"
|
||||
#include "vp.h"
|
||||
#include "version.h" /* FILEVERSION and FIXVERSION */
|
||||
#include "scanner.h"
|
||||
|
||||
#include <stdlib.h> /* atoi */
|
||||
#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