aboutsummaryrefslogtreecommitdiff
path: root/Doc/Manual/margin-left.patch
blob: 8bef6305c321cd4bfdc236d098447230e32ea08d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# This patch is against htmldoc 1.8.27, and it hacks in support for
# correctly indenting the <div class=""> 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: <num>em;
+ *
+ * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
+ *
+ * Released under GNU GPL v2 or above.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <ctype.h>
+
+#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);
+}