1 /* $Id: mandoc.c,v 1.103 2017/07/03 13:40:19 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <errno.h>
524 mandoc_normdate(struct roff_man *man, char *in, int ln, int pos)
525 {
526 char *cp;
527 time_t t;
528
529 /* No date specified: use today's date. */
530
531 if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) {
532 mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, ln, pos, NULL);
533 return time2a(time(NULL));
534 }
535
536 /* Valid mdoc(7) date format. */
537
538 if (a2time(&t, "$" "Mdocdate: %b %d %Y $", in) ||
539 a2time(&t, "%b %d, %Y", in)) {
540 cp = time2a(t);
541 if (t > time(NULL) + 86400)
542 mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse,
543 ln, pos, cp);
544 return cp;
545 }
546
547 /* In man(7), do not warn about the legacy format. */
548
549 if (a2time(&t, "%Y-%m-%d", in) == 0)
550 mandoc_msg(MANDOCERR_DATE_BAD, man->parse, ln, pos, in);
551 else if (t > time(NULL) + 86400)
552 mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, ln, pos, in);
553 else if (man->macroset == MACROSET_MDOC)
554 mandoc_vmsg(MANDOCERR_DATE_LEGACY, man->parse,
555 ln, pos, "Dd %s", in);
556
557 /* Use any non-mdoc(7) date verbatim. */
558
559 return mandoc_strdup(in);
560 }
561
562 int
563 mandoc_eos(const char *p, size_t sz)
|
1 /* $Id: mandoc.c,v 1.104 2018/07/28 18:34:15 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <errno.h>
524 mandoc_normdate(struct roff_man *man, char *in, int ln, int pos)
525 {
526 char *cp;
527 time_t t;
528
529 /* No date specified: use today's date. */
530
531 if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) {
532 mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, ln, pos, NULL);
533 return time2a(time(NULL));
534 }
535
536 /* Valid mdoc(7) date format. */
537
538 if (a2time(&t, "$" "Mdocdate: %b %d %Y $", in) ||
539 a2time(&t, "%b %d, %Y", in)) {
540 cp = time2a(t);
541 if (t > time(NULL) + 86400)
542 mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse,
543 ln, pos, cp);
544 else if (*in != '$' && strcmp(in, cp) != 0)
545 mandoc_msg(MANDOCERR_DATE_NORM, man->parse,
546 ln, pos, cp);
547 return cp;
548 }
549
550 /* In man(7), do not warn about the legacy format. */
551
552 if (a2time(&t, "%Y-%m-%d", in) == 0)
553 mandoc_msg(MANDOCERR_DATE_BAD, man->parse, ln, pos, in);
554 else if (t > time(NULL) + 86400)
555 mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, ln, pos, in);
556 else if (man->macroset == MACROSET_MDOC)
557 mandoc_vmsg(MANDOCERR_DATE_LEGACY, man->parse,
558 ln, pos, "Dd %s", in);
559
560 /* Use any non-mdoc(7) date verbatim. */
561
562 return mandoc_strdup(in);
563 }
564
565 int
566 mandoc_eos(const char *p, size_t sz)
|