move all envirnment reading into readenv; rename isuptodate; make dir function arguments constant
This commit is contained in:
parent
ea8166963b
commit
e31e3d9536
25
source/dir.c
25
source/dir.c
@ -435,15 +435,13 @@ bool is_source_file(char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add a source directory to the list for each view path source directory */
|
/* add a source directory to the list for each view path source directory */
|
||||||
void sourcedir(char *dirlist) {
|
void sourcedir(const char * dirlist) {
|
||||||
char path[PATHLEN + 1];
|
char path[PATHLEN + 1];
|
||||||
char *dir;
|
|
||||||
|
|
||||||
make_vp_source_directories(); /* make the view source directory list */
|
make_vp_source_directories(); /* make the view source directory list */
|
||||||
dirlist = strdup(dirlist); /* don't change environment variable text */
|
char * mdirlist = strdup(dirlist); /* don't change environment variable text */
|
||||||
|
|
||||||
/* parse the directory list */
|
/* parse the directory list */
|
||||||
dir = strtok(dirlist, DIRSEPS);
|
char * dir = strtok(mdirlist, DIRSEPS);
|
||||||
while(dir != NULL) {
|
while(dir != NULL) {
|
||||||
int dir_len = strlen(dir);
|
int dir_len = strlen(dir);
|
||||||
|
|
||||||
@ -451,7 +449,7 @@ void sourcedir(char *dirlist) {
|
|||||||
|
|
||||||
/* if it isn't a full path name and there is a
|
/* if it isn't a full path name and there is a
|
||||||
multi-directory view path */
|
multi-directory view path */
|
||||||
if(*dirlist != '/' && vpndirs > 1) {
|
if(*mdirlist != '/' && vpndirs > 1) {
|
||||||
|
|
||||||
/* compute its path from higher view path source dirs */
|
/* compute its path from higher view path source dirs */
|
||||||
for(unsigned i = 1; i < nvpsrcdirs; ++i) {
|
for(unsigned i = 1; i < nvpsrcdirs; ++i) {
|
||||||
@ -466,19 +464,20 @@ void sourcedir(char *dirlist) {
|
|||||||
}
|
}
|
||||||
dir = strtok(NULL, DIRSEPS);
|
dir = strtok(NULL, DIRSEPS);
|
||||||
}
|
}
|
||||||
free(dirlist);
|
free(mdirlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: useless strdup
|
||||||
/* add a #include directory to the list for each view path source directory */
|
/* add a #include directory to the list for each view path source directory */
|
||||||
void includedir(char *dirlist) {
|
void includedir(const char * dirlist) {
|
||||||
char path[PATHLEN + 1];
|
char path[PATHLEN + 1];
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
make_vp_source_directories(); /* make the view source directory list */
|
make_vp_source_directories(); /* make the view source directory list */
|
||||||
dirlist = strdup(dirlist); /* don't change environment variable text */
|
char * mdirlist = strdup(dirlist); /* don't change environment variable text */
|
||||||
|
|
||||||
/* parse the directory list */
|
/* parse the directory list */
|
||||||
dir = strtok(dirlist, DIRSEPS);
|
dir = strtok(mdirlist, DIRSEPS);
|
||||||
while(dir != NULL) {
|
while(dir != NULL) {
|
||||||
size_t dir_len = strlen(dir);
|
size_t dir_len = strlen(dir);
|
||||||
|
|
||||||
@ -486,7 +485,7 @@ void includedir(char *dirlist) {
|
|||||||
|
|
||||||
/* if it isn't a full path name and there is a
|
/* if it isn't a full path name and there is a
|
||||||
multi-directory view path */
|
multi-directory view path */
|
||||||
if(*dirlist != '/' && vpndirs > 1) {
|
if(*mdirlist != '/' && vpndirs > 1) {
|
||||||
|
|
||||||
/* compute its path from higher view path source dirs */
|
/* compute its path from higher view path source dirs */
|
||||||
for(unsigned i = 1; i < nvpsrcdirs; ++i) {
|
for(unsigned i = 1; i < nvpsrcdirs; ++i) {
|
||||||
@ -501,7 +500,7 @@ void includedir(char *dirlist) {
|
|||||||
}
|
}
|
||||||
dir = strtok(NULL, DIRSEPS);
|
dir = strtok(NULL, DIRSEPS);
|
||||||
}
|
}
|
||||||
free(dirlist); /* HBB 20000421: avoid leaks */
|
free(mdirlist); /* HBB 20000421: avoid leaks */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make the source file list */
|
/* make the source file list */
|
||||||
@ -668,7 +667,7 @@ void freefilelist(void) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* if '-d' option is used a string space block is allocated */
|
/* if '-d' option is used a string space block is allocated */
|
||||||
if(isuptodate == false) {
|
if(preserve_database == false) {
|
||||||
while(nsrcfiles > 0) {
|
while(nsrcfiles > 0) {
|
||||||
free(srcfiles[--nsrcfiles]);
|
free(srcfiles[--nsrcfiles]);
|
||||||
}
|
}
|
||||||
|
@ -706,7 +706,7 @@ int findinit(const char *pattern_) {
|
|||||||
}
|
}
|
||||||
/* look for use of the -T option (truncate symbol to 8
|
/* look for use of the -T option (truncate symbol to 8
|
||||||
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 && preserve_database == true && dbtruncated == false &&
|
||||||
s - pattern >= 8) {
|
s - pattern >= 8) {
|
||||||
strcpy(pattern + 8, ".*");
|
strcpy(pattern + 8, ".*");
|
||||||
isregexp = true;
|
isregexp = true;
|
||||||
|
@ -101,6 +101,7 @@ extern int input_mode;
|
|||||||
#ifndef DFLT_INCDIR
|
#ifndef DFLT_INCDIR
|
||||||
# define DFLT_INCDIR "/usr/include"
|
# define DFLT_INCDIR "/usr/include"
|
||||||
#endif
|
#endif
|
||||||
|
extern const char * incdir;
|
||||||
|
|
||||||
/* digraph data for text compression */
|
/* digraph data for text compression */
|
||||||
extern char dichar1[]; /* 16 most frequent first chars */
|
extern char dichar1[]; /* 16 most frequent first chars */
|
||||||
@ -132,7 +133,7 @@ extern char **fileargv; /* file argument values */
|
|||||||
extern int fileversion; /* cross-reference file version */
|
extern int fileversion; /* cross-reference file version */
|
||||||
extern bool incurses; /* in curses */
|
extern bool incurses; /* in curses */
|
||||||
extern bool invertedindex; /* the database has an inverted index */
|
extern bool invertedindex; /* the database has an inverted index */
|
||||||
extern bool isuptodate; /* consider the crossref up-to-date */
|
extern bool preserve_database; /* consider the crossref up-to-date */
|
||||||
extern bool kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
extern bool kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
||||||
extern bool linemode; /* use line oriented user interface */
|
extern bool linemode; /* use line oriented user interface */
|
||||||
extern bool verbosemode; /* print extra information on line mode */
|
extern bool verbosemode; /* print extra information on line mode */
|
||||||
@ -229,7 +230,7 @@ char *read_block(void);
|
|||||||
char *scanpast(char c);
|
char *scanpast(char c);
|
||||||
|
|
||||||
char **parse_options(int *argc, char **argv);
|
char **parse_options(int *argc, char **argv);
|
||||||
void readenv(void);
|
void readenv(bool preserve_database);
|
||||||
|
|
||||||
void error_usage(void);
|
void error_usage(void);
|
||||||
void longusage(void);
|
void longusage(void);
|
||||||
@ -284,7 +285,7 @@ void freecrossref(void);
|
|||||||
void freefilelist(void);
|
void freefilelist(void);
|
||||||
const char *help(void);
|
const char *help(void);
|
||||||
void incfile(char *file, char *type);
|
void incfile(char *file, char *type);
|
||||||
void includedir(char *_dirname);
|
void includedir(const char *dirname);
|
||||||
void initsymtab(void);
|
void initsymtab(void);
|
||||||
void makefilelist(void);
|
void makefilelist(void);
|
||||||
void mousecleanup(void);
|
void mousecleanup(void);
|
||||||
@ -302,7 +303,7 @@ void postfatal(const char *msg, ...);
|
|||||||
void putposting(char *term, int type);
|
void putposting(char *term, int type);
|
||||||
void fetch_string_from_dbase(char *, size_t);
|
void fetch_string_from_dbase(char *, size_t);
|
||||||
void shellpath(char *out, int limit, char *in);
|
void shellpath(char *out, int limit, char *in);
|
||||||
void sourcedir(char *dirlist);
|
void sourcedir(const char * dirlist);
|
||||||
void myungetch(int c);
|
void myungetch(int c);
|
||||||
void warning(char *text);
|
void warning(char *text);
|
||||||
void writestring(char *s);
|
void writestring(char *s);
|
||||||
|
@ -70,7 +70,7 @@ static void catchint(int sig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline bool rebuild_reference() {
|
static inline bool rebuild_reference() {
|
||||||
if(isuptodate == true) {
|
if(preserve_database == true) {
|
||||||
postmsg("The -d option prevents rebuilding the symbol database");
|
postmsg("The -d option prevents rebuilding the symbol database");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,6 @@ unsigned int fileargc; /* file argument count */
|
|||||||
char **fileargv; /* file argument values */
|
char **fileargv; /* file argument values */
|
||||||
int fileversion; /* cross-reference file version */
|
int fileversion; /* cross-reference file version */
|
||||||
bool incurses = false; /* in curses */
|
bool incurses = false; /* in curses */
|
||||||
bool invertedindex; /* the database has an inverted index */
|
|
||||||
bool isuptodate; /* consider the crossref up-to-date */
|
|
||||||
bool kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
|
||||||
bool linemode = false; /* use line oriented user interface */
|
|
||||||
bool verbosemode = false; /* print extra information on line mode */
|
|
||||||
bool recurse_dir = false; /* recurse dirs when searching for src files */
|
|
||||||
char *namefile; /* file of file names */
|
|
||||||
char *prependpath; /* prepend path to file names */
|
char *prependpath; /* prepend path to file names */
|
||||||
FILE *refsfound; /* references found file */
|
FILE *refsfound; /* references found file */
|
||||||
long totalterms; /* total inverted index terms */
|
long totalterms; /* total inverted index terms */
|
||||||
@ -295,9 +288,6 @@ int main(int argc, char **argv) {
|
|||||||
FILE *oldrefs; /* old cross-reference file */
|
FILE *oldrefs; /* old cross-reference file */
|
||||||
char *s;
|
char *s;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
pid_t pid;
|
|
||||||
struct stat stat_buf;
|
|
||||||
mode_t orig_umask;
|
|
||||||
|
|
||||||
yyin = stdin;
|
yyin = stdin;
|
||||||
yyout = stdout;
|
yyout = stdout;
|
||||||
@ -308,7 +298,9 @@ int main(int argc, char **argv) {
|
|||||||
argv = parse_options(&argc, argv);
|
argv = parse_options(&argc, argv);
|
||||||
|
|
||||||
/* read the environment */
|
/* read the environment */
|
||||||
readenv();
|
/* NOTE: the envirnment under no condition can overwrite cli set variables
|
||||||
|
*/
|
||||||
|
readenv(preserve_database);
|
||||||
|
|
||||||
/* XXX */
|
/* XXX */
|
||||||
init_temp_files();
|
init_temp_files();
|
||||||
@ -343,7 +335,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
|
|
||||||
/* if the cross-reference is to be considered up-to-date */
|
/* if the cross-reference is to be considered up-to-date */
|
||||||
if(isuptodate == true) {
|
if(preserve_database == true) {
|
||||||
if((oldrefs = vpfopen(reffile, "rb")) == NULL) {
|
if((oldrefs = vpfopen(reffile, "rb")) == NULL) {
|
||||||
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
|
postfatal(PROGRAM_NAME ": cannot open file %s\n", reffile);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
@ -462,8 +454,6 @@ int main(int argc, char **argv) {
|
|||||||
fileargc = argc;
|
fileargc = argc;
|
||||||
fileargv = argv;
|
fileargv = argv;
|
||||||
|
|
||||||
/* get source directories from the environment */
|
|
||||||
if((s = getenv("SOURCEDIRS")) != NULL) { sourcedir(s); }
|
|
||||||
/* make the source file list */
|
/* make the source file list */
|
||||||
srcfiles = malloc(msrcfiles * sizeof(*srcfiles));
|
srcfiles = malloc(msrcfiles * sizeof(*srcfiles));
|
||||||
makefilelist();
|
makefilelist();
|
||||||
@ -471,16 +461,11 @@ int main(int argc, char **argv) {
|
|||||||
postfatal(PROGRAM_NAME ": no source files found\n");
|
postfatal(PROGRAM_NAME ": no source files found\n");
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
/* get include directories from the environment */
|
|
||||||
if((s = getenv("INCLUDEDIRS")) != NULL) { includedir(s); }
|
|
||||||
/* add /usr/include to the #include directory list,
|
/* add /usr/include to the #include directory list,
|
||||||
but not in kernelmode... kernels tend not to use it. */
|
but not in kernelmode... kernels tend not to use it. */
|
||||||
if(kernelmode == false) {
|
if(!kernelmode) {
|
||||||
if(NULL != (s = getenv("INCDIR"))) {
|
includedir(incdir);
|
||||||
includedir(s);
|
|
||||||
} else {
|
|
||||||
includedir(DFLT_INCDIR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the C keyword table */
|
/* initialize the C keyword table */
|
||||||
|
26
source/opt.c
26
source/opt.c
@ -22,10 +22,22 @@ char * shell;
|
|||||||
char * lineflag;
|
char * lineflag;
|
||||||
char * tmpdir;
|
char * tmpdir;
|
||||||
bool lineflagafterfile;
|
bool lineflagafterfile;
|
||||||
|
/* XXX: this might be a war crime;
|
||||||
|
* its currently required for respecting kernel mode
|
||||||
|
*/
|
||||||
|
const char * incdir = NULL;
|
||||||
|
|
||||||
|
/* option holders */
|
||||||
bool remove_symfile_onexit = false;
|
bool remove_symfile_onexit = false;
|
||||||
bool onesearch; /* one search only in line mode */
|
bool onesearch; /* one search only in line mode */
|
||||||
char *reflines; /* symbol reference lines file */
|
char *reflines; /* symbol reference lines file */
|
||||||
|
bool invertedindex; /* the database has an inverted index */
|
||||||
|
bool preserve_database = false; /* consider the crossref up-to-date */
|
||||||
|
bool kernelmode; /* don't use DFLT_INCDIR - bad for kernels */
|
||||||
|
bool linemode = false; /* use line oriented user interface */
|
||||||
|
bool verbosemode = false; /* print extra information on line mode */
|
||||||
|
bool recurse_dir = false; /* recurse dirs when searching for src files */
|
||||||
|
char *namefile; /* file of file names */
|
||||||
|
|
||||||
/* From a list of envirnment variable names,
|
/* From a list of envirnment variable names,
|
||||||
* return the first valid variable value
|
* return the first valid variable value
|
||||||
@ -57,7 +69,7 @@ char * _coalesce_env(char * mydefault, size_t argc, ...) {
|
|||||||
/* XXX: Add CSOPE_* equivalents while preserving the originals.
|
/* XXX: Add CSOPE_* equivalents while preserving the originals.
|
||||||
* DO NOT do it without writting documentation
|
* DO NOT do it without writting documentation
|
||||||
*/
|
*/
|
||||||
void readenv(void) {
|
void readenv(bool preserve_database) {
|
||||||
editor = coalesce_env(DEFAULT_EDITOR, "CSCOPE_EDITOR", "VIEWER", "EDITOR");
|
editor = coalesce_env(DEFAULT_EDITOR, "CSCOPE_EDITOR", "VIEWER", "EDITOR");
|
||||||
home = coalesce_env(DEFAULT_HOME, "HOME");
|
home = coalesce_env(DEFAULT_HOME, "HOME");
|
||||||
shell = coalesce_env(DEFAULT_SHELL, "SHELL");
|
shell = coalesce_env(DEFAULT_SHELL, "SHELL");
|
||||||
@ -65,6 +77,16 @@ void readenv(void) {
|
|||||||
tmpdir = coalesce_env(DEFAULT_TMPDIR, "TMPDIR");
|
tmpdir = coalesce_env(DEFAULT_TMPDIR, "TMPDIR");
|
||||||
|
|
||||||
lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE") ? 1 : 0;
|
lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE") ? 1 : 0;
|
||||||
|
|
||||||
|
if (!preserve_database) {
|
||||||
|
incdir = coalesce_env(DFLT_INCDIR, "INCDIR");
|
||||||
|
/* get source directories from the environment */
|
||||||
|
const char * const my_source_dirs = getenv("SOURCEDIRS");
|
||||||
|
if(my_source_dirs) { sourcedir(my_source_dirs); }
|
||||||
|
/* get include directories from the environment */
|
||||||
|
const char * const my_include_dirs = getenv("INCLUDEDIRS");
|
||||||
|
if(my_include_dirs) { includedir(my_source_dirs); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char **parse_options(int *argc, char **argv) {
|
char **parse_options(int *argc, char **argv) {
|
||||||
@ -133,7 +155,7 @@ char **parse_options(int *argc, char **argv) {
|
|||||||
egrepcaseless(caseless); /* simulate egrep -i flag */
|
egrepcaseless(caseless); /* simulate egrep -i flag */
|
||||||
break;
|
break;
|
||||||
case 'd': /* consider crossref up-to-date */
|
case 'd': /* consider crossref up-to-date */
|
||||||
isuptodate = true;
|
preserve_database = true;
|
||||||
break;
|
break;
|
||||||
case 'e': /* suppress ^E prompt between files */
|
case 'e': /* suppress ^E prompt between files */
|
||||||
editallprompt = false;
|
editallprompt = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user