'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

@ -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])) {
if((1 != fscanf(oldrefs, " %[^\n]", oldname)) || strnotequal(oldname, names[i])) {
return (false);
}
}
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,9 +142,7 @@ void setup_build_filenames(char *reffile)
/* open the database */
void
opendatabase(void)
{
void opendatabase(void) {
if((symrefs = vpopen(reffile, O_BINARY | O_RDONLY)) == -1) {
cannotopen(reffile);
myexit(1);
@ -165,18 +150,14 @@ opendatabase(void)
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) {
invclose(&invcontrol);
@ -193,11 +174,8 @@ rebuild(void)
}
}
/* 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 */
@ -228,10 +206,10 @@ 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);
@ -265,14 +243,15 @@ 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");
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");
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);
posterr(PROGRAM_NAME ": removed files %s and %s\n", invname, invpost);
unlink(invname);
unlink(invpost);
}
@ -286,12 +265,10 @@ build(void)
}
}
/* 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 */
@ -301,11 +278,10 @@ 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)
) {
if((1 != fscanf(oldrefs, " %[^\n]", oldname)) ||
strnotequal(oldname, srcfiles[i]) ||
(lstat(srcfiles[i], &statstruct) != 0) ||
(statstruct.st_mtime > reftime)) {
goto outofdate;
}
}
@ -320,7 +296,8 @@ 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");
fprintf(stderr,
PROGRAM_NAME ": converting to new symbol database file format\n");
goto force;
}
/* reopen the old cross-reference file for fast scanning */
@ -365,10 +342,8 @@ build(void)
srcoffset = malloc((nsrcfiles + 1u) * sizeof(*srcoffset));
}
for(;;) {
progress("Building symbol database", (long)built,
(long)lastfile);
if (linemode == false)
refresh();
progress("Building symbol database", (long)built, (long)lastfile);
if(linemode == false) refresh();
/* get the next source file name */
for(fileindex = firstfile; fileindex < lastfile; ++fileindex) {
@ -386,8 +361,7 @@ build(void)
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;
@ -411,9 +385,7 @@ build(void)
}
}
/* see if any included files were found */
if (lastfile == nsrcfiles) {
break;
}
if(lastfile == nsrcfiles) { break; }
firstfile = lastfile;
lastfile = nsrcfiles;
if(invertedindex == true) {
@ -449,7 +421,11 @@ build(void)
}
fstat(fileno(postings), &statstruct);
fclose(postings);
snprintf(sortcommand, sizeof(sortcommand), "env LC_ALL=C sort -T %s %s", tmpdir, temp1);
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();
@ -471,32 +447,22 @@ 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)
{
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));
}
/* seek to the trailer, in a given file */
void
seek_to_trailer(FILE *f)
{
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 */
@ -507,11 +473,8 @@ seek_to_trailer(FILE *f)
}
}
/* 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) {
@ -529,25 +492,18 @@ getoldfile(void)
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(compress == false) { dboffset += fprintf(newrefs, " -c"); }
if(invertedindex == true) {
dboffset += fprintf(newrefs, " -q %.10ld", totalterms);
} else {
@ -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,11 +520,8 @@ 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);
@ -583,19 +534,15 @@ putlist(char **names, int count)
fprintf(newrefs, "%d\n", size);
}
for(i = 0; i < count; ++i) {
if (fputs(names[i], newrefs) == EOF ||
putc('\n', newrefs) == EOF) {
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');
@ -612,13 +559,9 @@ copydata(void)
/* 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) {
char symbol[PATLEN + 1];
@ -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) */
@ -658,13 +599,9 @@ copyinverted(void)
/* 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;
}
if(cp == NULL) { break; }
switch(*cp) {
case '\n':
lineoffset = dboffset + 1;
@ -697,34 +634,25 @@ copyinverted(void)
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) {
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

@ -68,9 +68,7 @@ static void scrollbar(MOUSE *p);
/* read references from a file */
bool
readrefs(char *filename)
{
bool readrefs(char *filename) {
FILE *file;
int c;
@ -103,9 +101,7 @@ readrefs(char *filename)
}
/* scrollbar actions */
static void
scrollbar(MOUSE *p)
{
static void scrollbar(MOUSE *p) {
///* reposition list if it makes sense */
// if (totallines == 0) {
// return;
@ -140,11 +136,8 @@ scrollbar(MOUSE *p)
////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 */
@ -159,39 +152,27 @@ countrefs(void)
* since it's not used. But it has to be assigned just so the return value
* of fscanf will actually reach 4. */
while(EOF != (i = fscanf(refsfound,
"%" PATHLEN_STR "s%" PATLEN_STR "s%" NUMLEN_STR "s %" TEMPSTRING_LEN_STR "[^\n]",
file, function, linenum, tempstring
)
)
) {
if ( (i != 4)
|| !isgraph((unsigned char) *file)
|| !isgraph((unsigned char) *function)
|| !isdigit((unsigned char) *linenum)
) {
"%" 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((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 */
@ -91,6 +92,7 @@ enum {
FILENAME = 7,
INCLUDES = 8
};
#define FIELDS 10
// XXX

View File

@ -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;
@ -120,9 +117,7 @@ crossref(char *srcfile)
initscanner(srcfile);
fcnoffset = macrooffset = 0;
symbols = 0;
if (symbol == NULL) {
symbol = malloc(msymbols * sizeof(*symbol));
}
if(symbol == NULL) { symbol = malloc(msymbols * sizeof(*symbol)); }
for(;;) {
/* get the next token */
@ -130,8 +125,8 @@ crossref(char *srcfile)
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;
}
@ -141,18 +136,14 @@ crossref(char *srcfile)
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() */
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;
}
}
@ -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,9 +170,7 @@ 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();
}
if(symbols > 0) { putcrossref(); }
(void)fclose(yyin); /* close the source file */
/* output the leading tab expected by the next call */
@ -194,9 +182,7 @@ 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) {
msymbols += SYMBOLINC;
@ -213,9 +199,7 @@ 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) {
@ -223,18 +207,14 @@ putfilename(char *srcfile)
/* 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 */
@ -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;
@ -295,8 +273,7 @@ putcrossref(void)
blank = false;
}
j = i + strcspn(my_yytext + i, "\t ");
if (symput < symbols
&& j >= symbol[symput].first)
if(symput < symbols && j >= symbol[symput].first)
j = symbol[symput].first;
c = my_yytext[j];
my_yytext[j] = '\0';
@ -314,9 +291,8 @@ putcrossref(void)
} 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;
@ -345,10 +321,7 @@ putcrossref(void)
}
}
/* 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 */
@ -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,9 +363,7 @@ 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) {
case DEFINE:
@ -414,13 +380,9 @@ 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);
@ -457,9 +419,7 @@ 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;
@ -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;
}

226
src/dir.c
View File

