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

View File

@ -85,13 +85,13 @@ void editall(void) {
} }
/* call the editor */ /* 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); const char *const editor_basename = basename(editor);
char msg[MSGLEN + 1]; /* message */ char msg[MSGLEN + 1]; /* message */
char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */ char plusnum[NUMLEN + 20]; /* line number option: allow space for wordy line# flag */
file = filepath(file); filename = prepend_path(prependpath, filename);
snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, file); snprintf(msg, sizeof(msg), "%s +%s %s", basename(editor), linenum, filename);
postmsg(msg); postmsg(msg);
snprintf(plusnum, sizeof(plusnum), lineflag, linenum); 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}; const char *const shit_pagers[] = {"page", "more", NULL};
for(const char *const *sp = shit_pagers; *sp != NULL; sp++) { for(const char *const *sp = shit_pagers; *sp != NULL; sp++) {
if(!strcmp(editor_basename, *sp)) { if(!strcmp(editor_basename, *sp)) {
execute(editor, editor, plusnum, file, "/dev/null", NULL); execute(editor, editor, plusnum, filename, "/dev/null", NULL);
goto end; goto end;
} }
} }
if(lineflagafterfile) { if(lineflagafterfile) {
execute(editor, editor, file, plusnum, NULL); execute(editor, editor, filename, plusnum, NULL);
} else { } else {
execute(editor, editor, plusnum, file, NULL); execute(editor, editor, plusnum, filename, NULL);
} }
end: end:
@ -119,13 +119,14 @@ end:
} }
/* if requested, prepend a path to a relative file name */ /* 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) { if (!prepand_with
static char path[PATHLEN + 1]; || *file == '/') {
return file;
}
if(prependpath != NULL && *file != '/') { snprintf(path, sizeof(path), "%s/%s", prependpath, file);
(void)snprintf(path, sizeof(path), "%s/%s", prependpath, file); return path;
file = path;
}
return (file);
} }

View File

@ -554,7 +554,7 @@ size_t read_next_chunk(char **p, FILE *fptr)
return fread(*p, sizeof(**p), buf_end - *p, 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; char *p;
unsigned int cstat; unsigned int cstat;
int ccount; int ccount;

View File

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

View File

@ -193,7 +193,7 @@ extern int rl_point;
/* cscope functions called from more than one function or between files */ /* 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 *findsymbol(const char *pattern);
char *finddef(const char *pattern); char *finddef(const char *pattern);
char *findcalledby(const char *pattern); char *findcalledby(const char *pattern);
@ -253,7 +253,7 @@ void dispinit(void);
void display(void); void display(void);
void redisplay(void); void redisplay(void);
void drawscrollbar(int top, int bot); 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 editall(void);
void editref(int); void editref(int);
void entercurses(void); void entercurses(void);
@ -293,7 +293,7 @@ bool writerefsfound(void);
int findinit(const char *pattern_); 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 hash(const char * ss);
int execute(char *a, ...); int execute(char *a, ...);
long dbseek(long offset); long dbseek(long offset);