* do not reformat man(7)-style dates
@ 2011-11-01 16:24 Ingo Schwarze
2011-11-03 15:35 ` Kristaps Dzonsons
0 siblings, 1 reply; 3+ messages in thread
From: Ingo Schwarze @ 2011-11-01 16:24 UTC (permalink / raw)
To: tech
Hi,
while it's certainly a nice idea to reformat YYYY-MM-DD dates,
which are common in man(7) manuals, to the Month Day, Year form
used by mdoc(7), groff does not do this. I prefer groff-mandoc
compatibility over man-mdoc uniformity in case the two conflict.
So continue to accept YYYY-MM-DD, still do not warn about it,
and leave the formatting untouched.
OK?
Ingo
Index: mandoc.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandoc.c,v
retrieving revision 1.29
diff -u -p -r1.29 mandoc.c
--- mandoc.c 24 Oct 2011 20:29:21 -0000 1.29
+++ mandoc.c 1 Nov 2011 16:26:24 -0000
@@ -609,9 +609,10 @@ mandoc_normdate(struct mparse *parse, ch
mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
time(&t);
}
+ else if (a2time(&t, "%Y-%m-%d", in))
+ t = 0;
else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
- !a2time(&t, "%b %d, %Y", in) &&
- !a2time(&t, "%Y-%m-%d", in)) {
+ !a2time(&t, "%b %d, %Y", in)) {
mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
t = 0;
}
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: do not reformat man(7)-style dates
2011-11-01 16:24 do not reformat man(7)-style dates Ingo Schwarze
@ 2011-11-03 15:35 ` Kristaps Dzonsons
2011-11-13 11:43 ` Ingo Schwarze
0 siblings, 1 reply; 3+ messages in thread
From: Kristaps Dzonsons @ 2011-11-03 15:35 UTC (permalink / raw)
To: tech
[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]
> Index: mandoc.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mandoc/mandoc.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 mandoc.c
> --- mandoc.c 24 Oct 2011 20:29:21 -0000 1.29
> +++ mandoc.c 1 Nov 2011 16:26:24 -0000
> @@ -609,9 +609,10 @@ mandoc_normdate(struct mparse *parse, ch
> mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
> time(&t);
> }
> + else if (a2time(&t, "%Y-%m-%d", in))
> + t = 0;
> else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in)&&
> - !a2time(&t, "%b %d, %Y", in)&&
> - !a2time(&t, "%Y-%m-%d", in)) {
> + !a2time(&t, "%b %d, %Y", in)) {
> mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
> t = 0;
> }
Ingo,
Isn't it easier just to do as in the enclosed patch? man(7) doesn't
seem to care at all about the date, so let's stop pretending that it
does and just mandoc_strdup() instead of mandoc_normdate(). This patch
also moves mandoc_normdate(), mandoc.c, into mdoc_normdate(), mdoc.c.
Thoughts?
Kristaps
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 8907 bytes --]
? apropos
? config.h
? config.log
? demandoc
? foo.1
? foo.1.html
? mandoc
? mandoc.core
? mandocdb
? patch.txt
? preconv
? roff.bak.7
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.28
diff -u -p -r1.28 libmandoc.h
--- libmandoc.h 28 Jul 2011 14:17:11 -0000 1.28
+++ libmandoc.h 3 Nov 2011 15:33:05 -0000
@@ -45,7 +45,6 @@ void mandoc_msg(enum mandocerr, struct
void mandoc_vmsg(enum mandocerr, struct mparse *,
int, int, const char *, ...);
char *mandoc_getarg(struct mparse *, char **, int, int *);
-char *mandoc_normdate(struct mparse *, char *, int, int);
int mandoc_eos(const char *, size_t, int);
int mandoc_getcontrol(const char *, int *);
int mandoc_strntoi(const char *, size_t, int);
Index: libmdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmdoc.h,v
retrieving revision 1.77
diff -u -p -r1.77 libmdoc.h
--- libmdoc.h 18 Sep 2011 14:14:15 -0000 1.77
+++ libmdoc.h 3 Nov 2011 15:33:05 -0000
@@ -125,6 +125,7 @@ const char *mdoc_a2st(const char *);
const char *mdoc_a2arch(const char *);
const char *mdoc_a2vol(const char *);
const char *mdoc_a2msec(const char *);
+char *mdoc_normdate(struct mparse *, char *, int, int);
int mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
int mdoc_valid_post(struct mdoc *);
enum margverr mdoc_argv(struct mdoc *, int, enum mdoct,
Index: man.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.7,v
retrieving revision 1.111
diff -u -p -r1.111 man.7
--- man.7 26 Sep 2011 23:07:31 -0000 1.111
+++ man.7 3 Nov 2011 15:33:05 -0000
@@ -549,11 +549,7 @@ The recommended
.Ar date
format is
.Sy YYYY-MM-DD
-as specified in the ISO-8601 standard;
-if the argument does not conform, it is printed verbatim.
-If the
-.Ar date
-is empty or not specified, the current date is used.
+as specified in the ISO-8601 standard.
The optional
.Ar source
string specifies the organisation providing the utility.
Index: man.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v
retrieving revision 1.59
diff -u -p -r1.59 man.h
--- man.h 6 Oct 2011 22:29:12 -0000 1.59
+++ man.h 3 Nov 2011 15:33:05 -0000
@@ -68,7 +68,7 @@ enum man_type {
struct man_meta {
char *msec; /* `TH' section (1, 3p, etc.) */
- char *date; /* `TH' normalised date */
+ char *date; /* `TH' free-form date */
char *vol; /* `TH' volume */
char *title; /* `TH' title (e.g., FOO) */
char *source; /* `TH' source (e.g., GNU) */
Index: man_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_validate.c,v
retrieving revision 1.76
diff -u -p -r1.76 man_validate.c
--- man_validate.c 16 Oct 2011 12:20:34 -0000 1.76
+++ man_validate.c 3 Nov 2011 15:33:05 -0000
@@ -201,8 +201,7 @@ check_root(CHKARGS)
m->meta.title = mandoc_strdup("unknown");
m->meta.msec = mandoc_strdup("1");
- m->meta.date = mandoc_normdate
- (m->parse, NULL, n->line, n->pos);
+ m->meta.date = mandoc_strdup("");
}
return(1);
@@ -417,8 +416,8 @@ post_TH(CHKARGS)
n = n->next;
if (n)
pos = n->pos;
- m->meta.date = mandoc_normdate
- (m->parse, n ? n->string : NULL, line, pos);
+
+ m->meta.date = mandoc_strdup(n ? n->string : "");
/* TITLE MSEC DATE ->SOURCE<- VOL */
Index: mandoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.c,v
retrieving revision 1.60
diff -u -p -r1.60 mandoc.c
--- mandoc.c 24 Oct 2011 20:30:57 -0000 1.60
+++ mandoc.c 3 Nov 2011 15:33:06 -0000
@@ -33,10 +33,6 @@
#include "mandoc.h"
#include "libmandoc.h"
-#define DATESIZE 32
-
-static int a2time(time_t *, const char *, const char *);
-static char *time2a(time_t);
static int numescape(const char *);
/*
@@ -548,82 +544,6 @@ mandoc_getarg(struct mparse *parse, char
mandoc_msg(MANDOCERR_EOLNSPACE, parse, ln, *pos, NULL);
return(start);
-}
-
-static int
-a2time(time_t *t, const char *fmt, const char *p)
-{
- struct tm tm;
- char *pp;
-
- memset(&tm, 0, sizeof(struct tm));
-
- pp = NULL;
-#ifdef HAVE_STRPTIME
- pp = strptime(p, fmt, &tm);
-#endif
- if (NULL != pp && '\0' == *pp) {
- *t = mktime(&tm);
- return(1);
- }
-
- return(0);
-}
-
-static char *
-time2a(time_t t)
-{
- struct tm *tm;
- char *buf, *p;
- size_t ssz;
- int isz;
-
- tm = localtime(&t);
-
- /*
- * Reserve space:
- * up to 9 characters for the month (September) + blank
- * up to 2 characters for the day + comma + blank
- * 4 characters for the year and a terminating '\0'
- */
- p = buf = mandoc_malloc(10 + 4 + 4 + 1);
-
- if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm)))
- goto fail;
- p += (int)ssz;
-
- if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)))
- goto fail;
- p += isz;
-
- if (0 == strftime(p, 4 + 1, "%Y", tm))
- goto fail;
- return(buf);
-
-fail:
- free(buf);
- return(NULL);
-}
-
-char *
-mandoc_normdate(struct mparse *parse, char *in, int ln, int pos)
-{
- char *out;
- time_t t;
-
- if (NULL == in || '\0' == *in ||
- 0 == strcmp(in, "$" "Mdocdate$")) {
- mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
- time(&t);
- }
- else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
- !a2time(&t, "%b %d, %Y", in) &&
- !a2time(&t, "%Y-%m-%d", in)) {
- mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
- t = 0;
- }
- out = t ? time2a(t) : NULL;
- return(out ? out : mandoc_strdup(in));
}
int
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.196
diff -u -p -r1.196 mdoc.c
--- mdoc.c 30 Sep 2011 00:13:28 -0000 1.196
+++ mdoc.c 3 Nov 2011 15:33:06 -0000
@@ -102,6 +102,8 @@ static int mdoc_preptext(struct mdoc
#endif
static int mdoc_ptext(struct mdoc *, int, char *, int);
static int mdoc_pmacro(struct mdoc *, int, char *, int);
+static int a2time(time_t *, const char *, const char *);
+static char *time2a(time_t);
const struct mdoc_node *
mdoc_node(const struct mdoc *m)
@@ -333,7 +335,7 @@ mdoc_macro(MACRO_PROT_ARGS)
if (NULL == m->meta.os)
m->meta.os = mandoc_strdup("LOCAL");
if (NULL == m->meta.date)
- m->meta.date = mandoc_normdate
+ m->meta.date = mdoc_normdate
(m->parse, NULL, line, ppos);
m->flags |= MDOC_PBODY;
}
@@ -985,3 +987,80 @@ mdoc_isdelim(const char *p)
return(DELIM_NONE);
}
+
+char *
+mdoc_normdate(struct mparse *parse, char *in, int ln, int pos)
+{
+ char *out;
+ time_t t;
+
+ if (NULL == in || '\0' == *in ||
+ 0 == strcmp(in, "$" "Mdocdate$")) {
+ mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
+ time(&t);
+ }
+ else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
+ !a2time(&t, "%b %d, %Y", in) &&
+ !a2time(&t, "%Y-%m-%d", in)) {
+ mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
+ t = 0;
+ }
+ out = t ? time2a(t) : NULL;
+ return(out ? out : mandoc_strdup(in));
+}
+
+static int
+a2time(time_t *t, const char *fmt, const char *p)
+{
+ struct tm tm;
+ char *pp;
+
+ memset(&tm, 0, sizeof(struct tm));
+
+ pp = NULL;
+#ifdef HAVE_STRPTIME
+ pp = strptime(p, fmt, &tm);
+#endif
+ if (NULL != pp && '\0' == *pp) {
+ *t = mktime(&tm);
+ return(1);
+ }
+
+ return(0);
+}
+
+static char *
+time2a(time_t t)
+{
+ struct tm *tm;
+ char *buf, *p;
+ size_t ssz;
+ int isz;
+
+ tm = localtime(&t);
+
+ /*
+ * Reserve space:
+ * up to 9 characters for the month (September) + blank
+ * up to 2 characters for the day + comma + blank
+ * 4 characters for the year and a terminating '\0'
+ */
+ p = buf = mandoc_malloc(10 + 4 + 4 + 1);
+
+ if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm)))
+ goto fail;
+ p += (int)ssz;
+
+ if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)))
+ goto fail;
+ p += isz;
+
+ if (0 == strftime(p, 4 + 1, "%Y", tm))
+ goto fail;
+ return(buf);
+
+fail:
+ free(buf);
+ return(NULL);
+}
+
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.177
diff -u -p -r1.177 mdoc_validate.c
--- mdoc_validate.c 16 Oct 2011 12:20:34 -0000 1.177
+++ mdoc_validate.c 3 Nov 2011 15:33:06 -0000
@@ -1990,7 +1990,7 @@ post_dd(POST_ARGS)
n = mdoc->last;
if (NULL == n->child || '\0' == n->child->string[0]) {
- mdoc->meta.date = mandoc_normdate
+ mdoc->meta.date = mdoc_normdate
(mdoc->parse, NULL, n->line, n->pos);
return(1);
}
@@ -2002,7 +2002,7 @@ post_dd(POST_ARGS)
}
assert(c);
- mdoc->meta.date = mandoc_normdate
+ mdoc->meta.date = mdoc_normdate
(mdoc->parse, buf, n->line, n->pos);
return(1);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: do not reformat man(7)-style dates
2011-11-03 15:35 ` Kristaps Dzonsons
@ 2011-11-13 11:43 ` Ingo Schwarze
0 siblings, 0 replies; 3+ messages in thread
From: Ingo Schwarze @ 2011-11-13 11:43 UTC (permalink / raw)
To: tech
Hi Kristaps,
Kristaps Dzonsons wrote on Thu, Nov 03, 2011 at 04:35:08PM +0100:
> Ingo Schwarze wrote:
>>Index: mandoc.c
>>===================================================================
>>RCS file: /cvs/src/usr.bin/mandoc/mandoc.c,v
>>retrieving revision 1.29
>>diff -u -p -r1.29 mandoc.c
>>--- mandoc.c 24 Oct 2011 20:29:21 -0000 1.29
>>+++ mandoc.c 1 Nov 2011 16:26:24 -0000
>>@@ -609,9 +609,10 @@ mandoc_normdate(struct mparse *parse, ch
>> mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
>> time(&t);
>> }
>>+ else if (a2time(&t, "%Y-%m-%d", in))
>>+ t = 0;
>> else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in)&&
>>- !a2time(&t, "%b %d, %Y", in)&&
>>- !a2time(&t, "%Y-%m-%d", in)) {
>>+ !a2time(&t, "%b %d, %Y", in)) {
>> mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
>> t = 0;
>> }
> Isn't it easier just to do as in the enclosed patch?
Even though your patch is much larger than mine,
the resulting code is slightly simpler; granted.
> man(7) doesn't seem to care at all about the date, so let's stop
> pretending that it does and just mandoc_strdup() instead of
> mandoc_normdate().
Still, i don't like that approach. Even if groff does not care,
i'd still like to provide a WARNING if somebody puts
"Febuary 30, 2o11" \" note: three typos
"20l1_31_12" \" note: three errors
into a man(7) document.
Thus, i prefer my patch.
Yours,
Ingo
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-13 11:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 16:24 do not reformat man(7)-style dates Ingo Schwarze
2011-11-03 15:35 ` Kristaps Dzonsons
2011-11-13 11:43 ` Ingo Schwarze
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).