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

Diff for /mandoc/html.c between version 1.155 and 1.156

version 1.155, 2014/03/23 11:25:26 version 1.156, 2014/04/20 16:46:04
Line 115  static void  print_metaf(struct html *, enum mandoc_es
Line 115  static void  print_metaf(struct html *, enum mandoc_es
 static  void     print_attr(struct html *, const char *, const char *);  static  void     print_attr(struct html *, const char *, const char *);
 static  void     *ml_alloc(char *, enum htmltype);  static  void     *ml_alloc(char *, enum htmltype);
   
   
 static void *  static void *
 ml_alloc(char *outopts, enum htmltype type)  ml_alloc(char *outopts, enum htmltype type)
 {  {
Line 136  ml_alloc(char *outopts, enum htmltype type)
Line 137  ml_alloc(char *outopts, enum htmltype type)
   
         while (outopts && *outopts)          while (outopts && *outopts)
                 switch (getsubopt(&outopts, UNCONST(toks), &v)) {                  switch (getsubopt(&outopts, UNCONST(toks), &v)) {
                 case (0):                  case 0:
                         h->style = v;                          h->style = v;
                         break;                          break;
                 case (1):                  case 1:
                         h->base_man = v;                          h->base_man = v;
                         break;                          break;
                 case (2):                  case 2:
                         h->base_includes = v;                          h->base_includes = v;
                         break;                          break;
                 case (3):                  case 3:
                         h->oflags |= HTML_FRAGMENT;                          h->oflags |= HTML_FRAGMENT;
                         break;                          break;
                 default:                  default:
Line 162  html_alloc(char *outopts)
Line 163  html_alloc(char *outopts)
         return(ml_alloc(outopts, HTML_HTML_4_01_STRICT));          return(ml_alloc(outopts, HTML_HTML_4_01_STRICT));
 }  }
   
   
 void *  void *
 xhtml_alloc(char *outopts)  xhtml_alloc(char *outopts)
 {  {
Line 170  xhtml_alloc(char *outopts)
Line 170  xhtml_alloc(char *outopts)
         return(ml_alloc(outopts, HTML_XHTML_1_0_STRICT));          return(ml_alloc(outopts, HTML_XHTML_1_0_STRICT));
 }  }
   
   
 void  void
 html_free(void *p)  html_free(void *p)
 {  {
Line 180  html_free(void *p)
Line 179  html_free(void *p)
         h = (struct html *)p;          h = (struct html *)p;
   
         while ((tag = h->tags.head) != NULL) {          while ((tag = h->tags.head) != NULL) {
                 h->tags.head = tag->next;                  h->tags.head = tag->next;
                 free(tag);                  free(tag);
         }          }
   
         if (h->symtab)          if (h->symtab)
                 mchars_free(h->symtab);                  mchars_free(h->symtab);
   
         free(h);          free(h);
 }  }
   
   
 void  void
 print_gen_head(struct html *h)  print_gen_head(struct html *h)
 {  {
Line 227  print_metaf(struct html *h, enum mandoc_esc deco)
Line 225  print_metaf(struct html *h, enum mandoc_esc deco)
         enum htmlfont    font;          enum htmlfont    font;
   
         switch (deco) {          switch (deco) {
         case (ESCAPE_FONTPREV):          case ESCAPE_FONTPREV:
                 font = h->metal;                  font = h->metal;
                 break;                  break;
         case (ESCAPE_FONTITALIC):          case ESCAPE_FONTITALIC:
                 font = HTMLFONT_ITALIC;                  font = HTMLFONT_ITALIC;
                 break;                  break;
         case (ESCAPE_FONTBOLD):          case ESCAPE_FONTBOLD:
                 font = HTMLFONT_BOLD;                  font = HTMLFONT_BOLD;
                 break;                  break;
         case (ESCAPE_FONTBI):          case ESCAPE_FONTBI:
                 font = HTMLFONT_BI;                  font = HTMLFONT_BI;
                 break;                  break;
         case (ESCAPE_FONT):          case ESCAPE_FONT:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (ESCAPE_FONTROMAN):          case ESCAPE_FONTROMAN:
                 font = HTMLFONT_NONE;                  font = HTMLFONT_NONE;
                 break;                  break;
         default:          default:
Line 258  print_metaf(struct html *h, enum mandoc_esc deco)
Line 256  print_metaf(struct html *h, enum mandoc_esc deco)
         h->metac = font;          h->metac = font;
   
         switch (font) {          switch (font) {
         case (HTMLFONT_ITALIC):          case HTMLFONT_ITALIC:
                 h->metaf = print_otag(h, TAG_I, 0, NULL);                  h->metaf = print_otag(h, TAG_I, 0, NULL);
                 break;                  break;
         case (HTMLFONT_BOLD):          case HTMLFONT_BOLD:
                 h->metaf = print_otag(h, TAG_B, 0, NULL);                  h->metaf = print_otag(h, TAG_B, 0, NULL);
                 break;                  break;
         case (HTMLFONT_BI):          case HTMLFONT_BI:
                 h->metaf = print_otag(h, TAG_B, 0, NULL);                  h->metaf = print_otag(h, TAG_B, 0, NULL);
                 print_otag(h, TAG_I, 0, NULL);                  print_otag(h, TAG_I, 0, NULL);
                 break;                  break;
Line 303  html_strlen(const char *cp)
Line 301  html_strlen(const char *cp)
                         break;                          break;
                 cp++;                  cp++;
                 switch (mandoc_escape(&cp, NULL, NULL)) {                  switch (mandoc_escape(&cp, NULL, NULL)) {
                 case (ESCAPE_ERROR):                  case ESCAPE_ERROR:
                         return(sz);                          return(sz);
                 case (ESCAPE_UNICODE):                  case ESCAPE_UNICODE:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_NUMBERED):                  case ESCAPE_NUMBERED:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_SPECIAL):                  case ESCAPE_SPECIAL:
                         if (skip)                          if (skip)
                                 skip = 0;                                  skip = 0;
                         else                          else
                                 sz++;                                  sz++;
                         break;                          break;
                 case (ESCAPE_SKIPCHAR):                  case ESCAPE_SKIPCHAR:
                         skip = 1;                          skip = 1;
                         break;                          break;
                 default:                  default:
Line 353  print_encode(struct html *h, const char *p, int norecu
Line 351  print_encode(struct html *h, const char *p, int norecu
                         break;                          break;
   
                 switch (*p++) {                  switch (*p++) {
                 case ('<'):                  case '<':
                         printf("&lt;");                          printf("&lt;");
                         continue;                          continue;
                 case ('>'):                  case '>':
                         printf("&gt;");                          printf("&gt;");
                         continue;                          continue;
                 case ('&'):                  case '&':
                         printf("&amp;");                          printf("&amp;");
                         continue;                          continue;
                 case (ASCII_NBRSP):                  case ASCII_NBRSP:
                         putchar('-');                          putchar('-');
                         continue;                          continue;
                 case (ASCII_HYPH):                  case ASCII_HYPH:
                         putchar('-');                          putchar('-');
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ASCII_BREAK):                  case ASCII_BREAK:
                         continue;                          continue;
                 default:                  default:
                         break;                          break;
Line 379  print_encode(struct html *h, const char *p, int norecu
Line 377  print_encode(struct html *h, const char *p, int norecu
                         break;                          break;
   
                 switch (esc) {                  switch (esc) {
                 case (ESCAPE_FONT):                  case ESCAPE_FONT:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_FONTPREV):                  case ESCAPE_FONTPREV:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_FONTBOLD):                  case ESCAPE_FONTBOLD:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_FONTITALIC):                  case ESCAPE_FONTITALIC:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_FONTBI):                  case ESCAPE_FONTBI:
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ESCAPE_FONTROMAN):                  case ESCAPE_FONTROMAN:
                         if (0 == norecurse)                          if (0 == norecurse)
                                 print_metaf(h, esc);                                  print_metaf(h, esc);
                         continue;                          continue;
                 case (ESCAPE_SKIPCHAR):                  case ESCAPE_SKIPCHAR:
                         h->flags |= HTML_SKIPCHAR;                          h->flags |= HTML_SKIPCHAR;
                         continue;                          continue;
                 default:                  default:
Line 406  print_encode(struct html *h, const char *p, int norecu
Line 404  print_encode(struct html *h, const char *p, int norecu
                 }                  }
   
                 switch (esc) {                  switch (esc) {
                 case (ESCAPE_UNICODE):                  case ESCAPE_UNICODE:
                         /* Skip passed "u" header. */                          /* Skip passed "u" header. */
                         c = mchars_num2uc(seq + 1, len - 1);                          c = mchars_num2uc(seq + 1, len - 1);
                         if ('\0' != c)                          if ('\0' != c)
                                 printf("&#x%x;", c);                                  printf("&#x%x;", c);
                         break;                          break;
                 case (ESCAPE_NUMBERED):                  case ESCAPE_NUMBERED:
                         c = mchars_num2char(seq, len);                          c = mchars_num2char(seq, len);
                         if ('\0' != c)                          if ('\0' != c)
                                 putchar(c);                                  putchar(c);
                         break;                          break;
                 case (ESCAPE_SPECIAL):                  case ESCAPE_SPECIAL:
                         c = mchars_spec2cp(h->symtab, seq, len);                          c = mchars_spec2cp(h->symtab, seq, len);
                         if (c > 0)                          if (c > 0)
                                 printf("&#%d;", c);                                  printf("&#%d;", c);
                         else if (-1 == c && 1 == len)                          else if (-1 == c && 1 == len)
                                 putchar((int)*seq);                                  putchar((int)*seq);
                         break;                          break;
                 case (ESCAPE_NOSPACE):                  case ESCAPE_NOSPACE:
                         if ('\0' == *p)                          if ('\0' == *p)
                                 nospace = 1;                                  nospace = 1;
                         break;                          break;
Line 436  print_encode(struct html *h, const char *p, int norecu
Line 434  print_encode(struct html *h, const char *p, int norecu
         return(nospace);          return(nospace);
 }  }
   
   
 static void  static void
 print_attr(struct html *h, const char *key, const char *val)  print_attr(struct html *h, const char *key, const char *val)
 {  {
Line 445  print_attr(struct html *h, const char *key, const char
Line 442  print_attr(struct html *h, const char *key, const char
         putchar('\"');          putchar('\"');
 }  }
   
   
 struct tag *  struct tag *
 print_otag(struct html *h, enum htmltag tag,  print_otag(struct html *h, enum htmltag tag,
                 int sz, const struct htmlpair *p)                  int sz, const struct htmlpair *p)
 {  {
         int              i;          int              i;
Line 497  print_otag(struct html *h, enum htmltag tag, 
Line 493  print_otag(struct html *h, enum htmltag tag, 
   
         if (HTML_AUTOCLOSE & htmltags[tag].flags)          if (HTML_AUTOCLOSE & htmltags[tag].flags)
                 switch (h->type) {                  switch (h->type) {
                 case (HTML_XHTML_1_0_STRICT):                  case HTML_XHTML_1_0_STRICT:
                         putchar('/');                          putchar('/');
                         break;                          break;
                 default:                  default:
Line 514  print_otag(struct html *h, enum htmltag tag, 
Line 510  print_otag(struct html *h, enum htmltag tag, 
         return(t);          return(t);
 }  }
   
   
 static void  static void
 print_ctag(struct html *h, enum htmltag tag)  print_ctag(struct html *h, enum htmltag tag)
 {  {
   
         printf("</%s>", htmltags[tag].name);          printf("</%s>", htmltags[tag].name);
         if (HTML_CLRLINE & htmltags[tag].flags) {          if (HTML_CLRLINE & htmltags[tag].flags) {
                 h->flags |= HTML_NOSPACE;                  h->flags |= HTML_NOSPACE;
                 putchar('\n');                  putchar('\n');
         }          }
 }  }
   
 void  void
Line 534  print_gen_decls(struct html *h)
Line 529  print_gen_decls(struct html *h)
         const char      *name;          const char      *name;
   
         switch (h->type) {          switch (h->type) {
         case (HTML_HTML_4_01_STRICT):          case HTML_HTML_4_01_STRICT:
                 name = "HTML";                  name = "HTML";
                 doctype = "-//W3C//DTD HTML 4.01//EN";                  doctype = "-//W3C//DTD HTML 4.01//EN";
                 dtd = "http://www.w3.org/TR/html4/strict.dtd";                  dtd = "http://www.w3.org/TR/html4/strict.dtd";
Line 547  print_gen_decls(struct html *h)
Line 542  print_gen_decls(struct html *h)
                 break;                  break;
         }          }
   
         printf("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n",          printf("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n",
                         name, doctype, dtd);              name, doctype, dtd);
 }  }
   
 void  void
Line 567  print_text(struct html *h, const char *word)
Line 562  print_text(struct html *h, const char *word)
   
         assert(NULL == h->metaf);          assert(NULL == h->metaf);
         switch (h->metac) {          switch (h->metac) {
         case (HTMLFONT_ITALIC):          case HTMLFONT_ITALIC:
                 h->metaf = print_otag(h, TAG_I, 0, NULL);                  h->metaf = print_otag(h, TAG_I, 0, NULL);
                 break;                  break;
         case (HTMLFONT_BOLD):          case HTMLFONT_BOLD:
                 h->metaf = print_otag(h, TAG_B, 0, NULL);                  h->metaf = print_otag(h, TAG_B, 0, NULL);
                 break;                  break;
         case (HTMLFONT_BI):          case HTMLFONT_BI:
                 h->metaf = print_otag(h, TAG_B, 0, NULL);                  h->metaf = print_otag(h, TAG_B, 0, NULL);
                 print_otag(h, TAG_I, 0, NULL);                  print_otag(h, TAG_I, 0, NULL);
                 break;                  break;
Line 596  print_text(struct html *h, const char *word)
Line 591  print_text(struct html *h, const char *word)
         h->flags &= ~HTML_IGNDELIM;          h->flags &= ~HTML_IGNDELIM;
 }  }
   
   
 void  void
 print_tagq(struct html *h, const struct tag *until)  print_tagq(struct html *h, const struct tag *until)
 {  {
         struct tag      *tag;          struct tag      *tag;
   
         while ((tag = h->tags.head) != NULL) {          while ((tag = h->tags.head) != NULL) {
                 /*                  /*
                  * Remember to close out and nullify the current                   * Remember to close out and nullify the current
                  * meta-font and table, if applicable.                   * meta-font and table, if applicable.
                  */                   */
Line 619  print_tagq(struct html *h, const struct tag *until)
Line 613  print_tagq(struct html *h, const struct tag *until)
         }          }
 }  }
   
   
 void  void
 print_stagq(struct html *h, const struct tag *suntil)  print_stagq(struct html *h, const struct tag *suntil)
 {  {
Line 628  print_stagq(struct html *h, const struct tag *suntil)
Line 621  print_stagq(struct html *h, const struct tag *suntil)
         while ((tag = h->tags.head) != NULL) {          while ((tag = h->tags.head) != NULL) {
                 if (suntil && tag == suntil)                  if (suntil && tag == suntil)
                         return;                          return;
                 /*                  /*
                  * Remember to close out and nullify the current                   * Remember to close out and nullify the current
                  * meta-font and table, if applicable.                   * meta-font and table, if applicable.
                  */                   */
Line 674  bufcat_fmt(struct html *h, const char *fmt, ...)
Line 667  bufcat_fmt(struct html *h, const char *fmt, ...)
         va_list          ap;          va_list          ap;
   
         va_start(ap, fmt);          va_start(ap, fmt);
         (void)vsnprintf(h->buf + (int)h->buflen,          (void)vsnprintf(h->buf + (int)h->buflen,
                         BUFSIZ - h->buflen - 1, fmt, ap);              BUFSIZ - h->buflen - 1, fmt, ap);
         va_end(ap);          va_end(ap);
         h->buflen = strlen(h->buf);          h->buflen = strlen(h->buf);
 }  }
Line 695  buffmt_includes(struct html *h, const char *name)
Line 688  buffmt_includes(struct html *h, const char *name)
         const char      *p, *pp;          const char      *p, *pp;
   
         pp = h->base_includes;          pp = h->base_includes;
   
         bufinit(h);          bufinit(h);
         while (NULL != (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':
                         bufcat(h, name);                          bufcat(h, name);
                         break;                          break;
                 default:                  default:
Line 714  buffmt_includes(struct html *h, const char *name)
Line 707  buffmt_includes(struct html *h, const char *name)
 }  }
   
 void  void
 buffmt_man(struct html *h,  buffmt_man(struct html *h, const char *name, const char *sec)
                 const char *name, const char *sec)  
 {  {
         const char      *p, *pp;          const char      *p, *pp;
   
         pp = h->base_man;          pp = h->base_man;
   
         bufinit(h);          bufinit(h);
         while (NULL != (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('S'):                  case 'S':
                         bufcat(h, sec ? sec : "1");                          bufcat(h, sec ? sec : "1");
                         break;                          break;
                 case('N'):                  case 'N':
                         bufcat_fmt(h, "%s", name);                          bufcat_fmt(h, "%s", name);
                         break;                          break;
                 default:                  default:

Legend:
Removed from v.1.155  
changed lines
  Added in v.1.156

CVSweb