[BACK]Return to html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/html.c between version 1.59 and 1.68

version 1.59, 2009/10/07 14:39:00 version 1.68, 2009/10/28 05:08:17
Line 15 
Line 15 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/queue.h>  
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
 #include <err.h>  #include <err.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdarg.h>  #include <stdarg.h>
   #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
Line 28 
Line 29 
 #include "out.h"  #include "out.h"
 #include "chars.h"  #include "chars.h"
 #include "html.h"  #include "html.h"
   #include "main.h"
   
   #define UNCONST(a)      ((void *)(uintptr_t)(const void *)(a))
   
 #define DOCTYPE         "-//W3C//DTD HTML 4.01//EN"  #define DOCTYPE         "-//W3C//DTD HTML 4.01//EN"
 #define DTD             "http://www.w3.org/TR/html4/strict.dtd"  #define DTD             "http://www.w3.org/TR/html4/strict.dtd"
   
 struct  htmldata {  struct  htmldata {
         char             *name;          const char       *name;
         int               flags;          int               flags;
 #define HTML_CLRLINE     (1 << 0)  #define HTML_CLRLINE     (1 << 0)
 #define HTML_NOSTACK     (1 << 1)  #define HTML_NOSTACK     (1 << 1)
Line 77  static const char  *const htmlattrs[ATTR_MAX] = {
Line 81  static const char  *const htmlattrs[ATTR_MAX] = {
         "valign",          "valign",
         "target",          "target",
         "id",          "id",
           "summary",
 };  };
   
 #ifdef __linux__  #ifdef __linux__
Line 87  void *
Line 92  void *
 html_alloc(char *outopts)  html_alloc(char *outopts)
 {  {
         struct html     *h;          struct html     *h;
         char            *toks[4], *v;          const char      *toks[4];
           char            *v;
   
         toks[0] = "style";          toks[0] = "style";
         toks[1] = "man";          toks[1] = "man";
Line 97  html_alloc(char *outopts)
Line 103  html_alloc(char *outopts)
         if (NULL == (h = calloc(1, sizeof(struct html))))          if (NULL == (h = calloc(1, sizeof(struct html))))
                 return(NULL);                  return(NULL);
   
         SLIST_INIT(&h->tags);          h->tags.head = NULL;
         SLIST_INIT(&h->ords);          h->ords.head = NULL;
   
         if (NULL == (h->symtab = chars_init(CHARS_HTML))) {          if (NULL == (h->symtab = chars_init(CHARS_HTML))) {
                 free(h);                  free(h);
Line 106  html_alloc(char *outopts)
Line 112  html_alloc(char *outopts)
         }          }
   
         while (outopts && *outopts)          while (outopts && *outopts)
                 switch (getsubopt(&outopts, toks, &v)) {                  switch (getsubopt(&outopts, UNCONST(toks), &v)) {
                 case (0):                  case (0):
                         h->style = v;                          h->style = v;
                         break;                          break;
Line 133  html_free(void *p)
Line 139  html_free(void *p)
   
         h = (struct html *)p;          h = (struct html *)p;
   
         while ( ! SLIST_EMPTY(&h->ords)) {          while ((ord = h->ords.head) != NULL) {
                 ord = SLIST_FIRST(&h->ords);                  h->ords.head = ord->next;
                 SLIST_REMOVE_HEAD(&h->ords, entry);  
                 free(ord);                  free(ord);
         }          }
   
         while ( ! SLIST_EMPTY(&h->tags)) {          while ((tag = h->tags.head) != NULL) {
                 tag = SLIST_FIRST(&h->tags);                  h->tags.head = tag->next;
                 SLIST_REMOVE_HEAD(&h->tags, entry);  
                 free(tag);                  free(tag);
         }          }
   
Line 353  print_otag(struct html *h, enum htmltag tag, 
Line 357  print_otag(struct html *h, enum htmltag tag, 
                 if (NULL == (t = malloc(sizeof(struct tag))))                  if (NULL == (t = malloc(sizeof(struct tag))))
                         err(EXIT_FAILURE, "malloc");                          err(EXIT_FAILURE, "malloc");
                 t->tag = tag;                  t->tag = tag;
                 SLIST_INSERT_HEAD(&h->tags, t, entry);                  t->next = h->tags.head;
                   h->tags.head = t;
         } else          } else
                 t = NULL;                  t = NULL;
   
Line 463  print_tagq(struct html *h, const struct tag *until)
Line 468  print_tagq(struct html *h, const struct tag *until)
 {  {
         struct tag      *tag;          struct tag      *tag;
   
         while ( ! SLIST_EMPTY(&h->tags)) {          while ((tag = h->tags.head) != NULL) {
                 tag = SLIST_FIRST(&h->tags);  
                 print_ctag(h, tag->tag);                  print_ctag(h, tag->tag);
                 SLIST_REMOVE_HEAD(&h->tags, entry);                  h->tags.head = tag->next;
                 free(tag);                  free(tag);
                 if (until && tag == until)                  if (until && tag == until)
                         return;                          return;
Line 479  print_stagq(struct html *h, const struct tag *suntil)
Line 483  print_stagq(struct html *h, const struct tag *suntil)
 {  {
         struct tag      *tag;          struct tag      *tag;
   
         while ( ! SLIST_EMPTY(&h->tags)) {          while ((tag = h->tags.head) != NULL) {
                 tag = SLIST_FIRST(&h->tags);  
                 if (suntil && tag == suntil)                  if (suntil && tag == suntil)
                         return;                          return;
                 print_ctag(h, tag->tag);                  print_ctag(h, tag->tag);
                 SLIST_REMOVE_HEAD(&h->tags, entry);                  h->tags.head = tag->next;
                 free(tag);                  free(tag);
         }          }
 }  }
Line 549  buffmt_includes(struct html *h, const char *name)
Line 552  buffmt_includes(struct html *h, const char *name)
         const char      *p, *pp;          const char      *p, *pp;
   
         pp = h->base_includes;          pp = h->base_includes;
         while ((p = strchr(pp, '%'))) {  
           while (NULL != (p = strchr(pp, '%'))) {
                 bufncat(h, pp, (size_t)(p - pp));                  bufncat(h, pp, (size_t)(p - pp));
                 switch (*(p + 1)) {                  switch (*(p + 1)) {
                 case('I'):                  case('I'):
Line 573  buffmt_man(struct html *h, 
Line 577  buffmt_man(struct html *h, 
         const char      *p, *pp;          const char      *p, *pp;
   
         pp = h->base_man;          pp = h->base_man;
         while ((p = strchr(pp, '%'))) {  
           /* LINTED */
           while (NULL != (p = strchr(pp, '%'))) {
                 bufncat(h, pp, (size_t)(p - pp));                  bufncat(h, pp, (size_t)(p - pp));
                 switch (*(p + 1)) {                  switch (*(p + 1)) {
                 case('S'):                  case('S'):
Line 596  buffmt_man(struct html *h, 
Line 602  buffmt_man(struct html *h, 
 void  void
 bufcat_su(struct html *h, const char *p, const struct roffsu *su)  bufcat_su(struct html *h, const char *p, const struct roffsu *su)
 {  {
         int              v;          double           v;
         char            *u;          const char      *u;
   
         v = su->scale;          v = su->scale;
   
Line 636  bufcat_su(struct html *h, const char *p, const struct 
Line 642  bufcat_su(struct html *h, const char *p, const struct 
                 break;                  break;
         }          }
   
         buffmt(h, "%s: %d%s;", p, v, u);          if (su->pt)
                   buffmt(h, "%s: %f%s;", p, v, u);
           else
                   /* LINTED */
                   buffmt(h, "%s: %d%s;", p, (int)v, u);
   }
   
   
   void
   html_idcpy(char *dst, const char *src, int sz)
   {
   
           assert(sz);
           dst[0] = '\0';
           html_idcat(dst, src, sz);
   }
   
   
   void
   html_idcat(char *dst, const char *src, int sz)
   {
           int              i;
   
           /* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
   
           for (i = 0; *dst != '\0' && i < sz - 1; dst++, i++)
                   /* Jump to end. */ ;
   
           for ( ; *src != '\0' && i < sz - 1; src++, i++) {
                   if (isalnum((u_char)*src)) {
                           *dst++ = *src;
                           continue;
                   }
   
                   switch (*src) {
                   case (';'):
                           *dst++ = ';';
                           break;
                   case ('-'):
                           *dst++ = '-';
                           break;
                   case (':'):
                           *dst++ = ':';
                           break;
                   case ('_'):
                           /* FALLTHROUGH */
                   default:
                           *dst++ = '_';
                           break;
                   }
           }
   
           *dst = '\0';
 }  }

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.68

CVSweb