version 1.68, 2009/10/28 05:08:17 |
version 1.74, 2009/10/30 18:53:08 |
|
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <stdint.h> |
#include <stdint.h> |
Line 100 html_alloc(char *outopts) |
|
Line 99 html_alloc(char *outopts) |
|
toks[2] = "includes"; |
toks[2] = "includes"; |
toks[3] = NULL; |
toks[3] = NULL; |
|
|
if (NULL == (h = calloc(1, sizeof(struct html)))) |
h = calloc(1, sizeof(struct html)); |
return(NULL); |
if (NULL == h) { |
|
fprintf(stderr, "memory exhausted\n"); |
|
exit(EXIT_FAILURE); |
|
} |
|
|
h->tags.head = NULL; |
h->tags.head = NULL; |
h->ords.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) |
while (outopts && *outopts) |
switch (getsubopt(&outopts, UNCONST(toks), &v)) { |
switch (getsubopt(&outopts, UNCONST(toks), &v)) { |
case (0): |
case (0): |
Line 354 print_otag(struct html *h, enum htmltag tag, |
|
Line 352 print_otag(struct html *h, enum htmltag tag, |
|
struct tag *t; |
struct tag *t; |
|
|
if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { |
if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { |
if (NULL == (t = malloc(sizeof(struct tag)))) |
t = malloc(sizeof(struct tag)); |
err(EXIT_FAILURE, "malloc"); |
if (NULL == t) { |
|
fprintf(stderr, "memory exhausted\n"); |
|
exit(EXIT_FAILURE); |
|
} |
t->tag = tag; |
t->tag = tag; |
t->next = h->tags.head; |
t->next = h->tags.head; |
h->tags.head = t; |
h->tags.head = t; |
Line 391 print_ctag(struct html *h, enum htmltag tag) |
|
Line 392 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 651 bufcat_su(struct html *h, const char *p, const struct |
|
Line 652 bufcat_su(struct html *h, const char *p, const struct |
|
|
|
|
|
void |
void |
html_idcpy(char *dst, const char *src, int sz) |
html_idcat(char *dst, const char *src, int sz) |
{ |
{ |
|
int ssz; |
|
|
assert(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>. */ |
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */ |
|
|
for (i = 0; *dst != '\0' && i < sz - 1; dst++, i++) |
for ( ; *dst != '\0' && sz; dst++, sz--) |
/* Jump to end. */ ; |
/* Jump to end. */ ; |
|
|
for ( ; *src != '\0' && i < sz - 1; src++, i++) { |
assert(sz > 2); |
if (isalnum((u_char)*src)) { |
|
*dst++ = *src; |
|
continue; |
|
} |
|
|
|
switch (*src) { |
/* We can't start with a number (bah). */ |
case (';'): |
|
*dst++ = ';'; |
|
break; |
|
case ('-'): |
|
*dst++ = '-'; |
|
break; |
|
case (':'): |
|
*dst++ = ':'; |
|
break; |
|
case ('_'): |
|
/* FALLTHROUGH */ |
|
default: |
|
*dst++ = '_'; |
|
break; |
|
} |
|
} |
|
|
|
|
*dst++ = 'x'; |
*dst = '\0'; |
*dst = '\0'; |
|
sz--; |
|
|
|
for ( ; *src != '\0' && sz > 1; src++) { |
|
ssz = snprintf(dst, (size_t)sz, "%.2x", *src); |
|
sz -= ssz; |
|
dst += ssz; |
|
} |
} |
} |