rename filepath to prepend_path; require a prefix to be explicitly passed; prepare prependpath, the legacy global for refactoring

This commit is contained in:
anon 2024-11-13 13:57:10 +01:00
parent 9bc64414b3
commit 7370aa2b4e
4 changed files with 19 additions and 18 deletions

@ -85,13 +85,13 @@ void editall(void) {
}
/* call the editor */
void edit(char *file, const char *const linenum) {
void edit(const char *filename, 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 */
file = filepath(file);
snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, file);
filename = prepend_path(prependpath, filename);
snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, filename);
postmsg(msg);
snprintf(plusnum, sizeof(plusnum), lineflag, linenum);
@ -103,15 +103,15 @@ void edit(char *file, const char *const linenum) {
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);
execute(editor, editor, plusnum, filename, "/dev/null", NULL);
goto end;
}
}
if(lineflagafterfile) {
execute(editor, editor, file, plusnum, NULL);
execute(editor, editor, filename, plusnum, NULL);
} else {
execute(editor, editor, plusnum, file, NULL);
execute(editor, editor, plusnum, filename, NULL);
}
end:
@ -119,13 +119,14 @@ end:
}
/* if requested, prepend a path to a relative file name */
const char * prepend_path(const char * prepand_with, const char * file) {
static char path[PATHLEN + 1]; // XXX
char *filepath(char *file) {
static char path[PATHLEN + 1];
if (!prepand_with
|| *file == '/') {
return file;
}
if(prependpath != NULL && *file != '/') {
(void)snprintf(path, sizeof(path), "%s/%s", prependpath, file);
file = path;
}
return (file);
snprintf(path, sizeof(path), "%s/%s", prependpath, file);
return path;
}

@ -554,7 +554,7 @@ size_t read_next_chunk(char **p, FILE *fptr)
return fread(*p, sizeof(**p), buf_end - *p, fptr);
}
int egrep(char * file, FILE *output, char *format) {
int egrep(const char * file, FILE *output, char *format) {
char *p;
unsigned int cstat;
int ccount;

@ -578,7 +578,7 @@ char *findregexp(const char *egreppat) {
/* search the files */
for(i = 0; i < nsrcfiles; ++i) {
char *file = filepath(srcfiles[i]);
const char * file = prepend_path(prependpath, srcfiles[i]);
progress("Search", searchcount, nsrcfiles);
if(egrep(file, refsfound, "%s <unknown> %ld ") < 0) {

@ -193,7 +193,7 @@ extern int rl_point;
/* cscope functions called from more than one function or between files */
char *filepath(char *file);
const char * prepend_path(const char * prepand_with, const char * file);
char *findsymbol(const char *pattern);
char *finddef(const char *pattern);
char *findcalledby(const char *pattern);
@ -253,7 +253,7 @@ void dispinit(void);
void display(void);
void redisplay(void);
void drawscrollbar(int top, int bot);
void edit(char *file, const char *const linenum);
void edit(const char * filename, const char *const linenum);
void editall(void);
void editref(int);
void entercurses(void);
@ -293,7 +293,7 @@ bool writerefsfound(void);
int findinit(const char *pattern_);
int egrep(char *file, FILE *output, char *format);
int egrep(const char * file, FILE *output, char *format);
int hash(const char * ss);
int execute(char *a, ...);
long dbseek(long offset);