use to "feature" in DEBUGFILES
The code to lookup a value in DEBUGFILES usually operates on a file name, but there are few non-file uses. The latter wouldn't work on VMS because of the way it was manipulating the name: first stripping away path, suffix, and version, then adding hardcoded ".c" suffix on. I thought we already had a routine to get the base part of a name from a full path, but if so, I haven't been able to find it. This adds new nh_basename() to do that, with the option of either keeping or discarding the suffix or type portion. The VMS usage that prompted this hasn't actually been tested.
This commit is contained in:
@@ -868,6 +868,7 @@ extern void makerogueghost(void);
|
|||||||
|
|
||||||
/* ### files.c ### */
|
/* ### files.c ### */
|
||||||
|
|
||||||
|
extern const char *nh_basename(const char *, boolean);
|
||||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||||
extern int l_get_config_errors(lua_State *);
|
extern int l_get_config_errors(lua_State *);
|
||||||
#endif
|
#endif
|
||||||
@@ -3210,7 +3211,7 @@ extern int vms_creat(const char *, unsigned int);
|
|||||||
extern int vms_open(const char *, int, unsigned int);
|
extern int vms_open(const char *, int, unsigned int);
|
||||||
extern boolean same_dir(const char *, const char *);
|
extern boolean same_dir(const char *, const char *);
|
||||||
extern int c__translate(int);
|
extern int c__translate(int);
|
||||||
extern char *vms_basename(const char *);
|
extern char *vms_basename(const char *, boolean);
|
||||||
|
|
||||||
/* ### vmsmail.c ### */
|
/* ### vmsmail.c ### */
|
||||||
|
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ typedef int32_t off_t;
|
|||||||
extern void vms_exit(int);
|
extern void vms_exit(int);
|
||||||
extern int vms_open(const char *, int, unsigned);
|
extern int vms_open(const char *, int, unsigned);
|
||||||
extern FILE *vms_fopen(const char *, const char *);
|
extern FILE *vms_fopen(const char *, const char *);
|
||||||
char *vms_basename(const char *); /* vmsfiles.c */
|
char *vms_basename(const char *, boolean); /* vmsfiles.c */
|
||||||
|
|
||||||
#endif /* VMSCONF_H */
|
#endif /* VMSCONF_H */
|
||||||
#endif /* VMS */
|
#endif /* VMS */
|
||||||
|
|||||||
48
src/files.c
48
src/files.c
@@ -232,6 +232,40 @@ static boolean copy_bytes(int, int);
|
|||||||
#endif
|
#endif
|
||||||
static NHFILE *viable_nhfile(NHFILE *);
|
static NHFILE *viable_nhfile(NHFILE *);
|
||||||
|
|
||||||
|
/* return a file's name without its path and optionally trailing 'type' */
|
||||||
|
const char *
|
||||||
|
nh_basename(const char *fname, boolean keep_suffix)
|
||||||
|
{
|
||||||
|
#ifndef VMS
|
||||||
|
static char basebuf[80];
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
if ((p = strrchr(fname, '/')) != 0)
|
||||||
|
fname = p + 1;
|
||||||
|
#if defined(WIN32) || defined(MSDOS)
|
||||||
|
if ((p = strrchr(fname, '\\')) != 0)
|
||||||
|
fname = p + 1;
|
||||||
|
#endif
|
||||||
|
if ((p = strrchr(fname, '.')) != 0 && !keep_suffix) {
|
||||||
|
size_t ln = (size_t) (p - fname);
|
||||||
|
/* note that without path, name should be reasonable length;
|
||||||
|
it is expected to refer to a source file name or run-time
|
||||||
|
configuration file name and those aren't arbitrarily long;
|
||||||
|
if "name" part of "name.suffix" is too long for 'basebuf[]',
|
||||||
|
just return that as-is without stripping off ".suffix" */
|
||||||
|
|
||||||
|
if (ln < sizeof basebuf) {
|
||||||
|
strncpy(basebuf, fname, ln);
|
||||||
|
basebuf[ln] = '\0';
|
||||||
|
fname = basebuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else /* VMS */
|
||||||
|
fname = vms_basename(fname, keep_suffix);
|
||||||
|
#endif
|
||||||
|
return fname;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fname_encode()
|
* fname_encode()
|
||||||
*
|
*
|
||||||
@@ -4437,18 +4471,8 @@ debugcore(const char *filename, boolean wildcards)
|
|||||||
if (!debugfiles || !*debugfiles)
|
if (!debugfiles || !*debugfiles)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* strip filename's path if present */
|
/* strip filename's path if present */
|
||||||
#ifdef UNIX
|
filename = nh_basename(filename, TRUE);
|
||||||
if ((p = strrchr(filename, '/')) != 0)
|
|
||||||
filename = p + 1;
|
|
||||||
#endif
|
|
||||||
#ifdef VMS
|
|
||||||
filename = vms_basename(filename);
|
|
||||||
/* vms_basename strips off 'type' suffix as well as path and version;
|
|
||||||
we want to put suffix back (".c" assumed); since it always returns
|
|
||||||
a pointer to a static buffer, we can safely modify its result */
|
|
||||||
Strcat((char *) filename, ".c");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wildcard match will only work if there's a single pattern (which
|
* Wildcard match will only work if there's a single pattern (which
|
||||||
|
|||||||
@@ -305,10 +305,10 @@ static char base_name[NAM$C_MAXRSS + 1];
|
|||||||
|
|
||||||
/* return a copy of the 'base' portion of a filename */
|
/* return a copy of the 'base' portion of a filename */
|
||||||
char *
|
char *
|
||||||
vms_basename(const char *name)
|
vms_basename(const char *name, boolean keep_suffix)
|
||||||
{
|
{
|
||||||
unsigned len;
|
unsigned len;
|
||||||
char *base, *base_p;
|
char *base, *base_p, *xtra_p;
|
||||||
register const char *name_p;
|
register const char *name_p;
|
||||||
|
|
||||||
/* skip directory/path */
|
/* skip directory/path */
|
||||||
@@ -323,10 +323,14 @@ vms_basename(const char *name)
|
|||||||
if (!*name)
|
if (!*name)
|
||||||
name = "."; /* this should never happen */
|
name = "."; /* this should never happen */
|
||||||
|
|
||||||
/* find extension/version and derive length of basename */
|
/* find extension/version and derive length of basename;
|
||||||
if ((name_p = strchr(name, '.')) == 0 || name_p == name)
|
for 'keep_suffix', this won't be accurate if version number is
|
||||||
name_p = strchr(name, ';');
|
present and delimited by dot instead of semi-colon, but normal
|
||||||
len = (name_p && name_p > name) ? name_p - name : strlen(name);
|
usage is for DEBUGFILES and that uses compiler supplied name */
|
||||||
|
name_p = strrchr(name, ';');
|
||||||
|
if (!keep_suffix && (xtra_p = strrchr(name, '.')) != 0)
|
||||||
|
name_p = xtra_p;
|
||||||
|
len = (name_p && name_p > name) ? name_p - name : (unsigned) strlen(name);
|
||||||
|
|
||||||
/* return a lowercase copy of the name in a private static buffer */
|
/* return a lowercase copy of the name in a private static buffer */
|
||||||
base = strncpy(base_name, name, len);
|
base = strncpy(base_name, name, len);
|
||||||
|
|||||||
Reference in New Issue
Block a user