This commit is contained in:
anon 2023-08-10 14:36:16 +02:00
parent cf671948ea
commit e19aaa09b9
12 changed files with 309 additions and 170 deletions

View File

@ -83,6 +83,8 @@ fixing it would have been a lost cause, if not for Cscope itself. Well, Csope no
+ Ordering function declarations in global.h by alpha order is not smart + Ordering function declarations in global.h by alpha order is not smart
+ lineflagafterfile is stupid + lineflagafterfile is stupid
+ library.h...; "private library", in a program using 90 globals; ffs + library.h...; "private library", in a program using 90 globals; ffs
+ sort out the global hell
+ changestring() forks sh to execute an ed script...
## Original ## Original
+ Display the current case mode (^C) onscreen + Display the current case mode (^C) onscreen
+ emacs like key bindings + emacs like key bindings

View File

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

View File

@ -1,65 +0,0 @@
/*===========================================================================
Copyright (c) 1998-2000, The Santa Cruz Operation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
*Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
*Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
*Neither name of The Santa Cruz Operation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT falseT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT falseT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
=========================================================================*/
/* get a file's base name from its path name */
#include "global.h"
const char *
basename(char *path)
{
char *s;
if ((s = strrchr(path, '/')) != 0) {
return(s + 1);
}
return(path);
}
/* get the requested path components */
char *
pathcomponents(char *path, int components)
{
int i;
char *s;
s = path + strlen(path) - 1;
for (i = 0; i < components; ++i) {
while (s > path && *--s != '/') {
;
}
}
if (s > path && *s == '/') {
++s;
}
return(s);
}

View File

