code quality, micro optimization
This commit is contained in:
parent
92ff012047
commit
3db14b2685
109
source/find.c
109
source/find.c
@ -144,7 +144,9 @@ static bool check_for_assignment(void) {
|
|||||||
if(asgn_char[0] == '\0') {
|
if(asgn_char[0] == '\0') {
|
||||||
/* get the next block when we reach the end of
|
/* get the next block when we reach the end of
|
||||||
* the current block */
|
* the current block */
|
||||||
if(NULL == (asgn_char = read_block())) return false;
|
if(NULL == (asgn_char = read_block())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* check for digraph starting with = */
|
/* check for digraph starting with = */
|
||||||
@ -159,12 +161,13 @@ static bool check_for_assignment(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check for operator assignments: +=, ... ^= ? */
|
/* check for operator assignments: +=, ... ^= ? */
|
||||||
if(((asgn_char[0] == '+') || (asgn_char[0] == '-') || (asgn_char[0] == '*') ||
|
if((asgn_char[1] == '=')
|
||||||
|
|| ((asgn_char[1] & 0x80)
|
||||||
|
&& (dichar1[(asgn_char[1] & 0177) / 8] == '='))
|
||||||
|
&&
|
||||||
|
((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[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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -173,8 +176,10 @@ static bool check_for_assignment(void) {
|
|||||||
if(((asgn_char[0] == '<') || (asgn_char[0] == '>')) &&
|
if(((asgn_char[0] == '<') || (asgn_char[0] == '>')) &&
|
||||||
(asgn_char[1] == asgn_char[0]) &&
|
(asgn_char[1] == asgn_char[0]) &&
|
||||||
((asgn_char[2] == '=') ||
|
((asgn_char[2] == '=') ||
|
||||||
((asgn_char[2] & 0x80) && (dichar1[(asgn_char[2] & 0177) / 8] == '='))))
|
((asgn_char[2] & 0x80) && (dichar1[(asgn_char[2] & 0177) / 8] == '=')))
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,9 +594,9 @@ char *findregexp(const char *egreppat) {
|
|||||||
/* find matching file names */
|
/* find matching file names */
|
||||||
|
|
||||||
char *findfile(const char *dummy) {
|
char *findfile(const char *dummy) {
|
||||||
unsigned int i;
|
UNUSED(dummy);
|
||||||
|
|
||||||
(void)dummy; /* unused argument */
|
unsigned int i;
|
||||||
|
|
||||||
for(i = 0; i < nsrcfiles; ++i) {
|
for(i = 0; i < nsrcfiles; ++i) {
|
||||||
char *s;
|
char *s;
|
||||||
@ -706,7 +711,7 @@ int findinit(const char *pattern_) {
|
|||||||
characters) on a database not built with -T */
|
characters) on a database not built with -T */
|
||||||
if(trun_syms == true && isuptodate == true && dbtruncated == false &&
|
if(trun_syms == true && isuptodate == true && dbtruncated == false &&
|
||||||
s - pattern >= 8) {
|
s - pattern >= 8) {
|
||||||
(void)strcpy(pattern + 8, ".*");
|
strcpy(pattern + 8, ".*");
|
||||||
isregexp = true;
|
isregexp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -717,8 +722,8 @@ int findinit(const char *pattern_) {
|
|||||||
/* remove a leading ^ */
|
/* remove a leading ^ */
|
||||||
s = pattern;
|
s = pattern;
|
||||||
if(*s == '^') {
|
if(*s == '^') {
|
||||||
(void)strcpy(newpat, s + 1);
|
strcpy(newpat, s + 1);
|
||||||
(void)strcpy(s, newpat);
|
strcpy(s, newpat);
|
||||||
}
|
}
|
||||||
/* remove a trailing $ */
|
/* remove a trailing $ */
|
||||||
i = strlen(s) - 1;
|
i = strlen(s) - 1;
|
||||||
@ -731,7 +736,7 @@ int findinit(const char *pattern_) {
|
|||||||
/* must be an exact match */
|
/* must be an exact match */
|
||||||
/* note: regcomp doesn't recognize ^*keypad$ as a syntax error
|
/* note: regcomp doesn't recognize ^*keypad$ as a syntax error
|
||||||
unless it is given as a single arg */
|
unless it is given as a single arg */
|
||||||
(void)snprintf(buf, sizeof(buf), "^%s$", s);
|
snprintf(buf, sizeof(buf), "^%s$", s);
|
||||||
if(regcomp(®exp, buf, REG_EXTENDED | REG_NOSUB) != 0) {
|
if(regcomp(®exp, buf, REG_EXTENDED | REG_NOSUB) != 0) {
|
||||||
r = REGCMPERROR;
|
r = REGCMPERROR;
|
||||||
goto end;
|
goto end;
|
||||||
@ -807,7 +812,7 @@ static void putref(int seemore, const char *file, const char *func) {
|
|||||||
} else {
|
} else {
|
||||||
output = nonglobalrefs;
|
output = nonglobalrefs;
|
||||||
}
|
}
|
||||||
(void)fprintf(output, "%s %s ", file, func);
|
fprintf(output, "%s %s ", file, func);
|
||||||
putsource(seemore, output);
|
putsource(seemore, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,9 +824,9 @@ static void putsource(int seemore, FILE *output) {
|
|||||||
bool Change = false, retreat = false;
|
bool Change = false, retreat = false;
|
||||||
|
|
||||||
if(fileversion <= 5) {
|
if(fileversion <= 5) {
|
||||||
(void)scanpast(' ');
|
scanpast(' ');
|
||||||
putline(output);
|
putline(output);
|
||||||
(void)putc('\n', output);
|
putc('\n', output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* scan back to the beginning of the source line */
|
/* scan back to the beginning of the source line */
|
||||||
@ -831,7 +836,7 @@ static void putsource(int seemore, FILE *output) {
|
|||||||
if(--cp < block) {
|
if(--cp < block) {
|
||||||
retreat = true;
|
retreat = true;
|
||||||
/* read the previous block */
|
/* read the previous block */
|
||||||
(void)dbseek((blocknumber - 1) * BUFSIZ);
|
dbseek((blocknumber - 1) * BUFSIZ);
|
||||||
cp = block + (BUFSIZ - 1);
|
cp = block + (BUFSIZ - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -860,7 +865,7 @@ static void putsource(int seemore, FILE *output) {
|
|||||||
putline(output);
|
putline(output);
|
||||||
if(retreat == true) retreat = false;
|
if(retreat == true) retreat = false;
|
||||||
} while(blockp != NULL && getrefchar() != '\n');
|
} while(blockp != NULL && getrefchar() != '\n');
|
||||||
(void)putc('\n', output);
|
putc('\n', output);
|
||||||
if(Change == true) blockp = cp;
|
if(Change == true) blockp = cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,16 +883,16 @@ static void putline(FILE *output) {
|
|||||||
/* check for a compressed digraph */
|
/* check for a compressed digraph */
|
||||||
if(c > '\177') {
|
if(c > '\177') {
|
||||||
c &= 0177;
|
c &= 0177;
|
||||||
(void)putc(dichar1[c / 8], output);
|
putc(dichar1[c / 8], output);
|
||||||
(void)putc(dichar2[c & 7], output);
|
putc(dichar2[c & 7], output);
|
||||||
}
|
}
|
||||||
/* check for a compressed keyword */
|
/* check for a compressed keyword */
|
||||||
else if(c < ' ') {
|
else if(c < ' ') {
|
||||||
(void)fputs(keyword[c].text, output);
|
fputs(keyword[c].text, output);
|
||||||
if(keyword[c].delim != '\0') { (void)putc(' ', output); }
|
if(keyword[c].delim != '\0') { putc(' ', output); }
|
||||||
if(keyword[c].delim == '(') { (void)putc('(', output); }
|
if(keyword[c].delim == '(') { (putc('(', output); }
|
||||||
} else {
|
} else {
|
||||||
(void)putc((int)c, output);
|
putc((int)c, output);
|
||||||
}
|
}
|
||||||
++cp;
|
++cp;
|
||||||
}
|
}
|
||||||
@ -1044,7 +1049,7 @@ static void findterm(const char *pattern) {
|
|||||||
boolclear(); /* clear the posting set */
|
boolclear(); /* clear the posting set */
|
||||||
|
|
||||||
/* get the string prefix (if any) of the regular expression */
|
/* get the string prefix (if any) of the regular expression */
|
||||||
(void)strcpy(prefix, pattern);
|
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 letter case is to be ignored */
|
||||||
if(caseless == true) {
|
if(caseless == true) {
|
||||||
@ -1058,16 +1063,16 @@ static void findterm(const char *pattern) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* find the term lexically >= the prefix */
|
/* find the term lexically >= the prefix */
|
||||||
(void)invfind(&invcontrol, prefix);
|
UNUSED(invfind(&invcontrol, prefix));
|
||||||
if(caseless == true) { /* restore lower case */
|
if(caseless == true) { /* restore lower case */
|
||||||
(void)strcpy(prefix, lcasify(prefix));
|
UNUSED(strcpy(prefix, lcasify(prefix)));
|
||||||
}
|
}
|
||||||
/* a null prefix matches the null term in the inverted index,
|
/* a null prefix matches the null term in the inverted index,
|
||||||
so move to the first real term */
|
so move to the first real term */
|
||||||
if(*prefix == '\0') { (void)invforward(&invcontrol); }
|
if(*prefix == '\0') { invforward(&invcontrol); }
|
||||||
len = strlen(prefix);
|
len = strlen(prefix);
|
||||||
do {
|
do {
|
||||||
(void)invterm(&invcontrol, term); /* get the term */
|
UNUSED(invterm(&invcontrol, term)); /* get the term */
|
||||||
s = 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 it matches */
|
||||||
@ -1108,7 +1113,7 @@ static POSTING *getposting(void) {
|
|||||||
if(++searchcount % 100 == 0) {
|
if(++searchcount % 100 == 0) {
|
||||||
progress("Possible references retrieved", searchcount, postingsfound);
|
progress("Possible references retrieved", searchcount, postingsfound);
|
||||||
}
|
}
|
||||||
return (postingp++);
|
return postingp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put the posting reference into the file */
|
/* put the posting reference into the file */
|
||||||
@ -1150,14 +1155,14 @@ long dbseek(long offset) {
|
|||||||
if((n = offset / BUFSIZ) != blocknumber) {
|
if((n = offset / BUFSIZ) != blocknumber) {
|
||||||
if((rc = lseek(symrefs, n * BUFSIZ, 0)) == -1) {
|
if((rc = lseek(symrefs, n * BUFSIZ, 0)) == -1) {
|
||||||
myperror("Lseek failed");
|
myperror("Lseek failed");
|
||||||
(void)sleep(3);
|
sleep(3);
|
||||||
return (rc);
|
return rc;
|
||||||
}
|
}
|
||||||
(void)read_block();
|
read_block();
|
||||||
blocknumber = n;
|
blocknumber = n;
|
||||||
}
|
}
|
||||||
blockp = block + offset % BUFSIZ;
|
blockp = block + offset % BUFSIZ;
|
||||||
return (rc);
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void findcalledbysub(const char *file, bool macro) {
|
static void findcalledbysub(const char *file, bool macro) {
|
||||||
@ -1175,12 +1180,12 @@ static void findcalledbysub(const char *file, bool macro) {
|
|||||||
case FCNCALL: /* function call */
|
case FCNCALL: /* function call */
|
||||||
|
|
||||||
/* output the file name */
|
/* output the file name */
|
||||||
(void)fprintf(refsfound, "%s ", file);
|
UNUSED(fprintf(refsfound, "%s ", file));
|
||||||
|
|
||||||
/* output the function name */
|
/* output the function name */
|
||||||
skiprefchar();
|
skiprefchar();
|
||||||
putline(refsfound);
|
putline(refsfound);
|
||||||
(void)putc(' ', refsfound);
|
UNUSED(putc(' ', refsfound));
|
||||||
|
|
||||||
/* output the source line */
|
/* output the source line */
|
||||||
putsource(1, refsfound);
|
putsource(1, refsfound);
|
||||||
@ -1211,16 +1216,16 @@ bool writerefsfound(void) {
|
|||||||
if(refsfound == NULL) {
|
if(refsfound == NULL) {
|
||||||
if((refsfound = myfopen(temp1, "wb")) == NULL) {
|
if((refsfound = myfopen(temp1, "wb")) == NULL) {
|
||||||
cannotopen(temp1);
|
cannotopen(temp1);
|
||||||
return (false);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(void)fclose(refsfound);
|
fclose(refsfound);
|
||||||
if((refsfound = myfopen(temp1, "wb")) == NULL) {
|
if((refsfound = myfopen(temp1, "wb")) == NULL) {
|
||||||
postmsg("Cannot reopen temporary file");
|
postmsg("Cannot reopen temporary file");
|
||||||
return (false);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform token search based on "field" */
|
/* Perform token search based on "field" */
|
||||||
@ -1249,31 +1254,31 @@ bool search(const char *query) {
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
if((rc = findinit(query)) == NOERROR) {
|
if((rc = findinit(query)) == NOERROR) {
|
||||||
(void)dbseek(0L); /* read the first block */
|
UNUSED(dbseek(0L)); /* read the first block */
|
||||||
findresult = (*f)(query);
|
findresult = (*f)(query);
|
||||||
if(f == findcalledby) funcexist = (*findresult == 'y');
|
if(f == findcalledby) funcexist = (*findresult == 'y');
|
||||||
findcleanup();
|
findcleanup();
|
||||||
|
|
||||||
/* append the non-global references */
|
/* append the non-global references */
|
||||||
(void)fclose(nonglobalrefs);
|
UNUSED(fclose(nonglobalrefs));
|
||||||
if((nonglobalrefs = myfopen(temp2, "rb")) == NULL) {
|
if((nonglobalrefs = myfopen(temp2, "rb")) == NULL) {
|
||||||
cannotopen(temp2);
|
cannotopen(temp2);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
while((c = getc(nonglobalrefs)) != EOF) {
|
while((c = getc(nonglobalrefs)) != EOF) {
|
||||||
(void)putc(c, refsfound);
|
UNUSED(putc(c, refsfound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)fclose(nonglobalrefs);
|
UNUSED(fclose(nonglobalrefs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal(SIGINT, savesig);
|
signal(SIGINT, savesig);
|
||||||
|
|
||||||
/* rewind the cross-reference file */
|
/* rewind the cross-reference file */
|
||||||
(void)lseek(symrefs, (long)0, 0);
|
lseek(symrefs, (long)0, 0);
|
||||||
|
|
||||||
/* reopen the references found file for reading */
|
/* reopen the references found file for reading */
|
||||||
(void)fclose(refsfound);
|
fclose(refsfound);
|
||||||
if((refsfound = myfopen(temp1, "rb")) == NULL) {
|
if((refsfound = myfopen(temp1, "rb")) == NULL) {
|
||||||
cannotopen(temp1);
|
cannotopen(temp1);
|
||||||
return (false);
|
return (false);
|
||||||
@ -1284,26 +1289,26 @@ bool search(const char *query) {
|
|||||||
/* see if it is empty */
|
/* see if it is empty */
|
||||||
if((c = getc(refsfound)) == EOF) {
|
if((c = getc(refsfound)) == EOF) {
|
||||||
if(findresult != NULL) {
|
if(findresult != NULL) {
|
||||||
(void)snprintf(msg,
|
snprintf(msg,
|
||||||
sizeof(msg),
|
sizeof(msg),
|
||||||
"Egrep %s in this pattern: %s",
|
"Egrep %s in this pattern: %s",
|
||||||
findresult,
|
findresult,
|
||||||
query);
|
query);
|
||||||
} else if(rc == NOTSYMBOL) {
|
} else if(rc == NOTSYMBOL) {
|
||||||
(void)snprintf(msg, sizeof(msg), "This is not a C symbol: %s", query);
|
snprintf(msg, sizeof(msg), "This is not a C symbol: %s", query);
|
||||||
} else if(rc == REGCMPERROR) {
|
} else if(rc == REGCMPERROR) {
|
||||||
(void)snprintf(msg,
|
snprintf(msg,
|
||||||
sizeof(msg),
|
sizeof(msg),
|
||||||
"Error in this regcomp(3) regular expression: %s",
|
"Error in this regcomp(3) regular expression: %s",
|
||||||
query);
|
query);
|
||||||
|
|
||||||
} else if(funcexist == false) {
|
} else if(funcexist == false) {
|
||||||
(void)snprintf(msg,
|
snprintf(msg,
|
||||||
sizeof(msg),
|
sizeof(msg),
|
||||||
"Function definition does not exist: %s",
|
"Function definition does not exist: %s",
|
||||||
query);
|
query);
|
||||||
} else {
|
} else {
|
||||||
(void)snprintf(msg,
|
snprintf(msg,
|
||||||
sizeof(msg),
|
sizeof(msg),
|
||||||
"Could not find the %s: %s",
|
"Could not find the %s: %s",
|
||||||
fields[field].text2,
|
fields[field].text2,
|
||||||
@ -1313,7 +1318,7 @@ bool search(const char *query) {
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
/* put back the character read */
|
/* put back the character read */
|
||||||
(void)ungetc(c, refsfound);
|
ungetc(c, refsfound);
|
||||||
|
|
||||||
countrefs();
|
countrefs();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user