@ -79,18 +79,13 @@ 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) {
fprintf(stderr, PROGRAM_NAME ": warning: cannot get current directory name\n");
@ -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;
@ -139,9 +132,12 @@ sourcedir(char *dirlist)
/* compute its path from higher view path source dirs */
for(i = 1; i < nvpsrcdirs; ++i) {
snprintf(path, sizeof(path), "%.*s/%s",
snprintf(path,
sizeof(path),
"%.*s/%s",
PATHLEN - 2 - dir_len,
srcdirs[i], dir);
srcdirs[i],
dir);
addsrcdir(path);
}
}
@ -152,14 +148,11 @@ 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) {
@ -172,11 +165,8 @@ addsrcdir(char *dir)
/* HBB 20000421: new function, for avoiding leaks */
/* free list of src directories */
void
freesrclist()
{
if (!srcdirs)
return;
void freesrclist() {
if(!srcdirs) return;
while(nsrcdirs > 1)
free(srcdirs[--nsrcdirs]);
free(srcdirs);
@ -184,9 +174,7 @@ freesrclist()
/* 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;
@ -207,9 +195,12 @@ includedir(char *dirlist)
/* compute its path from higher view path source dirs */
for(i = 1; i < nvpsrcdirs; ++i) {
snprintf(path, sizeof(path), "%.*s/%s",
snprintf(path,
sizeof(path),
"%.*s/%s",
(int)(PATHLEN - 2 - dir_len),
srcdirs[i], dir);
srcdirs[i],
dir);
addincdir(dir, path);
}
}
@ -220,14 +211,11 @@ 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(lstat(compath(path), &statstruct) == 0 && S_ISDIR(statstruct.st_mode)) {
if(incdirs == NULL) {
incdirs = malloc(mincdirs * sizeof(*incdirs));
incnames = malloc(mincdirs * sizeof(*incnames));
@ -244,11 +232,8 @@ 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;
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];
@ -283,8 +266,7 @@ makefilelist(void)
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,9 +275,7 @@ 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) {
/* No namefile --> make a list of all the source files
@ -323,8 +303,7 @@ makefilelist(void)
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;
@ -337,7 +316,9 @@ makefilelist(void)
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;
}
@ -381,7 +362,8 @@ makefilelist(void)
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", \
fprintf(stderr, \
"csope: -p option in file %s: missing or invalid numeric value\n", \
namefile); \
} \
dispcomponents = atoi(s); \
@ -396,7 +378,9 @@ 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('-') */
@ -412,10 +396,9 @@ makefilelist(void)
* 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;
@ -435,8 +418,7 @@ makefilelist(void)
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;
}
}
@ -452,8 +434,7 @@ makefilelist(void)
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;
}
}
@ -471,13 +452,10 @@ makefilelist(void)
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);
@ -488,21 +466,21 @@ scan_dir(const char *adir, bool recurse_dir)
char path[PATHLEN + 1];
while((entry = readdir(dirfile)) != NULL) {
if ((strcmp(".",entry->d_name) != 0)
&& (strcmp("..",entry->d_name) != 0)) {
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(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,19 +491,15 @@ 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 */
@ -550,8 +524,7 @@ issrcfile(char *path)
}
} 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 */
@ -561,30 +534,22 @@ issrcfile(char *path)
/* C++ template source */
&& ((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,9 +557,7 @@ 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) {
addsrcfile(s);
@ -604,15 +567,19 @@ incfile(char *file, char *type)
/* search for the file in the #include directory list */
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) {
addsrcfile(path);
@ -622,51 +589,34 @@ 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);
}
/* check if a file is readable enough to be allowed in the
* database */
static bool
accessible_file(char *file)
{
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 */
@ -675,12 +625,13 @@ inviewpath(char *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],
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);
@ -688,9 +639,7 @@ inviewpath(char *file)
/* add a source file to the list */
void
addsrcfile(char *path)
{
void addsrcfile(char *path) {
struct listitem *p;
int i;
@ -710,9 +659,7 @@ addsrcfile(char *path)
/* free the memory allocated for the source file list */
void
freefilelist(void)
{
void freefilelist(void) {
struct listitem *p, *nextp;
int i;
@ -724,8 +671,7 @@ freefilelist(void)
} 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;
}

View File

@ -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 */
@ -120,11 +118,69 @@ 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'
};
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];
@ -139,7 +195,8 @@ 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 */
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"},
@ -154,9 +211,7 @@ fields[FIELDS + 1] = { /* samuel has a search that is not part of the cscope
};
/* 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) {
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));
@ -221,9 +275,7 @@ dispinit(void)
}
/* enter curses mode */
void
entercurses(void)
{
void entercurses(void) {
incurses = true;
window_change = CH_ALL;
@ -240,9 +292,7 @@ entercurses(void)
}
/* exit curses mode */
void
exitcurses(void)
{
void exitcurses(void) {
/* clear the bottom line */
move(LINES - 1, 0);
clrtoeol();
@ -258,7 +308,8 @@ exitcurses(void)
}
static inline void display_help() {
// XXX: this could be optimized by only overriding the buffer if theres an actual change
// 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));
@ -314,9 +365,11 @@ static inline void display_mode(){
for(int i = 0; i < FIELDS; ++i) {
if(i == field) {
wattron(wmode, COLOR_PAIR(COLOR_PAIR_FIELD_SELECTED) | ATTRIBUTE_FIELD_SELECTED);
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);
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);
@ -334,6 +387,7 @@ static inline void display_command_field(){
display_cursor();
}
static inline void display_results() {
int i;
char *s;
@ -370,8 +424,12 @@ static inline void display_results(){
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);
@ -384,15 +442,12 @@ static inline void display_results(){
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) {
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 --- */
@ -402,12 +457,8 @@ static inline void display_results(){
/* NOTE: the +1s are column gaps */
srctxtw = second_col_width;
srctxtw -= 1 + 1; // dispchars
if (ogs == true) {
srctxtw -= subsystemlen+1 + booklen+1;
}
if (dispcomponents > 0) {
srctxtw -= filelen+1;
}
if(ogs == true) { srctxtw -= subsystemlen + 1 + booklen + 1; }
if(dispcomponents > 0) { srctxtw -= filelen + 1; }
if(field == SYMBOL || field == CALLEDBY || field == CALLING) {
srctxtw -= fcnlen + 1;
}
@ -425,32 +476,32 @@ static inline void display_results(){
there is no more room */
for(disprefs = 0, screenline = WRESULT_TABLE_BODY_START;
disprefs < mdisprefs && screenline < (result_window_height - 1);
++disprefs, ++screenline)
{
++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]) {
waddch(wresult, '>');
@ -460,7 +511,8 @@ 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) {
wprintw(wresult, "%-*s ", filelen, file);
@ -473,7 +525,10 @@ static inline void display_results(){
}
/* display the requested path components */
if(dispcomponents > 0) {
wprintw(wresult, "%-*.*s ", filelen, filelen,
wprintw(wresult,
"%-*.*s ",
filelen,
filelen,
pathcomponents(file, dispcomponents));
}
} /* else(field == FILENAME) */
@ -481,7 +536,9 @@ static inline void display_results(){
/* 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;
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));
@ -492,7 +549,8 @@ static inline void display_results(){
}
/* 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));
@ -502,7 +560,8 @@ static inline void display_results(){
}
/* 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(;;) {
@ -514,26 +573,20 @@ static inline void display_results(){
;
}
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 == ' ') {
++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) {
@ -571,8 +624,7 @@ endrefs:
i = result_window_height - 1;
if(screenline < i) {
waddch(wresult, '\n');
}
else {
} else {
wmove(wresult, i, 0);
}
/**/
@ -581,7 +633,12 @@ endrefs:
i = totallines - nextline + 1;
bottomline = nextline;
if(i > 0) {
wprintw(wresult, "* Lines %d-%d of %d, %d more. *", topref, bottomline, totallines, i);
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) {
@ -602,8 +659,8 @@ static inline void display_cursor(void){
i |= A_REVERSE;
waddch(*current_window, i);
}
void
horswp_field(void){
void horswp_field(void) {
if(current_window != &wresult) {
if(totallines == 0) { return; }
if(current_window == &winput) {
@ -615,36 +672,27 @@ horswp_field(void){
current_window = &wresult;
} 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){
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,15 +703,12 @@ 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;
@ -672,9 +717,7 @@ progress(char *what, long current, long max)
waddch(wresult, inch());
standend();
refresh();
}
else
if(linemode == false || verbosemode == true){
} else if(linemode == false || verbosemode == true) {
postmsg(lastmsg);
}
}
@ -682,9 +725,7 @@ 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);
@ -695,23 +736,18 @@ myperror(char *text)
/* postmsg clears the message line and prints the message */
void
postmsg(char *msg)
{
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)
{
void clearmsg2(void) {
if(linemode == false) {
wmove(wresult, MSGLINE + 1, 0);
wclrtoeol(wresult);
@ -719,13 +755,10 @@ clearmsg2(void)
}
/* postmsg2 clears the second message line and prints the message */
void
postmsg2(char *msg)
{
void postmsg2(char *msg) {
if(linemode == true) {
(void)printf("%s\n", msg);
}
else {
} else {
clearmsg2();
waddstr(wresult, msg);
wrefresh(wresult);
@ -733,15 +766,12 @@ 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)
{
if(linemode == true || incurses == false) {
(void)vfprintf(stderr, msg, ap);
(void)fputc('\n', stderr);
} else {
@ -752,18 +782,14 @@ 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);
@ -773,18 +799,14 @@ postfatal(const char *msg, ...)
}
/* 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);
s = buf;
if (*s == '/') {
++s;
}
if(*s == '/') { ++s; }
while((slash = strchr(s, '/')) != NULL) {
*slash = '\0';
if((int)strlen(s) >= 3 && strncmp(slash - 3, ".ss", 3) == 0) {
@ -819,9 +841,7 @@ static inline void display_tooltip(void){
wattroff(wtooltip, COLOR_PAIR(COLOR_PAIR_TOOLTIP));
}
void
display(void)
{
void display(void) {
// drawscrollbar(topline, nextline); /* display the scrollbar */
static void *lstwin = NULL; /* for the tooltip (see below) */
@ -835,9 +855,7 @@ 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.
*/
@ -845,15 +863,9 @@ display(void)
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

@ -44,16 +44,12 @@
/* 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);
@ -65,36 +61,31 @@ editref(int i)
/* 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;
}
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,11 +100,7 @@ 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
};
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);
@ -123,8 +110,7 @@ edit(char *file, const char *const linenum)
if(lineflagafterfile) {
execute(editor, editor, file, plusnum, NULL);
}
else {
} else {
execute(editor, editor, plusnum, file, NULL);
}
@ -134,9 +120,7 @@ edit(char *file, const char *const linenum)
/* 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 != '/') {

File diff suppressed because it is too large Load Diff

View File

@ -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 */

View File

@ -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;
@ -83,8 +82,7 @@ execute(char *a, ...) /* NOTE: "exec" is already defined on u370 */
#else
if((p = myfork()) == 0) {
myexecvp(a, argv); /* child */
}
else {
} else {
exitcode = join(p); /* parent */
}
#endif /* MSDOS */
@ -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,9 +116,7 @@ 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();
@ -145,17 +139,13 @@ myfork(void)
# 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;

View File

@ -114,33 +114,25 @@ extern struct TI fields[FIELDS + 1];
/* Internal prototypes: */
static void jumpback(int sig);
static void
jumpback(int sig)
{
static void jumpback(int sig) {
signal(sig, jumpback);
siglongjmp(env, 1);
}
/* find the symbol in the cross-reference */
char *
findsymbol(const char *pattern)
{
char *findsymbol(const char *pattern) {
return find_symbol_or_assignment(pattern, false);
}
/* find the symbol in the cross-reference, and look for assignments */
char *
findassign(const char *pattern)
{
char *findassign(const char *pattern) {
return find_symbol_or_assignment(pattern, true);
}
/* Test reference whether it's an assignment to the symbol found at
* (global variable) 'blockp' */
static bool
check_for_assignment(void)
{
static bool check_for_assignment(void) {
/* Do the extra work here to determine if this is an
* assignment or not. Do this by examining the next character
* or two in blockp */
@ -152,8 +144,7 @@ check_for_assignment(void)
if(asgn_char[0] == '\0') {
/* get the next block when we reach the end of
* the current block */
if (NULL == (asgn_char = read_block()))
return false;
if(NULL == (asgn_char = read_block())) return false;
}
}
/* check for digraph starting with = */
@ -168,37 +159,28 @@ check_for_assignment(void)
}
/* check for operator assignments: +=, ... ^= ? */
if ( ( (asgn_char[0] == '+')
|| (asgn_char[0] == '-')
|| (asgn_char[0] == '*')
|| (asgn_char[0] == '/')
|| (asgn_char[0] == '%')
|| (asgn_char[0] == '&')
|| (asgn_char[0] == '|')
|| (asgn_char[0] == '^')
)
&& ((asgn_char[1] == '=') || ((asgn_char[1] & 0x80) && (dichar1[(asgn_char[1] &0177)/8] == '=')))
if(((asgn_char[0] == '+') || (asgn_char[0] == '-') || (asgn_char[0] == '*') ||
(asgn_char[0] == '/') || (asgn_char[0] == '%') || (asgn_char[0] == '&') ||
(asgn_char[0] == '|') || (asgn_char[0] == '^')) &&
((asgn_char[1] == '=') ||
((asgn_char[1] & 0x80) && (dichar1[(asgn_char[1] & 0177) / 8] == '=')))
) {
return true;
}
/* check for two-letter operator assignments: <<= or >>= ? */
if ( ( (asgn_char[0] == '<')
|| (asgn_char[0] == '>')
)
&& (asgn_char[1] == asgn_char[0])
&& ((asgn_char[2] == '=') || ((asgn_char[2] & 0x80) && (dichar1[(asgn_char[2] & 0177)/8] == '=')))
)
if(((asgn_char[0] == '<') || (asgn_char[0] == '>')) &&
(asgn_char[1] == asgn_char[0]) &&
((asgn_char[2] == '=') ||
((asgn_char[2] & 0x80) && (dichar1[(asgn_char[2] & 0177) / 8] == '='))))
return true;
return false;
}
/* The actual routine that does the work for findsymbol() and
* findassign() */
static char *
find_symbol_or_assignment(const char *pattern, bool assign_flag)
{
static char *find_symbol_or_assignment(const char *pattern, bool assign_flag) {
char file[PATHLEN + 1]; /* source file name */
char function[PATLEN + 1]; /* function name */
char macro[PATLEN + 1]; /* macro name */
@ -242,12 +224,8 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
} while(*(cp + 1) == '\0' && (cp = read_block()) != NULL);
/* skip the found character */
if (cp != NULL && *(++cp + 1) == '\0') {
cp = read_block();
}
if (cp == NULL) {
break;
}
if(cp != NULL && *(++cp + 1) == '\0') { cp = read_block(); }
if(cp == NULL) { break; }
/* look for a source file, function, or macro name */
if(*cp == '\t') {
blockp = cp;
@ -260,9 +238,7 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
fetch_string_from_dbase(file, sizeof(file));
/* check for the end of the symbols */
if (*file == '\0') {
return NULL;
}
if(*file == '\0') { return NULL; }
progress("Search", searchcount, nsrcfiles);
/* FALLTHROUGH */
@ -303,9 +279,7 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
/* see if this is a regular expression pattern */
if(isregexp_valid == true) {
if (caseless == true) {
s = lcasify(s);
}
if(caseless == true) { s = lcasify(s); }
if(*s != '\0' && regexec(&regexp, s, (size_t)0, NULL, 0) == 0) {
goto matched;
}
@ -330,8 +304,7 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
**************************************************/
if(*cp & 0200) { /* digraph char? */
firstchar = dichar1[(*cp & 0177) / 8];
}
else {
} else {
firstchar = *cp;
}
@ -340,8 +313,7 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
fetch_string_from_dbase(symbol, sizeof(symbol));
if(caseless == true) {
s = lcasify(symbol); /* point to lower case version */
}
else {
} else {
s = symbol;
}
@ -363,27 +335,21 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
/* if the assignment flag is set then
* we are looking for assignments and
* some extra filtering is needed */
if(assign_flag == true
&& ! check_for_assignment())
goto notmatched;
if(assign_flag == true && !check_for_assignment()) goto notmatched;
/* output the file, function or macro, and source line */
if(strcmp(macro, global) && s != macro) {
putref(0, file, macro);
}
else if (fcndef == true || s != function) {
} else if(fcndef == true || s != function) {
fcndef = false;
putref(0, file, function);
}
else {
} else {
putref(0, file, global);
}
}
notmatched:
if (blockp == NULL) {
return NULL;
}
if(blockp == NULL) { return NULL; }
fcndef = false;
cp = blockp;
}
@ -392,11 +358,10 @@ find_symbol_or_assignment(const char *pattern, bool assign_flag)
return NULL;
}
/* find the function definition or #define */
char *
finddef(const char *pattern)
{
char *finddef(const char *pattern) {
char file[PATHLEN + 1]; /* source file name */
if(invertedindex == true) {
@ -455,11 +420,10 @@ finddef(const char *pattern)
return NULL;
}
/* find all function definitions (used by samuel only) */
char *
findallfcns(const char *dummy)
{
char *findallfcns(const char *dummy) {
char file[PATHLEN + 1]; /* source file name */
char function[PATLEN + 1]; /* function name */
@ -497,9 +461,7 @@ findallfcns(const char *dummy)
/* find the functions calling this function */
char *
findcalling(const char *pattern)
{
char *findcalling(const char *pattern) {
char file[PATHLEN + 1]; /* source file name */
char function[PATLEN + 1]; /* function name */
char tmpfunc[10][PATLEN + 1]; /* 10 temporary function names */
@ -512,9 +474,7 @@ findcalling(const char *pattern)
findterm(pattern);
while((p = getposting()) != NULL) {
if (p->type == FCNCALL) {
putpostingref(p, 0);
}
if(p->type == FCNCALL) { putpostingref(p, 0); }
}
return NULL;
}
@ -522,7 +482,8 @@ findcalling(const char *pattern)
*macro = '\0'; /* a macro can be inside a function, but not vice versa */
tmpblockp = 0;
morefuns = 0; /* one function definition is normal case */
for (i = 0; i < 10; i++) *(tmpfunc[i]) = '\0';
for(i = 0; i < 10; i++)
*(tmpfunc[i]) = '\0';
while(scanpast('\t') != NULL) {
switch(*blockp) {
@ -551,8 +512,7 @@ findcalling(const char *pattern)
skiprefchar();
fetch_string_from_dbase(function, sizeof(function));
for(i = 0; i < morefuns; i++)
if ( !strcmp(tmpfunc[i], function) )
break;
if(!strcmp(tmpfunc[i], function)) break;
if(i == morefuns) {
(void)strcpy(tmpfunc[morefuns], function);
if(++morefuns >= 10) morefuns = 9;
@ -572,8 +532,7 @@ findcalling(const char *pattern)
/* output the file, calling function or macro, and source */
if(*macro != '\0') {
putref(1, file, macro);
}
else {
} else {
tmpblockp = blockp;
for(i = 0; i < morefuns; i++) {
blockp = tmpblockp;
@ -589,18 +548,14 @@ findcalling(const char *pattern)
/* find the text in the source files */
char *
findstring(const char *pattern)
{
char *findstring(const char *pattern) {
char egreppat[2 * PATLEN];
char *cp = egreppat;
const char *pp;
/* translate special characters in the regular expression */
for(pp = pattern; *pp != '\0'; ++pp) {
if (strchr(".*[\\^$+?|()", *pp) != NULL) {
*cp++ = '\\';
}
if(strchr(".*[\\^$+?|()", *pp) != NULL) { *cp++ = '\\'; }
*cp++ = *pp;
}
*cp = '\0';
@ -611,9 +566,7 @@ findstring(const char *pattern)
/* find this regular expression in the source files */
char *
findregexp(const char *egreppat)
{
char *findregexp(const char *egreppat) {
unsigned int i;
char *egreperror;
@ -635,9 +588,7 @@ findregexp(const char *egreppat)
/* find matching file names */
char *
findfile(const char *dummy)
{
char *findfile(const char *dummy) {
unsigned int i;
(void)dummy; /* unused argument */
@ -651,8 +602,7 @@ findfile(const char *dummy)
s = srcfiles[i];
}
if(regexec(&regexp, s, (size_t)0, NULL, 0) == 0) {
(void) fprintf(refsfound, "%s <unknown> 1 <unknown>\n",
srcfiles[i]);
(void)fprintf(refsfound, "%s <unknown> 1 <unknown>\n", srcfiles[i]);
}
}
@ -661,9 +611,7 @@ findfile(const char *dummy)
/* find files #including this file */
char *
findinclude(const char *pattern)
{
char *findinclude(const char *pattern) {
char file[PATHLEN + 1]; /* source file name */
if(invertedindex == true) {
@ -671,9 +619,7 @@ findinclude(const char *pattern)
findterm(pattern);
while((p = getposting()) != NULL) {
if (p->type == INCLUDE) {
putpostingref(p, 0);
}
if(p->type == INCLUDE) { putpostingref(p, 0); }
}
return NULL;
}
@ -707,9 +653,7 @@ findinclude(const char *pattern)
/* initialize */
int
findinit(const char *pattern_)
{
int findinit(const char *pattern_) {
char *pattern = strdup(pattern_);
int r = NOERROR;
char buf[PATLEN + 3];
@ -719,24 +663,19 @@ findinit(const char *pattern_)
unsigned char c;
/* HBB: be nice: free regexp before allocating a new one */
if(isregexp_valid == true)
regfree(&regexp);
if(isregexp_valid == true) regfree(&regexp);
isregexp_valid = false;
/* remove trailing white space */
for (s = pattern + strlen(pattern) - 1;
isspace((unsigned char)*s);
--s) {
for(s = pattern + strlen(pattern) - 1; isspace((unsigned char)*s); --s) {
*s = '\0';
}
/* Make sure pattern is lowercased. Curses
* mode gets this right all on its own, but at least -L mode
* doesn't */
if (caseless == true) {
pattern = lcasify(pattern);
}
if(caseless == true) { pattern = lcasify(pattern); }
/* allow a partial match for a file name */
if(field == FILENAME || field == INCLUDES) {
@ -765,8 +704,8 @@ findinit(const char *pattern_)
}
/* look for use of the -T option (truncate symbol to 8
characters) on a database not built with -T */
if (trun_syms == true && isuptodate == true &&
dbtruncated == false && s - pattern >= 8) {
if(trun_syms == true && isuptodate == true && dbtruncated == false &&
s - pattern >= 8) {
(void)strcpy(pattern + 8, ".*");
isregexp = true;
}
@ -784,15 +723,11 @@ findinit(const char *pattern_)
/* remove a trailing $ */
i = strlen(s) - 1;
if(s[i] == '$') {
if (i > 0 && s[i-1] == '\\' ) {
s[i-1] = '$';
}
if(i > 0 && s[i - 1] == '\\') { s[i - 1] = '$'; }
s[i] = '\0';
}
/* if requested, try to truncate a C symbol pattern */
if (trun_syms == true && strpbrk(s, "[{*+") == NULL) {
s[8] = '\0';
}
if(trun_syms == true && strpbrk(s, "[{*+") == NULL) { s[8] = '\0'; }
/* must be an exact match */
/* note: regcomp doesn't recognize ^*keypad$ as a syntax error
unless it is given as a single arg */
@ -800,17 +735,12 @@ findinit(const char *pattern_)
if(regcomp(&regexp, buf, REG_EXTENDED | REG_NOSUB) != 0) {
r = REGCMPERROR;
goto end;
}
else
{
} else {
isregexp_valid = true;
}
}
else {
} else {
/* if requested, truncate a C symbol pattern */
if (trun_syms == true && field <= CALLING) {
pattern[8] = '\0';
}
if(trun_syms == true && field <= CALLING) { pattern[8] = '\0'; }
/* compress the string pattern for matching */
s = cpattern;
for(i = 0; (c = pattern[i]) != '\0'; ++i) {
@ -828,29 +758,22 @@ findinit(const char *pattern_)
return r;
}
void
findcleanup(void)
{
void findcleanup(void) {
/* discard any regular expression */
}
/* match the pattern to the string */
static bool
match(void)
{
static bool match(void) {
char string[PATLEN + 1];
/* see if this is a regular expression pattern */
if(isregexp_valid == true) {
fetch_string_from_dbase(string, sizeof(string));
if (*string == '\0') {
return(false);
}
if(*string == '\0') { return (false); }
if(caseless == true) {
return (regexec(&regexp, lcasify(string), (size_t)0, NULL, 0) ? false : true);
}
else {
} else {
return (regexec(&regexp, string, (size_t)0, NULL, 0) ? false : true);
}
}
@ -860,9 +783,7 @@ match(void)
/* match the rest of the pattern to the name */
static bool
matchrest(void)
{
static bool matchrest(void) {
int i = 1;
skiprefchar();
@ -873,23 +794,18 @@ matchrest(void)
}
} while(*(blockp + 1) == '\0' && read_block() != NULL);
if (*blockp == '\n' && cpattern[i] == '\0') {
return(true);
}
if(*blockp == '\n' && cpattern[i] == '\0') { return (true); }
return (false);
}
/* put the reference into the file */
static void
putref(int seemore, const char *file, const char *func)
{
static void putref(int seemore, const char *file, const char *func) {
FILE *output;
if(strcmp(func, global) == 0) {
output = refsfound;
}
else {
} else {
output = nonglobalrefs;
}
(void)fprintf(output, "%s %s ", file, func);
@ -898,9 +814,7 @@ putref(int seemore, const char *file, const char *func)
/* put the source line into the file */
static void
putsource(int seemore, FILE *output)
{
static void putsource(int seemore, FILE *output) {
char *tmpblockp;
char *cp, nextc = '\0';
bool Change = false, retreat = false;
@ -936,8 +850,7 @@ putsource(int seemore, FILE *output)
* point to different blocks. Offset comparison should
* falseT be performed until they point to the same block.
*/
if (seemore && Change == false && retreat == false &&
blockp > tmpblockp) {
if(seemore && Change == false && retreat == false && blockp > tmpblockp) {
Change = true;
cp = blockp;
}
@ -954,9 +867,7 @@ putsource(int seemore, FILE *output)
/* put the rest of the cross-reference line into the file */
static void
putline(FILE *output)
{
static void putline(FILE *output) {
char *cp;
unsigned c;
@ -974,14 +885,9 @@ putline(FILE *output)
/* check for a compressed keyword */
else if(c < ' ') {
(void)fputs(keyword[c].text, output);
if (keyword[c].delim != '\0') {
(void) putc(' ', output);
}
if (keyword[c].delim == '(') {
(void) putc('(', output);
}
}
else {
if(keyword[c].delim != '\0') { (void)putc(' ', output); }
if(keyword[c].delim == '(') { (void)putc('(', output); }
} else {
(void)putc((int)c, output);
}
++cp;
@ -990,11 +896,8 @@ putline(FILE *output)
blockp = cp;
}
/* put the rest of the cross-reference line into the string */
void
fetch_string_from_dbase(char *s, size_t length)
{
void fetch_string_from_dbase(char *s, size_t length) {
char *cp;
unsigned int c;
@ -1020,11 +923,8 @@ fetch_string_from_dbase(char *s, size_t length)
*s = '\0';
}
/* scan past the next occurence of this character in the cross-reference */
char *
scanpast(char c)
{
char *scanpast(char c) {
char *cp;
setmark(c);
@ -1035,17 +935,13 @@ scanpast(char c)
}
} while(*(cp + 1) == '\0' && (cp = read_block()) != NULL);
blockp = cp;
if (cp != NULL) {
skiprefchar(); /* skip the found character */
}
if(cp != NULL) { skiprefchar(); /* skip the found character */ }
return (blockp);
}
/* read a block of the cross-reference */
/* HBB 20040430: renamed from readblock(), to avoid name clash on QNX */
char *
read_block(void)
{
char *read_block(void) {
/* read the next block */
blocklen = read(symrefs, block, BUFSIZ);
blockp = block;
@ -1057,16 +953,13 @@ read_block(void)
/* return NULL on end-of-file */
if(blocklen == 0) {
blockp = NULL;
}
else {
} else {
++blocknumber;
}
return (blockp);
}
static char *
lcasify(const char *s)
{
static char *lcasify(const char *s) {
static char ls[PATLEN + 1]; /* largest possible match string */
char *lptr = ls;
@ -1086,9 +979,7 @@ lcasify(const char *s)
* too. Implemented as a pointer to static storage containing 'y' or
* 'n', for the boolean result values true and false */
char *
findcalledby(const char *pattern)
{
char *findcalledby(const char *pattern) {
char file[PATHLEN + 1]; /* source file name */
static char found_caller = 'n'; /* seen calling function? */
bool macro = false;
@ -1124,9 +1015,7 @@ findcalledby(const char *pattern)
break;
case DEFINE: /* could be a macro */
if (fileversion < 10) {
break;
}
if(fileversion < 10) { break; }
macro = true;
/* FALLTHROUGH */
@ -1145,9 +1034,7 @@ findcalledby(const char *pattern)
/* find this term, which can be a regular expression */
static void
findterm(const char *pattern)
{
static void findterm(const char *pattern) {
char *s;
int len;
char prefix[PATLEN + 1];
@ -1159,9 +1046,7 @@ findterm(const char *pattern)
/* get the string prefix (if any) of the regular expression */
(void)strcpy(prefix, pattern);
if ((s = strpbrk(prefix, ".[{*+")) != NULL) {
*s = '\0';
}
if((s = strpbrk(prefix, ".[{*+")) != NULL) { *s = '\0'; }
/* if letter case is to be ignored */
if(caseless == true) {
@ -1180,23 +1065,17 @@ findterm(const char *pattern)
}
/* a null prefix matches the null term in the inverted index,
so move to the first real term */
if (*prefix == '\0') {
(void) invforward(&invcontrol);
}
if(*prefix == '\0') { (void)invforward(&invcontrol); }
len = strlen(prefix);
do {
(void)invterm(&invcontrol, term); /* get the term */
s = term;
if (caseless == true) {
s = lcasify(s); /* make it lower case */
}
if(caseless == true) { s = lcasify(s); /* make it lower case */ }
/* if it matches */
if(regexec(&regexp, s, (size_t)0, NULL, 0) == 0) {
/* add its postings to the set */
if ((postingp = boolfile(&invcontrol, &npostings, bool_OR)) == NULL) {
break;
}
if((postingp = boolfile(&invcontrol, &npostings, bool_OR)) == NULL) { break; }
}
/* if there is a prefix */
else if(len > 0) {
@ -1204,9 +1083,7 @@ findterm(const char *pattern)
/* if ignoring letter case and the term is out of the
range of possible matches */
if(caseless == true) {
if (strncmp(term, prefix, len) > 0) {
break; /* stop searching */
}
if(strncmp(term, prefix, len) > 0) { break; /* stop searching */ }
}
/* if using letter case and the prefix doesn't match */
else if(strncmp(term, prefix, len) != 0) {
@ -1226,25 +1103,18 @@ findterm(const char *pattern)
/* get the next posting for this term */
static POSTING *
getposting(void)
{
if (npostings-- <= 0) {
return(NULL);
}
static POSTING *getposting(void) {
if(npostings-- <= 0) { return (NULL); }
/* display progress about every three seconds */
if(++searchcount % 100 == 0) {
progress("Possible references retrieved", searchcount,
postingsfound);
progress("Possible references retrieved", searchcount, postingsfound);
}
return (postingp++);
}
/* put the posting reference into the file */
static void
putpostingref(POSTING *p, const char *pat)
{
static void putpostingref(POSTING *p, const char *pat) {
// initialize function to "unknown" so that the first line of temp1
// is properly formed if symbol matches a header file entry first time
static char function[PATLEN + 1] = "unknown"; /* function name */
@ -1255,12 +1125,10 @@ putpostingref(POSTING *p, const char *pat)
scanpast(FCNDEF);
fetch_string_from_dbase(function, sizeof(function));
}
}
else if (p->type != FCNCALL) {
} else if(p->type != FCNCALL) {
strcpy(function, global);
}
}
else if (p->fcnoffset != lastfcnoffset) {
} else if(p->fcnoffset != lastfcnoffset) {
if(dbseek(p->fcnoffset) != -1) {
fetch_string_from_dbase(function, sizeof(function));
lastfcnoffset = p->fcnoffset;
@ -1276,9 +1144,7 @@ putpostingref(POSTING *p, const char *pat)
/* seek to the database offset */
long
dbseek(long offset)
{
long dbseek(long offset) {
long n;
int rc = 0;
@ -1295,17 +1161,14 @@ dbseek(long offset)
return (rc);
}
static void
findcalledbysub(const char *file, bool macro)
{
static void findcalledbysub(const char *file, bool macro) {
/* find the next function call or the end of this function */
while(scanpast('\t') != NULL) {
switch(*blockp) {
case DEFINE: /* #define inside a function */
if(fileversion >= 10) { /* skip it */
while (scanpast('\t') != NULL &&
*blockp != DEFINEEND)
while(scanpast('\t') != NULL && *blockp != DEFINEEND)
;
}
break;
@ -1327,9 +1190,7 @@ findcalledbysub(const char *file, bool macro)
case DEFINEEND: /* #define end */
if(invertedindex == false) {
if (macro == true) {
return;
}
if(macro == true) { return; }
break; /* inside a function */
}
/* FALLTHROUGH */
@ -1347,9 +1208,7 @@ findcalledbysub(const char *file, bool macro)
}
/* open the references found file for writing */
bool
writerefsfound(void)
{
bool writerefsfound(void) {
if(refsfound == NULL) {
if((refsfound = myfopen(temp1, "wb")) == NULL) {
cannotopen(temp1);
@ -1366,9 +1225,7 @@ writerefsfound(void)
}
/* Perform token search based on "field" */
bool
search(const char* query)
{
bool search(const char *query) {
char msg[MSGLEN + 1];
char *findresult = NULL; /* find function output */
bool funcexist = true; /* find "function" error */
@ -1378,13 +1235,9 @@ search(const char* query)
int c;
/* open the references found file for writing */
if (writerefsfound() == false) {
return(false);
}
if(writerefsfound() == false) { return (false); }
/* find the pattern - stop on an interrupt */
if (linemode == false) {
postmsg("Searching");
}
if(linemode == false) { postmsg("Searching"); }
searchcount = 0;
savesig = signal(SIGINT, jumpback);
if(sigsetjmp(env, 1) == 0) {
@ -1399,14 +1252,12 @@ search(const char* query)
if((rc = findinit(query)) == NOERROR) {
(void)dbseek(0L); /* read the first block */
findresult = (*f)(query);
if (f == findcalledby)
funcexist = (*findresult == 'y');
if(f == findcalledby) funcexist = (*findresult == 'y');
findcleanup();
/* append the non-global references */
(void)fclose(nonglobalrefs);
if ((nonglobalrefs = myfopen(temp2, "rb"))
== NULL) {
if((nonglobalrefs = myfopen(temp2, "rb")) == NULL) {
cannotopen(temp2);
return (false);
}
@ -1435,21 +1286,30 @@ search(const char* query)
/* see if it is empty */
if((c = getc(refsfound)) == EOF) {
if(findresult != NULL) {
(void) snprintf(msg, sizeof(msg), "Egrep %s in this pattern: %s",
findresult, query);
} else if (rc == NOTSYMBOL) {
(void) snprintf(msg, sizeof(msg), "This is not a C symbol: %s",
(void)snprintf(msg,
sizeof(msg),
"Egrep %s in this pattern: %s",
findresult,
query);
} else if(rc == NOTSYMBOL) {
(void)snprintf(msg, sizeof(msg), "This is not a C symbol: %s", query);
} else if(rc == REGCMPERROR) {
(void) snprintf(msg, sizeof(msg), "Error in this regcomp(3) regular expression: %s",
(void)snprintf(msg,
sizeof(msg),
"Error in this regcomp(3) regular expression: %s",
query);
} else if(funcexist == false) {
(void) snprintf(msg, sizeof(msg), "Function definition does not exist: %s",
(void)snprintf(msg,
sizeof(msg),
"Function definition does not exist: %s",
query);
} else {
(void) snprintf(msg, sizeof(msg), "Could not find the %s: %s",
fields[field].text2, query);
(void)snprintf(msg,
sizeof(msg),
"Could not find the %s: %s",
fields[field].text2,
query);
}
postmsg(msg);
return (false);

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 */
@ -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);

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,12 +94,9 @@ 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)
{
const char *help(void) {
if(input_mode == INPUT_CHANGE) {
return help_msg;
} else {
@ -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,8 +42,7 @@
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;
@ -63,9 +62,7 @@ addcmd(int f, char *s) /* field number and command text */
}
/* return previous history item */
struct cmd *
prevcmd(void)
{
struct cmd *prevcmd(void) {
if(current) {
if(current->prev) /* stay on first item */
return current = current->prev;
@ -78,9 +75,7 @@ prevcmd(void)
}
/* return next history item */
struct cmd *
nextcmd(void)
{
struct cmd *nextcmd(void) {
if(current) {
if(current->next) /* stay on first item */
return current = current->next;
@ -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,32 +64,26 @@ 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;
@ -151,16 +144,14 @@ 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){
static int wmode_input(const int c) {
switch(c) {
case KEY_ENTER:
case '\r':
@ -192,8 +183,7 @@ wmode_input(const int c){
return 1;
}
static int
wresult_input(const int c){
static int wresult_input(const int c) {
switch(c) {
case KEY_ENTER: /* open for editing */
case '\r':
@ -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;
@ -234,8 +220,7 @@ wresult_input(const int c){
return 1;
}
static int
global_input(const int c){
static int global_input(const int c) {
switch(c) {
case '\t':
horswp_field();
@ -290,18 +275,12 @@ global_input(const int c){
////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;
@ -347,7 +326,8 @@ global_input(const int c){
// }
// exitcurses();
// if ((file = mypopen(newpat, "w")) == NULL) {
// fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat);
// fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n",
// newpat);
// } else {
// seekline(1);
// while ((c = getc(refsfound)) != EOF) {
@ -393,8 +373,7 @@ 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) {
@ -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];
}
@ -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 */
@ -480,10 +453,11 @@ changestring(const char* from,
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; }
@ -497,9 +471,7 @@ changestring(const char* from,
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,9 +480,7 @@ 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(strchr("/\\[.^*", *s) != NULL) { putc('\\', script); }
if(caseless == true && isalpha((unsigned char)*s)) {
putc('[', script);
if(islower((unsigned char)*s)) {
@ -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,8 +514,7 @@ 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) {
do_press_any_key = false;

View File

@ -86,10 +86,12 @@ static POSTING *POST, *postptr;
static unsigned long *SUPINT, *supint, nextsupfing;
static char *SUPFING, *supfing;
static char thisterm[TERMMAX];
typedef union logicalblk {
long invblk[BLOCKSIZE / sizeof(long)];
char chrblk[BLOCKSIZE];
} t_logicalblk;
static t_logicalblk logicalblk;
#if DEBUG || STATS
@ -100,9 +102,7 @@ static long totpost;
static int zipf[ZIPFSIZE + 1];
#endif
long
invmake(char *invname, char *invpost, FILE *infile)
{
long invmake(char *invname, char *invpost, FILE *infile) {
unsigned char *s;
long num;
int i;
@ -181,14 +181,11 @@ invmake(char *invname, char *invpost, FILE *infile)
s = strchr(line, SEP);
if(s != NULL) {
*s = '\0';
}
else {
} else {
continue;
}
#if STATS
if ((i = strlen(line)) > maxtermlen) {
maxtermlen = i;
}
if((i = strlen(line)) > maxtermlen) { maxtermlen = i; }
#endif
#if DEBUG
printf("%ld: %s ", totpost, line);
@ -204,16 +201,13 @@ invmake(char *invname, char *invpost, FILE *infile)
}
postptr = i + POST;
#if DEBUG
printf("reallocated post space to %u, totpost=%ld\n",
postsize, totpost);
printf("reallocated post space to %u, totpost=%ld\n", postsize, totpost);
#endif
}
numpost++;
} else {
/* have a new term */
if (!invnewterm()) {
return(0);
}
if(!invnewterm()) { return (0); }
strcpy(thisterm, line);
numpost = 1;
postptr = POST;
@ -238,33 +232,29 @@ invmake(char *invname, char *invpost, FILE *infile)
num = BASE * num + *s - '!';
}
posting.fcnoffset = num;
}
else {
} else {
posting.fcnoffset = 0;
}
*postptr++ = posting;
#if DEBUG
printf("%ld %ld %ld %ld\n", posting.fileindex,
posting.fcnoffset, posting.lineoffset, posting.type);
printf("%ld %ld %ld %ld\n",
posting.fileindex,
posting.fcnoffset,
posting.lineoffset,
posting.type);
fflush(stdout);
#endif
}
if (!invnewterm()) {
return(0);
}
if(!invnewterm()) { return (0); }
/* now clean up final block */
logicalblk.invblk[0] = numinvitems;
/* loops pointer around to start */
logicalblk.invblk[1] = 0;
logicalblk.invblk[2] = numlogblk - 1;
if (fwrite(&logicalblk, sizeof(t_logicalblk), 1, outfile) == 0) {
goto cannotwrite;
}
if(fwrite(&logicalblk, sizeof(t_logicalblk), 1, outfile) == 0) { goto cannotwrite; }
numlogblk++;
/* write out block to save space. what in it doesn't matter */
if (fwrite(&logicalblk, sizeof(t_logicalblk), 1, outfile) == 0) {
goto cannotwrite;
}
if(fwrite(&logicalblk, sizeof(t_logicalblk), 1, outfile) == 0) { goto cannotwrite; }
/* finish up the super finger */
*SUPINT = numlogblk;
/* add to the offsets the size of the offset pointers */
@ -293,17 +283,14 @@ invmake(char *invname, char *invpost, FILE *infile)
param.version = FMTVERSION;
param.filestat = 0;
param.sizeblk = sizeof(t_logicalblk);
param.startbyte = (numlogblk + 1) * sizeof(t_logicalblk) + BUFSIZ;;
param.startbyte = (numlogblk + 1) * sizeof(t_logicalblk) + BUFSIZ;
;
param.supsize = nextsupfing;
param.cntlsize = BUFSIZ;
param.share = 0;
if (fwrite(&param, sizeof(param), 1, outfile) == 0) {
goto cannotwrite;
}
if(fwrite(&param, sizeof(param), 1, outfile) == 0) { goto cannotwrite; }
for(i = 0; i < 10; i++) /* for future use */
if (fwrite(&zerolong, sizeof(zerolong), 1, outfile) == 0) {
goto cannotwrite;
}
if(fwrite(&zerolong, sizeof(zerolong), 1, outfile) == 0) { goto cannotwrite; }
/* make first block loop backwards to last block */
if(fflush(outfile) == EOF) { /* fseek doesn't check for write failure */
@ -312,8 +299,7 @@ invmake(char *invname, char *invpost, FILE *infile)
/* get to second word first block */
fseek(outfile, BUFSIZ + 2 * sizeof(long), SEEK_SET);
tlong = numlogblk - 1;
if (fwrite(&tlong, sizeof(tlong), 1, outfile) == 0 ||
fclose(outfile) == EOF) {
if(fwrite(&tlong, sizeof(tlong), 1, outfile) == 0 || fclose(outfile) == EOF) {
cannotwrite:
invcannotwrite(invname);
return (0);
@ -325,12 +311,14 @@ invmake(char *invname, char *invpost, FILE *infile)
--totterm; /* don't count null term */
#if STATS
printf("logical blocks = %d, postings = %ld, terms = %ld, max term length = %d\n",
numlogblk, totpost, totterm, maxtermlen);
numlogblk,
totpost,
totterm,
maxtermlen);
if(showzipf) {
printf("\n************* ZIPF curve ****************\n");
for(j = ZIPFSIZE; j > 1; j--)
if (zipf[j])
break;
if(zipf[j]) break;
for(i = 1; i < j; ++i) {
printf("%3d -%6d ", i, zipf[i]);
if(i % 6 == 0) putchar('\n');
@ -347,9 +335,7 @@ invmake(char *invname, char *invpost, FILE *infile)
/* add a term to the data base */
static int
invnewterm(void)
{
static int invnewterm(void) {
int backupflag, i, j, holditems, gooditems, howfar;
unsigned int maxback, len, numwilluse, wdlen;
char *tptr, *tptr3;
@ -387,7 +373,8 @@ invnewterm(void)
supfing = i + SUPFING;
#if DEBUG
printf("reallocated superfinger space to %d, totpost=%ld\n",
supersize, totpost);
supersize,
totpost);
#endif
}
/* check that room for the offset as well */
@ -401,15 +388,16 @@ invnewterm(void)
}
supint = i + SUPINT;
#if DEBUG
printf("reallocated superfinger offset to %d, totpost = %ld\n", supintsize * sizeof(*SUPINT), totpost);
printf("reallocated superfinger offset to %d, totpost = %ld\n",
supintsize * sizeof(*SUPINT),
totpost);
#endif
}
/* See if backup is efficatious */
backupflag = 0;
maxback = (int)strlen(thisterm) / 10;
holditems = numinvitems;
if (maxback > numinvitems)
maxback = numinvitems - 2;
if(maxback > numinvitems) maxback = numinvitems - 2;
howfar = 0;
while(maxback-- > 1) {
howfar++;
@ -422,9 +410,7 @@ invnewterm(void)
}
}
/* see if backup will occur */
if (backupflag) {
numinvitems = gooditems;
}
if(backupflag) { numinvitems = gooditems; }
logicalblk.invblk[0] = numinvitems;
/* set forward pointer pointing to next */
logicalblk.invblk[1] = numlogblk + 1;
@ -454,8 +440,7 @@ invnewterm(void)
strncpy(supfing, tptr2, (int)iteminfo.e.size);
*(supfing + iteminfo.e.size) = '\0';
#if DEBUG
printf("backup %d at term=%s to term=%s\n",
backupflag, thisterm, supfing);
printf("backup %d at term=%s to term=%s\n", backupflag, thisterm, supfing);
#endif
*supint++ = nextsupfing;
nextsupfing += strlen(supfing) + 1;
@ -513,9 +498,7 @@ invnewterm(void)
* returns 0. Otherwise, returns -1.
*/
static int
invflipname(char * invname, const char *from, const char *to)
{
static int invflipname(char *invname, const char *from, const char *to) {
char *temp, *i = NULL;
assert(strlen(from) == strlen(to));
@ -523,8 +506,7 @@ invflipname(char * invname, const char *from, const char *to)
temp = invname - 1;
while((temp = strstr(temp + 1, from)))
i = temp;
if (!i || i[strlen(from)] != '\0')
return -1;
if(!i || i[strlen(from)] != '\0') return -1;
while(*to)
*i++ = *to++;
return 0;
@ -532,9 +514,7 @@ invflipname(char * invname, const char *from, const char *to)
/* small helper function to centralize handling of binary opening
* for reading, and use of the 'stat" flag */
static FILE *
open_for_reading(char *name, int stat)
{
static FILE *open_for_reading(char *name, int stat) {
return vpfopen(name, ((stat == 0) ? "rb" : "r+b"));
}
@ -545,37 +525,31 @@ open_for_reading(char *name, int stat)
/* more silliness: if you create the db with '-f cscope', then try to open
* it without '-f cscope', you'll fail unless we check for 'cscope.out.in'
* here. */
static FILE *
open_file_with_flipped_name(char *name, const char *flip_in, const char *flip_out, int stat)
{
static FILE *open_file_with_flipped_name(char *name, const char *flip_in,
const char *flip_out, int stat) {
if(!invflipname(name, flip_in, flip_out)) {
FILE *fptr = open_for_reading(name, stat);
if (! fptr)
/* flip back for error message */
if(!fptr) /* flip back for error message */
invflipname(name, flip_out, flip_in);
return fptr;
};
return 0;
}
static FILE *
open_file_with_possibly_flipped_name(char *name, const char *flip1, const char *flip2, int stat)
{
static FILE *open_file_with_possibly_flipped_name(char *name, const char *flip1,
const char *flip2, int stat) {
FILE *fptr = open_for_reading(name, stat);
if (! fptr)
fptr = open_file_with_flipped_name(name, flip2, flip1, stat);
if (! fptr)
fptr = open_file_with_flipped_name(name, flip1, flip2, stat);
if(!fptr) fptr = open_file_with_flipped_name(name, flip2, flip1, stat);
if(!fptr) fptr = open_file_with_flipped_name(name, flip1, flip2, stat);
return fptr;
}
int
invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
{
int invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat) {
int read_index;
invcntl->invfile = open_file_with_possibly_flipped_name(invname, INVNAME, INVNAME2, stat);
invcntl->invfile =
open_file_with_possibly_flipped_name(invname, INVNAME, INVNAME2, stat);
if(!invcntl->invfile) {
invcannotopen(invname);
return (-1);
@ -586,7 +560,9 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
return (-1);
}
if(invcntl->param.version != FMTVERSION) {
fprintf(stderr, PROGRAM_NAME ": cannot read old index format; use -U option to force database to rebuild\n");
fprintf(stderr,
PROGRAM_NAME
": cannot read old index format; use -U option to force database to rebuild\n");
fclose(invcntl->invfile);
return (-1);
}
@ -598,7 +574,8 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
return (-1);
}
invcntl->postfile = open_file_with_possibly_flipped_name(invpost, INVPOST, INVPOST2, stat);
invcntl->postfile =
open_file_with_possibly_flipped_name(invpost, INVPOST, INVPOST2, stat);
if(!invcntl->postfile) {
invcannotopen(invpost);
fclose(invcntl->invfile);
@ -626,10 +603,11 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
shm_id = shmget(shm_key, 0, 0);
/* Failure simply means (hopefully) that segment doesn't exists */
if(shm_id == -1) {
/* Have to give general write permission due to AMdahl not having protected segments */
shm_id = shmget(shm_key, invcntl->param.supsize + sizeof(long), IPC_CREAT | 0666);
if (shm_id == -1)
perror("Could not create shared memory segment");
/* Have to give general write permission due to AMdahl not having protected
* segments */
shm_id =
shmget(shm_key, invcntl->param.supsize + sizeof(long), IPC_CREAT | 0666);
if(shm_id == -1) perror("Could not create shared memory segment");
} else
read_index = 0;
@ -643,8 +621,7 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
}
}
#endif
if (invcntl->iindex == NULL)
/* FIXME HBB: magic number alert (4, sizeof(long)) */
if(invcntl->iindex == NULL) /* FIXME HBB: magic number alert (4, sizeof(long)) */
invcntl->iindex = malloc((size_t)invcntl->param.supsize + 4 * sizeof(long));
if(invcntl->iindex == NULL) {
invcannotalloc((size_t)invcntl->param.supsize);
@ -655,8 +632,7 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
}
if(read_index) {
fseek(invcntl->invfile, invcntl->param.startbyte, SEEK_SET);
fread(invcntl->iindex, (int) invcntl->param.supsize, 1,
invcntl->invfile);
fread(invcntl->iindex, (int)invcntl->param.supsize, 1, invcntl->invfile);
}
invcntl->numblk = -1;
if(boolready() == -1) {
@ -674,21 +650,17 @@ invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat)
}
/** invclose must be called to wrap things up and deallocate core **/
void
invclose(INVCONTROL *invcntl)
{
void invclose(INVCONTROL *invcntl) {
/* write out the control block in case anything changed */
if(invcntl->param.filestat > 0) {
invcntl->param.filestat = 0;
rewind(invcntl->invfile);
fwrite(&invcntl->param, 1,
sizeof(invcntl->param), invcntl->invfile);
fwrite(&invcntl->param, 1, sizeof(invcntl->param), invcntl->invfile);
}
if(invcntl->param.filestat == INVALONE) {
/* write out the super finger */
fseek(invcntl->invfile, invcntl->param.startbyte, SEEK_SET);
fwrite(invcntl->iindex, 1,
(int) invcntl->param.supsize, invcntl->invfile);
fwrite(invcntl->iindex, 1, (int)invcntl->param.supsize, invcntl->invfile);
}
fclose(invcntl->invfile);
fclose(invcntl->postfile);
@ -698,36 +670,31 @@ invclose(INVCONTROL *invcntl)
invcntl->iindex = NULL;
}
#endif
if (invcntl->iindex != NULL)
free(invcntl->iindex);
if(invcntl->iindex != NULL) free(invcntl->iindex);
free(invcntl->logblk);
}
/** invstep steps the inverted file forward one item **/
static void
invstep(INVCONTROL *invcntl)
{
static void invstep(INVCONTROL *invcntl) {
if(invcntl->keypnt < (invcntl->logblk->invblk[0] - 1)) {
invcntl->keypnt++;
return;
}
/* move forward a block else wrap */
invcntl->numblk = invcntl->logblk->invblk[1]; /* was: *(int *)(invcntl->logblk + sizeof(long))*/
invcntl->numblk =
invcntl->logblk->invblk[1]; /* was: *(int *)(invcntl->logblk + sizeof(long))*/
/* now read in the block */
fseek(invcntl->invfile,
invcntl->numblk * invcntl->param.sizeblk + invcntl->param.cntlsize,
SEEK_SET);
fread(invcntl->logblk, (int) invcntl->param.sizeblk, 1,
invcntl->invfile);
fread(invcntl->logblk, (int)invcntl->param.sizeblk, 1, invcntl->invfile);
invcntl->keypnt = 0;
}
/** invforward moves forward one term in the inverted file **/
int
invforward(INVCONTROL *invcntl)
{
int invforward(INVCONTROL *invcntl) {
invstep(invcntl);
/* skip things with 0 postings */
/* FIXME HBB: magic number alert! (3) */
@ -735,28 +702,23 @@ invforward(INVCONTROL *invcntl)
invstep(invcntl);
}
/* Check for having wrapped - reached start of inverted file! */
if ((invcntl->numblk == 0) && (invcntl->keypnt == 0))
return(0);
if((invcntl->numblk == 0) && (invcntl->keypnt == 0)) return (0);
return (1);
}
/** invterm gets the present term from the present logical block **/
long
invterm(INVCONTROL *invcntl, char *term)
{
long invterm(INVCONTROL *invcntl, char *term) {
ENTRY *entryptr;
/* FIXME HBB: magic number alert! (3) */
entryptr = (ENTRY *)(invcntl->logblk->invblk + 3) + invcntl->keypnt;
strncpy(term, invcntl->logblk->chrblk + entryptr->offset,
(int) entryptr->size);
strncpy(term, invcntl->logblk->chrblk + entryptr->offset, (int)entryptr->size);
*(term + entryptr->size) = '\0';
return (entryptr->post);
}
/** invfind searches for an individual item in the inverted file **/
long
invfind(INVCONTROL *invcntl, char *searchterm) /* term being searched for */
long invfind(INVCONTROL *invcntl, char *searchterm) /* term being searched for */
{
int imid, ilow, ihigh;
long num;
@ -765,8 +727,7 @@ invfind(INVCONTROL *invcntl, char *searchterm) /* term being searched for */
ENTRY *entryptr;
/* make sure it is initialized via invready */
if (invcntl->invfile == 0)
return(-1L);
if(invcntl->invfile == 0) return (-1L);
/* now search for the appropriate finger block */
intptr = (unsigned long *)invcntl->iindex;
@ -796,8 +757,7 @@ invfind(INVCONTROL *invcntl, char *searchterm) /* term being searched for */
(imid * invcntl->param.sizeblk) + invcntl->param.cntlsize,
SEEK_SET);
invcntl->numblk = imid;
fread(invcntl->logblk, (int)invcntl->param.sizeblk, 1,
invcntl->invfile);
fread(invcntl->logblk, (int)invcntl->param.sizeblk, 1, invcntl->invfile);
}
srch_ext:
@ -811,10 +771,10 @@ srch_ext:
while(ilow <= ihigh) {
imid = (ilow + ihigh) / 2;
entryptr = (ENTRY *)intptr + imid;
i = strncmp(searchterm, invcntl->logblk->chrblk + entryptr->offset,
i = strncmp(searchterm,
invcntl->logblk->chrblk + entryptr->offset,
(int)entryptr->size);
if (i == 0)
i = strlen(searchterm) - entryptr->size;
if(i == 0) i = strlen(searchterm) - entryptr->size;
if(i < 0)
ihigh = imid - 1;
else if(i > 0)
@ -839,9 +799,7 @@ srch_ext:
#if DEBUG
/** invdump dumps the block the term parameter is in **/
void
invdump(INVCONTROL *invcntl, char *term)
{
void invdump(INVCONTROL *invcntl, char *term) {
long i, j, n, *longptr;
ENTRY *entryptr;
char temp[512], *ptr;
@ -865,14 +823,16 @@ invdump(INVCONTROL *invcntl, char *term)
fseek(invcntl->invfile,
(j * invcntl->param.sizeblk) + invcntl->param.cntlsize,
SEEK_SET);
fread(invcntl->logblk, (int) invcntl->param.sizeblk, 1,
invcntl->invfile);
fread(invcntl->logblk, (int)invcntl->param.sizeblk, 1, invcntl->invfile);
} else
i = abs((int)invfind(invcntl, term));
longptr = invcntl->logblk->invblk;
n = *longptr++;
printf("Entry term to invdump=%s, postings=%ld, forwrd ptr=%ld, back ptr=%ld\n"
, term, i, *(longptr), *(longptr + 1));
printf("Entry term to invdump=%s, postings=%ld, forwrd ptr=%ld, back ptr=%ld\n",
term,
i,
*(longptr),
*(longptr + 1));
/* FIXME HBB: magic number alert! (3) */
entryptr = (ENTRY *)(invcntl->logblk->invblk + 3);
printf("%ld terms in this block, block=%ld\n", n, invcntl->numblk);
@ -881,28 +841,30 @@ invdump(INVCONTROL *invcntl, char *term)
ptr = invcntl->logblk->chrblk + entryptr->offset;
strncpy(temp, ptr, (int)entryptr->size);
temp[entryptr->size] = '\0';
ptr += (sizeof(long) * (long)((entryptr->size + (sizeof(long) - 1)) / sizeof(long)));
printf("%2ld %-24s\t%5ld\t%3d\t%d\t%d\t%ld\n", j, temp, entryptr->post,
entryptr->size, entryptr->offset, entryptr->space,
ptr +=
(sizeof(long) * (long)((entryptr->size + (sizeof(long) - 1)) / sizeof(long)));
printf("%2ld %-24s\t%5ld\t%3d\t%d\t%d\t%ld\n",
j,
temp,
entryptr->post,
entryptr->size,
entryptr->offset,
entryptr->space,
*(long *)ptr);
entryptr++;
}
}
#endif
static int
boolready(void)
{
static int boolready(void) {
numitems = 0;
if (item1 != NULL)
free(item1);
if(item1 != NULL) free(item1);
setsize1 = SETINC;
if((item1 = malloc(SETINC * sizeof(*item1))) == NULL) {
invcannotalloc(SETINC);
return (-1);
}
if (item2 != NULL)
free(item2);
if(item2 != NULL) free(item2);
setsize2 = SETINC;
if((item2 = malloc(SETINC * sizeof(*item2))) == NULL) {
invcannotalloc(SETINC);
@ -913,17 +875,13 @@ boolready(void)
return (0);
}
void
boolclear(void)
{
void boolclear(void) {
numitems = 0;
item = item1;
enditem = item;
}
POSTING *
boolfile(INVCONTROL *invcntl, long *num, int boolarg)
{
POSTING *boolfile(INVCONTROL *invcntl, long *num, int boolarg) {
ENTRY *entryptr;
FILE *file;
void *ptr;
@ -972,8 +930,7 @@ boolfile(INVCONTROL *invcntl, long *num, int boolarg)
setsize1 = u;
}
newitem = item1;
}
else {
} else {
if(u > setsize2) {
u += SETINC;
if((item2 = realloc(item2, u * sizeof(*item2))) == NULL) {
@ -1000,27 +957,22 @@ boolfile(INVCONTROL *invcntl, long *num, int boolarg)
/* while something in both sets */
set1p = item;
newsetp = newitem;
for (set1c = 0, set2c = 0;
set1c < numitems && set2c < *num; newsetc++) {
for(set1c = 0, set2c = 0; set1c < numitems && set2c < *num; newsetc++) {
if(set1p->lineoffset < posting.lineoffset) {
*newsetp++ = *set1p++;
set1c++;
}
else if (set1p->lineoffset > posting.lineoffset) {
} else if(set1p->lineoffset > posting.lineoffset) {
*newsetp++ = posting;
fread(&posting, (int)sizeof(posting), 1, file);
set2c++;
}
else if (set1p->type < posting.type) {
} else if(set1p->type < posting.type) {
*newsetp++ = *set1p++;
set1c++;
}
else if (set1p->type > posting.type) {
} else if(set1p->type > posting.type) {
*newsetp++ = posting;
fread(&posting, (int)sizeof(posting), 1, file);
set2c++;
}
else { /* identical postings */
} else { /* identical postings */
*newsetp++ = *set1p++;
set1c++;
fread(&posting, (int)sizeof(posting), 1, file);
@ -1184,21 +1136,15 @@ boolsave(int clear) /* flag about whether to clear core */
}
#endif
static void
invcannotalloc(unsigned n)
{
static void invcannotalloc(unsigned n) {
fprintf(stderr, PROGRAM_NAME ": cannot allocate %u bytes\n", n);
}
static void
invcannotopen(char *file)
{
static void invcannotopen(char *file) {
fprintf(stderr, PROGRAM_NAME "%s: cannot open file %s\n", file);
}
static void
invcannotwrite(char *file)
{
static void invcannotwrite(char *file) {
perror(PROGRAM_NAME); /* must be first to preserve errno */
fprintf(stderr, PROGRAM_NAME ": write to file %s failed\n", file);
}

View File

@ -50,37 +50,29 @@ static char line[OURBUFSIZ+1];
/* Internal prototypes: */
static char *nextfield(char *p);
static char *
nextfield(char *p)
{
static char *nextfield(char *p) {
while(*p && *p != ':')
++p;
if(*p) *p++ = 0;
return (p);
}
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;
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 */
p = nextfield(line); /* get the logname */

View File

@ -101,9 +101,7 @@ 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;
@ -117,9 +115,7 @@ initsymtab(void)
/* see if this identifier is a keyword */
char *
lookup(char *ident)
{
char *lookup(char *ident) {
struct keystruct *p;
int c;
@ -137,9 +133,7 @@ lookup(char *ident)
}
/* form hash value for string */
int
hash(char *ss)
{
int hash(char *ss) {
int i;
unsigned char *s = (unsigned char *)ss;

View File

@ -106,23 +106,16 @@ 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) {
/* cleanup on the interrupt and quit signals */
@ -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,11 +153,8 @@ 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) {
@ -185,9 +169,7 @@ initcompress(void)
/* 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) {
@ -203,13 +185,9 @@ 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') {
@ -218,13 +196,9 @@ myexit(int sig)
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();
@ -259,9 +233,7 @@ static inline void linemode_event_loop(void){
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)
putchar(c);
@ -277,13 +249,9 @@ static inline void linemode_event_loop(void){
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';
}
if(*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; }
switch(*buf) {
case '0':
case '1':
@ -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');
@ -362,9 +329,7 @@ static inline void screenmode_event_loop(void){
}
}
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 */
@ -393,11 +358,14 @@ main(int argc, char **argv)
/* 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",
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");
PROGRAM_NAME
": Please create the directory or set the environment variable\n" PROGRAM_NAME
": TMPDIR to a valid directory\n");
myexit(1);
}
@ -452,8 +420,7 @@ main(int argc, char **argv)
}
/* 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);
postfatal(PROGRAM_NAME ": cannot read file version from file %s\n", reffile);
/* NOTREACHED */
}
if(fileversion >= 8) {
@ -492,8 +459,7 @@ main(int argc, char **argv)
/* get the number of source files */
if(fscanf(oldrefs, "%lu", &nsrcfiles) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file size from file %s\n",
postfatal(PROGRAM_NAME ": cannot read source file size from file %s\n",
reffile);
/* NOTREACHED */
}
@ -503,8 +469,7 @@ main(int argc, char **argv)
/* allocate the string space */
if(fscanf(oldrefs, "%d", &oldnum) != 1) {
postfatal(
PROGRAM_NAME ": cannot read string space size from file %s\n",
postfatal(PROGRAM_NAME ": cannot read string space size from file %s\n",
reffile);
/* NOTREACHED */
}
@ -513,8 +478,7 @@ main(int argc, char **argv)
/* read the strings */
if(fread(s, oldnum, 1, oldrefs) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file names from file %s\n",
postfatal(PROGRAM_NAME ": cannot read source file names from file %s\n",
reffile);
/* NOTREACHED */
}
@ -528,8 +492,8 @@ main(int argc, char **argv)
++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 == '-') {
@ -542,8 +506,9 @@ main(int argc, char **argv)
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);
posterr(PROGRAM_NAME
": -p option in file %s: missing or invalid numeric value\n",
namefile);
}
dispcomponents = atoi(s);
}
@ -553,10 +518,9 @@ main(int argc, char **argv)
} 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
);
postfatal(PROGRAM_NAME
": cannot read source file name from file %s\n",
reffile);
/* NOTREACHED */
}
srcfiles[i] = strdup(path);
@ -569,9 +533,7 @@ 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();
@ -580,9 +542,7 @@ main(int argc, char **argv)
/* 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) {
@ -605,9 +565,7 @@ main(int argc, char **argv)
postmsg("Building cross-reference...");
}
build();
if (linemode == false ) {
postmsg(""); /* clear any build progress message */
}
if(linemode == false) { postmsg(""); /* clear any build progress message */ }
if(buildonly == true) {
myexit(0);
/* NOTREACHED */
@ -617,9 +575,7 @@ 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) {
errorsfound = false;

View File

@ -54,7 +54,8 @@ typedef struct { /* menu */
char *value;
} MENU;
static MENU mainmenu[] = { /* main menu */
static MENU mainmenu[] = {
/* main menu */
{"Send", "##\033s##\r"},
{"Repeat", "\031" },
{"Edit All", "\05" },
@ -66,7 +67,8 @@ static MENU mainmenu[] = { /* main menu */
{NULL, NULL }
};
static MENU changemenu[] = { /* change mode menu */
static MENU changemenu[] = {
/* change mode menu */
{"Mark Screen", "*" },
{"Mark All", "a" },
{"Change", "\04" },
@ -86,15 +88,12 @@ 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;
}
@ -105,8 +104,7 @@ mouseinit(void)
mouse = true;
}
#if UNIXPC
else if (strcmp(term,"s4") == 0 ||
strcmp(term,"s120") == 0 ||
else if(strcmp(term, "s4") == 0 || strcmp(term, "s120") == 0 ||
strcmp(term, "s90") == 0) {
int retval;
struct uwdata uwd; /* Window data structure */
@ -122,13 +120,11 @@ mouseinit(void)
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;
@ -145,21 +141,16 @@ mouseinit(void)
unixpcmouse = true;
}
#endif
if (mouse == true) {
loadmenu(mainmenu);
}
if(mouse == true) { loadmenu(mainmenu); }
}
/* load the correct mouse menu */
void
mousemenu(void)
{
void mousemenu(void) {
if(mouse == true) {
if(input_mode == INPUT_CHANGE) {
loadmenu(changemenu);
}
else {
} else {
loadmenu(mainmenu);
}
}
@ -167,9 +158,7 @@ mousemenu(void)
/* download a menu */
static void
loadmenu(MENU *menu)
{
static void loadmenu(MENU *menu) {
int i;
if(emacsviterm == true) {
@ -179,17 +168,18 @@ loadmenu(MENU *menu)
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) {
len = strlen(menu[i].text);
(void) printf("\033[%d;%dx%s%s", len,
(void)printf("\033[%d;%dx%s%s",
len,
(int)(len + strlen(menu[i].value)),
menu[i].text, menu[i].value);
menu[i].text,
menu[i].value);
}
loaded = menu;
}
@ -198,9 +188,7 @@ loadmenu(MENU *menu)
/* reinitialize the mouse in case curses changed the attributes */
void
mousereinit(void)
{
void mousereinit(void) {
if(emacsviterm == true) {
/* enable the mouse click and sweep coordinate control sequence */
@ -212,9 +200,7 @@ mousereinit(void)
/* restore the mouse attributes */
void
mousecleanup(void)
{
void mousecleanup(void) {
int i;
if(loaded != NULL) { /* only true for myx */
@ -230,30 +216,19 @@ 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) {
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);
@ -262,9 +237,7 @@ drawscrollbar(int top, int bot)
/* get the mouse information */
MOUSE *
getmouseaction(char leading_char)
{
MOUSE *getmouseaction(char leading_char) {
static MOUSE m;
#if UNIXPC
@ -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
@ -364,8 +335,7 @@ getmouseaction(char leading_char)
/* "null" out the other fields */
m.percent = m.x2 = m.y2 = -1;
}
else
} else
#endif /* not UNIXPC */
if(mouse == true && leading_char == ctrl('X')) {
@ -374,8 +344,7 @@ getmouseaction(char leading_char)
case ctrl('_'): /* click */
if((m.button = getch()) == '0') { /* if scrollbar */
m.percent = getpercent();
}
else {
} else {
m.x1 = getcoordinate();
m.y1 = getcoordinate();
m.x2 = m.y2 = -1;
@ -392,17 +361,15 @@ getmouseaction(char leading_char)
default:
return (NULL);
}
}
else return(NULL);
} else
return (NULL);
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();
@ -411,26 +378,18 @@ getcoordinate(void)
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);
}
if(c < 16) { return (0); }
if(c > 120) { return (100); }
return (c - 16);
}
@ -446,27 +405,21 @@ int process_mouse(){
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) {
/* 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);
}
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);
}

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);
}
if(value == NULL || *value == '\0') { return (deflt); }
return (value);
}

View File

@ -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);
@ -76,54 +73,42 @@ myopen(char *path, int flag, int mode)
if(fd != -1 && (fcntl(fd, F_SETFD, CLOSE_ON_EXEC) != -1))
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);
}
}
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);
else {
if (fp)
fclose(fp);
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) {
@ -132,8 +117,7 @@ mypopen(char *cmd, char *mode)
/* close all pipes from other popen's */
for(poptr = popen_pid; poptr < popen_pid + 20; poptr++) {
if(*poptr)
(void) close(poptr - popen_pid);
if(*poptr) (void)close(poptr - popen_pid);
}
stdio = tst(0, 1);
close(myside);
@ -144,8 +128,7 @@ mypopen(char *cmd, char *mode)
_exit(1);
} 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));
@ -153,9 +136,7 @@ mypopen(char *cmd, char *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;
@ -168,8 +149,7 @@ mypclose(FILE *ptr)
hstat = signal(SIGHUP, SIG_IGN);
while((r = wait(&status)) != popen_pid[f] && r != -1)
; /* nothing */
if(r == -1)
status = -1;
if(r == -1) status = -1;
(void)signal(SIGINT, istat);
(void)signal(SIGQUIT, qstat);
(void)signal(SIGHUP, hstat);

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 */
@ -25,9 +24,11 @@ char ** parse_options(int *argc, char **argv)
{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 '?':
@ -52,7 +53,8 @@ char ** parse_options(int *argc, char **argv)
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 */
@ -114,7 +115,8 @@ char ** parse_options(int *argc, char **argv)
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,21 +34,15 @@
#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);
}
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;
@ -58,13 +52,10 @@ pathcomponents(char *path, int components)
;
}
}
if (s > path && *s == '/') {
++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) == '/'))
{
if((*lastchar == '/') && (*(lastchar - 1) == '/')) {
/*
* find the character after the last slash
*/
nextchar = lastchar;
while (*++lastchar == '/')
{
}
while(*++lastchar == '/') { }
/*
* eliminate the extra slashes by copying
@ -130,8 +116,7 @@ compath(char *pathname) /*FDEF*/
for(lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
if((*lastchar == '/') && (*(lastchar - 1) == '.') &&
((lastchar - 1 == pathname) || (*(lastchar - 2) == '/')))
{
((lastchar - 1 == pathname) || (*(lastchar - 2) == '/'))) {
/*
* copy everything after the "./" over the "./"
@ -149,18 +134,16 @@ compath(char *pathname) /*FDEF*/
*/
for(lastchar = pathname + 1; *lastchar != '\0'; lastchar++)
if ((lastchar != pathname) && (*lastchar == '/') &&
(*(lastchar + 1) == '.') && (*(lastchar + 2) == '.') &&
((*(lastchar + 3) == '/') || (*(lastchar + 3) == '\0')))
{
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;
/*
@ -172,8 +155,7 @@ compath(char *pathname) /*FDEF*/
((*(nextchar + 1) == '/') ||
((*(nextchar + 1) == '.') && (*(nextchar + 2) == '/'))))
/* EMPTY */;
else
{
else {
/*
* prepare to eliminate either
@ -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);
}

View File

@ -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);

View File

@ -24,9 +24,7 @@ long seekpage(const size_t 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(lc == mdisprefs) { PCS_pos[++PCS_top] = ftell(*hto_page); }
}
return PCS_pos[PCS_top];
}
@ -78,4 +76,3 @@ void PCS_reset(void){
// }
// }
// }

View File

@ -37,9 +37,7 @@
#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;
@ -48,9 +46,7 @@ vpaccess(char *path, mode_t amode)
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;
}
if((returncode = access(buf, amode)) != -1) { break; }
}
}
return (returncode);

View File

@ -37,25 +37,19 @@
#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;
}
if((returncode = myfopen(buf, type)) != NULL) { break; }
}
}
return (returncode);

View File

@ -50,9 +50,7 @@ char vpdirs[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];
@ -75,10 +73,7 @@ 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) {
fprintf(stderr, PROGRAM_NAME ": cannot get current directory name\n");
@ -98,9 +93,7 @@ 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;
}
if(vpath[i] == ':' && vpath[i + 1]) { ++vpndirs; }
}
/* create the source directory list */
vpdirs = malloc(vpndirs * sizeof(*vpdirs));
@ -112,13 +105,9 @@ vpinit(char *current_dir)
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';
if(*s == '\n') { *s = '\0'; }
}
if(*s != '\0') { *s++ = '\0'; }
}
/* convert the view path nodes to directories */
for(i = 0; i < vpndirs; ++i) {
@ -131,7 +120,11 @@ vpinit(char *current_dir)
#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);
(void)fprintf(stderr,
"%s: VPATH is longer than %d characters: %s\n",
argv0,
MAXVPATH,
vpath);
return;
}
(void)strcpy(vpathbuf, vpath);
@ -143,22 +136,21 @@ vpinit(char *current_dir)
/* get the next node */
node = s;
while(*s != '\0' && *++s != ':') {
if (*s == '\n') {
*s = '\0';
}
}
if (*s != '\0') {
*s++ = '\0';
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 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);

View File

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