version 1.64, 2009/10/13 10:57:25 |
version 1.71, 2009/10/30 04:57:17 |
|
|
* 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> |
Line 81 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 102 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 138 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 358 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 391 print_ctag(struct html *h, enum htmltag tag) |
|
Line 391 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; |
if (HTML_CLRLINE & htmltags[tag].flags) |
|
h->flags |= HTML_NEWLINE; |
h->flags |= HTML_NEWLINE; |
else |
printf("\n"); |
|
} else |
h->flags &= ~HTML_NEWLINE; |
h->flags &= ~HTML_NEWLINE; |
} |
} |
|
|
Line 468 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 484 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 649 bufcat_su(struct html *h, const char *p, const struct |
|
Line 647 bufcat_su(struct html *h, const char *p, const struct |
|
else |
else |
/* LINTED */ |
/* LINTED */ |
buffmt(h, "%s: %d%s;", p, (int)v, u); |
buffmt(h, "%s: %d%s;", p, (int)v, u); |
|
} |
|
|
|
|
|
void |
|
html_idcat(char *dst, const char *src, int sz) |
|
{ |
|
int ssz; |
|
|
|
assert(sz); |
|
|
|
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */ |
|
|
|
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, sz, "%.2x", *src); |
|
sz -= ssz; |
|
dst += ssz; |
|
} |
} |
} |