]> git.cameronkatri.com Git - mandoc.git/blobdiff - mandoc.c
Place mandoc.css into the public domain.
[mandoc.git] / mandoc.c
index 3e16d2c64fbc616d6182274560d66a9e2fd85ccb..5476fb410e2d2f25d706f1be70b7ffb0865e9775 100644 (file)
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,7 +1,7 @@
-/*     $Id: mandoc.c,v 1.103 2017/07/03 13:40:19 schwarze Exp $ */
+/*     $Id: mandoc.c,v 1.108 2018/10/25 01:32:40 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -41,7 +41,7 @@ enum mandoc_esc
 mandoc_escape(const char **end, const char **start, int *sz)
 {
        const char      *local_start;
-       int              local_sz;
+       int              local_sz, c, i;
        char             term;
        enum mandoc_esc  gly;
 
@@ -139,6 +139,13 @@ mandoc_escape(const char **end, const char **start, int *sz)
                        break;
                }
                break;
+       case '*':
+               if (strncmp(*start, "(.T", 3) != 0)
+                       abort();
+               gly = ESCAPE_DEVICE;
+               *start = ++*end;
+               *sz = 2;
+               break;
 
        /*
         * These escapes are of the form \X'Y', where 'X' is the trigger
@@ -295,21 +302,29 @@ mandoc_escape(const char **end, const char **start, int *sz)
 
        switch (gly) {
        case ESCAPE_FONT:
-               if (2 == *sz) {
-                       if ('C' == **start) {
+               if (*sz == 2) {
+                       if (**start == 'C') {
+                               if ((*start)[1] == 'W' ||
+                                   (*start)[1] == 'R') {
+                                       gly = ESCAPE_FONTCW;
+                                       break;
+                               }
                                /*
-                                * Treat constant-width font modes
+                                * Treat other constant-width font modes
                                 * just like regular font modes.
                                 */
                                (*start)++;
                                (*sz)--;
                        } else {
-                               if ('B' == (*start)[0] && 'I' == (*start)[1])
+                               if ((*start)[0] == 'B' && (*start)[1] == 'I')
                                        gly = ESCAPE_FONTBI;
                                break;
                        }
-               } else if (1 != *sz)
+               } else if (*sz != 1) {
+                       if (*sz == 0)
+                               gly = ESCAPE_FONTPREV;
                        break;
+               }
 
                switch (**start) {
                case '3':
@@ -330,8 +345,26 @@ mandoc_escape(const char **end, const char **start, int *sz)
                }
                break;
        case ESCAPE_SPECIAL:
-               if (1 == *sz && 'c' == **start)
-                       gly = ESCAPE_NOSPACE;
+               if (**start == 'c') {
+                       if (*sz == 1) {
+                               gly = ESCAPE_NOSPACE;
+                               break;
+                       }
+                       if (*sz < 6 || *sz > 7 ||
+                           strncmp(*start, "char", 4) != 0 ||
+                           (int)strspn(*start + 4, "0123456789") + 4 < *sz)
+                               break;
+                       c = 0;
+                       for (i = 4; i < *sz; i++)
+                               c = 10 * c + ((*start)[i] - '0');
+                       if (c < 0x21 || (c > 0x7e && c < 0xa0) || c > 0xff)
+                               break;
+                       *start += 4;
+                       *sz -= 4;
+                       gly = ESCAPE_NUMBERED;
+                       break;
+               }
+
                /*
                 * Unicode escapes are defined in groff as \[u0000]
                 * to \[u10FFFF], where the contained value must be
@@ -541,6 +574,9 @@ mandoc_normdate(struct roff_man *man, char *in, int ln, int pos)
                if (t > time(NULL) + 86400)
                        mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse,
                            ln, pos, cp);
+               else if (*in != '$' && strcmp(in, cp) != 0)
+                       mandoc_msg(MANDOCERR_DATE_NORM, man->parse,
+                           ln, pos, cp);
                return cp;
        }