summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-09-24 13:18:10 +0100
committerColin Watson <cjwatson@debian.org>2022-09-24 13:18:10 +0100
commit40cd7c5a3e05e6d830f1cf39fe6532804b51dae2 (patch)
treed7c9a13ff4a11d72fc0d223d9157703f09a2c5b5 /src
parentd9277251cfc21038121ca11ae623183a2c4f0be8 (diff)
filename_info: Always allocate info->name
Only one call site has any interest in this being unset (in order to pass the result to `dbstore`), and even there it's easier for the caller to deal with unsetting it. Otherwise, it's strictly more convenient if the structure returned by `filename_info` always includes the name of the page. * lib/filenames.c (filename_info): Remove `req_name` parameter; update all callers. Always set `info->name` before returning successfully. * lib/filenames.h (filename_info): Update prototype. * src/check_mandirs.c (test_manfile): Use `info->name` for `manpage_base` rather than poking around in `info->addr`. (count_glob_matches): Remove `name` parameter; update all callers. * src/descriptions_store.c (store_descriptions): Drop now-unnecessary check for `trace_info->name`. * src/man.c (do_global_apropos_section): Build `title` using `info->name` rather than poking around in `info->addr`. * src/mandb.c (update_one_file): Drop now-unnecessary check for `info->name`.
Diffstat (limited to 'src')
-rw-r--r--src/check_mandirs.c18
-rw-r--r--src/descriptions_store.c4
-rw-r--r--src/man.c8
-rw-r--r--src/mandb.c4
4 files changed, 16 insertions, 18 deletions
diff --git a/src/check_mandirs.c b/src/check_mandirs.c
index 75428c35..419efb5d 100644
--- a/src/check_mandirs.c
+++ b/src/check_mandirs.c
@@ -168,10 +168,11 @@ void test_manfile (MYDBM_FILE dbf, const char *file, const char *path)
memset (&lg, 0, sizeof (struct lexgrog));
- info = filename_info (file, NULL, quiet < 2);
+ info = filename_info (file, quiet < 2);
if (!info)
return;
- manpage_base = info->addr + strlen (info->addr) + 1;
+ manpage_base = info->name; /* steal memory */
+ info->name = NULL;
len = strlen (info->addr) + 1; /* skip over directory name */
len += strlen (info->addr + len) + 1; /* skip over base name */
@@ -761,8 +762,8 @@ pointers_next:
* (which may return inexact extension matches in some cases). It may turn
* out that this is better handled in look_for_file() itself.
*/
-static int count_glob_matches (const char *name, const char *ext,
- gl_list_t source, struct timespec db_mtime)
+static int count_glob_matches (const char *ext, gl_list_t source,
+ struct timespec db_mtime)
{
const char *walk;
int count = 0;
@@ -783,7 +784,7 @@ static int count_glob_matches (const char *name, const char *ext,
continue;
}
- info = filename_info (walk, name, quiet < 2);
+ info = filename_info (walk, quiet < 2);
if (info) {
if (STREQ (ext, info->ext))
++count;
@@ -807,7 +808,7 @@ static int purge_normal (MYDBM_FILE dbf, const char *name,
*/
t.tv_sec = -1;
t.tv_nsec = -1;
- if (count_glob_matches (name, info->ext, found, t))
+ if (count_glob_matches (info->ext, found, t))
return 0;
if (!opt_test)
@@ -827,7 +828,7 @@ static int purge_whatis (MYDBM_FILE dbf, const char *path, int cat,
/* TODO: On some systems, the cat page extension differs from the
* man page extension, so this may be too strict.
*/
- if (count_glob_matches (name, info->ext, found, db_mtime)) {
+ if (count_glob_matches (info->ext, found, db_mtime)) {
/* If the page exists and didn't beforehand, then presumably
* we're about to rescan, which will replace the WHATIS_MAN
* entry with something better. However, there have been
@@ -873,8 +874,7 @@ static int purge_whatis (MYDBM_FILE dbf, const char *path, int cat,
t.tv_sec = -1;
t.tv_nsec = -1;
- count = count_glob_matches (info->pointer, info->ext,
- real_found, t);
+ count = count_glob_matches (info->ext, real_found, t);
gl_list_free (real_found);
if (count)
return 0;
diff --git a/src/descriptions_store.c b/src/descriptions_store.c
index 96c0b028..fcaab2a7 100644
--- a/src/descriptions_store.c
+++ b/src/descriptions_store.c
@@ -102,9 +102,9 @@ void store_descriptions (MYDBM_FILE dbf, gl_list_t descs, struct mandata *info,
struct mandata *trace_info;
struct stat st;
- trace_info = filename_info (trace_name, "",
+ trace_info = filename_info (trace_name,
quiet < 2);
- if (!trace_info || !trace_info->name ||
+ if (!trace_info ||
!STREQ (trace_info->name, desc->name))
goto next_trace;
diff --git a/src/man.c b/src/man.c
index 5c7bfc45..e0e878e1 100644
--- a/src/man.c
+++ b/src/man.c
@@ -3159,8 +3159,7 @@ static int try_section (const char *path, const char *sec, const char *name,
order_files (path, &names);
GL_LIST_FOREACH (names, found_name) {
- struct mandata *info = filename_info (found_name, name,
- quiet < 2);
+ struct mandata *info = filename_info (found_name, quiet < 2);
const char *ult;
int f;
@@ -3726,12 +3725,11 @@ static int do_global_apropos_section (const char *path, const char *sec,
if (!grep (found_name, name, &search))
continue;
- info = filename_info (found_name, NULL, quiet < 2);
+ info = filename_info (found_name, quiet < 2);
if (!info)
goto next;
- title = xasprintf ("%s(%s)", strchr (info->addr, '\0') + 1,
- info->ext);
+ title = xasprintf ("%s(%s)", info->name, info->ext);
man_file = ult_src (found_name, path, NULL, ult_flags, NULL);
if (!man_file)
goto next;
diff --git a/src/mandb.c b/src/mandb.c
index 95319b74..b189a8d9 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -356,8 +356,8 @@ static int update_one_file (MYDBM_FILE dbf,
if (dbf->file || MYDBM_RWOPEN (dbf)) {
struct mandata *info;
- info = filename_info (filename, "", quiet < 2);
- if (info && info->name) {
+ info = filename_info (filename, quiet < 2);
+ if (info) {
dbdelete (dbf, info->name, info);
purge_pointers (dbf, info->name);
}