Remove tabs
This commit is contained in:
parent
f5f14dca06
commit
51322bf512
@ -37,10 +37,10 @@
|
||||
char *
|
||||
basename(char *path)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if ((s = strrchr(path, '/')) != 0) {
|
||||
return(s + 1);
|
||||
}
|
||||
return(path);
|
||||
char *s;
|
||||
|
||||
if ((s = strrchr(path, '/')) != 0) {
|
||||
return(s + 1);
|
||||
}
|
||||
return(path);
|
||||
}
|
||||
|
774
src/build.c
774
src/build.c
@ -31,19 +31,19 @@
|
||||
=========================================================================*/
|
||||
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* main functions
|
||||
* main functions
|
||||
*/
|
||||
|
||||
#include "build.h"
|
||||
|
||||
#include "global.h" /* FIXME: get rid of this! */
|
||||
#include "global.h" /* FIXME: get rid of this! */
|
||||
|
||||
#include "library.h"
|
||||
|
||||
#include "scanner.h"
|
||||
#include "version.h" /* for FILEVERSION */
|
||||
#include "version.h" /* for FILEVERSION */
|
||||
#include "vp.h"
|
||||
|
||||
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
|
||||
@ -54,43 +54,43 @@
|
||||
|
||||
/* Exported variables: */
|
||||
|
||||
BOOL buildonly = NO; /* only build the database */
|
||||
BOOL unconditional = NO; /* unconditionally build database */
|
||||
BOOL fileschanged; /* assume some files changed */
|
||||
BOOL buildonly = NO; /* only build the database */
|
||||
BOOL unconditional = NO; /* unconditionally build database */
|
||||
BOOL fileschanged; /* assume some files changed */
|
||||
|
||||
/* variable copies of the master strings... */
|
||||
char invname_buf[] = INVNAME;
|
||||
char invpost_buf[] = INVPOST;
|
||||
char reffile_buf[] = REFFILE;
|
||||
char *invname = invname_buf; /* inverted index to the database */
|
||||
char *invpost = invpost_buf; /* inverted index postings */
|
||||
char *reffile = reffile_buf; /* cross-reference file path name */
|
||||
char invname_buf[] = INVNAME;
|
||||
char invpost_buf[] = INVPOST;
|
||||
char reffile_buf[] = REFFILE;
|
||||
char *invname = invname_buf; /* inverted index to the database */
|
||||
char *invpost = invpost_buf; /* inverted index postings */
|
||||
char *reffile = reffile_buf; /* cross-reference file path name */
|
||||
|
||||
char *newreffile; /* new cross-reference file name */
|
||||
FILE *newrefs; /* new cross-reference */
|
||||
FILE *postings; /* new inverted index postings */
|
||||
int symrefs = -1; /* cross-reference file */
|
||||
char *newreffile; /* new cross-reference file name */
|
||||
FILE *newrefs; /* new cross-reference */
|
||||
FILE *postings; /* new inverted index postings */
|
||||
int symrefs = -1; /* cross-reference file */
|
||||
|
||||
INVCONTROL invcontrol; /* inverted file control structure */
|
||||
INVCONTROL invcontrol; /* inverted file control structure */
|
||||
|
||||
|
||||
/* Local variables: */
|
||||
static char *newinvname; /* new inverted index file name */
|
||||
static char *newinvpost; /* new inverted index postings file name */
|
||||
static long traileroffset; /* file trailer offset */
|
||||
static char *newinvname; /* new inverted index file name */
|
||||
static char *newinvpost; /* new inverted index postings file name */
|
||||
static long traileroffset; /* file trailer offset */
|
||||
|
||||
|
||||
/* Internal prototypes: */
|
||||
static void cannotindex(void);
|
||||
static int compare(const void *s1, const void *s2);
|
||||
static void copydata(void);
|
||||
static void copyinverted(void);
|
||||
static char *getoldfile(void);
|
||||
static void movefile(char *new, char *old);
|
||||
static void putheader(char *dir);
|
||||
static void fetch_include_from_dbase(char *, size_t);
|
||||
static void putlist(char **names, int count);
|
||||
static BOOL samelist(FILE *oldrefs, char **names, int count);
|
||||
static void cannotindex(void);
|
||||
static int compare(const void *s1, const void *s2);
|
||||
static void copydata(void);
|
||||
static void copyinverted(void);
|
||||
static char *getoldfile(void);
|
||||
static void movefile(char *new, char *old);
|
||||
static void putheader(char *dir);
|
||||
static void fetch_include_from_dbase(char *, size_t);
|
||||
static void putlist(char **names, int count);
|
||||
static BOOL samelist(FILE *oldrefs, char **names, int count);
|
||||
|
||||
|
||||
/* Error handling routine if inverted index creation fails */
|
||||
@ -103,7 +103,7 @@ cscope: cannot create inverted index; ignoring -q option\n");
|
||||
errorsfound = YES;
|
||||
fprintf(stderr, "\
|
||||
cscope: removed files %s and %s\n",
|
||||
newinvname, newinvpost);
|
||||
newinvname, newinvpost);
|
||||
unlink(newinvname);
|
||||
unlink(newinvpost);
|
||||
}
|
||||
@ -119,15 +119,15 @@ samelist(FILE *oldrefs, char **names, int count)
|
||||
|
||||
/* see if the number of names is the same */
|
||||
if (fscanf(oldrefs, "%d", &oldcount) != 1 ||
|
||||
oldcount != count) {
|
||||
return(NO);
|
||||
oldcount != count) {
|
||||
return(NO);
|
||||
}
|
||||
/* see if the name list is the same */
|
||||
for (i = 0; i < count; ++i) {
|
||||
if ((1 != fscanf(oldrefs," %[^\n]",oldname)) ||
|
||||
strnotequal(oldname, names[i])) {
|
||||
return(NO);
|
||||
}
|
||||
if ((1 != fscanf(oldrefs," %[^\n]",oldname)) ||
|
||||
strnotequal(oldname, names[i])) {
|
||||
return(NO);
|
||||
}
|
||||
}
|
||||
return(YES);
|
||||
}
|
||||
@ -137,8 +137,8 @@ samelist(FILE *oldrefs, char **names, int count)
|
||||
|
||||
void setup_build_filenames(char *reffile)
|
||||
{
|
||||
char *path; /* file pathname */
|
||||
char *s; /* pointer to basename in path */
|
||||
char *path; /* file pathname */
|
||||
char *s; /* pointer to basename in path */
|
||||
|
||||
path = malloc(strlen(reffile) + 10u);
|
||||
strcpy(path, reffile);
|
||||
@ -161,16 +161,16 @@ void
|
||||
opendatabase(void)
|
||||
{
|
||||
if ((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
|
||||
cannotopen(reffile);
|
||||
myexit(1);
|
||||
cannotopen(reffile);
|
||||
myexit(1);
|
||||
}
|
||||
blocknumber = -1; /* force next seek to read the first block */
|
||||
|
||||
blocknumber = -1; /* force next seek to read the first block */
|
||||
|
||||
/* open any inverted index */
|
||||
if (invertedindex == YES &&
|
||||
invopen(&invcontrol, invname, invpost, INVAVAIL) == -1) {
|
||||
askforreturn(); /* so user sees message */
|
||||
invertedindex = NO;
|
||||
invopen(&invcontrol, invname, invpost, INVAVAIL) == -1) {
|
||||
askforreturn(); /* so user sees message */
|
||||
invertedindex = NO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,17 +181,17 @@ rebuild(void)
|
||||
{
|
||||
close(symrefs);
|
||||
if (invertedindex == YES) {
|
||||
invclose(&invcontrol);
|
||||
nsrcoffset = 0;
|
||||
npostings = 0;
|
||||
invclose(&invcontrol);
|
||||
nsrcoffset = 0;
|
||||
npostings = 0;
|
||||
}
|
||||
build();
|
||||
opendatabase();
|
||||
|
||||
/* revert to the initial display */
|
||||
if (refsfound != NULL) {
|
||||
fclose(refsfound);
|
||||
refsfound = NULL;
|
||||
fclose(refsfound);
|
||||
refsfound = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,29 +201,29 @@ void
|
||||
build(void)
|
||||
{
|
||||
unsigned long i;
|
||||
FILE *oldrefs; /* old cross-reference file */
|
||||
time_t reftime; /* old crossref modification time */
|
||||
char *file; /* current file */
|
||||
char *oldfile; /* file in old cross-reference */
|
||||
FILE *oldrefs; /* old cross-reference file */
|
||||
time_t reftime; /* old crossref modification time */
|
||||
char *file; /* current file */
|
||||
char *oldfile; /* file in old cross-reference */
|
||||
char newdir[PATHLEN + 1]; /* directory in new cross-reference */
|
||||
char olddir[PATHLEN + 1]; /* directory in old cross-reference */
|
||||
char oldname[PATHLEN + 1]; /* name in old cross-reference */
|
||||
unsigned long oldnum; /* number in old cross-ref */
|
||||
struct stat statstruct; /* file status */
|
||||
unsigned long firstfile; /* first source file in pass */
|
||||
unsigned long lastfile; /* last source file in pass */
|
||||
int built = 0; /* built crossref for these files */
|
||||
int copied = 0; /* copied crossref for these files */
|
||||
unsigned long fileindex; /* source file name index */
|
||||
BOOL interactive = YES; /* output progress messages */
|
||||
unsigned long oldnum; /* number in old cross-ref */
|
||||
struct stat statstruct; /* file status */
|
||||
unsigned long firstfile; /* first source file in pass */
|
||||
unsigned long lastfile; /* last source file in pass */
|
||||
int built = 0; /* built crossref for these files */
|
||||
int copied = 0; /* copied crossref for these files */
|
||||
unsigned long fileindex; /* source file name index */
|
||||
BOOL interactive = YES; /* output progress messages */
|
||||
|
||||
/* normalize the current directory relative to the home directory so
|
||||
the cross-reference is not rebuilt when the user's login is moved */
|
||||
strcpy(newdir, currentdir);
|
||||
if (strcmp(currentdir, home) == 0) {
|
||||
strcpy(newdir, "$HOME");
|
||||
strcpy(newdir, "$HOME");
|
||||
} else if (strncmp(currentdir, home, strlen(home)) == 0) {
|
||||
snprintf(newdir, sizeof(newdir), "$HOME%s", currentdir + strlen(home));
|
||||
snprintf(newdir, sizeof(newdir), "$HOME%s", currentdir + strlen(home));
|
||||
}
|
||||
/* sort the source file names (needed for rebuilding) */
|
||||
qsort(srcfiles, nsrcfiles, sizeof(*srcfiles), compare);
|
||||
@ -231,133 +231,133 @@ build(void)
|
||||
/* if there is an old cross-reference and its current directory matches */
|
||||
/* or this is an unconditional build */
|
||||
if ((oldrefs = vpfopen(reffile, "rb")) != NULL
|
||||
&& unconditional == NO
|
||||
&& fscanf(oldrefs, "cscope %d %" PATHLEN_STR "s", &fileversion, olddir) == 2
|
||||
&& (strcmp(olddir, currentdir) == 0 /* remain compatible */
|
||||
|| strcmp(olddir, newdir) == 0)) {
|
||||
/* get the cross-reference file's modification time */
|
||||
fstat(fileno(oldrefs), &statstruct);
|
||||
reftime = statstruct.st_mtime;
|
||||
if (fileversion >= 8) {
|
||||
BOOL oldcompress = YES;
|
||||
BOOL oldinvertedindex = NO;
|
||||
BOOL oldtruncate = NO;
|
||||
int c;
|
||||
&& unconditional == NO
|
||||
&& fscanf(oldrefs, "cscope %d %" PATHLEN_STR "s", &fileversion, olddir) == 2
|
||||
&& (strcmp(olddir, currentdir) == 0 /* remain compatible */
|
||||
|| strcmp(olddir, newdir) == 0)) {
|
||||
/* get the cross-reference file's modification time */
|
||||
fstat(fileno(oldrefs), &statstruct);
|
||||
reftime = statstruct.st_mtime;
|
||||
if (fileversion >= 8) {
|
||||
BOOL oldcompress = YES;
|
||||
BOOL oldinvertedindex = NO;
|
||||
BOOL oldtruncate = NO;
|
||||
int c;
|
||||
|
||||
/* see if there are options in the database */
|
||||
for (;;) {
|
||||
while((c = getc(oldrefs)) == ' ')
|
||||
; /* do nothing */
|
||||
if (c != '-') {
|
||||
ungetc(c, oldrefs);
|
||||
break;
|
||||
}
|
||||
switch (getc(oldrefs)) {
|
||||
case 'c': /* ASCII characters only */
|
||||
oldcompress = NO;
|
||||
break;
|
||||
case 'q': /* quick search */
|
||||
oldinvertedindex = YES;
|
||||
fscanf(oldrefs, "%ld", &totalterms);
|
||||
break;
|
||||
case 'T': /* truncate symbols to 8 characters */
|
||||
oldtruncate = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* check the old and new option settings */
|
||||
if (oldcompress != compress || oldtruncate != trun_syms) {
|
||||
posterr("\
|
||||
/* see if there are options in the database */
|
||||
for (;;) {
|
||||
while((c = getc(oldrefs)) == ' ')
|
||||
; /* do nothing */
|
||||
if (c != '-') {
|
||||
ungetc(c, oldrefs);
|
||||
break;
|
||||
}
|
||||
switch (getc(oldrefs)) {
|
||||
case 'c': /* ASCII characters only */
|
||||
oldcompress = NO;
|
||||
break;
|
||||
case 'q': /* quick search */
|
||||
oldinvertedindex = YES;
|
||||
fscanf(oldrefs, "%ld", &totalterms);
|
||||
break;
|
||||
case 'T': /* truncate symbols to 8 characters */
|
||||
oldtruncate = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* check the old and new option settings */
|
||||
if (oldcompress != compress || oldtruncate != trun_syms) {
|
||||
posterr("\
|
||||
cscope: -c or -T option mismatch between command line and old symbol database\n");
|
||||
goto force;
|
||||
}
|
||||
if (oldinvertedindex != invertedindex) {
|
||||
posterr("\
|
||||
goto force;
|
||||
}
|
||||
if (oldinvertedindex != invertedindex) {
|
||||
posterr("\
|
||||
cscope: -q option mismatch between command line and old symbol database\n");
|
||||
if (invertedindex == NO) {
|
||||
posterr("cscope: removed files %s and %s\n",
|
||||
invname, invpost);
|
||||
unlink(invname);
|
||||
unlink(invpost);
|
||||
}
|
||||
goto outofdate;
|
||||
}
|
||||
/* seek to the trailer */
|
||||
if (fscanf(oldrefs, "%ld", &traileroffset) != 1 ||
|
||||
fseek(oldrefs, traileroffset, SEEK_SET) == -1) {
|
||||
posterr("cscope: incorrect symbol database file format\n");
|
||||
goto force;
|
||||
}
|
||||
}
|
||||
/* if assuming that some files have changed */
|
||||
if (fileschanged == YES) {
|
||||
goto outofdate;
|
||||
}
|
||||
/* see if the directory lists are the same */
|
||||
if (samelist(oldrefs, srcdirs, nsrcdirs) == NO
|
||||
|| samelist(oldrefs, incdirs, nincdirs) == NO
|
||||
/* get the old number of files */
|
||||
|| fscanf(oldrefs, "%lu", &oldnum) != 1
|
||||
/* skip the string space size */
|
||||
|| (fileversion >= 9 && fscanf(oldrefs, "%*s") != 0)) {
|
||||
goto outofdate;
|
||||
}
|
||||
/* see if the list of source files is the same and
|
||||
none have been changed up to the included files */
|
||||
for (i = 0; i < nsrcfiles; ++i) {
|
||||
if ((1 != fscanf(oldrefs," %[^\n]",oldname))
|
||||
|| strnotequal(oldname, srcfiles[i])
|
||||
|| (lstat(srcfiles[i], &statstruct) != 0)
|
||||
|| (statstruct.st_mtime > reftime)
|
||||
) {
|
||||
goto outofdate;
|
||||
}
|
||||
}
|
||||
/* the old cross-reference is up-to-date */
|
||||
/* so get the list of included files */
|
||||
while (i++ < oldnum && fgets(oldname, sizeof(oldname), oldrefs)) {
|
||||
addsrcfile(oldname);
|
||||
}
|
||||
fclose(oldrefs);
|
||||
return;
|
||||
|
||||
if (invertedindex == NO) {
|
||||
posterr("cscope: removed files %s and %s\n",
|
||||
invname, invpost);
|
||||
unlink(invname);
|
||||
unlink(invpost);
|
||||
}
|
||||
goto outofdate;
|
||||
}
|
||||
/* seek to the trailer */
|
||||
if (fscanf(oldrefs, "%ld", &traileroffset) != 1 ||
|
||||
fseek(oldrefs, traileroffset, SEEK_SET) == -1) {
|
||||
posterr("cscope: incorrect symbol database file format\n");
|
||||
goto force;
|
||||
}
|
||||
}
|
||||
/* if assuming that some files have changed */
|
||||
if (fileschanged == YES) {
|
||||
goto outofdate;
|
||||
}
|
||||
/* see if the directory lists are the same */
|
||||
if (samelist(oldrefs, srcdirs, nsrcdirs) == NO
|
||||
|| samelist(oldrefs, incdirs, nincdirs) == NO
|
||||
/* get the old number of files */
|
||||
|| fscanf(oldrefs, "%lu", &oldnum) != 1
|
||||
/* skip the string space size */
|
||||
|| (fileversion >= 9 && fscanf(oldrefs, "%*s") != 0)) {
|
||||
goto outofdate;
|
||||
}
|
||||
/* see if the list of source files is the same and
|
||||
none have been changed up to the included files */
|
||||
for (i = 0; i < nsrcfiles; ++i) {
|
||||
if ((1 != fscanf(oldrefs," %[^\n]",oldname))
|
||||
|| strnotequal(oldname, srcfiles[i])
|
||||
|| (lstat(srcfiles[i], &statstruct) != 0)
|
||||
|| (statstruct.st_mtime > reftime)
|
||||
) {
|
||||
goto outofdate;
|
||||
}
|
||||
}
|
||||
/* the old cross-reference is up-to-date */
|
||||
/* so get the list of included files */
|
||||
while (i++ < oldnum && fgets(oldname, sizeof(oldname), oldrefs)) {
|
||||
addsrcfile(oldname);
|
||||
}
|
||||
fclose(oldrefs);
|
||||
return;
|
||||
|
||||
outofdate:
|
||||
/* if the database format has changed, rebuild it all */
|
||||
if (fileversion != FILEVERSION) {
|
||||
fprintf(stderr, "\
|
||||
/* if the database format has changed, rebuild it all */
|
||||
if (fileversion != FILEVERSION) {
|
||||
fprintf(stderr, "\
|
||||
cscope: converting to new symbol database file format\n");
|
||||
goto force;
|
||||
}
|
||||
/* reopen the old cross-reference file for fast scanning */
|
||||
if ((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
|
||||
postfatal("cscope: cannot open file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
/* get the first file name in the old cross-reference */
|
||||
blocknumber = -1;
|
||||
read_block(); /* read the first cross-ref block */
|
||||
scanpast('\t'); /* skip the header */
|
||||
oldfile = getoldfile();
|
||||
} else { /* force cross-referencing of all the source files */
|
||||
force:
|
||||
reftime = 0;
|
||||
oldfile = NULL;
|
||||
goto force;
|
||||
}
|
||||
/* reopen the old cross-reference file for fast scanning */
|
||||
if ((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
|
||||
postfatal("cscope: cannot open file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
/* get the first file name in the old cross-reference */
|
||||
blocknumber = -1;
|
||||
read_block(); /* read the first cross-ref block */
|
||||
scanpast('\t'); /* skip the header */
|
||||
oldfile = getoldfile();
|
||||
} else { /* force cross-referencing of all the source files */
|
||||
force:
|
||||
reftime = 0;
|
||||
oldfile = NULL;
|
||||
}
|
||||
/* open the new cross-reference file */
|
||||
if ((newrefs = myfopen(newreffile, "wb")) == NULL) {
|
||||
postfatal("cscope: cannot open file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
postfatal("cscope: cannot open file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (invertedindex == YES && (postings = myfopen(temp1, "wb")) == NULL) {
|
||||
cannotwrite(temp1);
|
||||
cannotindex();
|
||||
cannotwrite(temp1);
|
||||
cannotindex();
|
||||
}
|
||||
putheader(newdir);
|
||||
fileversion = FILEVERSION;
|
||||
if (buildonly == YES && verbosemode != YES && !isatty(0)) {
|
||||
interactive = NO;
|
||||
interactive = NO;
|
||||
} else {
|
||||
searchcount = 0;
|
||||
searchcount = 0;
|
||||
}
|
||||
/* output the leading tab expected by crossref() */
|
||||
dbputc('\t');
|
||||
@ -367,125 +367,125 @@ cscope: converting to new symbol database file format\n");
|
||||
firstfile = 0;
|
||||
lastfile = nsrcfiles;
|
||||
if (invertedindex == YES) {
|
||||
srcoffset = malloc((nsrcfiles + 1u) * sizeof(*srcoffset));
|
||||
srcoffset = malloc((nsrcfiles + 1u) * sizeof(*srcoffset));
|
||||
}
|
||||
for (;;) {
|
||||
progress("Building symbol database", (long)built,
|
||||
(long)lastfile);
|
||||
if (linemode == NO)
|
||||
refresh();
|
||||
progress("Building symbol database", (long)built,
|
||||
(long)lastfile);
|
||||
if (linemode == NO)
|
||||
refresh();
|
||||
|
||||
/* get the next source file name */
|
||||
for (fileindex = firstfile; fileindex < lastfile; ++fileindex) {
|
||||
|
||||
/* display the progress about every three seconds */
|
||||
if (interactive == YES && fileindex % 10 == 0) {
|
||||
progress("Building symbol database", fileindex, lastfile);
|
||||
}
|
||||
/* if the old file has been deleted get the next one */
|
||||
file = srcfiles[fileindex];
|
||||
while (oldfile != NULL && strcmp(file, oldfile) > 0) {
|
||||
oldfile = getoldfile();
|
||||
}
|
||||
/* if there isn't an old database or this is a new file */
|
||||
if (oldfile == NULL || strcmp(file, oldfile) < 0) {
|
||||
crossref(file);
|
||||
++built;
|
||||
} else if (lstat(file, &statstruct) == 0
|
||||
&& statstruct.st_mtime > reftime) {
|
||||
/* if this file was modified */
|
||||
crossref(file);
|
||||
++built;
|
||||
|
||||
/* skip its old crossref so modifying the last source
|
||||
* file does not cause all included files to be built.
|
||||
* Unfortunately a new file that is alphabetically
|
||||
* last will cause all included files to be build, but
|
||||
* this is less likely */
|
||||
oldfile = getoldfile();
|
||||
} else {
|
||||
/* copy its cross-reference */
|
||||
putfilename(file);
|
||||
if (invertedindex == YES) {
|
||||
copyinverted();
|
||||
} else {
|
||||
copydata();
|
||||
}
|
||||
++copied;
|
||||
oldfile = getoldfile();
|
||||
}
|
||||
}
|
||||
/* see if any included files were found */
|
||||
if (lastfile == nsrcfiles) {
|
||||
break;
|
||||
}
|
||||
firstfile = lastfile;
|
||||
lastfile = nsrcfiles;
|
||||
if (invertedindex == YES) {
|
||||
srcoffset = realloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset));
|
||||
}
|
||||
/* sort the included file names */
|
||||
qsort(srcfiles + firstfile, lastfile - firstfile, sizeof(*srcfiles), compare);
|
||||
/* get the next source file name */
|
||||
for (fileindex = firstfile; fileindex < lastfile; ++fileindex) {
|
||||
|
||||
/* display the progress about every three seconds */
|
||||
if (interactive == YES && fileindex % 10 == 0) {
|
||||
progress("Building symbol database", fileindex, lastfile);
|
||||
}
|
||||
/* if the old file has been deleted get the next one */
|
||||
file = srcfiles[fileindex];
|
||||
while (oldfile != NULL && strcmp(file, oldfile) > 0) {
|
||||
oldfile = getoldfile();
|
||||
}
|
||||
/* if there isn't an old database or this is a new file */
|
||||
if (oldfile == NULL || strcmp(file, oldfile) < 0) {
|
||||
crossref(file);
|
||||
++built;
|
||||
} else if (lstat(file, &statstruct) == 0
|
||||
&& statstruct.st_mtime > reftime) {
|
||||
/* if this file was modified */
|
||||
crossref(file);
|
||||
++built;
|
||||
|
||||
/* skip its old crossref so modifying the last source
|
||||
* file does not cause all included files to be built.
|
||||
* Unfortunately a new file that is alphabetically
|
||||
* last will cause all included files to be build, but
|
||||
* this is less likely */
|
||||
oldfile = getoldfile();
|
||||
} else {
|
||||
/* copy its cross-reference */
|
||||
putfilename(file);
|
||||
if (invertedindex == YES) {
|
||||
copyinverted();
|
||||
} else {
|
||||
copydata();
|
||||
}
|
||||
++copied;
|
||||
oldfile = getoldfile();
|
||||
}
|
||||
}
|
||||
/* see if any included files were found */
|
||||
if (lastfile == nsrcfiles) {
|
||||
break;
|
||||
}
|
||||
firstfile = lastfile;
|
||||
lastfile = nsrcfiles;
|
||||
if (invertedindex == YES) {
|
||||
srcoffset = realloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset));
|
||||
}
|
||||
/* sort the included file names */
|
||||
qsort(srcfiles + firstfile, lastfile - firstfile, sizeof(*srcfiles), compare);
|
||||
}
|
||||
/* add a null file name to the trailing tab */
|
||||
putfilename("");
|
||||
dbputc('\n');
|
||||
|
||||
|
||||
/* get the file trailer offset */
|
||||
traileroffset = dboffset;
|
||||
|
||||
|
||||
/* output the source and include directory and file lists */
|
||||
putlist(srcdirs, nsrcdirs);
|
||||
putlist(incdirs, nincdirs);
|
||||
putlist(srcfiles, nsrcfiles);
|
||||
if (fflush(newrefs) == EOF) {
|
||||
/* rewind doesn't check for write failure */
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
/* rewind doesn't check for write failure */
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* create the inverted index if requested */
|
||||
if (invertedindex == YES) {
|
||||
char sortcommand[PATHLEN + 1];
|
||||
char sortcommand[PATHLEN + 1];
|
||||
|
||||
if (fflush(postings) == EOF) {
|
||||
cannotwrite(temp1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
fstat(fileno(postings), &statstruct);
|
||||
fclose(postings);
|
||||
snprintf(sortcommand, sizeof(sortcommand), "env LC_ALL=C sort -T %s %s", tmpdir, temp1);
|
||||
if ((postings = mypopen(sortcommand, "r")) == NULL) {
|
||||
fprintf(stderr, "cscope: cannot open pipe to sort command\n");
|
||||
cannotindex();
|
||||
} else {
|
||||
if ((totalterms = invmake(newinvname, newinvpost, postings)) > 0) {
|
||||
movefile(newinvname, invname);
|
||||
movefile(newinvpost, invpost);
|
||||
} else {
|
||||
cannotindex();
|
||||
}
|
||||
mypclose(postings);
|
||||
}
|
||||
unlink(temp1);
|
||||
free(srcoffset);
|
||||
if (fflush(postings) == EOF) {
|
||||
cannotwrite(temp1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
fstat(fileno(postings), &statstruct);
|
||||
fclose(postings);
|
||||
snprintf(sortcommand, sizeof(sortcommand), "env LC_ALL=C sort -T %s %s", tmpdir, temp1);
|
||||
if ((postings = mypopen(sortcommand, "r")) == NULL) {
|
||||
fprintf(stderr, "cscope: cannot open pipe to sort command\n");
|
||||
cannotindex();
|
||||
} else {
|
||||
if ((totalterms = invmake(newinvname, newinvpost, postings)) > 0) {
|
||||
movefile(newinvname, invname);
|
||||
movefile(newinvpost, invpost);
|
||||
} else {
|
||||
cannotindex();
|
||||
}
|
||||
mypclose(postings);
|
||||
}
|
||||
unlink(temp1);
|
||||
free(srcoffset);
|
||||
}
|
||||
/* rewrite the header with the trailer offset and final option list */
|
||||
rewind(newrefs);
|
||||
putheader(newdir);
|
||||
fclose(newrefs);
|
||||
|
||||
|
||||
/* close the old database file */
|
||||
if (symrefs >= 0) {
|
||||
close(symrefs);
|
||||
close(symrefs);
|
||||
}
|
||||
if (oldrefs != NULL) {
|
||||
fclose(oldrefs);
|
||||
fclose(oldrefs);
|
||||
}
|
||||
/* replace it with the new database file */
|
||||
movefile(newreffile, reffile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* string comparison function for qsort */
|
||||
static int
|
||||
@ -493,7 +493,7 @@ compare(const void *arg_s1, const void *arg_s2)
|
||||
{
|
||||
const char **s1 = (const char **) arg_s1;
|
||||
const char **s2 = (const char **) arg_s2;
|
||||
|
||||
|
||||
return(strcmp(*s1, *s2));
|
||||
}
|
||||
|
||||
@ -503,12 +503,12 @@ void
|
||||
seek_to_trailer(FILE *f)
|
||||
{
|
||||
if (fscanf(f, "%ld", &traileroffset) != 1) {
|
||||
postfatal("cscope: cannot read trailer offset from file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
postfatal("cscope: cannot read trailer offset from file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (fseek(f, traileroffset, SEEK_SET) == -1) {
|
||||
postfatal("cscope: cannot seek to trailer in file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
postfatal("cscope: cannot seek to trailer in file %s\n", reffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,19 +517,19 @@ seek_to_trailer(FILE *f)
|
||||
static char *
|
||||
getoldfile(void)
|
||||
{
|
||||
static char file[PATHLEN + 1]; /* file name in old crossref */
|
||||
static char file[PATHLEN + 1]; /* file name in old crossref */
|
||||
|
||||
if (blockp != NULL) {
|
||||
do {
|
||||
if (*blockp == NEWFILE) {
|
||||
skiprefchar();
|
||||
fetch_string_from_dbase(file, sizeof(file));
|
||||
if (file[0] != '\0') { /* if not end-of-crossref */
|
||||
return(file);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
} while (scanpast('\t') != NULL);
|
||||
do {
|
||||
if (*blockp == NEWFILE) {
|
||||
skiprefchar();
|
||||
fetch_string_from_dbase(file, sizeof(file));
|
||||
if (file[0] != '\0') { /* if not end-of-crossref */
|
||||
return(file);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
} while (scanpast('\t') != NULL);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
@ -541,7 +541,7 @@ void free_newbuildfiles(void)
|
||||
free(newinvname);
|
||||
free(newinvpost);
|
||||
free(newreffile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* output the cscope version, current directory, database format options, and
|
||||
@ -551,18 +551,18 @@ putheader(char *dir)
|
||||
{
|
||||
dboffset = fprintf(newrefs, "cscope %d %s", FILEVERSION, dir);
|
||||
if (compress == NO) {
|
||||
dboffset += fprintf(newrefs, " -c");
|
||||
dboffset += fprintf(newrefs, " -c");
|
||||
}
|
||||
if (invertedindex == YES) {
|
||||
dboffset += fprintf(newrefs, " -q %.10ld", totalterms);
|
||||
} else {
|
||||
/* leave space so if the header is overwritten without -q
|
||||
* because writing the inverted index failed, the header
|
||||
* is the same length */
|
||||
dboffset += fprintf(newrefs, " ");
|
||||
dboffset += fprintf(newrefs, " -q %.10ld", totalterms);
|
||||
} else {
|
||||
/* leave space so if the header is overwritten without -q
|
||||
* because writing the inverted index failed, the header
|
||||
* is the same length */
|
||||
dboffset += fprintf(newrefs, " ");
|
||||
}
|
||||
if (trun_syms == YES) {
|
||||
dboffset += fprintf(newrefs, " -T");
|
||||
dboffset += fprintf(newrefs, " -T");
|
||||
}
|
||||
|
||||
dboffset += fprintf(newrefs, " %.10ld\n", traileroffset);
|
||||
@ -576,23 +576,23 @@ putheader(char *dir)
|
||||
static void
|
||||
putlist(char **names, int count)
|
||||
{
|
||||
int i, size = 0;
|
||||
|
||||
int i, size = 0;
|
||||
|
||||
fprintf(newrefs, "%d\n", count);
|
||||
if (names == srcfiles) {
|
||||
|
||||
/* calculate the string space needed */
|
||||
for (i = 0; i < count; ++i) {
|
||||
size += strlen(names[i]) + 1;
|
||||
}
|
||||
fprintf(newrefs, "%d\n", size);
|
||||
/* calculate the string space needed */
|
||||
for (i = 0; i < count; ++i) {
|
||||
size += strlen(names[i]) + 1;
|
||||
}
|
||||
fprintf(newrefs, "%d\n", size);
|
||||
}
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (fputs(names[i], newrefs) == EOF ||
|
||||
putc('\n', newrefs) == EOF) {
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (fputs(names[i], newrefs) == EOF ||
|
||||
putc('\n', newrefs) == EOF) {
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,33 +606,33 @@ copydata(void)
|
||||
setmark('\t');
|
||||
cp = blockp;
|
||||
for (;;) {
|
||||
/* copy up to the next \t */
|
||||
do { /* innermost loop optimized to only one test */
|
||||
while (*cp != '\t') {
|
||||
dbputc(*cp++);
|
||||
}
|
||||
} while (*++cp == '\0' && (cp = read_block()) != NULL);
|
||||
dbputc('\t'); /* copy the tab */
|
||||
|
||||
/* get the next character */
|
||||
/* HBB 2010-08-21: potential problem if above loop was left
|
||||
* with cp==NULL */
|
||||
if (cp && (*(cp + 1) == '\0')) {
|
||||
cp = read_block();
|
||||
}
|
||||
/* exit if at the end of this file's data */
|
||||
if (cp == NULL || *cp == NEWFILE) {
|
||||
break;
|
||||
}
|
||||
/* look for an #included file */
|
||||
if (*cp == INCLUDE) {
|
||||
/* copy up to the next \t */
|
||||
do { /* innermost loop optimized to only one test */
|
||||
while (*cp != '\t') {
|
||||
dbputc(*cp++);
|
||||
}
|
||||
} while (*++cp == '\0' && (cp = read_block()) != NULL);
|
||||
dbputc('\t'); /* copy the tab */
|
||||
|
||||
/* get the next character */
|
||||
/* HBB 2010-08-21: potential problem if above loop was left
|
||||
* with cp==NULL */
|
||||
if (cp && (*(cp + 1) == '\0')) {
|
||||
cp = read_block();
|
||||
}
|
||||
/* exit if at the end of this file's data */
|
||||
if (cp == NULL || *cp == NEWFILE) {
|
||||
break;
|
||||
}
|
||||
/* look for an #included file */
|
||||
if (*cp == INCLUDE) {
|
||||
char symbol[PATLEN + 1];
|
||||
blockp = cp;
|
||||
fetch_include_from_dbase(symbol, sizeof(symbol));
|
||||
writestring(symbol);
|
||||
setmark('\t');
|
||||
cp = blockp;
|
||||
}
|
||||
blockp = cp;
|
||||
fetch_include_from_dbase(symbol, sizeof(symbol));
|
||||
writestring(symbol);
|
||||
setmark('\t');
|
||||
cp = blockp;
|
||||
}
|
||||
}
|
||||
blockp = cp;
|
||||
}
|
||||
@ -652,61 +652,61 @@ copyinverted(void)
|
||||
/* other macros were replaced by code using cp instead of blockp */
|
||||
cp = blockp;
|
||||
for (;;) {
|
||||
setmark('\n');
|
||||
do { /* innermost loop optimized to only one test */
|
||||
while (*cp != '\n') {
|
||||
dbputc(*cp++);
|
||||
}
|
||||
} while (*++cp == '\0' && (cp = read_block()) != NULL);
|
||||
dbputc('\n'); /* copy the newline */
|
||||
|
||||
/* get the next character */
|
||||
/* HBB 2010-08-21: potential problem if above loop was left
|
||||
* with cp==NULL */
|
||||
if (cp && (*(cp + 1) == '\0')) {
|
||||
cp = read_block();
|
||||
}
|
||||
/* exit if at the end of this file's data */
|
||||
if (cp == NULL) {
|
||||
break;
|
||||
}
|
||||
switch (*cp) {
|
||||
case '\n':
|
||||
lineoffset = dboffset + 1;
|
||||
continue;
|
||||
case '\t':
|
||||
dbputc('\t');
|
||||
blockp = cp;
|
||||
type = getrefchar();
|
||||
switch (type) {
|
||||
case NEWFILE: /* file name */
|
||||
return;
|
||||
case INCLUDE: /* #included file */
|
||||
fetch_include_from_dbase(symbol, sizeof(symbol));
|
||||
goto output;
|
||||
}
|
||||
dbputc(type);
|
||||
skiprefchar();
|
||||
fetch_string_from_dbase(symbol, sizeof(symbol));
|
||||
goto output;
|
||||
}
|
||||
c = *cp;
|
||||
if (c & 0200) { /* digraph char? */
|
||||
c = dichar1[(c & 0177) / 8];
|
||||
}
|
||||
/* if this is a symbol */
|
||||
if (isalpha((unsigned char)c) || c == '_') {
|
||||
blockp = cp;
|
||||
fetch_string_from_dbase(symbol, sizeof(symbol));
|
||||
type = ' ';
|
||||
output:
|
||||
putposting(symbol, type);
|
||||
writestring(symbol);
|
||||
if (blockp == NULL) {
|
||||
return;
|
||||
}
|
||||
cp = blockp;
|
||||
}
|
||||
setmark('\n');
|
||||
do { /* innermost loop optimized to only one test */
|
||||
while (*cp != '\n') {
|
||||
dbputc(*cp++);
|
||||
}
|
||||
} while (*++cp == '\0' && (cp = read_block()) != NULL);
|
||||
dbputc('\n'); /* copy the newline */
|
||||
|
||||
/* get the next character */
|
||||
/* HBB 2010-08-21: potential problem if above loop was left
|
||||
* with cp==NULL */
|
||||
if (cp && (*(cp + 1) == '\0')) {
|
||||
cp = read_block();
|
||||
}
|
||||
/* exit if at the end of this file's data */
|
||||
if (cp == NULL) {
|
||||
break;
|
||||
}
|
||||
switch (*cp) {
|
||||
case '\n':
|
||||
lineoffset = dboffset + 1;
|
||||
continue;
|
||||
case '\t':
|
||||
dbputc('\t');
|
||||
blockp = cp;
|
||||
type = getrefchar();
|
||||
switch (type) {
|
||||
case NEWFILE: /* file name */
|
||||
return;
|
||||
case INCLUDE: /* #included file */
|
||||
fetch_include_from_dbase(symbol, sizeof(symbol));
|
||||
goto output;
|
||||
}
|
||||
dbputc(type);
|
||||
skiprefchar();
|
||||
fetch_string_from_dbase(symbol, sizeof(symbol));
|
||||
goto output;
|
||||
}
|
||||
c = *cp;
|
||||
if (c & 0200) { /* digraph char? */
|
||||
c = dichar1[(c & 0177) / 8];
|
||||
}
|
||||
/* if this is a symbol */
|
||||
if (isalpha((unsigned char)c) || c == '_') {
|
||||
blockp = cp;
|
||||
fetch_string_from_dbase(symbol, sizeof(symbol));
|
||||
type = ' ';
|
||||
output:
|
||||
putposting(symbol, type);
|
||||
writestring(symbol);
|
||||
if (blockp == NULL) {
|
||||
return;
|
||||
}
|
||||
cp = blockp;
|
||||
}
|
||||
}
|
||||
blockp = cp;
|
||||
}
|
||||
@ -718,10 +718,10 @@ movefile(char *new, char *old)
|
||||
{
|
||||
unlink(old);
|
||||
if (rename(new, old) == -1) {
|
||||
myperror("cscope");
|
||||
postfatal("cscope: cannot rename file %s to file %s\n",
|
||||
new, old);
|
||||
/* NOTREACHED */
|
||||
myperror("cscope");
|
||||
postfatal("cscope: cannot rename file %s to file %s\n",
|
||||
new, old);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
|
40
src/build.h
40
src/build.h
@ -33,38 +33,38 @@
|
||||
#ifndef CSCOPE_BUILD_H
|
||||
#define CSCOPE_BUILD_H
|
||||
|
||||
#include "global.h" /* FIXME: temp. only */
|
||||
#include "global.h" /* FIXME: temp. only */
|
||||
#include "invlib.h"
|
||||
|
||||
/* types and macros of build.c to be used by other modules */
|
||||
|
||||
/* database output macros that update its offset */
|
||||
#define dbputc(c) (++dboffset, (void) putc(c, newrefs))
|
||||
#define dbfputs(s) (dboffset += strlen(s), fputs(s, newrefs))
|
||||
#define dbputc(c) (++dboffset, (void) putc(c, newrefs))
|
||||
#define dbfputs(s) (dboffset += strlen(s), fputs(s, newrefs))
|
||||
|
||||
/* declarations for globals defined in build.c */
|
||||
|
||||
extern BOOL buildonly; /* only build the database */
|
||||
extern BOOL unconditional; /* unconditionally build database */
|
||||
extern BOOL fileschanged; /* assume some files changed */
|
||||
extern BOOL buildonly; /* only build the database */
|
||||
extern BOOL unconditional; /* unconditionally build database */
|
||||
extern BOOL fileschanged; /* assume some files changed */
|
||||
|
||||
extern char *reffile; /* cross-reference file path name */
|
||||
extern char *invname; /* inverted index to the database */
|
||||
extern char *invpost; /* inverted index postings */
|
||||
extern char *newreffile; /* new cross-reference file name */
|
||||
extern FILE *newrefs; /* new cross-reference */
|
||||
extern FILE *postings; /* new inverted index postings */
|
||||
extern int symrefs; /* cross-reference file */
|
||||
extern char *reffile; /* cross-reference file path name */
|
||||
extern char *invname; /* inverted index to the database */
|
||||
extern char *invpost; /* inverted index postings */
|
||||
extern char *newreffile; /* new cross-reference file name */
|
||||
extern FILE *newrefs; /* new cross-reference */
|
||||
extern FILE *postings; /* new inverted index postings */
|
||||
extern int symrefs; /* cross-reference file */
|
||||
|
||||
extern INVCONTROL invcontrol; /* inverted file control structure */
|
||||
extern INVCONTROL invcontrol; /* inverted file control structure */
|
||||
|
||||
/* Prototypes of external functions defined by build.c */
|
||||
|
||||
void build(void);
|
||||
void free_newbuildfiles(void);
|
||||
void opendatabase(void);
|
||||
void rebuild(void);
|
||||
void setup_build_filenames(char *reffile);
|
||||
void seek_to_trailer(FILE *f);
|
||||
void build(void);
|
||||
void free_newbuildfiles(void);
|
||||
void opendatabase(void);
|
||||
void rebuild(void);
|
||||
void setup_build_filenames(char *reffile);
|
||||
void seek_to_trailer(FILE *f);
|
||||
|
||||
#endif /* CSCOPE_BUILD_H */
|
||||
|
216
src/command.c
216
src/command.c
@ -30,13 +30,13 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol or text cross-reference
|
||||
/* cscope - interactive C symbol or text cross-reference
|
||||
*
|
||||
* command functions
|
||||
* command functions
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "build.h" /* for rebuild() */
|
||||
#include "build.h" /* for rebuild() */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -59,23 +59,23 @@ extern const void const* wmode;
|
||||
extern const void const* wresult;
|
||||
extern const void const* const* current_window;
|
||||
|
||||
BOOL caseless; /* ignore letter case when searching */
|
||||
BOOL *change; /* change this line */
|
||||
BOOL changing; /* changing text */
|
||||
char newpat[PATLEN + 1]; /* new pattern */
|
||||
BOOL caseless; /* ignore letter case when searching */
|
||||
BOOL *change; /* change this line */
|
||||
BOOL changing; /* changing text */
|
||||
char newpat[PATLEN + 1]; /* new pattern */
|
||||
|
||||
/* Internal prototypes: */
|
||||
static void clearprompt(void);
|
||||
static void mark(unsigned int i);
|
||||
static void scrollbar(MOUSE *p);
|
||||
static void clearprompt(void);
|
||||
static void mark(unsigned int i);
|
||||
static void scrollbar(MOUSE *p);
|
||||
|
||||
/* clear the prompt line */
|
||||
|
||||
static void
|
||||
clearprompt(void)
|
||||
{
|
||||
move(PRLINE, 0);
|
||||
clrtoeol();
|
||||
move(PRLINE, 0);
|
||||
clrtoeol();
|
||||
}
|
||||
|
||||
/* read references from a file */
|
||||
@ -83,35 +83,35 @@ clearprompt(void)
|
||||
BOOL
|
||||
readrefs(char *filename)
|
||||
{
|
||||
FILE *file;
|
||||
int c;
|
||||
FILE *file;
|
||||
int c;
|
||||
|
||||
if ((file = myfopen(filename, "rb")) == NULL) {
|
||||
cannotopen(filename);
|
||||
return(NO);
|
||||
}
|
||||
if ((c = getc(file)) == EOF) { /* if file is empty */
|
||||
fclose(file);
|
||||
return(NO);
|
||||
}
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
nextline = 1;
|
||||
if (writerefsfound() == YES) {
|
||||
putc(c, refsfound);
|
||||
while ((c = getc(file)) != EOF) {
|
||||
putc(c, refsfound);
|
||||
}
|
||||
fclose(file);
|
||||
fclose(refsfound);
|
||||
if ( (refsfound = myfopen(temp1, "rb")) == NULL) {
|
||||
cannotopen(temp1);
|
||||
return(NO);
|
||||
}
|
||||
countrefs();
|
||||
} else
|
||||
fclose(file);
|
||||
return(YES);
|
||||
if ((file = myfopen(filename, "rb")) == NULL) {
|
||||
cannotopen(filename);
|
||||
return(NO);
|
||||
}
|
||||
if ((c = getc(file)) == EOF) { /* if file is empty */
|
||||
fclose(file);
|
||||
return(NO);
|
||||
}
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
nextline = 1;
|
||||
if (writerefsfound() == YES) {
|
||||
putc(c, refsfound);
|
||||
while ((c = getc(file)) != EOF) {
|
||||
putc(c, refsfound);
|
||||
}
|
||||
fclose(file);
|
||||
fclose(refsfound);
|
||||
if ( (refsfound = myfopen(temp1, "rb")) == NULL) {
|
||||
cannotopen(temp1);
|
||||
return(NO);
|
||||
}
|
||||
countrefs();
|
||||
} else
|
||||
fclose(file);
|
||||
return(YES);
|
||||
}
|
||||
|
||||
/* mark/unmark this displayed line to be changed */
|
||||
@ -119,18 +119,18 @@ static void
|
||||
mark(unsigned int i)
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
|
||||
j = i + topline - 1;
|
||||
if (j < totallines) {
|
||||
move(displine[i], 1);
|
||||
move(displine[i], 1);
|
||||
|
||||
if (change[j] == NO) {
|
||||
change[j] = YES;
|
||||
addch('>');
|
||||
} else {
|
||||
change[j] = NO;
|
||||
addch(' ');
|
||||
}
|
||||
if (change[j] == NO) {
|
||||
change[j] = YES;
|
||||
addch('>');
|
||||
} else {
|
||||
change[j] = NO;
|
||||
addch(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,34 +141,34 @@ scrollbar(MOUSE *p)
|
||||
{
|
||||
/* reposition list if it makes sense */
|
||||
if (totallines == 0) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
switch (p->percent) {
|
||||
|
||||
|
||||
case 101: /* scroll down one page */
|
||||
if (nextline + mdisprefs > totallines) {
|
||||
nextline = totallines - mdisprefs + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
if (nextline + mdisprefs > totallines) {
|
||||
nextline = totallines - mdisprefs + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 102: /* scroll up one page */
|
||||
nextline = topline - mdisprefs;
|
||||
if (nextline < 1) {
|
||||
nextline = 1;
|
||||
}
|
||||
break;
|
||||
nextline = topline - mdisprefs;
|
||||
if (nextline < 1) {
|
||||
nextline = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 103: /* scroll down one line */
|
||||
nextline = topline + 1;
|
||||
break;
|
||||
|
||||
nextline = topline + 1;
|
||||
break;
|
||||
|
||||
case 104: /* scroll up one line */
|
||||
if (topline > 1) {
|
||||
nextline = topline - 1;
|
||||
}
|
||||
break;
|
||||
if (topline > 1) {
|
||||
nextline = topline - 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
nextline = p->percent * totallines / 100;
|
||||
nextline = p->percent * totallines / 100;
|
||||
}
|
||||
seekline(nextline);
|
||||
}
|
||||
@ -192,40 +192,40 @@ countrefs(void)
|
||||
* since it's not used. But it has to be assigned just so the return value
|
||||
* of fscanf will actually reach 4. */
|
||||
while (EOF != (i = fscanf(refsfound,
|
||||
"%" PATHLEN_STR "s%" PATLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
|
||||
file, function, linenum, tempstring
|
||||
)
|
||||
)
|
||||
) {
|
||||
if ( (i != 4)
|
||||
|| !isgraph((unsigned char) *file)
|
||||
|| !isgraph((unsigned char) *function)
|
||||
|| !isdigit((unsigned char) *linenum)
|
||||
) {
|
||||
postmsg("File does not have expected format");
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
return;
|
||||
}
|
||||
if ((i = strlen(pathcomponents(file, dispcomponents))) > filelen) {
|
||||
filelen = i;
|
||||
}
|
||||
if (ogs == YES) {
|
||||
ogsnames(file, &subsystem, &book);
|
||||
if ((i = strlen(subsystem)) > subsystemlen) {
|
||||
subsystemlen = i;
|
||||
}
|
||||
if ((i = strlen(book)) > booklen) {
|
||||
booklen = i;
|
||||
}
|
||||
}
|
||||
if ((i = strlen(function)) > fcnlen) {
|
||||
fcnlen = i;
|
||||
}
|
||||
if ((i = strlen(linenum)) > numlen) {
|
||||
numlen = i;
|
||||
}
|
||||
++totallines;
|
||||
"%" PATHLEN_STR "s%" PATLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
|
||||
file, function, linenum, tempstring
|
||||
)
|
||||
)
|
||||
) {
|
||||
if ( (i != 4)
|
||||
|| !isgraph((unsigned char) *file)
|
||||
|| !isgraph((unsigned char) *function)
|
||||
|| !isdigit((unsigned char) *linenum)
|
||||
) {
|
||||
postmsg("File does not have expected format");
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
return;
|
||||
}
|
||||
if ((i = strlen(pathcomponents(file, dispcomponents))) > filelen) {
|
||||
filelen = i;
|
||||
}
|
||||
if (ogs == YES) {
|
||||
ogsnames(file, &subsystem, &book);
|
||||
if ((i = strlen(subsystem)) > subsystemlen) {
|
||||
subsystemlen = i;
|
||||
}
|
||||
if ((i = strlen(book)) > booklen) {
|
||||
booklen = i;
|
||||
}
|
||||
}
|
||||
if ((i = strlen(function)) > fcnlen) {
|
||||
fcnlen = i;
|
||||
}
|
||||
if ((i = strlen(linenum)) > numlen) {
|
||||
numlen = i;
|
||||
}
|
||||
++totallines;
|
||||
}
|
||||
rewind(refsfound);
|
||||
|
||||
@ -233,18 +233,18 @@ countrefs(void)
|
||||
/* HBB FIXME 20060419: magic number alert! */
|
||||
i = (COLS - 5) / 3;
|
||||
if (ogs == YES) {
|
||||
i = (COLS - 7) / 5;
|
||||
i = (COLS - 7) / 5;
|
||||
}
|
||||
if (filelen > i && i > 4) {
|
||||
filelen = i;
|
||||
filelen = i;
|
||||
}
|
||||
if (subsystemlen > i && i > 9) {
|
||||
subsystemlen = i;
|
||||
subsystemlen = i;
|
||||
}
|
||||
if (booklen > i && i > 4) {
|
||||
booklen = i;
|
||||
booklen = i;
|
||||
}
|
||||
if (fcnlen > i && i > 8) {
|
||||
fcnlen = i;
|
||||
fcnlen = i;
|
||||
}
|
||||
}
|
||||
|
266
src/compath.c
266
src/compath.c
@ -31,181 +31,181 @@
|
||||
=========================================================================*/
|
||||
|
||||
/*
|
||||
* compath(pathname)
|
||||
* compath(pathname)
|
||||
*
|
||||
* This compresses pathnames. All strings of multiple slashes are
|
||||
* changed to a single slash. All occurrences of "./" are removed.
|
||||
* Whenever possible, strings of "/.." are removed together with
|
||||
* the directory names that they follow.
|
||||
* This compresses pathnames. All strings of multiple slashes are
|
||||
* changed to a single slash. All occurrences of "./" are removed.
|
||||
* Whenever possible, strings of "/.." are removed together with
|
||||
* the directory names that they follow.
|
||||
*
|
||||
* WARNING: since pathname is altered by this function, it should
|
||||
* be located in a temporary buffer. This avoids the problem
|
||||
* of accidently changing strings obtained from makefiles
|
||||
* and stored in global structures.
|
||||
* WARNING: since pathname is altered by this function, it should
|
||||
* be located in a temporary buffer. This avoids the problem
|
||||
* of accidently changing strings obtained from makefiles
|
||||
* and stored in global structures.
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
char *
|
||||
compath(char *pathname) /*FDEF*/
|
||||
compath(char *pathname) /*FDEF*/
|
||||
{
|
||||
char *nextchar;
|
||||
char *lastchar;
|
||||
char *sofar;
|
||||
char *pnend;
|
||||
char *nextchar;
|
||||
char *lastchar;
|
||||
char *sofar;
|
||||
char *pnend;
|
||||
|
||||
int pnlen;
|
||||
int pnlen;
|
||||
|
||||
/*
|
||||
* do not change the path if it has no "/"
|
||||
*/
|
||||
/*
|
||||
* do not change the path if it has no "/"
|
||||
*/
|
||||
|
||||
if (strchr(pathname, '/') == NULL)
|
||||
return(pathname);
|
||||
if (strchr(pathname, '/') == NULL)
|
||||
return(pathname);
|
||||
|
||||
/*
|
||||
* find all strings consisting of more than one '/'
|
||||
*/
|
||||
/*
|
||||
* find all strings consisting of more than one '/'
|
||||
*/
|
||||
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((*lastchar == '/') && (*(lastchar - 1) == '/'))
|
||||
{
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((*lastchar == '/') && (*(lastchar - 1) == '/'))
|
||||
{
|
||||
|
||||
/*
|
||||
* find the character after the last slash
|
||||
*/
|
||||
/*
|
||||
* find the character after the last slash
|
||||
*/
|
||||
|
||||
nextchar = lastchar;
|
||||
while (*++lastchar == '/')
|
||||
{
|
||||
}
|
||||
nextchar = lastchar;
|
||||
while (*++lastchar == '/')
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* eliminate the extra slashes by copying
|
||||
* everything after the slashes over the slashes
|
||||
*/
|
||||
/*
|
||||
* eliminate the extra slashes by copying
|
||||
* everything after the slashes over the slashes
|
||||
*/
|
||||
|
||||
sofar = nextchar;
|
||||
while ((*nextchar++ = *lastchar++) != '\0')
|
||||
;
|
||||
lastchar = sofar;
|
||||
}
|
||||
sofar = nextchar;
|
||||
while ((*nextchar++ = *lastchar++) != '\0')
|
||||
;
|
||||
lastchar = sofar;
|
||||
}
|
||||
|
||||
/*
|
||||
* find all strings of "./"
|
||||
*/
|
||||
/*
|
||||
* find all strings of "./"
|
||||
*/
|
||||
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((*lastchar == '/') && (*(lastchar - 1) == '.') &&
|
||||
((lastchar - 1 == pathname) || (*(lastchar - 2) == '/')))
|
||||
{
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((*lastchar == '/') && (*(lastchar - 1) == '.') &&
|
||||
((lastchar - 1 == pathname) || (*(lastchar - 2) == '/')))
|
||||
{
|
||||
|
||||
/*
|
||||
* copy everything after the "./" over the "./"
|
||||
*/
|
||||
/*
|
||||
* copy everything after the "./" over the "./"
|
||||
*/
|
||||
|
||||
nextchar = lastchar - 1;
|
||||
sofar = nextchar;
|
||||
while ((*nextchar++ = *++lastchar) != '\0')
|
||||
;
|
||||
lastchar = sofar;
|
||||
}
|
||||
nextchar = lastchar - 1;
|
||||
sofar = nextchar;
|
||||
while ((*nextchar++ = *++lastchar) != '\0')
|
||||
;
|
||||
lastchar = sofar;
|
||||
}
|
||||
|
||||
/*
|
||||
* find each occurrence of "/.."
|
||||
*/
|
||||
/*
|
||||
* find each occurrence of "/.."
|
||||
*/
|
||||
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((lastchar != pathname) && (*lastchar == '/') &&
|
||||
(*(lastchar + 1) == '.') && (*(lastchar + 2) == '.') &&
|
||||
((*(lastchar + 3) == '/') || (*(lastchar + 3) == '\0')))
|
||||
{
|
||||
for (lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
|
||||
if ((lastchar != pathname) && (*lastchar == '/') &&
|
||||
(*(lastchar + 1) == '.') && (*(lastchar + 2) == '.') &&
|
||||
((*(lastchar + 3) == '/') || (*(lastchar + 3) == '\0')))
|
||||
{
|
||||
|
||||
/*
|
||||
* find the directory name preceding the "/.."
|
||||
*/
|
||||
/*
|
||||
* find the directory name preceding the "/.."
|
||||
*/
|
||||
|
||||
nextchar = lastchar - 1;
|
||||
while ((nextchar != pathname) &&
|
||||
(*(nextchar - 1) != '/'))
|
||||
--nextchar;
|
||||
nextchar = lastchar - 1;
|
||||
while ((nextchar != pathname) &&
|
||||
(*(nextchar - 1) != '/'))
|
||||
--nextchar;
|
||||
|
||||
/*
|
||||
* make sure the preceding directory's name
|
||||
* is not "." or ".."
|
||||
*/
|
||||
/*
|
||||
* make sure the preceding directory's name
|
||||
* is not "." or ".."
|
||||
*/
|
||||
|
||||
if ((*nextchar == '.') &&
|
||||
((*(nextchar + 1) == '/') ||
|
||||
((*(nextchar + 1) == '.') && (*(nextchar + 2) == '/'))))
|
||||
/* EMPTY */;
|
||||
else
|
||||
{
|
||||
if ((*nextchar == '.') &&
|
||||
((*(nextchar + 1) == '/') ||
|
||||
((*(nextchar + 1) == '.') && (*(nextchar + 2) == '/'))))
|
||||
/* EMPTY */;
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* prepare to eliminate either
|
||||
* "dir_name/../" or "dir_name/.."
|
||||
*/
|
||||
/*
|
||||
* prepare to eliminate either
|
||||
* "dir_name/../" or "dir_name/.."
|
||||
*/
|
||||
|
||||
if (*(lastchar + 3) == '/')
|
||||
lastchar += 4;
|
||||
else
|
||||
lastchar += 3;
|
||||
if (*(lastchar + 3) == '/')
|
||||
lastchar += 4;
|
||||
else
|
||||
lastchar += 3;
|
||||
|
||||
/*
|
||||
* copy everything after the "/.." to
|
||||
* before the preceding directory name
|
||||
*/
|
||||
/*
|
||||
* copy everything after the "/.." to
|
||||
* before the preceding directory name
|
||||
*/
|
||||
|
||||
sofar = nextchar - 1;
|
||||
while ((*nextchar++ = *lastchar++) != '\0');
|
||||
|
||||
lastchar = sofar;
|
||||
sofar = nextchar - 1;
|
||||
while ((*nextchar++ = *lastchar++) != '\0');
|
||||
|
||||
lastchar = sofar;
|
||||
|
||||
/*
|
||||
* if the character before what was taken
|
||||
* out is '/', set up to check if the
|
||||
* slash is part of "/.."
|
||||
*/
|
||||
/*
|
||||
* if the character before what was taken
|
||||
* out is '/', set up to check if the
|
||||
* slash is part of "/.."
|
||||
*/
|
||||
|
||||
if ((sofar + 1 != pathname) && (*sofar == '/'))
|
||||
--lastchar;
|
||||
}
|
||||
}
|
||||
if ((sofar + 1 != pathname) && (*sofar == '/'))
|
||||
--lastchar;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if the string is more than a character long and ends
|
||||
* in '/', eliminate the '/'.
|
||||
*/
|
||||
/*
|
||||
* if the string is more than a character long and ends
|
||||
* in '/', eliminate the '/'.
|
||||
*/
|
||||
|
||||
pnlen = strlen(pathname);
|
||||
pnend = strchr(pathname, '\0') - 1;
|
||||
pnlen = strlen(pathname);
|
||||
pnend = strchr(pathname, '\0') - 1;
|
||||
|
||||
if ((pnlen > 1) && (*pnend == '/'))
|
||||
{
|
||||
*pnend-- = '\0';
|
||||
pnlen--;
|
||||
}
|
||||
if ((pnlen > 1) && (*pnend == '/'))
|
||||
{
|
||||
*pnend-- = '\0';
|
||||
pnlen--;
|
||||
}
|
||||
|
||||
/*
|
||||
* if the string has more than two characters and ends in
|
||||
* "/.", remove the "/.".
|
||||
*/
|
||||
/*
|
||||
* if the string has more than two characters and ends in
|
||||
* "/.", remove the "/.".
|
||||
*/
|
||||
|
||||
if ((pnlen > 2) && (*(pnend - 1) == '/') && (*pnend == '.'))
|
||||
*--pnend = '\0';
|
||||
if ((pnlen > 2) && (*(pnend - 1) == '/') && (*pnend == '.'))
|
||||
*--pnend = '\0';
|
||||
|
||||
/*
|
||||
* if all characters were deleted, return ".";
|
||||
* otherwise return pathname
|
||||
*/
|
||||
/*
|
||||
* if all characters were deleted, return ".";
|
||||
* otherwise return pathname
|
||||
*/
|
||||
|
||||
if (*pathname == '\0')
|
||||
(void) strcpy(pathname, ".");
|
||||
if (*pathname == '\0')
|
||||
(void) strcpy(pathname, ".");
|
||||
|
||||
return(pathname);
|
||||
return(pathname);
|
||||
}
|
||||
|
104
src/constants.h
104
src/constants.h
@ -30,51 +30,51 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* preprocessor macro and constant definitions
|
||||
* preprocessor macro and constant definitions
|
||||
*/
|
||||
|
||||
#ifndef CSCOPE_CONSTANTS_H
|
||||
#define CSCOPE_CONSTANTS_H
|
||||
|
||||
#define ctrl(x) (x & 037) /* control character macro */
|
||||
#define ctrl(x) (x & 037) /* control character macro */
|
||||
|
||||
/* fast string equality tests (avoids most strcmp() calls) */
|
||||
#define strequal(s1, s2) (*(s1) == *(s2) && strcmp(s1, s2) == 0)
|
||||
#define strnotequal(s1, s2) (*(s1) != *(s2) || strcmp(s1, s2) != 0)
|
||||
#define strequal(s1, s2) (*(s1) == *(s2) && strcmp(s1, s2) == 0)
|
||||
#define strnotequal(s1, s2) (*(s1) != *(s2) || strcmp(s1, s2) != 0)
|
||||
|
||||
/* set the mark character for searching the cross-reference file */
|
||||
#define setmark(c) (blockmark = c, block[blocklen] = blockmark)
|
||||
#define setmark(c) (blockmark = c, block[blocklen] = blockmark)
|
||||
|
||||
/* get the next character in the cross-reference */
|
||||
/* note that blockp is assumed not to be null */
|
||||
#define getrefchar() (*(++blockp + 1) != '\0' ? *blockp : \
|
||||
(read_block() != NULL ? *blockp : '\0'))
|
||||
#define getrefchar() (*(++blockp + 1) != '\0' ? *blockp : \
|
||||
(read_block() != NULL ? *blockp : '\0'))
|
||||
|
||||
/* skip the next character in the cross-reference */
|
||||
/* note that blockp is assumed not to be null and that
|
||||
this macro will always be in a statement by itself */
|
||||
#define skiprefchar() if (*(++blockp + 1) == '\0') (void) read_block()
|
||||
#define skiprefchar() if (*(++blockp + 1) == '\0') (void) read_block()
|
||||
|
||||
#ifndef ESC
|
||||
# define ESC '\033' /* escape character */
|
||||
# define ESC '\033' /* escape character */
|
||||
#endif
|
||||
#define DEL '\177' /* delete character */
|
||||
#define DUMMYCHAR ' ' /* use space as a dummy character */
|
||||
#define MSGLEN ((PATLEN) + 80) /* displayed message length */
|
||||
#define NUMLEN 10 /* line number length */
|
||||
#define PATHLEN 250 /* file pathname length */
|
||||
#define PATLEN 250 /* symbol pattern length */
|
||||
#define DEL '\177' /* delete character */
|
||||
#define DUMMYCHAR ' ' /* use space as a dummy character */
|
||||
#define MSGLEN ((PATLEN) + 80) /* displayed message length */
|
||||
#define NUMLEN 10 /* line number length */
|
||||
#define PATHLEN 250 /* file pathname length */
|
||||
#define PATLEN 250 /* symbol pattern length */
|
||||
#define TEMPSTRING_LEN 8191 /* max strlen() of the global temp string */
|
||||
#define REFFILE "cscope.out" /* cross-reference output file */
|
||||
#define NAMEFILE "cscope.files" /* default list-of-files file */
|
||||
#define INVNAME "cscope.in.out" /* inverted index to the database */
|
||||
#define INVPOST "cscope.po.out" /* inverted index postings */
|
||||
#define INVNAME2 "cscope.out.in"/* follows correct naming convention */
|
||||
#define INVPOST2 "cscope.out.po"/* follows correct naming convention */
|
||||
#define REFFILE "cscope.out" /* cross-reference output file */
|
||||
#define NAMEFILE "cscope.files" /* default list-of-files file */
|
||||
#define INVNAME "cscope.in.out" /* inverted index to the database */
|
||||
#define INVPOST "cscope.po.out" /* inverted index postings */
|
||||
#define INVNAME2 "cscope.out.in"/* follows correct naming convention */
|
||||
#define INVPOST2 "cscope.out.po"/* follows correct naming convention */
|
||||
|
||||
#define STMTMAX 10000 /* maximum source statement length */
|
||||
#define STMTMAX 10000 /* maximum source statement length */
|
||||
|
||||
#define STR2(x) #x
|
||||
#define STRINGIZE(x) STR2(x)
|
||||
@ -84,32 +84,32 @@
|
||||
#define TEMPSTRING_LEN_STR STRINGIZE(TEMPSTRING_LEN)
|
||||
|
||||
/* screen lines */
|
||||
#define FLDLINE (LINES - FIELDS - 1 - 1) /* first input field line */
|
||||
#define MSGLINE 0 /* message line */
|
||||
#define PRLINE (LINES - 1) /* input prompt line */
|
||||
#define FLDLINE (LINES - FIELDS - 1 - 1) /* first input field line */
|
||||
#define MSGLINE 0 /* message line */
|
||||
#define PRLINE (LINES - 1) /* input prompt line */
|
||||
|
||||
/* input fields (value matches field order on screen) */
|
||||
#define SYMBOL 0
|
||||
#define DEFINITION 1
|
||||
#define CALLEDBY 2
|
||||
#define CALLING 3
|
||||
#define STRING 4
|
||||
#define CHANGE 5
|
||||
#define REGEXP 6
|
||||
#define FILENAME 7
|
||||
#define INCLUDES 8
|
||||
#define FIELDS 10
|
||||
#define SYMBOL 0
|
||||
#define DEFINITION 1
|
||||
#define CALLEDBY 2
|
||||
#define CALLING 3
|
||||
#define STRING 4
|
||||
#define CHANGE 5
|
||||
#define REGEXP 6
|
||||
#define FILENAME 7
|
||||
#define INCLUDES 8
|
||||
#define FIELDS 10
|
||||
|
||||
/* file open modes */
|
||||
#ifndef R_OK
|
||||
# define READ R_OK
|
||||
# define READ R_OK
|
||||
#else
|
||||
# define READ 4
|
||||
# define READ 4
|
||||
#endif
|
||||
#ifdef W_OK
|
||||
# define WRITE W_OK
|
||||
# define WRITE W_OK
|
||||
#else
|
||||
# define WRITE 2
|
||||
# define WRITE 2
|
||||
#endif
|
||||
|
||||
#define O_TEXT 0x00
|
||||
@ -139,7 +139,7 @@
|
||||
# define KEY_HOME _KEY_UNDEF_BASE-5
|
||||
#endif
|
||||
#ifndef KEY_LL
|
||||
# define KEY_LL KEY_UNDEF_BASE-6
|
||||
# define KEY_LL KEY_UNDEF_BASE-6
|
||||
#endif
|
||||
#ifndef KEY_PPAGE
|
||||
# define KEY_PPAGE KEY_UNDEF_BASE-7
|
||||
@ -159,34 +159,34 @@
|
||||
|
||||
/**/
|
||||
#if (BSD || V9) && !__NetBSD__ && !__FreeBSD__ && !__APPLE__
|
||||
# define TERMINFO 0 /* no terminfo curses */
|
||||
# define TERMINFO 0 /* no terminfo curses */
|
||||
#else
|
||||
# define TERMINFO 1
|
||||
# define TERMINFO 1
|
||||
#endif
|
||||
|
||||
|
||||
#if !TERMINFO
|
||||
# ifndef KEY_BREAK
|
||||
# define KEY_BREAK 0400 /* easier to define than to add #if around the use */
|
||||
# define KEY_BREAK 0400 /* easier to define than to add #if around the use */
|
||||
# endif
|
||||
# ifndef KEY_ENTER
|
||||
# define KEY_ENTER 0401
|
||||
# define KEY_ENTER 0401
|
||||
# endif
|
||||
# ifndef KEY_BACKSPACE
|
||||
# define KEY_BACKSPACE 0402
|
||||
# define KEY_BACKSPACE 0402
|
||||
# endif
|
||||
|
||||
# if !sun
|
||||
# define cbreak() crmode() /* name change */
|
||||
# define cbreak() crmode() /* name change */
|
||||
# endif
|
||||
|
||||
# if UNIXPC
|
||||
# define erasechar() (_tty.c_cc[VERASE]) /* equivalent */
|
||||
# define killchar() (_tty.c_cc[VKILL]) /* equivalent */
|
||||
# define erasechar() (_tty.c_cc[VERASE]) /* equivalent */
|
||||
# define killchar() (_tty.c_cc[VKILL]) /* equivalent */
|
||||
# else
|
||||
# define erasechar() (_tty.sg_erase) /* equivalent */
|
||||
# define killchar() (_tty.sg_kill) /* equivalent */
|
||||
# define erasechar() (_tty.sg_erase) /* equivalent */
|
||||
# define killchar() (_tty.sg_kill) /* equivalent */
|
||||
# endif /* if UNIXPC */
|
||||
#endif /* if !TERMINFO */
|
||||
#endif /* if !TERMINFO */
|
||||
|
||||
#endif /* CSCOPE_CONSTANTS_H */
|
||||
|
624
src/crossref.c
624
src/crossref.c
@ -31,9 +31,9 @@
|
||||
=========================================================================*/
|
||||
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* build cross-reference file
|
||||
* build cross-reference file
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
@ -46,73 +46,73 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* convert long to a string in base BASE notation */
|
||||
#define ltobase(value) \
|
||||
#define ltobase(value) \
|
||||
do { \
|
||||
n = (value); \
|
||||
s = buf + (sizeof(buf) - 1); \
|
||||
*s = '\0'; \
|
||||
digits = 1; \
|
||||
while (n >= BASE) { \
|
||||
++digits; \
|
||||
i = n; \
|
||||
n /= BASE; \
|
||||
*--s = i - n * BASE + '!'; \
|
||||
} \
|
||||
*--s = n + '!'; \
|
||||
n = (value); \
|
||||
s = buf + (sizeof(buf) - 1); \
|
||||
*s = '\0'; \
|
||||
digits = 1; \
|
||||
while (n >= BASE) { \
|
||||
++digits; \
|
||||
i = n; \
|
||||
n /= BASE; \
|
||||
*--s = i - n * BASE + '!'; \
|
||||
} \
|
||||
*--s = n + '!'; \
|
||||
} while (0)
|
||||
|
||||
#define SYMBOLINC 20 /* symbol list size increment */
|
||||
#define SYMBOLINC 20 /* symbol list size increment */
|
||||
|
||||
long dboffset; /* new database offset */
|
||||
BOOL errorsfound; /* prompt before clearing messages */
|
||||
long lineoffset; /* source line database offset */
|
||||
long npostings; /* number of postings */
|
||||
int nsrcoffset; /* number of file name database offsets */
|
||||
long *srcoffset; /* source file name database offsets */
|
||||
unsigned long symbols; /* number of symbols */
|
||||
long dboffset; /* new database offset */
|
||||
BOOL errorsfound; /* prompt before clearing messages */
|
||||
long lineoffset; /* source line database offset */
|
||||
long npostings; /* number of postings */
|
||||
int nsrcoffset; /* number of file name database offsets */
|
||||
long *srcoffset; /* source file name database offsets */
|
||||
unsigned long symbols; /* number of symbols */
|
||||
|
||||
static char *filename; /* file name for warning messages */
|
||||
static long fcnoffset; /* function name database offset */
|
||||
static long macrooffset; /* macro name database offset */
|
||||
static unsigned long msymbols = SYMBOLINC; /* maximum number of symbols */
|
||||
static char *filename; /* file name for warning messages */
|
||||
static long fcnoffset; /* function name database offset */
|
||||
static long macrooffset; /* macro name database offset */
|
||||
static unsigned long msymbols = SYMBOLINC; /* maximum number of symbols */
|
||||
|
||||
struct symbol { /* symbol data */
|
||||
int type; /* type */
|
||||
unsigned int first; /* index of first character in text */
|
||||
unsigned int last; /* index of last+1 character in text */
|
||||
unsigned int length; /* symbol length */
|
||||
unsigned int fcn_level; /* function level of the symbol */
|
||||
struct symbol { /* symbol data */
|
||||
int type; /* type */
|
||||
unsigned int first; /* index of first character in text */
|
||||
unsigned int last; /* index of last+1 character in text */
|
||||
unsigned int length; /* symbol length */
|
||||
unsigned int fcn_level; /* function level of the symbol */
|
||||
};
|
||||
static struct symbol *symbol;
|
||||
|
||||
static void putcrossref(void);
|
||||
static void savesymbol(int token, int num);
|
||||
static void putcrossref(void);
|
||||
static void savesymbol(int token, int num);
|
||||
|
||||
void
|
||||
crossref(char *srcfile)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int length; /* symbol length */
|
||||
unsigned int entry_no; /* function level of the symbol */
|
||||
unsigned int length; /* symbol length */
|
||||
unsigned int entry_no; /* function level of the symbol */
|
||||
int token; /* current token */
|
||||
struct stat st;
|
||||
|
||||
if (! ((stat(srcfile, &st) == 0)
|
||||
&& S_ISREG(st.st_mode))) {
|
||||
cannotopen(srcfile);
|
||||
errorsfound = YES;
|
||||
return;
|
||||
&& S_ISREG(st.st_mode))) {
|
||||
cannotopen(srcfile);
|
||||
errorsfound = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
entry_no = 0;
|
||||
/* open the source file */
|
||||
if ((yyin = myfopen(srcfile, "r")) == NULL) {
|
||||
cannotopen(srcfile);
|
||||
errorsfound = YES;
|
||||
return;
|
||||
cannotopen(srcfile);
|
||||
errorsfound = YES;
|
||||
return;
|
||||
}
|
||||
filename = srcfile; /* save the file name for warning messages */
|
||||
putfilename(srcfile); /* output the file name */
|
||||
filename = srcfile; /* save the file name for warning messages */
|
||||
putfilename(srcfile); /* output the file name */
|
||||
dbputc('\n');
|
||||
dbputc('\n');
|
||||
|
||||
@ -121,74 +121,74 @@ crossref(char *srcfile)
|
||||
fcnoffset = macrooffset = 0;
|
||||
symbols = 0;
|
||||
if (symbol == NULL) {
|
||||
symbol = malloc(msymbols * sizeof(*symbol));
|
||||
symbol = malloc(msymbols * sizeof(*symbol));
|
||||
}
|
||||
for (;;) {
|
||||
|
||||
/* get the next token */
|
||||
switch (token = yylex()) {
|
||||
default:
|
||||
/* if requested, truncate C symbols */
|
||||
length = last - first;
|
||||
if (trun_syms == YES && length > 8 &&
|
||||
token != INCLUDE && token != NEWFILE) {
|
||||
length = 8;
|
||||
last = first + 8;
|
||||
}
|
||||
/* see if the token has a symbol */
|
||||
if (length == 0) {
|
||||
savesymbol(token, entry_no);
|
||||
break;
|
||||
}
|
||||
/* update entry_no if see function entry */
|
||||
if (token == FCNDEF) {
|
||||
entry_no++;
|
||||
}
|
||||
/* see if the symbol is already in the list */
|
||||
for (i = 0; i < symbols; ++i) {
|
||||
if (length == symbol[i].length
|
||||
&& strncmp(my_yytext + first,
|
||||
my_yytext + symbol[i].first,
|
||||
length) == 0
|
||||
&& entry_no == symbol[i].fcn_level
|
||||
&& token == symbol[i].type
|
||||
) { /* could be a::a() */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == symbols) { /* if not already in list */
|
||||
savesymbol(token, entry_no);
|
||||
}
|
||||
break;
|
||||
|
||||
/* get the next token */
|
||||
switch (token = yylex()) {
|
||||
default:
|
||||
/* if requested, truncate C symbols */
|
||||
length = last - first;
|
||||
if (trun_syms == YES && length > 8 &&
|
||||
token != INCLUDE && token != NEWFILE) {
|
||||
length = 8;
|
||||
last = first + 8;
|
||||
}
|
||||
/* see if the token has a symbol */
|
||||
if (length == 0) {
|
||||
savesymbol(token, entry_no);
|
||||
break;
|
||||
}
|
||||
/* update entry_no if see function entry */
|
||||
if (token == FCNDEF) {
|
||||
entry_no++;
|
||||
}
|
||||
/* see if the symbol is already in the list */
|
||||
for (i = 0; i < symbols; ++i) {
|
||||
if (length == symbol[i].length
|
||||
&& strncmp(my_yytext + first,
|
||||
my_yytext + symbol[i].first,
|
||||
length) == 0
|
||||
&& entry_no == symbol[i].fcn_level
|
||||
&& token == symbol[i].type
|
||||
) { /* could be a::a() */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == symbols) { /* if not already in list */
|
||||
savesymbol(token, entry_no);
|
||||
}
|
||||
break;
|
||||
|
||||
case NEWLINE: /* end of line containing symbols */
|
||||
entry_no = 0; /* reset entry_no for each line */
|
||||
case NEWLINE: /* end of line containing symbols */
|
||||
entry_no = 0; /* reset entry_no for each line */
|
||||
#ifdef USING_LEX
|
||||
--yyleng; /* remove the newline */
|
||||
--yyleng; /* remove the newline */
|
||||
#endif
|
||||
putcrossref(); /* output the symbols and source line */
|
||||
lineno = myylineno; /* save the symbol line number */
|
||||
putcrossref(); /* output the symbols and source line */
|
||||
lineno = myylineno; /* save the symbol line number */
|
||||
#ifndef USING_LEX
|
||||
/* HBB 20010425: replaced yyleng-- by this chunk: */
|
||||
if (my_yytext)
|
||||
*my_yytext = '\0';
|
||||
my_yyleng = 0;
|
||||
/* HBB 20010425: replaced yyleng-- by this chunk: */
|
||||
if (my_yytext)
|
||||
*my_yytext = '\0';
|
||||
my_yyleng = 0;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case LEXERR: /* Lexer error, abort further parsing of this file */
|
||||
case LEXEOF: /* end of file; last line may not have \n */
|
||||
|
||||
/* if there were symbols, output them and the source line */
|
||||
if (symbols > 0) {
|
||||
putcrossref();
|
||||
}
|
||||
(void) fclose(yyin); /* close the source file */
|
||||
break;
|
||||
|
||||
case LEXERR: /* Lexer error, abort further parsing of this file */
|
||||
case LEXEOF: /* end of file; last line may not have \n */
|
||||
|
||||
/* if there were symbols, output them and the source line */
|
||||
if (symbols > 0) {
|
||||
putcrossref();
|
||||
}
|
||||
(void) fclose(yyin); /* close the source file */
|
||||
|
||||
/* output the leading tab expected by the next call */
|
||||
dbputc('\t');
|
||||
return;
|
||||
}
|
||||
/* output the leading tab expected by the next call */
|
||||
dbputc('\t');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,8 +199,8 @@ savesymbol(int token, int num)
|
||||
{
|
||||
/* make sure there is room for the symbol */
|
||||
if (symbols == msymbols) {
|
||||
msymbols += SYMBOLINC;
|
||||
symbol = realloc(symbol, msymbols * sizeof(*symbol));
|
||||
msymbols += SYMBOLINC;
|
||||
symbol = realloc(symbol, msymbols * sizeof(*symbol));
|
||||
}
|
||||
/* save the symbol */
|
||||
symbol[symbols].type = token;
|
||||
@ -216,18 +216,18 @@ savesymbol(int token, int num)
|
||||
void
|
||||
putfilename(char *srcfile)
|
||||
{
|
||||
/* check for file system out of space */
|
||||
/* note: dbputc is not used to avoid lint complaint */
|
||||
if (putc(NEWFILE, newrefs) == EOF) {
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
++dboffset;
|
||||
if (invertedindex == YES) {
|
||||
srcoffset[nsrcoffset++] = dboffset;
|
||||
}
|
||||
dbfputs(srcfile);
|
||||
fcnoffset = macrooffset = 0;
|
||||
/* check for file system out of space */
|
||||
/* note: dbputc is not used to avoid lint complaint */
|
||||
if (putc(NEWFILE, newrefs) == EOF) {
|
||||
cannotwrite(newreffile);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
++dboffset;
|
||||
if (invertedindex == YES) {
|
||||
srcoffset[nsrcoffset++] = dboffset;
|
||||
}
|
||||
dbfputs(srcfile);
|
||||
fcnoffset = macrooffset = 0;
|
||||
}
|
||||
|
||||
/* output the symbols and source line */
|
||||
@ -253,105 +253,105 @@ putcrossref(void)
|
||||
|
||||
blank = NO;
|
||||
for (i = 0; i < my_yyleng; ++i) {
|
||||
|
||||
/* change a tab to a blank and compress blanks */
|
||||
if ((c = my_yytext[i]) == ' ' || c == '\t') {
|
||||
blank = YES;
|
||||
} else if (symput < symbols && i == symbol[symput].first) {
|
||||
/* look for the start of a symbol */
|
||||
|
||||
/* change a tab to a blank and compress blanks */
|
||||
if ((c = my_yytext[i]) == ' ' || c == '\t') {
|
||||
blank = YES;
|
||||
} else if (symput < symbols && i == symbol[symput].first) {
|
||||
/* look for the start of a symbol */
|
||||
|
||||
/* check for compressed blanks */
|
||||
if (blank == YES) {
|
||||
blank = NO;
|
||||
dbputc(' ');
|
||||
}
|
||||
dbputc('\n'); /* symbols start on a new line */
|
||||
|
||||
/* output any symbol type */
|
||||
if ((type = symbol[symput].type) != IDENT) {
|
||||
dbputc('\t');
|
||||
dbputc(type);
|
||||
} else {
|
||||
type = ' ';
|
||||
}
|
||||
/* output the symbol */
|
||||
j = symbol[symput].last;
|
||||
c = my_yytext[j];
|
||||
my_yytext[j] = '\0';
|
||||
if (invertedindex == YES) {
|
||||
putposting(my_yytext + i, type);
|
||||
}
|
||||
writestring(my_yytext + i);
|
||||
dbputc('\n');
|
||||
my_yytext[j] = c;
|
||||
i = j - 1;
|
||||
++symput;
|
||||
} else {
|
||||
/* HBB: try to save some time by early-out handling of
|
||||
* non-compressed mode */
|
||||
if (compress == NO) {
|
||||
if (blank == YES) {
|
||||
dbputc(' ');
|
||||
blank = NO;
|
||||
}
|
||||
j = i + strcspn(my_yytext+i, "\t ");
|
||||
if (symput < symbols
|
||||
&& j >= symbol[symput].first)
|
||||
j = symbol[symput].first;
|
||||
c = my_yytext[j];
|
||||
my_yytext[j] = '\0';
|
||||
writestring(my_yytext + i);
|
||||
my_yytext[j] = c;
|
||||
i = j - 1;
|
||||
/* finished this 'i', continue with the blank */
|
||||
continue;
|
||||
}
|
||||
/* check for compressed blanks */
|
||||
if (blank == YES) {
|
||||
blank = NO;
|
||||
dbputc(' ');
|
||||
}
|
||||
dbputc('\n'); /* symbols start on a new line */
|
||||
|
||||
/* output any symbol type */
|
||||
if ((type = symbol[symput].type) != IDENT) {
|
||||
dbputc('\t');
|
||||
dbputc(type);
|
||||
} else {
|
||||
type = ' ';
|
||||
}
|
||||
/* output the symbol */
|
||||
j = symbol[symput].last;
|
||||
c = my_yytext[j];
|
||||
my_yytext[j] = '\0';
|
||||
if (invertedindex == YES) {
|
||||
putposting(my_yytext + i, type);
|
||||
}
|
||||
writestring(my_yytext + i);
|
||||
dbputc('\n');
|
||||
my_yytext[j] = c;
|
||||
i = j - 1;
|
||||
++symput;
|
||||
} else {
|
||||
/* HBB: try to save some time by early-out handling of
|
||||
* non-compressed mode */
|
||||
if (compress == NO) {
|
||||
if (blank == YES) {
|
||||
dbputc(' ');
|
||||
blank = NO;
|
||||
}
|
||||
j = i + strcspn(my_yytext+i, "\t ");
|
||||
if (symput < symbols
|
||||
&& j >= symbol[symput].first)
|
||||
j = symbol[symput].first;
|
||||
c = my_yytext[j];
|
||||
my_yytext[j] = '\0';
|
||||
writestring(my_yytext + i);
|
||||
my_yytext[j] = c;
|
||||
i = j - 1;
|
||||
/* finished this 'i', continue with the blank */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check for compressed blanks */
|
||||
if (blank == YES) {
|
||||
if (dicode2[c]) {
|
||||
c = DICODE_COMPRESS(' ', c);
|
||||
} else {
|
||||
dbputc(' ');
|
||||
}
|
||||
} else if (IS_A_DICODE(c, my_yytext[i + 1])
|
||||
&& symput < symbols
|
||||
&& i + 1 != symbol[symput].first) {
|
||||
/* compress digraphs */
|
||||
c = DICODE_COMPRESS(c, my_yytext[i + 1]);
|
||||
++i;
|
||||
}
|
||||
dbputc((int) c);
|
||||
blank = NO;
|
||||
|
||||
/* skip compressed characters */
|
||||
if (c < ' ') {
|
||||
++i;
|
||||
|
||||
/* skip blanks before a preprocesor keyword */
|
||||
/* note: don't use isspace() because \f and \v
|
||||
are used for keywords */
|
||||
while ((j = my_yytext[i]) == ' ' || j == '\t') {
|
||||
++i;
|
||||
}
|
||||
/* skip the rest of the keyword */
|
||||
while (isalpha((unsigned char)my_yytext[i])) {
|
||||
++i;
|
||||
}
|
||||
/* skip space after certain keywords */
|
||||
if (keyword[c].delim != '\0') {
|
||||
while ((j = my_yytext[i]) == ' ' || j == '\t') {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
/* skip a '(' after certain keywords */
|
||||
if (keyword[c].delim == '('
|
||||
&& my_yytext[i] == '(') {
|
||||
++i;
|
||||
}
|
||||
--i; /* compensate for ++i in for() */
|
||||
} /* if compressed char */
|
||||
} /* else: not a symbol */
|
||||
/* check for compressed blanks */
|
||||
if (blank == YES) {
|
||||
if (dicode2[c]) {
|
||||
c = DICODE_COMPRESS(' ', c);
|
||||
} else {
|
||||
dbputc(' ');
|
||||
}
|
||||
} else if (IS_A_DICODE(c, my_yytext[i + 1])
|
||||
&& symput < symbols
|
||||
&& i + 1 != symbol[symput].first) {
|
||||
/* compress digraphs */
|
||||
c = DICODE_COMPRESS(c, my_yytext[i + 1]);
|
||||
++i;
|
||||
}
|
||||
dbputc((int) c);
|
||||
blank = NO;
|
||||
|
||||
/* skip compressed characters */
|
||||
if (c < ' ') {
|
||||
++i;
|
||||
|
||||
/* skip blanks before a preprocesor keyword */
|
||||
/* note: don't use isspace() because \f and \v
|
||||
are used for keywords */
|
||||
while ((j = my_yytext[i]) == ' ' || j == '\t') {
|
||||
++i;
|
||||
}
|
||||
/* skip the rest of the keyword */
|
||||
while (isalpha((unsigned char)my_yytext[i])) {
|
||||
++i;
|
||||
}
|
||||
/* skip space after certain keywords */
|
||||
if (keyword[c].delim != '\0') {
|
||||
while ((j = my_yytext[i]) == ' ' || j == '\t') {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
/* skip a '(' after certain keywords */
|
||||
if (keyword[c].delim == '('
|
||||
&& my_yytext[i] == '(') {
|
||||
++i;
|
||||
}
|
||||
--i; /* compensate for ++i in for() */
|
||||
} /* if compressed char */
|
||||
} /* else: not a symbol */
|
||||
} /* for(i) */
|
||||
|
||||
/* ignore trailing blanks */
|
||||
@ -362,11 +362,11 @@ putcrossref(void)
|
||||
/* note: must not be part of #define so putsource() doesn't discard it
|
||||
so findcalledbysub() can find it and return */
|
||||
if (symput < symbols && symbol[symput].type == DEFINEEND) {
|
||||
dbputc('\t');
|
||||
dbputc(DEFINEEND);
|
||||
dbputc('\n');
|
||||
dbputc('\n'); /* mark beginning of next source line */
|
||||
macrooffset = 0;
|
||||
dbputc('\t');
|
||||
dbputc(DEFINEEND);
|
||||
dbputc('\n');
|
||||
dbputc('\n'); /* mark beginning of next source line */
|
||||
macrooffset = 0;
|
||||
}
|
||||
symbols = 0;
|
||||
}
|
||||
@ -376,10 +376,10 @@ putcrossref(void)
|
||||
void
|
||||
freecrossref()
|
||||
{
|
||||
if (symbol)
|
||||
free(symbol);
|
||||
symbol = NULL;
|
||||
symbols = 0;
|
||||
if (symbol)
|
||||
free(symbol);
|
||||
symbol = NULL;
|
||||
symbols = 0;
|
||||
}
|
||||
|
||||
/* output the inverted index posting */
|
||||
@ -387,72 +387,72 @@ freecrossref()
|
||||
void
|
||||
putposting(char *term, int type)
|
||||
{
|
||||
long i, n;
|
||||
char *s;
|
||||
int digits; /* digits output */
|
||||
long offset; /* function/macro database offset */
|
||||
char buf[11]; /* number buffer */
|
||||
long i, n;
|
||||
char *s;
|
||||
int digits; /* digits output */
|
||||
long offset; /* function/macro database offset */
|
||||
char buf[11]; /* number buffer */
|
||||
|
||||
/* get the function or macro name offset */
|
||||
offset = fcnoffset;
|
||||
if (macrooffset != 0) {
|
||||
offset = macrooffset;
|
||||
}
|
||||
/* then update them to avoid negative relative name offset */
|
||||
switch (type) {
|
||||
case DEFINE:
|
||||
macrooffset = dboffset;
|
||||
break;
|
||||
case DEFINEEND:
|
||||
macrooffset = 0;
|
||||
return; /* null term */
|
||||
case FCNDEF:
|
||||
fcnoffset = dboffset;
|
||||
break;
|
||||
case FCNEND:
|
||||
fcnoffset = 0;
|
||||
return; /* null term */
|
||||
}
|
||||
/* ignore a null term caused by a enum/struct/union without a tag */
|
||||
if (*term == '\0') {
|
||||
return;
|
||||
}
|
||||
/* skip any #include secondary type char (< or ") */
|
||||
if (type == INCLUDE) {
|
||||
++term;
|
||||
}
|
||||
/* output the posting, which should be as small as possible to reduce
|
||||
the temp file size and sort time */
|
||||
(void) fputs(term, postings);
|
||||
(void) putc(' ', postings);
|
||||
/* get the function or macro name offset */
|
||||
offset = fcnoffset;
|
||||
if (macrooffset != 0) {
|
||||
offset = macrooffset;
|
||||
}
|
||||
/* then update them to avoid negative relative name offset */
|
||||
switch (type) {
|
||||
case DEFINE:
|
||||
macrooffset = dboffset;
|
||||
break;
|
||||
case DEFINEEND:
|
||||
macrooffset = 0;
|
||||
return; /* null term */
|
||||
case FCNDEF:
|
||||
fcnoffset = dboffset;
|
||||
break;
|
||||
case FCNEND:
|
||||
fcnoffset = 0;
|
||||
return; /* null term */
|
||||
}
|
||||
/* ignore a null term caused by a enum/struct/union without a tag */
|
||||
if (*term == '\0') {
|
||||
return;
|
||||
}
|
||||
/* skip any #include secondary type char (< or ") */
|
||||
if (type == INCLUDE) {
|
||||
++term;
|
||||
}
|
||||
/* output the posting, which should be as small as possible to reduce
|
||||
the temp file size and sort time */
|
||||
(void) fputs(term, postings);
|
||||
(void) putc(' ', postings);
|
||||
|
||||
/* the line offset is padded so postings for the same term will sort
|
||||
in ascending line offset order to order the references as they
|
||||
appear withing a source file */
|
||||
ltobase(lineoffset);
|
||||
for (i = PRECISION - digits; i > 0; --i) {
|
||||
(void) putc('!', postings);
|
||||
}
|
||||
do {
|
||||
(void) putc(*s, postings);
|
||||
} while (*++s != '\0');
|
||||
|
||||
/* postings are also sorted by type */
|
||||
(void) putc(type, postings);
|
||||
|
||||
/* function or macro name offset */
|
||||
if (offset > 0) {
|
||||
(void) putc(' ', postings);
|
||||
ltobase(offset);
|
||||
do {
|
||||
(void) putc(*s, postings);
|
||||
} while (*++s != '\0');
|
||||
}
|
||||
if (putc('\n', postings) == EOF) {
|
||||
cannotwrite(temp1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
++npostings;
|
||||
/* the line offset is padded so postings for the same term will sort
|
||||
in ascending line offset order to order the references as they
|
||||
appear withing a source file */
|
||||
ltobase(lineoffset);
|
||||
for (i = PRECISION - digits; i > 0; --i) {
|
||||
(void) putc('!', postings);
|
||||
}
|
||||
do {
|
||||
(void) putc(*s, postings);
|
||||
} while (*++s != '\0');
|
||||
|
||||
/* postings are also sorted by type */
|
||||
(void) putc(type, postings);
|
||||
|
||||
/* function or macro name offset */
|
||||
if (offset > 0) {
|
||||
(void) putc(' ', postings);
|
||||
ltobase(offset);
|
||||
do {
|
||||
(void) putc(*s, postings);
|
||||
} while (*++s != '\0');
|
||||
}
|
||||
if (putc('\n', postings) == EOF) {
|
||||
cannotwrite(temp1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
++npostings;
|
||||
}
|
||||
|
||||
/* put the string into the new database */
|
||||
@ -460,24 +460,24 @@ putposting(char *term, int type)
|
||||
void
|
||||
writestring(char *s)
|
||||
{
|
||||
unsigned char c;
|
||||
int i;
|
||||
|
||||
if (compress == NO) {
|
||||
/* Save some I/O overhead by using puts() instead of putc(): */
|
||||
dbfputs(s);
|
||||
return;
|
||||
}
|
||||
/* compress digraphs */
|
||||
for (i = 0; (c = s[i]) != '\0'; ++i) {
|
||||
if (/* dicode1[c] && dicode2[(unsigned char) s[i + 1]] */
|
||||
IS_A_DICODE(c, s[i + 1])) {
|
||||
/* c = (0200 - 2) + dicode1[c] + dicode2[(unsigned char) s[i + 1]]; */
|
||||
c = DICODE_COMPRESS(c, s[i + 1]);
|
||||
++i;
|
||||
}
|
||||
dbputc(c);
|
||||
}
|
||||
unsigned char c;
|
||||
int i;
|
||||
|
||||
if (compress == NO) {
|
||||
/* Save some I/O overhead by using puts() instead of putc(): */
|
||||
dbfputs(s);
|
||||
return;
|
||||
}
|
||||
/* compress digraphs */
|
||||
for (i = 0; (c = s[i]) != '\0'; ++i) {
|
||||
if (/* dicode1[c] && dicode2[(unsigned char) s[i + 1]] */
|
||||
IS_A_DICODE(c, s[i + 1])) {
|
||||
/* c = (0200 - 2) + dicode1[c] + dicode2[(unsigned char) s[i + 1]]; */
|
||||
c = DICODE_COMPRESS(c, s[i + 1]);
|
||||
++i;
|
||||
}
|
||||
dbputc(c);
|
||||
}
|
||||
}
|
||||
|
||||
/* print a warning message with the file name and line number */
|
||||
@ -485,8 +485,8 @@ writestring(char *s)
|
||||
void
|
||||
warning(char *text)
|
||||
{
|
||||
|
||||
(void) fprintf(stderr, "cscope: \"%s\", line %d: warning: %s\n", filename,
|
||||
myylineno, text);
|
||||
errorsfound = YES;
|
||||
|
||||
(void) fprintf(stderr, "cscope: \"%s\", line %d: warning: %s\n", filename,
|
||||
myylineno, text);
|
||||
errorsfound = YES;
|
||||
}
|
||||
|
1142
src/display.c
1142
src/display.c
File diff suppressed because it is too large
Load Diff
132
src/edit.c
132
src/edit.c
@ -30,9 +30,9 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* file editing functions
|
||||
* file editing functions
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
@ -47,21 +47,21 @@
|
||||
void
|
||||
editref(int i)
|
||||
{
|
||||
char file[PATHLEN + 1]; /* file name */
|
||||
char linenum[NUMLEN + 1]; /* line number */
|
||||
char file[PATHLEN + 1]; /* file name */
|
||||
char linenum[NUMLEN + 1]; /* line number */
|
||||
|
||||
/* verify that there is a references found file */
|
||||
if (refsfound == NULL) {
|
||||
return;
|
||||
}
|
||||
/* get the selected line */
|
||||
seekline(i + topline);
|
||||
|
||||
/* 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 */
|
||||
}
|
||||
seekline(topline); /* restore the line pointer */
|
||||
/* verify that there is a references found file */
|
||||
if (refsfound == NULL) {
|
||||
return;
|
||||
}
|
||||
/* get the selected line */
|
||||
seekline(i + topline);
|
||||
|
||||
/* 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 */
|
||||
}
|
||||
seekline(topline); /* restore the line pointer */
|
||||
}
|
||||
|
||||
/* edit all references */
|
||||
@ -69,57 +69,57 @@ editref(int i)
|
||||
void
|
||||
editall(void)
|
||||
{
|
||||
char file[PATHLEN + 1]; /* file name */
|
||||
char linenum[NUMLEN + 1]; /* line number */
|
||||
int c;
|
||||
char file[PATHLEN + 1]; /* file name */
|
||||
char linenum[NUMLEN + 1]; /* line number */
|
||||
int c;
|
||||
|
||||
/* verify that there is a references found file */
|
||||
if (refsfound == NULL) {
|
||||
return;
|
||||
}
|
||||
/* get the first line */
|
||||
seekline(1);
|
||||
|
||||
/* get each file name and line number */
|
||||
while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
|
||||
edit(file, linenum); /* edit it */
|
||||
if (editallprompt == YES) {
|
||||
addstr("Type ^D to stop editing all lines, or any other character to continue: ");
|
||||
if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
seekline(topline);
|
||||
/* verify that there is a references found file */
|
||||
if (refsfound == NULL) {
|
||||
return;
|
||||
}
|
||||
/* get the first line */
|
||||
seekline(1);
|
||||
|
||||
/* get each file name and line number */
|
||||
while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
|
||||
edit(file, linenum); /* edit it */
|
||||
if (editallprompt == YES) {
|
||||
addstr("Type ^D to stop editing all lines, or any other character to continue: ");
|
||||
if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
seekline(topline);
|
||||
}
|
||||
|
||||
|
||||
/* call the editor */
|
||||
|
||||
void
|
||||
edit(char *file, char *linenum)
|
||||
{
|
||||
char msg[MSGLEN + 1]; /* message */
|
||||
char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */
|
||||
char *s;
|
||||
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);
|
||||
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) {
|
||||
|
||||
/* 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);
|
||||
}
|
||||
else {
|
||||
(void) execute(editor, editor, plusnum, file, NULL);
|
||||
}
|
||||
clear(); /* redisplay screen */
|
||||
file = filepath(file);
|
||||
(void) 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) {
|
||||
|
||||
/* 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);
|
||||
}
|
||||
else {
|
||||
(void) execute(editor, editor, plusnum, file, NULL);
|
||||
}
|
||||
clear(); /* redisplay screen */
|
||||
}
|
||||
|
||||
/* if requested, prepend a path to a relative file name */
|
||||
@ -127,11 +127,11 @@ edit(char *file, char *linenum)
|
||||
char *
|
||||
filepath(char *file)
|
||||
{
|
||||
static char path[PATHLEN + 1];
|
||||
|
||||
if (prependpath != NULL && *file != '/') {
|
||||
(void) snprintf(path, sizeof(path), "%s/%s", prependpath, file);
|
||||
file = path;
|
||||
}
|
||||
return(file);
|
||||
static char path[PATHLEN + 1];
|
||||
|
||||
if (prependpath != NULL && *file != '/') {
|
||||
(void) snprintf(path, sizeof(path), "%s/%s", prependpath, file);
|
||||
file = path;
|
||||
}
|
||||
return(file);
|
||||
}
|
||||
|
616
src/egrep.c
616
src/egrep.c
@ -110,53 +110,53 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <setjmp.h> /* jmp_buf */
|
||||
#include <setjmp.h> /* jmp_buf */
|
||||
|
||||
#define nextch() (*input++)
|
||||
#define nextch() (*input++)
|
||||
|
||||
#define MAXLIN 350
|
||||
#define MAXPOS 4000
|
||||
#define NCHARS 256
|
||||
#define NSTATES 128
|
||||
#define FINAL -1
|
||||
static char gotofn[NSTATES][NCHARS];
|
||||
static int state[NSTATES];
|
||||
static char out[NSTATES];
|
||||
static unsigned int line;
|
||||
static int name[MAXLIN];
|
||||
static unsigned int left[MAXLIN];
|
||||
static unsigned int right[MAXLIN];
|
||||
static unsigned int parent[MAXLIN];
|
||||
static int foll[MAXLIN];
|
||||
static int positions[MAXPOS];
|
||||
static char chars[MAXLIN];
|
||||
static int nxtpos;
|
||||
static int nxtchar;
|
||||
static int tmpstat[MAXLIN];
|
||||
static int initstat[MAXLIN];
|
||||
static int xstate;
|
||||
static int count;
|
||||
static int icount;
|
||||
static char *input;
|
||||
static long lnum;
|
||||
static int iflag;
|
||||
static jmp_buf env; /* setjmp/longjmp buffer */
|
||||
static char *message; /* error message */
|
||||
static char gotofn[NSTATES][NCHARS];
|
||||
static int state[NSTATES];
|
||||
static char out[NSTATES];
|
||||
static unsigned int line;
|
||||
static int name[MAXLIN];
|
||||
static unsigned int left[MAXLIN];
|
||||
static unsigned int right[MAXLIN];
|
||||
static unsigned int parent[MAXLIN];
|
||||
static int foll[MAXLIN];
|
||||
static int positions[MAXPOS];
|
||||
static char chars[MAXLIN];
|
||||
static int nxtpos;
|
||||
static int nxtchar;
|
||||
static int tmpstat[MAXLIN];
|
||||
static int initstat[MAXLIN];
|
||||
static int xstate;
|
||||
static int count;
|
||||
static int icount;
|
||||
static char *input;
|
||||
static long lnum;
|
||||
static int iflag;
|
||||
static jmp_buf env; /* setjmp/longjmp buffer */
|
||||
static char *message; /* error message */
|
||||
|
||||
/* Internal prototypes: */
|
||||
static void cfoll(int v);
|
||||
static void cgotofn(void);
|
||||
static int cstate(int v);
|
||||
static int member(int symb, int set, int torf);
|
||||
static int notin(int n);
|
||||
static void synerror(void);
|
||||
static void overflo(void);
|
||||
static void add(int *array, int n);
|
||||
static void follow(unsigned int v);
|
||||
static int unary(int x, int d);
|
||||
static int node(int x, int l, int r);
|
||||
static unsigned int cclenter(int x);
|
||||
static unsigned int enter(int x);
|
||||
static void cfoll(int v);
|
||||
static void cgotofn(void);
|
||||
static int cstate(int v);
|
||||
static int member(int symb, int set, int torf);
|
||||
static int notin(int n);
|
||||
static void synerror(void);
|
||||
static void overflo(void);
|
||||
static void add(int *array, int n);
|
||||
static void follow(unsigned int v);
|
||||
static int unary(int x, int d);
|
||||
static int node(int x, int l, int r);
|
||||
static unsigned int cclenter(int x);
|
||||
static unsigned int enter(int x);
|
||||
|
||||
static int yylex(void);
|
||||
static int yyerror(char *);
|
||||
@ -1242,8 +1242,8 @@ yyreduce:
|
||||
case 2: /* s: t */
|
||||
#line 104 "src/egrep.y"
|
||||
{ unary(FINAL, yyvsp[0]);
|
||||
line--;
|
||||
}
|
||||
line--;
|
||||
}
|
||||
#line 1248 "y.tab.c"
|
||||
break;
|
||||
|
||||
@ -1274,7 +1274,7 @@ yyreduce:
|
||||
case 7: /* b: %empty */
|
||||
#line 118 "src/egrep.y"
|
||||
{ yyval = enter(DOT);
|
||||
yyval = unary(STAR, yyval); }
|
||||
yyval = unary(STAR, yyval); }
|
||||
#line 1279 "y.tab.c"
|
||||
break;
|
||||
|
||||
@ -1537,9 +1537,9 @@ yyreturnlab:
|
||||
static int
|
||||
yyerror(char *s)
|
||||
{
|
||||
message = s;
|
||||
longjmp(env, 1);
|
||||
return 1; /* silence a warning */
|
||||
message = s;
|
||||
longjmp(env, 1);
|
||||
return 1; /* silence a warning */
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1551,66 +1551,66 @@ yylex(void)
|
||||
switch(c = nextch()) {
|
||||
case '|':
|
||||
case '\n':
|
||||
return (OR);
|
||||
return (OR);
|
||||
case '*':
|
||||
return (STAR);
|
||||
return (STAR);
|
||||
case '+':
|
||||
return (PLUS);
|
||||
return (PLUS);
|
||||
case '?':
|
||||
return (QUEST);
|
||||
return (QUEST);
|
||||
case '(':
|
||||
case ')':
|
||||
return (c);
|
||||
return (c);
|
||||
case '.':
|
||||
return (DOT);
|
||||
return (DOT);
|
||||
case '\0':
|
||||
return (0);
|
||||
return (0);
|
||||
case '[':
|
||||
x = CCL;
|
||||
cclcnt = 0;
|
||||
count = nxtchar++;
|
||||
if ((c = nextch()) == '^') {
|
||||
x = NCCL;
|
||||
c = nextch();
|
||||
}
|
||||
do {
|
||||
if (c == '\0')
|
||||
synerror();
|
||||
if ( (c == '-')
|
||||
&& (cclcnt > 0)
|
||||
&& (chars[nxtchar-1] != 0)
|
||||
) {
|
||||
if ((d = nextch()) != 0) {
|
||||
c = chars[nxtchar-1];
|
||||
while ((unsigned int)c < (unsigned int)d) {
|
||||
if (nxtchar >= MAXLIN)
|
||||
overflo();
|
||||
chars[nxtchar++] = ++c;
|
||||
cclcnt++;
|
||||
}
|
||||
continue;
|
||||
} /* if() */
|
||||
} /* if() */
|
||||
if (nxtchar >= MAXLIN)
|
||||
overflo();
|
||||
chars[nxtchar++] = c;
|
||||
cclcnt++;
|
||||
} while ((c = nextch()) != ']');
|
||||
chars[count] = cclcnt;
|
||||
return (x);
|
||||
x = CCL;
|
||||
cclcnt = 0;
|
||||
count = nxtchar++;
|
||||
if ((c = nextch()) == '^') {
|
||||
x = NCCL;
|
||||
c = nextch();
|
||||
}
|
||||
do {
|
||||
if (c == '\0')
|
||||
synerror();
|
||||
if ( (c == '-')
|
||||
&& (cclcnt > 0)
|
||||
&& (chars[nxtchar-1] != 0)
|
||||
) {
|
||||
if ((d = nextch()) != 0) {
|
||||
c = chars[nxtchar-1];
|
||||
while ((unsigned int)c < (unsigned int)d) {
|
||||
if (nxtchar >= MAXLIN)
|
||||
overflo();
|
||||
chars[nxtchar++] = ++c;
|
||||
cclcnt++;
|
||||
}
|
||||
continue;
|
||||
} /* if() */
|
||||
} /* if() */
|
||||
if (nxtchar >= MAXLIN)
|
||||
overflo();
|
||||
chars[nxtchar++] = c;
|
||||
cclcnt++;
|
||||
} while ((c = nextch()) != ']');
|
||||
chars[count] = cclcnt;
|
||||
return (x);
|
||||
case '\\':
|
||||
if ((c = nextch()) == '\0')
|
||||
synerror();
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
if ((c = nextch()) == '\0')
|
||||
synerror();
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
case '$':
|
||||
case '^':
|
||||
c = '\n';
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
c = '\n';
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
default:
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
yylval = c;
|
||||
return (CHAR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1624,7 +1624,7 @@ static unsigned int
|
||||
enter(int x)
|
||||
{
|
||||
if(line >= MAXLIN)
|
||||
overflo();
|
||||
overflo();
|
||||
name[line] = x;
|
||||
left[line] = 0;
|
||||
right[line] = 0;
|
||||
@ -1645,7 +1645,7 @@ static int
|
||||
node(int x, int l, int r)
|
||||
{
|
||||
if(line >= MAXLIN)
|
||||
overflo();
|
||||
overflo();
|
||||
name[line] = x;
|
||||
left[line] = l;
|
||||
right[line] = r;
|
||||
@ -1658,7 +1658,7 @@ static int
|
||||
unary(int x, int d)
|
||||
{
|
||||
if(line >= MAXLIN)
|
||||
overflo();
|
||||
overflo();
|
||||
name[line] = x;
|
||||
left[line] = d;
|
||||
right[line] = 0;
|
||||
@ -1678,16 +1678,16 @@ cfoll(int v)
|
||||
unsigned int i;
|
||||
|
||||
if (left[v] == 0) {
|
||||
count = 0;
|
||||
for (i = 1; i <= line; i++)
|
||||
tmpstat[i] = 0;
|
||||
follow(v);
|
||||
add(foll, v);
|
||||
count = 0;
|
||||
for (i = 1; i <= line; i++)
|
||||
tmpstat[i] = 0;
|
||||
follow(v);
|
||||
add(foll, v);
|
||||
} else if (right[v] == 0)
|
||||
cfoll(left[v]);
|
||||
cfoll(left[v]);
|
||||
else {
|
||||
cfoll(left[v]);
|
||||
cfoll(right[v]);
|
||||
cfoll(left[v]);
|
||||
cfoll(right[v]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1704,126 +1704,126 @@ cgotofn(void)
|
||||
|
||||
count = 0;
|
||||
for (n=3; n<=line; n++)
|
||||
tmpstat[n] = 0;
|
||||
tmpstat[n] = 0;
|
||||
if (cstate(line-1)==0) {
|
||||
tmpstat[line] = 1;
|
||||
count++;
|
||||
out[0] = 1;
|
||||
tmpstat[line] = 1;
|
||||
count++;
|
||||
out[0] = 1;
|
||||
}
|
||||
for (n=3; n<=line; n++)
|
||||
initstat[n] = tmpstat[n];
|
||||
count--; /*leave out position 1 */
|
||||
initstat[n] = tmpstat[n];
|
||||
count--; /*leave out position 1 */
|
||||
icount = count;
|
||||
tmpstat[1] = 0;
|
||||
add(state, 0);
|
||||
n = 0;
|
||||
for (s = 0; s <= n; s++) {
|
||||
if (out[s] == 1)
|
||||
continue;
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
symbol[i] = 0;
|
||||
num = positions[state[s]];
|
||||
count = icount;
|
||||
for (i = 3; i <= line; i++)
|
||||
tmpstat[i] = initstat[i];
|
||||
pos = state[s] + 1;
|
||||
for (i = 0; i < num; i++) {
|
||||
curpos = positions[pos];
|
||||
if ((c = name[curpos]) >= 0) {
|
||||
if (c < NCHARS) {
|
||||
symbol[c] = 1;
|
||||
} else if (c == DOT) {
|
||||
for (k = 0; k < NCHARS; k++)
|
||||
if (k != '\n')
|
||||
symbol[k] = 1;
|
||||
} else if (c == CCL) {
|
||||
nc = chars[right[curpos]];
|
||||
pc = right[curpos] + 1;
|
||||
for (j = 0; j < nc; j++)
|
||||
symbol[(unsigned char)chars[pc++]] = 1;
|
||||
} else if (c == NCCL) {
|
||||
nc = chars[right[curpos]];
|
||||
for (j = 0; j < NCHARS; j++) {
|
||||
pc = right[curpos] + 1;
|
||||
for (l = 0; l < nc; l++)
|
||||
if (j==(unsigned char)chars[pc++])
|
||||
goto cont;
|
||||
if (j != '\n')
|
||||
symbol[j] = 1;
|
||||
cont:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
} /* for (i) */
|
||||
for (c=0; c<NCHARS; c++) {
|
||||
if (symbol[c] == 1) {
|
||||
/* nextstate(s,c) */
|
||||
count = icount;
|
||||
for (i=3; i <= line; i++)
|
||||
tmpstat[i] = initstat[i];
|
||||
pos = state[s] + 1;
|
||||
for (i=0; i<num; i++) {
|
||||
curpos = positions[pos];
|
||||
if ((k = name[curpos]) >= 0)
|
||||
if ((k == c)
|
||||
|| (k == DOT)
|
||||
|| (k == CCL && member(c, right[curpos], 1))
|
||||
|| (k == NCCL && member(c, right[curpos], 0))
|
||||
) {
|
||||
number = positions[foll[curpos]];
|
||||
newpos = foll[curpos] + 1;
|
||||
for (j = 0; j < number; j++) {
|
||||
if (tmpstat[positions[newpos]] != 1) {
|
||||
tmpstat[positions[newpos]] = 1;
|
||||
count++;
|
||||
}
|
||||
newpos++;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
} /* end nextstate */
|
||||
if (notin(n)) {
|
||||
if (n >= NSTATES)
|
||||
overflo();
|
||||
add(state, ++n);
|
||||
if (tmpstat[line] == 1)
|
||||
out[n] = 1;
|
||||
gotofn[s][c] = n;
|
||||
} else {
|
||||
gotofn[s][c] = xstate;
|
||||
}
|
||||
} /* if (symbol) */
|
||||
} /* for(c) */
|
||||
if (out[s] == 1)
|
||||
continue;
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
symbol[i] = 0;
|
||||
num = positions[state[s]];
|
||||
count = icount;
|
||||
for (i = 3; i <= line; i++)
|
||||
tmpstat[i] = initstat[i];
|
||||
pos = state[s] + 1;
|
||||
for (i = 0; i < num; i++) {
|
||||
curpos = positions[pos];
|
||||
if ((c = name[curpos]) >= 0) {
|
||||
if (c < NCHARS) {
|
||||
symbol[c] = 1;
|
||||
} else if (c == DOT) {
|
||||
for (k = 0; k < NCHARS; k++)
|
||||
if (k != '\n')
|
||||
symbol[k] = 1;
|
||||
} else if (c == CCL) {
|
||||
nc = chars[right[curpos]];
|
||||
pc = right[curpos] + 1;
|
||||
for (j = 0; j < nc; j++)
|
||||
symbol[(unsigned char)chars[pc++]] = 1;
|
||||
} else if (c == NCCL) {
|
||||
nc = chars[right[curpos]];
|
||||
for (j = 0; j < NCHARS; j++) {
|
||||
pc = right[curpos] + 1;
|
||||
for (l = 0; l < nc; l++)
|
||||
if (j==(unsigned char)chars[pc++])
|
||||
goto cont;
|
||||
if (j != '\n')
|
||||
symbol[j] = 1;
|
||||
cont:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
} /* for (i) */
|
||||
for (c=0; c<NCHARS; c++) {
|
||||
if (symbol[c] == 1) {
|
||||
/* nextstate(s,c) */
|
||||
count = icount;
|
||||
for (i=3; i <= line; i++)
|
||||
tmpstat[i] = initstat[i];
|
||||
pos = state[s] + 1;
|
||||
for (i=0; i<num; i++) {
|
||||
curpos = positions[pos];
|
||||
if ((k = name[curpos]) >= 0)
|
||||
if ((k == c)
|
||||
|| (k == DOT)
|
||||
|| (k == CCL && member(c, right[curpos], 1))
|
||||
|| (k == NCCL && member(c, right[curpos], 0))
|
||||
) {
|
||||
number = positions[foll[curpos]];
|
||||
newpos = foll[curpos] + 1;
|
||||
for (j = 0; j < number; j++) {
|
||||
if (tmpstat[positions[newpos]] != 1) {
|
||||
tmpstat[positions[newpos]] = 1;
|
||||
count++;
|
||||
}
|
||||
newpos++;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
} /* end nextstate */
|
||||
if (notin(n)) {
|
||||
if (n >= NSTATES)
|
||||
overflo();
|
||||
add(state, ++n);
|
||||
if (tmpstat[line] == 1)
|
||||
out[n] = 1;
|
||||
gotofn[s][c] = n;
|
||||
} else {
|
||||
gotofn[s][c] = xstate;
|
||||
}
|
||||
} /* if (symbol) */
|
||||
} /* for(c) */
|
||||
} /* for(s) */
|
||||
}
|
||||
|
||||
static int
|
||||
cstate(int v)
|
||||
{
|
||||
int b;
|
||||
if (left[v] == 0) {
|
||||
if (tmpstat[v] != 1) {
|
||||
tmpstat[v] = 1;
|
||||
count++;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
else if (right[v] == 0) {
|
||||
if (cstate(left[v]) == 0) return (0);
|
||||
else if (name[v] == PLUS) return (1);
|
||||
else return (0);
|
||||
}
|
||||
else if (name[v] == CAT) {
|
||||
if (cstate(left[v]) == 0 && cstate(right[v]) == 0) return (0);
|
||||
else return (1);
|
||||
}
|
||||
else { /* name[v] == OR */
|
||||
b = cstate(right[v]);
|
||||
if (cstate(left[v]) == 0 || b == 0) return (0);
|
||||
else return (1);
|
||||
}
|
||||
int b;
|
||||
if (left[v] == 0) {
|
||||
if (tmpstat[v] != 1) {
|
||||
tmpstat[v] = 1;
|
||||
count++;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
else if (right[v] == 0) {
|
||||
if (cstate(left[v]) == 0) return (0);
|
||||
else if (name[v] == PLUS) return (1);
|
||||
else return (0);
|
||||
}
|
||||
else if (name[v] == CAT) {
|
||||
if (cstate(left[v]) == 0 && cstate(right[v]) == 0) return (0);
|
||||
else return (1);
|
||||
}
|
||||
else { /* name[v] == OR */
|
||||
b = cstate(right[v]);
|
||||
if (cstate(left[v]) == 0 || b == 0) return (0);
|
||||
else return (1);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1834,26 +1834,26 @@ member(int symb, int set, int torf)
|
||||
num = chars[set];
|
||||
pos = set + 1;
|
||||
for (i = 0; i < num; i++)
|
||||
if (symb == (unsigned char)(chars[pos++]))
|
||||
return (torf);
|
||||
if (symb == (unsigned char)(chars[pos++]))
|
||||
return (torf);
|
||||
return (!torf);
|
||||
}
|
||||
|
||||
static int
|
||||
notin(int n)
|
||||
{
|
||||
int i, j, pos;
|
||||
for (i=0; i<=n; i++) {
|
||||
if (positions[state[i]] == count) {
|
||||
pos = state[i] + 1;
|
||||
for (j=0; j < count; j++)
|
||||
if (tmpstat[positions[pos++]] != 1) goto nxt;
|
||||
xstate = i;
|
||||
return (0);
|
||||
}
|
||||
nxt: ;
|
||||
}
|
||||
return (1);
|
||||
int i, j, pos;
|
||||
for (i=0; i<=n; i++) {
|
||||
if (positions[state[i]] == count) {
|
||||
pos = state[i] + 1;
|
||||
for (j=0; j < count; j++)
|
||||
if (tmpstat[positions[pos++]] != 1) goto nxt;
|
||||
xstate = i;
|
||||
return (0);
|
||||
}
|
||||
nxt: ;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1862,13 +1862,13 @@ add(int *array, int n)
|
||||
unsigned int i;
|
||||
|
||||
if (nxtpos + count > MAXPOS)
|
||||
overflo();
|
||||
overflo();
|
||||
array[n] = nxtpos;
|
||||
positions[nxtpos++] = count;
|
||||
for (i=3; i <= line; i++) {
|
||||
if (tmpstat[i] == 1) {
|
||||
positions[nxtpos++] = i;
|
||||
}
|
||||
if (tmpstat[i] == 1) {
|
||||
positions[nxtpos++] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1878,33 +1878,33 @@ follow(unsigned int v)
|
||||
unsigned int p;
|
||||
|
||||
if (v == line)
|
||||
return;
|
||||
return;
|
||||
p = parent[v];
|
||||
switch(name[p]) {
|
||||
case STAR:
|
||||
case PLUS: cstate(v);
|
||||
follow(p);
|
||||
return;
|
||||
case PLUS: cstate(v);
|
||||
follow(p);
|
||||
return;
|
||||
|
||||
case OR:
|
||||
case QUEST: follow(p);
|
||||
return;
|
||||
case QUEST: follow(p);
|
||||
return;
|
||||
|
||||
case CAT:
|
||||
if (v == left[p]) {
|
||||
if (cstate(right[p]) == 0) {
|
||||
follow(p);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
follow(p);
|
||||
return;
|
||||
if (v == left[p]) {
|
||||
if (cstate(right[p]) == 0) {
|
||||
follow(p);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
follow(p);
|
||||
return;
|
||||
case FINAL:
|
||||
if (tmpstat[line] != 1) {
|
||||
tmpstat[line] = 1;
|
||||
count++;
|
||||
}
|
||||
return;
|
||||
if (tmpstat[line] != 1) {
|
||||
tmpstat[line] = 1;
|
||||
count++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1933,9 +1933,9 @@ egrepinit(char *egreppat)
|
||||
input = egreppat;
|
||||
message = NULL;
|
||||
if (setjmp(env) == 0) {
|
||||
yyparse();
|
||||
cfoll(line-1);
|
||||
cgotofn();
|
||||
yyparse();
|
||||
cfoll(line-1);
|
||||
cgotofn();
|
||||
}
|
||||
return(message);
|
||||
}
|
||||
@ -1947,11 +1947,11 @@ static size_t read_next_chunk(char **p, FILE *fptr)
|
||||
{
|
||||
if (*p <= (buf + BUFSIZ)) {
|
||||
/* bwlow the middle, so enough space left for one entire BUFSIZ */
|
||||
return fread(*p, sizeof(**p), BUFSIZ, fptr);
|
||||
return fread(*p, sizeof(**p), BUFSIZ, fptr);
|
||||
} else if (*p == buf_end) {
|
||||
/* exactly at end ... wrap around and use lower half */
|
||||
*p = buf;
|
||||
return fread(*p, sizeof(**p), BUFSIZ, fptr);
|
||||
*p = buf;
|
||||
return fread(*p, sizeof(**p), BUFSIZ, fptr);
|
||||
}
|
||||
/* somewhere in second half, so do a limited read */
|
||||
return fread(*p, sizeof(**p), buf_end - *p, fptr);
|
||||
@ -1969,7 +1969,7 @@ egrep(char *file, FILE *output, char *format)
|
||||
FILE *fptr;
|
||||
|
||||
if ((fptr = myfopen(file, "r")) == NULL)
|
||||
return(-1);
|
||||
return(-1);
|
||||
|
||||
lnum = 1;
|
||||
p = buf;
|
||||
@ -1977,70 +1977,70 @@ egrep(char *file, FILE *output, char *format)
|
||||
ccount = read_next_chunk(&p, fptr);
|
||||
|
||||
if (ccount <= 0) {
|
||||
fclose(fptr);
|
||||
return(0);
|
||||
fclose(fptr);
|
||||
return(0);
|
||||
}
|
||||
in_line = 1;
|
||||
istat = cstat = (unsigned int) gotofn[0]['\n'];
|
||||
if (out[cstat])
|
||||
goto found;
|
||||
goto found;
|
||||
for (;;) {
|
||||
if (!iflag) {
|
||||
/* all input chars made positive */
|
||||
cstat = (unsigned int) gotofn[cstat][(unsigned char)*p];
|
||||
} else {
|
||||
/* for -i option*/
|
||||
cstat = (unsigned int) gotofn[cstat][tolower((unsigned char)*p)];
|
||||
if (!iflag) {
|
||||
/* all input chars made positive */
|
||||
cstat = (unsigned int) gotofn[cstat][(unsigned char)*p];
|
||||
} else {
|
||||
/* for -i option*/
|
||||
cstat = (unsigned int) gotofn[cstat][tolower((unsigned char)*p)];
|
||||
}
|
||||
if (out[cstat]) {
|
||||
found:
|
||||
for(;;) {
|
||||
if (*p++ == '\n') {
|
||||
in_line = 0;
|
||||
succeed:
|
||||
fprintf(output, format, file, lnum);
|
||||
if (p <= nlp) {
|
||||
while (nlp < buf_end)
|
||||
putc(*nlp++, output);
|
||||
nlp = buf;
|
||||
}
|
||||
while (nlp < p)
|
||||
putc(*nlp++, output);
|
||||
lnum++;
|
||||
nlp = p;
|
||||
if (out[cstat = istat] == 0)
|
||||
goto brk2;
|
||||
} /* if (p++ == \n) */
|
||||
cfound:
|
||||
if (--ccount <= 0) {
|
||||
ccount = read_next_chunk(&p, fptr);
|
||||
if (ccount <= 0) {
|
||||
if (in_line) {
|
||||
in_line = 0;
|
||||
goto succeed;
|
||||
}
|
||||
if (out[cstat]) {
|
||||
found:
|
||||
for(;;) {
|
||||
if (*p++ == '\n') {
|
||||
in_line = 0;
|
||||
succeed:
|
||||
fprintf(output, format, file, lnum);
|
||||
if (p <= nlp) {
|
||||
while (nlp < buf_end)
|
||||
putc(*nlp++, output);
|
||||
nlp = buf;
|
||||
}
|
||||
while (nlp < p)
|
||||
putc(*nlp++, output);
|
||||
lnum++;
|
||||
nlp = p;
|
||||
if (out[cstat = istat] == 0)
|
||||
goto brk2;
|
||||
} /* if (p++ == \n) */
|
||||
cfound:
|
||||
if (--ccount <= 0) {
|
||||
ccount = read_next_chunk(&p, fptr);
|
||||
if (ccount <= 0) {
|
||||
if (in_line) {
|
||||
in_line = 0;
|
||||
goto succeed;
|
||||
}
|
||||
fclose(fptr);
|
||||
return(0);
|
||||
}
|
||||
} /* if(ccount <= 0) */
|
||||
in_line = 1;
|
||||
} /* for(ever) */
|
||||
} /* if(out[cstat]) */
|
||||
}
|
||||
} /* if(ccount <= 0) */
|
||||
in_line = 1;
|
||||
} /* for(ever) */
|
||||
} /* if(out[cstat]) */
|
||||
|
||||
if (*p++ == '\n') {
|
||||
in_line = 0;
|
||||
lnum++;
|
||||
nlp = p;
|
||||
if (out[(cstat=istat)])
|
||||
goto cfound;
|
||||
}
|
||||
if (*p++ == '\n') {
|
||||
in_line = 0;
|
||||
lnum++;
|
||||
nlp = p;
|
||||
if (out[(cstat=istat)])
|
||||
goto cfound;
|
||||
}
|
||||
brk2:
|
||||
if (--ccount <= 0) {
|
||||
ccount = read_next_chunk(&p, fptr);
|
||||
if (ccount <= 0)
|
||||
break;
|
||||
}
|
||||
in_line = 1;
|
||||
if (--ccount <= 0) {
|
||||
ccount = read_next_chunk(&p, fptr);
|
||||
if (ccount <= 0)
|
||||
break;
|
||||
}
|
||||
in_line = 1;
|
||||
}
|
||||
fclose(fptr);
|
||||
return(0);
|
||||
@ -2049,5 +2049,5 @@ egrep(char *file, FILE *output, char *format)
|
||||
void
|
||||
egrepcaseless(int i)
|
||||
{
|
||||
iflag = i; /* simulate "egrep -i" */
|
||||
iflag = i; /* simulate "egrep -i" */
|
||||
}
|
||||
|
160
src/exec.c
160
src/exec.c
@ -30,9 +30,9 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* process execution functions
|
||||
* process execution functions
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@ -49,14 +49,14 @@
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
static sighandler_t oldsigquit; /* old value of quit signal */
|
||||
static sighandler_t oldsighup; /* old value of hangup signal */
|
||||
static sighandler_t oldsigtstp; /* old value of SIGTSTP */
|
||||
static sighandler_t oldsigquit; /* old value of quit signal */
|
||||
static sighandler_t oldsighup; /* old value of hangup signal */
|
||||
static sighandler_t oldsigtstp; /* old value of SIGTSTP */
|
||||
|
||||
#ifndef __MSDOS__ /* none of these is needed, there */
|
||||
static int join(pid_t p);
|
||||
static int myexecvp(char *a, char **args);
|
||||
static pid_t myfork(void);
|
||||
static int join(pid_t p);
|
||||
static int myexecvp(char *a, char **args);
|
||||
static pid_t myfork(void);
|
||||
#endif
|
||||
|
||||
/* execute forks and executes a program or shell script, waits for it to
|
||||
@ -65,45 +65,45 @@ 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 */
|
||||
char *argv[BUFSIZ];
|
||||
pid_t p;
|
||||
va_list ap;
|
||||
int exitcode = -1; /* initialize, to avoid warning */
|
||||
char *argv[BUFSIZ];
|
||||
pid_t p;
|
||||
|
||||
/* fork and exec the program or shell script */
|
||||
endwin(); /* restore the terminal modes */
|
||||
mousecleanup();
|
||||
fflush(stdout);
|
||||
va_start(ap, a);
|
||||
for (p = 0; (argv[p] = va_arg(ap, char *)) != 0; p++)
|
||||
;
|
||||
/* fork and exec the program or shell script */
|
||||
endwin(); /* restore the terminal modes */
|
||||
mousecleanup();
|
||||
fflush(stdout);
|
||||
va_start(ap, a);
|
||||
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: */
|
||||
/* HBB 20010313: in MSDOG, everything is completely different.
|
||||
* No fork()/exec()/wait(), but rather a single libc call: */
|
||||
exitcode = spawnvp(P_WAIT, a, argv);
|
||||
#else
|
||||
if ((p = myfork()) == 0) {
|
||||
myexecvp(a, argv); /* child */
|
||||
}
|
||||
else {
|
||||
exitcode = join(p); /* parent */
|
||||
}
|
||||
if ((p = myfork()) == 0) {
|
||||
myexecvp(a, argv); /* child */
|
||||
}
|
||||
else {
|
||||
exitcode = join(p); /* parent */
|
||||
}
|
||||
#endif /* MSDOS */
|
||||
|
||||
/* the menu and scrollbar may be changed by the command executed */
|
||||
|
||||
/* the menu and scrollbar may be changed by the command executed */
|
||||
#if UNIXPC || !TERMINFO
|
||||
# ifndef __DJGPP__ /* leave CRLF handling as is */
|
||||
nonl();
|
||||
nonl();
|
||||
# endif
|
||||
raw(); /* endwin() turns off cbreak mode so restore it */
|
||||
noecho();
|
||||
raw(); /* endwin() turns off cbreak mode so restore it */
|
||||
noecho();
|
||||
#endif
|
||||
mousemenu();
|
||||
drawscrollbar(topline, nextline);
|
||||
va_end(ap);
|
||||
return(exitcode);
|
||||
mousemenu();
|
||||
drawscrollbar(topline, nextline);
|
||||
va_end(ap);
|
||||
return(exitcode);
|
||||
}
|
||||
|
||||
#ifndef __MSDOS__ /* None of the following functions is used there */
|
||||
@ -115,18 +115,18 @@ static int
|
||||
myexecvp(char *a, char **args)
|
||||
{
|
||||
char msg[MSGLEN + 1];
|
||||
|
||||
|
||||
/* modify argv[0] to reference the last component of its path name */
|
||||
args[0] = basename(args[0]);
|
||||
|
||||
/* execute the program or shell script */
|
||||
execvp(a, args); /* returns only on failure */
|
||||
execvp(a, args); /* returns only on failure */
|
||||
snprintf(msg, sizeof(msg), "\nCannot exec %s", a);
|
||||
perror(msg); /* display the reason */
|
||||
askforreturn(); /* wait until the user sees the message */
|
||||
myexit(1); /* exit the child */
|
||||
perror(msg); /* display the reason */
|
||||
askforreturn(); /* wait until the user sees the message */
|
||||
myexit(1); /* exit the child */
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* myfork acts like fork but also handles signals */
|
||||
@ -134,32 +134,32 @@ myexecvp(char *a, char **args)
|
||||
static pid_t
|
||||
myfork(void)
|
||||
{
|
||||
pid_t p; /* process number */
|
||||
pid_t p; /* process number */
|
||||
|
||||
p = fork();
|
||||
|
||||
/* the parent ignores the interrupt, quit, and hangup signals */
|
||||
if (p > 0) {
|
||||
oldsigquit = signal(SIGQUIT, SIG_IGN);
|
||||
oldsighup = signal(SIGHUP, SIG_IGN);
|
||||
#ifdef SIGTSTP
|
||||
oldsigtstp = signal(SIGTSTP, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
/* so they can be used to stop the child */
|
||||
else if (p == 0) {
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
p = fork();
|
||||
|
||||
/* the parent ignores the interrupt, quit, and hangup signals */
|
||||
if (p > 0) {
|
||||
oldsigquit = signal(SIGQUIT, SIG_IGN);
|
||||
oldsighup = signal(SIGHUP, SIG_IGN);
|
||||
#ifdef SIGTSTP
|
||||
oldsigtstp = signal(SIGTSTP, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
/* so they can be used to stop the child */
|
||||
else if (p == 0) {
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
#ifdef SIGTSTP
|
||||
signal(SIGTSTP, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
/* check for fork failure */
|
||||
if (p == -1) {
|
||||
myperror("Cannot fork");
|
||||
}
|
||||
return p;
|
||||
signal(SIGTSTP, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
/* check for fork failure */
|
||||
if (p == -1) {
|
||||
myperror("Cannot fork");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/* join is the compliment of fork */
|
||||
@ -167,23 +167,23 @@ myfork(void)
|
||||
static int
|
||||
join(pid_t p)
|
||||
{
|
||||
int status = -1;
|
||||
pid_t w;
|
||||
int status = -1;
|
||||
pid_t w;
|
||||
|
||||
/* wait for the correct child to exit */
|
||||
do {
|
||||
w = wait(&status);
|
||||
} while (p != -1 && w != p);
|
||||
/* wait for the correct child to exit */
|
||||
do {
|
||||
w = wait(&status);
|
||||
} while (p != -1 && w != p);
|
||||
|
||||
/* restore signal handling */
|
||||
signal(SIGQUIT, oldsigquit);
|
||||
signal(SIGHUP, oldsighup);
|
||||
/* restore signal handling */
|
||||
signal(SIGQUIT, oldsigquit);
|
||||
signal(SIGHUP, oldsighup);
|
||||
#ifdef SIGTSTP
|
||||
signal(SIGTSTP, oldsigtstp);
|
||||
#endif
|
||||
signal(SIGTSTP, oldsigtstp);
|
||||
#endif
|
||||
|
||||
/* return the child's exit code */
|
||||
return(status >> 8);
|
||||
/* return the child's exit code */
|
||||
return(status >> 8);
|
||||
}
|
||||
|
||||
#endif /* !MSDOS */
|
||||
|
1896
src/find.c
1896
src/find.c
File diff suppressed because it is too large
Load Diff
390
src/global.h
390
src/global.h
@ -30,9 +30,9 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* global type, data, and function definitions
|
||||
* global type, data, and function definitions
|
||||
*/
|
||||
|
||||
#ifndef CSCOPE_GLOBAL_H
|
||||
@ -41,16 +41,16 @@
|
||||
//#include "config.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h> /* isalpha, isdigit, etc. */
|
||||
#include <signal.h> /* SIGINT and SIGQUIT */
|
||||
#include <stdio.h> /* standard I/O package */
|
||||
#include <ctype.h> /* isalpha, isdigit, etc. */
|
||||
#include <signal.h> /* SIGINT and SIGQUIT */
|
||||
#include <stdio.h> /* standard I/O package */
|
||||
#include <stdlib.h> /* standard library functions */
|
||||
|
||||
#include <string.h> /* string functions */
|
||||
#include <string.h> /* string functions */
|
||||
|
||||
#include "constants.h" /* misc. constants */
|
||||
#include "invlib.h" /* inverted index library */
|
||||
#include "library.h" /* library function return values */
|
||||
#include "constants.h" /* misc. constants */
|
||||
#include "invlib.h" /* inverted index library */
|
||||
#include "library.h" /* library function return values */
|
||||
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
@ -58,38 +58,38 @@ typedef void (*sighandler_t)(int);
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
typedef enum { /* boolean data type */
|
||||
NO,
|
||||
YES
|
||||
typedef enum { /* boolean data type */
|
||||
NO,
|
||||
YES
|
||||
} BOOL;
|
||||
|
||||
typedef enum { /* findinit return code */
|
||||
NOERROR,
|
||||
NOTSYMBOL,
|
||||
REGCMPERROR
|
||||
typedef enum { /* findinit return code */
|
||||
NOERROR,
|
||||
NOTSYMBOL,
|
||||
REGCMPERROR
|
||||
} FINDINIT;
|
||||
|
||||
typedef struct { /* mouse action */
|
||||
int button;
|
||||
int percent;
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
typedef struct { /* mouse action */
|
||||
int button;
|
||||
int percent;
|
||||
int x1;
|
||||
int y1;
|
||||
int x2;
|
||||
int y2;
|
||||
} MOUSE;
|
||||
|
||||
struct cmd { /* command history struct */
|
||||
struct cmd *prev, *next; /* list ptrs */
|
||||
int field; /* input field number */
|
||||
char *text; /* input field text */
|
||||
struct cmd { /* command history struct */
|
||||
struct cmd *prev, *next; /* list ptrs */
|
||||
int field; /* input field number */
|
||||
char *text; /* input field text */
|
||||
};
|
||||
|
||||
enum {
|
||||
CH_NONE = 0x0000,
|
||||
CH_RESULT = 0x0001 << 0,
|
||||
CH_INPUT = 0x0001 << 1,
|
||||
CH_MODE = 0x0001 << 2,
|
||||
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
|
||||
CH_NONE = 0x0000,
|
||||
CH_RESULT = 0x0001 << 0,
|
||||
CH_INPUT = 0x0001 << 1,
|
||||
CH_MODE = 0x0001 << 2,
|
||||
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
|
||||
};
|
||||
|
||||
|
||||
@ -100,113 +100,113 @@ enum {
|
||||
|
||||
|
||||
/* digraph data for text compression */
|
||||
extern char dichar1[]; /* 16 most frequent first chars */
|
||||
extern char dichar2[]; /* 8 most frequent second chars
|
||||
using the above as first chars */
|
||||
extern char dicode1[]; /* digraph first character code */
|
||||
extern char dicode2[]; /* digraph second character code */
|
||||
extern char dichar1[]; /* 16 most frequent first chars */
|
||||
extern char dichar2[]; /* 8 most frequent second chars
|
||||
using the above as first chars */
|
||||
extern char dicode1[]; /* digraph first character code */
|
||||
extern char dicode2[]; /* digraph second character code */
|
||||
|
||||
/* and some macros to help using dicodes: */
|
||||
/* Check if a given pair of chars is compressable as a dicode: */
|
||||
#define IS_A_DICODE(inchar1, inchar2) \
|
||||
#define IS_A_DICODE(inchar1, inchar2) \
|
||||
(dicode1[(unsigned char)(inchar1)] && dicode2[(unsigned char)(inchar2)])
|
||||
/* Combine the pair into a dicode */
|
||||
#define DICODE_COMPRESS(inchar1, inchar2) \
|
||||
((0200 - 2) + dicode1[(unsigned char)(inchar1)] \
|
||||
#define DICODE_COMPRESS(inchar1, inchar2) \
|
||||
((0200 - 2) + dicode1[(unsigned char)(inchar1)] \
|
||||
+ dicode2[(unsigned char)(inchar2)])
|
||||
|
||||
/* main.c global data */
|
||||
extern char *editor, *home, *shell, *lineflag; /* environment variables */
|
||||
extern char *home; /* Home directory */
|
||||
extern BOOL lineflagafterfile;
|
||||
extern char *argv0; /* command name */
|
||||
extern BOOL compress; /* compress the characters in the crossref */
|
||||
extern BOOL dbtruncated; /* database symbols truncated to 8 chars */
|
||||
extern int dispcomponents; /* file path components to display */
|
||||
extern char *editor, *home, *shell, *lineflag; /* environment variables */
|
||||
extern char *home; /* Home directory */
|
||||
extern BOOL lineflagafterfile;
|
||||
extern char *argv0; /* command name */
|
||||
extern BOOL compress; /* compress the characters in the crossref */
|
||||
extern BOOL dbtruncated; /* database symbols truncated to 8 chars */
|
||||
extern int dispcomponents; /* file path components to display */
|
||||
#if CCS
|
||||
extern BOOL displayversion; /* display the C Compilation System version */
|
||||
extern BOOL displayversion; /* display the C Compilation System version */
|
||||
#endif
|
||||
extern BOOL editallprompt; /* prompt between editing files */
|
||||
extern unsigned int fileargc; /* file argument count */
|
||||
extern char **fileargv; /* file argument values */
|
||||
extern int fileversion; /* cross-reference file version */
|
||||
extern BOOL incurses; /* in curses */
|
||||
extern BOOL invertedindex; /* the database has an inverted index */
|
||||
extern BOOL isuptodate; /* consider the crossref up-to-date */
|
||||
extern BOOL kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
||||
extern BOOL linemode; /* use line oriented user interface */
|
||||
extern BOOL verbosemode; /* print extra information on line mode */
|
||||
extern BOOL recurse_dir; /* recurse dirs when searching for src files */
|
||||
extern char *namefile; /* file of file names */
|
||||
extern BOOL ogs; /* display OGS book and subsystem names */
|
||||
extern char *prependpath; /* prepend path to file names */
|
||||
extern FILE *refsfound; /* references found file */
|
||||
extern char temp1[]; /* temporary file name */
|
||||
extern char temp2[]; /* temporary file name */
|
||||
extern long totalterms; /* total inverted index terms */
|
||||
extern BOOL trun_syms; /* truncate symbols to 8 characters */
|
||||
extern char tempstring[TEMPSTRING_LEN + 1]; /* global dummy string buffer */
|
||||
extern char *tmpdir; /* temporary directory */
|
||||
extern BOOL editallprompt; /* prompt between editing files */
|
||||
extern unsigned int fileargc; /* file argument count */
|
||||
extern char **fileargv; /* file argument values */
|
||||
extern int fileversion; /* cross-reference file version */
|
||||
extern BOOL incurses; /* in curses */
|
||||
extern BOOL invertedindex; /* the database has an inverted index */
|
||||
extern BOOL isuptodate; /* consider the crossref up-to-date */
|
||||
extern BOOL kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
||||
extern BOOL linemode; /* use line oriented user interface */
|
||||
extern BOOL verbosemode; /* print extra information on line mode */
|
||||
extern BOOL recurse_dir; /* recurse dirs when searching for src files */
|
||||
extern char *namefile; /* file of file names */
|
||||
extern BOOL ogs; /* display OGS book and subsystem names */
|
||||
extern char *prependpath; /* prepend path to file names */
|
||||
extern FILE *refsfound; /* references found file */
|
||||
extern char temp1[]; /* temporary file name */
|
||||
extern char temp2[]; /* temporary file name */
|
||||
extern long totalterms; /* total inverted index terms */
|
||||
extern BOOL trun_syms; /* truncate symbols to 8 characters */
|
||||
extern char tempstring[TEMPSTRING_LEN + 1]; /* global dummy string buffer */
|
||||
extern char *tmpdir; /* temporary directory */
|
||||
|
||||
/* command.c global data */
|
||||
extern BOOL caseless; /* ignore letter case when searching */
|
||||
extern BOOL *change; /* change this line */
|
||||
extern BOOL changing; /* changing text */
|
||||
extern unsigned int curdispline;
|
||||
extern char newpat[]; /* new pattern */
|
||||
extern BOOL caseless; /* ignore letter case when searching */
|
||||
extern BOOL *change; /* change this line */
|
||||
extern BOOL changing; /* changing text */
|
||||
extern unsigned int curdispline;
|
||||
extern char newpat[]; /* new pattern */
|
||||
|
||||
/* crossref.c global data */
|
||||
extern long dboffset; /* new database offset */
|
||||
extern BOOL errorsfound; /* prompt before clearing error messages */
|
||||
extern long lineoffset; /* source line database offset */
|
||||
extern long npostings; /* number of postings */
|
||||
extern unsigned long symbols; /* number of symbols */
|
||||
extern long dboffset; /* new database offset */
|
||||
extern BOOL errorsfound; /* prompt before clearing error messages */
|
||||
extern long lineoffset; /* source line database offset */
|
||||
extern long npostings; /* number of postings */
|
||||
extern unsigned long symbols; /* number of symbols */
|
||||
|
||||
/* dir.c global data */
|
||||
extern char currentdir[]; /* current directory */
|
||||
extern char **incdirs; /* #include directories */
|
||||
extern char **srcdirs; /* source directories */
|
||||
extern char **srcfiles; /* source files */
|
||||
extern unsigned long nincdirs; /* number of #include directories */
|
||||
extern unsigned long nsrcdirs; /* number of source directories */
|
||||
extern unsigned long nsrcfiles; /* number of source files */
|
||||
extern unsigned long msrcfiles; /* maximum number of source files */
|
||||
extern char currentdir[]; /* current directory */
|
||||
extern char **incdirs; /* #include directories */
|
||||
extern char **srcdirs; /* source directories */
|
||||
extern char **srcfiles; /* source files */
|
||||
extern unsigned long nincdirs; /* number of #include directories */
|
||||
extern unsigned long nsrcdirs; /* number of source directories */
|
||||
extern unsigned long nsrcfiles; /* number of source files */
|
||||
extern unsigned long msrcfiles; /* maximum number of source files */
|
||||
|
||||
/* display.c global data */
|
||||
extern int subsystemlen; /* OGS subsystem name display field length */
|
||||
extern int booklen; /* OGS book name display field length */
|
||||
extern int filelen; /* file name display field length */
|
||||
extern int fcnlen; /* function name display field length */
|
||||
extern int numlen; /* line number display field length */
|
||||
extern int *displine; /* screen line of displayed reference */
|
||||
extern unsigned int disprefs; /* displayed references */
|
||||
extern int field; /* input field */
|
||||
extern unsigned fldcolumn; /* input field column */
|
||||
extern unsigned int mdisprefs; /* maximum displayed references */
|
||||
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 unsigned int totallines; /* total reference lines */
|
||||
extern const char dispchars[]; /* display chars for jumping to lines */
|
||||
extern int window_change;
|
||||
extern int subsystemlen; /* OGS subsystem name display field length */
|
||||
extern int booklen; /* OGS book name display field length */
|
||||
extern int filelen; /* file name display field length */
|
||||
extern int fcnlen; /* function name display field length */
|
||||
extern int numlen; /* line number display field length */
|
||||
extern int *displine; /* screen line of displayed reference */
|
||||
extern unsigned int disprefs; /* displayed references */
|
||||
extern int field; /* input field */
|
||||
extern unsigned fldcolumn; /* input field column */
|
||||
extern unsigned int mdisprefs; /* maximum displayed references */
|
||||
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 unsigned int totallines; /* total reference lines */
|
||||
extern const char dispchars[]; /* display chars for jumping to lines */
|
||||
extern int window_change;
|
||||
|
||||
/* find.c global data */
|
||||
extern char block[]; /* cross-reference file block */
|
||||
extern char blockmark; /* mark character to be searched for */
|
||||
extern long blocknumber; /* block number */
|
||||
extern char *blockp; /* pointer to current character in block */
|
||||
extern int blocklen; /* length of disk block read */
|
||||
extern char block[]; /* cross-reference file block */
|
||||
extern char blockmark; /* mark character to be searched for */
|
||||
extern long blocknumber; /* block number */
|
||||
extern char *blockp; /* pointer to current character in block */
|
||||
extern int blocklen; /* length of disk block read */
|
||||
|
||||
/* lookup.c global data */
|
||||
extern struct keystruct {
|
||||
char *text;
|
||||
char delim;
|
||||
struct keystruct *next;
|
||||
extern struct keystruct {
|
||||
char *text;
|
||||
char delim;
|
||||
struct keystruct *next;
|
||||
} keyword[];
|
||||
|
||||
/* mouse.c global data */
|
||||
extern BOOL mouse; /* mouse interface */
|
||||
extern BOOL mouse; /* mouse interface */
|
||||
|
||||
/* readline.c global data */
|
||||
extern char* rl_line_buffer;
|
||||
@ -214,110 +214,110 @@ extern char input_line[PATLEN + 1];
|
||||
extern int rl_point;
|
||||
|
||||
#if UNIXPC
|
||||
extern BOOL unixpcmouse; /* UNIX PC mouse interface */
|
||||
extern BOOL unixpcmouse; /* UNIX PC mouse interface */
|
||||
#endif
|
||||
|
||||
/* cscope functions called from more than one function or between files */
|
||||
|
||||
char *filepath(char *file);
|
||||
char *findcalledby(char *pattern);
|
||||
char *findcalling(char *pattern);
|
||||
char *findallfcns(char *dummy);
|
||||
char *finddef(char *pattern);
|
||||
char *findfile(char *dummy);
|
||||
char *findinclude(char *pattern);
|
||||
char *findsymbol(char *pattern);
|
||||
char *findassign(char *pattern);
|
||||
char *findregexp(char *egreppat);
|
||||
char *findstring(char *pattern);
|
||||
char *inviewpath(char *file);
|
||||
char *lookup(char *ident);
|
||||
char *pathcomponents(char *path, int components);
|
||||
char *read_block(void);
|
||||
char *scanpast(char c);
|
||||
char *filepath(char *file);
|
||||
char *findcalledby(char *pattern);
|
||||
char *findcalling(char *pattern);
|
||||
char *findallfcns(char *dummy);
|
||||
char *finddef(char *pattern);
|
||||
char *findfile(char *dummy);
|
||||
char *findinclude(char *pattern);
|
||||
char *findsymbol(char *pattern);
|
||||
char *findassign(char *pattern);
|
||||
char *findregexp(char *egreppat);
|
||||
char *findstring(char *pattern);
|
||||
char *inviewpath(char *file);
|
||||
char *lookup(char *ident);
|
||||
char *pathcomponents(char *path, int components);
|
||||
char *read_block(void);
|
||||
char *scanpast(char c);
|
||||
|
||||
char ** parse_options(int *argc, char **argv);
|
||||
void error_usage(void);
|
||||
void longusage(void);
|
||||
void usage(void);
|
||||
extern BOOL remove_symfile_onexit;
|
||||
extern BOOL onesearch; /* one search only in line mode */
|
||||
extern char *reflines; /* symbol reference lines file */
|
||||
void longusage(void);
|
||||
void usage(void);
|
||||
extern BOOL remove_symfile_onexit;
|
||||
extern BOOL onesearch; /* one search only in line mode */
|
||||
extern char *reflines; /* symbol reference lines file */
|
||||
void verswp_field(void);
|
||||
void horswp_field(void);
|
||||
BOOL interpret(int c); // XXX: probably rename
|
||||
BOOL interpret(int c); // XXX: probably rename
|
||||
int handle_input(const char c);
|
||||
|
||||
void rlinit(void);
|
||||
void rlinit(void);
|
||||
|
||||
void addcmd(int f, char *s);
|
||||
void addsrcfile(char *path);
|
||||
void askforchar(void);
|
||||
void askforreturn(void);
|
||||
void cannotwrite(char *file);
|
||||
void cannotopen(char *file);
|
||||
void clearmsg(void);
|
||||
void clearmsg2(void);
|
||||
void countrefs(void);
|
||||
void crossref(char *srcfile);
|
||||
void addcmd(int f, char *s);
|
||||
void addsrcfile(char *path);
|
||||
void askforchar(void);
|
||||
void askforreturn(void);
|
||||
void cannotwrite(char *file);
|
||||
void cannotopen(char *file);
|
||||
void clearmsg(void);
|
||||
void clearmsg2(void);
|
||||
void countrefs(void);
|
||||
void crossref(char *srcfile);
|
||||
void dispinit(void);
|
||||
void display(void);
|
||||
void drawscrollbar(int top, int bot);
|
||||
void edit(char *file, char *linenum);
|
||||
void editall(void);
|
||||
void editref(int);
|
||||
void entercurses(void);
|
||||
void exitcurses(void);
|
||||
void findcleanup(void);
|
||||
void display(void);
|
||||
void drawscrollbar(int top, int bot);
|
||||
void edit(char *file, char *linenum);
|
||||
void editall(void);
|
||||
void editref(int);
|
||||
void entercurses(void);
|
||||
void exitcurses(void);
|
||||
void findcleanup(void);
|
||||
void freesrclist(void);
|
||||
void freeinclist(void);
|
||||
void freecrossref(void);
|
||||
void freefilelist(void);
|
||||
void help(void);
|
||||
void incfile(char *file, char *type);
|
||||
void freefilelist(void);
|
||||
void help(void);
|
||||
void incfile(char *file, char *type);
|
||||
void includedir(char *_dirname);
|
||||
void initsymtab(void);
|
||||
void makefilelist(void);
|
||||
void mousecleanup(void);
|
||||
void mousemenu(void);
|
||||
void mouseinit(void);
|
||||
void mousereinit(void);
|
||||
void myexit(int sig);
|
||||
void myperror(char *text);
|
||||
void ogsnames(char *file, char **subsystem, char **book);
|
||||
void progress(char *what, long current, long max);
|
||||
void putfilename(char *srcfile);
|
||||
void postmsg(char *msg);
|
||||
void postmsg2(char *msg);
|
||||
void posterr(char *msg,...);
|
||||
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 shellpath(char *out, int limit, char *in);
|
||||
void makefilelist(void);
|
||||
void mousecleanup(void);
|
||||
void mousemenu(void);
|
||||
void mouseinit(void);
|
||||
void mousereinit(void);
|
||||
void myexit(int sig);
|
||||
void myperror(char *text);
|
||||
void ogsnames(char *file, char **subsystem, char **book);
|
||||
void progress(char *what, long current, long max);
|
||||
void putfilename(char *srcfile);
|
||||
void postmsg(char *msg);
|
||||
void postmsg2(char *msg);
|
||||
void posterr(char *msg,...);
|
||||
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 shellpath(char *out, int limit, char *in);
|
||||
void sourcedir(char *dirlist);
|
||||
void myungetch(int c);
|
||||
void warning(char *text);
|
||||
void writestring(char *s);
|
||||
void myungetch(int c);
|
||||
void warning(char *text);
|
||||
void writestring(char *s);
|
||||
|
||||
BOOL infilelist(char *file);
|
||||
BOOL readrefs(char *filename);
|
||||
BOOL search(void);
|
||||
BOOL writerefsfound(void);
|
||||
BOOL infilelist(char *file);
|
||||
BOOL readrefs(char *filename);
|
||||
BOOL search(void);
|
||||
BOOL writerefsfound(void);
|
||||
|
||||
FINDINIT findinit(char *pattern);
|
||||
MOUSE *getmouseaction(char leading_char);
|
||||
struct cmd *currentcmd(void);
|
||||
struct cmd *prevcmd(void);
|
||||
struct cmd *nextcmd(void);
|
||||
MOUSE *getmouseaction(char leading_char);
|
||||
struct cmd *currentcmd(void);
|
||||
struct cmd *prevcmd(void);
|
||||
struct cmd *nextcmd(void);
|
||||
|
||||
int egrep(char *file, FILE *output, char *format);
|
||||
int mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless);
|
||||
int mygetch(void);
|
||||
int hash(char *ss);
|
||||
int execute(char *a, ...);
|
||||
long dbseek(long offset);
|
||||
int egrep(char *file, FILE *output, char *format);
|
||||
int mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless);
|
||||
int mygetch(void);
|
||||
int hash(char *ss);
|
||||
int execute(char *a, ...);
|
||||
long dbseek(long offset);
|
||||
|
||||
|
||||
#endif /* CSCOPE_GLOBAL_H */
|
||||
|
226
src/help.c
226
src/help.c
@ -30,9 +30,9 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* display help
|
||||
* display help
|
||||
*
|
||||
*/
|
||||
|
||||
@ -43,126 +43,126 @@
|
||||
#include <curses.h>
|
||||
#endif
|
||||
/*
|
||||
max num of lines of help screen -
|
||||
this number needs to be increased if more than n help items are needed
|
||||
max num of lines of help screen -
|
||||
this number needs to be increased if more than n help items are needed
|
||||
*/
|
||||
#define MAXHELP 50 /* maximum number of help strings */
|
||||
#define MAXHELP 50 /* maximum number of help strings */
|
||||
|
||||
void
|
||||
help(void)
|
||||
{
|
||||
char **ep, *s, **tp, *text[MAXHELP];
|
||||
int ln;
|
||||
char **ep, *s, **tp, *text[MAXHELP];
|
||||
int ln;
|
||||
|
||||
tp = text;
|
||||
if (changing == NO) {
|
||||
if (mouse) {
|
||||
*tp++ = "Point with the mouse and click button 1 to move to the desired input field,\n";
|
||||
*tp++ = "type the pattern to search for, and then press the RETURN key. For the first 4\n";
|
||||
*tp++ = "and last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
|
||||
*tp++ = "If the search is successful, you can edit the file containing a displayed line\n";
|
||||
*tp++ = "by pointing with the mouse and clicking button 1.\n";
|
||||
*tp++ = "\nYou can either use the button 2 menu or these single-character commands:\n\n";
|
||||
} else {
|
||||
*tp++ = "Press the RETURN key repeatedly to move to the desired input field, type the\n";
|
||||
*tp++ = "pattern to search for, and then press the RETURN key. For the first 4 and\n";
|
||||
*tp++ = "last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
|
||||
*tp++ = "If the search is successful, you can use these single-character commands:\n\n";
|
||||
*tp++ = "0-9a-zA-Z\tEdit the file containing the displayed line.\n";
|
||||
}
|
||||
*tp++ = "space bar\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "+\t\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "^V\t\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "-\t\tDisplay previous set of matching lines.\n";
|
||||
*tp++ = "^E\t\tEdit all lines.\n";
|
||||
*tp++ = ">\t\tWrite the list of lines being displayed to a file.\n";
|
||||
*tp++ = ">>\t\tAppend the list of lines being displayed to a file.\n";
|
||||
*tp++ = "<\t\tRead lines from a file.\n";
|
||||
*tp++ = "^\t\tFilter all lines through a shell command.\n";
|
||||
*tp++ = "|\t\tPipe all lines to a shell command.\n";
|
||||
if (!mouse) {
|
||||
*tp++ = "\nAt any time you can use these single-character commands:\n\n";
|
||||
*tp++ = "TAB\t\tSwap positions between input and output areas.\n";
|
||||
*tp++ = "RETURN\t\tMove to the next input field.\n";
|
||||
*tp++ = "^N\t\tMove to the next input field.\n";
|
||||
*tp++ = "^P\t\tMove to the previous input field.\n";
|
||||
}
|
||||
*tp++ = "^Y / ^A\t\tSearch with the last pattern typed.\n";
|
||||
*tp++ = "^B\t\tRecall previous input field and search pattern.\n";
|
||||
*tp++ = "^F\t\tRecall next input field and search pattern.\n";
|
||||
if(caseless)
|
||||
*tp++ = "^C\t\tToggle ignore/use letter case when searching (IGNORE).\n";
|
||||
else
|
||||
*tp++ = "^C\t\tToggle ignore/use letter case when searching (USE).\n";
|
||||
*tp++ = "^R\t\tRebuild the cross-reference.\n";
|
||||
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
|
||||
*tp++ = "^L\t\tRedraw the screen.\n";
|
||||
*tp++ = "?\t\tDisplay this list of commands.\n";
|
||||
*tp++ = "^D\t\tExit cscope.\n";
|
||||
*tp++ = "\nNote: If the first character of the pattern you want to search for matches\n";
|
||||
*tp++ = "a command, type a \\ character first.\n";
|
||||
*tp++ = "Note: Some ctrl keys may be occupied by your terminal configuration.\n";
|
||||
} else {
|
||||
if (mouse) {
|
||||
*tp++ = "Point with the mouse and click button 1 to mark or unmark the line to be\n";
|
||||
*tp++ = "changed. You can also use the button 2 menu or these single-character\n";
|
||||
*tp++ = "commands:\n\n";
|
||||
}
|
||||
else {
|
||||
*tp++ = "When changing text, you can use these single-character commands:\n\n";
|
||||
*tp++ = "0-9a-zA-Z\tMark or unmark the line to be changed.\n";
|
||||
}
|
||||
*tp++ = "*\t\tMark or unmark all displayed lines to be changed.\n";
|
||||
*tp++ = "space bar\tDisplay next set of lines.\n";
|
||||
*tp++ = "+\t\tDisplay next set of lines.\n";
|
||||
*tp++ = "-\t\tDisplay previous set of lines.\n";
|
||||
*tp++ = "^A\t\tMark or unmark all lines to be changed.\n";
|
||||
*tp++ = "^D\t\tChange the marked lines and exit.\n";
|
||||
*tp++ = "ESC\t\tExit without changing the marked lines.\n";
|
||||
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
|
||||
*tp++ = "^L\t\tRedraw the screen.\n";
|
||||
*tp++ = "?\t\tDisplay this list of commands.\n";
|
||||
}
|
||||
/* print help, a screen at a time */
|
||||
ep = tp;
|
||||
ln = 0;
|
||||
for (tp = text; tp < ep; ) {
|
||||
if (ln < LINES - 1) {
|
||||
for (s = *tp; *s != '\0'; ++s) {
|
||||
if (*s == '\n') {
|
||||
++ln;
|
||||
}
|
||||
}
|
||||
(void) addstr(*tp++);
|
||||
}
|
||||
else {
|
||||
(void) addstr("\n");
|
||||
askforchar();
|
||||
(void) clear();
|
||||
ln = 0;
|
||||
}
|
||||
}
|
||||
if (ln) {
|
||||
(void) addstr("\n");
|
||||
askforchar();
|
||||
}
|
||||
tp = text;
|
||||
if (changing == NO) {
|
||||
if (mouse) {
|
||||
*tp++ = "Point with the mouse and click button 1 to move to the desired input field,\n";
|
||||
*tp++ = "type the pattern to search for, and then press the RETURN key. For the first 4\n";
|
||||
*tp++ = "and last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
|
||||
*tp++ = "If the search is successful, you can edit the file containing a displayed line\n";
|
||||
*tp++ = "by pointing with the mouse and clicking button 1.\n";
|
||||
*tp++ = "\nYou can either use the button 2 menu or these single-character commands:\n\n";
|
||||
} else {
|
||||
*tp++ = "Press the RETURN key repeatedly to move to the desired input field, type the\n";
|
||||
*tp++ = "pattern to search for, and then press the RETURN key. For the first 4 and\n";
|
||||
*tp++ = "last 2 input fields, the pattern can be a regcomp(3) regular expression.\n";
|
||||
*tp++ = "If the search is successful, you can use these single-character commands:\n\n";
|
||||
*tp++ = "0-9a-zA-Z\tEdit the file containing the displayed line.\n";
|
||||
}
|
||||
*tp++ = "space bar\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "+\t\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "^V\t\tDisplay next set of matching lines.\n";
|
||||
*tp++ = "-\t\tDisplay previous set of matching lines.\n";
|
||||
*tp++ = "^E\t\tEdit all lines.\n";
|
||||
*tp++ = ">\t\tWrite the list of lines being displayed to a file.\n";
|
||||
*tp++ = ">>\t\tAppend the list of lines being displayed to a file.\n";
|
||||
*tp++ = "<\t\tRead lines from a file.\n";
|
||||
*tp++ = "^\t\tFilter all lines through a shell command.\n";
|
||||
*tp++ = "|\t\tPipe all lines to a shell command.\n";
|
||||
if (!mouse) {
|
||||
*tp++ = "\nAt any time you can use these single-character commands:\n\n";
|
||||
*tp++ = "TAB\t\tSwap positions between input and output areas.\n";
|
||||
*tp++ = "RETURN\t\tMove to the next input field.\n";
|
||||
*tp++ = "^N\t\tMove to the next input field.\n";
|
||||
*tp++ = "^P\t\tMove to the previous input field.\n";
|
||||
}
|
||||
*tp++ = "^Y / ^A\t\tSearch with the last pattern typed.\n";
|
||||
*tp++ = "^B\t\tRecall previous input field and search pattern.\n";
|
||||
*tp++ = "^F\t\tRecall next input field and search pattern.\n";
|
||||
if(caseless)
|
||||
*tp++ = "^C\t\tToggle ignore/use letter case when searching (IGNORE).\n";
|
||||
else
|
||||
*tp++ = "^C\t\tToggle ignore/use letter case when searching (USE).\n";
|
||||
*tp++ = "^R\t\tRebuild the cross-reference.\n";
|
||||
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
|
||||
*tp++ = "^L\t\tRedraw the screen.\n";
|
||||
*tp++ = "?\t\tDisplay this list of commands.\n";
|
||||
*tp++ = "^D\t\tExit cscope.\n";
|
||||
*tp++ = "\nNote: If the first character of the pattern you want to search for matches\n";
|
||||
*tp++ = "a command, type a \\ character first.\n";
|
||||
*tp++ = "Note: Some ctrl keys may be occupied by your terminal configuration.\n";
|
||||
} else {
|
||||
if (mouse) {
|
||||
*tp++ = "Point with the mouse and click button 1 to mark or unmark the line to be\n";
|
||||
*tp++ = "changed. You can also use the button 2 menu or these single-character\n";
|
||||
*tp++ = "commands:\n\n";
|
||||
}
|
||||
else {
|
||||
*tp++ = "When changing text, you can use these single-character commands:\n\n";
|
||||
*tp++ = "0-9a-zA-Z\tMark or unmark the line to be changed.\n";
|
||||
}
|
||||
*tp++ = "*\t\tMark or unmark all displayed lines to be changed.\n";
|
||||
*tp++ = "space bar\tDisplay next set of lines.\n";
|
||||
*tp++ = "+\t\tDisplay next set of lines.\n";
|
||||
*tp++ = "-\t\tDisplay previous set of lines.\n";
|
||||
*tp++ = "^A\t\tMark or unmark all lines to be changed.\n";
|
||||
*tp++ = "^D\t\tChange the marked lines and exit.\n";
|
||||
*tp++ = "ESC\t\tExit without changing the marked lines.\n";
|
||||
*tp++ = "!\t\tStart an interactive shell (type ^D to return to cscope).\n";
|
||||
*tp++ = "^L\t\tRedraw the screen.\n";
|
||||
*tp++ = "?\t\tDisplay this list of commands.\n";
|
||||
}
|
||||
/* print help, a screen at a time */
|
||||
ep = tp;
|
||||
ln = 0;
|
||||
for (tp = text; tp < ep; ) {
|
||||
if (ln < LINES - 1) {
|
||||
for (s = *tp; *s != '\0'; ++s) {
|
||||
if (*s == '\n') {
|
||||
++ln;
|
||||
}
|
||||
}
|
||||
(void) addstr(*tp++);
|
||||
}
|
||||
else {
|
||||
(void) addstr("\n");
|
||||
askforchar();
|
||||
(void) clear();
|
||||
ln = 0;
|
||||
}
|
||||
}
|
||||
if (ln) {
|
||||
(void) addstr("\n");
|
||||
askforchar();
|
||||
}
|
||||
}
|
||||
|
||||
/* error exit including short usage information */
|
||||
void
|
||||
error_usage(void)
|
||||
{
|
||||
usage();
|
||||
fprintf(stderr, "Try the -h option for more information.\n");
|
||||
myexit(1);
|
||||
usage();
|
||||
fprintf(stderr, "Try the -h option for more information.\n");
|
||||
myexit(1);
|
||||
}
|
||||
|
||||
/* normal usage message */
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: cscope [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]\n");
|
||||
fprintf(stderr, " [-p number] [-P path] [-[0-8] pattern] [source files]\n");
|
||||
fprintf(stderr, "Usage: cscope [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]\n");
|
||||
fprintf(stderr, " [-p number] [-P path] [-[0-8] pattern] [source files]\n");
|
||||
}
|
||||
|
||||
|
||||
@ -170,8 +170,8 @@ usage(void)
|
||||
void
|
||||
longusage(void)
|
||||
{
|
||||
usage();
|
||||
fprintf(stderr, "\
|
||||
usage();
|
||||
fprintf(stderr, "\
|
||||
\n\
|
||||
-b Build the cross-reference only.\n\
|
||||
-C Ignore letter case when searching.\n\
|
||||
@ -180,16 +180,16 @@ longusage(void)
|
||||
-e Suppress the <Ctrl>-e command prompt between files.\n\
|
||||
-F symfile Read symbol reference lines from symfile.\n\
|
||||
-f reffile Use reffile as cross-ref file name instead of %s.\n",
|
||||
REFFILE);
|
||||
fprintf(stderr, "\
|
||||
REFFILE);
|
||||
fprintf(stderr, "\
|
||||
-h This help screen.\n\
|
||||
-I incdir Look in incdir for any #include files.\n\
|
||||
-i namefile Browse through files listed in namefile, instead of %s\n",
|
||||
NAMEFILE);
|
||||
fprintf(stderr, "\
|
||||
NAMEFILE);
|
||||
fprintf(stderr, "\
|
||||
-k Kernel Mode - don't use %s for #include files.\n",
|
||||
DFLT_INCDIR);
|
||||
fputs("\
|
||||
DFLT_INCDIR);
|
||||
fputs("\
|
||||
-L Do a single search with line-oriented output.\n\
|
||||
-l Line-oriented interface.\n\
|
||||
-num pattern Go to input field num (counting from 0) and find pattern.\n\
|
||||
@ -205,5 +205,5 @@ longusage(void)
|
||||
-V Print the version number.\n\
|
||||
\n\
|
||||
Please see the manpage for more information.\n",
|
||||
stderr);
|
||||
stderr);
|
||||
}
|
||||
|
@ -30,75 +30,75 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol or text cross-reference
|
||||
/* cscope - interactive C symbol or text cross-reference
|
||||
*
|
||||
* command history
|
||||
* command history
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
|
||||
|
||||
static struct cmd *tail, *current;
|
||||
static struct cmd *tail, *current;
|
||||
|
||||
/* add a cmd to the history list */
|
||||
void
|
||||
addcmd(int f, char *s) /* field number and command text */
|
||||
addcmd(int f, char *s) /* field number and command text */
|
||||
{
|
||||
struct cmd *h;
|
||||
struct cmd *h;
|
||||
|
||||
h = malloc(sizeof(struct cmd));
|
||||
if( tail) {
|
||||
tail->next = h;
|
||||
h->next = 0;
|
||||
h->prev = tail;
|
||||
tail = h;
|
||||
} else {
|
||||
tail = h;
|
||||
h->next = h->prev = 0;
|
||||
}
|
||||
h->field = f;
|
||||
h->text = strdup( s);
|
||||
current = 0;
|
||||
h = malloc(sizeof(struct cmd));
|
||||
if( tail) {
|
||||
tail->next = h;
|
||||
h->next = 0;
|
||||
h->prev = tail;
|
||||
tail = h;
|
||||
} else {
|
||||
tail = h;
|
||||
h->next = h->prev = 0;
|
||||
}
|
||||
h->field = f;
|
||||
h->text = strdup( s);
|
||||
current = 0;
|
||||
}
|
||||
|
||||
/* return previous history item */
|
||||
struct cmd *
|
||||
prevcmd(void)
|
||||
{
|
||||
if( current) {
|
||||
if( current->prev) /* stay on first item */
|
||||
return current = current->prev;
|
||||
else
|
||||
return current;
|
||||
} else if( tail)
|
||||
return current = tail;
|
||||
else
|
||||
return NULL;
|
||||
if( current) {
|
||||
if( current->prev) /* stay on first item */
|
||||
return current = current->prev;
|
||||
else
|
||||
return current;
|
||||
} else if( tail)
|
||||
return current = tail;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* return next history item */
|
||||
struct cmd *
|
||||
nextcmd(void)
|
||||
{
|
||||
if( current) {
|
||||
if( current->next) /* stay on first item */
|
||||
return current = current->next;
|
||||
else
|
||||
return current;
|
||||
} else
|
||||
return NULL;
|
||||
if( current) {
|
||||
if( current->next) /* stay on first item */
|
||||
return current = current->next;
|
||||
else
|
||||
return current;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* reset current to tail */
|
||||
void
|
||||
resetcmd(void)
|
||||
{
|
||||
current = 0;
|
||||
current = 0;
|
||||
}
|
||||
|
||||
struct cmd *
|
||||
currentcmd(void)
|
||||
{
|
||||
return current;
|
||||
return current;
|
||||
}
|
||||
|
762
src/input.c
762
src/input.c
@ -30,9 +30,9 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* terminal input functions
|
||||
* terminal input functions
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
@ -41,15 +41,15 @@
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif
|
||||
#include <setjmp.h> /* jmp_buf */
|
||||
#include <setjmp.h> /* jmp_buf */
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#if HAVE_SYS_TERMIOS_H
|
||||
#include <sys/termios.h>
|
||||
#endif
|
||||
|
||||
static jmp_buf env; /* setjmp/longjmp buffer */
|
||||
static int prevchar; /* previous, ungotten character */
|
||||
static jmp_buf env; /* setjmp/longjmp buffer */
|
||||
static int prevchar; /* previous, ungotten character */
|
||||
|
||||
/* Internal prototypes: */
|
||||
static void catchint(int sig);
|
||||
@ -59,15 +59,15 @@ static void catchint(int sig);
|
||||
static void
|
||||
catchint(int sig)
|
||||
{
|
||||
signal(SIGINT, catchint);
|
||||
longjmp(env, 1);
|
||||
signal(SIGINT, catchint);
|
||||
longjmp(env, 1);
|
||||
}
|
||||
|
||||
/* unget a character */
|
||||
void
|
||||
myungetch(int c)
|
||||
{
|
||||
prevchar = c;
|
||||
prevchar = c;
|
||||
}
|
||||
|
||||
/* get a character from the terminal */
|
||||
@ -79,23 +79,23 @@ mygetch(void)
|
||||
|
||||
/* change an interrupt signal to a break key character */
|
||||
if (setjmp(env) == 0) {
|
||||
savesig = signal(SIGINT, catchint);
|
||||
refresh(); /* update the display */
|
||||
mousereinit(); /* curses can change the menu number */
|
||||
if(prevchar) {
|
||||
c = prevchar;
|
||||
prevchar = 0;
|
||||
} else {
|
||||
c = -1;
|
||||
while (c == -1) {
|
||||
/* get a character from the terminal */
|
||||
c = getch();
|
||||
if ((c == -1) && (errno != EINTR))
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { /* longjmp to here from signal handler */
|
||||
c = KEY_BREAK;
|
||||
savesig = signal(SIGINT, catchint);
|
||||
refresh(); /* update the display */
|
||||
mousereinit(); /* curses can change the menu number */
|
||||
if(prevchar) {
|
||||
c = prevchar;
|
||||
prevchar = 0;
|
||||
} else {
|
||||
c = -1;
|
||||
while (c == -1) {
|
||||
/* get a character from the terminal */
|
||||
c = getch();
|
||||
if ((c == -1) && (errno != EINTR))
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { /* longjmp to here from signal handler */
|
||||
c = KEY_BREAK;
|
||||
}
|
||||
signal(SIGINT, savesig);
|
||||
return(c);
|
||||
@ -106,10 +106,10 @@ mygetch(void)
|
||||
int
|
||||
mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
unsigned int i = 0, j;
|
||||
char *sright; /* substring to the right of the cursor */
|
||||
unsigned int ri = 0; /* position in right-string */
|
||||
char *sright; /* substring to the right of the cursor */
|
||||
unsigned int ri = 0; /* position in right-string */
|
||||
|
||||
/* Inserts and deletes are always performed on the left-string,
|
||||
* but we'll also have a right-string 'sright' to hold characters
|
||||
@ -126,107 +126,107 @@ mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless)
|
||||
i += strlen(p);
|
||||
/* if a character already has been typed */
|
||||
if (firstchar != '\0') {
|
||||
if(iscaseless == YES) {
|
||||
firstchar = tolower(firstchar);
|
||||
}
|
||||
addch(firstchar); /* display it */
|
||||
s[i++] = firstchar; /* save it */
|
||||
if(iscaseless == YES) {
|
||||
firstchar = tolower(firstchar);
|
||||
}
|
||||
addch(firstchar); /* display it */
|
||||
s[i++] = firstchar; /* save it */
|
||||
}
|
||||
/* until the end of the line is reached */
|
||||
while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER) {
|
||||
if (c == KEY_LEFT || c == ctrl('B')) { /* left */
|
||||
if (i > 0) {
|
||||
addch('\b');
|
||||
/* move this char into the second (rhs) string */
|
||||
sright[ri++] = s[--i];
|
||||
}
|
||||
} else if (c == KEY_RIGHT || c == ctrl('F')) { /* right */
|
||||
if (i < size && ri > 0) {
|
||||
/* move this char to the left of the cursor */
|
||||
s[i++] = sright[--ri];
|
||||
addch(s[i-1]);
|
||||
}
|
||||
} else if (
|
||||
if (c == KEY_LEFT || c == ctrl('B')) { /* left */
|
||||
if (i > 0) {
|
||||
addch('\b');
|
||||
/* move this char into the second (rhs) string */
|
||||
sright[ri++] = s[--i];
|
||||
}
|
||||
} else if (c == KEY_RIGHT || c == ctrl('F')) { /* right */
|
||||
if (i < size && ri > 0) {
|
||||
/* move this char to the left of the cursor */
|
||||
s[i++] = sright[--ri];
|
||||
addch(s[i-1]);
|
||||
}
|
||||
} else if (
|
||||
#ifdef KEY_HOME
|
||||
c == KEY_HOME ||
|
||||
c == KEY_HOME ||
|
||||
#endif
|
||||
c == ctrl('A') ) {
|
||||
while (i > 0) {
|
||||
sright[ri++] = s[--i];
|
||||
addch('\b');
|
||||
addch(s[i]);
|
||||
addch('\b');
|
||||
}
|
||||
} else if (
|
||||
c == ctrl('A') ) {
|
||||
while (i > 0) {
|
||||
sright[ri++] = s[--i];
|
||||
addch('\b');
|
||||
addch(s[i]);
|
||||
addch('\b');
|
||||
}
|
||||
} else if (
|
||||
#ifdef KEY_END
|
||||
c == KEY_END ||
|
||||
c == KEY_END ||
|
||||
#endif
|
||||
c == ctrl('E') ) {
|
||||
while (ri > 0) {
|
||||
s[i++] = sright[--ri];
|
||||
addch(s[i-1]);
|
||||
}
|
||||
} else if (c == erasechar() || c == KEY_BACKSPACE
|
||||
|| c == DEL || c == ctrl('H') ) {
|
||||
/* erase */
|
||||
if (i > 0) {
|
||||
if (ri == 0) {
|
||||
addstr("\b \b");
|
||||
} else {
|
||||
addch('\b');
|
||||
delch();
|
||||
}
|
||||
s[i] = '\0';
|
||||
--i;
|
||||
}
|
||||
} else if (c == killchar() || c == KEY_BREAK) {
|
||||
/* kill */
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch('\b');
|
||||
}
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch(' ');
|
||||
}
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch('\b');
|
||||
}
|
||||
i = 0;
|
||||
} else if (isprint(c) || c == '\t') {
|
||||
/* printable */
|
||||
if(iscaseless == YES) {
|
||||
c = tolower(c);
|
||||
}
|
||||
/* if it will fit on the line */
|
||||
if (i < size) {
|
||||
s[i++] = c; /* save it */
|
||||
if (ri == 0) {
|
||||
addch(c); /* display it */
|
||||
} else {
|
||||
insch(c); /* display it */
|
||||
addch(c); /* advance cursor */
|
||||
}
|
||||
}
|
||||
c == ctrl('E') ) {
|
||||
while (ri > 0) {
|
||||
s[i++] = sright[--ri];
|
||||
addch(s[i-1]);
|
||||
}
|
||||
} else if (c == erasechar() || c == KEY_BACKSPACE
|
||||
|| c == DEL || c == ctrl('H') ) {
|
||||
/* erase */
|
||||
if (i > 0) {
|
||||
if (ri == 0) {
|
||||
addstr("\b \b");
|
||||
} else {
|
||||
addch('\b');
|
||||
delch();
|
||||
}
|
||||
s[i] = '\0';
|
||||
--i;
|
||||
}
|
||||
} else if (c == killchar() || c == KEY_BREAK) {
|
||||
/* kill */
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch('\b');
|
||||
}
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch(' ');
|
||||
}
|
||||
for (j = 0; j < i; ++j) {
|
||||
addch('\b');
|
||||
}
|
||||
i = 0;
|
||||
} else if (isprint(c) || c == '\t') {
|
||||
/* printable */
|
||||
if(iscaseless == YES) {
|
||||
c = tolower(c);
|
||||
}
|
||||
/* if it will fit on the line */
|
||||
if (i < size) {
|
||||
s[i++] = c; /* save it */
|
||||
if (ri == 0) {
|
||||
addch(c); /* display it */
|
||||
} else {
|
||||
insch(c); /* display it */
|
||||
addch(c); /* advance cursor */
|
||||
}
|
||||
}
|
||||
#if UNIXPC
|
||||
} else if (unixpcmouse == YES && c == ESC) { /* mouse */
|
||||
getmouseaction(ESC); /* ignore it */
|
||||
} else if (unixpcmouse == YES && c == ESC) { /* mouse */
|
||||
getmouseaction(ESC); /* ignore it */
|
||||
#endif
|
||||
} else if (mouse == YES && c == ctrl('X')) {
|
||||
getmouseaction(ctrl('X')); /* ignore it */
|
||||
} else if (c == EOF) { /* end-of-file */
|
||||
break;
|
||||
}
|
||||
} else if (mouse == YES && c == ctrl('X')) {
|
||||
getmouseaction(ctrl('X')); /* ignore it */
|
||||
} else if (c == EOF) { /* end-of-file */
|
||||
break;
|
||||
}
|
||||
|
||||
/* return on an empty line to allow a command to be entered */
|
||||
if (firstchar != '\0' && (i+ri) == 0) {
|
||||
break;
|
||||
}
|
||||
/* return on an empty line to allow a command to be entered */
|
||||
if (firstchar != '\0' && (i+ri) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* move any remaining chars on the rhs of the cursor
|
||||
* onto the end of our string
|
||||
*/
|
||||
while (ri > 0) {
|
||||
s[i++] = sright[--ri];
|
||||
s[i++] = sright[--ri];
|
||||
}
|
||||
free(sright);
|
||||
|
||||
@ -252,7 +252,7 @@ askforreturn(void)
|
||||
getchar();
|
||||
/* HBB 20060419: message probably messed up the screen --- redraw */
|
||||
if (incurses == YES) {
|
||||
redrawwin(curscr);
|
||||
redrawwin(curscr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,70 +261,70 @@ askforreturn(void)
|
||||
void
|
||||
shellpath(char *out, int limit, char *in)
|
||||
{
|
||||
char *lastchar;
|
||||
char *s, *v;
|
||||
char *lastchar;
|
||||
char *s, *v;
|
||||
|
||||
/* skip leading white space */
|
||||
while (isspace((unsigned char)*in)) {
|
||||
++in;
|
||||
++in;
|
||||
}
|
||||
lastchar = out + limit - 1;
|
||||
|
||||
/* a tilde (~) by itself represents $HOME; followed by a name it
|
||||
represents the $LOGDIR of that login name */
|
||||
if (*in == '~') {
|
||||
*out++ = *in++; /* copy the ~ because it may not be expanded */
|
||||
*out++ = *in++; /* copy the ~ because it may not be expanded */
|
||||
|
||||
/* get the login name */
|
||||
s = out;
|
||||
while (s < lastchar && *in != '/' && *in != '\0' && !isspace((unsigned char)*in)) {
|
||||
*s++ = *in++;
|
||||
}
|
||||
*s = '\0';
|
||||
/* get the login name */
|
||||
s = out;
|
||||
while (s < lastchar && *in != '/' && *in != '\0' && !isspace((unsigned char)*in)) {
|
||||
*s++ = *in++;
|
||||
}
|
||||
*s = '\0';
|
||||
|
||||
/* if the login name is null, then use $HOME */
|
||||
if (*out == '\0') {
|
||||
v = getenv("HOME");
|
||||
} else { /* get the home directory of the login name */
|
||||
v = logdir(out);
|
||||
}
|
||||
/* copy the directory name if it isn't too big */
|
||||
if (v != NULL && strlen(v) < (lastchar - out)) {
|
||||
strcpy(out - 1, v);
|
||||
out += strlen(v) - 1;
|
||||
} else {
|
||||
/* login not found, so ~ must be part of the file name */
|
||||
out += strlen(out);
|
||||
}
|
||||
/* if the login name is null, then use $HOME */
|
||||
if (*out == '\0') {
|
||||
v = getenv("HOME");
|
||||
} else { /* get the home directory of the login name */
|
||||
v = logdir(out);
|
||||
}
|
||||
/* copy the directory name if it isn't too big */
|
||||
if (v != NULL && strlen(v) < (lastchar - out)) {
|
||||
strcpy(out - 1, v);
|
||||
out += strlen(v) - 1;
|
||||
} else {
|
||||
/* login not found, so ~ must be part of the file name */
|
||||
out += strlen(out);
|
||||
}
|
||||
}
|
||||
/* get the rest of the path */
|
||||
while (out < lastchar && *in != '\0' && !isspace((unsigned char)*in)) {
|
||||
|
||||
/* look for an environment variable */
|
||||
if (*in == '$') {
|
||||
*out++ = *in++; /* copy the $ because it may not be expanded */
|
||||
/* look for an environment variable */
|
||||
if (*in == '$') {
|
||||
*out++ = *in++; /* copy the $ because it may not be expanded */
|
||||
|
||||
/* get the variable name */
|
||||
s = out;
|
||||
while (s < lastchar && *in != '/' && *in != '\0' &&
|
||||
!isspace((unsigned char)*in)) {
|
||||
*s++ = *in++;
|
||||
}
|
||||
*s = '\0';
|
||||
|
||||
/* get its value, but only it isn't too big */
|
||||
if ((v = getenv(out)) != NULL && strlen(v) < (lastchar - out)) {
|
||||
strcpy(out - 1, v);
|
||||
out += strlen(v) - 1;
|
||||
} else {
|
||||
/* var not found, or too big, so assume $ must be part of the
|
||||
* file name */
|
||||
out += strlen(out);
|
||||
}
|
||||
}
|
||||
else { /* ordinary character */
|
||||
*out++ = *in++;
|
||||
}
|
||||
/* get the variable name */
|
||||
s = out;
|
||||
while (s < lastchar && *in != '/' && *in != '\0' &&
|
||||
!isspace((unsigned char)*in)) {
|
||||
*s++ = *in++;
|
||||
}
|
||||
*s = '\0';
|
||||
|
||||
/* get its value, but only it isn't too big */
|
||||
if ((v = getenv(out)) != NULL && strlen(v) < (lastchar - out)) {
|
||||
strcpy(out - 1, v);
|
||||
out += strlen(v) - 1;
|
||||
} else {
|
||||
/* var not found, or too big, so assume $ must be part of the
|
||||
* file name */
|
||||
out += strlen(out);
|
||||
}
|
||||
}
|
||||
else { /* ordinary character */
|
||||
*out++ = *in++;
|
||||
}
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
@ -332,223 +332,223 @@ shellpath(char *out, int limit, char *in)
|
||||
static int
|
||||
wmode_input(const int c){
|
||||
switch (c) {
|
||||
case KEY_ENTER:
|
||||
case '\r':
|
||||
case '\n':
|
||||
case ctrl('N'): /* go to next input field */
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
field = (field + 1) % FIELDS;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case ctrl('P'): /* go to previous input field */
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
field = (field + (FIELDS - 1)) % FIELDS;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case KEY_HOME: /* go to first input field */
|
||||
field = 0;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case KEY_LL: /* go to last input field */
|
||||
curdispline = disprefs;
|
||||
return(YES);
|
||||
}
|
||||
case KEY_ENTER:
|
||||
case '\r':
|
||||
case '\n':
|
||||
case ctrl('N'): /* go to next input field */
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
field = (field + 1) % FIELDS;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case ctrl('P'): /* go to previous input field */
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
field = (field + (FIELDS - 1)) % FIELDS;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case KEY_HOME: /* go to first input field */
|
||||
field = 0;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
case KEY_LL: /* go to last input field */
|
||||
curdispline = disprefs;
|
||||
return(YES);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
wresult_input(const int c){
|
||||
switch (c) {
|
||||
case KEY_ENTER: /* open for editing */
|
||||
case '\r':
|
||||
case '\n':
|
||||
editref(curdispline);
|
||||
window_change = CH_ALL;
|
||||
return(YES);
|
||||
case ctrl('N'):
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
if ((curdispline + 1) < disprefs) {
|
||||
++curdispline;
|
||||
}
|
||||
return(NO);
|
||||
case ctrl('P'):
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
if (curdispline) {
|
||||
--curdispline;
|
||||
}
|
||||
return(NO);
|
||||
case KEY_HOME:
|
||||
curdispline = 0;
|
||||
return(NO);
|
||||
case KEY_LL:
|
||||
field = FIELDS - 1;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
default:
|
||||
char *e;
|
||||
if ((e = strchr(dispchars, c)))
|
||||
editref(e - dispchars);
|
||||
}
|
||||
case KEY_ENTER: /* open for editing */
|
||||
case '\r':
|
||||
case '\n':
|
||||
editref(curdispline);
|
||||
window_change = CH_ALL;
|
||||
return(YES);
|
||||
case ctrl('N'):
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
if ((curdispline + 1) < disprefs) {
|
||||
++curdispline;
|
||||
}
|
||||
return(NO);
|
||||
case ctrl('P'):
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
if (curdispline) {
|
||||
--curdispline;
|
||||
}
|
||||
return(NO);
|
||||
case KEY_HOME:
|
||||
curdispline = 0;
|
||||
return(NO);
|
||||
case KEY_LL:
|
||||
field = FIELDS - 1;
|
||||
resetcmd();
|
||||
return(NO);
|
||||
default:
|
||||
char *e;
|
||||
if ((e = strchr(dispchars, c)))
|
||||
editref(e - dispchars);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
global_input(const int c){
|
||||
switch(c){
|
||||
case ' ': /* display next page */
|
||||
case '+':
|
||||
case ctrl('V'):
|
||||
case KEY_NPAGE:
|
||||
if (totallines == 0) { return(NO); } /* don't redisplay if there are no lines */
|
||||
/* XXX: figure out whether this comment is useful or not */
|
||||
/* NOTE: seekline() is not used to move to the next
|
||||
* page because display() leaves the file pointer at
|
||||
* the next page to optimize paging forward
|
||||
*/
|
||||
curdispline = 0;
|
||||
break;
|
||||
case ctrl('H'): /* display previous page */
|
||||
case '-':
|
||||
case KEY_PPAGE:
|
||||
if (totallines == 0) { return(NO); } /* don't redisplay if there are no lines */
|
||||
curdispline = 0;
|
||||
/* if there are only two pages, just go to the other one */
|
||||
if (totallines <= 2 * mdisprefs) {
|
||||
break;
|
||||
}
|
||||
/* 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
|
||||
//char filename[PATHLEN + 1];
|
||||
//char* s;
|
||||
//char ch;
|
||||
//FILE* file;
|
||||
//if (totallines == 0) {
|
||||
// postmsg("There are no lines to write to a file");
|
||||
// return(NO);
|
||||
//}
|
||||
//move(PRLINE, 0);
|
||||
////addstr("Write to file: "); // XXX
|
||||
//s = "w";
|
||||
//if ((ch = mygetch()) == '>') {
|
||||
//move(PRLINE, 0);
|
||||
////addstr(appendprompt); // XXX fix
|
||||
////ch = '\0';
|
||||
////s = "a";
|
||||
////}
|
||||
////if (ch != '\r' && mygetline("", newpat, COLS - sizeof(appendprompt), c, NO) > 0) {
|
||||
//// shellpath(filename, sizeof(filename), newpat);
|
||||
//// if ((file = myfopen(filename, s)) == NULL) {
|
||||
//// cannotopen(filename);
|
||||
//// } else {
|
||||
//// seekline(1);
|
||||
//// while ((ch = getc(refsfound)) != EOF) {
|
||||
//// putc(ch, file);
|
||||
//// }
|
||||
//// seekline(topline);
|
||||
//// fclose(file);
|
||||
//// }
|
||||
////}
|
||||
////clearprompt();
|
||||
return(NO); /* return to the previous field */
|
||||
case '<': /* read lines from a file */
|
||||
break; // XXX
|
||||
move(PRLINE, 0);
|
||||
//addstr(readprompt); // XXX fix
|
||||
//if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) {
|
||||
// clearprompt();
|
||||
// shellpath(filename, sizeof(filename), newpat);
|
||||
// if (readrefs(filename) == NO) {
|
||||
// postmsg2("Ignoring an empty file");
|
||||
// return(NO);
|
||||
// }
|
||||
// window_change |= CH_INPUT;
|
||||
// return(YES);
|
||||
//}
|
||||
//clearprompt();
|
||||
return(NO);
|
||||
case '|': /* pipe the lines to a shell command */
|
||||
case '^':
|
||||
break; // XXX fix
|
||||
if (totallines == 0) {
|
||||
postmsg("There are no lines to pipe to a shell command");
|
||||
return(NO);
|
||||
}
|
||||
/* get the shell command */
|
||||
move(PRLINE, 0);
|
||||
//addstr(pipeprompt);
|
||||
//if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) {
|
||||
// clearprompt();
|
||||
// return(NO);
|
||||
//}
|
||||
///* if the ^ command, redirect output to a temp file */
|
||||
//if (commandc == '^') {
|
||||
// strcat(strcat(newpat, " >"), temp2);
|
||||
// /* HBB 20020708: somebody might have even
|
||||
// * their non-interactive default shells
|
||||
// * complain about clobbering
|
||||
// * redirections... --> delete before
|
||||
// * overwriting */
|
||||
// remove(temp2);
|
||||
//}
|
||||
//exitcurses();
|
||||
//if ((file = mypopen(newpat, "w")) == NULL) {
|
||||
// fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat);
|
||||
//} else {
|
||||
// seekline(1);
|
||||
// while ((c = getc(refsfound)) != EOF) {
|
||||
// putc(c, file);
|
||||
// }
|
||||
// seekline(topline);
|
||||
// mypclose(file);
|
||||
//}
|
||||
//if (commandc == '^') {
|
||||
// if (readrefs(temp2) == NO) {
|
||||
// postmsg("Ignoring empty output of ^ command");
|
||||
// }
|
||||
//}
|
||||
//askforreturn();
|
||||
//entercurses();
|
||||
break;
|
||||
case '!': /* shell escape */
|
||||
execute(shell, shell, NULL);
|
||||
seekline(topline);
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
/* XXX: fill in*/
|
||||
break;
|
||||
case ctrl('L'): /* redraw screen */
|
||||
case KEY_CLEAR:
|
||||
window_change = CH_ALL;
|
||||
return(NO);
|
||||
case '?': /* help */
|
||||
clear();
|
||||
help();
|
||||
clear();
|
||||
seekline(topline);
|
||||
break;
|
||||
case ctrl('E'): /* edit all lines */
|
||||
editall();
|
||||
break;
|
||||
}
|
||||
switch(c){
|
||||
case ' ': /* display next page */
|
||||
case '+':
|
||||
case ctrl('V'):
|
||||
case KEY_NPAGE:
|
||||
if (totallines == 0) { return(NO); } /* don't redisplay if there are no lines */
|
||||
/* XXX: figure out whether this comment is useful or not */
|
||||
/* NOTE: seekline() is not used to move to the next
|
||||
* page because display() leaves the file pointer at
|
||||
* the next page to optimize paging forward
|
||||
*/
|
||||
curdispline = 0;
|
||||
break;
|
||||
case ctrl('H'): /* display previous page */
|
||||
case '-':
|
||||
case KEY_PPAGE:
|
||||
if (totallines == 0) { return(NO); } /* don't redisplay if there are no lines */
|
||||
curdispline = 0;
|
||||
/* if there are only two pages, just go to the other one */
|
||||
if (totallines <= 2 * mdisprefs) {
|
||||
break;
|
||||
}
|
||||
/* 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
|
||||
//char filename[PATHLEN + 1];
|
||||
//char* s;
|
||||
//char ch;
|
||||
//FILE* file;
|
||||
//if (totallines == 0) {
|
||||
// postmsg("There are no lines to write to a file");
|
||||
// return(NO);
|
||||
//}
|
||||
//move(PRLINE, 0);
|
||||
////addstr("Write to file: "); // XXX
|
||||
//s = "w";
|
||||
//if ((ch = mygetch()) == '>') {
|
||||
//move(PRLINE, 0);
|
||||
////addstr(appendprompt); // XXX fix
|
||||
////ch = '\0';
|
||||
////s = "a";
|
||||
////}
|
||||
////if (ch != '\r' && mygetline("", newpat, COLS - sizeof(appendprompt), c, NO) > 0) {
|
||||
//// shellpath(filename, sizeof(filename), newpat);
|
||||
//// if ((file = myfopen(filename, s)) == NULL) {
|
||||
//// cannotopen(filename);
|
||||
//// } else {
|
||||
//// seekline(1);
|
||||
//// while ((ch = getc(refsfound)) != EOF) {
|
||||
//// putc(ch, file);
|
||||
//// }
|
||||
//// seekline(topline);
|
||||
//// fclose(file);
|
||||
//// }
|
||||
////}
|
||||
////clearprompt();
|
||||
return(NO); /* return to the previous field */
|
||||
case '<': /* read lines from a file */
|
||||
break; // XXX
|
||||
move(PRLINE, 0);
|
||||
//addstr(readprompt); // XXX fix
|
||||
//if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) {
|
||||
// clearprompt();
|
||||
// shellpath(filename, sizeof(filename), newpat);
|
||||
// if (readrefs(filename) == NO) {
|
||||
// postmsg2("Ignoring an empty file");
|
||||
// return(NO);
|
||||
// }
|
||||
// window_change |= CH_INPUT;
|
||||
// return(YES);
|
||||
//}
|
||||
//clearprompt();
|
||||
return(NO);
|
||||
case '|': /* pipe the lines to a shell command */
|
||||
case '^':
|
||||
break; // XXX fix
|
||||
if (totallines == 0) {
|
||||
postmsg("There are no lines to pipe to a shell command");
|
||||
return(NO);
|
||||
}
|
||||
/* get the shell command */
|
||||
move(PRLINE, 0);
|
||||
//addstr(pipeprompt);
|
||||
//if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) {
|
||||
// clearprompt();
|
||||
// return(NO);
|
||||
//}
|
||||
///* if the ^ command, redirect output to a temp file */
|
||||
//if (commandc == '^') {
|
||||
// strcat(strcat(newpat, " >"), temp2);
|
||||
// /* HBB 20020708: somebody might have even
|
||||
// * their non-interactive default shells
|
||||
// * complain about clobbering
|
||||
// * redirections... --> delete before
|
||||
// * overwriting */
|
||||
// remove(temp2);
|
||||
//}
|
||||
//exitcurses();
|
||||
//if ((file = mypopen(newpat, "w")) == NULL) {
|
||||
// fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat);
|
||||
//} else {
|
||||
// seekline(1);
|
||||
// while ((c = getc(refsfound)) != EOF) {
|
||||
// putc(c, file);
|
||||
// }
|
||||
// seekline(topline);
|
||||
// mypclose(file);
|
||||
//}
|
||||
//if (commandc == '^') {
|
||||
// if (readrefs(temp2) == NO) {
|
||||
// postmsg("Ignoring empty output of ^ command");
|
||||
// }
|
||||
//}
|
||||
//askforreturn();
|
||||
//entercurses();
|
||||
break;
|
||||
case '!': /* shell escape */
|
||||
execute(shell, shell, NULL);
|
||||
seekline(topline);
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
/* XXX: fill in*/
|
||||
break;
|
||||
case ctrl('L'): /* redraw screen */
|
||||
case KEY_CLEAR:
|
||||
window_change = CH_ALL;
|
||||
return(NO);
|
||||
case '?': /* help */
|
||||
clear();
|
||||
help();
|
||||
clear();
|
||||
seekline(topline);
|
||||
break;
|
||||
case ctrl('E'): /* edit all lines */
|
||||
editall();
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern const void const* winput;
|
||||
@ -558,17 +558,17 @@ extern const void const* const* current_window;
|
||||
|
||||
int
|
||||
handle_input(const char c){
|
||||
/* --- global --- */
|
||||
const int r = global_input(c);
|
||||
if(r){ return r; }
|
||||
/* --- mode specific --- */
|
||||
if(*current_window == winput){
|
||||
return interpret(c);
|
||||
}else if(*current_window == wmode){
|
||||
return wmode_input(c);
|
||||
}else if(*current_window == wresult){
|
||||
return wresult_input(c);
|
||||
}
|
||||
/* --- global --- */
|
||||
const int r = global_input(c);
|
||||
if(r){ return r; }
|
||||
/* --- mode specific --- */
|
||||
if(*current_window == winput){
|
||||
return interpret(c);
|
||||
}else if(*current_window == wmode){
|
||||
return wmode_input(c);
|
||||
}else if(*current_window == wresult){
|
||||
return wresult_input(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
1828
src/invlib.c
1828
src/invlib.c
File diff suppressed because it is too large
Load Diff
90
src/invlib.h
90
src/invlib.h
@ -33,54 +33,54 @@
|
||||
#ifndef CSCOPE_INVLIB_H
|
||||
#define CSCOPE_INVLIB_H
|
||||
|
||||
#include <stdio.h> /* need definition of FILE* */
|
||||
#include <stdio.h> /* need definition of FILE* */
|
||||
#include <limits.h> /* need definition of CHAR_MAX */
|
||||
|
||||
/* inverted index definitions */
|
||||
|
||||
/* postings temporary file long number coding into characters */
|
||||
#if CHAR_MAX==255
|
||||
# define BASE 223 /* 255 - ' ' */
|
||||
# define PRECISION 4 /* maximum digits after converting a long */
|
||||
# define BASE 223 /* 255 - ' ' */
|
||||
# define PRECISION 4 /* maximum digits after converting a long */
|
||||
#else
|
||||
# if CHAR_MAX==127 /* assume sign-extension of a char when converted to an int */
|
||||
# define BASE 95 /* 127 - ' ' */
|
||||
# define PRECISION 5 /* maximum digits after converting a long */
|
||||
# if CHAR_MAX==127 /* assume sign-extension of a char when converted to an int */
|
||||
# define BASE 95 /* 127 - ' ' */
|
||||
# define PRECISION 5 /* maximum digits after converting a long */
|
||||
# else
|
||||
#error Need a platform with 8 bits in a char value
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* inverted index access parameters */
|
||||
#define INVAVAIL 0
|
||||
#define INVBUSY 1
|
||||
#define INVALONE 2
|
||||
#define INVAVAIL 0
|
||||
#define INVBUSY 1
|
||||
#define INVALONE 2
|
||||
|
||||
/* boolean set operations */
|
||||
#define BOOL_OR 3
|
||||
#define AND 4
|
||||
#define NOT 5
|
||||
#define REVERSENOT 6
|
||||
#define BOOL_OR 3
|
||||
#define AND 4
|
||||
#define NOT 5
|
||||
#define REVERSENOT 6
|
||||
|
||||
/* note that the entire first block is for parameters */
|
||||
typedef struct {
|
||||
long version; /* inverted index format version */
|
||||
long filestat; /* file status word */
|
||||
long sizeblk; /* size of logical block in bytes */
|
||||
long startbyte; /* first byte of superfinger */
|
||||
long supsize; /* size of superfinger in bytes */
|
||||
long cntlsize; /* size of max cntl space (should be a multiple of BUFSIZ) */
|
||||
long share; /* flag whether to use shared memory */
|
||||
typedef struct {
|
||||
long version; /* inverted index format version */
|
||||
long filestat; /* file status word */
|
||||
long sizeblk; /* size of logical block in bytes */
|
||||
long startbyte; /* first byte of superfinger */
|
||||
long supsize; /* size of superfinger in bytes */
|
||||
long cntlsize; /* size of max cntl space (should be a multiple of BUFSIZ) */
|
||||
long share; /* flag whether to use shared memory */
|
||||
} PARAM;
|
||||
|
||||
typedef struct {
|
||||
FILE *invfile; /* the inverted file ptr */
|
||||
FILE *postfile; /* posting file ptr */
|
||||
PARAM param; /* control parameters for the file */
|
||||
char *iindex; /* ptr to space for superindex */
|
||||
union logicalblk *logblk; /* ptr to space for a logical block */
|
||||
long numblk; /* number of block presently at *logblk */
|
||||
long keypnt; /* number item in present block found */
|
||||
typedef struct {
|
||||
FILE *invfile; /* the inverted file ptr */
|
||||
FILE *postfile; /* posting file ptr */
|
||||
PARAM param; /* control parameters for the file */
|
||||
char *iindex; /* ptr to space for superindex */
|
||||
union logicalblk *logblk; /* ptr to space for a logical block */
|
||||
long numblk; /* number of block presently at *logblk */
|
||||
long keypnt; /* number item in present block found */
|
||||
} INVCONTROL;
|
||||
|
||||
typedef struct {
|
||||
@ -90,25 +90,25 @@ typedef struct {
|
||||
long post; /* number of postings for this entry */
|
||||
} ENTRY;
|
||||
|
||||
typedef struct {
|
||||
long lineoffset; /* source line database offset */
|
||||
long fcnoffset; /* function name database offset */
|
||||
long fileindex : 24; /* source file name index */
|
||||
long type : 8; /* reference type (mark character) */
|
||||
typedef struct {
|
||||
long lineoffset; /* source line database offset */
|
||||
long fcnoffset; /* function name database offset */
|
||||
long fileindex : 24; /* source file name index */
|
||||
long type : 8; /* reference type (mark character) */
|
||||
} POSTING;
|
||||
|
||||
extern long *srcoffset; /* source file name database offsets */
|
||||
extern int nsrcoffset; /* number of file name database offsets */
|
||||
extern long *srcoffset; /* source file name database offsets */
|
||||
extern int nsrcoffset; /* number of file name database offsets */
|
||||
|
||||
|
||||
void boolclear(void);
|
||||
POSTING *boolfile(INVCONTROL *invcntl, long *num, int boolarg);
|
||||
void invclose(INVCONTROL *invcntl);
|
||||
void invdump(INVCONTROL *invcntl, char *term);
|
||||
long invfind(INVCONTROL *invcntl, char *searchterm);
|
||||
int invforward(INVCONTROL *invcntl);
|
||||
int invopen(INVCONTROL *invcntl, char *invname, char *invpost, int status);
|
||||
long invmake(char *invname, char *invpost, FILE *infile);
|
||||
long invterm(INVCONTROL *invcntl, char *term);
|
||||
void boolclear(void);
|
||||
POSTING *boolfile(INVCONTROL *invcntl, long *num, int boolarg);
|
||||
void invclose(INVCONTROL *invcntl);
|
||||
void invdump(INVCONTROL *invcntl, char *term);
|
||||
long invfind(INVCONTROL *invcntl, char *searchterm);
|
||||
int invforward(INVCONTROL *invcntl);
|
||||
int invopen(INVCONTROL *invcntl, char *invname, char *invpost, int status);
|
||||
long invmake(char *invname, char *invpost, FILE *infile);
|
||||
long invterm(INVCONTROL *invcntl, char *term);
|
||||
|
||||
#endif /* CSCOPE_INVLIB_H */
|
||||
|
@ -33,19 +33,19 @@
|
||||
#ifndef CSCOPE_LIBRARY_H
|
||||
#define CSCOPE_LIBRARY_H
|
||||
|
||||
#include <stdio.h> /* need FILE* type def. */
|
||||
#include <stdio.h> /* need FILE* type def. */
|
||||
|
||||
/* private library */
|
||||
char *compath(char *pathname);
|
||||
char *egrepinit(char *egreppat);
|
||||
char *logdir(char *name);
|
||||
char *basename(char *path);
|
||||
FILE *myfopen(char *path, char *mode);
|
||||
char *mygetenv(char *variable, char *deflt);
|
||||
int myopen(char *path, int flag, int mode);
|
||||
FILE *mypopen(char *cmd, char *mode);
|
||||
int mypclose(FILE *ptr);
|
||||
FILE *vpfopen(char *filename, char *type);
|
||||
void egrepcaseless(int i);
|
||||
char *compath(char *pathname);
|
||||
char *egrepinit(char *egreppat);
|
||||
char *logdir(char *name);
|
||||
char *basename(char *path);
|
||||
FILE *myfopen(char *path, char *mode);
|
||||
char *mygetenv(char *variable, char *deflt);
|
||||
int myopen(char *path, int flag, int mode);
|
||||
FILE *mypopen(char *cmd, char *mode);
|
||||
int mypclose(FILE *ptr);
|
||||
FILE *vpfopen(char *filename, char *type);
|
||||
void egrepcaseless(int i);
|
||||
|
||||
#endif /* CSCOPE_LIBRARY_H */
|
||||
|
90
src/logdir.c
90
src/logdir.c
@ -31,70 +31,70 @@
|
||||
=========================================================================*/
|
||||
|
||||
/*
|
||||
* logdir()
|
||||
* logdir()
|
||||
*
|
||||
* This routine does not use the getpwent(3) library routine
|
||||
* because the latter uses the stdio package. The allocation of
|
||||
* storage in this package destroys the integrity of the shell's
|
||||
* storage allocation.
|
||||
* This routine does not use the getpwent(3) library routine
|
||||
* because the latter uses the stdio package. The allocation of
|
||||
* storage in this package destroys the integrity of the shell's
|
||||
* storage allocation.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "global.h"
|
||||
|
||||
#define OURBUFSIZ 160 /* renamed: avoid conflict with <stdio.h> */
|
||||
#define OURBUFSIZ 160 /* renamed: avoid conflict with <stdio.h> */
|
||||
|
||||
static char line[OURBUFSIZ+1];
|
||||
|
||||
/* Internal prototypes: */
|
||||
static char *nextfield(char *p);
|
||||
static char *nextfield(char *p);
|
||||
|
||||
|
||||
static char *
|
||||
nextfield(char *p)
|
||||
{
|
||||
while (*p && *p != ':')
|
||||
++p;
|
||||
if (*p) *p++ = 0;
|
||||
return(p);
|
||||
while (*p && *p != ':')
|
||||
++p;
|
||||
if (*p) *p++ = 0;
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *
|
||||
logdir(char *name)
|
||||
{
|
||||
char *p;
|
||||
int i, j;
|
||||
int pwf;
|
||||
|
||||
/* attempt to open the password file */
|
||||
if ((pwf = myopen("/etc/passwd", 0, 0)) == -1)
|
||||
return(0);
|
||||
|
||||
/* find the matching password entry */
|
||||
do {
|
||||
/* get the next line in the password file */
|
||||
i = read(pwf, line, OURBUFSIZ);
|
||||
for (j = 0; j < i; j++)
|
||||
if (line[j] == '\n')
|
||||
break;
|
||||
/* return a null pointer if the whole file has been read */
|
||||
if (j >= i)
|
||||
return(0);
|
||||
line[++j] = 0; /* terminate the line */
|
||||
(void) lseek(pwf, (long) (j - i), 1); /* point at the next line */
|
||||
p = nextfield(line); /* get the logname */
|
||||
} while (*name != *line || /* fast pretest */
|
||||
strcmp(name, line) != 0);
|
||||
(void) close(pwf);
|
||||
|
||||
/* skip the intervening fields */
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
|
||||
/* return the login directory */
|
||||
(void) nextfield(p);
|
||||
return(p);
|
||||
char *p;
|
||||
int i, j;
|
||||
int pwf;
|
||||
|
||||
/* attempt to open the password file */
|
||||
if ((pwf = myopen("/etc/passwd", 0, 0)) == -1)
|
||||
return(0);
|
||||
|
||||
/* find the matching password entry */
|
||||
do {
|
||||
/* get the next line in the password file */
|
||||
i = read(pwf, line, OURBUFSIZ);
|
||||
for (j = 0; j < i; j++)
|
||||
if (line[j] == '\n')
|
||||
break;
|
||||
/* return a null pointer if the whole file has been read */
|
||||
if (j >= i)
|
||||
return(0);
|
||||
line[++j] = 0; /* terminate the line */
|
||||
(void) lseek(pwf, (long) (j - i), 1); /* point at the next line */
|
||||
p = nextfield(line); /* get the logname */
|
||||
} while (*name != *line || /* fast pretest */
|
||||
strcmp(name, line) != 0);
|
||||
(void) close(pwf);
|
||||
|
||||
/* skip the intervening fields */
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
p = nextfield(p);
|
||||
|
||||
/* return the login directory */
|
||||
(void) nextfield(p);
|
||||
return(p);
|
||||
}
|
||||
|
152
src/lookup.c
152
src/lookup.c
@ -30,20 +30,20 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* keyword look-up routine for the C symbol scanner
|
||||
* keyword look-up routine for the C symbol scanner
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "lookup.h"
|
||||
|
||||
/* keyword text for fast testing of keywords in the scanner */
|
||||
char enumtext[] = "enum";
|
||||
char externtext[] = "extern";
|
||||
char structtext[] = "struct";
|
||||
char typedeftext[] = "typedef";
|
||||
char uniontext[] = "union";
|
||||
char enumtext[] = "enum";
|
||||
char externtext[] = "extern";
|
||||
char structtext[] = "struct";
|
||||
char typedeftext[] = "typedef";
|
||||
char uniontext[] = "union";
|
||||
|
||||
/* This keyword table is also used for keyword text compression. Keywords
|
||||
* with an index less than the numeric value of a space are replaced with the
|
||||
@ -51,53 +51,53 @@ char uniontext[] = "union";
|
||||
* without changing the database file version and adding compatibility code
|
||||
* for old databases.
|
||||
*/
|
||||
struct keystruct keyword[] = {
|
||||
{"", '\0', NULL}, /* dummy entry */
|
||||
{"#define", ' ', NULL}, /* must be table entry 1 */
|
||||
{"#include", ' ', NULL}, /* must be table entry 2 */
|
||||
{"break", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"case", ' ', NULL},
|
||||
{"char", ' ', NULL},
|
||||
{"continue", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"default", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"double", ' ', NULL},
|
||||
{"\t", '\0', NULL}, /* must be the table entry 9 */
|
||||
{"\n", '\0', NULL}, /* must be the table entry 10 */
|
||||
{"else", ' ', NULL},
|
||||
{enumtext, ' ', NULL},
|
||||
{externtext, ' ', NULL},
|
||||
{"float", ' ', NULL},
|
||||
{"for", '(', NULL},
|
||||
{"goto", ' ', NULL},
|
||||
{"if", '(', NULL},
|
||||
{"int", ' ', NULL},
|
||||
{"long", ' ', NULL},
|
||||
{"register", ' ', NULL},
|
||||
{"return", '\0', NULL},
|
||||
{"short", ' ', NULL},
|
||||
{"sizeof", '\0', NULL},
|
||||
{"static", ' ', NULL},
|
||||
{structtext, ' ', NULL},
|
||||
{"switch", '(', NULL},
|
||||
{typedeftext, ' ', NULL},
|
||||
{uniontext, ' ', NULL},
|
||||
{"unsigned", ' ', NULL},
|
||||
{"void", ' ', NULL},
|
||||
{"while", '(', NULL},
|
||||
|
||||
/* these keywords are not compressed */
|
||||
{"do", '\0', NULL},
|
||||
{"auto", ' ', NULL},
|
||||
{"fortran", ' ', NULL},
|
||||
{"const", ' ', NULL},
|
||||
{"signed", ' ', NULL},
|
||||
{"volatile", ' ', NULL},
|
||||
struct keystruct keyword[] = {
|
||||
{"", '\0', NULL}, /* dummy entry */
|
||||
{"#define", ' ', NULL}, /* must be table entry 1 */
|
||||
{"#include", ' ', NULL}, /* must be table entry 2 */
|
||||
{"break", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"case", ' ', NULL},
|
||||
{"char", ' ', NULL},
|
||||
{"continue", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"default", '\0', NULL}, /* rarely in cross-reference */
|
||||
{"double", ' ', NULL},
|
||||
{"\t", '\0', NULL}, /* must be the table entry 9 */
|
||||
{"\n", '\0', NULL}, /* must be the table entry 10 */
|
||||
{"else", ' ', NULL},
|
||||
{enumtext, ' ', NULL},
|
||||
{externtext, ' ', NULL},
|
||||
{"float", ' ', NULL},
|
||||
{"for", '(', NULL},
|
||||
{"goto", ' ', NULL},
|
||||
{"if", '(', NULL},
|
||||
{"int", ' ', NULL},
|
||||
{"long", ' ', NULL},
|
||||
{"register", ' ', NULL},
|
||||
{"return", '\0', NULL},
|
||||
{"short", ' ', NULL},
|
||||
{"sizeof", '\0', NULL},
|
||||
{"static", ' ', NULL},
|
||||
{structtext, ' ', NULL},
|
||||
{"switch", '(', NULL},
|
||||
{typedeftext, ' ', NULL},
|
||||
{uniontext, ' ', NULL},
|
||||
{"unsigned", ' ', NULL},
|
||||
{"void", ' ', NULL},
|
||||
{"while", '(', NULL},
|
||||
|
||||
/* these keywords are not compressed */
|
||||
{"do", '\0', NULL},
|
||||
{"auto", ' ', NULL},
|
||||
{"fortran", ' ', NULL},
|
||||
{"const", ' ', NULL},
|
||||
{"signed", ' ', NULL},
|
||||
{"volatile", ' ', NULL},
|
||||
};
|
||||
#define KEYWORDS (sizeof(keyword) / sizeof(keyword[0]))
|
||||
#define KEYWORDS (sizeof(keyword) / sizeof(keyword[0]))
|
||||
|
||||
#define HASHMOD (KEYWORDS * 2 + 1)
|
||||
#define HASHMOD (KEYWORDS * 2 + 1)
|
||||
|
||||
static struct keystruct *hashtab[HASHMOD]; /* pointer table */
|
||||
static struct keystruct *hashtab[HASHMOD]; /* pointer table */
|
||||
|
||||
/* put the keywords into the symbol table */
|
||||
|
||||
@ -106,12 +106,12 @@ initsymtab(void)
|
||||
{
|
||||
unsigned int i, j;
|
||||
struct keystruct *p;
|
||||
|
||||
|
||||
for (i = 1; i < KEYWORDS; ++i) {
|
||||
p = keyword + i;
|
||||
j = hash(p->text) % HASHMOD;
|
||||
p->next = hashtab[j];
|
||||
hashtab[j] = p;
|
||||
p = keyword + i;
|
||||
j = hash(p->text) % HASHMOD;
|
||||
p->next = hashtab[j];
|
||||
hashtab[j] = p;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,30 +120,30 @@ initsymtab(void)
|
||||
char *
|
||||
lookup(char *ident)
|
||||
{
|
||||
struct keystruct *p;
|
||||
int c;
|
||||
|
||||
/* look up the identifier in the keyword table */
|
||||
for (p = hashtab[hash(ident) % HASHMOD]; p != NULL; p = p->next) {
|
||||
if (strequal(ident, p->text)) {
|
||||
if (compress == YES && (c = p - keyword) < ' ') {
|
||||
ident[0] = c; /* compress the keyword */
|
||||
}
|
||||
return(p->text);
|
||||
}
|
||||
}
|
||||
/* this is an identifier */
|
||||
return(NULL);
|
||||
struct keystruct *p;
|
||||
int c;
|
||||
|
||||
/* look up the identifier in the keyword table */
|
||||
for (p = hashtab[hash(ident) % HASHMOD]; p != NULL; p = p->next) {
|
||||
if (strequal(ident, p->text)) {
|
||||
if (compress == YES && (c = p - keyword) < ' ') {
|
||||
ident[0] = c; /* compress the keyword */
|
||||
}
|
||||
return(p->text);
|
||||
}
|
||||
}
|
||||
/* this is an identifier */
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* form hash value for string */
|
||||
int
|
||||
hash(char *ss)
|
||||
{
|
||||
int i;
|
||||
unsigned char *s = (unsigned char *)ss;
|
||||
|
||||
for (i = 0; *s != '\0'; )
|
||||
i += *s++; /* += is faster than <<= for cscope */
|
||||
return(i);
|
||||
int i;
|
||||
unsigned char *s = (unsigned char *)ss;
|
||||
|
||||
for (i = 0; *s != '\0'; )
|
||||
i += *s++; /* += is faster than <<= for cscope */
|
||||
return(i);
|
||||
}
|
||||
|
10
src/lookup.h
10
src/lookup.h
@ -36,10 +36,10 @@
|
||||
/* declarations for objects defined in lookup.c */
|
||||
|
||||
/* keyword text for fast testing of keywords in the scanner */
|
||||
extern char enumtext[];
|
||||
extern char externtext[];
|
||||
extern char structtext[];
|
||||
extern char typedeftext[];
|
||||
extern char uniontext[];
|
||||
extern char enumtext[];
|
||||
extern char externtext[];
|
||||
extern char structtext[];
|
||||
extern char typedeftext[];
|
||||
extern char uniontext[];
|
||||
|
||||
#endif /* CSCOPE_LOOKUP_H */
|
||||
|
866
src/main.c
866
src/main.c
File diff suppressed because it is too large
Load Diff
608
src/mouse.c
608
src/mouse.c
@ -30,120 +30,120 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* mouse functions
|
||||
* mouse functions
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
BOOL mouse = NO; /* mouse interface */
|
||||
BOOL mouse = NO; /* mouse interface */
|
||||
|
||||
#ifdef UNIXPC /* build command requires #ifdef instead of #if */
|
||||
#ifdef UNIXPC /* build command requires #ifdef instead of #if */
|
||||
#include <sys/window.h>
|
||||
BOOL unixpcmouse = NO; /* running with a mouse on the Unix PC? */
|
||||
static int uw_hs, uw_vs; /* character height and width */
|
||||
BOOL unixpcmouse = NO; /* running with a mouse on the Unix PC? */
|
||||
static int uw_hs, uw_vs; /* character height and width */
|
||||
#endif
|
||||
|
||||
typedef struct { /* menu */
|
||||
char *text;
|
||||
char *value;
|
||||
typedef struct { /* menu */
|
||||
char *text;
|
||||
char *value;
|
||||
} MENU;
|
||||
|
||||
static MENU mainmenu[] = { /* main menu */
|
||||
{"Send", "##\033s##\r"},
|
||||
{"Repeat", "\031"},
|
||||
{"Edit All", "\05"},
|
||||
{"Rebuild", "\022"},
|
||||
{"Shell", "!"},
|
||||
{"Redraw", "\f"},
|
||||
{"Help", "?"},
|
||||
{"Exit", "\04"},
|
||||
{NULL, NULL}
|
||||
static MENU mainmenu[] = { /* main menu */
|
||||
{"Send", "##\033s##\r"},
|
||||
{"Repeat", "\031"},
|
||||
{"Edit All", "\05"},
|
||||
{"Rebuild", "\022"},
|
||||
{"Shell", "!"},
|
||||
{"Redraw", "\f"},
|
||||
{"Help", "?"},
|
||||
{"Exit", "\04"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static MENU changemenu[] = { /* change mode menu */
|
||||
{"Mark Screen", "*"},
|
||||
{"Mark All", "a"},
|
||||
{"Change", "\04"},
|
||||
{"No Change", "\033"},
|
||||
{"Shell", "!"},
|
||||
{"Redraw", "\f"},
|
||||
{"Help", "?"},
|
||||
{NULL, NULL}
|
||||
static MENU changemenu[] = { /* change mode menu */
|
||||
{"Mark Screen", "*"},
|
||||
{"Mark All", "a"},
|
||||
{"Change", "\04"},
|
||||
{"No Change", "\033"},
|
||||
{"Shell", "!"},
|
||||
{"Redraw", "\f"},
|
||||
{"Help", "?"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static MENU *loaded; /* menu loaded */
|
||||
static BOOL emacsviterm = NO; /* terminal type */
|
||||
static MENU *loaded; /* menu loaded */
|
||||
static BOOL emacsviterm = NO; /* terminal type */
|
||||
|
||||
static void loadmenu(MENU *menu);
|
||||
static int getcoordinate(void);
|
||||
static int getpercent(void);
|
||||
static void loadmenu(MENU *menu);
|
||||
static int getcoordinate(void);
|
||||
static int getpercent(void);
|
||||
|
||||
/* see if there is a mouse interface */
|
||||
|
||||
void
|
||||
mouseinit(void)
|
||||
{
|
||||
char *term;
|
||||
char *term;
|
||||
|
||||
/* see if this is emacsterm or viterm */
|
||||
term = mygetenv("TERM", "");
|
||||
if (strcmp(term, "emacsterm") == 0 ||
|
||||
strcmp(term, "viterm") == 0) {
|
||||
emacsviterm = YES;
|
||||
mouse = YES;
|
||||
}
|
||||
/* the MOUSE enviroment variable is for 5620 terminal programs that have
|
||||
mouse support but the TERM environment variable is the same as a
|
||||
terminal without a mouse, such as myx */
|
||||
else if (strcmp(mygetenv("MOUSE", ""), "myx") == 0) {
|
||||
mouse = YES;
|
||||
}
|
||||
/* see if this is emacsterm or viterm */
|
||||
term = mygetenv("TERM", "");
|
||||
if (strcmp(term, "emacsterm") == 0 ||
|
||||
strcmp(term, "viterm") == 0) {
|
||||
emacsviterm = YES;
|
||||
mouse = YES;
|
||||
}
|
||||
/* the MOUSE enviroment variable is for 5620 terminal programs that have
|
||||
mouse support but the TERM environment variable is the same as a
|
||||
terminal without a mouse, such as myx */
|
||||
else if (strcmp(mygetenv("MOUSE", ""), "myx") == 0) {
|
||||
mouse = YES;
|
||||
}
|
||||
#if UNIXPC
|
||||
else if (strcmp(term,"s4") == 0 ||
|
||||
strcmp(term,"s120") == 0 ||
|
||||
strcmp(term,"s90") == 0) {
|
||||
int retval;
|
||||
struct uwdata uwd; /* Window data structure */
|
||||
struct umdata umd; /* Mouse data structure */
|
||||
else if (strcmp(term,"s4") == 0 ||
|
||||
strcmp(term,"s120") == 0 ||
|
||||
strcmp(term,"s90") == 0) {
|
||||
int retval;
|
||||
struct uwdata uwd; /* Window data structure */
|
||||
struct umdata umd; /* Mouse data structure */
|
||||
|
||||
/* Ask for character size info */
|
||||
|
||||
retval = ioctl(1,WIOCGETD,&uwd);
|
||||
if(retval || uwd.uw_hs <= 0 || uwd.uw_vs <= 0) {
|
||||
/**************************************************
|
||||
* something wrong with the kernel, so fake it...
|
||||
**************************************************/
|
||||
if(!strcmp(term,"s4")) {
|
||||
uw_hs = 9;
|
||||
uw_vs = 12;
|
||||
}
|
||||
else {
|
||||
uw_hs = 6;
|
||||
uw_vs = 10;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Kernel is working and knows about this font */
|
||||
uw_hs = uwd.uw_hs;
|
||||
uw_vs = uwd.uw_vs;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
* Now turn on mouse reporting so we can actually
|
||||
* make use of all this stuff.
|
||||
**************************************************/
|
||||
if((retval = ioctl(1,WIOCGETMOUSE,&umd)) != -1) {
|
||||
umd.um_flags= MSDOWN+MSUP;
|
||||
ioctl(1,WIOCSETMOUSE,&umd);
|
||||
}
|
||||
unixpcmouse = YES;
|
||||
}
|
||||
/* Ask for character size info */
|
||||
|
||||
retval = ioctl(1,WIOCGETD,&uwd);
|
||||
if(retval || uwd.uw_hs <= 0 || uwd.uw_vs <= 0) {
|
||||
/**************************************************
|
||||
* something wrong with the kernel, so fake it...
|
||||
**************************************************/
|
||||
if(!strcmp(term,"s4")) {
|
||||
uw_hs = 9;
|
||||
uw_vs = 12;
|
||||
}
|
||||
else {
|
||||
uw_hs = 6;
|
||||
uw_vs = 10;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Kernel is working and knows about this font */
|
||||
uw_hs = uwd.uw_hs;
|
||||
uw_vs = uwd.uw_vs;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
* Now turn on mouse reporting so we can actually
|
||||
* make use of all this stuff.
|
||||
**************************************************/
|
||||
if((retval = ioctl(1,WIOCGETMOUSE,&umd)) != -1) {
|
||||
umd.um_flags= MSDOWN+MSUP;
|
||||
ioctl(1,WIOCSETMOUSE,&umd);
|
||||
}
|
||||
unixpcmouse = YES;
|
||||
}
|
||||
#endif
|
||||
if (mouse == YES) {
|
||||
loadmenu(mainmenu);
|
||||
}
|
||||
if (mouse == YES) {
|
||||
loadmenu(mainmenu);
|
||||
}
|
||||
}
|
||||
|
||||
/* load the correct mouse menu */
|
||||
@ -151,14 +151,14 @@ mouseinit(void)
|
||||
void
|
||||
mousemenu(void)
|
||||
{
|
||||
if (mouse == YES) {
|
||||
if (changing == YES) {
|
||||
loadmenu(changemenu);
|
||||
}
|
||||
else {
|
||||
loadmenu(mainmenu);
|
||||
}
|
||||
}
|
||||
if (mouse == YES) {
|
||||
if (changing == YES) {
|
||||
loadmenu(changemenu);
|
||||
}
|
||||
else {
|
||||
loadmenu(mainmenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* download a menu */
|
||||
@ -166,30 +166,30 @@ mousemenu(void)
|
||||
static void
|
||||
loadmenu(MENU *menu)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (emacsviterm == YES) {
|
||||
mousereinit();
|
||||
(void) printf("\033V1"); /* display the scrollbar */
|
||||
(void) printf("\033M0@%s@%s@", menu[0].text, menu[0].value);
|
||||
for (i = 1; menu[i].text != NULL; ++i) {
|
||||
(void) printf("\033M@%s@%s@", menu[i].text, menu[i].value);
|
||||
}
|
||||
}
|
||||
else { /* myx */
|
||||
int len;
|
||||
|
||||
mousecleanup();
|
||||
(void) printf("\033[6;1X\033[9;1X");
|
||||
for (i = 0; menu[i].text != NULL; ++i) {
|
||||
len = strlen(menu[i].text);
|
||||
(void) printf("\033[%d;%dx%s%s", len,
|
||||
(int) (len + strlen(menu[i].value)),
|
||||
menu[i].text, menu[i].value);
|
||||
}
|
||||
loaded = menu;
|
||||
}
|
||||
(void) fflush(stdout);
|
||||
if (emacsviterm == YES) {
|
||||
mousereinit();
|
||||
(void) printf("\033V1"); /* display the scrollbar */
|
||||
(void) printf("\033M0@%s@%s@", menu[0].text, menu[0].value);
|
||||
for (i = 1; menu[i].text != NULL; ++i) {
|
||||
(void) printf("\033M@%s@%s@", menu[i].text, menu[i].value);
|
||||
}
|
||||
}
|
||||
else { /* myx */
|
||||
int len;
|
||||
|
||||
mousecleanup();
|
||||
(void) printf("\033[6;1X\033[9;1X");
|
||||
for (i = 0; menu[i].text != NULL; ++i) {
|
||||
len = strlen(menu[i].text);
|
||||
(void) printf("\033[%d;%dx%s%s", len,
|
||||
(int) (len + strlen(menu[i].value)),
|
||||
menu[i].text, menu[i].value);
|
||||
}
|
||||
loaded = menu;
|
||||
}
|
||||
(void) fflush(stdout);
|
||||
}
|
||||
|
||||
/* reinitialize the mouse in case curses changed the attributes */
|
||||
@ -197,13 +197,13 @@ loadmenu(MENU *menu)
|
||||
void
|
||||
mousereinit(void)
|
||||
{
|
||||
if (emacsviterm == YES) {
|
||||
if (emacsviterm == YES) {
|
||||
|
||||
/* enable the mouse click and sweep coordinate control sequence */
|
||||
/* and switch to menu 2 */
|
||||
(void) printf("\033{2\033#2");
|
||||
(void) fflush(stdout);
|
||||
}
|
||||
/* enable the mouse click and sweep coordinate control sequence */
|
||||
/* and switch to menu 2 */
|
||||
(void) printf("\033{2\033#2");
|
||||
(void) fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* restore the mouse attributes */
|
||||
@ -211,17 +211,17 @@ mousereinit(void)
|
||||
void
|
||||
mousecleanup(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (loaded != NULL) { /* only true for myx */
|
||||
|
||||
/* remove the mouse menu */
|
||||
(void) printf("\033[6;0X\033[9;0X");
|
||||
for (i = 0; loaded[i].text != NULL; ++i) {
|
||||
(void) printf("\033[0;0x");
|
||||
}
|
||||
loaded = NULL;
|
||||
}
|
||||
if (loaded != NULL) { /* only true for myx */
|
||||
|
||||
/* remove the mouse menu */
|
||||
(void) printf("\033[6;0X\033[9;0X");
|
||||
for (i = 0; loaded[i].text != NULL; ++i) {
|
||||
(void) printf("\033[0;0x");
|
||||
}
|
||||
loaded = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* draw the scrollbar */
|
||||
@ -229,31 +229,31 @@ mousecleanup(void)
|
||||
void
|
||||
drawscrollbar(int top, int bot)
|
||||
{
|
||||
int p1, p2;
|
||||
int p1, p2;
|
||||
|
||||
if (emacsviterm == YES) {
|
||||
if (bot > top) {
|
||||
p1 = 16 + (top - 1) * 100 / totallines;
|
||||
p2 = 16 + (bot - 1) * 100 / totallines;
|
||||
if (p2 > 116) {
|
||||
p2 = 116;
|
||||
}
|
||||
if (p1 < 16) {
|
||||
p1 = 16;
|
||||
}
|
||||
/* don't send ^S or ^Q because it will hang a layer using cu(1) */
|
||||
if (p1 == ctrl('Q') || p1 == ctrl('S')) {
|
||||
++p1;
|
||||
}
|
||||
if (p2 == ctrl('Q') || p2 == ctrl('S')) {
|
||||
++p2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
p1 = p2 = 16;
|
||||
}
|
||||
(void) printf("\033W%c%c", p1, p2);
|
||||
}
|
||||
if (emacsviterm == YES) {
|
||||
if (bot > top) {
|
||||
p1 = 16 + (top - 1) * 100 / totallines;
|
||||
p2 = 16 + (bot - 1) * 100 / totallines;
|
||||
if (p2 > 116) {
|
||||
p2 = 116;
|
||||
}
|
||||
if (p1 < 16) {
|
||||
p1 = 16;
|
||||
}
|
||||
/* don't send ^S or ^Q because it will hang a layer using cu(1) */
|
||||
if (p1 == ctrl('Q') || p1 == ctrl('S')) {
|
||||
++p1;
|
||||
}
|
||||
if (p2 == ctrl('Q') || p2 == ctrl('S')) {
|
||||
++p2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
p1 = p2 = 16;
|
||||
}
|
||||
(void) printf("\033W%c%c", p1, p2);
|
||||
}
|
||||
}
|
||||
|
||||
/* get the mouse information */
|
||||
@ -261,137 +261,137 @@ drawscrollbar(int top, int bot)
|
||||
MOUSE *
|
||||
getmouseaction(char leading_char)
|
||||
{
|
||||
static MOUSE m;
|
||||
static MOUSE m;
|
||||
|
||||
#if UNIXPC
|
||||
|
||||
if(unixpcmouse == YES && leading_char == ESC) {
|
||||
if(unixpcmouse == YES && leading_char == ESC) {
|
||||
|
||||
/* Called if cscope received an ESC character. See if it is
|
||||
* a mouse report and if so, decipher it. A mouse report
|
||||
* looks like: "<ESC>[?xx;yy;b;rM"
|
||||
*/
|
||||
int x = 0, y = 0, button = 0, reason = 0;
|
||||
int i;
|
||||
|
||||
/* Get a mouse report. The form is: XX;YY;B;RM where
|
||||
* XX is 1,2, or 3 decimal digits with the X pixel position.
|
||||
* Similarly for YY. B is a single decimal digit with the
|
||||
* button number (4 for one, 2 for two, and 1 for three).
|
||||
* R is the reason for the mouse report.
|
||||
*
|
||||
* In general, the input is read until the mouse report has
|
||||
* been completely read in or we have discovered that this
|
||||
* escape sequence is NOT a mouse report. In the latter case
|
||||
* return the last character read to the input stream with
|
||||
* myungetch().
|
||||
*/
|
||||
|
||||
/* Check for "[?" being next 2 chars */
|
||||
if(((i = mygetch()) != '[') || ((i = mygetch()) != '?')) {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Grab the X position (in pixels) */
|
||||
while(isdigit(i = mygetch())) {
|
||||
x = (x*10) + (i - '0');
|
||||
}
|
||||
if(i != ';') {
|
||||
myungetch(i);
|
||||
return(NULL); /* not a mouse report after all */
|
||||
}
|
||||
|
||||
/* Grab the Y position (in pixels) */
|
||||
while(isdigit(i = mygetch())) {
|
||||
y = (y*10) + (i - '0');
|
||||
}
|
||||
if(i != ';') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Get which button */
|
||||
if((button = mygetch()) > '4') {
|
||||
myungetch(button);
|
||||
return(NULL);
|
||||
}
|
||||
if((i = mygetch()) != ';') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Get the reason for this mouse report */
|
||||
if((reason = mygetch()) > '8') {
|
||||
myungetch(reason);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* sequence should terminate with an 'M' */
|
||||
if((i = mygetch()) != 'M') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
/* OK. We get a mouse report whenever a button is depressed
|
||||
* or released. Let's ignore the report whenever the button
|
||||
* is depressed until when I am ready to implement sweeping.
|
||||
*/
|
||||
if(reason != '2') {
|
||||
return(NULL); /* '2' means button is released */
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Always indicate button 1 irregardless of which button was
|
||||
* really pushed.
|
||||
************************************************************/
|
||||
m.button = 1;
|
||||
|
||||
/************************************************************
|
||||
* Convert pixel coordinates to line and column coords.
|
||||
* The height and width are obtained using an ioctl() call
|
||||
* in mouseinit(). This assumes that variable width chars
|
||||
* are not being used ('though it would probably work anyway).
|
||||
************************************************************/
|
||||
|
||||
m.x1 = x/uw_hs; /* pixel/horizontal_spacing */
|
||||
m.y1 = y/uw_vs; /* pixel/vertical_spacing */
|
||||
|
||||
/* "null" out the other fields */
|
||||
m.percent = m.x2 = m.y2 = -1;
|
||||
}
|
||||
else
|
||||
#endif /* not UNIXPC */
|
||||
/* Called if cscope received an ESC character. See if it is
|
||||
* a mouse report and if so, decipher it. A mouse report
|
||||
* looks like: "<ESC>[?xx;yy;b;rM"
|
||||
*/
|
||||
int x = 0, y = 0, button = 0, reason = 0;
|
||||
int i;
|
||||
|
||||
/* Get a mouse report. The form is: XX;YY;B;RM where
|
||||
* XX is 1,2, or 3 decimal digits with the X pixel position.
|
||||
* Similarly for YY. B is a single decimal digit with the
|
||||
* button number (4 for one, 2 for two, and 1 for three).
|
||||
* R is the reason for the mouse report.
|
||||
*
|
||||
* In general, the input is read until the mouse report has
|
||||
* been completely read in or we have discovered that this
|
||||
* escape sequence is NOT a mouse report. In the latter case
|
||||
* return the last character read to the input stream with
|
||||
* myungetch().
|
||||
*/
|
||||
|
||||
/* Check for "[?" being next 2 chars */
|
||||
if(((i = mygetch()) != '[') || ((i = mygetch()) != '?')) {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Grab the X position (in pixels) */
|
||||
while(isdigit(i = mygetch())) {
|
||||
x = (x*10) + (i - '0');
|
||||
}
|
||||
if(i != ';') {
|
||||
myungetch(i);
|
||||
return(NULL); /* not a mouse report after all */
|
||||
}
|
||||
|
||||
/* Grab the Y position (in pixels) */
|
||||
while(isdigit(i = mygetch())) {
|
||||
y = (y*10) + (i - '0');
|
||||
}
|
||||
if(i != ';') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Get which button */
|
||||
if((button = mygetch()) > '4') {
|
||||
myungetch(button);
|
||||
return(NULL);
|
||||
}
|
||||
if((i = mygetch()) != ';') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Get the reason for this mouse report */
|
||||
if((reason = mygetch()) > '8') {
|
||||
myungetch(reason);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* sequence should terminate with an 'M' */
|
||||
if((i = mygetch()) != 'M') {
|
||||
myungetch(i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
/* OK. We get a mouse report whenever a button is depressed
|
||||
* or released. Let's ignore the report whenever the button
|
||||
* is depressed until when I am ready to implement sweeping.
|
||||
*/
|
||||
if(reason != '2') {
|
||||
return(NULL); /* '2' means button is released */
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Always indicate button 1 irregardless of which button was
|
||||
* really pushed.
|
||||
************************************************************/
|
||||
m.button = 1;
|
||||
|
||||
/************************************************************
|
||||
* Convert pixel coordinates to line and column coords.
|
||||
* The height and width are obtained using an ioctl() call
|
||||
* in mouseinit(). This assumes that variable width chars
|
||||
* are not being used ('though it would probably work anyway).
|
||||
************************************************************/
|
||||
|
||||
m.x1 = x/uw_hs; /* pixel/horizontal_spacing */
|
||||
m.y1 = y/uw_vs; /* pixel/vertical_spacing */
|
||||
|
||||
/* "null" out the other fields */
|
||||
m.percent = m.x2 = m.y2 = -1;
|
||||
}
|
||||
else
|
||||
#endif /* not UNIXPC */
|
||||
|
||||
if (mouse == YES && leading_char == ctrl('X')) {
|
||||
|
||||
switch (mygetch()) {
|
||||
case ctrl('_'): /* click */
|
||||
if ((m.button = mygetch()) == '0') { /* if scrollbar */
|
||||
m.percent = getpercent();
|
||||
}
|
||||
else {
|
||||
m.x1 = getcoordinate();
|
||||
m.y1 = getcoordinate();
|
||||
m.x2 = m.y2 = -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case ctrl(']'): /* sweep */
|
||||
m.button = mygetch();
|
||||
m.x1 = getcoordinate();
|
||||
m.y1 = getcoordinate();
|
||||
m.x2 = getcoordinate();
|
||||
m.y2 = getcoordinate();
|
||||
break;
|
||||
default:
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
else return(NULL);
|
||||
if (mouse == YES && leading_char == ctrl('X')) {
|
||||
|
||||
switch (mygetch()) {
|
||||
case ctrl('_'): /* click */
|
||||
if ((m.button = mygetch()) == '0') { /* if scrollbar */
|
||||
m.percent = getpercent();
|
||||
}
|
||||
else {
|
||||
m.x1 = getcoordinate();
|
||||
m.y1 = getcoordinate();
|
||||
m.x2 = m.y2 = -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case ctrl(']'): /* sweep */
|
||||
m.button = mygetch();
|
||||
m.x1 = getcoordinate();
|
||||
m.y1 = getcoordinate();
|
||||
m.x2 = getcoordinate();
|
||||
m.y2 = getcoordinate();
|
||||
break;
|
||||
default:
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
else return(NULL);
|
||||
|
||||
return(&m);
|
||||
return(&m);
|
||||
}
|
||||
|
||||
/* get a row or column coordinate from a mouse button click or sweep */
|
||||
@ -399,18 +399,18 @@ getmouseaction(char leading_char)
|
||||
static int
|
||||
getcoordinate(void)
|
||||
{
|
||||
int c, next;
|
||||
int c, next;
|
||||
|
||||
c = mygetch();
|
||||
next = 0;
|
||||
if (c == ctrl('A')) {
|
||||
next = 95;
|
||||
c = mygetch();
|
||||
}
|
||||
if (c < ' ') {
|
||||
return (0);
|
||||
}
|
||||
return (next + c - ' ');
|
||||
c = mygetch();
|
||||
next = 0;
|
||||
if (c == ctrl('A')) {
|
||||
next = 95;
|
||||
c = mygetch();
|
||||
}
|
||||
if (c < ' ') {
|
||||
return (0);
|
||||
}
|
||||
return (next + c - ' ');
|
||||
}
|
||||
|
||||
/* get a percentage */
|
||||
@ -418,14 +418,14 @@ getcoordinate(void)
|
||||
static int
|
||||
getpercent(void)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
c = mygetch();
|
||||
if (c < 16) {
|
||||
return(0);
|
||||
}
|
||||
if (c > 120) {
|
||||
return(100);
|
||||
}
|
||||
return(c - 16);
|
||||
c = mygetch();
|
||||
if (c < 16) {
|
||||
return(0);
|
||||
}
|
||||
if (c > 120) {
|
||||
return(100);
|
||||
}
|
||||
return(c - 16);
|
||||
}
|
||||
|
@ -36,14 +36,14 @@
|
||||
|
||||
/* return the non-null environment value or the default argument */
|
||||
|
||||
char *
|
||||
char *
|
||||
mygetenv(char *variable, char *deflt)
|
||||
{
|
||||
char *value;
|
||||
char *value;
|
||||
|
||||
value = getenv(variable);
|
||||
if (value == NULL || *value == '\0') {
|
||||
return(deflt);
|
||||
}
|
||||
return(value);
|
||||
value = getenv(variable);
|
||||
if (value == NULL || *value == '\0') {
|
||||
return(deflt);
|
||||
}
|
||||
return(value);
|
||||
}
|
||||
|
174
src/mypopen.c
174
src/mypopen.c
@ -35,11 +35,11 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include "global.h" /* pid_t, shell, and basename() */
|
||||
#include "global.h" /* pid_t, shell, and basename() */
|
||||
|
||||
#define tst(a,b) (*mode == 'r'? (b) : (a))
|
||||
#define RDR 0
|
||||
#define WTR 1
|
||||
#define tst(a,b) (*mode == 'r'? (b) : (a))
|
||||
#define RDR 0
|
||||
#define WTR 1
|
||||
|
||||
/* HBB 20010312: make this a bit safer --- don't blindly assume it's 1 */
|
||||
#ifdef FD_CLOEXEC
|
||||
@ -49,7 +49,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
# include <io.h> /* for setmode() */
|
||||
# include <io.h> /* for setmode() */
|
||||
#endif
|
||||
|
||||
static pid_t popen_pid[20];
|
||||
@ -66,34 +66,34 @@ myopen(char *path, int flag, int mode)
|
||||
* mode for files in "binary mounted" paths */
|
||||
#if O_BINARY != O_TEXT
|
||||
if (! (flag | O_BINARY))
|
||||
flag |= O_TEXT;
|
||||
flag |= O_TEXT;
|
||||
#endif
|
||||
if(mode)
|
||||
fd = open(path, flag, mode);
|
||||
fd = open(path, flag, mode);
|
||||
else
|
||||
fd = open(path, flag);
|
||||
fd = open(path, flag);
|
||||
|
||||
#ifdef __DJGPP__ /* FIXME: test feature, not platform */
|
||||
#ifdef __DJGPP__ /* FIXME: test feature, not platform */
|
||||
/* HBB 20010312: DOS GCC doesn't have FD_CLOEXEC (yet), so it
|
||||
* always fails this call. Have to skip that step */
|
||||
if(fd != -1)
|
||||
return(fd);
|
||||
return(fd);
|
||||
#endif
|
||||
if(fd != -1 && (fcntl(fd, F_SETFD, CLOSE_ON_EXEC) != -1))
|
||||
return(fd);
|
||||
return(fd);
|
||||
|
||||
else
|
||||
{
|
||||
/* Ensure that if the fcntl fails and fd is valid, then
|
||||
the file is closed properly. In general this should
|
||||
not happen. */
|
||||
if (fd != -1)
|
||||
{
|
||||
close (fd);
|
||||
}
|
||||
{
|
||||
/* Ensure that if the fcntl fails and fd is valid, then
|
||||
the file is closed properly. In general this should
|
||||
not happen. */
|
||||
if (fd != -1)
|
||||
{
|
||||
close (fd);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
FILE *
|
||||
@ -106,70 +106,70 @@ myfopen(char *path, char *mode)
|
||||
|
||||
#ifdef SETMODE
|
||||
if (fp && ! strchr(mode, 'b')) {
|
||||
SETMODE(fileno(fp), O_TEXT);
|
||||
SETMODE(fileno(fp), O_TEXT);
|
||||
}
|
||||
#endif /* SETMODE */
|
||||
|
||||
|
||||
#ifdef __DJGPP__ /* FIXME: test feature, not platform */
|
||||
/* HBB 20010312: DOS GCC doesn't have FD_CLOEXEC (yet), so it
|
||||
* always fails this call. Have to skip that step */
|
||||
if(fp)
|
||||
#else
|
||||
if(fp && (fcntl(fileno(fp), F_SETFD, CLOSE_ON_EXEC) != -1))
|
||||
if(fp && (fcntl(fileno(fp), F_SETFD, CLOSE_ON_EXEC) != -1))
|
||||
#endif
|
||||
return(fp);
|
||||
return(fp);
|
||||
|
||||
else {
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
return(NULL);
|
||||
}
|
||||
else {
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
FILE *
|
||||
mypopen(char *cmd, char *mode)
|
||||
{
|
||||
#ifdef __DJGPP__
|
||||
/* HBB 20010312: Has its own implementation of popen(), which
|
||||
* is better suited to the platform than cscope's */
|
||||
return (popen)(cmd, mode);
|
||||
/* HBB 20010312: Has its own implementation of popen(), which
|
||||
* is better suited to the platform than cscope's */
|
||||
return (popen)(cmd, mode);
|
||||
#else
|
||||
int p[2];
|
||||
pid_t *poptr;
|
||||
int myside, yourside;
|
||||
pid_t pid;
|
||||
int p[2];
|
||||
pid_t *poptr;
|
||||
int myside, yourside;
|
||||
pid_t pid;
|
||||
|
||||
if(pipe(p) < 0)
|
||||
return(NULL);
|
||||
myside = tst(p[WTR], p[RDR]);
|
||||
yourside = tst(p[RDR], p[WTR]);
|
||||
if((pid = fork()) == 0) {
|
||||
/* myside and yourside reverse roles in child */
|
||||
int stdio;
|
||||
if(pipe(p) < 0)
|
||||
return(NULL);
|
||||
myside = tst(p[WTR], p[RDR]);
|
||||
yourside = tst(p[RDR], p[WTR]);
|
||||
if((pid = fork()) == 0) {
|
||||
/* myside and yourside reverse roles in child */
|
||||
int stdio;
|
||||
|
||||
/* close all pipes from other popen's */
|
||||
for (poptr = popen_pid; poptr < popen_pid+20; poptr++) {
|
||||
if(*poptr)
|
||||
(void) close(poptr - popen_pid);
|
||||
}
|
||||
stdio = tst(0, 1);
|
||||
close(myside);
|
||||
close(stdio);
|
||||
/* close all pipes from other popen's */
|
||||
for (poptr = popen_pid; poptr < popen_pid+20; poptr++) {
|
||||
if(*poptr)
|
||||
(void) close(poptr - popen_pid);
|
||||
}
|
||||
stdio = tst(0, 1);
|
||||
close(myside);
|
||||
close(stdio);
|
||||
#if V9
|
||||
dup2(yourside, stdio);
|
||||
dup2(yourside, stdio);
|
||||
#else
|
||||
fcntl(yourside, F_DUPFD, stdio);
|
||||
fcntl(yourside, F_DUPFD, stdio);
|
||||
#endif
|
||||
close(yourside);
|
||||
execlp(shell, basename(shell), "-c", cmd, (void *)0);
|
||||
_exit(1);
|
||||
} else if (pid > 0)
|
||||
tstat = signal(SIGTSTP, SIG_DFL);
|
||||
if(pid == -1)
|
||||
return(NULL);
|
||||
popen_pid[myside] = pid;
|
||||
(void) close(yourside);
|
||||
return(fdopen(myside, mode));
|
||||
close(yourside);
|
||||
execlp(shell, basename(shell), "-c", cmd, (void *)0);
|
||||
_exit(1);
|
||||
} else if (pid > 0)
|
||||
tstat = signal(SIGTSTP, SIG_DFL);
|
||||
if(pid == -1)
|
||||
return(NULL);
|
||||
popen_pid[myside] = pid;
|
||||
(void) close(yourside);
|
||||
return(fdopen(myside, mode));
|
||||
#endif /* DJGPP */
|
||||
}
|
||||
|
||||
@ -179,30 +179,30 @@ int
|
||||
mypclose(FILE *ptr)
|
||||
{
|
||||
#ifdef __DJGPP__
|
||||
/* HBB 20010705: This system has its own pclose(), which we
|
||||
* don't want to replace */
|
||||
return (pclose)(ptr);
|
||||
/* HBB 20010705: This system has its own pclose(), which we
|
||||
* don't want to replace */
|
||||
return (pclose)(ptr);
|
||||
#else
|
||||
int f;
|
||||
pid_t r;
|
||||
int status = -1;
|
||||
sighandler_t hstat, istat, qstat;
|
||||
int f;
|
||||
pid_t r;
|
||||
int status = -1;
|
||||
sighandler_t hstat, istat, qstat;
|
||||
|
||||
f = fileno(ptr);
|
||||
(void) fclose(ptr);
|
||||
istat = signal(SIGINT, SIG_IGN);
|
||||
qstat = signal(SIGQUIT, SIG_IGN);
|
||||
hstat = signal(SIGHUP, SIG_IGN);
|
||||
while((r = wait(&status)) != popen_pid[f] && r != -1)
|
||||
; /* nothing */
|
||||
if(r == -1)
|
||||
status = -1;
|
||||
(void) signal(SIGINT, istat);
|
||||
(void) signal(SIGQUIT, qstat);
|
||||
(void) signal(SIGHUP, hstat);
|
||||
(void) signal(SIGTSTP, tstat);
|
||||
/* mark this pipe closed */
|
||||
popen_pid[f] = 0;
|
||||
return(status);
|
||||
f = fileno(ptr);
|
||||
(void) fclose(ptr);
|
||||
istat = signal(SIGINT, SIG_IGN);
|
||||
qstat = signal(SIGQUIT, SIG_IGN);
|
||||
hstat = signal(SIGHUP, SIG_IGN);
|
||||
while((r = wait(&status)) != popen_pid[f] && r != -1)
|
||||
; /* nothing */
|
||||
if(r == -1)
|
||||
status = -1;
|
||||
(void) signal(SIGINT, istat);
|
||||
(void) signal(SIGQUIT, qstat);
|
||||
(void) signal(SIGHUP, hstat);
|
||||
(void) signal(SIGTSTP, tstat);
|
||||
/* mark this pipe closed */
|
||||
popen_pid[f] = 0;
|
||||
return(status);
|
||||
#endif /* DJGPP */
|
||||
}
|
||||
|
282
src/opt.c
282
src/opt.c
@ -2,158 +2,158 @@
|
||||
|
||||
#include "build.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>
|
||||
|
||||
BOOL remove_symfile_onexit = NO;
|
||||
BOOL onesearch; /* one search only in line mode */
|
||||
char *reflines; /* symbol reference lines file */
|
||||
BOOL onesearch; /* one search only in line mode */
|
||||
char *reflines; /* symbol reference lines file */
|
||||
|
||||
char ** parse_options(int *argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
int longind;
|
||||
char path[PATHLEN + 1]; /* file path */
|
||||
char *s;
|
||||
int argcc = *argc;
|
||||
int opt;
|
||||
int longind;
|
||||
char path[PATHLEN + 1]; /* file path */
|
||||
char *s;
|
||||
int argcc = *argc;
|
||||
|
||||
struct option lopts[] = {
|
||||
{"help", 0, NULL, 'h'},
|
||||
{"version", 0, NULL, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
struct option lopts[] = {
|
||||
{"help", 0, NULL, 'h'},
|
||||
{"version", 0, NULL, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argcc, argv,
|
||||
"hVbcCdeF:f:I:i:kLl0:1:2:3:4:5:6:7:8:9:P:p:qRs:TUuvX",
|
||||
lopts, &longind)) != -1) {
|
||||
switch(opt) {
|
||||
while ((opt = getopt_long(argcc, argv,
|
||||
"hVbcCdeF:f:I:i:kLl0:1:2:3:4:5:6:7:8:9:P:p:qRs:TUuvX",
|
||||
lopts, &longind)) != -1) {
|
||||
switch(opt) {
|
||||
|
||||
case '?':
|
||||
usage();
|
||||
myexit(1);
|
||||
break;
|
||||
case 'X':
|
||||
remove_symfile_onexit = YES;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
/* The input fields numbers for line mode operation */
|
||||
field = opt - '0';
|
||||
if (strlen(optarg) > PATHLEN) {
|
||||
postfatal("\
|
||||
cscope: pattern too long, cannot be > \
|
||||
%d characters\n", PATLEN);
|
||||
}
|
||||
strcpy(input_line, optarg);
|
||||
break;
|
||||
case 'b': /* only build the cross-reference */
|
||||
buildonly = YES;
|
||||
linemode = YES;
|
||||
break;
|
||||
case 'c': /* ASCII characters only in crossref */
|
||||
compress = NO;
|
||||
break;
|
||||
case 'C': /* turn on caseless mode for symbol searches */
|
||||
caseless = YES;
|
||||
egrepcaseless(caseless); /* simulate egrep -i flag */
|
||||
break;
|
||||
case 'd': /* consider crossref up-to-date */
|
||||
isuptodate = YES;
|
||||
break;
|
||||
case 'e': /* suppress ^E prompt between files */
|
||||
editallprompt = NO;
|
||||
break;
|
||||
case 'h':
|
||||
longusage();
|
||||
myexit(1);
|
||||
break;
|
||||
case 'k': /* ignore DFLT_INCDIR */
|
||||
kernelmode = YES;
|
||||
break;
|
||||
case 'L':
|
||||
onesearch = YES;
|
||||
/* FALLTHROUGH */
|
||||
case 'l':
|
||||
linemode = YES;
|
||||
break;
|
||||
case 'v':
|
||||
verbosemode = YES;
|
||||
break;
|
||||
case 'V':
|
||||
fprintf(stderr, "%s: version %d%s\n", argv0,
|
||||
FILEVERSION, FIXVERSION);
|
||||
myexit(0);
|
||||
break;
|
||||
case 'q': /* quick search */
|
||||
invertedindex = YES;
|
||||
break;
|
||||
case 'T': /* truncate symbols to 8 characters */
|
||||
trun_syms = YES;
|
||||
break;
|
||||
case 'u': /* unconditionally build the cross-reference */
|
||||
unconditional = YES;
|
||||
break;
|
||||
case 'U': /* assume some files have changed */
|
||||
fileschanged = YES;
|
||||
break;
|
||||
case 'R':
|
||||
recurse_dir = YES;
|
||||
break;
|
||||
case 'f': /* alternate cross-reference file */
|
||||
reffile = optarg;
|
||||
if (strlen(reffile) > sizeof(path) - 3) {
|
||||
postfatal("\
|
||||
cscope: reffile too long, cannot \
|
||||
be > %d characters\n", sizeof(path) - 3);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
strcpy(path, reffile);
|
||||
case '?':
|
||||
usage();
|
||||
myexit(1);
|
||||
break;
|
||||
case 'X':
|
||||
remove_symfile_onexit = YES;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
/* The input fields numbers for line mode operation */
|
||||
field = opt - '0';
|
||||
if (strlen(optarg) > PATHLEN) {
|
||||
postfatal("\
|
||||
cscope: pattern too long, cannot be > \
|
||||
%d characters\n", PATLEN);
|
||||
}
|
||||
strcpy(input_line, optarg);
|
||||
break;
|
||||
case 'b': /* only build the cross-reference */
|
||||
buildonly = YES;
|
||||
linemode = YES;
|
||||
break;
|
||||
case 'c': /* ASCII characters only in crossref */
|
||||
compress = NO;
|
||||
break;
|
||||
case 'C': /* turn on caseless mode for symbol searches */
|
||||
caseless = YES;
|
||||
egrepcaseless(caseless); /* simulate egrep -i flag */
|
||||
break;
|
||||
case 'd': /* consider crossref up-to-date */
|
||||
isuptodate = YES;
|
||||
break;
|
||||
case 'e': /* suppress ^E prompt between files */
|
||||
editallprompt = NO;
|
||||
break;
|
||||
case 'h':
|
||||
longusage();
|
||||
myexit(1);
|
||||
break;
|
||||
case 'k': /* ignore DFLT_INCDIR */
|
||||
kernelmode = YES;
|
||||
break;
|
||||
case 'L':
|
||||
onesearch = YES;
|
||||
/* FALLTHROUGH */
|
||||
case 'l':
|
||||
linemode = YES;
|
||||
break;
|
||||
case 'v':
|
||||
verbosemode = YES;
|
||||
break;
|
||||
case 'V':
|
||||
fprintf(stderr, "%s: version %d%s\n", argv0,
|
||||
FILEVERSION, FIXVERSION);
|
||||
myexit(0);
|
||||
break;
|
||||
case 'q': /* quick search */
|
||||
invertedindex = YES;
|
||||
break;
|
||||
case 'T': /* truncate symbols to 8 characters */
|
||||
trun_syms = YES;
|
||||
break;
|
||||
case 'u': /* unconditionally build the cross-reference */
|
||||
unconditional = YES;
|
||||
break;
|
||||
case 'U': /* assume some files have changed */
|
||||
fileschanged = YES;
|
||||
break;
|
||||
case 'R':
|
||||
recurse_dir = YES;
|
||||
break;
|
||||
case 'f': /* alternate cross-reference file */
|
||||
reffile = optarg;
|
||||
if (strlen(reffile) > sizeof(path) - 3) {
|
||||
postfatal("\
|
||||
cscope: reffile too long, cannot \
|
||||
be > %d characters\n", sizeof(path) - 3);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
strcpy(path, reffile);
|
||||
|
||||
s = path + strlen(path);
|
||||
strcpy(s, ".in");
|
||||
/*coverity[overwrite_var]*/
|
||||
invname = strdup(path);
|
||||
strcpy(s, ".po");
|
||||
/*coverity[overwrite_var]*/
|
||||
invpost = strdup(path);
|
||||
break;
|
||||
s = path + strlen(path);
|
||||
strcpy(s, ".in");
|
||||
/*coverity[overwrite_var]*/
|
||||
invname = strdup(path);
|
||||
strcpy(s, ".po");
|
||||
/*coverity[overwrite_var]*/
|
||||
invpost = strdup(path);
|
||||
break;
|
||||
|
||||
case 'F': /* symbol reference lines file */
|
||||
reflines = optarg;
|
||||
break;
|
||||
case 'i': /* file containing file names */
|
||||
namefile = optarg;
|
||||
break;
|
||||
case 'I': /* #include file directory */
|
||||
includedir(optarg);
|
||||
break;
|
||||
case 'p': /* file path components to display */
|
||||
dispcomponents = atoi(optarg);
|
||||
break;
|
||||
case 'P': /* prepend path to file names */
|
||||
prependpath = optarg;
|
||||
break;
|
||||
case 's': /* additional source file directory */
|
||||
sourcedir(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This adjusts argv so that we only see the remaining
|
||||
* args. Its ugly, but we need to do it so that the rest
|
||||
* of the main routine doesn't get all confused
|
||||
*/
|
||||
*argc = *argc - optind;
|
||||
return argv + optind;
|
||||
case 'F': /* symbol reference lines file */
|
||||
reflines = optarg;
|
||||
break;
|
||||
case 'i': /* file containing file names */
|
||||
namefile = optarg;
|
||||
break;
|
||||
case 'I': /* #include file directory */
|
||||
includedir(optarg);
|
||||
break;
|
||||
case 'p': /* file path components to display */
|
||||
dispcomponents = atoi(optarg);
|
||||
break;
|
||||
case 'P': /* prepend path to file names */
|
||||
prependpath = optarg;
|
||||
break;
|
||||
case 's': /* additional source file directory */
|
||||
sourcedir(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This adjusts argv so that we only see the remaining
|
||||
* args. Its ugly, but we need to do it so that the rest
|
||||
* of the main routine doesn't get all confused
|
||||
*/
|
||||
*argc = *argc - optind;
|
||||
return argv + optind;
|
||||
}
|
||||
|
188
src/readline.c
188
src/readline.c
@ -3,7 +3,7 @@
|
||||
#include "global.h"
|
||||
#include "build.h"
|
||||
|
||||
extern int LINES; // XXX
|
||||
extern int LINES; // XXX
|
||||
|
||||
static int input_available = 0;
|
||||
static char input_char;
|
||||
@ -12,139 +12,139 @@ char input_line[PATLEN + 1];
|
||||
BOOL do_terminate = NO;
|
||||
|
||||
BOOL interpret(int c){
|
||||
input_char = c;
|
||||
input_available = 1;
|
||||
rl_callback_read_char();
|
||||
input_char = c;
|
||||
input_available = 1;
|
||||
rl_callback_read_char();
|
||||
|
||||
return do_terminate;
|
||||
return do_terminate;
|
||||
}
|
||||
|
||||
static int getc_function(FILE* ignore){
|
||||
input_available = 0;
|
||||
return (int)input_char;
|
||||
input_available = 0;
|
||||
return (int)input_char;
|
||||
}
|
||||
|
||||
static int input_available_hook(){
|
||||
return input_available;
|
||||
return input_available;
|
||||
}
|
||||
|
||||
static void redisplay_function(){
|
||||
window_change |= CH_INPUT;
|
||||
window_change |= CH_INPUT;
|
||||
}
|
||||
|
||||
static void callback_handler(char* line){
|
||||
strncpy(input_line, line, PATLEN);
|
||||
search();
|
||||
strncpy(input_line, line, PATLEN);
|
||||
search();
|
||||
}
|
||||
|
||||
static int horswp_field_proxy(int i, int h){
|
||||
horswp_field();
|
||||
horswp_field();
|
||||
}
|
||||
|
||||
static int verswp_field_proxy(int i, int h){
|
||||
verswp_field();
|
||||
verswp_field();
|
||||
}
|
||||
|
||||
static int interpret_break(){
|
||||
do_terminate = YES;
|
||||
do_terminate = YES;
|
||||
}
|
||||
|
||||
static int ctrl_z(){
|
||||
kill(0, SIGTSTP);
|
||||
kill(0, SIGTSTP);
|
||||
}
|
||||
|
||||
static int toggle_caseless(){
|
||||
if (caseless == NO) {
|
||||
caseless = YES;
|
||||
postmsg2("Caseless mode is now ON");
|
||||
} else {
|
||||
caseless = NO;
|
||||
postmsg2("Caseless mode is now OFF");
|
||||
}
|
||||
egrepcaseless(caseless); /* turn on/off -i flag */
|
||||
if (caseless == NO) {
|
||||
caseless = YES;
|
||||
postmsg2("Caseless mode is now ON");
|
||||
} else {
|
||||
caseless = NO;
|
||||
postmsg2("Caseless mode is now OFF");
|
||||
}
|
||||
egrepcaseless(caseless); /* turn on/off -i flag */
|
||||
}
|
||||
|
||||
static int rebuild_reference(){
|
||||
if (isuptodate == YES) {
|
||||
postmsg("The -d option prevents rebuilding the symbol database");
|
||||
return(NO);
|
||||
}
|
||||
exitcurses();
|
||||
freefilelist(); /* remake the source file list */
|
||||
makefilelist();
|
||||
rebuild();
|
||||
if (errorsfound == YES) {
|
||||
errorsfound = NO;
|
||||
askforreturn();
|
||||
}
|
||||
entercurses();
|
||||
clearmsg(); /* clear any previous message */
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
topline = nextline = 1;
|
||||
return(YES);
|
||||
if (isuptodate == YES) {
|
||||
postmsg("The -d option prevents rebuilding the symbol database");
|
||||
return(NO);
|
||||
}
|
||||
exitcurses();
|
||||
freefilelist(); /* remake the source file list */
|
||||
makefilelist();
|
||||
rebuild();
|
||||
if (errorsfound == YES) {
|
||||
errorsfound = NO;
|
||||
askforreturn();
|
||||
}
|
||||
entercurses();
|
||||
clearmsg(); /* clear any previous message */
|
||||
totallines = 0;
|
||||
disprefs = 0;
|
||||
topline = nextline = 1;
|
||||
return(YES);
|
||||
}
|
||||
|
||||
static int process_mouse(){
|
||||
int i;
|
||||
MOUSE* p;
|
||||
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
|
||||
return(NO); /* unknown control sequence */
|
||||
}
|
||||
/* if the button number is a scrollbar tag */
|
||||
if (p->button == '0') {
|
||||
//scrollbar(p); // XXX
|
||||
return(NO);
|
||||
}
|
||||
/* ignore a sweep */
|
||||
if (p->x2 >= 0) {
|
||||
return(NO);
|
||||
}
|
||||
/* if this is a line selection */
|
||||
if (p->y1 > FLDLINE) {
|
||||
int i;
|
||||
MOUSE* p;
|
||||
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
|
||||
return(NO); /* unknown control sequence */
|
||||
}
|
||||
/* if the button number is a scrollbar tag */
|
||||
if (p->button == '0') {
|
||||
//scrollbar(p); // XXX
|
||||
return(NO);
|
||||
}
|
||||
/* ignore a sweep */
|
||||
if (p->x2 >= 0) {
|
||||
return(NO);
|
||||
}
|
||||
/* if this is a line selection */
|
||||
if (p->y1 > FLDLINE) {
|
||||
|
||||
/* find the selected line */
|
||||
/* note: the selection is forced into range */
|
||||
for (i = disprefs - 1; i > 0; --i) {
|
||||
if (p->y1 >= displine[i]) {
|
||||
return(NO);
|
||||
}
|
||||
}
|
||||
/* display it in the file with the editor */
|
||||
editref(i);
|
||||
} else { /* this is an input field selection */
|
||||
field = p->y1 - FLDLINE;
|
||||
/* force it into range */
|
||||
if (field >= FIELDS) {
|
||||
field = FIELDS - 1;
|
||||
}
|
||||
resetcmd();
|
||||
return(NO);
|
||||
}
|
||||
/* find the selected line */
|
||||
/* note: the selection is forced into range */
|
||||
for (i = disprefs - 1; i > 0; --i) {
|
||||
if (p->y1 >= displine[i]) {
|
||||
return(NO);
|
||||
}
|
||||
}
|
||||
/* display it in the file with the editor */
|
||||
editref(i);
|
||||
} else { /* this is an input field selection */
|
||||
field = p->y1 - FLDLINE;
|
||||
/* force it into range */
|
||||
if (field >= FIELDS) {
|
||||
field = FIELDS - 1;
|
||||
}
|
||||
resetcmd();
|
||||
return(NO);
|
||||
}
|
||||
}
|
||||
|
||||
void rlinit(){
|
||||
rl_catch_signals = 0;
|
||||
rl_catch_sigwinch = 0;
|
||||
rl_prep_term_function = NULL;
|
||||
rl_deprep_term_function = NULL;
|
||||
rl_change_environment = 0;
|
||||
rl_catch_signals = 0;
|
||||
rl_catch_sigwinch = 0;
|
||||
rl_prep_term_function = NULL;
|
||||
rl_deprep_term_function = NULL;
|
||||
rl_change_environment = 0;
|
||||
|
||||
rl_getc_function = getc_function;
|
||||
rl_input_available_hook = input_available_hook;
|
||||
rl_redisplay_function = redisplay_function;
|
||||
rl_callback_handler_install("", callback_handler);
|
||||
rl_getc_function = getc_function;
|
||||
rl_input_available_hook = input_available_hook;
|
||||
rl_redisplay_function = redisplay_function;
|
||||
rl_callback_handler_install("", callback_handler);
|
||||
|
||||
rl_bind_key('\t', horswp_field_proxy);
|
||||
rl_bind_key('%', verswp_field_proxy);
|
||||
rl_bind_key('\t', horswp_field_proxy);
|
||||
rl_bind_key('%', verswp_field_proxy);
|
||||
|
||||
rl_bind_key(EOF, interpret_break);
|
||||
rl_bind_key(ctrl('D'), interpret_break); //XXX: why the fuck does it not work if its the first char?
|
||||
rl_bind_key(ctrl('Z'), ctrl_z);
|
||||
rl_bind_key(ctrl('Z'), toggle_caseless);
|
||||
rl_bind_key(ctrl('R'), rebuild_reference);
|
||||
rl_bind_key(ESC, process_mouse); /* possible unixpc mouse selection */
|
||||
rl_bind_key(ctrl('X'), process_mouse); /* mouse selection */
|
||||
rl_bind_key(EOF, interpret_break);
|
||||
rl_bind_key(ctrl('D'), interpret_break); //XXX: why the fuck does it not work if its the first char?
|
||||
rl_bind_key(ctrl('Z'), ctrl_z);
|
||||
rl_bind_key(ctrl('Z'), toggle_caseless);
|
||||
rl_bind_key(ctrl('R'), rebuild_reference);
|
||||
rl_bind_key(ESC, process_mouse); /* possible unixpc mouse selection */
|
||||
rl_bind_key(ctrl('X'), process_mouse); /* mouse selection */
|
||||
|
||||
//rl_bind_key(ctrl('\\'), /**/); /* bypass bindings */
|
||||
//rl_bind_key(ctrl('\\'), /**/); /* bypass bindings */
|
||||
}
|
||||
|
@ -35,60 +35,60 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef YYLMAX
|
||||
#define YYLMAX STMTMAX + PATLEN + 1 /* scanner line buffer size */
|
||||
#undef YYLMAX
|
||||
#define YYLMAX STMTMAX + PATLEN + 1 /* scanner line buffer size */
|
||||
|
||||
/* cross-reference database mark characters (when new ones are added,
|
||||
* update the cscope.out format description in cscope.1)
|
||||
*/
|
||||
#define CLASSDEF 'c'
|
||||
#define DEFINE '#'
|
||||
#define DEFINEEND ')'
|
||||
#define ENUMDEF 'e'
|
||||
#define FCNCALL '`'
|
||||
#define FCNDEF '$'
|
||||
#define FCNEND '}'
|
||||
#define GLOBALDEF 'g'
|
||||
#define INCLUDE '~'
|
||||
#define MEMBERDEF 'm'
|
||||
#define NEWFILE '@'
|
||||
#define STRUCTDEF 's'
|
||||
#define TYPEDEF 't'
|
||||
#define UNIONDEF 'u'
|
||||
#define CLASSDEF 'c'
|
||||
#define DEFINE '#'
|
||||
#define DEFINEEND ')'
|
||||
#define ENUMDEF 'e'
|
||||
#define FCNCALL '`'
|
||||
#define FCNDEF '$'
|
||||
#define FCNEND '}'
|
||||
#define GLOBALDEF 'g'
|
||||
#define INCLUDE '~'
|
||||
#define MEMBERDEF 'm'
|
||||
#define NEWFILE '@'
|
||||
#define STRUCTDEF 's'
|
||||
#define TYPEDEF 't'
|
||||
#define UNIONDEF 'u'
|
||||
|
||||
/* other scanner token types */
|
||||
#define LEXEOF 0
|
||||
#define LEXERR 1
|
||||
#define IDENT 2
|
||||
#define NEWLINE 3
|
||||
#define LEXEOF 0
|
||||
#define LEXERR 1
|
||||
#define IDENT 2
|
||||
#define NEWLINE 3
|
||||
|
||||
/* scanner.l global data */
|
||||
extern int first; /* buffer index for first char of symbol */
|
||||
extern int last; /* buffer index for last char of symbol */
|
||||
extern int lineno; /* symbol line number */
|
||||
extern FILE *yyin; /* input file descriptor */
|
||||
extern FILE *yyout; /* output file */
|
||||
extern int myylineno; /* input line number */
|
||||
extern int first; /* buffer index for first char of symbol */
|
||||
extern int last; /* buffer index for last char of symbol */
|
||||
extern int lineno; /* symbol line number */
|
||||
extern FILE *yyin; /* input file descriptor */
|
||||
extern FILE *yyout; /* output file */
|
||||
extern int myylineno; /* input line number */
|
||||
|
||||
#ifdef USING_LEX
|
||||
/* HBB 20010430: if lex is used instead of flex, have to simulate the
|
||||
* private copies of yytext and yytext for the world outside scanner.l: */
|
||||
/* FIXME: there should be a feature test for this! */
|
||||
#if defined(__OSF1__) || defined(__sun) || defined(_AIX)
|
||||
extern char yytext[];
|
||||
extern char yytext[];
|
||||
#else
|
||||
extern unsigned char yytext[];
|
||||
extern unsigned char yytext[];
|
||||
#endif
|
||||
extern int yyleng;
|
||||
extern int yyleng;
|
||||
# define my_yytext yytext
|
||||
# define my_yyleng yyleng
|
||||
#else
|
||||
extern char *my_yytext; /* private copy of input line */
|
||||
extern size_t my_yyleng; /* ... and current length of it */
|
||||
extern char *my_yytext; /* private copy of input line */
|
||||
extern size_t my_yyleng; /* ... and current length of it */
|
||||
#endif
|
||||
|
||||
/* The master function exported by scanner.l */
|
||||
int yylex(void);
|
||||
void initscanner(char *srcfile);
|
||||
int yylex(void);
|
||||
void initscanner(char *srcfile);
|
||||
|
||||
#endif /* CSCOPE_SCANNER_H ends */
|
||||
|
@ -30,16 +30,16 @@
|
||||
DAMAGE.
|
||||
=========================================================================*/
|
||||
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
/* cscope - interactive C symbol cross-reference
|
||||
*
|
||||
* Changing the cross-reference file part of the program version
|
||||
* forces rebuilding of the cross-reference.
|
||||
* Changing the cross-reference file part of the program version
|
||||
* forces rebuilding of the cross-reference.
|
||||
*/
|
||||
|
||||
#ifndef CSCOPE_VERSION_H
|
||||
#define CSCOPE_VERSION_H
|
||||
|
||||
#define FILEVERSION 15 /* Initial Open Source and Linux Port */
|
||||
#define FIXVERSION ".9" /* feature and bug fix version */
|
||||
#define FILEVERSION 15 /* Initial Open Source and Linux Port */
|
||||
#define FIXVERSION ".9" /* feature and bug fix version */
|
||||
|
||||
#endif /* CSCOPE_VERSION_H */
|
||||
|
30
src/vp.h
30
src/vp.h
@ -31,40 +31,40 @@
|
||||
=========================================================================*/
|
||||
|
||||
/*
|
||||
* VPATH assumptions:
|
||||
* VPATH is the environment variable containing the view path
|
||||
* where each path name is followed by ':', '\n', or '\0'.
|
||||
* Embedded blanks are considered part of the path.
|
||||
* VPATH assumptions:
|
||||
* VPATH is the environment variable containing the view path
|
||||
* where each path name is followed by ':', '\n', or '\0'.
|
||||
* Embedded blanks are considered part of the path.
|
||||
*/
|
||||
|
||||
#ifndef CSCOPE_VP_H
|
||||
#define CSCOPE_VP_H
|
||||
|
||||
#define MAXPATH 200 /* max length for entire name */
|
||||
#define MAXPATH 200 /* max length for entire name */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#else
|
||||
# define HAVE_FCNTL_H 1 /* in case of doubt, assume it's there */
|
||||
# define HAVE_FCNTL_H 1 /* in case of doubt, assume it's there */
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h> /* needed for O_... open flags */
|
||||
# include <fcntl.h> /* needed for O_... open flags */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if !NOMALLOC
|
||||
extern char **vpdirs; /* directories (including current) in view path */
|
||||
extern char **vpdirs; /* directories (including current) in view path */
|
||||
#else
|
||||
#define MAXDIR 25 /* same as libVP */
|
||||
#define DIRLEN 80 /* same as libVP */
|
||||
extern char vpdirs[MAXDIR][DIRLEN + 1];
|
||||
#define MAXDIR 25 /* same as libVP */
|
||||
#define DIRLEN 80 /* same as libVP */
|
||||
extern char vpdirs[MAXDIR][DIRLEN + 1];
|
||||
#endif
|
||||
extern int vpndirs; /* number of directories in view path */
|
||||
extern int vpndirs; /* number of directories in view path */
|
||||
|
||||
void vpinit(char *current_dir);
|
||||
int vpopen(char *path, int oflag);
|
||||
int vpaccess(char *path, mode_t amode);
|
||||
void vpinit(char *current_dir);
|
||||
int vpopen(char *path, int oflag);
|
||||
int vpaccess(char *path, mode_t amode);
|
||||
|
||||
#endif /* CSCOPE_VP_H */
|
||||
|
@ -40,18 +40,18 @@
|
||||
int
|
||||
vpaccess(char *path, mode_t amode)
|
||||
{
|
||||
char buf[MAXPATH + 1];
|
||||
int returncode;
|
||||
int i;
|
||||
char buf[MAXPATH + 1];
|
||||
int returncode;
|
||||
int i;
|
||||
|
||||
if ((returncode = access(path, amode)) == -1 && path[0] != '/') {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], path);
|
||||
if ((returncode = access(buf, amode)) != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
if ((returncode = access(path, amode)) == -1 && path[0] != '/') {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], path);
|
||||
if ((returncode = access(buf, amode)) != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
}
|
||||
|
@ -40,23 +40,23 @@
|
||||
FILE *
|
||||
vpfopen(char *filename, char *type)
|
||||
{
|
||||
char buf[MAXPATH + 1];
|
||||
FILE *returncode;
|
||||
int i;
|
||||
char buf[MAXPATH + 1];
|
||||
FILE *returncode;
|
||||
int i;
|
||||
|
||||
if ((returncode = myfopen(filename, type)) == NULL
|
||||
&& filename[0] != '/'
|
||||
/* && strcmp(type, "r") == 0 */ /* HBB: this breaks if type=="rb" */
|
||||
&& type[0] == 'r'
|
||||
) {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], filename);
|
||||
if ((returncode = myfopen(buf, type)) != NULL) {
|
||||
break;
|
||||
}
|
||||
if ((returncode = myfopen(filename, type)) == NULL
|
||||
&& filename[0] != '/'
|
||||
/* && strcmp(type, "r") == 0 */ /* HBB: this breaks if type=="rb" */
|
||||
&& type[0] == 'r'
|
||||
) {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], filename);
|
||||
if ((returncode = myfopen(buf, type)) != NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
}
|
||||
|
218
src/vpinit.c
218
src/vpinit.c
@ -32,7 +32,7 @@
|
||||
|
||||
/* vpinit - initialize vpdirs or update vpdirs based on currentdir */
|
||||
|
||||
#include <stdio.h> /* stderr */
|
||||
#include <stdio.h> /* stderr */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -43,127 +43,127 @@
|
||||
#include "constants.h"
|
||||
|
||||
#if !NOMALLOC
|
||||
char **vpdirs; /* directories (including current) in view path */
|
||||
char **vpdirs; /* directories (including current) in view path */
|
||||
#else
|
||||
char vpdirs[MAXDIR][DIRLEN + 1];
|
||||
#define MAXVPATH (MAXDIR * (DIRLEN + 1))
|
||||
char vpdirs[MAXDIR][DIRLEN + 1];
|
||||
#define MAXVPATH (MAXDIR * (DIRLEN + 1))
|
||||
#endif
|
||||
int vpndirs; /* number of directories in view path */
|
||||
int vpndirs; /* number of directories in view path */
|
||||
|
||||
void
|
||||
vpinit(char *current_dir)
|
||||
{
|
||||
char *suffix; /* path from view path node */
|
||||
char *vpath; /* VPATH environment variable value */
|
||||
char buf[MAXPATH + 1];
|
||||
int i;
|
||||
char *s;
|
||||
char *suffix; /* path from view path node */
|
||||
char *vpath; /* VPATH environment variable value */
|
||||
char buf[MAXPATH + 1];
|
||||
int i;
|
||||
char *s;
|
||||
#if NOMALLOC
|
||||
char *node; /* view path node */
|
||||
char vpathbuf[MAXVPATH + 1];
|
||||
char *node; /* view path node */
|
||||
char vpathbuf[MAXVPATH + 1];
|
||||
#endif
|
||||
|
||||
/* if an existing directory list is to be updated, free it */
|
||||
if (current_dir != NULL && vpndirs > 0) {
|
||||
|
||||
/* if an existing directory list is to be updated, free it */
|
||||
if (current_dir != NULL && vpndirs > 0) {
|
||||
#if !NOMALLOC
|
||||
for (i = 0; i < vpndirs; ++i) {
|
||||
free(vpdirs[i]);
|
||||
}
|
||||
free(vpdirs);
|
||||
for (i = 0; i < vpndirs; ++i) {
|
||||
free(vpdirs[i]);
|
||||
}
|
||||
free(vpdirs);
|
||||
#endif
|
||||
vpndirs = 0;
|
||||
}
|
||||
/* return if the directory list has been computed */
|
||||
/* or there isn't a view path environment variable */
|
||||
if (vpndirs > 0 || (vpath = getenv("VPATH")) == NULL ||
|
||||
*vpath == '\0') {
|
||||
return;
|
||||
}
|
||||
/* if not given, get the current directory name */
|
||||
if (current_dir == NULL && (current_dir = getcwd(buf, MAXPATH)) == NULL) {
|
||||
(void) fprintf(stderr, "%s: cannot get current directory name\n", argv0);
|
||||
return;
|
||||
}
|
||||
/* see if this directory is in the first view path node */
|
||||
for (i = 0; vpath[i] == current_dir[i] && vpath[i] != '\0'; ++i) {
|
||||
;
|
||||
}
|
||||
if ((vpath[i] != ':' && vpath[i] != '\0') ||
|
||||
(current_dir[i] != '/' && current_dir[i] != '\0')) {
|
||||
return;
|
||||
}
|
||||
suffix = ¤t_dir[i];
|
||||
vpndirs = 0;
|
||||
}
|
||||
/* return if the directory list has been computed */
|
||||
/* or there isn't a view path environment variable */
|
||||
if (vpndirs > 0 || (vpath = getenv("VPATH")) == NULL ||
|
||||
*vpath == '\0') {
|
||||
return;
|
||||
}
|
||||
/* if not given, get the current directory name */
|
||||
if (current_dir == NULL && (current_dir = getcwd(buf, MAXPATH)) == NULL) {
|
||||
(void) fprintf(stderr, "%s: cannot get current directory name\n", argv0);
|
||||
return;
|
||||
}
|
||||
/* see if this directory is in the first view path node */
|
||||
for (i = 0; vpath[i] == current_dir[i] && vpath[i] != '\0'; ++i) {
|
||||
;
|
||||
}
|
||||
if ((vpath[i] != ':' && vpath[i] != '\0') ||
|
||||
(current_dir[i] != '/' && current_dir[i] != '\0')) {
|
||||
return;
|
||||
}
|
||||
suffix = ¤t_dir[i];
|
||||
#if !NOMALLOC
|
||||
|
||||
/* count the nodes in the view path */
|
||||
vpndirs = 1;
|
||||
for (i = 0; vpath[i] != '\0'; ++i) {
|
||||
if (vpath[i] == ':' && vpath[i + 1]) {
|
||||
++vpndirs;
|
||||
}
|
||||
}
|
||||
/* create the source directory list */
|
||||
vpdirs = malloc(vpndirs * sizeof(*vpdirs));
|
||||
/* count the nodes in the view path */
|
||||
vpndirs = 1;
|
||||
for (i = 0; vpath[i] != '\0'; ++i) {
|
||||
if (vpath[i] == ':' && vpath[i + 1]) {
|
||||
++vpndirs;
|
||||
}
|
||||
}
|
||||
/* create the source directory list */
|
||||
vpdirs = malloc(vpndirs * sizeof(*vpdirs));
|
||||
|
||||
/* don't change VPATH in the environment */
|
||||
vpath = strdup(vpath);
|
||||
|
||||
/* split the view path into nodes */
|
||||
for (i = 0, s = vpath; *s != '\0'; ++i) {
|
||||
vpdirs[i] = s;
|
||||
while (*s != '\0' && *++s != ':') {
|
||||
if (*s == '\n') {
|
||||
*s = '\0';
|
||||
}
|
||||
}
|
||||
if (*s != '\0') {
|
||||
*s++ = '\0';
|
||||
}
|
||||
}
|
||||
/* convert the view path nodes to directories */
|
||||
for (i = 0; i < vpndirs; ++i) {
|
||||
s = malloc(strlen(vpdirs[i]) + strlen(suffix) + 1);
|
||||
(void) strcpy(s, vpdirs[i]);
|
||||
(void) strcat(s, suffix);
|
||||
vpdirs[i] = s;
|
||||
}
|
||||
free(vpath);
|
||||
/* don't change VPATH in the environment */
|
||||
vpath = strdup(vpath);
|
||||
|
||||
/* split the view path into nodes */
|
||||
for (i = 0, s = vpath; *s != '\0'; ++i) {
|
||||
vpdirs[i] = s;
|
||||
while (*s != '\0' && *++s != ':') {
|
||||
if (*s == '\n') {
|
||||
*s = '\0';
|
||||
}
|
||||
}
|
||||
if (*s != '\0') {
|
||||
*s++ = '\0';
|
||||
}
|
||||
}
|
||||
/* convert the view path nodes to directories */
|
||||
for (i = 0; i < vpndirs; ++i) {
|
||||
s = malloc(strlen(vpdirs[i]) + strlen(suffix) + 1);
|
||||
(void) strcpy(s, vpdirs[i]);
|
||||
(void) strcat(s, suffix);
|
||||
vpdirs[i] = s;
|
||||
}
|
||||
free(vpath);
|
||||
#else
|
||||
/* don't change VPATH in the environment */
|
||||
if (strlen(vpath) > MAXVPATH) {
|
||||
(void) fprintf(stderr, "%s: VPATH is longer than %d characters: %s\n", argv0, MAXVPATH, vpath);
|
||||
return;
|
||||
}
|
||||
(void) strcpy(vpathbuf, vpath);
|
||||
s = vpathbuf;
|
||||
|
||||
/* convert the view path nodes to directories */
|
||||
while (*s != '\0') {
|
||||
|
||||
/* get the next node */
|
||||
node = s;
|
||||
while (*s != '\0' && *++s != ':') {
|
||||
if (*s == '\n') {
|
||||
*s = '\0';
|
||||
}
|
||||
}
|
||||
if (*s != '\0') {
|
||||
*s++ = '\0';
|
||||
}
|
||||
/* ignore a directory that is too long */
|
||||
if (strlen(node) + strlen(suffix) > DIRLEN) {
|
||||
(void) fprintf(stderr, "%s: VPATH directory is longer than %d characters: %s%s\n", argv0, DIRLEN, node, suffix);
|
||||
}
|
||||
else if (vpndirs >= MAXDIR) {
|
||||
(void) fprintf(stderr, "%s: VPATH has more than %d nodes\n", argv0, vpndirs);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* create the view path directory */
|
||||
(void) strcpy(vpdirs[vpndirs], node);
|
||||
(void) strcat(vpdirs[vpndirs], suffix);
|
||||
++vpndirs;
|
||||
}
|
||||
}
|
||||
/* don't change VPATH in the environment */
|
||||
if (strlen(vpath) > MAXVPATH) {
|
||||
(void) fprintf(stderr, "%s: VPATH is longer than %d characters: %s\n", argv0, MAXVPATH, vpath);
|
||||
return;
|
||||
}
|
||||
(void) strcpy(vpathbuf, vpath);
|
||||
s = vpathbuf;
|
||||
|
||||
/* convert the view path nodes to directories */
|
||||
while (*s != '\0') {
|
||||
|
||||
/* get the next node */
|
||||
node = s;
|
||||
while (*s != '\0' && *++s != ':') {
|
||||
if (*s == '\n') {
|
||||
*s = '\0';
|
||||
}
|
||||
}
|
||||
if (*s != '\0') {
|
||||
*s++ = '\0';
|
||||
}
|
||||
/* ignore a directory that is too long */
|
||||
if (strlen(node) + strlen(suffix) > DIRLEN) {
|
||||
(void) fprintf(stderr, "%s: VPATH directory is longer than %d characters: %s%s\n", argv0, DIRLEN, node, suffix);
|
||||
}
|
||||
else if (vpndirs >= MAXDIR) {
|
||||
(void) fprintf(stderr, "%s: VPATH has more than %d nodes\n", argv0, vpndirs);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* create the view path directory */
|
||||
(void) strcpy(vpdirs[vpndirs], node);
|
||||
(void) strcat(vpdirs[vpndirs], suffix);
|
||||
++vpndirs;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
30
src/vpopen.c
30
src/vpopen.c
@ -37,24 +37,24 @@
|
||||
#include "global.h"
|
||||
#include "vp.h"
|
||||
|
||||
#define OPENFLAG_READ 0
|
||||
#define OPENFLAG_READ 0
|
||||
|
||||
int
|
||||
vpopen(char *path, int oflag)
|
||||
{
|
||||
char buf[MAXPATH + 1];
|
||||
int returncode;
|
||||
int i;
|
||||
char buf[MAXPATH + 1];
|
||||
int returncode;
|
||||
int i;
|
||||
|
||||
if ((returncode = myopen(path, oflag, 0666)) == -1 && path[0] != '/' &&
|
||||
oflag == OPENFLAG_READ) {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], path);
|
||||
if ((returncode = myopen(buf, oflag, 0666)) != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
if ((returncode = myopen(path, oflag, 0666)) == -1 && path[0] != '/' &&
|
||||
oflag == OPENFLAG_READ) {
|
||||
vpinit(NULL);
|
||||
for (i = 1; i < vpndirs; i++) {
|
||||
(void) snprintf(buf, sizeof(buf), "%s/%s", vpdirs[i], path);
|
||||
if ((returncode = myopen(buf, oflag, 0666)) != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(returncode);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user