aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-01-02 20:24:39 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-01-02 20:24:39 +0000
commitd20ac4526efe7743f187888af3cbbac672857bbf (patch)
tree8e61ed6e94a7cf1e405f1ffb043154f59338c3d7 /mandocdb.c
parent2e3140fd6827475a7eddf589dfb5d7f1409cb9aa (diff)
downloadmandoc-d20ac4526efe7743f187888af3cbbac672857bbf.tar.gz
mandoc-d20ac4526efe7743f187888af3cbbac672857bbf.tar.zst
mandoc-d20ac4526efe7743f187888af3cbbac672857bbf.zip
Polish the mlink_add() interface:
Allocate memory inside, not in the callers. No functional change.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 642e6104..90129460 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.93 2014/01/02 18:52:15 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.94 2014/01/02 20:24:39 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -522,8 +522,8 @@ treescan(void)
FTSENT *ff;
struct mlink *mlink;
int dform;
- char *fsec;
- const char *dsec, *arch, *cp, *path;
+ char *dsec, *arch, *fsec, *cp;
+ const char *path;
const char *argv[2];
argv[0] = ".";
@@ -588,16 +588,14 @@ treescan(void)
continue;
} else
fsec[-1] = '\0';
+
mlink = mandoc_calloc(1, sizeof(struct mlink));
strlcpy(mlink->file, path, sizeof(mlink->file));
mlink->dform = dform;
- if (NULL != dsec)
- mlink->dsec = mandoc_strdup(dsec);
- if (NULL != arch)
- mlink->arch = mandoc_strdup(arch);
- mlink->name = mandoc_strdup(ff->fts_name);
- if (NULL != fsec)
- mlink->fsec = mandoc_strdup(fsec);
+ mlink->dsec = dsec;
+ mlink->arch = arch;
+ mlink->name = ff->fts_name;
+ mlink->fsec = fsec;
mlink_add(mlink, ff->fts_statp);
continue;
} else if (FTS_D != ff->fts_info &&
@@ -617,8 +615,6 @@ treescan(void)
* Try to infer this from the name.
* If we're not in use_all, enforce it.
*/
- dsec = NULL;
- dform = FORM_NONE;
cp = ff->fts_name;
if (FTS_DP == ff->fts_info)
break;
@@ -629,6 +625,9 @@ treescan(void)
} else if (0 == strncmp(cp, "cat", 3)) {
dform = FORM_CAT;
dsec = cp + 3;
+ } else {
+ dform = FORM_NONE;
+ dsec = NULL;
}
if (NULL != dsec || use_all)
@@ -643,9 +642,10 @@ treescan(void)
* Possibly our architecture.
* If we're descending, keep tabs on it.
*/
- arch = NULL;
if (FTS_DP != ff->fts_info && NULL != dsec)
arch = ff->fts_name;
+ else
+ arch = NULL;
break;
default:
if (FTS_DP == ff->fts_info || use_all)
@@ -719,16 +719,16 @@ filescan(const char *file)
*p++ = '\0';
if (0 == strncmp(start, "man", 3)) {
mlink->dform = FORM_SRC;
- mlink->dsec = mandoc_strdup(start + 3);
+ mlink->dsec = start + 3;
} else if (0 == strncmp(start, "cat", 3)) {
mlink->dform = FORM_CAT;
- mlink->dsec = mandoc_strdup(start + 3);
+ mlink->dsec = start + 3;
}
start = p;
if (NULL != mlink->dsec && NULL != (p = strchr(start, '/'))) {
*p++ = '\0';
- mlink->arch = mandoc_strdup(start);
+ mlink->arch = start;
start = p;
}
}
@@ -743,7 +743,7 @@ filescan(const char *file)
if ('.' == *p) {
*p++ = '\0';
- mlink->fsec = mandoc_strdup(p);
+ mlink->fsec = p;
}
/*
@@ -755,8 +755,6 @@ filescan(const char *file)
mlink->name = p + 1;
*p = '\0';
}
- mlink->name = mandoc_strdup(mlink->name);
-
mlink_add(mlink, &st);
}
@@ -769,14 +767,10 @@ mlink_add(struct mlink *mlink, const struct stat *st)
assert(NULL != mlink->file);
- if (NULL == mlink->dsec)
- mlink->dsec = mandoc_strdup("");
- if (NULL == mlink->arch)
- mlink->arch = mandoc_strdup("");
- if (NULL == mlink->name)
- mlink->name = mandoc_strdup("");
- if (NULL == mlink->fsec)
- mlink->fsec = mandoc_strdup("");
+ mlink->dsec = mandoc_strdup(mlink->dsec ? mlink->dsec : "");
+ mlink->arch = mandoc_strdup(mlink->arch ? mlink->arch : "");
+ mlink->name = mandoc_strdup(mlink->name ? mlink->name : "");
+ mlink->fsec = mandoc_strdup(mlink->fsec ? mlink->fsec : "");
if ('0' == *mlink->fsec) {
free(mlink->fsec);