]> git.cameronkatri.com Git - mandoc.git/blobdiff - html.c
Update historical record to be historical and not made-up. Data from
[mandoc.git] / html.c
diff --git a/html.c b/html.c
index 5203abdbfb1a0ecd65bf769500b15000c34125b8..326df035fc443c83adaa3b25773ab43a3bb284de 100644 (file)
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/*     $Id: html.c,v 1.142 2011/05/17 11:34:31 kristaps Exp $ */
+/*     $Id: html.c,v 1.150 2011/10/05 21:35:17 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -108,8 +108,6 @@ static      const char      *const roffscales[SCALE_MAX] = {
 };
 
 static void     bufncat(struct html *, const char *, size_t);
-static void     print_spec(struct html *, const char *, size_t);
-static void     print_res(struct html *, const char *, size_t);
 static void     print_ctag(struct html *, enum htmltag);
 static int      print_encode(struct html *, const char *, int);
 static void     print_metaf(struct html *, enum mandoc_esc);
@@ -120,13 +118,14 @@ static void *
 ml_alloc(char *outopts, enum htmltype type)
 {
        struct html     *h;
-       const char      *toks[4];
+       const char      *toks[5];
        char            *v;
 
        toks[0] = "style";
        toks[1] = "man";
        toks[2] = "includes";
-       toks[3] = NULL;
+       toks[3] = "fragment";
+       toks[4] = NULL;
 
        h = mandoc_calloc(1, sizeof(struct html));
 
@@ -145,6 +144,9 @@ ml_alloc(char *outopts, enum htmltype type)
                case (2):
                        h->base_includes = v;
                        break;
+               case (3):
+                       h->oflags |= HTML_FRAGMENT;
+                       break;
                default:
                        break;
                }
@@ -218,45 +220,6 @@ print_gen_head(struct html *h)
        }
 }
 
-static void
-print_spec(struct html *h, const char *p, size_t len)
-{
-       int              cp;
-       const char      *rhs;
-       size_t           sz;
-
-       if ((cp = mchars_spec2cp(h->symtab, p, len)) > 0) {
-               printf("&#%d;", cp);
-               return;
-       } else if (-1 == cp && 1 == len) {
-               fwrite(p, 1, len, stdout);
-               return;
-       } else if (-1 == cp)
-               return;
-
-       if (NULL != (rhs = mchars_spec2str(h->symtab, p, len, &sz)))
-               fwrite(rhs, 1, sz, stdout);
-}
-
-
-static void
-print_res(struct html *h, const char *p, size_t len)
-{
-       int              cp;
-       const char      *rhs;
-       size_t           sz;
-
-       if ((cp = mchars_res2cp(h->symtab, p, len)) > 0) {
-               printf("&#%d;", cp);
-               return;
-       } else if (-1 == cp)
-               return;
-
-       if (NULL != (rhs = mchars_res2str(h->symtab, p, len, &sz)))
-               fwrite(rhs, 1, sz, stdout);
-}
-
-
 static void
 print_metaf(struct html *h, enum mandoc_esc deco)
 {
@@ -272,6 +235,8 @@ print_metaf(struct html *h, enum mandoc_esc deco)
        case (ESCAPE_FONTBOLD):
                font = HTMLFONT_BOLD;
                break;
+       case (ESCAPE_FONT):
+               /* FALLTHROUGH */
        case (ESCAPE_FONTROMAN):
                font = HTMLFONT_NONE;
                break;
@@ -315,9 +280,9 @@ html_strlen(const char *cp)
                switch (mandoc_escape(&cp, &seq, &ssz)) {
                case (ESCAPE_ERROR):
                        return(sz);
-               case (ESCAPE_NUMBERED):
+               case (ESCAPE_UNICODE):
                        /* FALLTHROUGH */
-               case (ESCAPE_PREDEF):
+               case (ESCAPE_NUMBERED):
                        /* FALLTHROUGH */
                case (ESCAPE_SPECIAL):
                        sz++;
@@ -373,17 +338,26 @@ print_encode(struct html *h, const char *p, int norecurse)
                        break;
 
                switch (esc) {
+               case (ESCAPE_UNICODE):
+                       /* Skip passed "u" header. */
+                       c = mchars_num2uc(seq + 1, len - 1);
+                       if ('\0' != c)
+                               printf("&#x%x;", c);
+                       break;
                case (ESCAPE_NUMBERED):
                        c = mchars_num2char(seq, len);
                        if ('\0' != c)
                                putchar(c);
                        break;
-               case (ESCAPE_PREDEF):
-                       print_res(h, seq, len);
-                       break;
                case (ESCAPE_SPECIAL):
-                       print_spec(h, seq, len);
+                       c = mchars_spec2cp(h->symtab, seq, len);
+                       if (c > 0)
+                               printf("&#%d;", c);
+                       else if (-1 == c && 1 == len)
+                               putchar((int)*seq);
                        break;
+               case (ESCAPE_FONT):
+                       /* FALLTHROUGH */
                case (ESCAPE_FONTPREV):
                        /* FALLTHROUGH */
                case (ESCAPE_FONTBOLD):
@@ -543,9 +517,11 @@ print_text(struct html *h, const char *word)
                        print_otag(h, TAG_I, 0, NULL);
 
        assert(word);
-       if ( ! print_encode(h, word, 0))
+       if ( ! print_encode(h, word, 0)) {
                if ( ! (h->flags & HTML_NONOSPACE))
                        h->flags &= ~HTML_NOSPACE;
+       } else
+               h->flags |= HTML_NOSPACE;
 
        if (h->metaf) {
                print_tagq(h, h->metaf);
@@ -625,7 +601,6 @@ bufcat(struct html *h, const char *p)
 
        h->buflen = strlcat(h->buf, p, BUFSIZ);
        assert(h->buflen < BUFSIZ);
-       h->buflen--;
 }
 
 void
@@ -656,6 +631,7 @@ buffmt_includes(struct html *h, const char *name)
 
        pp = h->base_includes;
        
+       bufinit(h);
        while (NULL != (p = strchr(pp, '%'))) {
                bufncat(h, pp, (size_t)(p - pp));
                switch (*(p + 1)) {
@@ -680,7 +656,7 @@ buffmt_man(struct html *h,
 
        pp = h->base_man;
        
-       /* LINTED */
+       bufinit(h);
        while (NULL != (p = strchr(pp, '%'))) {
                bufncat(h, pp, (size_t)(p - pp));
                switch (*(p + 1)) {
@@ -718,8 +694,6 @@ bufcat_id(struct html *h, const char *src)
 
        /* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
 
-       if (0 == h->buflen)
-               bufcat(h, "#x");
        while ('\0' != *src)
                bufcat_fmt(h, "%.2x", *src++);
 }