@ -74,7 +74,7 @@ static void scrollbar(MOUSE *p);
static void static void
clearprompt(void) clearprompt(void)
{ {
move(PRLINE, 0); wmove(winput, 0, 0);
clrtoeol(); clrtoeol();
} }
@ -120,7 +120,7 @@ mark(unsigned int i)
{ {
unsigned int j; unsigned int j;
j = i + topline - 1; //j = i + topline - 1;
if (j < totallines) { if (j < totallines) {
move(displine[i], 1); move(displine[i], 1);
@ -139,38 +139,38 @@ mark(unsigned int i)
static void static void
scrollbar(MOUSE *p) scrollbar(MOUSE *p)
{ {
/* reposition list if it makes sense */ ///* reposition list if it makes sense */
if (totallines == 0) { //if (totallines == 0) {
return; //return;
} //}
switch (p->percent) { //switch (p->percent) {
case 101: /* scroll down one page */ //case 101: /* scroll down one page */
if (nextline + mdisprefs > totallines) { //if (nextline + mdisprefs > totallines) {
nextline = totallines - mdisprefs + 1; // nextline = totallines - mdisprefs + 1;
} //}
break; //break;
case 102: /* scroll up one page */ //case 102: /* scroll up one page */
nextline = topline - mdisprefs; //nextline = topline - mdisprefs;
if (nextline < 1) { //if (nextline < 1) {
nextline = 1; // nextline = 1;
} //}
break; //break;
case 103: /* scroll down one line */ //case 103: /* scroll down one line */
nextline = topline + 1; //nextline = topline + 1;
break; //break;
case 104: /* scroll up one line */ //case 104: /* scroll up one line */
if (topline > 1) { //if (topline > 1) {
nextline = topline - 1; // nextline = topline - 1;
} //}
break; //break;
default: //default:
nextline = p->percent * totallines / 100; //nextline = p->percent * totallines / 100;
} //}
//seekline(nextline); ////seekline(nextline);
} }

View File

@ -79,21 +79,23 @@
#define NUMLEN_STR STRINGIZE(NUMLEN) #define NUMLEN_STR STRINGIZE(NUMLEN)
#define TEMPSTRING_LEN_STR STRINGIZE(TEMPSTRING_LEN) #define TEMPSTRING_LEN_STR STRINGIZE(TEMPSTRING_LEN)
/* screen lines */
#define PRLINE (LINES - 1) /* input prompt line */
/* input fields (value matches field order on screen) */ /* input fields (value matches field order on screen) */
#define SYMBOL 0 enum {
#define DEFINITION 1 SYMBOL = 0,
#define CALLEDBY 2 DEFINITION = 1,
#define CALLING 3 CALLEDBY = 2,
#define STRING 4 CALLING = 3,
#define CHANGE 5 STRING = 4,
#define REGEXP 6 CHANGE = 5,
#define FILENAME 7 REGEXP = 6,
#define INCLUDES 8 FILENAME = 7,
INCLUDES = 8
};
#define FIELDS 10 #define FIELDS 10
// XXX
#define bazdmeg 1
/* file open modes */ /* file open modes */
#ifndef R_OK #ifndef R_OK
# define READ R_OK # define READ R_OK

View File

@ -49,18 +49,11 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
/* XXX */ /* XXX */
#define MSGLINE 0 /* message line */ #define MSGLINE 0 /* message line */
#define MSGCOL 0 /* message column */ #define MSGCOL 0 /* message column */
static const char appendprompt[] = "Append to file: ";
static const char pipeprompt[] = "Pipe to shell command: ";
static const char readprompt[] = "Read from file: ";
static const char toprompt[] = "To: ";
static const char inputprompt[] = "$ ";
int subsystemlen = sizeof("Subsystem")-1; /* OGS subsystem name display field length */ int subsystemlen = sizeof("Subsystem")-1; /* OGS subsystem name display field length */
int booklen = sizeof("Book")-1; /* OGS book name display field length */ int booklen = sizeof("Book")-1; /* OGS book name display field length */
int filelen = sizeof("File")-1; /* file name display field length */ int filelen = sizeof("File")-1; /* file name display field length */
@ -72,14 +65,21 @@ unsigned int disprefs; /* displayed references */
int field; /* input field */ int field; /* input field */
unsigned int mdisprefs; /* maximum displayed references */ unsigned int mdisprefs; /* maximum displayed references */
unsigned int nextline; /* next line to be shown */ unsigned int nextline; /* next line to be shown */
FILE *nonglobalrefs; /* non-global references file */
unsigned int topline = 1; /* top line of page */
static int bottomline; /* bottom line of page */ static int bottomline; /* bottom line of page */
long searchcount; /* count of files searched */ long searchcount; /* count of files searched */
unsigned int totallines; /* total reference lines */ unsigned int totallines; /* total reference lines */
unsigned fldcolumn; /* input field column */
unsigned int curdispline = 0; unsigned int curdispline = 0;
int current_page = 0; int current_page = 0;
int input_mode = INPUT_NORMAL;
const char* prompts[] = {
[INPUT_NORMAL] = "$ ",
[INPUT_APPEND] = "Append to file: ",
[INPUT_PIPE] = "Pipe to shell command: ",
[INPUT_READ] = "Read from file: ",
[INPUT_CHANGE] = "To: "
};
static unsigned int topline = 1; /* top line of page */
/* Selectable windows */ /* Selectable windows */
WINDOW* winput; WINDOW* winput;
@ -124,17 +124,17 @@ struct { /* text of input fields */
char *text2; char *text2;
} /* Paralel array to "field_searchers", indexed by "field" */ } /* Paralel array to "field_searchers", indexed by "field" */
fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope display */ fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope display */
{"Find this", "C symbol", findsymbol}, {"Find this", "C symbol"},
{"Find this", "global definition", finddef}, {"Find this", "global definition"},
{"Find", "functions called by this function", findcalledby}, {"Find", "functions called by this function"},
{"Find", "functions calling this function", findcalling}, {"Find", "functions calling this function"},
{"Find this", "text string", findstring}, {"Find this", "text string"},
{"Change this", "text string", findstring}, {"Change this", "text string"},
{"Find this", "egrep pattern", findregexp}, {"Find this", "egrep pattern"},
{"Find this", "file", findfile}, {"Find this", "file"},
{"Find", "files #including this file", findinclude}, {"Find", "files #including this file"},
{"Find", "assignments to this symbol", findassign}, {"Find", "assignments to this symbol"},
{"Find all", "function definitions", findallfcns}, /* samuel only */ {"Find all", "function definitions"}, /* samuel only */
}; };
/* initialize display parameters */ /* initialize display parameters */
@ -270,7 +270,7 @@ static inline void display_mode(){
} }
static inline void display_command_field(){ static inline void display_command_field(){
mvwaddstr(winput, 0, 0, inputprompt); mvwaddstr(winput, 0, 0, prompts[input_mode]);
waddstr(winput, rl_line_buffer); waddstr(winput, rl_line_buffer);
} }
static inline void display_results(){ static inline void display_results(){
@ -491,13 +491,13 @@ void display_cursor(void){
int yoffset = 0, xoffset = 0; int yoffset = 0, xoffset = 0;
if(current_window == &winput){ if(current_window == &winput){
xoffset = sizeof(inputprompt)-1 + rl_point; xoffset = strlen(prompts[input_mode]) + rl_point;
}else if(current_window == &wmode){ }else if(current_window == &wmode){
yoffset = field; yoffset = field;
}else if(current_window == &wresult){ }else if(current_window == &wresult){
yoffset = displine[curdispline]; yoffset = displine[curdispline];
}else{ }else{
assert(("No window selected.", true)); assert("No window selected.");
} }
wmove(*current_window, yoffset, xoffset); wmove(*current_window, yoffset, xoffset);

View File

@ -79,6 +79,7 @@ static bool check_for_assignment(void);
static void putpostingref(POSTING *p, char *pat); static void putpostingref(POSTING *p, char *pat);
static void putref(int seemore, char *file, char *func); static void putref(int seemore, char *file, char *func);
static void putsource(int seemore, FILE *output); static void putsource(int seemore, FILE *output);
static FILE *nonglobalrefs; /* non-global references file */
static sigjmp_buf env; /* setjmp/longjmp buffer */ static sigjmp_buf env; /* setjmp/longjmp buffer */
@ -707,7 +708,7 @@ findinit(char *pattern)
bool isregexp = false; bool isregexp = false;
int i; int i;
char *s; char *s;
unsigned char c; /* HBB 20010427: changed uint to uchar */ unsigned char c;
/* HBB: be nice: free regexp before allocating a new one */ /* HBB: be nice: free regexp before allocating a new one */
if(isregexp_valid == true) if(isregexp_valid == true)
@ -722,7 +723,7 @@ findinit(char *pattern)
*s = '\0'; *s = '\0';
} }
/* HBB 20020620: new: make sure pattern is lowercased. Curses /* Make sure pattern is lowercased. Curses
* mode gets this right all on its own, but at least -L mode * mode gets this right all on its own, but at least -L mode
* doesn't */ * doesn't */
if (caseless == true) { if (caseless == true) {

View File

@ -93,6 +93,13 @@ enum {
CH_HELP = 0x0001 << 3, /* do NOT add to CH_ALL */ CH_HELP = 0x0001 << 3, /* do NOT add to CH_ALL */
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
}; };
enum {
INPUT_NORMAL,
INPUT_APPEND,
INPUT_PIPE,
INPUT_READ,
INPUT_CHANGE
};
#ifndef DFLT_INCDIR #ifndef DFLT_INCDIR
# define DFLT_INCDIR "/usr/include" # define DFLT_INCDIR "/usr/include"
@ -180,14 +187,11 @@ extern int numlen; /* line number display field length */
extern int *displine; /* screen line of displayed reference */ extern int *displine; /* screen line of displayed reference */
extern unsigned int disprefs; /* displayed references */ extern unsigned int disprefs; /* displayed references */
extern int field; /* input field */ extern int field; /* input field */
extern unsigned fldcolumn; /* input field column */
extern unsigned int mdisprefs; /* maximum displayed references */ extern unsigned int mdisprefs; /* maximum displayed references */
extern unsigned int nextline; /* next line to be shown */ extern unsigned int nextline; /* next line to be shown */
extern FILE *nonglobalrefs; /* non-global references file */
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 int window_change; extern int window_change; /* bitmask type to mark which windows have to be rerendered by display() */
/* find.c global data */ /* find.c global data */
extern char block[]; /* cross-reference file block */ extern char block[]; /* cross-reference file block */
@ -249,6 +253,7 @@ bool interpret(int c); // XXX: probably rename
int handle_input(const int c); int handle_input(const int c);
int dispchar2int(const char c); int dispchar2int(const char c);
int process_mouse(); int process_mouse();
extern int input_mode;
long seekpage(size_t i); long seekpage(size_t i);
long seekrelline(unsigned i); long seekrelline(unsigned i);

View File

@ -57,8 +57,7 @@ static void catchint(int sig);
/* catch the interrupt signal */ /* catch the interrupt signal */
static void static void
catchint(int sig) catchint(int sig){
{
UNUSED(sig); UNUSED(sig);
signal(SIGINT, catchint); signal(SIGINT, catchint);
@ -74,8 +73,7 @@ myungetch(int c)
/* get a line from the terminal in non-canonical mode */ /* get a line from the terminal in non-canonical mode */
int int
mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless) mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless){
{
int c; int c;
unsigned int i = 0, j; unsigned int i = 0, j;
char *sright; /* substring to the right of the cursor */ char *sright; /* substring to the right of the cursor */
@ -207,8 +205,7 @@ mygetline(char p[], char s[], unsigned size, int firstchar, bool iscaseless)
/* ask user to enter a character after reading the message */ /* ask user to enter a character after reading the message */
void void
askforchar(void) askforchar(void){
{
addstr("Type any character to continue: "); addstr("Type any character to continue: ");
getch(); getch();
} }
@ -216,8 +213,7 @@ askforchar(void)
/* ask user to press the RETURN key after reading the message */ /* ask user to press the RETURN key after reading the message */
void void
askforreturn(void) askforreturn(void){
{
fprintf(stderr, "Press the RETURN key to continue: "); fprintf(stderr, "Press the RETURN key to continue: ");
getchar(); getchar();
/* HBB 20060419: message probably messed up the screen --- redraw */ /* HBB 20060419: message probably messed up the screen --- redraw */
@ -229,8 +225,7 @@ askforreturn(void)
/* expand the ~ and $ shell meta characters in a path */ /* expand the ~ and $ shell meta characters in a path */
void void
shellpath(char *out, int limit, char *in) shellpath(char *out, int limit, char *in){
{
char *lastchar; char *lastchar;
char *s, *v; char *s, *v;
@ -449,7 +444,7 @@ global_input(const int c){
break; break;
case '<': /* read lines from a file */ case '<': /* read lines from a file */
break; // XXX break; // XXX
move(PRLINE, 0); //move(PRLINE, 0);
//addstr(readprompt); // XXX fix //addstr(readprompt); // XXX fix
//if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) { //if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) {
// clearprompt(); // clearprompt();
@ -471,7 +466,7 @@ global_input(const int c){
return 0; return 0;
} }
/* get the shell command */ /* get the shell command */
move(PRLINE, 0); //move(PRLINE, 0);
//addstr(pipeprompt); //addstr(pipeprompt);
//if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) { //if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) {
// clearprompt(); // clearprompt();
@ -530,10 +525,159 @@ global_input(const int c){
return 1; return 1;
} }
extern const void const* winput; extern const void *const winput;
extern const void const* wmode; extern const void *const wmode;
extern const void const* wresult; extern const void *const wresult;
extern const void const* const* current_window; extern const void *const *const current_window;
static int changestring(bool *change);
static int
change_input(const int c){
MOUSE *p; /* mouse data */
change = calloc(totallines, sizeof(*change));
switch(c){
case '*': /* invert selection */
for(int i = 0; topline + i < nextline; ++i){
change[i] = !change[i];
}
break;
case ctrl('A'): /* mark/unmark all lines */
for(unsigned i = 0; i < totallines; ++i) {
change[i] = !change[i];
}
/* show that all have been marked */
seekline(totallines); // ?!
break;
case ctrl('X'): /* mouse selection */
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
break; /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
scrollbar(p);
break;
}
/* find the selected line */
/* NOTE: the selection is forced into range */
{
int i;
for(i = disprefs - 1; i > 0; --i) {
if (p->y1 >= displine[i]) {
break;
}
}
change[i] = !change[i];
}
break;
case ctrl('D'):
changestring(change);
break;
default:
{
/* if a line was selected */
const int cc = dispchar2int(c);
if(cc != -1){
change[cc] = !change[cc];
}
}
}
return 0;
}
static int
changestring(bool *change){
char newfile[PATHLEN + 1]; /* new file name */
char oldfile[PATHLEN + 1]; /* old file name */
char linenum[NUMLEN + 1]; /* file line number */
char msg[MSGLEN + 1]; /* message */
FILE *script; /* shell script file */
bool anymarked = false; /* any line marked */
/* open the temporary file */
if((script = myfopen(temp2, "w")) == NULL) {
cannotopen(temp2);
return(false);
}
/* for each line containing the old text */
fprintf(script, "ed - <<\\!\n");
*oldfile = '\0';
fseek(refsfound, 0, SEEK_SET);
for(int i = 0;
fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", newfile, linenum) == 2;
++i)
{
/* see if the line is to be changed */
if (change[i] == false) { break; }
anymarked = true;
/* if this is a new file */
if (strcmp(newfile, oldfile) != 0) {
/* make sure it can be changed */
if (access(newfile, WRITE) != 0) {
snprintf(msg, sizeof(msg), "Cannot write to file %s", newfile);
postmsg(msg);
anymarked = false;
break;
}
/* if there was an old file */
if (*oldfile != '\0') {
fprintf(script, "w\n"); /* save it */
}
/* edit the new file */
strcpy(oldfile, newfile);
fprintf(script, "e %s\n", oldfile);
}
/* output substitute command */
fprintf(script, "%ss/", linenum); /* change */
for (char *s = Pattern; *s != '\0'; ++s) {
/* old text */
if (strchr("/\\[.^*", *s) != NULL) {
putc('\\', script);
}
if (caseless == true && isalpha((unsigned char)*s)) {
putc('[', script);
if(islower((unsigned char)*s)) {
putc(toupper((unsigned char)*s), script);
putc(*s, script);
} else {
putc(*s, script);
putc(tolower((unsigned char)*s), script);
}
putc(']', script);
} else {
putc(*s, script);
}
}
putc('/', script); /* to */
for (char *s = newpat; *s != '\0'; ++s) { /* new text */
if (strchr("/\\&", *s) != NULL) {
putc('\\', script);
}
putc(*s, script);
}
fprintf(script, "/gp\n"); /* and print */
}
fprintf(script, "w\nq\n!\n"); /* write and quit */
fclose(script);
/* if any line was marked */
if (anymarked == true) {
/* edit the files */
fprintf(stderr, "Changed lines:\n\r");
execute("sh", "sh", temp2, NULL);
askforchar();
}
changing = false;
mousemenu();
fclose(script);
free(change);
return(anymarked);
}
int int
handle_input(const int c){ handle_input(const int c){
@ -546,13 +690,20 @@ handle_input(const int c){
const int r = global_input(c); const int r = global_input(c);
if(r){ return 0; } if(r){ return 0; }
/* --- mode specific --- */ /* --- mode specific --- */
if(*current_window == winput){ switch(input_mode){
return interpret(c); case INPUT_NORMAL:
}else if(*current_window == wmode){ if(*current_window == winput){
return wmode_input(c); return interpret(c);
}else if(*current_window == wresult){ }else if(*current_window == wmode){
return wresult_input(c); return wmode_input(c);
} }else if(*current_window == wresult){
return wresult_input(c);
}
assert("'current_window' dangling.");
break; /* NOTREACHED */
case INPUT_CHANGE:
return change_input(c);
}
return 0; return 0;
} }

View File

@ -35,7 +35,7 @@
#ifndef KEY_NPAGE #ifndef KEY_NPAGE
# define KEY_NPAGE KEY_UNDEF_BASE-8 # define KEY_NPAGE KEY_UNDEF_BASE-8
#endif #endif
#ifdef KEY_ENTER #ifndef KEY_ENTER
# define KEY_ENTER KEY_UNDEF_BASE-9 # define KEY_ENTER KEY_UNDEF_BASE-9
#endif #endif
#ifndef KEY_CLEAR #ifndef KEY_CLEAR

View File

@ -30,6 +30,41 @@
DAMAGE. DAMAGE.
=========================================================================*/ =========================================================================*/
/* get a file's base name from its path name */
#include "global.h"
const char *
basename(char *path)
{
char *s;
if ((s = strrchr(path, '/')) != 0) {
return(s + 1);
}
return(path);
}
/* get the requested path components */
char *
pathcomponents(char *path, int components)
{
int i;
char *s;
s = path + strlen(path) - 1;
for (i = 0; i < components; ++i) {
while (s > path && *--s != '/') {
;
}
}
if (s > path && *s == '/') {
++s;
}
return(s);
}
/* /*
* compath(pathname) * compath(pathname)
* *
@ -44,12 +79,6 @@
* and stored in global structures. * and stored in global structures.
*/ */
#include "global.h"
#ifndef NULL
#define NULL 0
#endif
char * char *
compath(char *pathname) /*FDEF*/ compath(char *pathname) /*FDEF*/
{ {

View File

@ -35,8 +35,24 @@ static void callback_handler(char* line){
if(!line){ return; } if(!line){ return; }
strncpy(input_line, line, PATLEN); strncpy(input_line, line, PATLEN);
if(!search()){ switch(input_mode){
case INPUT_NORMAL:
search();
break;
case INPUT_CHANGE:
changestring();
input_mode = INPUT_NORMAL;
break;
}
switch(field){
case CHANGE:
input_mode = INPUT_CHANGE;
break;
case DEFINITION:
case FILENAME:
if(totallines == 1){ editref(0); }
break;
} }
curdispline = 0; curdispline = 0;
@ -78,7 +94,6 @@ static int rebuild_reference(){
postmsg(""); /* clear any previous message */ postmsg(""); /* clear any previous message */
totallines = 0; totallines = 0;
disprefs = 0; disprefs = 0;
topline = nextline = 1;
return(true); return(true);
} }