From: Yuri Pankov <yuri.pankov@gmail.com>
To: discuss@mdocml.bsd.lv
Subject: Use OSNAME/uname and msec.in for man(7) input
Date: Sat, 8 Oct 2011 01:14:28 +0400 [thread overview]
Message-ID: <20111007211428.GG1294@procyon.xvoid.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 384 bytes --]
Hi,
I want to propose the following change to man_validate.c - if we are
missing SOURCE and VOL in TH, do the same as for the mdoc manpages -
use OSNAME, if it's not defined, use uname output and get the VOL from
msec.in if VOL isn't defined in manpage. I've attached the diff that
seems to work for me (mostly just copy/paste from mdoc_validate.c), hope
the idea sounds ok..
Yuri
[-- Attachment #2: mandoc.diff --]
[-- Type: text/x-diff, Size: 3504 bytes --]
diff -r e29e4165c957 usr/src/cmd/mandoc/libmdoc.h
--- a/usr/src/cmd/mandoc/libmdoc.h Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/libmdoc.h Sat Oct 08 01:01:42 2011 +0400
@@ -124,7 +124,6 @@
const char *mdoc_a2st(const char *);
const char *mdoc_a2arch(const char *);
const char *mdoc_a2vol(const char *);
-const char *mdoc_a2msec(const char *);
int mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
int mdoc_valid_post(struct mdoc *);
enum margverr mdoc_argv(struct mdoc *, int, enum mdoct,
diff -r e29e4165c957 usr/src/cmd/mandoc/man_validate.c
--- a/usr/src/cmd/mandoc/man_validate.c Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/man_validate.c Sat Oct 08 01:01:42 2011 +0400
@@ -19,6 +19,10 @@
#include "config.h"
#endif
+#ifndef OSNAME
+#include <sys/utsname.h>
+#endif
+
#include <sys/types.h>
#include <assert.h>
@@ -357,8 +361,12 @@
static int
post_TH(CHKARGS)
{
- const char *p;
+ char buf[BUFSIZ];
+ const char *cp, *p;
int line, pos;
+#ifndef OSNAME
+ struct utsname utsname;
+#endif
if (m->meta.title)
free(m->meta.title);
@@ -412,13 +420,47 @@
/* TITLE MSEC DATE ->SOURCE<- VOL */
- if (n && (n = n->next))
+ if (n && (n = n->next)) {
m->meta.source = mandoc_strdup(n->string);
+ } else {
+#ifdef OSNAME
+ if (strlcpy(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
+ man_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+#else /*!OSNAME */
+ if (-1 == uname(&utsname)) {
+ man_nmsg(m, n, MANDOCERR_UNAME);
+ m->meta.source = mandoc_strdup("UNKNOWN");
+ return(0);
+ }
+
+ if (strlcpy(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
+ man_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+ if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) {
+ man_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+ if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
+ man_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+#endif /*!OSNAME*/
+ m->meta.source = mandoc_strdup(buf);
+ }
/* TITLE MSEC DATE SOURCE ->VOL<- */
- if (n && (n = n->next))
+ if (n && (n = n->next)) {
m->meta.vol = mandoc_strdup(n->string);
+ } else {
+ if (NULL != (cp = mandoc_a2msec(m->meta.msec)))
+ m->meta.vol = mandoc_strdup(cp);
+ else
+ m->meta.vol = mandoc_strdup("UNKNOWN");
+ }
/*
* Remove the `TH' node after we've processed it for our
diff -r e29e4165c957 usr/src/cmd/mandoc/mandoc.h
--- a/usr/src/cmd/mandoc/mandoc.h Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/mandoc.h Sat Oct 08 01:01:42 2011 +0400
@@ -409,6 +409,8 @@
const char *mparse_strerror(enum mandocerr);
const char *mparse_strlevel(enum mandoclevel);
+const char *mandoc_a2msec(const char *);
+
void *mandoc_calloc(size_t, size_t);
void *mandoc_malloc(size_t);
void *mandoc_realloc(void *, size_t);
diff -r e29e4165c957 usr/src/cmd/mandoc/mdoc_validate.c
--- a/usr/src/cmd/mandoc/mdoc_validate.c Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/mdoc_validate.c Sat Oct 08 01:01:42 2011 +0400
@@ -2077,7 +2077,7 @@
* arch = NULL
*/
- cp = mdoc_a2msec(nn->string);
+ cp = mandoc_a2msec(nn->string);
if (cp) {
mdoc->meta.vol = mandoc_strdup(cp);
mdoc->meta.msec = mandoc_strdup(nn->string);
diff -r e29e4165c957 usr/src/cmd/mandoc/msec.c
--- a/usr/src/cmd/mandoc/msec.c Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/msec.c Sat Oct 08 01:01:42 2011 +0400
@@ -29,7 +29,7 @@
if (0 == strcmp(p, x)) return(y);
const char *
-mdoc_a2msec(const char *p)
+mandoc_a2msec(const char *p)
{
#include "msec.in"
next reply other threads:[~2011-10-07 21:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-07 21:14 Yuri Pankov [this message]
2011-10-07 22:12 ` Kristaps Dzonsons
2011-10-07 22:21 ` Yuri Pankov
2011-10-09 22:33 ` Ingo Schwarze
2011-10-10 2:39 ` Yuri Pankov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111007211428.GG1294@procyon.xvoid.org \
--to=yuri.pankov@gmail.com \
--cc=discuss@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).