-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.c
385 lines (350 loc) · 9.1 KB
/
list.c
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#include <stdlib.h>
#ifdef __PUREC__
# define PARSER struct s_parser * PARSER
#endif
#include "global.h"
#include "token.h"
#include "scanner.h"
#include "Loader.h"
#include "parser.h"
#include "fontbase.h"
/*============================================================================*/
void
list_start (PARSER parser, TEXTBUFF current, BULLET bullet, short counter, short type )
{
LSTSTACK list = malloc (sizeof (struct list_stack_item));
DOMBOX * nest = (current->parentbox->BoxClass == BC_LIST
? current->parentbox : NULL);
DOMBOX * box = create_box (current, BC_LIST, (nest ? 0 : 2));
char out[100];
box->HtmlCode = list->Type = type;
if (nest) {
PARAGRPH last = current->lst_stack->ListItem;
if (last && last->Box.Sibling == box
&& !last->item->next_word->next_word) {
last->Box.SetWidth = dombox_MinWidth (&last->Box);
last->Box.Floating = FLT_MASK|ALN_CENTER;
}
box->Margin.Lft = current->lst_stack->Hanging;
}
/* moved these here since all lists called them */
css_box_styles (parser, box, ALN_LEFT);
css_text_styles (parser, current->font);
box->FontStk = current->font;
list->BulletStyle = bullet;
list->Counter = counter;
/* special case ? */
if ((get_value (parser, CSS_MARGIN, out, sizeof(out))) &&
(box->Margin.Lft == 0))
list->Hanging = 0;
else
list->Hanging = current->word->font->SpaceWidth *5;
list->ListItem = NULL;
list->FontStk = current->font;
list->next_stack_item = current->lst_stack;
current->lst_stack = list;
current->paragraph->Box.Margin.Lft = list->Hanging;
}
/*============================================================================*/
void
list_finish (TEXTBUFF current)
{
LSTSTACK list = current->lst_stack;
if (list->FontStk != current->font) {
fontstack_pop (current);
}
if (leave_box (current, list->Type)) {
if ((current->lst_stack = list->next_stack_item) == NULL) {
add_paragraph (current, 2);
}
free (list);
}
}
/*------------------------------------------------------------------------------
* Recursively converts a positive long to a decimal number wide string.
* Rainer Seitel, 2002-03-11
*/
static void long2decimal (char **p_ws, long l)
{
if (l >= 10)
long2decimal(p_ws, l / 10);
*((*p_ws)++) = (char)((l % 10) + '0');
}
/*------------------------------------------------------------------------------
* Recursively converts a positive long to an alphabet number wide string.
* Rainer Seitel, 2002-03-11
*/
static void long2alpha (char **p_ws, long l, BOOL upper)
{
if (l > 26)
long2alpha(p_ws, l / 26, upper);
*((*p_ws)++) = (char)(((l - 1) % 26) + (upper? 'A' : 'a'));
}
/*------------------------------------------------------------------------------
* Sources:
* Friedlein, Gottfried: Die Zahlzeichen und das elementare Rechnen
* der Griechen und Roemer und des christlichen Abendlandes vom 7.
* bis 13. Jahrhundert. - unveraenderter Neudruck der Ausgabe von
* 1869. - Wiesbaden : Dr. Martin Saendig oHG, 1968.
* Ifroh, Georges: Universalgeschichte der Zahlen. - Frankfurt am
* Main ; New York : Campus, 1986. - ISBN 3-593-33666-9. - Kapitel
* 9. (Histoire Universelle des Chiffres. - Paris : Seghers, 1981.)
* Rainer Seitel, 2002-03-11
*/
static void short2roman (char **p_ws, short count, BOOL upper)
{
struct { char M, D, C, L, X, V, I; }
u_case = { 'M','D','C','L','X','V','I' },
l_case = { 'm','d','c','l','x','v','i' },
* letter = (upper ? &u_case : &l_case);
char * text = *p_ws;
if (count >= 10000) {
*(text++) = '(';
*(text++) = '(';
*(text++) = '|';
*(text++) = ')';
*(text++) = ')';
}
switch ((count % 10000) / 1000 * 1000) {
case 9000:
*(text++) = '|';
*(text++) = ')';
*(text++) = ')';
*(text++) = letter->M;
*(text++) = letter->M;
*(text++) = letter->M;
*(text++) = letter->M;
break;
case 8000:
*(text++) = '|';
*(text++) = ')';
*(text++) = ')';
*(text++) = letter->M;
*(text++) = letter->M;
*(text++) = letter->M;
break;
case 7000:
*(text++) = '|';
*(text++) = ')';
*(text++) = ')';
*(text++) = letter->M;
*(text++) = letter->M;
break;
case 6000:
*(text++) = '|';
*(text++) = ')';
*(text++) = ')';
*(text++) = letter->M;
break;
case 5000:
*(text++) = letter->M;
case 4000:
*(text++) = letter->M;
case 3000:
*(text++) = letter->M;
case 2000:
*(text++) = letter->M;
case 1000:
*(text++) = letter->M;
break;
}
switch ((count % 1000) / 100 * 100) {
case 300:
*(text++) = letter->C;
case 200:
*(text++) = letter->C;
case 100:
*(text++) = letter->C;
break;
case 400:
*(text++) = letter->C;
case 500:
*(text++) = letter->D;
break;
case 600:
*(text++) = letter->D;
*(text++) = letter->C;
break;
case 700:
*(text++) = letter->D;
*(text++) = letter->C;
*(text++) = letter->C;
break;
case 800:
*(text++) = letter->D;
*(text++) = letter->C;
*(text++) = letter->C;
*(text++) = letter->C;
break;
case 900:
*(text++) = letter->C;
*(text++) = letter->M;
break;
}
switch ((count % 100) / 10 * 10) {
case 30:
*(text++) = letter->X;
case 20:
*(text++) = letter->X;
case 10:
*(text++) = letter->X;
break;
case 40:
*(text++) = letter->X;
case 50:
*(text++) = letter->L;
break;
case 60:
*(text++) = letter->L;
*(text++) = letter->X;
break;
case 70:
*(text++) = letter->L;
*(text++) = letter->X;
*(text++) = letter->X;
break;
case 80:
*(text++) = letter->L;
*(text++) = letter->X;
*(text++) = letter->X;
*(text++) = letter->X;
break;
case 90:
*(text++) = letter->X;
*(text++) = letter->C;
break;
}
switch (count % 10) {
case 3:
*(text++) = letter->I;
case 2:
*(text++) = letter->I;
case 1:
*(text++) = letter->I;
break;
case 4:
*(text++) = letter->I;
case 5:
*(text++) = letter->V;
break;
case 6:
*(text++) = letter->V;
*(text++) = letter->I;
break;
case 7:
*(text++) = letter->V;
*(text++) = letter->I;
*(text++) = letter->I;
break;
case 8:
*(text++) = letter->V;
*(text++) = letter->I;
*(text++) = letter->I;
*(text++) = letter->I;
break;
case 9:
*(text++) = letter->I;
*(text++) = letter->X;
break;
}
*p_ws = text;
}
/*============================================================================*/
void
list_marker (TEXTBUFF current, BULLET bullet, short counter)
{
char buffer[80] = "", * text = buffer;
WORD mapping = current->word->font->Base->Mapping;
LSTSTACK list = current->lst_stack;
WORD width = list->Hanging;
WORD spc_wd = (current->word->font->SpaceWidth +1) /2;
PARAGRPH par = add_paragraph (current, 0);
par->Box.HtmlCode = TAG_LI;
par->Box.Margin.Lft = 0;
par->Box.TextIndent = -list->Hanging;
list->ListItem = par;
*(current->text++) = font_Nobrk (current->word->font);
new_word (current, TRUE);
current->paragraph->Box.FontStk = current->font;
switch (bullet)
{
case LT_DISC:
current->text = unicode_to_wchar (0x2022, /* BULLET */
current->text, mapping);
break;
case LT_SQUARE:
current->text = unicode_to_wchar (0x25AA, /* BLACK SMALL SQUARE */
current->text, mapping);
break;
case LT_CIRCLE:
current->text = unicode_to_wchar (0x25E6, /* WHITE BULLET */
current->text, mapping);
break;
case LT_DECIMAL:
list->Counter = counter +1;
if (counter < 0) {
current->text = unicode_to_wchar (0x2212, /* MINUS SIGN */
current->text, mapping);
counter = -counter;
}
long2decimal (&text, counter);
break;
case LT_L_ALPHA:
if (counter != 0) {
list->Counter = counter +1;
if (counter < 0) {
current->text = unicode_to_wchar (0x2212, /* MINUS SIGN */
current->text, mapping);
counter = -counter;
}
long2alpha (&text, counter, FALSE);
break;
}
/* else use @ as small alphabet zero */
case LT_U_ALPHA:
list->Counter = counter +1;
if (counter < 0) {
current->text = unicode_to_wchar (0x2212, /* MINUS SIGN */
current->text, mapping);
counter = -counter;
}
long2alpha (&text, counter, TRUE);
break;
case LT_L_ROMAN:
list->Counter = counter +1;
if (counter > 0 && counter < 3000) {
short2roman (&text, counter, FALSE);
} else { /* BUG: small Roman numerals >= 3000 not implemented! */
long2decimal (&text, counter);
}
break;
case LT_U_ROMAN:
list->Counter = counter +1;
if (counter > 0 && counter < 20000) {
short2roman (&text, counter, TRUE);
} else { /* BUG: Roman numerals >= 20000 not implemented! */
long2decimal (&text, counter);
}
break;
case LT_NONE:
if (list->Hanging == 0)
{
spc_wd = 0;
width = 0;
}else {
*(current->text++) = font_Nobrk (current->word->font);
if (!list->BulletStyle) {
spc_wd = 0;
width = current->prev_wrd->word_width *2;
}
}
}
if (text > buffer) {
*(text++) = '.';
*(text) = '\0';
scan_string_to_16bit (buffer, ENCODING_ATARIST, ¤t->text, mapping);
}
new_word (current, TRUE);
width -= (current->prev_wrd->word_width += spc_wd);
par->item->word_width = (spc_wd > width ? spc_wd : width);
}