'clang-format'-ing

This commit is contained in:
anon 2023-08-13 11:21:52 +02:00
parent dc399a1b86
commit 987c69f75c
38 changed files with 8022 additions and 8311 deletions

View File

@ -47,9 +47,9 @@
#include "vp.h"
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
# include <ncurses.h>
#else
#include <curses.h>
# include <curses.h>
#endif
/* Exported variables: */
@ -92,49 +92,36 @@ 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 */
static void
cannotindex(void)
{
static void cannotindex(void) {
fprintf(stderr, PROGRAM_NAME ": cannot create inverted index; ignoring -q option\n");
invertedindex = false;
errorsfound = true;
fprintf(stderr, PROGRAM_NAME ": removed files %s and %s\n",
newinvname, newinvpost);
fprintf(stderr, PROGRAM_NAME ": removed files %s and %s\n", newinvname, newinvpost);
unlink(newinvname);
unlink(newinvpost);
}
/* see if the name list is the same in the cross-reference file */
static bool
samelist(FILE *oldrefs, char **names, int count)
{
static bool samelist(FILE *oldrefs, char **names, int count) {
char oldname[PATHLEN + 1]; /* name in old cross-reference */
int oldcount;
int i;
/* see if the number of names is the same */
if (fscanf(oldrefs, "%d", &oldcount) != 1 ||
oldcount != count) {
return(false);
}
if(fscanf(oldrefs, "%d", &oldcount) != 1 || oldcount != count) { return (false); }
/* 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(false);
for(i = 0; i < count; ++i) {
if((1 != fscanf(oldrefs, " %[^\n]", oldname)) || strnotequal(oldname, names[i])) {
return (false);
}
}
return(true);
return (true);
}
/* create the file name(s) used for a new cross-referene */
void setup_build_filenames(char *reffile)
{
void setup_build_filenames(char *reffile) {
char *path; /* file pathname */
char *s; /* pointer to basename in path */
@ -155,30 +142,24 @@ void setup_build_filenames(char *reffile)
/* open the database */
void
opendatabase(void)
{
if ((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
void opendatabase(void) {
if((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
cannotopen(reffile);
myexit(1);
}
blocknumber = -1; /* force next seek to read the first block */
/* open any inverted index */
if (invertedindex == true &&
invopen(&invcontrol, invname, invpost, INVAVAIL) == -1) {
if(invertedindex == true && invopen(&invcontrol, invname, invpost, INVAVAIL) == -1) {
askforreturn(); /* so user sees message */
invertedindex = false;
}
}
/* rebuild the database */
void
rebuild(void)
{
void rebuild(void) {
close(symrefs);
if (invertedindex == true) {
if(invertedindex == true) {
invclose(&invcontrol);
nsrcoffset = 0;
npostings = 0;
@ -187,17 +168,14 @@ rebuild(void)
opendatabase();
/* revert to the initial display */
if (refsfound != NULL) {
if(refsfound != NULL) {
fclose(refsfound);
refsfound = NULL;
}
}
/* build the cross-reference */
void
build(void)
{
void build(void) {
unsigned long i;
FILE *oldrefs; /* old cross-reference file */
time_t reftime; /* old crossref modification time */
@ -218,9 +196,9 @@ build(void)
/* 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) {
if(strcmp(currentdir, home) == 0) {
strcpy(newdir, "$HOME");
} else if (strncmp(currentdir, home, strlen(home)) == 0) {
} else if(strncmp(currentdir, home, strlen(home)) == 0) {
snprintf(newdir, sizeof(newdir), "$HOME%s", currentdir + strlen(home));
}
/* sort the source file names (needed for rebuilding) */
@ -228,29 +206,29 @@ 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 == false
&& fscanf(oldrefs, PROGRAM_NAME " %d %" PATHLEN_STR "s", &fileversion, olddir) == 2
&& (strcmp(olddir, currentdir) == 0 /* remain compatible */
if((oldrefs = vpfopen(reffile, "rb")) != NULL && unconditional == false &&
fscanf(oldrefs, PROGRAM_NAME " %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) {
if(fileversion >= 8) {
bool oldcompress = true;
bool oldinvertedindex = false;
bool oldtruncate = false;
int c;
/* see if there are options in the database */
for (;;) {
for(;;) {
while((c = getc(oldrefs)) == ' ')
; /* do nothing */
if (c != '-') {
if(c != '-') {
ungetc(c, oldrefs);
break;
}
switch (getc(oldrefs)) {
switch(getc(oldrefs)) {
case 'c': /* ASCII characters only */
oldcompress = false;
break;
@ -264,34 +242,33 @@ build(void)
}
}
/* check the old and new option settings */
if (oldcompress != compress || oldtruncate != trun_syms) {
posterr(PROGRAM_NAME ": -c or -T option mismatch between command line and old symbol database\n");
if(oldcompress != compress || oldtruncate != trun_syms) {
posterr(PROGRAM_NAME
": -c or -T option mismatch between command line and old symbol database\n");
goto force;
}
if (oldinvertedindex != invertedindex) {
posterr(PROGRAM_NAME ": -q option mismatch between command line and old symbol database\n");
if (invertedindex == false) {
posterr(PROGRAM_NAME ": removed files %s and %s\n",
invname, invpost);
if(oldinvertedindex != invertedindex) {
posterr(PROGRAM_NAME
": -q option mismatch between command line and old symbol database\n");
if(invertedindex == false) {
posterr(PROGRAM_NAME ": removed files %s and %s\n", invname, invpost);
unlink(invname);
unlink(invpost);
}
goto outofdate;
}
/* seek to the trailer */
if (fscanf(oldrefs, "%ld", &traileroffset) != 1 ||
if(fscanf(oldrefs, "%ld", &traileroffset) != 1 ||
fseek(oldrefs, traileroffset, SEEK_SET) == -1) {
posterr(PROGRAM_NAME ": incorrect symbol database file format\n");
goto force;
}
}
/* if assuming that some files have changed */
if (fileschanged == true) {
goto outofdate;
}
if(fileschanged == true) { goto outofdate; }
/* see if the directory lists are the same */
if (samelist(oldrefs, srcdirs, nsrcdirs) == false
|| samelist(oldrefs, incdirs, nincdirs) == false
if(samelist(oldrefs, srcdirs, nsrcdirs) == false ||
samelist(oldrefs, incdirs, nincdirs) == false
/* get the old number of files */
|| fscanf(oldrefs, "%lu", &oldnum) != 1
/* skip the string space size */
@ -300,18 +277,17 @@ build(void)
}
/* 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)
) {
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)) {
while(i++ < oldnum && fgets(oldname, sizeof(oldname), oldrefs)) {
addsrcfile(oldname);
}
fclose(oldrefs);
@ -319,12 +295,13 @@ build(void)
outofdate:
/* if the database format has changed, rebuild it all */
if (fileversion != FILEVERSION) {
fprintf(stderr, PROGRAM_NAME ": converting to new symbol database file format\n");
if(fileversion != FILEVERSION) {
fprintf(stderr,
PROGRAM_NAME ": 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) {
if((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
/* NOTREACHED */
}
@ -339,17 +316,17 @@ build(void)
oldfile = NULL;
}
/* open the new cross-reference file */
if ((newrefs = myfopen(newreffile, "wb")) == NULL) {
if((newrefs = myfopen(newreffile, "wb")) == NULL) {
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
/* NOTREACHED */
}
if (invertedindex == true && (postings = myfopen(temp1, "wb")) == NULL) {
if(invertedindex == true && (postings = myfopen(temp1, "wb")) == NULL) {
cannotwrite(temp1);
cannotindex();
}
putheader(newdir);
fileversion = FILEVERSION;
if (buildonly == true && verbosemode != true && !isatty(0)) {
if(buildonly == true && verbosemode != true && !isatty(0)) {
interactive = false;
} else {
searchcount = 0;
@ -361,33 +338,30 @@ build(void)
included files is processed */
firstfile = 0;
lastfile = nsrcfiles;
if (invertedindex == true) {
if(invertedindex == true) {
srcoffset = malloc((nsrcfiles + 1u) * sizeof(*srcoffset));
}
for (;;) {
progress("Building symbol database", (long)built,
(long)lastfile);
if (linemode == false)
refresh();
for(;;) {
progress("Building symbol database", (long)built, (long)lastfile);
if(linemode == false) refresh();
/* get the next source file name */
for (fileindex = firstfile; fileindex < lastfile; ++fileindex) {
for(fileindex = firstfile; fileindex < lastfile; ++fileindex) {
/* display the progress about every three seconds */
if (interactive == true && fileindex % 10 == 0) {
if(interactive == true && 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) {
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) {
if(oldfile == NULL || strcmp(file, oldfile) < 0) {
crossref(file);
++built;
} else if (lstat(file, &statstruct) == 0
&& statstruct.st_mtime > reftime) {
} else if(lstat(file, &statstruct) == 0 && statstruct.st_mtime > reftime) {
/* if this file was modified */
crossref(file);
++built;
@ -401,7 +375,7 @@ build(void)
} else {
/* copy its cross-reference */
putfilename(file);
if (invertedindex == true) {
if(invertedindex == true) {
copyinverted();
} else {
copydata();
@ -411,12 +385,10 @@ build(void)
}
}
/* see if any included files were found */
if (lastfile == nsrcfiles) {
break;
}
if(lastfile == nsrcfiles) { break; }
firstfile = lastfile;
lastfile = nsrcfiles;
if (invertedindex == true) {
if(invertedindex == true) {
srcoffset = realloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset));
}
/* sort the included file names */
@ -433,28 +405,32 @@ build(void)
putlist(srcdirs, nsrcdirs);
putlist(incdirs, nincdirs);
putlist(srcfiles, nsrcfiles);
if (fflush(newrefs) == EOF) {
if(fflush(newrefs) == EOF) {
/* rewind doesn't check for write failure */
cannotwrite(newreffile);
/* NOTREACHED */
}
/* create the inverted index if requested */
if (invertedindex == true) {
if(invertedindex == true) {
char sortcommand[PATHLEN + 1];
if (fflush(postings) == EOF) {
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) {
snprintf(sortcommand,
sizeof(sortcommand),
"env LC_ALL=C sort -T %s %s",
tmpdir,
temp1);
if((postings = mypopen(sortcommand, "r")) == NULL) {
fprintf(stderr, PROGRAM_NAME ": cannot open pipe to sort command\n");
cannotindex();
} else {
if ((totalterms = invmake(newinvname, newinvpost, postings)) > 0) {
if((totalterms = invmake(newinvname, newinvpost, postings)) > 0) {
movefile(newinvname, invname);
movefile(newinvpost, invpost);
} else {
@ -471,84 +447,64 @@ build(void)
fclose(newrefs);
/* close the old database file */
if (symrefs >= 0) {
close(symrefs);
}
if (oldrefs != NULL) {
fclose(oldrefs);
}
if(symrefs >= 0) { close(symrefs); }
if(oldrefs != NULL) { fclose(oldrefs); }
/* replace it with the new database file */
movefile(newreffile, reffile);
}
/* string comparison function for qsort */
static int
compare(const void *arg_s1, const void *arg_s2)
{
const char **s1 = (const char **) arg_s1;
const char **s2 = (const char **) arg_s2;
static int 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));
return (strcmp(*s1, *s2));
}
/* seek to the trailer, in a given file */
void
seek_to_trailer(FILE *f)
{
if (fscanf(f, "%ld", &traileroffset) != 1) {
void seek_to_trailer(FILE *f) {
if(fscanf(f, "%ld", &traileroffset) != 1) {
postfatal(PROGRAM_NAME ": cannot read trailer offset from file %s\n", reffile);
/* NOTREACHED */
}
if (fseek(f, traileroffset, SEEK_SET) == -1) {
if(fseek(f, traileroffset, SEEK_SET) == -1) {
postfatal(PROGRAM_NAME ": cannot seek to trailer in file %s\n", reffile);
/* NOTREACHED */
}
}
/* get the next file name in the old cross-reference */
static char *
getoldfile(void)
{
static char *getoldfile(void) {
static char file[PATHLEN + 1]; /* file name in old crossref */
if (blockp != NULL) {
if(blockp != NULL) {
do {
if (*blockp == NEWFILE) {
if(*blockp == NEWFILE) {
skiprefchar();
fetch_string_from_dbase(file, sizeof(file));
if (file[0] != '\0') { /* if not end-of-crossref */
return(file);
if(file[0] != '\0') { /* if not end-of-crossref */
return (file);
}
return(NULL);
return (NULL);
}
} while (scanpast('\t') != NULL);
} while(scanpast('\t') != NULL);
}
return(NULL);
return (NULL);
}
/* Free all storage allocated for filenames: */
void free_newbuildfiles(void)
{
void free_newbuildfiles(void) {
free(newinvname);
free(newinvpost);
free(newreffile);
}
/* output the cscope version, current directory, database format options, and
the database trailer offset */
static void
putheader(char *dir)
{
static void putheader(char *dir) {
dboffset = fprintf(newrefs, PROGRAM_NAME " %d %s", FILEVERSION, dir);
if (compress == false) {
dboffset += fprintf(newrefs, " -c");
}
if (invertedindex == true) {
if(compress == false) { dboffset += fprintf(newrefs, " -c"); }
if(invertedindex == true) {
dboffset += fprintf(newrefs, " -q %.10ld", totalterms);
} else {
/* leave space so if the header is overwritten without -q
@ -556,9 +512,7 @@ putheader(char *dir)
* is the same length */
dboffset += fprintf(newrefs, " ");
}
if (trun_syms == true) {
dboffset += fprintf(newrefs, " -T");
}
if(trun_syms == true) { dboffset += fprintf(newrefs, " -T"); }
dboffset += fprintf(newrefs, " %.10ld\n", traileroffset);
#ifdef PRINTF_RETVAL_BROKEN
@ -566,61 +520,50 @@ putheader(char *dir)
#endif
}
/* put the name list into the cross-reference file */
static void
putlist(char **names, int count)
{
static void putlist(char **names, int count) {
int i, size = 0;
fprintf(newrefs, "%d\n", count);
if (names == srcfiles) {
if(names == srcfiles) {
/* calculate the string space needed */
for (i = 0; i < count; ++i) {
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) {
for(i = 0; i < count; ++i) {
if(fputs(names[i], newrefs) == EOF || putc('\n', newrefs) == EOF) {
cannotwrite(newreffile);
/* NOTREACHED */
}
}
}
/* copy this file's symbol data */
static void
copydata(void)
{
static void copydata(void) {
char *cp;
setmark('\t');
cp = blockp;
for (;;) {
for(;;) {
/* copy up to the next \t */
do { /* innermost loop optimized to only one test */
while (*cp != '\t') {
while(*cp != '\t') {
dbputc(*cp++);
}
} while (*++cp == '\0' && (cp = read_block()) != NULL);
} 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();
}
if(cp && (*(cp + 1) == '\0')) { cp = read_block(); }
/* exit if at the end of this file's data */
if (cp == NULL || *cp == NEWFILE) {
break;
}
if(cp == NULL || *cp == NEWFILE) { break; }
/* look for an #included file */
if (*cp == INCLUDE) {
if(*cp == INCLUDE) {
char symbol[PATLEN + 1];
blockp = cp;
fetch_include_from_dbase(symbol, sizeof(symbol));
@ -634,9 +577,7 @@ copydata(void)
/* copy this file's symbol data and output the inverted index postings */
static void
copyinverted(void)
{
static void copyinverted(void) {
char *cp;
char c;
int type; /* reference type (mark character) */
@ -646,26 +587,22 @@ copyinverted(void)
/* while (scanpast('\n') != NULL) { */
/* other macros were replaced by code using cp instead of blockp */
cp = blockp;
for (;;) {
for(;;) {
setmark('\n');
do { /* innermost loop optimized to only one test */
while (*cp != '\n') {
while(*cp != '\n') {
dbputc(*cp++);
}
} while (*++cp == '\0' && (cp = read_block()) != NULL);
} 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();
}
if(cp && (*(cp + 1) == '\0')) { cp = read_block(); }
/* exit if at the end of this file's data */
if (cp == NULL) {
break;
}
switch (*cp) {
if(cp == NULL) { break; }
switch(*cp) {
case '\n':
lineoffset = dboffset + 1;
continue;
@ -673,7 +610,7 @@ copyinverted(void)
dbputc('\t');
blockp = cp;
type = getrefchar();
switch (type) {
switch(type) {
case NEWFILE: /* file name */
return;
case INCLUDE: /* #included file */
@ -686,45 +623,36 @@ copyinverted(void)
goto output;
}
c = *cp;
if (c & 0200) { /* digraph char? */
if(c & 0200) { /* digraph char? */
c = dichar1[(c & 0177) / 8];
}
/* if this is a symbol */
if (isalpha((unsigned char)c) || c == '_') {
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;
}
if(blockp == NULL) { return; }
cp = blockp;
}
}
blockp = cp;
}
/* replace the old file with the new file */
static void
movefile(char *new, char *old)
{
static void movefile(char *new, char *old) {
unlink(old);
if (rename(new, old) == -1) {
if(rename(new, old) == -1) {
myperror(PROGRAM_NAME);
postfatal(PROGRAM_NAME ": cannot rename file %s to file %s\n",
new, old);
postfatal(PROGRAM_NAME ": cannot rename file %s to file %s\n", new, old);
/* NOTREACHED */
}
}
/* process the #included file in the old database */
static void
fetch_include_from_dbase(char *s, size_t length)
{
static void fetch_include_from_dbase(char *s, size_t length) {
dbputc(INCLUDE);
skiprefchar();
fetch_string_from_dbase(s, length);

View File

@ -39,7 +39,7 @@
/* 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 dbputc(c) (++dboffset, (void)putc(c, newrefs))
#define dbfputs(s) (dboffset += strlen(s), fputs(s, newrefs))
/* declarations for globals defined in build.c */

View File

@ -41,9 +41,9 @@
#include <stdlib.h>
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
# include <ncurses.h>
#else
#include <curses.h>
# include <curses.h>
#endif
#include <ctype.h>
@ -68,83 +68,76 @@ static void scrollbar(MOUSE *p);
/* read references from a file */
bool
readrefs(char *filename)
{
bool readrefs(char *filename) {
FILE *file;
int c;
if ((file = myfopen(filename, "rb")) == NULL) {
if((file = myfopen(filename, "rb")) == NULL) {
cannotopen(filename);
return(false);
return (false);
}
if ((c = getc(file)) == EOF) { /* if file is empty */
if((c = getc(file)) == EOF) { /* if file is empty */
fclose(file);
return(false);
return (false);
}
totallines = 0;
disprefs = 0;
nextline = 1;
if (writerefsfound() == true) {
if(writerefsfound() == true) {
putc(c, refsfound);
while ((c = getc(file)) != EOF) {
while((c = getc(file)) != EOF) {
putc(c, refsfound);
}
fclose(file);
fclose(refsfound);
if ( (refsfound = myfopen(temp1, "rb")) == NULL) {
if((refsfound = myfopen(temp1, "rb")) == NULL) {
cannotopen(temp1);
return(false);
return (false);
}
countrefs();
} else
fclose(file);
return(true);
return (true);
}
/* scrollbar actions */
static void
scrollbar(MOUSE *p)
{
static void scrollbar(MOUSE *p) {
///* reposition list if it makes sense */
//if (totallines == 0) {
//return;
//}
//switch (p->percent) {
// if (totallines == 0) {
// return;
// }
// switch (p->percent) {
//case 101: /* scroll down one page */
//if (nextline + mdisprefs > totallines) {
// case 101: /* scroll down one page */
// if (nextline + mdisprefs > totallines) {
// nextline = totallines - mdisprefs + 1;
//}
//break;
// }
// break;
//case 102: /* scroll up one page */
//nextline = topline - mdisprefs;
//if (nextline < 1) {
// case 102: /* scroll up one page */
// nextline = topline - mdisprefs;
// if (nextline < 1) {
// nextline = 1;
//}
//break;
// }
// break;
//case 103: /* scroll down one line */
//nextline = topline + 1;
//break;
// case 103: /* scroll down one line */
// nextline = topline + 1;
// break;
//case 104: /* scroll up one line */
//if (topline > 1) {
// case 104: /* scroll up one line */
// if (topline > 1) {
// nextline = topline - 1;
//}
//break;
//default:
//nextline = p->percent * totallines / 100;
//}
// }
// break;
// default:
// nextline = p->percent * totallines / 100;
// }
////seekline(nextline);
}
/* count the references found */
void
countrefs(void)
{
void countrefs(void) {
char *subsystem; /* OGS subsystem name */
char *book; /* OGS book name */
char file[PATHLEN + 1]; /* file name */
@ -158,40 +151,28 @@ countrefs(void)
/* HBB falseTE 2012-04-07: it may look like we shouldn't assing tempstring here,
* 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)
) {
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 == true) {
if((i = strlen(pathcomponents(file, dispcomponents))) > filelen) { filelen = i; }
if(ogs == true) {
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;
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);
@ -199,19 +180,9 @@ countrefs(void)
/* restrict the width of displayed columns */
/* HBB FIXME 20060419: magic number alert! */
i = (COLS - 5) / 3;
if (ogs == true) {
i = (COLS - 7) / 5;
}
if (filelen > i && i > 4) {
filelen = i;
}
if (subsystemlen > i && i > 9) {
subsystemlen = i;
}
if (booklen > i && i > 4) {
booklen = i;
}
if (fcnlen > i && i > 8) {
fcnlen = i;
}
if(ogs == true) { i = (COLS - 7) / 5; }
if(filelen > i && i > 4) { filelen = i; }
if(subsystemlen > i && i > 9) { subsystemlen = i; }
if(booklen > i && i > 4) { booklen = i; }
if(fcnlen > i && i > 8) { fcnlen = i; }
}

View File

@ -49,13 +49,14 @@
/* 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()
#define DUMMYCHAR ' ' /* use space as a dummy character */
#define MSGLEN ((PATLEN) + 80) /* displayed message length */
@ -67,8 +68,8 @@
#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 INVNAME2 "cscope.out.in" /* follows correct naming convention */
#define INVPOST2 "cscope.out.po" /* follows correct naming convention */
#define STMTMAX 10000 /* maximum source statement length */
@ -91,6 +92,7 @@ enum {
FILENAME = 7,
INCLUDES = 8
};
#define FIELDS 10
// XXX

View File

@ -47,19 +47,19 @@
/* convert long to a string in base BASE notation */
#define ltobase(value) \
do { \
do { \
n = (value); \
s = buf + (sizeof(buf) - 1); \
*s = '\0'; \
digits = 1; \
while (n >= BASE) { \
while(n >= BASE) { \
++digits; \
i = n; \
n /= BASE; \
*--s = i - n * BASE + '!'; \
} \
*--s = n + '!'; \
} while (0)
} while(0)
#define SYMBOLINC 20 /* symbol list size increment */
@ -88,17 +88,14 @@ static struct symbol *symbol;
static void putcrossref(void);
static void savesymbol(int token, int num);
void
crossref(char *srcfile)
{
void crossref(char *srcfile) {
unsigned int i;
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))) {
if(!((stat(srcfile, &st) == 0) && S_ISREG(st.st_mode))) {
cannotopen(srcfile);
errorsfound = true;
return;
@ -106,7 +103,7 @@ crossref(char *srcfile)
entry_no = 0;
/* open the source file */
if ((yyin = myfopen(srcfile, "r")) == NULL) {
if((yyin = myfopen(srcfile, "r")) == NULL) {
cannotopen(srcfile);
errorsfound = true;
return;
@ -120,43 +117,37 @@ crossref(char *srcfile)
initscanner(srcfile);
fcnoffset = macrooffset = 0;
symbols = 0;
if (symbol == NULL) {
symbol = malloc(msymbols * sizeof(*symbol));
}
for (;;) {
if(symbol == NULL) { symbol = malloc(msymbols * sizeof(*symbol)); }
for(;;) {
/* get the next token */
switch (token = yylex()) {
switch(token = yylex()) {
default:
/* if requested, truncate C symbols */
length = last - first;
if (trun_syms == true && length > 8 &&
token != INCLUDE && token != NEWFILE) {
if(trun_syms == true && length > 8 && token != INCLUDE &&
token != NEWFILE) {
length = 8;
last = first + 8;
}
/* see if the token has a symbol */
if (length == 0) {
if(length == 0) {
savesymbol(token, entry_no);
break;
}
/* update entry_no if see function entry */
if (token == FCNDEF) {
entry_no++;
}
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() */
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 */
if(i == symbols) { /* if not already in list */
savesymbol(token, entry_no);
}
break;
@ -170,8 +161,7 @@ crossref(char *srcfile)
lineno = myylineno; /* save the symbol line number */
#ifndef USING_LEX
/* HBB 20010425: replaced yyleng-- by this chunk: */
if (my_yytext)
*my_yytext = '\0';
if(my_yytext) *my_yytext = '\0';
my_yyleng = 0;
#endif
break;
@ -180,10 +170,8 @@ crossref(char *srcfile)
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 */
if(symbols > 0) { putcrossref(); }
(void)fclose(yyin); /* close the source file */
/* output the leading tab expected by the next call */
dbputc('\t');
@ -194,11 +182,9 @@ crossref(char *srcfile)
/* save the symbol in the list */
static void
savesymbol(int token, int num)
{
static void savesymbol(int token, int num) {
/* make sure there is room for the symbol */
if (symbols == msymbols) {
if(symbols == msymbols) {
msymbols += SYMBOLINC;
symbol = realloc(symbol, msymbols * sizeof(*symbol));
}
@ -213,28 +199,22 @@ savesymbol(int token, int num)
/* output the file name */
void
putfilename(char *srcfile)
{
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) {
if(putc(NEWFILE, newrefs) == EOF) {
cannotwrite(newreffile);
/* NOTREACHED */
}
++dboffset;
if (invertedindex == true) {
srcoffset[nsrcoffset++] = dboffset;
}
if(invertedindex == true) { srcoffset[nsrcoffset++] = dboffset; }
dbfputs(srcfile);
fcnoffset = macrooffset = 0;
}
/* output the symbols and source line */
static void
putcrossref(void)
{
static void putcrossref(void) {
unsigned int i, j;
unsigned char c;
bool blank; /* blank indicator */
@ -252,23 +232,23 @@ putcrossref(void)
my_yytext[my_yyleng] = '\0';
blank = false;
for (i = 0; i < my_yyleng; ++i) {
for(i = 0; i < my_yyleng; ++i) {
/* change a tab to a blank and compress blanks */
if ((c = my_yytext[i]) == ' ' || c == '\t') {
if((c = my_yytext[i]) == ' ' || c == '\t') {
blank = true;
} else if (symput < symbols && i == symbol[symput].first) {
} else if(symput < symbols && i == symbol[symput].first) {
/* look for the start of a symbol */
/* check for compressed blanks */
if (blank == true) {
if(blank == true) {
blank = false;
dbputc(' ');
}
dbputc('\n'); /* symbols start on a new line */
/* output any symbol type */
if ((type = symbol[symput].type) != IDENT) {
if((type = symbol[symput].type) != IDENT) {
dbputc('\t');
dbputc(type);
} else {
@ -278,9 +258,7 @@ putcrossref(void)
j = symbol[symput].last;
c = my_yytext[j];
my_yytext[j] = '\0';
if (invertedindex == true) {
putposting(my_yytext + i, type);
}
if(invertedindex == true) { putposting(my_yytext + i, type); }
writestring(my_yytext + i);
dbputc('\n');
my_yytext[j] = c;
@ -289,14 +267,13 @@ putcrossref(void)
} else {
/* HBB: try to save some time by early-out handling of
* non-compressed mode */
if (compress == false) {
if (blank == true) {
if(compress == false) {
if(blank == true) {
dbputc(' ');
blank = false;
}
j = i + strcspn(my_yytext+i, "\t ");
if (symput < symbols
&& j >= symbol[symput].first)
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';
@ -308,47 +285,43 @@ putcrossref(void)
}
/* check for compressed blanks */
if (blank == true) {
if (dicode2[c]) {
if(blank == true) {
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) {
} 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);
dbputc((int)c);
blank = false;
/* skip compressed characters */
if (c < ' ') {
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') {
while((j = my_yytext[i]) == ' ' || j == '\t') {
++i;
}
/* skip the rest of the keyword */
while (isalpha((unsigned char)my_yytext[i])) {
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') {
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;
}
if(keyword[c].delim == '(' && my_yytext[i] == '(') { ++i; }
--i; /* compensate for ++i in for() */
} /* if compressed char */
} /* else: not a symbol */
@ -361,7 +334,7 @@ putcrossref(void)
/* output any #define end marker */
/* 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) {
if(symput < symbols && symbol[symput].type == DEFINEEND) {
dbputc('\t');
dbputc(DEFINEEND);
dbputc('\n');
@ -373,20 +346,15 @@ putcrossref(void)
/* HBB 20000421: new function, for avoiding memory leaks */
/* free the cross reference symbol table */
void
freecrossref()
{
if (symbol)
free(symbol);
void freecrossref() {
if(symbol) free(symbol);
symbol = NULL;
symbols = 0;
}
/* output the inverted index posting */
void
putposting(char *term, int type)
{
void putposting(char *term, int type) {
long i, n;
char *s;
int digits; /* digits output */
@ -395,11 +363,9 @@ putposting(char *term, int type)
/* get the function or macro name offset */
offset = fcnoffset;
if (macrooffset != 0) {
offset = macrooffset;
}
if(macrooffset != 0) { offset = macrooffset; }
/* then update them to avoid negative relative name offset */
switch (type) {
switch(type) {
case DEFINE:
macrooffset = dboffset;
break;
@ -414,41 +380,37 @@ putposting(char *term, int type)
return; /* null term */
}
/* ignore a null term caused by a enum/struct/union without a tag */
if (*term == '\0') {
return;
}
if(*term == '\0') { return; }
/* skip any #include secondary type char (< or ") */
if (type == INCLUDE) {
++term;
}
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);
(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);
for(i = PRECISION - digits; i > 0; --i) {
(void)putc('!', postings);
}
do {
(void) putc(*s, postings);
} while (*++s != '\0');
(void)putc(*s, postings);
} while(*++s != '\0');
/* postings are also sorted by type */
(void) putc(type, postings);
(void)putc(type, postings);
/* function or macro name offset */
if (offset > 0) {
(void) putc(' ', postings);
if(offset > 0) {
(void)putc(' ', postings);
ltobase(offset);
do {
(void) putc(*s, postings);
} while (*++s != '\0');
(void)putc(*s, postings);
} while(*++s != '\0');
}
if (putc('\n', postings) == EOF) {
if(putc('\n', postings) == EOF) {
cannotwrite(temp1);
/* NOTREACHED */
}
@ -457,20 +419,18 @@ putposting(char *term, int type)
/* put the string into the new database */
void
writestring(char *s)
{
void writestring(char *s) {
unsigned char c;
int i;
if (compress == false) {
if(compress == false) {
/* 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]] */
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]);
@ -482,11 +442,12 @@ writestring(char *s)
/* print a warning message with the file name and line number */
void
warning(char *text)
{
void warning(char *text) {
(void) fprintf(stderr, PROGRAM_NAME ": \"%s\", line %d: warning: %s\n", filename,
myylineno, text);
(void)fprintf(stderr,
PROGRAM_NAME ": \"%s\", line %d: warning: %s\n",
filename,
myylineno,
text);
errorsfound = true;
}

366
src/dir.c
View File

@ -52,7 +52,7 @@
#define SRCINC HASHMOD /* source file list size increment */
/* largest known database had 22049 files */
char currentdir[PATHLEN + 1];/* current directory */
char currentdir[PATHLEN + 1]; /* current directory */
char **incdirs; /* #include directories */
char **srcdirs; /* source directories */
char **srcfiles; /* source files */
@ -79,26 +79,21 @@ static void addincdir(char *name, char *path);
static void scan_dir(const char *dirfile, bool recurse);
static void makevpsrcdirs(void);
/* make the view source directory list */
static void
makevpsrcdirs(void)
{
static void makevpsrcdirs(void) {
int i;
/* return if this function has already been called */
if (nsrcdirs > 0) {
return;
}
if(nsrcdirs > 0) { return; }
/* get the current directory name */
if (getcwd(currentdir, PATHLEN) == NULL) {
if(getcwd(currentdir, PATHLEN) == NULL) {
fprintf(stderr, PROGRAM_NAME ": warning: cannot get current directory name\n");
strcpy(currentdir, "<unknown>");
}
/* see if there is a view path and this directory is in it */
vpinit(currentdir);
if (vpndirs > 1) {
if(vpndirs > 1) {
nsrcdirs = vpndirs;
} else {
nsrcdirs = 1;
@ -107,7 +102,7 @@ makevpsrcdirs(void)
msrcdirs = nsrcdirs + DIRINC;
srcdirs = malloc(msrcdirs * sizeof(*srcdirs));
*srcdirs = "."; /* first source dir is always current dir */
for (i = 1; i < vpndirs; ++i) {
for(i = 1; i < vpndirs; ++i) {
srcdirs[i] = vpdirs[i];
}
/* save the number of original source directories in the view path */
@ -116,9 +111,7 @@ makevpsrcdirs(void)
/* add a source directory to the list for each view path source directory */
void
sourcedir(char *dirlist)
{
void sourcedir(char *dirlist) {
char path[PATHLEN + 1];
char *dir;
unsigned int i;
@ -128,20 +121,23 @@ sourcedir(char *dirlist)
/* parse the directory list */
dir = strtok(dirlist, DIRSEPS);
while (dir != NULL) {
while(dir != NULL) {
int dir_len = strlen(dir);
addsrcdir(dir);
/* if it isn't a full path name and there is a
multi-directory view path */
if (*dirlist != '/' && vpndirs > 1) {
if(*dirlist != '/' && vpndirs > 1) {
/* compute its path from higher view path source dirs */
for (i = 1; i < nvpsrcdirs; ++i) {
snprintf(path, sizeof(path), "%.*s/%s",
for(i = 1; i < nvpsrcdirs; ++i) {
snprintf(path,
sizeof(path),
"%.*s/%s",
PATHLEN - 2 - dir_len,
srcdirs[i], dir);
srcdirs[i],
dir);
addsrcdir(path);
}
}
@ -152,17 +148,14 @@ sourcedir(char *dirlist)
/* add a source directory to the list */
static void
addsrcdir(char *dir)
{
static void addsrcdir(char *dir) {
struct stat statstruct;
/* make sure it is a directory */
if (lstat(compath(dir), &statstruct) == 0 &&
S_ISDIR(statstruct.st_mode)) {
if(lstat(compath(dir), &statstruct) == 0 && S_ISDIR(statstruct.st_mode)) {
/* note: there already is a source directory list */
if (nsrcdirs == msrcdirs) {
if(nsrcdirs == msrcdirs) {
msrcdirs += DIRINC;
srcdirs = realloc(srcdirs, msrcdirs * sizeof(*srcdirs));
}
@ -172,21 +165,16 @@ addsrcdir(char *dir)
/* HBB 20000421: new function, for avoiding leaks */
/* free list of src directories */
void
freesrclist()
{
if (!srcdirs)
return;
while(nsrcdirs>1)
void freesrclist() {
if(!srcdirs) return;
while(nsrcdirs > 1)
free(srcdirs[--nsrcdirs]);
free(srcdirs);
}
/* add a #include directory to the list for each view path source directory */
void
includedir(char *dirlist)
{
void includedir(char *dirlist) {
char path[PATHLEN + 1];
char *dir;
unsigned int i;
@ -196,20 +184,23 @@ includedir(char *dirlist)
/* parse the directory list */
dir = strtok(dirlist, DIRSEPS);
while (dir != NULL) {
while(dir != NULL) {
size_t dir_len = strlen(dir);
addincdir(dir, dir);
/* if it isn't a full path name and there is a
multi-directory view path */
if (*dirlist != '/' && vpndirs > 1) {
if(*dirlist != '/' && vpndirs > 1) {
/* compute its path from higher view path source dirs */
for (i = 1; i < nvpsrcdirs; ++i) {
snprintf(path, sizeof(path), "%.*s/%s",
for(i = 1; i < nvpsrcdirs; ++i) {
snprintf(path,
sizeof(path),
"%.*s/%s",
(int)(PATHLEN - 2 - dir_len),
srcdirs[i], dir);
srcdirs[i],
dir);
addincdir(dir, path);
}
}
@ -220,18 +211,15 @@ includedir(char *dirlist)
/* add a #include directory to the list */
static void
addincdir(char *name, char *path)
{
static void addincdir(char *name, char *path) {
struct stat statstruct;
/* make sure it is a directory */
if (lstat(compath(path), &statstruct) == 0 &&
S_ISDIR(statstruct.st_mode)) {
if (incdirs == NULL) {
if(lstat(compath(path), &statstruct) == 0 && S_ISDIR(statstruct.st_mode)) {
if(incdirs == NULL) {
incdirs = malloc(mincdirs * sizeof(*incdirs));
incnames = malloc(mincdirs * sizeof(*incnames));
} else if (nincdirs == mincdirs) {
} else if(nincdirs == mincdirs) {
mincdirs += DIRINC;
incdirs = realloc(incdirs, mincdirs * sizeof(*incdirs));
incnames = realloc(incnames, mincdirs * sizeof(*incnames));
@ -244,12 +232,9 @@ addincdir(char *name, char *path)
/* HBB 2000421: new function, for avoiding memory leaks */
/* free the list of include files, if wanted */
void
freeinclist()
{
if (!incdirs)
return;
while(nincdirs>0) {
void freeinclist() {
if(!incdirs) return;
while(nincdirs > 0) {
free(incdirs[--nincdirs]);
free(incnames[nincdirs]);
}
@ -259,9 +244,7 @@ freeinclist()
/* make the source file list */
void
makefilelist(void)
{
void makefilelist(void) {
static bool firstbuild = true; /* first time through */
FILE *names; /* name file pointer */
char dir[PATHLEN + 1];
@ -274,17 +257,16 @@ makefilelist(void)
makevpsrcdirs(); /* make the view source directory list */
/* if -i was falseT given and there are source file arguments */
if (namefile == NULL && fileargc > 0) {
if(namefile == NULL && fileargc > 0) {
/* put them in a list that can be expanded */
for (i = 0; i < fileargc; ++i) {
for(i = 0; i < fileargc; ++i) {
file = fileargv[i];
if (infilelist(file) == false) {
if ((s = inviewpath(file)) != NULL) {
if(infilelist(file) == false) {
if((s = inviewpath(file)) != NULL) {
addsrcfile(s);
} else {
fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n",
file);
fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n", file);
errorsfound = true;
}
}
@ -293,14 +275,12 @@ makefilelist(void)
}
/* see if a file name file exists */
if (namefile == NULL && vpaccess(NAMEFILE, READ) == 0) {
namefile = NAMEFILE;
}
if(namefile == NULL && vpaccess(NAMEFILE, READ) == 0) { namefile = NAMEFILE; }
if (namefile == NULL) {
if(namefile == NULL) {
/* No namefile --> make a list of all the source files
* in the directories */
for (i = 0; i < nsrcdirs; ++i) {
for(i = 0; i < nsrcdirs; ++i) {
scan_dir(srcdirs[i], recurse_dir);
}
return;
@ -308,42 +288,43 @@ makefilelist(void)
/* Came here --> there is a file of source file names */
if (strcmp(namefile, "-") == 0)
if(strcmp(namefile, "-") == 0)
names = stdin;
else if ((names = vpfopen(namefile, "r")) == NULL) {
else if((names = vpfopen(namefile, "r")) == NULL) {
cannotopen(namefile);
myexit(1);
}
/* get the names in the file */
while (fgets(line, 10*PATHLEN, names) != NULL) {
while(fgets(line, 10 * PATHLEN, names) != NULL) {
char *point_in_line = line + (strlen(line) - 1);
size_t length_of_name = 0;
int unfinished_option = 0;
bool done = false;
/* Kill away \n left at end of fgets()'d string: */
if (*point_in_line == '\n')
*point_in_line = '\0';
if(*point_in_line == '\n') *point_in_line = '\0';
/* Parse whitespace-terminated strings in line: */
point_in_line = line;
while (sscanf(point_in_line, "%" PATHLEN_STR "s", path) == 1) {
while(sscanf(point_in_line, "%" PATHLEN_STR "s", path) == 1) {
/* Have to store this length --- inviewpath() will
* modify path, later! */
length_of_name = strlen(path);
if (*path == '-') { /* if an option */
if (unfinished_option) {
if(*path == '-') { /* if an option */
if(unfinished_option) {
/* Can't have another option directly after an
* -I or -p option with no name after it! */
fprintf(stderr, PROGRAM_NAME ": Syntax error in namelist file %s: unfinished -I or -p option\n",
fprintf(stderr,
PROGRAM_NAME
": Syntax error in namelist file %s: unfinished -I or -p option\n",
namefile);
unfinished_option = 0;
}
i = path[1];
switch (i) {
switch(i) {
case 'c': /* ASCII characters only in crossref */
compress = false;
break;
@ -360,7 +341,7 @@ makefilelist(void)
case 'p': /* file path components to display */
/* coverity[overwrite_var] */
s = path + 2; /* for "-Ipath" */
if (*s == '\0') { /* if "-I path" */
if(*s == '\0') { /* if "-I path" */
unfinished_option = i;
break;
}
@ -369,9 +350,9 @@ makefilelist(void)
* --> make it a macro to avoid unnecessary
* duplication */
#define HANDLE_OPTION_ARGUMENT(i, s) \
switch (i) { \
switch(i) { \
case 'I': /* #include file directory */ \
if (firstbuild == true) { \
if(firstbuild == true) { \
/* expand $ and ~ */ \
shellpath(dir, sizeof(dir), (s)); \
includedir(dir); \
@ -380,8 +361,9 @@ makefilelist(void)
done = true; \
break; \
case 'p': /* file path components to display */ \
if (*(s) < '0' || *(s) > '9') { \
fprintf(stderr, "csope: -p option in file %s: missing or invalid numeric value\n", \
if(*(s) < '0' || *(s) > '9') { \
fprintf(stderr, \
"csope: -p option in file %s: missing or invalid numeric value\n", \
namefile); \
} \
dispcomponents = atoi(s); \
@ -396,26 +378,27 @@ makefilelist(void)
HANDLE_OPTION_ARGUMENT(i, s)
break;
default:
fprintf(stderr, PROGRAM_NAME ": only -I, -c, -k, -p, and -T options can be in file %s\n",
fprintf(stderr,
PROGRAM_NAME
": only -I, -c, -k, -p, and -T options can be in file %s\n",
namefile);
} /* switch(i) */
} /* if('-') */
else if (*path == '"') {
else if(*path == '"') {
/* handle quoted filenames... */
size_t in = 1, out = 0;
char *newpath = malloc(PATHLEN + 1);
while (in < PATHLEN && point_in_line[in] != '\0') {
if (point_in_line[in] == '"') {
while(in < PATHLEN && point_in_line[in] != '\0') {
if(point_in_line[in] == '"') {
newpath[out] = '\0';
/* Tell outer loop to skip over this entire
* quoted string */
length_of_name = in + 1;
break; /* found end of quoted string */
} else if (point_in_line[in] == '\\'
&& in < PATHLEN - 1
&& (point_in_line[in + 1]== '"'
|| point_in_line[in + 1] == '\\')) {
} else if(point_in_line[in] == '\\' && in < PATHLEN - 1 &&
(point_in_line[in + 1] == '"' ||
point_in_line[in + 1] == '\\')) {
/* un-escape \" or \\ sequence */
newpath[out++] = point_in_line[in + 1];
in += 2;
@ -423,20 +406,19 @@ makefilelist(void)
newpath[out++] = point_in_line[in++];
}
} /* while(in) */
if (in >= PATHLEN) { /* safeguard against almost-overflow */
newpath[out]='\0';
if(in >= PATHLEN) { /* safeguard against almost-overflow */
newpath[out] = '\0';
}
/* If an -I or -p arguments was missing before,
* treat this name as the argument: */
HANDLE_OPTION_ARGUMENT(unfinished_option, newpath);
if (! done) {
if(!done) {
/* coverity[overwrite_var] */
if ((s = inviewpath(newpath)) != NULL) {
if((s = inviewpath(newpath)) != NULL) {
addsrcfile(s);
} else {
fprintf(stderr, PROGRAM_NAME, ": cannot find file %s\n",
newpath);
fprintf(stderr, PROGRAM_NAME, ": cannot find file %s\n", newpath);
errorsfound = true;
}
}
@ -448,61 +430,57 @@ makefilelist(void)
/* If an -I or -p arguments was missing before,
* treat this name as the argument: */
HANDLE_OPTION_ARGUMENT(unfinished_option, path);
if (!done) {
if ((s = inviewpath(path)) != NULL) {
if(!done) {
if((s = inviewpath(path)) != NULL) {
addsrcfile(s);
} else {
fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n",
path);
fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n", path);
errorsfound = true;
}
}
} /* else(ordinary name) */
point_in_line += length_of_name;
while (isspace((unsigned char) *point_in_line))
point_in_line ++;
while(isspace((unsigned char)*point_in_line))
point_in_line++;
} /* while(sscanf(line)) */
} /* while(fgets(line)) */
if (names == stdin)
if(names == stdin)
clearerr(stdin);
else
fclose(names);
firstbuild = false;
return;
}
/* scan a directory (recursively?) for source files */
static void
scan_dir(const char *adir, bool recurse_dir)
{
static void scan_dir(const char *adir, bool recurse_dir) {
DIR *dirfile;
int adir_len = strlen(adir);
/* FIXME: no guards against adir_len > PATHLEN, yet */
if ((dirfile = opendir(adir)) != NULL) {
if((dirfile = opendir(adir)) != NULL) {
struct dirent *entry;
char path[PATHLEN + 1];
while ((entry = readdir(dirfile)) != NULL) {
if ((strcmp(".",entry->d_name) != 0)
&& (strcmp("..",entry->d_name) != 0)) {
while((entry = readdir(dirfile)) != NULL) {
if((strcmp(".", entry->d_name) != 0) && (strcmp("..", entry->d_name) != 0)) {
struct stat buf;
snprintf(path, sizeof(path), "%s/%.*s", adir,
snprintf(path,
sizeof(path),
"%s/%.*s",
adir,
PATHLEN - 2 - adir_len,
entry->d_name);
if (lstat(path,&buf) == 0) {
if (recurse_dir
&& S_ISDIR(buf.st_mode) ) {
if(lstat(path, &buf) == 0) {
if(recurse_dir && S_ISDIR(buf.st_mode)) {
scan_dir(path, recurse_dir);
} else if (issrcfile(path)
&& infilelist(path) == false
&& access(path, R_OK) == 0) {
} else if(issrcfile(path) && infilelist(path) == false &&
access(path, R_OK) == 0) {
addsrcfile(path);
}
}
@ -513,31 +491,27 @@ scan_dir(const char *adir, bool recurse_dir)
return;
}
/* see if this is a source file */
static bool
issrcfile(char *path)
{
static bool issrcfile(char *path) {
struct stat statstruct;
char *file = basename(path);
char *s = strrchr(file, '.');
bool looks_like_source = false;
/* ensure there is some file suffix */
if (s == NULL || *++s == '\0')
return false;
if(s == NULL || *++s == '\0') return false;
/* if an SCCS or versioned file */
if (file[1] == '.' && file + 2 != s) { /* 1 character prefix */
switch (*file) {
if(file[1] == '.' && file + 2 != s) { /* 1 character prefix */
switch(*file) {
case 's':
case 'S':
return(false);
return (false);
}
}
if (s[1] == '\0') { /* 1 character suffix */
switch (*s) {
if(s[1] == '\0') { /* 1 character suffix */
switch(*s) {
case 'c':
case 'h':
case 'l':
@ -548,10 +522,9 @@ issrcfile(char *path)
case 'L':
looks_like_source = true;
}
} else if ((s[2] == '\0') /* 2 char suffix */
} else if((s[2] == '\0') /* 2 char suffix */
&& ((s[0] == 'b' && s[1] == 'p') /* breakpoint listing */
|| (s[0] == 'q'
&& (s[1] == 'c' || s[1] == 'h')) /* Ingres */
|| (s[0] == 'q' && (s[1] == 'c' || s[1] == 'h')) /* Ingres */
|| (s[0] == 's' && s[1] == 'd') /* SDL */
|| (s[0] == 'c' && s[1] == 'c') /* C++ source */
|| (s[0] == 'h' && s[1] == 'h'))) { /* C++ header */
@ -559,32 +532,24 @@ issrcfile(char *path)
} else if((s[3] == '\0') /* 3 char suffix */
/* C++ template source */
&& ((s[0] == 't' && s[1] == 'c' && s[2] == 'c' )
&& ((s[0] == 't' && s[1] == 'c' && s[2] == 'c')
/* C++ source: */
|| (s[0] == 'c' && s[1] == 'p' && s[2] == 'p' )
|| (s[0] == 'c' && s[1] == 'x' && s[2] == 'x' )
|| (s[0] == 'h' && s[1] == 'p' && s[2] == 'p' )
|| (s[0] == 'h' && s[1] == 'x' && s[2] == 'x' ))
) {
|| (s[0] == 'c' && s[1] == 'p' && s[2] == 'p') ||
(s[0] == 'c' && s[1] == 'x' && s[2] == 'x') ||
(s[0] == 'h' && s[1] == 'p' && s[2] == 'p') ||
(s[0] == 'h' && s[1] == 'x' && s[2] == 'x'))) {
looks_like_source = true;
}
if (looks_like_source != true)
return false;
if(looks_like_source != true) return false;
/* make sure it is a file */
if (lstat(path, &statstruct) == 0 &&
S_ISREG(statstruct.st_mode)) {
return(true);
}
if(lstat(path, &statstruct) == 0 && S_ISREG(statstruct.st_mode)) { return (true); }
return false;
}
/* add an include file to the source file list */
void
incfile(char *file, char *type)
{
void incfile(char *file, char *type) {
char name[PATHLEN + 1];
char path[PATHLEN + 1];
char *s;
@ -592,29 +557,31 @@ incfile(char *file, char *type)
assert(file != NULL); /* should never happen, but let's make sure anyway */
/* see if the file is already in the source file list */
if (infilelist(file) == true) {
return;
}
if(infilelist(file) == true) { return; }
/* look in current directory if it was #include "file" */
if (type[0] == '"' && (s = inviewpath(file)) != NULL) {
if(type[0] == '"' && (s = inviewpath(file)) != NULL) {
addsrcfile(s);
} else {
size_t file_len = strlen(file);
/* search for the file in the #include directory list */
for (i = 0; i < nincdirs; ++i) {
for(i = 0; i < nincdirs; ++i) {
/* don't include the file from two directories */
snprintf(name, sizeof(name), "%.*s/%s",
(int)(PATHLEN - 2 - file_len), incnames[i],
snprintf(name,
sizeof(name),
"%.*s/%s",
(int)(PATHLEN - 2 - file_len),
incnames[i],
file);
if (infilelist(name) == true) {
break;
}
if(infilelist(name) == true) { break; }
/* make sure it exists and is readable */
snprintf(path, sizeof(path), "%.*s/%s",
(int)(PATHLEN - 2 - file_len), incdirs[i],
snprintf(path,
sizeof(path),
"%.*s/%s",
(int)(PATHLEN - 2 - file_len),
incdirs[i],
file);
if (access(compath(path), READ) == 0) {
if(access(compath(path), READ) == 0) {
addsrcfile(path);
break;
}
@ -622,80 +589,62 @@ incfile(char *file, char *type)
}
}
/* see if the file is already in the list */
bool
infilelist(char *path)
{
bool infilelist(char *path) {
struct listitem *p;
for (p = srcnames[hash(compath(path)) % HASHMOD];
p != NULL;
p = p->next) {
if (strequal(path, p->text)) {
return(true);
for(p = srcnames[hash(compath(path)) % HASHMOD]; p != NULL; p = p->next) {
if(strequal(path, p->text)) { return (true); }
}
}
return(false);
return (false);
}
/* check if a file is readable enough to be allowed in the
* database */
static bool
accessible_file(char *file)
{
if (access(compath(file), READ) == 0) {
static bool accessible_file(char *file) {
if(access(compath(file), READ) == 0) {
struct stat stats;
if (lstat(file, &stats) == 0
&& S_ISREG(stats.st_mode)) {
return true;
}
if(lstat(file, &stats) == 0 && S_ISREG(stats.st_mode)) { return true; }
}
return false;
}
/* search for the file in the view path */
char *
inviewpath(char *file)
{
char *inviewpath(char *file) {
static char path[PATHLEN + 1];
unsigned int i;
/* look for the file */
if (accessible_file(file)) {
return(file);
}
if(accessible_file(file)) { return (file); }
/* if it isn't a full path name and there is a multi-directory
* view path */
if (*file != '/' && vpndirs > 1) {
if(*file != '/' && vpndirs > 1) {
int file_len = strlen(file);
/* compute its path from higher view path source dirs */
for (i = 1; i < nvpsrcdirs; ++i) {
snprintf(path, sizeof(path), "%.*s/%s",
PATHLEN - 2 - file_len, srcdirs[i],
for(i = 1; i < nvpsrcdirs; ++i) {
snprintf(path,
sizeof(path),
"%.*s/%s",
PATHLEN - 2 - file_len,
srcdirs[i],
file);
if (accessible_file(path)) {
return(path);
if(accessible_file(path)) { return (path); }
}
}
}
return(NULL);
return (NULL);
}
/* add a source file to the list */
void
addsrcfile(char *path)
{
void addsrcfile(char *path) {
struct listitem *p;
int i;
/* make sure there is room for the file */
if (nsrcfiles == msrcfiles) {
if(nsrcfiles == msrcfiles) {
msrcfiles += SRCINC;
srcfiles = realloc(srcfiles, msrcfiles * sizeof(*srcfiles));
}
@ -710,31 +659,28 @@ addsrcfile(char *path)
/* free the memory allocated for the source file list */
void
freefilelist(void)
{
void freefilelist(void) {
struct listitem *p, *nextp;
int i;
/* if '-d' option is used a string space block is allocated */
if (isuptodate == false) {
while (nsrcfiles > 0) {
free (srcfiles[--nsrcfiles]);
if(isuptodate == false) {
while(nsrcfiles > 0) {
free(srcfiles[--nsrcfiles]);
}
} else {
/* for '-d' option free the string space block */
/* protect against empty list */
if (nsrcfiles > 0)
free (srcfiles[0]);
if(nsrcfiles > 0) free(srcfiles[0]);
nsrcfiles = 0;
}
free (srcfiles); /* HBB 20000421: avoid leak */
free(srcfiles); /* HBB 20000421: avoid leak */
msrcfiles = 0;
srcfiles=0;
srcfiles = 0;
for (i = 0; i < HASHMOD; ++i) {
for (p = srcnames[i]; p != NULL; p = nextp) {
for(i = 0; i < HASHMOD; ++i) {
for(p = srcnames[i]; p != NULL; p = nextp) {
/* HBB 20000421: avoid memory leak */
free(p->text);
nextp = p->next;

View File

@ -40,9 +40,9 @@
#include "colors.h"
#ifdef CCS
#include "sgs.h" /* ESG_PKG and ESG_REL */
# include "sgs.h" /* ESG_PKG and ESG_REL */
#else
#include "version.h" /* FILEVERSION and FIXVERSION */
# include "version.h" /* FILEVERSION and FIXVERSION */
#endif
#include <ncurses.h>
@ -55,10 +55,10 @@
#define MSGLINE 0 /* message line */
#define MSGCOL 0 /* message column */
int subsystemlen = sizeof("Subsystem")-1; /* OGS subsystem name display field length */
int booklen = sizeof("Book")-1; /* OGS book name display field length */
int filelen = sizeof("File")-1; /* file name display field length */
int fcnlen = sizeof("Function")-1; /* function name display field length */
int subsystemlen = sizeof("Subsystem") - 1; /* OGS subsystem name display field length */
int booklen = sizeof("Book") - 1; /* OGS book name display field length */
int filelen = sizeof("File") - 1; /* file name display field length */
int fcnlen = sizeof("Function") - 1; /* function name display field length */
int numlen = 0; /* line number display field length */
int *displine; /* screen line of displayed reference */
@ -72,14 +72,12 @@ unsigned int totallines; /* total reference lines */
unsigned int curdispline = 0;
int current_page = 0;
int input_mode = INPUT_NORMAL;
const char* prompts[] = {
[INPUT_NORMAL] = "$ ",
const char *prompts[] = {[INPUT_NORMAL] = "$ ",
[INPUT_APPEND] = "Append to file: ",
[INPUT_PIPE] = "Pipe to shell command: ",
[INPUT_READ] = "Read from file: ",
[INPUT_CHANGE_TO] = "To: ",
[INPUT_CHANGE] = "To: "
};
[INPUT_CHANGE] = "To: "};
unsigned int topline = 1; /* top line of page */
@ -90,15 +88,15 @@ extern const char tooltip_wresult[];
#define MAX(a, b) ((a) > (b) ? (a) : (b))
/* Selectable windows */
WINDOW* winput;
WINDOW* wmode;
WINDOW* wresult;
WINDOW* whelp;
WINDOW *winput;
WINDOW *wmode;
WINDOW *wresult;
WINDOW *whelp;
/* Non-Selectable windows */
WINDOW* wtooltip;
WINDOW *wtooltip;
/* Selected window pointer */
WINDOW** current_window;
static WINDOW** last_window;
WINDOW **current_window;
static WINDOW **last_window;
static int result_window_height;
static int second_col_width;
@ -120,16 +118,74 @@ static inline void display_results(void);
static inline void display_tooltip(void);
/* NOTE: It's declared like this because we dont need a terminating '\00'. */
static const char dispchars[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
int dispchar2int(const char c){
static const char dispchars[] = {'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z'};
int dispchar2int(const char c) {
const char fst = dispchars[0];
const char lst = dispchars[sizeof(dispchars)-1];
const char lst = dispchars[sizeof(dispchars) - 1];
int r = c - fst;
if(r < 0 || lst < r){ return -1; }
if(r < 0 || lst < r) { return -1; }
return r;
}
@ -139,24 +195,23 @@ struct { /* text of input fields */
char *text1;
char *text2;
} /* Paralel array to "field_searchers", indexed by "field" */
fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope display */
{"Find this", "C symbol"},
{"Find this", "global definition"},
fields[FIELDS + 1] = {
/* samuel has a search that is not part of the cscope display */
{"Find this", "C symbol" },
{"Find this", "global definition" },
{"Find", "functions called by this function"},
{"Find", "functions calling this function"},
{"Find this", "text string"},
{"Change this", "text string"},
{"Find this", "egrep pattern"},
{"Find this", "file"},
{"Find", "files #including this file"},
{"Find", "assignments to this symbol"},
{"Find all", "function definitions"}, /* samuel only */
{"Find", "functions calling this function" },
{"Find this", "text string" },
{"Change this", "text string" },
{"Find this", "egrep pattern" },
{"Find this", "file" },
{"Find", "files #including this file" },
{"Find", "assignments to this symbol" },
{"Find all", "function definitions" }, /* samuel only */
};
/* initialize display parameters */
void
dispinit(void)
{
void dispinit(void) {
/* initialize the curses display package */
initscr(); /* initialize the screen */
start_color();
@ -193,15 +248,14 @@ dispinit(void)
first_col_width = 48; // (((COLS - 2)%2 == 0) ? ((COLS-2)/2) : (((COLS-2)/2)+1));
second_col_width = COLS - 2 - 1 - first_col_width; //((COLS - 2) / 2) - 1;
mdisprefs = result_window_height - (WRESULT_TABLE_BODY_START + 1);
tooltip_width = MAX(MAX(strlen(tooltip_winput), strlen(tooltip_wmode)), strlen(tooltip_wresult));
tooltip_width =
MAX(MAX(strlen(tooltip_winput), strlen(tooltip_wmode)), strlen(tooltip_wresult));
if (mdisprefs <= 0) {
if(mdisprefs <= 0) {
postfatal(PROGRAM_NAME ": screen too small\n");
/* NOTREACHED */
}
if(mdisprefs > sizeof(dispchars)){
mdisprefs = sizeof(dispchars);
}
if(mdisprefs > sizeof(dispchars)) { mdisprefs = sizeof(dispchars); }
/* allocate the displayed line array */
displine = malloc(mdisprefs * sizeof(*displine));
@ -211,19 +265,17 @@ dispinit(void)
/* initialize windows */
winput = newwin(input_window_height, first_col_width, 1, 1);
wmode = newwin(mode_window_height, first_col_width, input_window_height+1 + 1, 1);
wmode = newwin(mode_window_height, first_col_width, input_window_height + 1 + 1, 1);
wresult = newwin(result_window_height, second_col_width, 1, first_col_width + 1 + 1);
whelp = newwin(LINES-2, COLS-2, 1, 1);
wtooltip = newwin(1, tooltip_width, LINES-1, COLS - (tooltip_width+4));
whelp = newwin(LINES - 2, COLS - 2, 1, 1);
wtooltip = newwin(1, tooltip_width, LINES - 1, COLS - (tooltip_width + 4));
refresh();
current_window = &winput;
}
/* enter curses mode */
void
entercurses(void)
{
void entercurses(void) {
incurses = true;
window_change = CH_ALL;
@ -233,16 +285,14 @@ entercurses(void)
curs_set(0);
clear(); /* clear the screen */
mouseinit(); /* initialize any mouse interface */
//drawscrollbar(topline, nextline);
// drawscrollbar(topline, nextline);
keypad(stdscr, TRUE); /* enable the keypad */
//fixkeypad(); /* fix for getch() intermittently returning garbage */
// fixkeypad(); /* fix for getch() intermittently returning garbage */
standend(); /* turn off reverse video */
}
/* exit curses mode */
void
exitcurses(void)
{
void exitcurses(void) {
/* clear the bottom line */
move(LINES - 1, 0);
clrtoeol();
@ -257,8 +307,9 @@ exitcurses(void)
fflush(stdout);
}
static inline void display_help(){
// XXX: this could be optimized by only overriding the buffer if theres an actual change
static inline void display_help() {
// XXX: this could be optimized by only overriding the buffer if theres an actual
// change
werase(whelp);
wmove(whelp, 0, 0);
wattron(whelp, COLOR_PAIR(COLOR_PAIR_HELP));
@ -271,7 +322,7 @@ static inline void display_help(){
do_press_any_key = true;
}
static inline void display_frame(const bool border_only){
static inline void display_frame(const bool border_only) {
wattron(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));
box(stdscr, 0, 0);
@ -284,23 +335,23 @@ static inline void display_frame(const bool border_only){
wprintw(stdscr, PROGRAM_NAME " version %d%s", FILEVERSION, FIXVERSION);
#endif
wmove(stdscr, 0, COLS - (int)sizeof("Case: XXX") - 4);
if(caseless){
if(caseless) {
waddstr(stdscr, "Case: ON");
}else{
} else {
waddstr(stdscr, "Case: OFF");
}
/* --- */
if(!border_only){
if(!border_only) {
/* Vertical line */
mvaddch(0, first_col_width + 1, ACS_TTEE);
for(int i = 0; i < LINES-2; i++){
mvaddch(i+1, first_col_width + 1, ACS_VLINE);
for(int i = 0; i < LINES - 2; i++) {
mvaddch(i + 1, first_col_width + 1, ACS_VLINE);
}
mvaddch(LINES-1, first_col_width + 1, ACS_BTEE);
mvaddch(LINES - 1, first_col_width + 1, ACS_BTEE);
/* Horizontal line */
wmove(stdscr, input_window_height + 1, 0);
addch(ACS_LTEE);
for(int i = 0; i < first_col_width; i++){
for(int i = 0; i < first_col_width; i++) {
addch(ACS_HLINE);
}
addch(ACS_RTEE);
@ -309,15 +360,17 @@ static inline void display_frame(const bool border_only){
wattroff(stdscr, COLOR_PAIR(COLOR_PAIR_FRAME));
}
static inline void display_mode(){
static inline void display_mode() {
werase(wmode);
for(int i = 0; i < FIELDS; ++i){
if(i == field){
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
for(int i = 0; i < FIELDS; ++i) {
if(i == field) {
wattron(wmode,
COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
wattroff(wmode, COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
}else{
wattroff(wmode,
COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
} else {
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2);
wattroff(wmode, COLOR_PAIR(COLOR_PAIR_FIELD));
@ -325,7 +378,7 @@ static inline void display_mode(){
}
}
static inline void display_command_field(){
static inline void display_command_field() {
werase(winput);
wattron(winput, COLOR_PAIR(COLOR_PAIR_PROMPT));
mvwaddstr(winput, 0, 0, prompts[input_mode]);
@ -334,7 +387,8 @@ static inline void display_command_field(){
display_cursor();
}
static inline void display_results(){
static inline void display_results() {
int i;
char *s;
int screenline; /* screen line number */
@ -359,7 +413,7 @@ static inline void display_results(){
werase(wresult);
/* --- Display the message --- */
if (totallines == 0) { // Its a real message
if(totallines == 0) { // Its a real message
wmove(wresult, MSGLINE, 0);
wclrtoeol(wresult);
wattron(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
@ -367,11 +421,15 @@ static inline void display_results(){
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_MESSAGE));
return;
}
if (input_mode == INPUT_CHANGE) { // Its a pattern
if(input_mode == INPUT_CHANGE) { // Its a pattern
snprintf(lastmsg, MSGLEN, "Change \"%s\" to \"%s\"", input_line, newpat);
} else {
snprintf(lastmsg, MSGLEN, "%c%s: %s", toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1, input_line);
snprintf(lastmsg,
MSGLEN,
"%c%s: %s",
toupper((unsigned char)fields[field].text2[0]),
fields[field].text2 + 1,
input_line);
}
wattron(wresult, COLOR_PAIR(COLOR_PAIR_PATTERN));
waddstr(wresult, lastmsg);
@ -380,19 +438,16 @@ static inline void display_results(){
/* --- Display the column headings --- */
wattron(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));
wmove(wresult, 2, 2);
if (ogs == true && field != FILENAME) {
if(ogs == true && field != FILENAME) {
wprintw(wresult, "%-*s ", subsystemlen, "Subsystem");
wprintw(wresult, "%-*s ", booklen, "Book");
}
if (dispcomponents > 0)
wprintw(wresult, "%-*s ", filelen, "File");
if(dispcomponents > 0) wprintw(wresult, "%-*s ", filelen, "File");
if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
wprintw(wresult, "%-*s ", fcnlen, "Function");
}
if (field != FILENAME) {
waddstr(wresult, "Line");
}
if(field != FILENAME) { waddstr(wresult, "Line"); }
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_TABLE_HEADER));
/* --- Display table entries --- */
@ -401,58 +456,54 @@ static inline void display_results(){
/* calculate the source text column */
/* NOTE: the +1s are column gaps */
srctxtw = second_col_width;
srctxtw -= 1+1; // dispchars
if (ogs == true) {
srctxtw -= subsystemlen+1 + booklen+1;
srctxtw -= 1 + 1; // dispchars
if(ogs == true) { srctxtw -= subsystemlen + 1 + booklen + 1; }
if(dispcomponents > 0) { srctxtw -= filelen + 1; }
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
srctxtw -= fcnlen + 1;
}
if (dispcomponents > 0) {
srctxtw -= filelen+1;
}
if (field == SYMBOL || field == CALLEDBY || field == CALLING) {
srctxtw -= fcnlen+1;
}
srctxtw -= numlen+1;
srctxtw -= numlen + 1;
/* decide where to list from */
{
int seekerr;
do{
do {
seekerr = seekpage(current_page);
}while(seekerr == -1 && current_page--);
} while(seekerr == -1 && current_page--);
}
/* until the max references have been displayed or
there is no more room */
for (disprefs = 0, screenline = WRESULT_TABLE_BODY_START;
disprefs < mdisprefs && screenline < (result_window_height-1);
++disprefs, ++screenline)
{
for(disprefs = 0, screenline = WRESULT_TABLE_BODY_START;
disprefs < mdisprefs && screenline < (result_window_height - 1);
++disprefs, ++screenline) {
attr_swp = (disprefs != curdispline) ? A_NORMAL : ATTRIBUTE_RESULT_SELECTED;
wattron(wresult, attr_swp);
/* read the reference line */
if (
fscanf(refsfound, "%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
if(fscanf(refsfound,
"%" PATHLEN_STR "s%" PATHLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR
"[^\n]",
file,
function,
linenum,
tempstring
)
<
4
){ break; }
tempstring) < 4) {
break;
}
++nextline;
displine[disprefs] = screenline;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_ID : COLOR_PAIR_TABLE_SELECTED_ID;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_ID :
COLOR_PAIR_TABLE_SELECTED_ID;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%c", dispchars[disprefs]);
wattroff(wresult, COLOR_PAIR(color_swp));
/* display any change mark */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_MARK : COLOR_PAIR_TABLE_SELECTED_MARK;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_MARK :
COLOR_PAIR_TABLE_SELECTED_MARK;
wattron(wresult, COLOR_PAIR(color_swp));
if (input_mode == INPUT_CHANGE && change[topref + disprefs]) {
if(input_mode == INPUT_CHANGE && change[topref + disprefs]) {
waddch(wresult, '>');
} else {
waddch(wresult, ' ');
@ -460,93 +511,95 @@ static inline void display_results(){
wattroff(wresult, COLOR_PAIR(color_swp));
/* display the file name */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FILE : COLOR_PAIR_TABLE_COL_SELECTED_FILE;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FILE :
COLOR_PAIR_TABLE_COL_SELECTED_FILE;
wattron(wresult, COLOR_PAIR(color_swp));
if (field == FILENAME) {
if(field == FILENAME) {
wprintw(wresult, "%-*s ", filelen, file);
} else {
/* if OGS, display the subsystem and book names */
if (ogs == true) {
if(ogs == true) {
ogsnames(file, &subsystem, &book);
wprintw(wresult, "%-*.*s ", subsystemlen, subsystemlen, subsystem);
wprintw(wresult, "%-*.*s ", booklen, booklen, book);
}
/* display the requested path components */
if (dispcomponents > 0) {
wprintw(wresult, "%-*.*s ", filelen, filelen,
if(dispcomponents > 0) {
wprintw(wresult,
"%-*.*s ",
filelen,
filelen,
pathcomponents(file, dispcomponents));
}
} /* else(field == FILENAME) */
wattroff(wresult, COLOR_PAIR(color_swp));
/* display the function name */
if(field == SYMBOL || field == CALLEDBY || field == CALLING){
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_FUNCTION : COLOR_PAIR_TABLE_COL_SELECTED_FUNCTION;
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
color_swp = (disprefs != curdispline) ?
COLOR_PAIR_TABLE_COL_FUNCTION :
COLOR_PAIR_TABLE_COL_SELECTED_FUNCTION;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%-*.*s ", fcnlen, fcnlen, function);
wattroff(wresult, COLOR_PAIR(color_swp));
}
if(field == FILENAME){
if(field == FILENAME) {
waddch(wresult, '\n'); /* go to next line */
continue;
}
/* display the line number */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_LINE : COLOR_PAIR_TABLE_COL_SELECTED_LINE;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_LINE :
COLOR_PAIR_TABLE_COL_SELECTED_LINE;
wattron(wresult, COLOR_PAIR(color_swp));
wprintw(wresult, "%*s ", numlen, linenum);
wattroff(wresult, COLOR_PAIR(color_swp));
/* there may be tabs in egrep output */
while((s = strchr(tempstring, '\t')) != NULL){
while((s = strchr(tempstring, '\t')) != NULL) {
*s = ' ';
}
/* display the source line */
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_TEXT : COLOR_PAIR_TABLE_COL_SELECTED_TEXT;
color_swp = (disprefs != curdispline) ? COLOR_PAIR_TABLE_COL_TEXT :
COLOR_PAIR_TABLE_COL_SELECTED_TEXT;
wattron(wresult, COLOR_PAIR(color_swp));
s = tempstring;
for (;;) {
for(;;) {
/* if the source line does not fit */
if ((i = strlen(s)) > srctxtw) {
if((i = strlen(s)) > srctxtw) {
/* find the nearest blank */
for (i = srctxtw; s[i] != ' ' && i > 0; --i) {
for(i = srctxtw; s[i] != ' ' && i > 0; --i) {
;
}
if (i == 0) {
i = srctxtw; /* no blank */
}
if(i == 0) { i = srctxtw; /* no blank */ }
}
/* print up to this point */
wprintw(wresult, "%.*s", i, s);
s += i;
/* if line didn't wrap around */
if (i < srctxtw) {
waddch(wresult, '\n'); /* go to next line */
}
if(i < srctxtw) { waddch(wresult, '\n'); /* go to next line */ }
/* skip blanks */
while (*s == ' ') {
while(*s == ' ') {
++s;
}
/* see if there is more text */
if (*s == '\0') {
break;
}
if(*s == '\0') { break; }
/* if the source line is too long */
if (++screenline > result_window_height) {
if(++screenline > result_window_height) {
/* if this is the first displayed line,
display what will fit on the screen */
if (topref == nextline-1) {
if(topref == nextline - 1) {
disprefs++;
/* break out of two loops */
goto endrefs;
}
/* erase the reference */
while (--screenline >= displine[disprefs]) {
while(--screenline >= displine[disprefs]) {
wmove(wresult, screenline, 0);
wclrtoeol(wresult);
}
@ -569,10 +622,9 @@ endrefs:
/* --- display pager message --- */
/* position cursor */
i = result_window_height - 1;
if (screenline < i) {
if(screenline < i) {
waddch(wresult, '\n');
}
else {
} else {
wmove(wresult, i, 0);
}
/**/
@ -580,17 +632,22 @@ endrefs:
/* check for more references */
i = totallines - nextline + 1;
bottomline = nextline;
if (i > 0) {
wprintw(wresult, "* Lines %d-%d of %d, %d more. *", topref, bottomline, totallines, i);
if(i > 0) {
wprintw(wresult,
"* Lines %d-%d of %d, %d more. *",
topref,
bottomline,
totallines,
i);
}
/* if this is the last page of references */
else if (current_page > 0 && nextline > totallines) {
else if(current_page > 0 && nextline > totallines) {
waddstr(wresult, "* End of results. *");
}
wattroff(wresult, COLOR_PAIR(COLOR_PAIR_PAGER_MSG));
}
static inline void display_cursor(void){
static inline void display_cursor(void) {
chtype i;
int yoffset = 0, xoffset = 0;
@ -602,49 +659,40 @@ static inline void display_cursor(void){
i |= A_REVERSE;
waddch(*current_window, i);
}
void
horswp_field(void){
if(current_window != &wresult){
if(totallines == 0){ return; }
if(current_window == &winput){
void horswp_field(void) {
if(current_window != &wresult) {
if(totallines == 0) { return; }
if(current_window == &winput) {
window_change |= CH_INPUT;
}else{
} else {
window_change |= CH_MODE;
}
last_window = current_window;
current_window = &wresult;
}else{
} else {
current_window = last_window;
if(current_window == &winput){
window_change |= CH_INPUT;
}
if(current_window == &winput) { window_change |= CH_INPUT; }
}
window_change |= CH_RESULT;
}
void
verswp_field(void){
if(current_window == &wresult){ return; }
void verswp_field(void) {
if(current_window == &wresult) { return; }
current_window = (current_window == &winput) ? &wmode : &winput;
window_change |= CH_INPUT | CH_MODE;
}
/* display search progress with default custom format */
void
progress(char *what, long current, long max)
{
void progress(char *what, long current, long max) {
static long start;
long now;
int i;
/* save the start time */
if (searchcount == 0) {
start = time(NULL);
}
if ((now = time(NULL)) - start >= 1)
{
if (linemode == false)
{
if(searchcount == 0) { start = time(NULL); }
if((now = time(NULL)) - start >= 1) {
if(linemode == false) {
wmove(wresult, MSGLINE, MSGCOL);
wclrtoeol(wresult);
waddstr(wresult, what);
@ -655,26 +703,21 @@ progress(char *what, long current, long max)
wmove(wresult, MSGLINE, COLS - strlen(lastmsg));
waddstr(wresult, lastmsg);
refresh();
}
else if (verbosemode == true)
{
} else if(verbosemode == true) {
snprintf(lastmsg, sizeof(lastmsg), "> %s %ld of %ld", what, current, max);
}
start = now;
if ((linemode == false) && (incurses == true))
{
if((linemode == false) && (incurses == true)) {
wmove(wresult, MSGLINE, MSGCOL);
i = (float)COLS * (float)current / (float)max;
standout();
for (; i > 0; i--)
for(; i > 0; i--)
waddch(wresult, inch());
standend();
refresh();
}
else
if(linemode == false || verbosemode == true){
} else if(linemode == false || verbosemode == true) {
postmsg(lastmsg);
}
}
@ -682,50 +725,40 @@ progress(char *what, long current, long max)
}
/* print error message on system call failure */
void
myperror(char *text)
{
void myperror(char *text) {
char *s;
s = strerror(errno);
(void) snprintf(lastmsg, sizeof(lastmsg), "%s: %s", text, s);
(void)snprintf(lastmsg, sizeof(lastmsg), "%s: %s", text, s);
postmsg(lastmsg);
}
/* postmsg clears the message line and prints the message */
void
postmsg(char *msg)
{
if (linemode == true || incurses == false) {
void postmsg(char *msg) {
if(linemode == true || incurses == false) {
printf("%s\n", msg);
fflush(stdout);
}
else {
} else {
window_change |= CH_RESULT;
}
UNUSED(strncpy(lastmsg, msg, sizeof(lastmsg) - 1));
}
/* clearmsg2 clears the second message line */
void
clearmsg2(void)
{
if (linemode == false) {
void clearmsg2(void) {
if(linemode == false) {
wmove(wresult, MSGLINE + 1, 0);
wclrtoeol(wresult);
}
}
/* postmsg2 clears the second message line and prints the message */
void
postmsg2(char *msg)
{
if (linemode == true) {
(void) printf("%s\n", msg);
}
else {
void postmsg2(char *msg) {
if(linemode == true) {
(void)printf("%s\n", msg);
} else {
clearmsg2();
waddstr(wresult, msg);
wrefresh(wresult);
@ -733,17 +766,14 @@ postmsg2(char *msg)
}
/* display an error mesg - stdout or on second msg line */
void
posterr(char *msg, ...)
{
void posterr(char *msg, ...) {
va_list ap;
char errbuf[MSGLEN];
va_start(ap, msg);
if (linemode == true || incurses == false)
{
(void) vfprintf(stderr, msg, ap);
(void) fputc('\n', stderr);
if(linemode == true || incurses == false) {
(void)vfprintf(stderr, msg, ap);
(void)fputc('\n', stderr);
} else {
vsnprintf(errbuf, sizeof(errbuf), msg, ap);
postmsg2(errbuf);
@ -752,45 +782,37 @@ posterr(char *msg, ...)
}
/* display a fatal error mesg -- stderr *after* shutting down curses */
void
postfatal(const char *msg, ...)
{
void postfatal(const char *msg, ...) {
va_list ap;
char errbuf[MSGLEN];
va_start(ap, msg);
vsnprintf(errbuf, sizeof(errbuf), msg, ap);
/* restore the terminal to its original mode */
if (incurses == true) {
exitcurses();
}
if(incurses == true) { exitcurses(); }
/* display fatal error messages */
fprintf(stderr,"%s",errbuf);
fprintf(stderr, "%s", errbuf);
/* shut down */
myexit(1);
}
/* get the OGS subsystem and book names */
void
ogsnames(char *file, char **subsystem, char **book)
{
void ogsnames(char *file, char **subsystem, char **book) {
static char buf[PATHLEN + 1];
char *s, *slash;
*subsystem = *book = "";
(void) strcpy(buf,file);
(void)strcpy(buf, file);
s = buf;
if (*s == '/') {
++s;
}
while ((slash = strchr(s, '/')) != NULL) {
if(*s == '/') { ++s; }
while((slash = strchr(s, '/')) != NULL) {
*slash = '\0';
if ((int)strlen(s) >= 3 && strncmp(slash - 3, ".ss", 3) == 0) {
if((int)strlen(s) >= 3 && strncmp(slash - 3, ".ss", 3) == 0) {
*subsystem = s;
s = slash + 1;
if ((slash = strchr(s, '/')) != NULL) {
if((slash = strchr(s, '/')) != NULL) {
*book = s;
*slash = '\0';
}
@ -800,33 +822,31 @@ ogsnames(char *file, char **subsystem, char **book)
}
}
static inline void display_tooltip(void){
static inline void display_tooltip(void) {
wmove(wtooltip, 0, 0);
const char* tooltip;
if(*current_window == winput){
const char *tooltip;
if(*current_window == winput) {
tooltip = tooltip_winput;
}else if(*current_window == wmode){
} else if(*current_window == wmode) {
tooltip = tooltip_wmode;
}else if(*current_window == wresult){
} else if(*current_window == wresult) {
tooltip = tooltip_wresult;
}
wattron(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
waddstr(wtooltip, tooltip);
// XXX: cheap hack
for(int i = 0; i < (tooltip_width-strlen(tooltip)); i++){
for(int i = 0; i < (tooltip_width - strlen(tooltip)); i++) {
waddch(wtooltip, ' ');
}
wattroff(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
}
void
display(void)
{
//drawscrollbar(topline, nextline); /* display the scrollbar */
static void* lstwin = NULL; /* for the tooltip (see below) */
void display(void) {
// drawscrollbar(topline, nextline); /* display the scrollbar */
static void *lstwin = NULL; /* for the tooltip (see below) */
if(window_change){
if(window_change == CH_HELP){
if(window_change) {
if(window_change == CH_HELP) {
display_frame(true);
display_help();
/* Do not display over the help msg and
@ -835,25 +855,17 @@ display(void)
window_change = CH_ALL;
return;
}
if(window_change == CH_ALL){
display_frame(false);
}
if(window_change == CH_ALL) { display_frame(false); }
/* As it stands the tooltip has to be redisplayed
* on every window change.
*/
if(lstwin != *current_window){
if(lstwin != *current_window) {
lstwin = *current_window;
display_tooltip();
}
if(window_change & CH_INPUT){
display_command_field();
}
if(window_change & CH_RESULT){
display_results();
}
if(window_change & CH_MODE){
display_mode();
}
if(window_change & CH_INPUT) { display_command_field(); }
if(window_change & CH_RESULT) { display_results(); }
if(window_change & CH_MODE) { display_mode(); }
refresh();
wrefresh(winput);

View File

@ -37,64 +37,55 @@
#include "global.h"
#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
#include <ncurses.h>
# include <ncurses.h>
#else
#include <curses.h>
# include <curses.h>
#endif
/* edit this displayed reference */
void
editref(int i)
{
void editref(int i) {
char file[PATHLEN + 1]; /* file name */
char linenum[NUMLEN + 1]; /* line number */
/* verify that there is a references found file */
if (refsfound == NULL) {
return;
}
if(refsfound == NULL) { return; }
/* get the selected line */
seekrelline(i);
/* get the file name and line number */
if (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s", file, linenum) == 2) {
if(fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s", file, linenum) == 2) {
edit(file, linenum);
}
}
/* edit all references */
void
editall(void)
{
void editall(void) {
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;
}
if(refsfound == NULL) { return; }
/* get the first line */
fseek(refsfound, 0, SEEK_SET);
/* get each file name and line number */
while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
while(
fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) ==
2) {
edit(file, linenum); /* edit it */
if (editallprompt == true) {
addstr("Type ^D to stop editing all lines, or any other character to continue: ");
if ((c = getch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
break;
}
if(editallprompt == true) {
addstr(
"Type ^D to stop editing all lines, or any other character to continue: ");
if((c = getch()) == EOF || c == ctrl('D') || c == ctrl('Z')) { break; }
}
}
}
/* call the editor */
void
edit(char *file, const char *const linenum)
{
void edit(char *file, const char *const linenum) {
const char *const editor_basename = basename(editor);
char msg[MSGLEN + 1]; /* message */
char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */
@ -109,39 +100,32 @@ edit(char *file, const char *const linenum)
* The way to get them to pause, is to pass in /dev/null too,
* imatating endless blank lines.
*/
const char* const shit_pagers[] = {
"page",
"more",
NULL
};
for(const char *const *sp = shit_pagers; *sp != NULL; sp++){
if(!strcmp(editor_basename, *sp)){
const char *const shit_pagers[] = {"page", "more", NULL};
for(const char *const *sp = shit_pagers; *sp != NULL; sp++) {
if(!strcmp(editor_basename, *sp)) {
execute(editor, editor, plusnum, file, "/dev/null", NULL);
goto end;
}
}
if (lineflagafterfile) {
if(lineflagafterfile) {
execute(editor, editor, file, plusnum, NULL);
}
else {
} else {
execute(editor, editor, plusnum, file, NULL);
}
end:
end:
clear(); /* redisplay screen */
}
/* if requested, prepend a path to a relative file name */
char *
filepath(char *file)
{
char *filepath(char *file) {
static char path[PATHLEN + 1];
if (prependpath != NULL && *file != '/') {
(void) snprintf(path, sizeof(path), "%s/%s", prependpath, file);
if(prependpath != NULL && *file != '/') {
(void)snprintf(path, sizeof(path), "%s/%s", prependpath, file);
file = path;
}
return(file);
return (file);
}

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@
private implementation details that can be changed or removed. */
#ifndef YY_YY_EGREP_H_INCLUDED
# define YY_YY_EGREP_H_INCLUDED
#define YY_YY_EGREP_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@ -48,8 +48,8 @@ extern int yydebug;
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
enum yytokentype {
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
@ -63,8 +63,8 @@ extern int yydebug;
STAR = 264, /* STAR */
PLUS = 265, /* PLUS */
QUEST = 266 /* QUEST */
};
typedef enum yytokentype yytoken_kind_t;
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Token kinds. */
#define YYEMPTY -2
@ -82,7 +82,7 @@ extern int yydebug;
#define QUEST 266
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
@ -92,7 +92,7 @@ typedef int YYSTYPE;
extern YYSTYPE yylval;
int yyparse (void);
int yyparse(void);
#endif /* !YY_YY_EGREP_H_INCLUDED */

View File

@ -41,7 +41,7 @@
#include <sys/wait.h>
#include <sys/types.h> /* pid_t */
#ifdef __DJGPP__
#include <process.h>
# include <process.h>
#endif
#include <ncurses.h>
@ -60,8 +60,7 @@ static pid_t myfork(void);
*/
/*VARARGS1*/
int
execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
int execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
{
va_list ap;
int exitcode = -1;
@ -74,17 +73,16 @@ execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
fflush(stdout);
va_start(ap, a);
for (p = 0; (argv[p] = va_arg(ap, char *)) != 0; p++){}
for(p = 0; (argv[p] = va_arg(ap, char *)) != 0; p++) { }
#ifdef __MSDOS__
/* HBB 20010313: in MSDOG, everything is completely different.
* No fork()/exec()/wait(), but rather a single libc call: */
exitcode = spawnvp(P_WAIT, a, argv);
#else
if ((p = myfork()) == 0) {
if((p = myfork()) == 0) {
myexecvp(a, argv); /* child */
}
else {
} else {
exitcode = join(p); /* parent */
}
#endif /* MSDOS */
@ -92,7 +90,7 @@ execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
entercurses();
va_end(ap);
return(exitcode);
return (exitcode);
}
#ifndef __MSDOS__ /* None of the following functions is used there */
@ -100,9 +98,7 @@ execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
/* myexecvp is an interface to the execvp system call to
* modify argv[0] to reference the last component of its path-name.
*/
static int
myexecvp(char *a, char **args)
{
static int myexecvp(char *a, char **args) {
char msg[MSGLEN + 1];
/* modify argv[0] to reference the last component of its path name */
@ -120,59 +116,53 @@ myexecvp(char *a, char **args)
/* myfork acts like fork but also handles signals */
static pid_t
myfork(void)
{
static pid_t myfork(void) {
pid_t p; /* process number */
p = fork();
/* the parent ignores the interrupt, quit, and hangup signals */
if (p > 0) {
if(p > 0) {
oldsigquit = signal(SIGQUIT, SIG_IGN);
oldsighup = signal(SIGHUP, SIG_IGN);
#ifdef SIGTSTP
# ifdef SIGTSTP
oldsigtstp = signal(SIGTSTP, SIG_DFL);
#endif
# endif
}
/* so they can be used to stop the child */
else if (p == 0) {
else if(p == 0) {
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
#ifdef SIGTSTP
# ifdef SIGTSTP
signal(SIGTSTP, SIG_DFL);
#endif
# endif
}
/* check for fork failure */
if (p == -1) {
myperror("Cannot fork");
}
if(p == -1) { myperror("Cannot fork"); }
return p;
}
/* join is the compliment of fork */
static int
join(pid_t p)
{
static int join(pid_t p) {
int status = -1;
pid_t w;
/* wait for the correct child to exit */
do {
w = wait(&status);
} while (p != -1 && w != p);
} while(p != -1 && w != p);
/* restore signal handling */
signal(SIGQUIT, oldsigquit);
signal(SIGHUP, oldsighup);
#ifdef SIGTSTP
# ifdef SIGTSTP
signal(SIGTSTP, oldsigtstp);
#endif
# endif
/* return the child's exit code */
return(status >> 8);
return (status >> 8);
}
#endif /* !MSDOS */

File diff suppressed because it is too large Load Diff

View File

@ -83,6 +83,7 @@ enum {
CH_HELP = 0x0001 << 3, /* do NOT add to CH_ALL */
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE
};
enum {
INPUT_NORMAL,
INPUT_APPEND,
@ -109,8 +110,7 @@ extern char dicode2[]; /* digraph second character code */
(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)] \
+ dicode2[(unsigned char)(inchar2)])
((0200 - 2) + dicode1[(unsigned char)(inchar1)] + dicode2[(unsigned char)(inchar2)])
#define PROGRAM_NAME "Csope"
@ -180,7 +180,8 @@ extern unsigned int mdisprefs; /* maximum displayed references */
extern unsigned int nextline; /* next line to be shown */
extern long searchcount; /* count of files searched */
extern unsigned int totallines; /* total reference lines */
extern int window_change; /* bitmask type to mark which windows have to be rerendered by display() */
extern int window_change; /* bitmask type to mark which windows have to be rerendered by
display() */
/* find.c global data */
extern char block[]; /* cross-reference file block */
@ -200,11 +201,11 @@ extern struct keystruct {
extern bool mouse; /* mouse interface */
/* readline.c global data */
extern char* rl_line_buffer;
extern char *rl_line_buffer;
extern char input_line[PATLEN + 1];
extern int rl_point;
//extern bool unixpcmouse; /* UNIX PC mouse interface */
// extern bool unixpcmouse; /* UNIX PC mouse interface */
/* cscope functions called from more than one function or between files */
@ -225,7 +226,7 @@ char *pathcomponents(char *path, int components);
char *read_block(void);
char *scanpast(char c);
char ** parse_options(int *argc, char **argv);
char **parse_options(int *argc, char **argv);
void error_usage(void);
void longusage(void);
void usage(void);
@ -234,7 +235,7 @@ extern bool onesearch; /* one search only in line mode */
extern char *reflines; /* symbol reference lines file */
extern bool do_press_any_key; /* wait for any key to continue */
extern int current_page;
#define topref current_page*mdisprefs
#define topref current_page *mdisprefs
void verswp_field(void);
void horswp_field(void);
bool interpret(int c); // XXX: probably rename
@ -242,7 +243,8 @@ int handle_input(const int c);
int dispchar2int(const char c);
int process_mouse();
extern int input_mode;
int changestring(const char* from, const char* to, const bool *const change, const int change_len);
int changestring(const char *from, const char *to, const bool *const change,
const int change_len);
long seekpage(const size_t i);
long seekrelline(unsigned i);
@ -273,7 +275,7 @@ void freesrclist(void);
void freeinclist(void);
void freecrossref(void);
void freefilelist(void);
const char* help(void);
const char *help(void);
void incfile(char *file, char *type);
void includedir(char *_dirname);
void initsymtab(void);
@ -289,8 +291,8 @@ 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 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);
@ -302,7 +304,7 @@ void writestring(char *s);
bool infilelist(char *file);
bool readrefs(char *filename);
bool search(const char* query);
bool search(const char *query);
bool writerefsfound(void);
int findinit(const char *pattern_);

View File

@ -45,7 +45,8 @@
const char tooltip_winput[] = "Search [Enter] -Mode [^k] +Mode [^j] Right [Tab] Down [%]";
const char tooltip_wmode[] = "-Mode [Up] +Mode [Down] Right [Tab] Up [%]";
const char tooltip_wresult[] = "Edit [Enter] Up [Up] Down [Down] Left [Tab] Previous [-] Next [+]";
const char tooltip_wresult[] =
"Edit [Enter] Up [Up] Down [Down] Left [Tab] Previous [-] Next [+]";
static char help_msg[] =
"Press the RETURN key repeatedly to move to the desired input field, type the\n"
@ -79,8 +80,7 @@ static char help_msg[] =
"^D\t\tExit the program.\n"
"\nNote: If the first character of the pattern you want to search for matches\n"
"a command, type a \\ character first.\n"
"Note: Some ctrl keys may be occupied by your terminal configuration.\n"
;
"Note: Some ctrl keys may be occupied by your terminal configuration.\n";
static char changeing_help_msg[] =
"When changing text, you can use these single-character commands:\n\n"
@ -94,13 +94,10 @@ static char changeing_help_msg[] =
"ESC\t\tExit without changing the marked lines.\n"
"!\t\tStart an interactive shell (type ^D to return).\n"
"^L\t\tRedraw the screen.\n"
"?\t\tDisplay this list of commands.\n"
;
"?\t\tDisplay this list of commands.\n";
const char*
help(void)
{
if (input_mode == INPUT_CHANGE) {
const char *help(void) {
if(input_mode == INPUT_CHANGE) {
return help_msg;
} else {
return changeing_help_msg;
@ -108,32 +105,25 @@ help(void)
}
/* error exit including short usage information */
void
error_usage(void)
{
void error_usage(void) {
usage();
fputs("Try the -h option for more information.\n", stderr);
myexit(1);
}
/* normal usage message */
void
usage(void)
{
fputs(
"Usage: " PROGRAM_NAME " [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]\n"
void usage(void) {
fputs("Usage: " PROGRAM_NAME
" [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]\n"
" [-p number] [-P path] [-[0-8] pattern] [source files]\n",
stderr
);
stderr);
}
/* long usage message */
void
longusage(void)
{
void longusage(void) {
usage();
fprintf(stderr, "\
fprintf(stderr,
"\
\n\
-b Build the cross-reference only.\n\
-C Ignore letter case when searching.\n\
@ -143,12 +133,14 @@ longusage(void)
-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, "\
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, "\
fprintf(stderr,
"\
-k Kernel Mode - don't use %s for #include files.\n",
DFLT_INCDIR);
fputs("\

View File

@ -42,13 +42,12 @@
static struct cmd *tail, *current;
/* add a cmd to the history list */
void
addcmd(int f, char *s) /* field number and command text */
void addcmd(int f, char *s) /* field number and command text */
{
struct cmd *h;
h = malloc(sizeof(struct cmd));
if( tail) {
if(tail) {
tail->next = h;
h->next = 0;
h->prev = tail;
@ -58,31 +57,27 @@ addcmd(int f, char *s) /* field number and command text */
h->next = h->prev = 0;
}
h->field = f;
h->text = strdup( s);
h->text = strdup(s);
current = 0;
}
/* return previous history item */
struct cmd *
prevcmd(void)
{
if( current) {
if( current->prev) /* stay on first item */
struct cmd *prevcmd(void) {
if(current) {
if(current->prev) /* stay on first item */
return current = current->prev;
else
return current;
} else if( tail)
} 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 */
struct cmd *nextcmd(void) {
if(current) {
if(current->next) /* stay on first item */
return current = current->next;
else
return current;
@ -91,14 +86,10 @@ nextcmd(void)
}
/* reset current to tail */
void
resetcmd(void)
{
void resetcmd(void) {
current = 0;
}
struct cmd *
currentcmd(void)
{
struct cmd *currentcmd(void) {
return current;
}

View File

@ -56,8 +56,7 @@ static void catchint(int sig);
/* catch the interrupt signal */
static void
catchint(int sig){
static void catchint(int sig) {
UNUSED(sig);
signal(SIGINT, catchint);
@ -65,61 +64,55 @@ catchint(int sig){
}
/* unget a character */
void
myungetch(int c)
{
void myungetch(int c) {
prevchar = c;
}
/* ask user to enter a character after reading the message */
void
askforchar(void){
void askforchar(void) {
addstr("Type any character to continue: ");
getch();
}
/* ask user to press the RETURN key after reading the message */
void
askforreturn(void){
void askforreturn(void) {
fprintf(stderr, "Press the RETURN key to continue: ");
getchar();
/* HBB 20060419: message probably messed up the screen --- redraw */
if (incurses == true) {
redrawwin(curscr);
}
if(incurses == true) { redrawwin(curscr); }
}
/* expand the ~ and $ shell meta characters in a path */
void
shellpath(char *out, int limit, char *in){
void shellpath(char *out, int limit, char *in) {
char *lastchar;
char *s, *v;
/* skip leading white space */
while (isspace((unsigned char)*in)) {
while(isspace((unsigned char)*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 == '~') {
if(*in == '~') {
*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)) {
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') {
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)) {
if(v != NULL && strlen(v) < (lastchar - out)) {
strcpy(out - 1, v);
out += strlen(v) - 1;
} else {
@ -128,22 +121,22 @@ shellpath(char *out, int limit, char *in){
}
}
/* get the rest of the path */
while (out < lastchar && *in != '\0' && !isspace((unsigned char)*in)) {
while(out < lastchar && *in != '\0' && !isspace((unsigned char)*in)) {
/* look for an environment variable */
if (*in == '$') {
if(*in == '$') {
*out++ = *in++; /* copy the $ because it may not be expanded */
/* get the variable name */
s = out;
while (s < lastchar && *in != '/' && *in != '\0' &&
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)) {
if((v = getenv(out)) != NULL && strlen(v) < (lastchar - out)) {
strcpy(out - 1, v);
out += strlen(v) - 1;
} else {
@ -151,17 +144,15 @@ shellpath(char *out, int limit, char *in){
* file name */
out += strlen(out);
}
}
else { /* ordinary character */
} else { /* ordinary character */
*out++ = *in++;
}
}
*out = '\0';
}
static int
wmode_input(const int c){
switch (c) {
static int wmode_input(const int c) {
switch(c) {
case KEY_ENTER:
case '\r':
case '\n':
@ -192,9 +183,8 @@ wmode_input(const int c){
return 1;
}
static int
wresult_input(const int c){
switch (c) {
static int wresult_input(const int c) {
switch(c) {
case KEY_ENTER: /* open for editing */
case '\r':
case '\n':
@ -204,16 +194,12 @@ wresult_input(const int c){
case ctrl('N'):
case KEY_DOWN:
case KEY_RIGHT:
if ((curdispline + 1) < disprefs) {
++curdispline;
}
if((curdispline + 1) < disprefs) { ++curdispline; }
break;
case ctrl('P'):
case KEY_UP:
case KEY_LEFT:
if (curdispline) {
--curdispline;
}
if(curdispline) { --curdispline; }
break;
case KEY_HOME:
curdispline = 0;
@ -223,20 +209,19 @@ wresult_input(const int c){
resetcmd();
break;
default:
if(c > mdisprefs){ goto noredisp; }
if(c > mdisprefs) { goto noredisp; }
const int pos = dispchar2int(c);
if(pos > -1){ editref(pos); }
if(pos > -1) { editref(pos); }
goto noredisp;
}
window_change |= CH_RESULT;
noredisp:
noredisp:
return 1;
}
static int
global_input(const int c){
switch(c){
static int global_input(const int c) {
switch(c) {
case '\t':
horswp_field();
break;
@ -256,9 +241,9 @@ global_input(const int c){
case ctrl('H'): /* display previous page */
case '-':
case KEY_PPAGE:
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
if(totallines == 0) { return 0; } /* don't redisplay if there are no lines */
curdispline = 0;
if(current_page > 0){
if(current_page > 0) {
--current_page;
window_change |= CH_RESULT;
}
@ -266,50 +251,44 @@ global_input(const int c){
case '+':
case ctrl('L'):
case KEY_NPAGE:
if (totallines == 0) { return 0; } /* don't redisplay if there are no lines */
if(totallines == 0) { return 0; } /* don't redisplay if there are no lines */
curdispline = 0;
++current_page;
window_change |= CH_RESULT;
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) {
// 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);
// }
// move(PRLINE, 0);
////addstr("Write to file: "); // XXX
//s = "w";
//if ((ch = getch()) == '>') {
//move(PRLINE, 0);
// s = "w";
// if ((ch = getch()) == '>') {
// 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);
//// }
////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();
break;
case '<': /* read lines from a file */
break; // XXX
//move(PRLINE, 0);
//addstr(readprompt); // XXX fix
//if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) {
// 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) {
@ -318,25 +297,25 @@ global_input(const int c){
// }
// window_change |= CH_INPUT;
// return(YES);
//}
//clearprompt();
// }
// clearprompt();
return 0;
case '|': /* pipe the lines to a shell command */
case '^':
break; // XXX fix
if (totallines == 0) {
if(totallines == 0) {
postmsg("There are no lines to pipe to a shell command");
return 0;
}
/* get the shell command */
//move(PRLINE, 0);
//addstr(pipeprompt);
//if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) {
// 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 == '^') {
// if (commandc == '^') {
// strcat(strcat(newpat, " >"), temp2);
// /* HBB 20020708: somebody might have even
// * their non-interactive default shells
@ -344,25 +323,26 @@ global_input(const int c){
// * 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 {
// }
// 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 (commandc == '^') {
// if (readrefs(temp2) == NO) {
// postmsg("Ignoring empty output of ^ command");
// }
//}
//askforreturn();
//entercurses();
// }
// askforreturn();
// entercurses();
break;
case '!': /* shell escape */
execute(shell, shell, NULL);
@ -393,13 +373,12 @@ extern const void *const wmode;
extern const void *const wresult;
extern const void *const *const current_window;
int
change_input(const int c){
int change_input(const int c) {
MOUSE *p; /* mouse data */
switch(c){
switch(c) {
case '*': /* invert page */
for(int i = 0; topref + i < nextline; i++){
for(int i = 0; topref + i < nextline; i++) {
change[topref + i] = !change[topref + i];
}
window_change |= CH_RESULT;
@ -411,12 +390,12 @@ change_input(const int c){
window_change |= CH_RESULT;
break;
case ctrl('X'): /* mouse selection */
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
if((p = getmouseaction(DUMMYCHAR)) == NULL) {
break; /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
//scrollbar(p);
if(p->button == '0') {
// scrollbar(p);
break;
}
/* find the selected line */
@ -424,9 +403,7 @@ change_input(const int c){
{
int i;
for(i = disprefs - 1; i > 0; --i) {
if (p->y1 >= displine[i]) {
break;
}
if(p->y1 >= displine[i]) { break; }
}
change[i] = !change[i];
}
@ -438,7 +415,7 @@ change_input(const int c){
{
/* if a line was selected */
const int cc = dispchar2int(c);
if(cc != -1){
if(cc != -1) {
change[cc] = !change[cc];
window_change |= CH_RESULT;
}
@ -448,12 +425,8 @@ change_input(const int c){
return 0;
}
int
changestring(const char* from,
const char* to,
const bool *const change,
const int change_len
){
int changestring(const char *from, const char *to, const bool *const change,
const int change_len) {
char newfile[PATHLEN + 1]; /* new file name */
char oldfile[PATHLEN + 1]; /* old file name */
char linenum[NUMLEN + 1]; /* file line number */
@ -462,44 +435,43 @@ changestring(const char* from,
/* Return early */
bool anymarked = false; /* any line marked */
for(int i = 0; i < change_len; i++){
if(change[i]){
for(int i = 0; i < change_len; i++) {
if(change[i]) {
anymarked = true;
break;
}
}
if(!anymarked){ return false; }
if(!anymarked) { return false; }
/* open the temporary file */
if((script = myfopen(temp2, "w")) == NULL) {
cannotopen(temp2);
return(false);
return (false);
}
/* for each line containing the old text */
fprintf(script, "ed - <<\\!\n");
*oldfile = '\0';
fseek(refsfound, 0, SEEK_SET);
for(int i = 0;
fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", newfile, linenum) == 2;
++i)
{
for(int i = 0; fscanf(refsfound,
"%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]",
newfile,
linenum) == 2;
++i) {
/* see if the line is to be changed */
if (!change[i]) { break; }
if(!change[i]) { break; }
/* if this is a new file */
if (strcmp(newfile, oldfile) != 0) {
if(strcmp(newfile, oldfile) != 0) {
/* make sure it can be changed */
if (access(newfile, WRITE) != 0) {
if(access(newfile, WRITE) != 0) {
snprintf(msg, sizeof(msg), "Cannot write to file %s", newfile);
postmsg(msg);
goto end;
}
/* if there was an old file */
if (*oldfile != '\0') {
fprintf(script, "w\n"); /* save it */
}
if(*oldfile != '\0') { fprintf(script, "w\n"); /* save it */ }
/* edit the new file */
strcpy(oldfile, newfile);
fprintf(script, "e %s\n", oldfile);
@ -508,10 +480,8 @@ changestring(const char* from,
fprintf(script, "%ss/", linenum); /* change */
for(const char *s = from; *s != '\0'; ++s) {
/* old text */
if (strchr("/\\[.^*", *s) != NULL) {
putc('\\', script);
}
if (caseless == true && isalpha((unsigned char)*s)) {
if(strchr("/\\[.^*", *s) != NULL) { putc('\\', script); }
if(caseless == true && isalpha((unsigned char)*s)) {
putc('[', script);
if(islower((unsigned char)*s)) {
putc(toupper((unsigned char)*s), script);
@ -527,9 +497,7 @@ changestring(const char* from,
}
putc('/', script); /* to */
for(const char *s = to; *s != '\0'; ++s) { /* new text */
if (strchr("/\\&", *s) != NULL) {
putc('\\', script);
}
if(strchr("/\\&", *s) != NULL) { putc('\\', script); }
putc(*s, script);
}
fprintf(script, "/gp\n"); /* and print */
@ -546,24 +514,23 @@ end:
return true;
}
int
handle_input(const int c){
int handle_input(const int c) {
/* - was wating for any input - */
if(do_press_any_key){
if(do_press_any_key) {
do_press_any_key = false;
return 0;
}
/* --- global --- */
const int r = global_input(c);
if(r){ return 0; }
if(r) { return 0; }
/* --- mode specific --- */
switch(input_mode){
switch(input_mode) {
case INPUT_NORMAL:
if(*current_window == winput){
if(*current_window == winput) {
return interpret(c);
}else if(*current_window == wmode){
} else if(*current_window == wmode) {
return wmode_input(c);
}else if(*current_window == wresult){
} else if(*current_window == wresult) {
return wresult_input(c);
}
assert("'current_window' dangling.");

File diff suppressed because it is too large Load Diff

View File

@ -39,15 +39,15 @@
/* inverted index definitions */
/* postings temporary file long number coding into characters */
#if CHAR_MAX==255
#if CHAR_MAX == 255
# 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 */
# 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
# error Need a platform with 8 bits in a char value
# endif
#endif

View File

@ -12,40 +12,40 @@
#define KEY_UNDEF_BASE 0
#ifndef KEY_DOWN
# define KEY_DOWN KEY_UNDEF_BASE-1
# define KEY_DOWN KEY_UNDEF_BASE - 1
#endif
#ifndef KEY_UP
# define KEY_UP KEY_UNDEF_BASE-2
# define KEY_UP KEY_UNDEF_BASE - 2
#endif
#ifndef KEY_LEFT
# define KEY_LEFT KEY_UNDEF_BASE-3
# define KEY_LEFT KEY_UNDEF_BASE - 3
#endif
#ifndef KEY_RIGHT
# define KEY_RIGHT KEY_UNDEF_BASE-4
# define KEY_RIGHT KEY_UNDEF_BASE - 4
#endif
#ifndef KEY_HOME
# define KEY_HOME _KEY_UNDEF_BASE-5
# 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
# define KEY_PPAGE KEY_UNDEF_BASE - 7
#endif
#ifndef KEY_NPAGE
# define KEY_NPAGE KEY_UNDEF_BASE-8
# define KEY_NPAGE KEY_UNDEF_BASE - 8
#endif
#ifndef KEY_ENTER
# define KEY_ENTER KEY_UNDEF_BASE-9
# define KEY_ENTER KEY_UNDEF_BASE - 9
#endif
#ifndef KEY_CLEAR
# define KEY_CLEAR KEY_UNDEF_BASE-10
# define KEY_CLEAR KEY_UNDEF_BASE - 10
#endif
#ifndef KEY_RESIZE
# define KEY_RESIZE KEY_UNDEF_BASE-11
# define KEY_RESIZE KEY_UNDEF_BASE - 11
#endif
#ifndef KEY_END
# define KEY_END KEY_UNDEF_BASE-12
# define KEY_END KEY_UNDEF_BASE - 12
#endif
/* Always define these keys */

View File

@ -45,48 +45,40 @@
#define OURBUFSIZ 160 /* renamed: avoid conflict with <stdio.h> */
static char line[OURBUFSIZ+1];
static char line[OURBUFSIZ + 1];
/* Internal prototypes: */
static char *nextfield(char *p);
static char *
nextfield(char *p)
{
while (*p && *p != ':')
static char *nextfield(char *p) {
while(*p && *p != ':')
++p;
if (*p) *p++ = 0;
return(p);
if(*p) *p++ = 0;
return (p);
}
char *
logdir(char *name)
{
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);
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;
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);
if(j >= i) return (0);
line[++j] = 0; /* terminate the line */
(void) lseek(pwf, (long) (j - i), 1); /* point at the next line */
(void)lseek(pwf, (long)(j - i), 1); /* point at the next line */
p = nextfield(line); /* get the logname */
} while (*name != *line || /* fast pretest */
} while(*name != *line || /* fast pretest */
strcmp(name, line) != 0);
(void) close(pwf);
(void)close(pwf);
/* skip the intervening fields */
p = nextfield(p);
@ -95,6 +87,6 @@ logdir(char *name)
p = nextfield(p);
/* return the login directory */
(void) nextfield(p);
return(p);
(void)nextfield(p);
return (p);
}

View File

@ -101,13 +101,11 @@ static struct keystruct *hashtab[HASHMOD]; /* pointer table */
/* put the keywords into the symbol table */
void
initsymtab(void)
{
void initsymtab(void) {
unsigned int i, j;
struct keystruct *p;
for (i = 1; i < KEYWORDS; ++i) {
for(i = 1; i < KEYWORDS; ++i) {
p = keyword + i;
j = hash(p->text) % HASHMOD;
p->next = hashtab[j];
@ -117,33 +115,29 @@ initsymtab(void)
/* see if this identifier is a keyword */
char *
lookup(char *ident)
{
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 == true && (c = p - keyword) < ' ') {
for(p = hashtab[hash(ident) % HASHMOD]; p != NULL; p = p->next) {
if(strequal(ident, p->text)) {
if(compress == true && (c = p - keyword) < ' ') {
ident[0] = c; /* compress the keyword */
}
return(p->text);
return (p->text);
}
}
/* this is an identifier */
return(NULL);
return (NULL);
}
/* form hash value for string */
int
hash(char *ss)
{
int hash(char *ss) {
int i;
unsigned char *s = (unsigned char *)ss;
for (i = 0; *s != '\0'; )
for(i = 0; *s != '\0';)
i += *s++; /* += is faster than <<= for cscope */
return(i);
return (i);
}

View File

@ -106,25 +106,18 @@ static inline void linemode_event_loop(void);
static inline void screenmode_event_loop(void);
#if defined(KEY_RESIZE) && !defined(__DJGPP__)
void
sigwinch_handler(int sig, siginfo_t *info, void *unused)
{
void sigwinch_handler(int sig, siginfo_t *info, void *unused) {
UNUSED(sig);
UNUSED(info);
UNUSED(unused);
if(incurses == true){
ungetch(KEY_RESIZE);
}
if(incurses == true) { ungetch(KEY_RESIZE); }
}
#endif
static
inline
void
siginit(void){
static inline void siginit(void) {
/* if running in the foreground */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
if(signal(SIGINT, SIG_IGN) != SIG_IGN) {
/* cleanup on the interrupt and quit signals */
signal(SIGINT, myexit);
signal(SIGQUIT, myexit);
@ -141,21 +134,15 @@ siginit(void){
*/
signal(SIGPIPE, SIG_IGN);
if (linemode == false) {
signal(SIGWINCH, sigwinch_handler);
}
if(linemode == false) { signal(SIGWINCH, sigwinch_handler); }
}
void
cannotopen(const char *const file)
{
void cannotopen(const char *const file) {
posterr("Cannot open file %s", file);
}
/* FIXME MTE - should use postfatal here */
void
cannotwrite(const char *const file)
{
void cannotwrite(const char *const file) {
char msg[MSGLEN + 1];
snprintf(msg, sizeof(msg), "Removed file %s because write failed", file);
@ -166,36 +153,31 @@ cannotwrite(const char *const file)
myexit(1); /* calls exit(2), which closes files */
}
/* set up the digraph character tables for text compression */
static void
initcompress(void)
{
static void initcompress(void) {
int i;
if (compress == true) {
for (i = 0; i < 16; ++i) {
dicode1[(unsigned char) (dichar1[i])] = i * 8 + 1;
if(compress == true) {
for(i = 0; i < 16; ++i) {
dicode1[(unsigned char)(dichar1[i])] = i * 8 + 1;
}
for (i = 0; i < 8; ++i) {
dicode2[(unsigned char) (dichar2[i])] = i + 1;
for(i = 0; i < 8; ++i) {
dicode2[(unsigned char)(dichar2[i])] = i + 1;
}
}
}
/* skip the list in the cross-reference file */
static void
skiplist(FILE *oldrefs)
{
static void skiplist(FILE *oldrefs) {
int i;
if (fscanf(oldrefs, "%d", &i) != 1) {
if(fscanf(oldrefs, "%d", &i) != 1) {
postfatal(PROGRAM_NAME ": cannot read list size from file %s\n", reffile);
/* NOTREACHED */
}
while (--i >= 0) {
if (fscanf(oldrefs, "%*s") != 0) {
while(--i >= 0) {
if(fscanf(oldrefs, "%*s") != 0) {
postfatal(PROGRAM_NAME ": cannot read list name from file %s\n", reffile);
/* NOTREACHED */
}
@ -203,28 +185,20 @@ skiplist(FILE *oldrefs)
}
/* cleanup and exit */
void
myexit(int sig)
{
void myexit(int sig) {
/* Close file before unlinking it. DOS absolutely needs it */
if (refsfound != NULL){
fclose(refsfound);
}
if(refsfound != NULL) { fclose(refsfound); }
/* remove any temporary files */
if (temp1[0] != '\0') {
if(temp1[0] != '\0') {
unlink(temp1);
unlink(temp2);
rmdir(tempdirpv);
}
/* restore the terminal to its original mode */
if (incurses == true) {
exitcurses();
}
if(incurses == true) { exitcurses(); }
/* dump core for debugging on the quit signal */
if (sig == SIGQUIT) {
abort();
}
if(sig == SIGQUIT) { abort(); }
/* HBB 20000421: be nice: free allocated data */
freefilelist();
freeinclist();
@ -232,16 +206,16 @@ myexit(int sig)
freecrossref();
free_newbuildfiles();
if( remove_symfile_onexit == true ) {
unlink( reffile );
unlink( invname );
unlink( invpost );
if(remove_symfile_onexit == true) {
unlink(reffile);
unlink(invname);
unlink(invpost);
}
exit(sig);
}
static inline void readenv(void){
static inline void readenv(void) {
editor = mygetenv("EDITOR", EDITOR);
editor = mygetenv("VIEWER", editor); /* use viewer if set */
editor = mygetenv("CSCOPE_EDITOR", editor); /* has last word */
@ -252,39 +226,33 @@ static inline void readenv(void){
tmpdir = mygetenv("TMPDIR", TMPDIR);
}
static inline void linemode_event_loop(void){
static inline void linemode_event_loop(void) {
int c;
if (*input_line != '\0') { /* do any optional search */
if (search(input_line) == true) {
if(*input_line != '\0') { /* do any optional search */
if(search(input_line) == true) {
/* print the total number of lines in
* verbose mode */
if (verbosemode == true)
printf(PROGRAM_NAME ": %d lines\n",
totallines);
if(verbosemode == true) printf(PROGRAM_NAME ": %d lines\n", totallines);
while ((c = getc(refsfound)) != EOF)
while((c = getc(refsfound)) != EOF)
putchar(c);
}
}
if (onesearch == true) {
if(onesearch == true) {
myexit(0);
/* NOTREACHED */
}
for (char *s;;) {
for(char *s;;) {
char buf[PATLEN + 2];
printf(">> ");
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
myexit(0);
}
if(fgets(buf, sizeof(buf), stdin) == NULL) { myexit(0); }
/* remove any trailing newline character */
if (*(s = buf + strlen(buf) - 1) == '\n') {
*s = '\0';
}
switch (*buf) {
if(*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; }
switch(*buf) {
case '0':
case '1':
case '2':
@ -297,11 +265,11 @@ static inline void linemode_event_loop(void){
case '9': /* samuel only */
field = *buf - '0';
strcpy(input_line, buf + 1);
if (search(input_line) == false) {
if(search(input_line) == false) {
printf("Unable to search database\n");
} else {
printf("cscope: %d lines\n", totallines);
while ((c = getc(refsfound)) != EOF) {
while((c = getc(refsfound)) != EOF) {
putchar(c);
}
}
@ -309,7 +277,7 @@ static inline void linemode_event_loop(void){
case 'c': /* toggle caseless mode */
case ctrl('C'):
if (caseless == false) {
if(caseless == false) {
caseless = true;
} else {
caseless = false;
@ -335,8 +303,7 @@ static inline void linemode_event_loop(void){
case 'F': /* add a file name */
strcpy(path, buf + 1);
if (infilelist(path) == false &&
(s = inviewpath(path)) != NULL) {
if(infilelist(path) == false && (s = inviewpath(path)) != NULL) {
addsrcfile(s);
}
putchar('\n');
@ -355,16 +322,14 @@ static inline void linemode_event_loop(void){
}
}
static inline void screenmode_event_loop(void){
for (;;) {
static inline void screenmode_event_loop(void) {
for(;;) {
display();
handle_input(wgetch(stdscr)); // NOTE: getch() does not return key codes
}
}
int
main(int argc, char **argv)
{
int main(int argc, char **argv) {
FILE *names; /* name file pointer */
int oldnum; /* number in old cross-ref */
FILE *oldrefs; /* old cross-reference file */
@ -386,26 +351,29 @@ main(int argc, char **argv)
readenv();
/* XXX remove if/when clearerr() in dir.c does the right thing. */
if (namefile && strcmp(namefile, "-") == 0 && !buildonly) {
if(namefile && strcmp(namefile, "-") == 0 && !buildonly) {
postfatal(PROGRAM_NAME ": Must use -b if file list comes from stdin\n");
/* NOTREACHED */
}
/* make sure that tmpdir exists */
if (lstat (tmpdir, &stat_buf)) {
fprintf (stderr, PROGRAM_NAME ": Temporary directory %s does not exist or cannot be accessed\n",
if(lstat(tmpdir, &stat_buf)) {
fprintf(stderr,
PROGRAM_NAME
": Temporary directory %s does not exist or cannot be accessed\n",
tmpdir);
fprintf (stderr,
PROGRAM_NAME ": Please create the directory or set the environment variable\n"
PROGRAM_NAME ": TMPDIR to a valid directory\n");
fprintf(stderr,
PROGRAM_NAME
": Please create the directory or set the environment variable\n" PROGRAM_NAME
": TMPDIR to a valid directory\n");
myexit(1);
}
/* create the temporary file names */
orig_umask = umask(S_IRWXG|S_IRWXO);
orig_umask = umask(S_IRWXG | S_IRWXO);
pid = getpid();
snprintf(tempdirpv, sizeof(tempdirpv), "%s/"PROGRAM_NAME".%d", tmpdir, pid);
if(mkdir(tempdirpv,S_IRWXU)) {
snprintf(tempdirpv, sizeof(tempdirpv), "%s/" PROGRAM_NAME ".%d", tmpdir, pid);
if(mkdir(tempdirpv, S_IRWXU)) {
fprintf(stderr,
PROGRAM_NAME ": Could not create private temp dir %s\n",
tempdirpv);
@ -413,11 +381,11 @@ main(int argc, char **argv)
}
umask(orig_umask);
snprintf(temp1, sizeof(temp1), "%s/"PROGRAM_NAME".1", tempdirpv);
snprintf(temp2, sizeof(temp2), "%s/"PROGRAM_NAME".2", tempdirpv);
snprintf(temp1, sizeof(temp1), "%s/" PROGRAM_NAME ".1", tempdirpv);
snprintf(temp2, sizeof(temp2), "%s/" PROGRAM_NAME ".2", tempdirpv);
/* if the database path is relative and it can't be created */
if (reffile[0] != '/' && access(".", WRITE) != 0) {
if(reffile[0] != '/' && access(".", WRITE) != 0) {
/* put it in the home directory if the database may not be
* up-to-date or doesn't exist in the relative directory,
@ -426,7 +394,7 @@ main(int argc, char **argv)
* the home directory
*/
snprintf(path, sizeof(path), "%s/%s", home, reffile);
if (isuptodate == false || access(path, READ) == 0) {
if(isuptodate == false || access(path, READ) == 0) {
reffile = strdup(path);
snprintf(path, sizeof(path), "%s/%s", home, invname);
invname = strdup(path);
@ -437,7 +405,7 @@ main(int argc, char **argv)
siginit();
if (linemode == false) {
if(linemode == false) {
dispinit(); /* initialize display parameters */
postmsg(""); /* clear any build progress message */
display(); /* display the version number and input fields */
@ -445,31 +413,30 @@ main(int argc, char **argv)
/* if the cross-reference is to be considered up-to-date */
if (isuptodate == true) {
if ((oldrefs = vpfopen(reffile, "rb")) == NULL) {
if(isuptodate == true) {
if((oldrefs = vpfopen(reffile, "rb")) == NULL) {
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
/* NOTREACHED */
}
/* get the crossref file version but skip the current directory */
if (fscanf(oldrefs, PROGRAM_NAME " %d %*s", &fileversion) != 1) {
postfatal(PROGRAM_NAME ": cannot read file version from file %s\n",
reffile);
if(fscanf(oldrefs, PROGRAM_NAME " %d %*s", &fileversion) != 1) {
postfatal(PROGRAM_NAME ": cannot read file version from file %s\n", reffile);
/* NOTREACHED */
}
if (fileversion >= 8) {
if(fileversion >= 8) {
/* override these command line options */
compress = true;
invertedindex = false;
/* see if there are options in the database */
for (int c;;) {
for(int c;;) {
getc(oldrefs); /* skip the blank */
if ((c = getc(oldrefs)) != '-') {
if((c = getc(oldrefs)) != '-') {
ungetc(c, oldrefs);
break;
}
switch (getc(oldrefs)) {
switch(getc(oldrefs)) {
case 'c': /* ASCII characters only */
compress = false;
break;
@ -491,20 +458,18 @@ main(int argc, char **argv)
skiplist(oldrefs);
/* get the number of source files */
if (fscanf(oldrefs, "%lu", &nsrcfiles) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file size from file %s\n",
if(fscanf(oldrefs, "%lu", &nsrcfiles) != 1) {
postfatal(PROGRAM_NAME ": cannot read source file size from file %s\n",
reffile);
/* NOTREACHED */
}
/* get the source file list */
srcfiles = malloc(nsrcfiles * sizeof(*srcfiles));
if (fileversion >= 9) {
if(fileversion >= 9) {
/* allocate the string space */
if (fscanf(oldrefs, "%d", &oldnum) != 1) {
postfatal(
PROGRAM_NAME ": cannot read string space size from file %s\n",
if(fscanf(oldrefs, "%d", &oldnum) != 1) {
postfatal(PROGRAM_NAME ": cannot read string space size from file %s\n",
reffile);
/* NOTREACHED */
}
@ -512,38 +477,38 @@ main(int argc, char **argv)
getc(oldrefs); /* skip the newline */
/* read the strings */
if (fread(s, oldnum, 1, oldrefs) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file names from file %s\n",
if(fread(s, oldnum, 1, oldrefs) != 1) {
postfatal(PROGRAM_NAME ": cannot read source file names from file %s\n",
reffile);
/* NOTREACHED */
}
/* change newlines to nulls */
for (i = 0; i < nsrcfiles; ++i) {
for(i = 0; i < nsrcfiles; ++i) {
srcfiles[i] = s;
for (++s; *s != '\n'; ++s) {
for(++s; *s != '\n'; ++s) {
;
}
*s = '\0';
++s;
}
/* if there is a file of source file names */
if ((namefile != NULL && (names = vpfopen(namefile, "r")) != NULL)
|| (names = vpfopen(NAMEFILE, "r")) != NULL) {
if((namefile != NULL && (names = vpfopen(namefile, "r")) != NULL) ||
(names = vpfopen(NAMEFILE, "r")) != NULL) {
/* read any -p option from it */
while (fgets(path, sizeof(path), names) != NULL && *path == '-') {
while(fgets(path, sizeof(path), names) != NULL && *path == '-') {
i = path[1];
s = path + 2; /* for "-Ipath" */
if (*s == '\0') { /* if "-I path" */
if(*s == '\0') { /* if "-I path" */
fgets(path, sizeof(path), names);
s = path;
}
switch (i) {
switch(i) {
case 'p': /* file path components to display */
if (*s < '0' || *s > '9') {
posterr(PROGRAM_NAME ": -p option in file %s: missing or invalid numeric value\n", namefile);
if(*s < '0' || *s > '9') {
posterr(PROGRAM_NAME
": -p option in file %s: missing or invalid numeric value\n",
namefile);
}
dispcomponents = atoi(s);
}
@ -551,12 +516,11 @@ main(int argc, char **argv)
fclose(names);
}
} else {
for (i = 0; i < nsrcfiles; ++i) {
if (!fgets(path, sizeof(path), oldrefs) ) {
postfatal(
PROGRAM_NAME ": cannot read source file name from file %s\n",
reffile
);
for(i = 0; i < nsrcfiles; ++i) {
if(!fgets(path, sizeof(path), oldrefs)) {
postfatal(PROGRAM_NAME
": cannot read source file name from file %s\n",
reffile);
/* NOTREACHED */
}
srcfiles[i] = strdup(path);
@ -569,24 +533,20 @@ main(int argc, char **argv)
fileargv = argv;
/* get source directories from the environment */
if ((s = getenv("SOURCEDIRS")) != NULL) {
sourcedir(s);
}
if((s = getenv("SOURCEDIRS")) != NULL) { sourcedir(s); }
/* make the source file list */
srcfiles = malloc(msrcfiles * sizeof(*srcfiles));
makefilelist();
if (nsrcfiles == 0) {
if(nsrcfiles == 0) {
postfatal(PROGRAM_NAME ": no source files found\n");
/* NOTREACHED */
}
/* get include directories from the environment */
if ((s = getenv("INCLUDEDIRS")) != NULL) {
includedir(s);
}
if((s = getenv("INCLUDEDIRS")) != NULL) { includedir(s); }
/* add /usr/include to the #include directory list,
but not in kernelmode... kernels tend not to use it. */
if (kernelmode == false) {
if (NULL != (s = getenv("INCDIR"))) {
if(kernelmode == false) {
if(NULL != (s = getenv("INCDIR"))) {
includedir(s);
} else {
includedir(DFLT_INCDIR);
@ -601,14 +561,12 @@ main(int argc, char **argv)
/* build the cross-reference */
initcompress();
if (linemode == false || verbosemode == true) { /* display if verbose as well */
if(linemode == false || verbosemode == true) { /* display if verbose as well */
postmsg("Building cross-reference...");
}
build();
if (linemode == false ) {
postmsg(""); /* clear any build progress message */
}
if (buildonly == true) {
if(linemode == false) { postmsg(""); /* clear any build progress message */ }
if(buildonly == true) {
myexit(0);
/* NOTREACHED */
}
@ -617,18 +575,16 @@ main(int argc, char **argv)
/* if using the line oriented user interface so cscope can be a
subprocess to emacs or samuel */
if (linemode == true) {
linemode_event_loop();
}
if(linemode == true) { linemode_event_loop(); }
/* pause before clearing the screen if there have been error messages */
if (errorsfound == true) {
if(errorsfound == true) {
errorsfound = false;
askforreturn();
}
/* do any optional search */
if (*input_line != '\0') {
//command(ctrl('Y')); /* search */ // XXX: fix
} else if (reflines != NULL) {
if(*input_line != '\0') {
// command(ctrl('Y')); /* search */ // XXX: fix
} else if(reflines != NULL) {
/* read any symbol reference lines file */
readrefs(reflines);
}

View File

@ -44,7 +44,7 @@ extern int LINES;
bool mouse = false; /* mouse interface */
#ifdef UNIXPC /* build command requires #ifdef instead of #if */
#include <sys/window.h>
# include <sys/window.h>
bool unixpcmouse = false; /* running with a mouse on the Unix PC? */
static int uw_hs, uw_vs; /* character height and width */
#endif
@ -54,27 +54,29 @@ typedef struct { /* menu */
char *value;
} MENU;
static MENU mainmenu[] = { /* main menu */
static MENU mainmenu[] = {
/* main menu */
{"Send", "##\033s##\r"},
{"Repeat", "\031"},
{"Edit All", "\05"},
{"Rebuild", "\022"},
{"Shell", "!"},
{"Redraw", "\f"},
{"Help", "?"},
{"Exit", "\04"},
{NULL, NULL}
{"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"},
static MENU changemenu[] = {
/* change mode menu */
{"Mark Screen", "*" },
{"Mark All", "a" },
{"Change", "\04" },
{"No Change", "\033"},
{"Shell", "!"},
{"Redraw", "\f"},
{"Help", "?"},
{NULL, NULL}
{"Shell", "!" },
{"Redraw", "\f" },
{"Help", "?" },
{NULL, NULL }
};
static MENU *loaded; /* menu loaded */
@ -86,49 +88,43 @@ static int getpercent(void);
/* see if there is a mouse interface */
void
mouseinit(void)
{
void mouseinit(void) {
char *term;
/* see if this is emacsterm or viterm */
term = mygetenv("TERM", "");
if (strcmp(term, "emacsterm") == 0 ||
strcmp(term, "viterm") == 0) {
if(strcmp(term, "emacsterm") == 0 || strcmp(term, "viterm") == 0) {
emacsviterm = true;
mouse = true;
}
/* 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) {
else if(strcmp(mygetenv("MOUSE", ""), "myx") == 0) {
mouse = true;
}
#if UNIXPC
else if (strcmp(term,"s4") == 0 ||
strcmp(term,"s120") == 0 ||
strcmp(term,"s90") == 0) {
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);
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")) {
if(!strcmp(term, "s4")) {
uw_hs = 9;
uw_vs = 12;
}
else {
} else {
uw_hs = 6;
uw_vs = 10;
}
}
else {
} else {
/* Kernel is working and knows about this font */
uw_hs = uwd.uw_hs;
uw_vs = uwd.uw_vs;
@ -138,28 +134,23 @@ mouseinit(void)
* 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);
if((retval = ioctl(1, WIOCGETMOUSE, &umd)) != -1) {
umd.um_flags = MSDOWN + MSUP;
ioctl(1, WIOCSETMOUSE, &umd);
}
unixpcmouse = true;
}
#endif
if (mouse == true) {
loadmenu(mainmenu);
}
if(mouse == true) { loadmenu(mainmenu); }
}
/* load the correct mouse menu */
void
mousemenu(void)
{
if (mouse == true) {
if (input_mode == INPUT_CHANGE) {
void mousemenu(void) {
if(mouse == true) {
if(input_mode == INPUT_CHANGE) {
loadmenu(changemenu);
}
else {
} else {
loadmenu(mainmenu);
}
}
@ -167,62 +158,57 @@ mousemenu(void)
/* download a menu */
static void
loadmenu(MENU *menu)
{
static void loadmenu(MENU *menu) {
int i;
if (emacsviterm == true) {
if(emacsviterm == true) {
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);
(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 */
} else { /* myx */
int len;
mousecleanup();
(void) printf("\033[6;1X\033[9;1X");
for (i = 0; menu[i].text != NULL; ++i) {
(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);
(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);
(void)fflush(stdout);
}
/* reinitialize the mouse in case curses changed the attributes */
void
mousereinit(void)
{
if (emacsviterm == true) {
void mousereinit(void) {
if(emacsviterm == true) {
/* enable the mouse click and sweep coordinate control sequence */
/* and switch to menu 2 */
(void) printf("\033{2\033#2");
(void) fflush(stdout);
(void)printf("\033{2\033#2");
(void)fflush(stdout);
}
}
/* restore the mouse attributes */
void
mousecleanup(void)
{
void mousecleanup(void) {
int i;
if (loaded != NULL) { /* only true for myx */
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");
(void)printf("\033[6;0X\033[9;0X");
for(i = 0; loaded[i].text != NULL; ++i) {
(void)printf("\033[0;0x");
}
loaded = NULL;
}
@ -230,41 +216,28 @@ mousecleanup(void)
/* draw the scrollbar */
void
drawscrollbar(int top, int bot)
{
void drawscrollbar(int top, int bot) {
int p1, p2;
if (emacsviterm == true) {
if (bot > top) {
if(emacsviterm == true) {
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;
}
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 {
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);
(void)printf("\033W%c%c", p1, p2);
}
}
/* get the mouse information */
MOUSE *
getmouseaction(char leading_char)
{
MOUSE *getmouseaction(char leading_char) {
static MOUSE m;
#if UNIXPC
@ -294,47 +267,47 @@ getmouseaction(char leading_char)
/* Check for "[?" being next 2 chars */
if(((i = getch()) != '[') || ((i = getch()) != '?')) {
myungetch(i);
return(NULL);
return (NULL);
}
/* Grab the X position (in pixels) */
while(isdigit(i = getch())) {
x = (x*10) + (i - '0');
x = (x * 10) + (i - '0');
}
if(i != ';') {
myungetch(i);
return(NULL); /* not a mouse report after all */
return (NULL); /* not a mouse report after all */
}
/* Grab the Y position (in pixels) */
while(isdigit(i = getch())) {
y = (y*10) + (i - '0');
y = (y * 10) + (i - '0');
}
if(i != ';') {
myungetch(i);
return(NULL);
return (NULL);
}
/* Get which button */
if((button = getch()) > '4') {
myungetch(button);
return(NULL);
return (NULL);
}
if((i = getch()) != ';') {
myungetch(i);
return(NULL);
return (NULL);
}
/* Get the reason for this mouse report */
if((reason = getch()) > '8') {
myungetch(reason);
return(NULL);
return (NULL);
}
/* sequence should terminate with an 'M' */
if((i = getch()) != 'M') {
myungetch(i);
return(NULL);
return (NULL);
}
@ -342,9 +315,7 @@ getmouseaction(char leading_char)
* 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 */
}
if(reason != '2') { return (NULL); /* '2' means button is released */ }
/************************************************************
* Always indicate button 1 irregardless of which button was
@ -359,23 +330,21 @@ getmouseaction(char leading_char)
* 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 */
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
} else
#endif /* not UNIXPC */
if (mouse == true && leading_char == ctrl('X')) {
if(mouse == true && leading_char == ctrl('X')) {
switch (getch()) {
switch(getch()) {
case ctrl('_'): /* click */
if ((m.button = getch()) == '0') { /* if scrollbar */
if((m.button = getch()) == '0') { /* if scrollbar */
m.percent = getpercent();
}
else {
} else {
m.x1 = getcoordinate();
m.y1 = getcoordinate();
m.x2 = m.y2 = -1;
@ -390,85 +359,69 @@ getmouseaction(char leading_char)
m.y2 = getcoordinate();
break;
default:
return(NULL);
return (NULL);
}
}
else return(NULL);
} else
return (NULL);
return(&m);
return (&m);
}
/* get a row or column coordinate from a mouse button click or sweep */
static int
getcoordinate(void)
{
static int getcoordinate(void) {
int c, next;
c = getch();
next = 0;
if (c == ctrl('A')) {
if(c == ctrl('A')) {
next = 95;
c = getch();
}
if (c < ' ') {
return (0);
}
if(c < ' ') { return (0); }
return (next + c - ' ');
}
/* get a percentage */
static int
getpercent(void)
{
static int getpercent(void) {
int c;
c = getch();
if (c < 16) {
return(0);
}
if (c > 120) {
return(100);
}
return(c - 16);
if(c < 16) { return (0); }
if(c > 120) { return (100); }
return (c - 16);
}
int process_mouse(){
int process_mouse() {
int i;
MOUSE* p;
if ((p = getmouseaction(DUMMYCHAR)) == NULL) {
return(false); /* unknown control sequence */
MOUSE *p;
if((p = getmouseaction(DUMMYCHAR)) == NULL) {
return (false); /* unknown control sequence */
}
/* if the button number is a scrollbar tag */
if (p->button == '0') {
//scrollbar(p); // XXX
return(false);
if(p->button == '0') {
// scrollbar(p); // XXX
return (false);
}
/* ignore a sweep */
if (p->x2 >= 0) {
return(false);
}
if(p->x2 >= 0) { return (false); }
/* if this is a line selection */
if (p->y1 > FLDLINE) {
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(false);
}
for(i = disprefs - 1; i > 0; --i) {
if(p->y1 >= displine[i]) { return (false); }
}
/* 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;
}
if(field >= FIELDS) { field = FIELDS - 1; }
resetcmd();
return(false);
return (false);
}
return false;

View File

@ -36,14 +36,10 @@
/* return the non-null environment value or the default argument */
char *
mygetenv(char *variable, char *deflt)
{
char *mygetenv(char *variable, char *deflt) {
char *value;
value = getenv(variable);
if (value == NULL || *value == '\0') {
return(deflt);
}
return(value);
if(value == NULL || *value == '\0') { return (deflt); }
return (value);
}

View File

@ -37,7 +37,7 @@
#include <sys/wait.h>
#include "global.h" /* pid_t, shell, and basename() */
#define tst(a,b) (*mode == 'r'? (b) : (a))
#define tst(a, b) (*mode == 'r' ? (b) : (a))
#define RDR 0
#define WTR 1
@ -55,9 +55,7 @@
static pid_t popen_pid[20];
static void (*tstat)(int);
int
myopen(char *path, int flag, int mode)
{
int myopen(char *path, int flag, int mode) {
/* opens a file descriptor and then sets close-on-exec for the file */
int fd;
@ -65,8 +63,7 @@ myopen(char *path, int flag, int mode)
* sure we override silly Cygwin behaviour of automatic binary
* mode for files in "binary mounted" paths */
#if O_BINARY != O_TEXT
if (! (flag | O_BINARY))
flag |= O_TEXT;
if(!(flag | O_BINARY)) flag |= O_TEXT;
#endif
if(mode)
fd = open(path, flag, mode);
@ -74,56 +71,44 @@ myopen(char *path, int flag, int mode)
fd = open(path, flag);
if(fd != -1 && (fcntl(fd, F_SETFD, CLOSE_ON_EXEC) != -1))
return(fd);
return (fd);
else
{
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);
}
if(fd != -1) { close(fd); }
return(-1);
return (-1);
}
}
FILE *
myfopen(char *path, char *mode)
{
FILE *myfopen(char *path, char *mode) {
/* opens a file pointer and then sets close-on-exec for the file */
FILE *fp;
fp = fopen(path, mode);
#ifdef SETMODE
if (fp && ! strchr(mode, 'b')) {
SETMODE(fileno(fp), O_TEXT);
}
if(fp && !strchr(mode, 'b')) { SETMODE(fileno(fp), O_TEXT); }
#endif /* SETMODE */
if(fp && (fcntl(fileno(fp), F_SETFD, CLOSE_ON_EXEC) != -1))
return(fp);
return (fp);
else {
if (fp)
fclose(fp);
return(NULL);
if(fp) fclose(fp);
return (NULL);
}
}
FILE *
mypopen(char *cmd, char *mode)
{
FILE *mypopen(char *cmd, char *mode) {
int p[2];
pid_t *poptr;
int myside, yourside;
pid_t pid;
if(pipe(p) < 0)
return(NULL);
if(pipe(p) < 0) return (NULL);
myside = tst(p[WTR], p[RDR]);
yourside = tst(p[RDR], p[WTR]);
if((pid = fork()) == 0) {
@ -131,9 +116,8 @@ mypopen(char *cmd, char *mode)
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);
for(poptr = popen_pid; poptr < popen_pid + 20; poptr++) {
if(*poptr) (void)close(poptr - popen_pid);
}
stdio = tst(0, 1);
close(myside);
@ -142,39 +126,35 @@ mypopen(char *cmd, char *mode)
close(yourside);
execlp(shell, basename(shell), "-c", cmd, (void *)0);
_exit(1);
} else if (pid > 0)
} else if(pid > 0)
tstat = signal(SIGTSTP, SIG_DFL);
if(pid == -1)
return(NULL);
if(pid == -1) return (NULL);
popen_pid[myside] = pid;
(void) close(yourside);
return(fdopen(myside, mode));
(void)close(yourside);
return (fdopen(myside, mode));
}
/* HBB 20010705: renamed from 'pclose', which would collide with
* system-supplied function of same name */
int
mypclose(FILE *ptr)
{
int mypclose(FILE *ptr) {
int f;
pid_t r;
int status = -1;
sighandler_t hstat, istat, qstat;
f = fileno(ptr);
(void) fclose(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);
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);
return (status);
}

View File

@ -11,8 +11,7 @@ bool remove_symfile_onexit = false;
bool onesearch; /* one search only in line mode */
char *reflines; /* symbol reference lines file */
char ** parse_options(int *argc, char **argv)
{
char **parse_options(int *argc, char **argv) {
int opt;
int longind;
char path[PATHLEN + 1]; /* file path */
@ -22,12 +21,14 @@ char ** parse_options(int *argc, char **argv)
struct option lopts[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
{0, 0, 0, 0}
{0, 0, 0, 0 }
};
while ((opt = getopt_long(argcc, argv,
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) {
lopts,
&longind)) != -1) {
switch(opt) {
case '?':
@ -49,10 +50,11 @@ char ** parse_options(int *argc, char **argv)
case '9':
/* The input fields numbers for line mode operation */
field = opt - '0';
if (strlen(optarg) > PATHLEN) {
if(strlen(optarg) > PATHLEN) {
postfatal("\
cscope: pattern too long, cannot be > \
%d characters\n", PATLEN);
%d characters\n",
PATLEN);
}
strcpy(input_line, optarg);
break;
@ -90,8 +92,7 @@ char ** parse_options(int *argc, char **argv)
verbosemode = true;
break;
case 'V':
fprintf(stderr, PROGRAM_NAME ": version %d%s\n",
FILEVERSION, FIXVERSION);
fprintf(stderr, PROGRAM_NAME ": version %d%s\n", FILEVERSION, FIXVERSION);
myexit(0);
break;
case 'q': /* quick search */
@ -111,10 +112,11 @@ char ** parse_options(int *argc, char **argv)
break;
case 'f': /* alternate cross-reference file */
reffile = optarg;
if (strlen(reffile) > sizeof(path) - 3) {
if(strlen(reffile) > sizeof(path) - 3) {
postfatal("\
cscope: reffile too long, cannot \
be > %d characters\n", sizeof(path) - 3);
be > %d characters\n",
sizeof(path) - 3);
/* NOTREACHED */
}
strcpy(path, reffile);

View File

@ -34,37 +34,28 @@
#include "global.h"
const char *
basename(const char *path)
{
const char *basename(const char *path) {
const char *s;
if ((s = strrchr(path, '/')) != 0) {
return(s + 1);
}
return(path);
if((s = strrchr(path, '/')) != 0) { return (s + 1); }
return (path);
}
/* get the requested path components */
char *
pathcomponents(char *path, int components)
{
char *pathcomponents(char *path, int components) {
int i;
char *s;
s = path + strlen(path) - 1;
for (i = 0; i < components; ++i) {
while (s > path && *--s != '/') {
for(i = 0; i < components; ++i) {
while(s > path && *--s != '/') {
;
}
}
if (s > path && *s == '/') {
++s;
}
return(s);
if(s > path && *s == '/') { ++s; }
return (s);
}
/*
* compath(pathname)
*
@ -79,8 +70,7 @@ pathcomponents(char *path, int components)
* and stored in global structures.
*/
char *
compath(char *pathname) /*FDEF*/
char *compath(char *pathname) /*FDEF*/
{
char *nextchar;
char *lastchar;
@ -93,25 +83,21 @@ compath(char *pathname) /*FDEF*/
* 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 '/'
*/
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
*/
nextchar = lastchar;
while (*++lastchar == '/')
{
}
while(*++lastchar == '/') { }
/*
* eliminate the extra slashes by copying
@ -119,7 +105,7 @@ compath(char *pathname) /*FDEF*/
*/
sofar = nextchar;
while ((*nextchar++ = *lastchar++) != '\0')
while((*nextchar++ = *lastchar++) != '\0')
;
lastchar = sofar;
}
@ -128,10 +114,9 @@ compath(char *pathname) /*FDEF*/
* 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 "./"
@ -139,7 +124,7 @@ compath(char *pathname) /*FDEF*/
nextchar = lastchar - 1;
sofar = nextchar;
while ((*nextchar++ = *++lastchar) != '\0')
while((*nextchar++ = *++lastchar) != '\0')
;
lastchar = sofar;
}
@ -148,19 +133,17 @@ compath(char *pathname) /*FDEF*/
* 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 "/.."
*/
nextchar = lastchar - 1;
while ((nextchar != pathname) &&
(*(nextchar - 1) != '/'))
while((nextchar != pathname) && (*(nextchar - 1) != '/'))
--nextchar;
/*
@ -168,19 +151,18 @@ compath(char *pathname) /*FDEF*/
* is not "." or ".."
*/
if ((*nextchar == '.') &&
if((*nextchar == '.') &&
((*(nextchar + 1) == '/') ||
((*(nextchar + 1) == '.') && (*(nextchar + 2) == '/'))))
/* EMPTY */;
else
{
else {
/*
* prepare to eliminate either
* "dir_name/../" or "dir_name/.."
*/
if (*(lastchar + 3) == '/')
if(*(lastchar + 3) == '/')
lastchar += 4;
else
lastchar += 3;
@ -191,7 +173,8 @@ compath(char *pathname) /*FDEF*/
*/
sofar = nextchar - 1;
while ((*nextchar++ = *lastchar++) != '\0');
while((*nextchar++ = *lastchar++) != '\0')
;
lastchar = sofar;
@ -201,8 +184,7 @@ compath(char *pathname) /*FDEF*/
* slash is part of "/.."
*/
if ((sofar + 1 != pathname) && (*sofar == '/'))
--lastchar;
if((sofar + 1 != pathname) && (*sofar == '/')) --lastchar;
}
}
@ -214,8 +196,7 @@ compath(char *pathname) /*FDEF*/
pnlen = strlen(pathname);
pnend = strchr(pathname, '\0') - 1;
if ((pnlen > 1) && (*pnend == '/'))
{
if((pnlen > 1) && (*pnend == '/')) {
*pnend-- = '\0';
pnlen--;
}
@ -225,16 +206,14 @@ compath(char *pathname) /*FDEF*/
* "/.", 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 (*pathname == '\0')
(void) strcpy(pathname, ".");
if(*pathname == '\0') (void)strcpy(pathname, ".");
return(pathname);
return (pathname);
}

View File

@ -8,7 +8,7 @@ static int input_available = 0;
static char input_char;
char input_line[PATLEN + 1];
bool interpret(int c){
bool interpret(int c) {
input_char = c;
input_available = 1;
rl_callback_read_char();
@ -16,25 +16,25 @@ bool interpret(int c){
return 0;
}
static int getc_function(FILE* ignore){
static int getc_function(FILE *ignore) {
UNUSED(ignore);
input_available = 0;
return (int)input_char;
}
static int input_available_hook(){
static int input_available_hook() {
return input_available;
}
static void redisplay_function(){
static void redisplay_function() {
window_change |= CH_INPUT;
}
static void callback_handler(char* line){
if(!line){ return; }
static void callback_handler(char *line) {
if(!line) { return; }
switch(input_mode){
switch(input_mode) {
case INPUT_NORMAL:
strncpy(input_line, line, PATLEN);
search(input_line);
@ -50,24 +50,24 @@ static void callback_handler(char* line){
return;
}
switch(field){
switch(field) {
case CHANGE:
input_mode = INPUT_CHANGE_TO;
break;
case DEFINITION:
case FILENAME:
if(totallines == 1){ editref(0); }
if(totallines == 1) { editref(0); }
break;
}
}
static int ctrl_z(){
static int ctrl_z() {
kill(0, SIGTSTP);
return 0;
}
static int toggle_caseless(){
if (caseless == false) {
static int toggle_caseless() {
if(caseless == false) {
caseless = true;
postmsg2("Caseless mode is now ON");
} else {
@ -78,16 +78,16 @@ static int toggle_caseless(){
return 0;
}
static int rebuild_reference(){
if (isuptodate == true) {
static int rebuild_reference() {
if(isuptodate == true) {
postmsg("The -d option prevents rebuilding the symbol database");
return(false);
return (false);
}
exitcurses();
freefilelist(); /* remake the source file list */
makefilelist();
rebuild();
if (errorsfound == true) {
if(errorsfound == true) {
errorsfound = false;
askforreturn();
}
@ -95,10 +95,10 @@ static int rebuild_reference(){
postmsg(""); /* clear any previous message */
totallines = 0;
disprefs = 0;
return(true);
return (true);
}
void rlinit(){
void rlinit() {
rl_catch_signals = 0;
rl_catch_sigwinch = 0;
rl_prep_term_function = NULL;
@ -110,7 +110,8 @@ void rlinit(){
rl_redisplay_function = redisplay_function;
rl_callback_handler_install("", callback_handler);
rl_bind_key(7, rl_rubout); // XXX: 7 is backspace for some reason (on my system anyways?)
rl_bind_key(7,
rl_rubout); // XXX: 7 is backspace for some reason (on my system anyways?)
rl_bind_key(KEY_BACKSPACE, rl_rubout);
rl_bind_key(EOF, myexit);
@ -120,5 +121,5 @@ void rlinit(){
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 */
}

View File

@ -4,15 +4,15 @@
struct FILE;
/* Page cursor stack */
static FILE** hto_page = &refsfound;
static FILE **hto_page = &refsfound;
#define PCS_MAXPAGE 16
static size_t PCS_pos[PCS_MAXPAGE] = {0};
static size_t PCS_top = 0;
long seekpage(const size_t i){
if(i > PCS_MAXPAGE-1){ return -1; }
long seekpage(const size_t i) {
if(i > PCS_MAXPAGE - 1) { return -1; }
if(i < PCS_top){
if(i < PCS_top) {
fseek(*hto_page, PCS_pos[i], SEEK_SET);
return PCS_pos[i];
}
@ -20,35 +20,33 @@ long seekpage(const size_t i){
fseek(*hto_page, PCS_pos[PCS_top], SEEK_SET);
size_t lc = 0;
while(PCS_top < i){
while(PCS_top < i) {
const char c = getc(*hto_page);
if(c == '\n'){ ++lc; }
if(c == EOF){ return -1; }
if(lc == mdisprefs){
PCS_pos[++PCS_top] = ftell(*hto_page);
}
if(c == '\n') { ++lc; }
if(c == EOF) { return -1; }
if(lc == mdisprefs) { PCS_pos[++PCS_top] = ftell(*hto_page); }
}
return PCS_pos[PCS_top];
}
long seekrelline(unsigned i){
long seekrelline(unsigned i) {
seekpage(current_page);
size_t lc = 0;
while(lc < i){
while(lc < i) {
const char c = getc(*hto_page);
assert("seekrelline() tried to read past the reference file" && !(c == EOF));
if(c == '\n'){ ++lc; }
if(c == '\n') { ++lc; }
}
return ftell(*hto_page);
}
void PCS_reset(void){
void PCS_reset(void) {
PCS_top = 0;
}
///* position references found file at specified line */
//void
//seekline(unsigned int line)
// void
// seekline(unsigned int line)
//{
// /* verify that there is a references found file */
// if (refsfound == NULL) {
@ -58,11 +56,11 @@ void PCS_reset(void){
// rewind(refsfound);
// /**/
// seekrelline(line);
//}
// }
//
///* XXX: this is just dodging the problem */
//void
//seekrelline(unsigned int line){
// void
// seekrelline(unsigned int line){
// int c;
//
// /* verify that there is a references found file */
@ -77,5 +75,4 @@ void PCS_reset(void){
// nextline++;
// }
// }
//}
// }

View File

@ -74,11 +74,11 @@ extern int myylineno; /* input line number */
/* 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)
# if defined(__OSF1__) || defined(__sun) || defined(_AIX)
extern char yytext[];
#else
# else
extern unsigned char yytext[];
#endif
# endif
extern int yyleng;
# define my_yytext yytext
# define my_yyleng yyleng

View File

@ -57,8 +57,8 @@
#if !falseMALLOC
extern char **vpdirs; /* directories (including current) in view path */
#else
#define MAXDIR 25 /* same as libVP */
#define DIRLEN 80 /* same as libVP */
# 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 */

View File

@ -37,21 +37,17 @@
#include "vp.h"
#include <sys/types.h>
int
vpaccess(char *path, mode_t amode)
{
int vpaccess(char *path, mode_t amode) {
char buf[MAXPATH + 1];
int returncode;
int i;
if ((returncode = access(path, amode)) == -1 && path[0] != '/') {
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;
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);
return (returncode);
}

View File

@ -37,26 +37,20 @@
#include "vp.h"
#include "global.h"
FILE *
vpfopen(char *filename, char *type)
{
FILE *vpfopen(char *filename, char *type) {
char buf[MAXPATH + 1];
FILE *returncode;
int i;
if ((returncode = myfopen(filename, type)) == NULL
&& filename[0] != '/'
if((returncode = myfopen(filename, type)) == NULL &&
filename[0] != '/'
/* && strcmp(type, "r") == 0 */ /* HBB: this breaks if type=="rb" */
&& type[0] == 'r'
) {
&& 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;
}
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);
}

View File

@ -46,13 +46,11 @@
char **vpdirs; /* directories (including current) in view path */
#else
char vpdirs[MAXDIR][DIRLEN + 1];
#define MAXVPATH (MAXDIR * (DIRLEN + 1))
# define MAXVPATH (MAXDIR * (DIRLEN + 1))
#endif
int vpndirs; /* number of directories in view path */
void
vpinit(char *current_dir)
{
void vpinit(char *current_dir) {
char *suffix; /* path from view path node */
char *vpath; /* VPATH environment variable value */
char buf[MAXPATH + 1];
@ -64,9 +62,9 @@ vpinit(char *current_dir)
#endif
/* if an existing directory list is to be updated, free it */
if (current_dir != NULL && vpndirs > 0) {
if(current_dir != NULL && vpndirs > 0) {
#if !falseMALLOC
for (i = 0; i < vpndirs; ++i) {
for(i = 0; i < vpndirs; ++i) {
free(vpdirs[i]);
}
free(vpdirs);
@ -75,20 +73,17 @@ vpinit(char *current_dir)
}
/* 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(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) {
if(current_dir == NULL && (current_dir = getcwd(buf, MAXPATH)) == NULL) {
fprintf(stderr, PROGRAM_NAME ": cannot get current directory name\n");
return;
}
/* see if this directory is in the first view path node */
for (i = 0; vpath[i] == current_dir[i] && vpath[i] != '\0'; ++i) {
for(i = 0; vpath[i] == current_dir[i] && vpath[i] != '\0'; ++i) {
;
}
if ((vpath[i] != ':' && vpath[i] != '\0') ||
if((vpath[i] != ':' && vpath[i] != '\0') ||
(current_dir[i] != '/' && current_dir[i] != '\0')) {
return;
}
@ -97,10 +92,8 @@ vpinit(char *current_dir)
/* count the nodes in the view path */
vpndirs = 1;
for (i = 0; vpath[i] != '\0'; ++i) {
if (vpath[i] == ':' && vpath[i + 1]) {
++vpndirs;
}
for(i = 0; vpath[i] != '\0'; ++i) {
if(vpath[i] == ':' && vpath[i + 1]) { ++vpndirs; }
}
/* create the source directory list */
vpdirs = malloc(vpndirs * sizeof(*vpdirs));
@ -109,59 +102,58 @@ vpinit(char *current_dir)
vpath = strdup(vpath);
/* split the view path into nodes */
for (i = 0, s = vpath; *s != '\0'; ++i) {
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';
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) {
for(i = 0; i < vpndirs; ++i) {
s = malloc(strlen(vpdirs[i]) + strlen(suffix) + 1);
(void) strcpy(s, vpdirs[i]);
(void) strcat(s, suffix);
(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);
if(strlen(vpath) > MAXVPATH) {
(void)fprintf(stderr,
"%s: VPATH is longer than %d characters: %s\n",
argv0,
MAXVPATH,
vpath);
return;
}
(void) strcpy(vpathbuf, vpath);
(void)strcpy(vpathbuf, vpath);
s = vpathbuf;
/* convert the view path nodes to directories */
while (*s != '\0') {
while(*s != '\0') {
/* get the next node */
node = s;
while (*s != '\0' && *++s != ':') {
if (*s == '\n') {
*s = '\0';
}
}
if (*s != '\0') {
*s++ = '\0';
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);
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 {
} else {
/* create the view path directory */
(void) strcpy(vpdirs[vpndirs], node);
(void) strcat(vpdirs[vpndirs], suffix);
(void)strcpy(vpdirs[vpndirs], node);
(void)strcat(vpdirs[vpndirs], suffix);
++vpndirs;
}
}

View File

@ -39,22 +39,18 @@
#define OPENFLAG_READ 0
int
vpopen(char *path, int oflag)
{
int vpopen(char *path, int oflag) {
char buf[MAXPATH + 1];
int returncode;
int i;
if ((returncode = myopen(path, oflag, 0666)) == -1 && path[0] != '/' &&
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;
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);
return (returncode);
}