=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.66 retrieving revision 1.73 diff -u -p -r1.66 -r1.73 --- mandoc/html.c 2009/10/26 08:18:15 1.66 +++ mandoc/html.c 2009/10/30 18:50:11 1.73 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.66 2009/10/26 08:18:15 kristaps Exp $ */ +/* $Id: html.c,v 1.73 2009/10/30 18:50:11 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,7 @@ static const char *const htmlattrs[ATTR_MAX] = { "valign", "target", "id", + "summary", }; #ifdef __linux__ @@ -98,17 +100,16 @@ html_alloc(char *outopts) toks[2] = "includes"; toks[3] = NULL; - if (NULL == (h = calloc(1, sizeof(struct html)))) - return(NULL); + h = calloc(1, sizeof(struct html)); + if (NULL == h) { + fprintf(stderr, "memory exhausted\n"); + exit(EXIT_FAILURE); + } h->tags.head = NULL; h->ords.head = NULL; + h->symtab = chars_init(CHARS_HTML); - if (NULL == (h->symtab = chars_init(CHARS_HTML))) { - free(h); - return(NULL); - } - while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): @@ -352,8 +353,11 @@ print_otag(struct html *h, enum htmltag tag, struct tag *t; if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { - if (NULL == (t = malloc(sizeof(struct tag)))) - err(EXIT_FAILURE, "malloc"); + t = malloc(sizeof(struct tag)); + if (NULL == t) { + fprintf(stderr, "memory exhausted\n"); + exit(EXIT_FAILURE); + } t->tag = tag; t->next = h->tags.head; h->tags.head = t; @@ -389,11 +393,11 @@ print_ctag(struct html *h, enum htmltag tag) { printf("", htmltags[tag].name); - if (HTML_CLRLINE & htmltags[tag].flags) + if (HTML_CLRLINE & htmltags[tag].flags) { h->flags |= HTML_NOSPACE; - if (HTML_CLRLINE & htmltags[tag].flags) h->flags |= HTML_NEWLINE; - else + printf("\n"); + } else h->flags &= ~HTML_NEWLINE; } @@ -647,3 +651,30 @@ bufcat_su(struct html *h, const char *p, const struct buffmt(h, "%s: %d%s;", p, (int)v, u); } + +void +html_idcat(char *dst, const char *src, int sz) +{ + int ssz; + + assert(sz); + + /* Cf. . */ + + for ( ; *dst != '\0' && sz; dst++, sz--) + /* Jump to end. */ ; + + assert(sz > 2); + + /* We can't start with a number (bah). */ + + *dst++ = 'x'; + *dst = '\0'; + sz--; + + for ( ; *src != '\0' && sz > 1; src++) { + ssz = snprintf(dst, (size_t)sz, "%.2x", *src); + sz -= ssz; + dst += ssz; + } +}