/branches/closed/branch-php-utl/SWIG/Doc/Manual/margin-left.patch

# · Patch · 269 lines · 258 code · 11 blank · 0 comment · 0 complexity · aa4f87768d3ef8861bf8773baee339c1 MD5 · raw file

  1. #
  2. # Patch managed by http://www.holgerschurig.de/patcher.html
  3. #
  4. # This patch is against htmldoc 1.8.24, and it hacks in support for
  5. # correctly indenting the <div class=""> sections in the SWIG manual.
  6. # This patch should only be used until the 1.9 branch of htmldoc
  7. # stabalizes, since the 1.9 branch includes true CSS1 support.
  8. #
  9. # This patch only affects the PDF generation, an unpatched htmldoc
  10. # creates the one-page html documentation just fine.
  11. #
  12. --- htmldoc-1.8.24/htmldoc/ps-pdf.cxx~margin-left
  13. +++ htmldoc-1.8.24/htmldoc/ps-pdf.cxx
  14. @@ -158,6 +158,7 @@
  15. # undef page_t
  16. #endif // __hpux
  17. +extern int lookup_div_class(uchar *);
  18. /*
  19. * Constants...
  20. @@ -4188,9 +4189,24 @@
  21. para->child = para->last_child = NULL;
  22. }
  23. - parse_doc(t->child, left, right, bottom, top, x, y, page, NULL,
  24. + {
  25. + int num_indent = 0;
  26. + uchar *cname;
  27. +
  28. + if (cname = htmlGetVariable(t, (uchar *)"class")) {
  29. + num_indent = lookup_div_class(cname);
  30. + *left += 5.0f * num_indent;
  31. + *x = *left;
  32. + }
  33. +
  34. + parse_doc(t->child, left, right, bottom, top, x, y, page, NULL,
  35. needspace);
  36. + if (num_indent > 0) {
  37. + *left -= 5.0f * num_indent;
  38. + }
  39. + }
  40. +
  41. if (para->child != NULL)
  42. {
  43. parse_paragraph(para, *left, *right, *bottom, *top, x, y, page, *needspace);
  44. --- htmldoc-1.8.24/htmldoc/htmldoc.cxx~margin-left
  45. +++ htmldoc-1.8.24/htmldoc/htmldoc.cxx
  46. @@ -62,6 +62,8 @@
  47. const char *__XOS2RedirRoot(const char *);
  48. }
  49. #endif
  50. +
  51. +extern void parse_style(char *);
  52. /*
  53. @@ -2140,6 +2142,10 @@
  54. }
  55. else if (strcmp(temp, "--cookies") == 0)
  56. file_cookies(temp2);
  57. + else if (strcmp(temp, "--stylesheet") == 0)
  58. + {
  59. + parse_style(temp2);
  60. + }
  61. }
  62. }
  63. --- /dev/null
  64. +++ htmldoc-1.8.24/htmldoc/style.cxx
  65. @@ -0,0 +1,185 @@
  66. +/* Extreamly simple parsing routines for CSS style sheets.
  67. + * We only parse div.class { } sections, and only look
  68. + * for margin-left: <num>em;
  69. + *
  70. + * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
  71. + *
  72. + * Released under GNU GPL v2 or above.
  73. + */
  74. +
  75. +#include <stdio.h>
  76. +#include <stdlib.h>
  77. +#include <fcntl.h>
  78. +#include <string.h>
  79. +#include <ctype.h>
  80. +
  81. +#include "types.h"
  82. +
  83. +#define BUFF_SIZE 512
  84. +
  85. +struct div_entry {
  86. + uchar class_name[BUFF_SIZE];
  87. + int indent;
  88. + struct div_entry *next;
  89. +};
  90. +
  91. +static struct div_entry *head = 0;
  92. +
  93. +/* These are the parsing states */
  94. +#define IGNORE_TILL_SEMI 0
  95. +#define IGNORE_TILL_CLOSE_BRACE 1
  96. +#define READING_DIV 2
  97. +#define READING_CLASS 3
  98. +#define READING_ATTRIBUTE 4
  99. +#define READING_NUM 5
  100. +#define CHECKING_ONLY_DIV 6
  101. +
  102. +static int at_eof = 0;
  103. +
  104. +static int strucmp(uchar *a, uchar *b) {
  105. + int i;
  106. + for (i = 0; a[i] && b[i]; i++) {
  107. + if (a[i] < b[i]) return -1;
  108. + if (a[i] > b[i]) return 1;
  109. + }
  110. + /* This isn't right, but who cares...*/
  111. + if (a[i] || b[i]) return 1;
  112. + return 0;
  113. +}
  114. +
  115. +static int read_word(FILE *f, const char *word) {
  116. + char c;
  117. + for (int idx = 0; word[idx]; idx++) {
  118. + c = getc(f);
  119. + if (c == EOF) {
  120. + at_eof = 1;
  121. + return 0;
  122. + }
  123. + if (c != word[idx])
  124. + return 0;
  125. + }
  126. + return 1;
  127. +}
  128. +
  129. +int lookup_div_class(uchar *name) {
  130. + struct div_entry *node = head;
  131. +
  132. + while (node) {
  133. + if (strucmp(node->class_name, name) == 0)
  134. + return node->indent;
  135. + node = node->next;
  136. + }
  137. +
  138. + return 0;
  139. +}
  140. +
  141. +void parse_style(char *fname) {
  142. + FILE *f;
  143. + char c;
  144. + int state;
  145. + struct div_entry *cur = 0;
  146. + int class_idx = 0;
  147. + char num[BUFF_SIZE];
  148. + int num_idx = 0;
  149. +
  150. + if (!fname) return;
  151. +
  152. + f = fopen(fname, "r");
  153. + if (!f) {
  154. + fprintf(stderr, "Unable to parse style\n");
  155. + return;
  156. + }
  157. +
  158. + state = READING_DIV;
  159. + while (!at_eof && (c = getc(f)) != EOF) {
  160. + switch (state) {
  161. +
  162. + case IGNORE_TILL_SEMI:
  163. + if (c == ';')
  164. + state = READING_ATTRIBUTE;
  165. + break;
  166. +
  167. + case IGNORE_TILL_CLOSE_BRACE:
  168. + if (c == '}')
  169. + state = READING_DIV;
  170. + break;
  171. +
  172. + case READING_DIV:
  173. + if (c != ' ' && c != '\t' && c != '\n') {
  174. + if (c == 'd' && read_word(f, "iv.")) {
  175. + state = READING_CLASS;
  176. + cur = (struct div_entry *) malloc(sizeof(struct div_entry));
  177. + memset(cur, 0, sizeof(struct div_entry));
  178. + class_idx = 0;
  179. + } else
  180. + state = IGNORE_TILL_CLOSE_BRACE;
  181. + }
  182. + break;
  183. +
  184. + case READING_CLASS:
  185. + if (isalpha(c)) {
  186. + if (class_idx >= BUFF_SIZE-1) {
  187. + fprintf(stderr, "class size %s too long\n", cur->class_name);
  188. + free(cur);
  189. + state = IGNORE_TILL_CLOSE_BRACE;
  190. + } else {
  191. + cur->class_name[class_idx++] = c;
  192. + }
  193. + } else {
  194. + if (c == '{') {
  195. + cur->next = head;
  196. + head = cur;
  197. + state = READING_ATTRIBUTE;
  198. + } else
  199. + state = CHECKING_ONLY_DIV;
  200. + }
  201. + break;
  202. +
  203. + case READING_ATTRIBUTE:
  204. + if (c != ' ' && c != '\t' && c != '\n') {
  205. + if (c == '}')
  206. + state = READING_DIV;
  207. + else {
  208. + if (c == 'm' && read_word(f, "argin-left:")) {
  209. + num_idx = 0;
  210. + memset(num, 0, sizeof(num));
  211. + state = READING_NUM;
  212. + } else {
  213. + state = IGNORE_TILL_SEMI;
  214. + }
  215. + }
  216. + }
  217. + break;
  218. +
  219. + case READING_NUM:
  220. + if (isdigit(c)) {
  221. + if (num_idx >= BUFF_SIZE - 1) {
  222. + fprintf(stderr, "Number too long\n");
  223. + state = IGNORE_TILL_SEMI;
  224. + } else {
  225. + num[num_idx++] = c;
  226. + }
  227. + } else if (c != ' ' && c != '\t') {
  228. + if (num_idx > 0 && c == 'e' && read_word(f, "m"))
  229. + cur->indent = atoi(num);
  230. + state = IGNORE_TILL_SEMI;
  231. + }
  232. + break;
  233. +
  234. + case CHECKING_ONLY_DIV:
  235. + if (c != ' ' && c != '\t' && c != '\n') {
  236. + if (c == '{') {
  237. + cur->next = head;
  238. + head = cur;
  239. + state = READING_ATTRIBUTE;
  240. + } else {
  241. + free(cur);
  242. + state = IGNORE_TILL_CLOSE_BRACE;
  243. + }
  244. + }
  245. + break;
  246. + }
  247. + }
  248. +
  249. + fclose(f);
  250. +}
  251. --- htmldoc-1.8.24/htmldoc/Makefile~margin-left
  252. +++ htmldoc-1.8.24/htmldoc/Makefile
  253. @@ -35,7 +35,7 @@
  254. OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o http.o \
  255. http-addr.o http-support.o image.o iso8859.o license.o md5.o \
  256. - progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o
  257. + progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o style.o
  258. #