minor edits

This commit is contained in:
anon 2024-11-12 21:44:31 +01:00
parent e31e3d9536
commit b7f1782f96
2 changed files with 74 additions and 77 deletions

View File

@ -693,8 +693,9 @@ void myperror(char *text) {
/* postmsg clears the message line and prints the message */
void postmsg(char *msg) {
if(linemode == true || incurses == false) {
printf("%s\n", msg);
if (linemode == true
|| incurses == false) {
puts(msg);
fflush(stdout);
} else {
window_change |= CH_RESULT;

View File

@ -87,7 +87,7 @@ static inline void screenmode_event_loop(void);
static inline
void siginit(void) {
/* if running in the foreground */
if(signal(SIGINT, SIG_IGN) != SIG_IGN) {
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
/* cleanup on the interrupt and quit signals */
signal(SIGINT, myexit);
signal(SIGQUIT, myexit);
@ -102,7 +102,7 @@ void siginit(void) {
*/
signal(SIGPIPE, SIG_IGN);
//if(linemode == false) { signal(SIGWINCH, redisplay); }
//if (linemode == false) { signal(SIGWINCH, redisplay); }
}
void cannotopen(const char *const file) {
@ -124,11 +124,11 @@ void cannotwrite(const char *const file) {
/* set up the digraph character tables for text compression */
static
void initcompress(void) {
if(compress == true) {
for(int i = 0; i < 16; i++) {
if (compress == true) {
for (int i = 0; i < 16; i++) {
dicode1[(unsigned char)(dichar1[i])] = i * 8 + 1;
}
for(int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
dicode2[(unsigned char)(dichar2[i])] = i + 1;
}
}
@ -139,14 +139,12 @@ static
void skiplist(FILE *oldrefs) {
int i;
if(fscanf(oldrefs, "%d", &i) != 1) {
if (fscanf(oldrefs, "%d", &i) != 1) {
postfatal(PROGRAM_NAME ": cannot read list size from file %s\n", reffile);
/* NOTREACHED */
}
while(--i >= 0) {
if(fscanf(oldrefs, "%*s") != 0) {
if (fscanf(oldrefs, "%*s") != 0) {
postfatal(PROGRAM_NAME ": cannot read list name from file %s\n", reffile);
/* NOTREACHED */
}
}
}
@ -154,14 +152,14 @@ void skiplist(FILE *oldrefs) {
/* cleanup and exit */
void myexit(int sig) {
/* Close file before unlinking it. DOS absolutely needs it */
if(refsfound != NULL) { fclose(refsfound); }
if (refsfound != NULL) { fclose(refsfound); }
deinit_temp_files();
/* 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();
@ -169,7 +167,7 @@ void myexit(int sig) {
freecrossref();
free_newbuildfiles();
if(remove_symfile_onexit == true) {
if (remove_symfile_onexit == true) {
unlink(reffile);
unlink(invname);
unlink(invpost);
@ -182,11 +180,11 @@ static inline
void linemode_event_loop(void) {
int c;
if(*input_line != '\0') { /* do any optional search */
if(search(input_line) == true) {
if (*input_line != '\0') { /* do any optional search */
if (search(input_line) == true) {
/* print the total number of lines in
* verbose mode */
if(verbosemode == true) printf(PROGRAM_NAME ": %d lines\n", totallines);
if (verbosemode == true) printf(PROGRAM_NAME ": %d lines\n", totallines);
while((c = getc(refsfound)) != EOF) {
putchar(c);
@ -194,17 +192,17 @@ void linemode_event_loop(void) {
}
}
if(onesearch == true) { myexit(0); }
if (onesearch == true) { myexit(0); }
for(char *s;;) {
for (char *s;;) {
char buf[PATLEN + 2];
printf(">> ");
fflush(stdout);
if(fgets(buf, sizeof(buf), stdin) == NULL) { myexit(0); }
if (fgets(buf, sizeof(buf), stdin) == NULL) { myexit(0); }
/* remove any trailing newline character */
if(*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; }
switch(*buf) {
if (*(s = buf + strlen(buf) - 1) == '\n') { *s = '\0'; }
switch (*buf) {
case '0':
case '1':
case '2':
@ -217,7 +215,7 @@ void linemode_event_loop(void) {
case '9': /* samuel only */
field = *buf - '0';
strcpy(input_line, buf + 1);
if(search(input_line) == false) {
if (search(input_line) == false) {
printf("Unable to search database\n");
} else {
printf("cscope: %d lines\n", totallines);
@ -229,7 +227,7 @@ void linemode_event_loop(void) {
case 'c': /* toggle caseless mode */
case ctrl('C'):
if(caseless == false) {
if (caseless == false) {
caseless = true;
} else {
caseless = false;
@ -255,7 +253,7 @@ 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');
@ -276,7 +274,7 @@ void linemode_event_loop(void) {
static inline
void screenmode_event_loop(void) {
for(;;) {
for (;;) {
display();
handle_input(wgetch(stdscr)); // NOTE: getch() does not return KEY_* codes
}
@ -327,7 +325,7 @@ int main(int argc, char **argv) {
siginit();
if(linemode == false) {
if (linemode == false) {
dispinit(); /* initialize display parameters */
postmsg(""); /* clear any build progress message */
display(); /* display the version number and input fields */
@ -335,30 +333,28 @@ int main(int argc, char **argv) {
/* if the cross-reference is to be considered up-to-date */
if(preserve_database == true) {
if((oldrefs = vpfopen(reffile, "rb")) == NULL) {
if (preserve_database == true) {
if ((oldrefs = vpfopen(reffile, "rb")) == NULL) {
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
/* NOTREACHED */
}
/* get the crossref file version but skip the current directory */
if(fscanf(oldrefs, PROGRAM_NAME " %d %*s", &fileversion) != 1) {
if (fscanf(oldrefs, PROGRAM_NAME " %d %*s", &fileversion) != 1) {
postfatal(PROGRAM_NAME ": cannot read file version from file %s\n", reffile);
/* NOTREACHED */
}
if(fileversion >= 8) {
if (fileversion >= 8) {
/* override these command line options */
compress = true;
invertedindex = false;
/* see if there are options in the database */
for(int c;;) {
for (int c;;) {
getc(oldrefs); /* skip the blank */
if((c = getc(oldrefs)) != '-') {
if ((c = getc(oldrefs)) != '-') {
ungetc(c, oldrefs);
break;
}
switch(getc(oldrefs)) {
switch (getc(oldrefs)) {
case 'c': /* ASCII characters only */
compress = false;
break;
@ -380,57 +376,58 @@ int main(int argc, char **argv) {
skiplist(oldrefs);
/* get the number of source files */
if(fscanf(oldrefs, "%lu", &nsrcfiles) != 1) {
postfatal(PROGRAM_NAME ": cannot read source file size from file %s\n",
reffile);
/* NOTREACHED */
if (fscanf(oldrefs, "%lu", &nsrcfiles) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file size from file %s\n",
reffile
);
}
/* get the source file list */
srcfiles = malloc(nsrcfiles * sizeof(*srcfiles));
if(fileversion >= 9) {
if (fileversion >= 9) {
/* allocate the string space */
if(fscanf(oldrefs, "%d", &oldnum) != 1) {
postfatal(PROGRAM_NAME ": cannot read string space size from file %s\n",
reffile);
/* NOTREACHED */
if (fscanf(oldrefs, "%d", &oldnum) != 1) {
postfatal(
PROGRAM_NAME ": cannot read string space size from file %s\n",
reffile
);
}
s = malloc(oldnum);
getc(oldrefs); /* skip the newline */
/* read the strings */
if(fread(s, oldnum, 1, oldrefs) != 1) {
postfatal(PROGRAM_NAME ": cannot read source file names from file %s\n",
reffile);
/* NOTREACHED */
if (fread(s, oldnum, 1, oldrefs) != 1) {
postfatal(
PROGRAM_NAME ": cannot read source file names from file %s\n",
reffile
);
}
/* change newlines to nulls */
for(i = 0; i < nsrcfiles; ++i) {
for (int i = 0; i < nsrcfiles; i++) {
srcfiles[i] = s;
for(++s; *s != '\n'; ++s) {
;
}
for (++s; *s != '\n'; ++s) { ; }
*s = '\0';
++s;
}
/* if there is a file of source file names */
if((namefile != NULL && (names = vpfopen(namefile, "r")) != NULL) ||
(names = vpfopen(NAMEFILE, "r")) != NULL) {
if ((namefile != NULL && (names = vpfopen(namefile, "r")) != NULL)
|| (names = vpfopen(NAMEFILE, "r")) != NULL) {
/* read any -p option from it */
while(fgets(path, sizeof(path), names) != NULL && *path == '-') {
i = path[1];
char orig_path1 = path[1];
s = path + 2; /* for "-Ipath" */
if(*s == '\0') { /* if "-I path" */
if (*s == '\0') { /* if "-I path" */
fgets(path, sizeof(path), names);
s = path;
}
switch(i) {
switch (orig_path1) {
case 'p': /* file path components to display */
if(*s < '0' || *s > '9') {
posterr(PROGRAM_NAME
": -p option in file %s: missing or invalid numeric value\n",
namefile);
if (*s < '0' || *s > '9') {
posterr(
PROGRAM_NAME ": -p option in file %s: missing or invalid numeric value\n",
namefile
);
}
dispcomponents = atoi(s);
}
@ -438,8 +435,8 @@ int main(int argc, char **argv) {
fclose(names);
}
} else {
for(i = 0; i < nsrcfiles; ++i) {
if(!fgets(path, sizeof(path), oldrefs)) {
for (int i = 0; i < nsrcfiles; ++i) {
if (!fgets(path, sizeof(path), oldrefs)) {
postfatal(PROGRAM_NAME
": cannot read source file name from file %s\n",
reffile);
@ -457,14 +454,13 @@ int main(int argc, char **argv) {
/* make the source file list */
srcfiles = malloc(msrcfiles * sizeof(*srcfiles));
makefilelist();
if(nsrcfiles == 0) {
if (nsrcfiles == 0) {
postfatal(PROGRAM_NAME ": no source files found\n");
/* NOTREACHED */
}
/* add /usr/include to the #include directory list,
but not in kernelmode... kernels tend not to use it. */
if(!kernelmode) {
if (!kernelmode) {
includedir(incdir);
}
@ -476,30 +472,30 @@ int main(int argc, char **argv) {
/* build the cross-reference */
initcompress();
if(linemode == false || verbosemode == true) { /* display if verbose as well */
if (linemode == false
|| verbosemode == true) { /* display if verbose as well */
postmsg("Building cross-reference...");
}
build();
if(linemode == false) { postmsg(""); /* clear any build progress message */ }
if(buildonly == true) {
if (linemode == false) { postmsg(""); /* clear any build progress message */ }
if (buildonly == true) {
myexit(0);
/* NOTREACHED */
}
}
opendatabase();
/* if using the line oriented user interface so cscope can be a
subprocess to emacs or samuel */
if(linemode == true) { linemode_event_loop(); }
if (linemode == true) { linemode_event_loop(); }
/* pause before clearing the screen if there have been error messages */
if(errorsfound == true) {
if (errorsfound == true) {
errorsfound = false;
askforreturn();
}
/* do any optional search */
if(*input_line != '\0') {
if (*input_line != '\0') {
// command(ctrl('Y')); /* search */ // XXX: fix
} else if(reflines != NULL) {
} else if (reflines != NULL) {
/* read any symbol reference lines file */
readrefs(reflines);
}