html.c revision 95c635efb7c3b86efc493e0447eaec7aecca3f0f
/* $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>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mandoc.h"
#include "libmandoc.h"
#include "out.h"
#include "html.h"
#include "main.h"
struct htmldata {
const char *name;
int flags;
#define HTML_CLRLINE (1 << 0)
};
{"h1", 0}, /* TAG_H1 */
{"h2", 0}, /* TAG_H2 */
{"span", 0}, /* TAG_SPAN */
{"a", 0}, /* TAG_A */
{"b", 0 }, /* TAG_B */
{"i", 0 }, /* TAG_I */
{"code", 0 }, /* TAG_CODE */
{"small", 0 }, /* TAG_SMALL */
};
"http-equiv", /* ATTR_HTTPEQUIV */
"content", /* ATTR_CONTENT */
"name", /* ATTR_NAME */
"rel", /* ATTR_REL */
"href", /* ATTR_HREF */
"type", /* ATTR_TYPE */
"media", /* ATTR_MEDIA */
"class", /* ATTR_CLASS */
"style", /* ATTR_STYLE */
"width", /* ATTR_WIDTH */
"id", /* ATTR_ID */
"summary", /* ATTR_SUMMARY */
"align", /* ATTR_ALIGN */
"colspan", /* ATTR_COLSPAN */
};
static const char *const roffscales[SCALE_MAX] = {
"cm", /* SCALE_CM */
"in", /* SCALE_IN */
"pc", /* SCALE_PC */
"pt", /* SCALE_PT */
"em", /* SCALE_EM */
"em", /* SCALE_MM */
"ex", /* SCALE_EN */
"ex", /* SCALE_BU */
"em", /* SCALE_VS */
"ex", /* SCALE_FS */
};
static int print_encode(struct html *, const char *, int);
static void print_attr(struct html *, const char *, const char *);
static void *
{
struct html *h;
const char *toks[5];
char *v;
toks[0] = "style";
h->symtab = mchars_alloc();
case (0):
h->style = v;
break;
case (1):
h->base_man = v;
break;
case (2):
h->base_includes = v;
break;
case (3):
h->oflags |= HTML_FRAGMENT;
break;
default:
break;
}
return(h);
}
void *
html_alloc(char *outopts)
{
}
void *
xhtml_alloc(char *outopts)
{
}
void
html_free(void *p)
{
struct html *h;
h = (struct html *)p;
}
if (h->symtab)
mchars_free(h->symtab);
free(h);
}
void
print_gen_head(struct html *h)
{
if (h->style) {
}
}
static void
{
switch (deco) {
case (ESCAPE_FONTPREV):
break;
case (ESCAPE_FONTITALIC):
break;
case (ESCAPE_FONTBOLD):
break;
case (ESCAPE_FONT):
/* FALLTHROUGH */
case (ESCAPE_FONTROMAN):
break;
default:
abort();
/* NOTREACHED */
}
if (h->metaf) {
print_tagq(h, h->metaf);
}
if (HTMLFONT_NONE != font)
}
int
html_strlen(const char *cp)
{
const char *seq, *p;
/*
* Account for escaped sequences within string length
* calculations. This follows the logic in term_strlen() as we
* must calculate the width of produced strings.
* Assume that characters are always width of "1". This is
* hacky, but it gets the job done for approximation of widths.
*/
sz = 0;
++cp;
case (ESCAPE_ERROR):
return(sz);
case (ESCAPE_UNICODE):
/* FALLTHROUGH */
case (ESCAPE_NUMBERED):
/* FALLTHROUGH */
case (ESCAPE_SPECIAL):
sz++;
break;
default:
break;
}
}
}
static int
{
const char *seq;
enum mandoc_esc esc;
nospace = 0;
while ('\0' != *p) {
p += (int)sz;
if ('\0' == *p)
break;
switch (*p++) {
case ('<'):
printf("<");
continue;
case ('>'):
printf(">");
continue;
case ('&'):
printf("&");
continue;
case (ASCII_HYPH):
putchar('-');
continue;
default:
break;
}
if (ESCAPE_ERROR == esc)
break;
switch (esc) {
case (ESCAPE_UNICODE):
/* Skip passed "u" header. */
if ('\0' != c)
printf("&#x%x;", c);
break;
case (ESCAPE_NUMBERED):
if ('\0' != c)
putchar(c);
break;
case (ESCAPE_SPECIAL):
if (c > 0)
printf("&#%d;", c);
break;
case (ESCAPE_FONT):
/* FALLTHROUGH */
case (ESCAPE_FONTPREV):
/* FALLTHROUGH */
case (ESCAPE_FONTBOLD):
/* FALLTHROUGH */
case (ESCAPE_FONTITALIC):
/* FALLTHROUGH */
case (ESCAPE_FONTROMAN):
if (norecurse)
break;
print_metaf(h, esc);
break;
case (ESCAPE_NOSPACE):
if ('\0' == *p)
nospace = 1;
break;
default:
break;
}
}
return(nospace);
}
static void
{
putchar('\"');
}
struct tag *
{
int i;
struct tag *t;
/* Push this tags onto the stack of open scopes. */
t = mandoc_malloc(sizeof(struct tag));
} else
t = NULL;
if ( ! (HTML_NOSPACE & h->flags))
/* Manage keeps! */
if (HTML_PREKEEP & h->flags)
putchar(' ');
} else
printf(" ");
}
if ( ! (h->flags & HTML_NONOSPACE))
h->flags &= ~HTML_NOSPACE;
else
h->flags |= HTML_NOSPACE;
/* Print out the tag name and attributes. */
for (i = 0; i < sz; i++)
/* Add non-overridable attributes. */
}
/* Accommodate for XML "well-formed" singleton escaping. */
switch (h->type) {
case (HTML_XHTML_1_0_STRICT):
putchar('/');
break;
default:
break;
}
putchar('>');
h->flags |= HTML_NOSPACE;
putchar('\n');
return(t);
}
static void
{
h->flags |= HTML_NOSPACE;
putchar('\n');
}
}
void
print_gen_decls(struct html *h)
{
const char *doctype;
const char *dtd;
const char *name;
switch (h->type) {
case (HTML_HTML_4_01_STRICT):
name = "HTML";
doctype = "-//W3C//DTD HTML 4.01//EN";
break;
default:
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
name = "html";
doctype = "-//W3C//DTD XHTML 1.0 Strict//EN";
break;
}
printf("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n",
}
void
{
if ( ! (HTML_NOSPACE & h->flags)) {
/* Manage keeps! */
if (HTML_PREKEEP & h->flags)
putchar(' ');
} else
printf(" ");
}
if (HTMLFONT_NONE != h->metac)
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);
}
h->flags &= ~HTML_IGNDELIM;
}
void
{
/*
* Remember to close out and nullify the current
* meta-font and table, if applicable.
*/
return;
}
}
void
{
return;
/*
* Remember to close out and nullify the current
* meta-font and table, if applicable.
*/
}
}
void
{
h->buf[0] = '\0';
h->buflen = 0;
}
void
{
bufcat(h, ":");
bufcat(h, ";");
}
void
{
}
void
{
}
static void
{
}
void
{
const char *p, *pp;
pp = h->base_includes;
bufinit(h);
switch (*(p + 1)) {
case('I'):
break;
default:
bufncat(h, p, 2);
break;
}
pp = p + 2;
}
if (pp)
}
void
buffmt_man(struct html *h,
{
const char *p, *pp;
bufinit(h);
switch (*(p + 1)) {
case('S'):
break;
case('N'):
bufcat_fmt(h, name);
break;
default:
bufncat(h, p, 2);
break;
}
pp = p + 2;
}
if (pp)
}
void
{
double v;
v = 1.0;
}
void
{
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
while ('\0' != *src)
}