# This patch is against htmldoc 1.8.27, and it hacks in support for # correctly indenting the
sections in the SWIG manual. # This patch should only be used until the 1.9 branch of htmldoc # stabilizes, since the 1.9 branch includes true CSS1 support. # # This patch only affects the PDF generation, an unpatched htmldoc # creates the one-page html documentation just fine. # diff -Naur htmldoc-1.8.27/htmldoc/htmldoc.cxx htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx --- htmldoc-1.8.27/htmldoc/htmldoc.cxx 2006-03-30 14:01:20.000000000 +0100 +++ htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx 2013-05-11 10:11:47.428435647 +0100 @@ -65,6 +65,8 @@ const char *__XOS2RedirRoot(const char *); } #endif + +extern void parse_style(char *); /* @@ -1115,6 +1117,7 @@ else if (compare_strings(argv[i], "--version", 6) == 0) { puts(SVERSION); + puts("Patched with margin-left.patch"); return (0); } else if (compare_strings(argv[i], "--webpage", 3) == 0) @@ -2403,6 +2406,10 @@ } else if (strcmp(temp, "--cookies") == 0) file_cookies(temp2); + else if (strcmp(temp, "--stylesheet") == 0) + { + parse_style(temp2); + } } } diff -Naur htmldoc-1.8.27/htmldoc/Makefile htmldoc-1.8.27-margin-left/htmldoc/Makefile --- htmldoc-1.8.27/htmldoc/Makefile 2005-10-28 21:32:59.000000000 +0100 +++ htmldoc-1.8.27-margin-left/htmldoc/Makefile 2013-05-11 09:39:04.392367869 +0100 @@ -36,7 +36,7 @@ OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o \ http.o http-addr.o http-addrlist.o http-support.o image.o \ iso8859.o license.o md5.o progress.o ps-pdf.o rc4.o \ - snprintf.o string.o toc.o util.o + snprintf.o string.o toc.o util.o style.o # diff -Naur htmldoc-1.8.27/htmldoc/ps-pdf.cxx htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx --- htmldoc-1.8.27/htmldoc/ps-pdf.cxx 2006-08-01 17:58:50.000000000 +0100 +++ htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx 2013-05-11 09:37:40.096364957 +0100 @@ -160,6 +160,7 @@ # undef page_t #endif // __hpux +extern int lookup_div_class(uchar *); /* * Output options... @@ -4230,9 +4231,24 @@ para->child = para->last_child = NULL; } - parse_doc(t->child, left, right, bottom, top, x, y, page, NULL, + { + int num_indent = 0; + uchar *cname; + + if (cname = htmlGetVariable(t, (uchar *)"class")) { + num_indent = lookup_div_class(cname); + *left += 5.0f * num_indent; + *x = *left; + } + + parse_doc(t->child, left, right, bottom, top, x, y, page, NULL, needspace); + if (num_indent > 0) { + *left -= 5.0f * num_indent; + } + } + if (para->child != NULL) { parse_paragraph(para, *left, *right, *bottom, *top, x, y, page, *needspace); diff -Naur htmldoc-1.8.27/htmldoc/style.cxx htmldoc-1.8.27-margin-left/htmldoc/style.cxx --- htmldoc-1.8.27/htmldoc/style.cxx 1970-01-01 01:00:00.000000000 +0100 +++ htmldoc-1.8.27-margin-left/htmldoc/style.cxx 2013-05-11 09:37:40.096364957 +0100 @@ -0,0 +1,185 @@ +/* Extreamly simple parsing routines for CSS style sheets. + * We only parse div.class { } sections, and only look + * for margin-left: em; + * + * Copyright (C) 2005 John Lenz + * + * Released under GNU GPL v2 or above. + */ + +#include +#include +#include +#include +#include + +#include "types.h" + +#define BUFF_SIZE 512 + +struct div_entry { + uchar class_name[BUFF_SIZE]; + int indent; + struct div_entry *next; +}; + +static struct div_entry *head = 0; + +/* These are the parsing states */ +#define IGNORE_TILL_SEMI 0 +#define IGNORE_TILL_CLOSE_BRACE 1 +#define READING_DIV 2 +#define READING_CLASS 3 +#define READING_ATTRIBUTE 4 +#define READING_NUM 5 +#define CHECKING_ONLY_DIV 6 + +static int at_eof = 0; + +static int strucmp(uchar *a, uchar *b) { + int i; + for (i = 0; a[i] && b[i]; i++) { + if (a[i] < b[i]) return -1; + if (a[i] > b[i]) return 1; + } + /* This isn't right, but who cares...*/ + if (a[i] || b[i]) return 1; + return 0; +} + +static int read_word(FILE *f, const char *word) { + char c; + for (int idx = 0; word[idx]; idx++) { + c = getc(f); + if (c == EOF) { + at_eof = 1; + return 0; + } + if (c != word[idx]) + return 0; + } + return 1; +} + +int lookup_div_class(uchar *name) { + struct div_entry *node = head; + + while (node) { + if (strucmp(node->class_name, name) == 0) + return node->indent; + node = node->next; + } + + return 0; +} + +void parse_style(char *fname) { + FILE *f; + char c; + int state; + struct div_entry *cur = 0; + int class_idx = 0; + char num[BUFF_SIZE]; + int num_idx = 0; + + if (!fname) return; + + f = fopen(fname, "r"); + if (!f) { + fprintf(stderr, "Unable to parse style\n"); + return; + } + + state = READING_DIV; + while (!at_eof && (c = getc(f)) != EOF) { + switch (state) { + + case IGNORE_TILL_SEMI: + if (c == ';') + state = READING_ATTRIBUTE; + break; + + case IGNORE_TILL_CLOSE_BRACE: + if (c == '}') + state = READING_DIV; + break; + + case READING_DIV: + if (c != ' ' && c != '\t' && c != '\n') { + if (c == 'd' && read_word(f, "iv.")) { + state = READING_CLASS; + cur = (struct div_entry *) malloc(sizeof(struct div_entry)); + memset(cur, 0, sizeof(struct div_entry)); + class_idx = 0; + } else + state = IGNORE_TILL_CLOSE_BRACE; + } + break; + + case READING_CLASS: + if (isalpha(c)) { + if (class_idx >= BUFF_SIZE-1) { + fprintf(stderr, "class size %s too long\n", cur->class_name); + free(cur); + state = IGNORE_TILL_CLOSE_BRACE; + } else { + cur->class_name[class_idx++] = c; + } + } else { + if (c == '{') { + cur->next = head; + head = cur; + state = READING_ATTRIBUTE; + } else + state = CHECKING_ONLY_DIV; + } + break; + + case READING_ATTRIBUTE: + if (c != ' ' && c != '\t' && c != '\n') { + if (c == '}') + state = READING_DIV; + else { + if (c == 'm' && read_word(f, "argin-left:")) { + num_idx = 0; + memset(num, 0, sizeof(num)); + state = READING_NUM; + } else { + state = IGNORE_TILL_SEMI; + } + } + } + break; + + case READING_NUM: + if (isdigit(c)) { + if (num_idx >= BUFF_SIZE - 1) { + fprintf(stderr, "Number too long\n"); + state = IGNORE_TILL_SEMI; + } else { + num[num_idx++] = c; + } + } else if (c != ' ' && c != '\t') { + if (num_idx > 0 && c == 'e' && read_word(f, "m")) + cur->indent = atoi(num); + state = IGNORE_TILL_SEMI; + } + break; + + case CHECKING_ONLY_DIV: + if (c != ' ' && c != '\t' && c != '\n') { + if (c == '{') { + cur->next = head; + head = cur; + state = READING_ATTRIBUTE; + } else { + free(cur); + state = IGNORE_TILL_CLOSE_BRACE; + } + } + break; + } + } + + fclose(f); +}