Add support for doing different underlining of different heading levels
[sgt/halibut] / bk_info.c
CommitLineData
5dd44dce 1/*
2 * info backend for Halibut
3 *
b921687e 4 * Possible future work:
5dd44dce 5 *
b921687e 6 * - configurable choice of how to allocate node names?
7 * + possibly a template-like approach, choosing node names to
8 * be the full section title or perhaps the internal keyword?
9 * + neither of those seems quite right. Perhaps instead a
10 * Windows Help-like mechanism, where a magic config
11 * directive allows user choice of name for every node.
12 * + Only trouble with that is, now what happens to the section
13 * numbers? Do they become completely vestigial and just sit
14 * in the title text of each node? Or do we keep them in the
15 * menus somehow? I think people might occasionally want to
16 * go to a section by number, if only because all the _other_
17 * formats of the same document will reference the numbers
18 * all the time. So our menu lines could look like one of
19 * these:
20 * * Nodename: Section 1.2. Title of section.
21 * * Section 1.2: Nodename. Title of section.
5dd44dce 22 *
b921687e 23 * - might be helpful to diagnose duplicate node names!
c2d30a0d 24 *
25 * - more flexibility in heading underlines, like text backend.
26 * + Given info.el's fontifier, we'd want the following defaults:
27 * \cfg{info-title-underline}{*}
28 * \cfg{info-chapter-underline}{=}
29 * \cfg{info-section-underline}{0}{-}
30 * \cfg{info-section-underline}{1}{.}
31 *
32 * - Indices generated by makeinfo use a menu rather than a bunch of
33 * cross-references, which reduces visual clutter rather. For
34 * singly-referenced items, it looks like:
35 * * toner cartridge, replacing: Toner.
36 * It does a horrid job on multiply-referenced entries, though,
37 * perhaps because the name before the colon is meant to be unique.
22e33bba 38 * Info's 'i' command requires the use of a menu -- it fails to
39 * find any index entries at all with Halibut's current index format.
c2d30a0d 40 *
41 * - The string "*note" is matched case-insensitively, so we could
42 * make things slightly less ugly by using the lower-case version
43 * when the user asks for \k. Unfortunately, standalone Info seems
44 * to match node names case-sensitively, so we can't downcase that.
5dd44dce 45 */
46
47#include <stdio.h>
48#include <stdlib.h>
49#include <assert.h>
50#include "halibut.h"
51
52typedef struct {
e32df3e7 53 wchar_t *underline;
54} alignstruct;
55
56typedef struct {
5dd44dce 57 char *filename;
58 int maxfilesize;
91f93b94 59 int charset;
5b1d0032 60 int listindentbefore, listindentafter;
61 int indent_code, width, index_width;
e32df3e7 62 alignstruct atitle, achapter, *asect;
63 int nasect;
5b1d0032 64 wchar_t *bullet, *listsuffix;
65 wchar_t *startemph, *endemph;
66 wchar_t *lquote, *rquote;
e32df3e7 67 wchar_t *sectsuffix;
5b1d0032 68 wchar_t *rule;
f6220253 69 wchar_t *index_text;
5dd44dce 70} infoconfig;
71
91f93b94 72typedef struct {
73 rdstringc output;
74 int charset;
75 charset_state state;
76 int wcmode;
77} info_data;
78#define EMPTY_INFO_DATA { { 0, 0, NULL }, 0, CHARSET_INIT_STATE, FALSE }
79static const info_data empty_info_data = EMPTY_INFO_DATA;
80
5dd44dce 81typedef struct node_tag node;
82struct node_tag {
83 node *listnext;
84 node *up, *prev, *next, *lastchild;
85 int pos, started_menu, filenum;
86 char *name;
91f93b94 87 info_data text;
5dd44dce 88};
89
90typedef struct {
91 char *text;
91f93b94 92 int length;
5dd44dce 93 int nnodes, nodesize;
94 node **nodes;
95} info_idx;
96
91f93b94 97static int info_rdadd(info_data *, wchar_t);
98static int info_rdadds(info_data *, wchar_t const *);
99static int info_rdaddc(info_data *, char);
100static int info_rdaddsc(info_data *, char const *);
5dd44dce 101
e32df3e7 102static void info_heading(info_data *, word *, word *, alignstruct, int,
103 infoconfig *);
5b1d0032 104static void info_rule(info_data *, int, int, infoconfig *);
91f93b94 105static void info_para(info_data *, word *, wchar_t *, word *, keywordlist *,
5b1d0032 106 int, int, int, infoconfig *);
91f93b94 107static void info_codepara(info_data *, word *, int, int);
5b1d0032 108static void info_versionid(info_data *, word *, infoconfig *);
109static void info_menu_item(info_data *, node *, paragraph *, infoconfig *);
5dd44dce 110static word *info_transform_wordlist(word *, keywordlist *);
111static int info_check_index(word *, node *, indexdata *);
112
5b1d0032 113static int info_rdaddwc(info_data *, word *, word *, int, infoconfig *);
5dd44dce 114
91f93b94 115static node *info_node_new(char *name, int charset);
f6220253 116static char *info_node_name_for_para(paragraph *p, infoconfig *);
117static char *info_node_name_for_text(wchar_t *text, infoconfig *);
5dd44dce 118
119static infoconfig info_configure(paragraph *source) {
120 infoconfig ret;
5b1d0032 121 paragraph *p;
e32df3e7 122 int n;
5dd44dce 123
124 /*
125 * Defaults.
126 */
127 ret.filename = dupstr("output.info");
128 ret.maxfilesize = 64 << 10;
91f93b94 129 ret.charset = CS_ASCII;
5b1d0032 130 ret.width = 70;
131 ret.listindentbefore = 1;
132 ret.listindentafter = 3;
133 ret.indent_code = 2;
134 ret.index_width = 40;
135 ret.listsuffix = L".";
136 ret.bullet = L"\x2022\0-\0\0";
137 ret.rule = L"\x2500\0-\0\0";
138 ret.startemph = L"_\0_\0\0";
139 ret.endemph = uadv(ret.startemph);
140 ret.lquote = L"\x2018\0\x2019\0`\0'\0\0";
141 ret.rquote = uadv(ret.lquote);
142 ret.sectsuffix = L": ";
e32df3e7 143 /*
144 * Default underline characters are chosen to match those recognised by
145 * Info-fontify-node.
146 */
147 ret.atitle.underline = L"*\0\0";
148 ret.achapter.underline = L"=\0\0";
149 ret.nasect = 2;
150 ret.asect = snewn(ret.nasect, alignstruct);
151 ret.asect[0].underline = L"-\0\0";
152 ret.asect[1].underline = L".\0\0";
f6220253 153 ret.index_text = L"Index";
5b1d0032 154
155 /*
156 * Two-pass configuration so that we can pick up global config
157 * (e.g. `quotes') before having it overridden by specific
158 * config (`info-quotes'), irrespective of the order in which
159 * they occur.
160 */
161 for (p = source; p; p = p->next) {
162 if (p->type == para_Config) {
163 if (!ustricmp(p->keyword, L"quotes")) {
164 if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) {
165 ret.lquote = uadv(p->keyword);
166 ret.rquote = uadv(ret.lquote);
167 }
f6220253 168 } else if (!ustricmp(p->keyword, L"index")) {
169 ret.index_text = uadv(p->keyword);
5b1d0032 170 }
171 }
172 }
5dd44dce 173
5b1d0032 174 for (p = source; p; p = p->next) {
175 if (p->type == para_Config) {
176 if (!ustricmp(p->keyword, L"info-filename")) {
5dd44dce 177 sfree(ret.filename);
5b1d0032 178 ret.filename = dupstr(adv(p->origkeyword));
179 } else if (!ustricmp(p->keyword, L"info-charset")) {
0960a3d8 180 ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword));
5b1d0032 181 } else if (!ustricmp(p->keyword, L"info-max-file-size")) {
182 ret.maxfilesize = utoi(uadv(p->keyword));
183 } else if (!ustricmp(p->keyword, L"info-width")) {
184 ret.width = utoi(uadv(p->keyword));
185 } else if (!ustricmp(p->keyword, L"info-indent-code")) {
186 ret.indent_code = utoi(uadv(p->keyword));
187 } else if (!ustricmp(p->keyword, L"info-index-width")) {
188 ret.index_width = utoi(uadv(p->keyword));
189 } else if (!ustricmp(p->keyword, L"info-list-indent")) {
190 ret.listindentbefore = utoi(uadv(p->keyword));
191 } else if (!ustricmp(p->keyword, L"info-listitem-indent")) {
192 ret.listindentafter = utoi(uadv(p->keyword));
193 } else if (!ustricmp(p->keyword, L"info-section-suffix")) {
194 ret.sectsuffix = uadv(p->keyword);
195 } else if (!ustricmp(p->keyword, L"info-underline")) {
e32df3e7 196 ret.atitle.underline = ret.achapter.underline =
197 uadv(p->keyword);
198 for (n = 0; n < ret.nasect; n++)
199 ret.asect[n].underline = ret.atitle.underline;
200 } else if (!ustricmp(p->keyword, L"info-chapter-underline")) {
201 ret.achapter.underline = uadv(p->keyword);
202 } else if (!ustricmp(p->keyword, L"info-section-underline")) {
203 wchar_t *q = uadv(p->keyword);
204 int n = 0;
205 if (uisdigit(*q)) {
206 n = utoi(q);
207 q = uadv(q);
208 }
209 if (n >= ret.nasect) {
210 int i;
211 ret.asect = sresize(ret.asect, n+1, alignstruct);
212 for (i = ret.nasect; i <= n; i++)
213 ret.asect[i] = ret.asect[ret.nasect-1];
214 ret.nasect = n+1;
215 }
216 ret.asect[n].underline = q;
217 } else if (!ustricmp(p->keyword, L"text-title-underline")) {
218 ret.atitle.underline = uadv(p->keyword);
5b1d0032 219 } else if (!ustricmp(p->keyword, L"info-bullet")) {
220 ret.bullet = uadv(p->keyword);
221 } else if (!ustricmp(p->keyword, L"info-rule")) {
222 ret.rule = uadv(p->keyword);
223 } else if (!ustricmp(p->keyword, L"info-list-suffix")) {
224 ret.listsuffix = uadv(p->keyword);
225 } else if (!ustricmp(p->keyword, L"info-emphasis")) {
226 if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) {
227 ret.startemph = uadv(p->keyword);
228 ret.endemph = uadv(ret.startemph);
229 }
230 } else if (!ustricmp(p->keyword, L"info-quotes")) {
231 if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) {
232 ret.lquote = uadv(p->keyword);
233 ret.rquote = uadv(ret.lquote);
234 }
5dd44dce 235 }
236 }
237 }
238
5b1d0032 239 /*
240 * Now process fallbacks on quote characters, underlines, the
241 * rule character, the emphasis characters, and bullets.
242 */
243 while (*uadv(ret.rquote) && *uadv(uadv(ret.rquote)) &&
244 (!cvt_ok(ret.charset, ret.lquote) ||
245 !cvt_ok(ret.charset, ret.rquote))) {
246 ret.lquote = uadv(ret.rquote);
247 ret.rquote = uadv(ret.lquote);
248 }
249
250 while (*uadv(ret.endemph) && *uadv(uadv(ret.endemph)) &&
251 (!cvt_ok(ret.charset, ret.startemph) ||
252 !cvt_ok(ret.charset, ret.endemph))) {
253 ret.startemph = uadv(ret.endemph);
254 ret.endemph = uadv(ret.startemph);
255 }
256
e32df3e7 257 while (*ret.atitle.underline && *uadv(ret.atitle.underline) &&
258 !cvt_ok(ret.charset, ret.atitle.underline))
259 ret.atitle.underline = uadv(ret.atitle.underline);
260
261 while (*ret.achapter.underline && *uadv(ret.achapter.underline) &&
262 !cvt_ok(ret.charset, ret.achapter.underline))
263 ret.achapter.underline = uadv(ret.achapter.underline);
264
265 for (n = 0; n < ret.nasect; n++) {
266 while (*ret.asect[n].underline && *uadv(ret.asect[n].underline) &&
267 !cvt_ok(ret.charset, ret.asect[n].underline))
268 ret.asect[n].underline = uadv(ret.asect[n].underline);
269 }
270
5b1d0032 271 while (*ret.bullet && *uadv(ret.bullet) &&
272 !cvt_ok(ret.charset, ret.bullet))
273 ret.bullet = uadv(ret.bullet);
274
275 while (*ret.rule && *uadv(ret.rule) &&
276 !cvt_ok(ret.charset, ret.rule))
277 ret.rule = uadv(ret.rule);
278
5dd44dce 279 return ret;
280}
281
282paragraph *info_config_filename(char *filename)
283{
e4ea58f8 284 return cmdline_cfg_simple("info-filename", filename, NULL);
5dd44dce 285}
286
287void info_backend(paragraph *sourceform, keywordlist *keywords,
43341922 288 indexdata *idx, void *unused) {
5dd44dce 289 paragraph *p;
290 infoconfig conf;
291 word *prefix, *body, *wp;
292 word spaceword;
91f93b94 293 wchar_t *prefixextra;
5dd44dce 294 int nesting, nestindent;
295 int indentb, indenta;
296 int filepos;
297 int has_index;
91f93b94 298 info_data intro_text = EMPTY_INFO_DATA;
5dd44dce 299 node *topnode, *currnode;
300 word bullet;
301 FILE *fp;
302
43341922 303 IGNORE(unused);
5dd44dce 304
305 conf = info_configure(sourceform);
306
307 /*
308 * Go through and create a node for each section.
309 */
91f93b94 310 topnode = info_node_new("Top", conf.charset);
5dd44dce 311 currnode = topnode;
312 for (p = sourceform; p; p = p->next) switch (p->type) {
313 /*
314 * Chapter titles.
315 */
316 case para_Chapter:
317 case para_Appendix:
318 case para_UnnumberedChapter:
319 case para_Heading:
320 case para_Subsect:
321 {
322 node *newnode, *upnode;
323 char *nodename;
324
f6220253 325 nodename = info_node_name_for_para(p, &conf);
91f93b94 326 newnode = info_node_new(nodename, conf.charset);
5dd44dce 327 sfree(nodename);
328
329 p->private_data = newnode;
330
331 if (p->parent)
332 upnode = (node *)p->parent->private_data;
333 else
334 upnode = topnode;
335 assert(upnode);
336 newnode->up = upnode;
337
338 currnode->next = newnode;
339 newnode->prev = currnode;
340
341 currnode->listnext = newnode;
342 currnode = newnode;
343 }
344 break;
e0e55d41 345 default:
346 p->private_data = NULL;
347 break;
5dd44dce 348 }
349
350 /*
351 * Set up the display form of each index entry.
352 */
353 {
354 int i;
355 indexentry *entry;
356
357 for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) {
f1530049 358 info_idx *ii = snew(info_idx);
91f93b94 359 info_data id = EMPTY_INFO_DATA;
360
361 id.charset = conf.charset;
5dd44dce 362
363 ii->nnodes = ii->nodesize = 0;
364 ii->nodes = NULL;
365
5b1d0032 366 ii->length = info_rdaddwc(&id, entry->text, NULL, FALSE, &conf);
f4551933 367
91f93b94 368 ii->text = id.output.text;
5dd44dce 369
370 entry->backend_data = ii;
371 }
372 }
373
374 /*
375 * An Info file begins with a piece of introductory text which
376 * is apparently never shown anywhere. This seems to me to be a
d4c7e130 377 * good place to put the copyright notice and the version IDs.
378 * Also, Info directory entries are expected to go here.
5dd44dce 379 */
91f93b94 380 intro_text.charset = conf.charset;
5dd44dce 381
91f93b94 382 info_rdaddsc(&intro_text,
5dd44dce 383 "This Info file generated by Halibut, ");
91f93b94 384 info_rdaddsc(&intro_text, version);
385 info_rdaddsc(&intro_text, "\n\n");
5dd44dce 386
387 for (p = sourceform; p; p = p->next)
d4c7e130 388 if (p->type == para_Config &&
389 !ustricmp(p->keyword, L"info-dir-entry")) {
390 wchar_t *section, *shortname, *longname, *kw;
391 char *s;
392
393 section = uadv(p->keyword);
12f0ee84 394 shortname = *section ? uadv(section) : L"";
395 longname = *shortname ? uadv(shortname) : L"";
396 kw = *longname ? uadv(longname) : L"";
d4c7e130 397
398 if (!*longname) {
12f0ee84 399 error(err_cfginsufarg, &p->fpos, p->origkeyword, 3);
d4c7e130 400 continue;
401 }
402
91f93b94 403 info_rdaddsc(&intro_text, "INFO-DIR-SECTION ");
404 info_rdadds(&intro_text, section);
405 info_rdaddsc(&intro_text, "\nSTART-INFO-DIR-ENTRY\n* ");
406 info_rdadds(&intro_text, shortname);
407 info_rdaddsc(&intro_text, ": (");
d4c7e130 408 s = dupstr(conf.filename);
409 if (strlen(s) > 5 && !strcmp(s+strlen(s)-5, ".info"))
410 s[strlen(s)-5] = '\0';
91f93b94 411 info_rdaddsc(&intro_text, s);
d4c7e130 412 sfree(s);
91f93b94 413 info_rdaddsc(&intro_text, ")");
d4c7e130 414 if (*kw) {
415 keyword *kwl = kw_lookup(keywords, kw);
416 if (kwl && kwl->para->private_data) {
417 node *n = (node *)kwl->para->private_data;
91f93b94 418 info_rdaddsc(&intro_text, n->name);
d4c7e130 419 }
420 }
91f93b94 421 info_rdaddsc(&intro_text, ". ");
422 info_rdadds(&intro_text, longname);
423 info_rdaddsc(&intro_text, "\nEND-INFO-DIR-ENTRY\n\n");
d4c7e130 424 }
425
426 for (p = sourceform; p; p = p->next)
5dd44dce 427 if (p->type == para_Copyright)
428 info_para(&intro_text, NULL, NULL, p->words, keywords,
5b1d0032 429 0, 0, conf.width, &conf);
5dd44dce 430
431 for (p = sourceform; p; p = p->next)
432 if (p->type == para_VersionID)
5b1d0032 433 info_versionid(&intro_text, p->words, &conf);
5dd44dce 434
91f93b94 435 if (intro_text.output.text[intro_text.output.pos-1] != '\n')
436 info_rdaddc(&intro_text, '\n');
5dd44dce 437
438 /* Do the title */
439 for (p = sourceform; p; p = p->next)
440 if (p->type == para_Title)
e32df3e7 441 info_heading(&topnode->text, NULL, p->words,
442 conf.atitle, conf.width, &conf);
5dd44dce 443
5b1d0032 444 nestindent = conf.listindentbefore + conf.listindentafter;
5dd44dce 445 nesting = 0;
446
447 currnode = topnode;
448
449 /* Do the main document */
450 for (p = sourceform; p; p = p->next) switch (p->type) {
451
452 case para_QuotePush:
453 nesting += 2;
454 break;
455 case para_QuotePop:
456 nesting -= 2;
457 assert(nesting >= 0);
458 break;
459
460 case para_LcontPush:
461 nesting += nestindent;
462 break;
463 case para_LcontPop:
464 nesting -= nestindent;
465 assert(nesting >= 0);
466 break;
467
468 /*
469 * Things we ignore because we've already processed them or
470 * aren't going to touch them in this pass.
471 */
472 case para_IM:
473 case para_BR:
474 case para_Biblio: /* only touch BiblioCited */
475 case para_VersionID:
476 case para_NoCite:
477 case para_Title:
478 break;
479
480 /*
481 * Chapter titles.
482 */
483 case para_Chapter:
484 case para_Appendix:
485 case para_UnnumberedChapter:
486 case para_Heading:
487 case para_Subsect:
488 currnode = p->private_data;
489 assert(currnode);
490 assert(currnode->up);
491
492 if (!currnode->up->started_menu) {
91f93b94 493 info_rdaddsc(&currnode->up->text, "* Menu:\n\n");
5dd44dce 494 currnode->up->started_menu = TRUE;
495 }
5b1d0032 496 info_menu_item(&currnode->up->text, currnode, p, &conf);
5dd44dce 497
498 has_index |= info_check_index(p->words, currnode, idx);
e32df3e7 499 if (p->type == para_Chapter || p->type == para_Appendix ||
500 p->type == para_UnnumberedChapter)
501 info_heading(&currnode->text, p->kwtext, p->words,
502 conf.achapter, conf.width, &conf);
503 else
504 info_heading(&currnode->text, p->kwtext, p->words,
505 conf.asect[p->aux>=conf.nasect?conf.nasect-1:p->aux],
506 conf.width, &conf);
5dd44dce 507 nesting = 0;
508 break;
509
510 case para_Rule:
5b1d0032 511 info_rule(&currnode->text, nesting, conf.width - nesting, &conf);
5dd44dce 512 break;
513
514 case para_Normal:
515 case para_Copyright:
516 case para_DescribedThing:
517 case para_Description:
518 case para_BiblioCited:
519 case para_Bullet:
520 case para_NumberedList:
521 has_index |= info_check_index(p->words, currnode, idx);
522 if (p->type == para_Bullet) {
523 bullet.next = NULL;
524 bullet.alt = NULL;
525 bullet.type = word_Normal;
5b1d0032 526 bullet.text = conf.bullet;
5dd44dce 527 prefix = &bullet;
528 prefixextra = NULL;
5b1d0032 529 indentb = conf.listindentbefore;
530 indenta = conf.listindentafter;
5dd44dce 531 } else if (p->type == para_NumberedList) {
532 prefix = p->kwtext;
5b1d0032 533 prefixextra = conf.listsuffix;
534 indentb = conf.listindentbefore;
535 indenta = conf.listindentafter;
5dd44dce 536 } else if (p->type == para_Description) {
537 prefix = NULL;
538 prefixextra = NULL;
5b1d0032 539 indentb = conf.listindentbefore;
540 indenta = conf.listindentafter;
5dd44dce 541 } else {
542 prefix = NULL;
543 prefixextra = NULL;
544 indentb = indenta = 0;
545 }
546 if (p->type == para_BiblioCited) {
547 body = dup_word_list(p->kwtext);
548 for (wp = body; wp->next; wp = wp->next);
549 wp->next = &spaceword;
550 spaceword.next = p->words;
551 spaceword.alt = NULL;
552 spaceword.type = word_WhiteSpace;
553 spaceword.text = NULL;
554 } else {
555 wp = NULL;
556 body = p->words;
557 }
558 info_para(&currnode->text, prefix, prefixextra, body, keywords,
559 nesting + indentb, indenta,
5b1d0032 560 conf.width - nesting - indentb - indenta, &conf);
5dd44dce 561 if (wp) {
562 wp->next = NULL;
563 free_word_list(body);
564 }
565 break;
566
567 case para_Code:
568 info_codepara(&currnode->text, p->words,
5b1d0032 569 nesting + conf.indent_code,
570 conf.width - nesting - 2 * conf.indent_code);
5dd44dce 571 break;
572 }
573
574 /*
575 * Create an index node if required.
576 */
577 if (has_index) {
578 node *newnode;
579 int i, j, k;
580 indexentry *entry;
f6220253 581 char *nodename;
582
583 nodename = info_node_name_for_text(conf.index_text, &conf);
584 newnode = info_node_new(nodename, conf.charset);
585 sfree(nodename);
5dd44dce 586
5dd44dce 587 newnode->up = topnode;
588
589 currnode->next = newnode;
590 newnode->prev = currnode;
591 currnode->listnext = newnode;
592
f6220253 593 k = info_rdadds(&newnode->text, conf.index_text);
594 info_rdaddsc(&newnode->text, "\n");
595 while (k > 0) {
e32df3e7 596 info_rdadds(&newnode->text, conf.achapter.underline);
597 k -= ustrwid(conf.achapter.underline, conf.charset);
f6220253 598 }
599 info_rdaddsc(&newnode->text, "\n\n");
5dd44dce 600
5b1d0032 601 info_menu_item(&topnode->text, newnode, NULL, &conf);
5dd44dce 602
603 for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) {
604 info_idx *ii = (info_idx *)entry->backend_data;
605
606 for (j = 0; j < ii->nnodes; j++) {
5dd44dce 607 /*
608 * When we have multiple references for a single
609 * index term, we only display the actual term on
610 * the first line, to make it clear that the terms
611 * really are the same.
612 */
613 if (j == 0)
91f93b94 614 info_rdaddsc(&newnode->text, ii->text);
5b1d0032 615 for (k = (j ? 0 : ii->length); k < conf.index_width-2; k++)
91f93b94 616 info_rdaddc(&newnode->text, ' ');
5b1d0032 617 info_rdaddsc(&newnode->text, " *Note ");
91f93b94 618 info_rdaddsc(&newnode->text, ii->nodes[j]->name);
619 info_rdaddsc(&newnode->text, "::\n");
5dd44dce 620 }
621 }
622 }
623
624 /*
625 * Finalise the text of each node, by adding the ^_ delimiter
626 * and the node line at the top.
627 */
628 for (currnode = topnode; currnode; currnode = currnode->listnext) {
91f93b94 629 char *origtext = currnode->text.output.text;
630 currnode->text = empty_info_data;
631 currnode->text.charset = conf.charset;
632 info_rdaddsc(&currnode->text, "\037\nFile: ");
633 info_rdaddsc(&currnode->text, conf.filename);
634 info_rdaddsc(&currnode->text, ", Node: ");
635 info_rdaddsc(&currnode->text, currnode->name);
5dd44dce 636 if (currnode->prev) {
91f93b94 637 info_rdaddsc(&currnode->text, ", Prev: ");
638 info_rdaddsc(&currnode->text, currnode->prev->name);
5dd44dce 639 }
91f93b94 640 info_rdaddsc(&currnode->text, ", Up: ");
641 info_rdaddsc(&currnode->text, (currnode->up ?
642 currnode->up->name : "(dir)"));
5dd44dce 643 if (currnode->next) {
91f93b94 644 info_rdaddsc(&currnode->text, ", Next: ");
645 info_rdaddsc(&currnode->text, currnode->next->name);
5dd44dce 646 }
91f93b94 647 info_rdaddsc(&currnode->text, "\n\n");
648 info_rdaddsc(&currnode->text, origtext);
5dd44dce 649 /*
650 * Just make _absolutely_ sure we end with a newline.
651 */
91f93b94 652 if (currnode->text.output.text[currnode->text.output.pos-1] != '\n')
653 info_rdaddc(&currnode->text, '\n');
5dd44dce 654
655 sfree(origtext);
656 }
657
658 /*
659 * Compute the offsets for the tag table.
660 */
91f93b94 661 filepos = intro_text.output.pos;
5dd44dce 662 for (currnode = topnode; currnode; currnode = currnode->listnext) {
663 currnode->pos = filepos;
91f93b94 664 filepos += currnode->text.output.pos;
5dd44dce 665 }
666
667 /*
668 * Split into sub-files.
669 */
670 if (conf.maxfilesize > 0) {
91f93b94 671 int currfilesize = intro_text.output.pos, currfilenum = 1;
5dd44dce 672 for (currnode = topnode; currnode; currnode = currnode->listnext) {
91f93b94 673 if (currfilesize > intro_text.output.pos &&
674 currfilesize + currnode->text.output.pos > conf.maxfilesize) {
5dd44dce 675 currfilenum++;
91f93b94 676 currfilesize = intro_text.output.pos;
5dd44dce 677 }
678 currnode->filenum = currfilenum;
91f93b94 679 currfilesize += currnode->text.output.pos;
5dd44dce 680 }
681 }
682
683 /*
684 * Write the primary output file.
685 */
686 fp = fopen(conf.filename, "w");
687 if (!fp) {
688 error(err_cantopenw, conf.filename);
689 return;
690 }
91f93b94 691 fputs(intro_text.output.text, fp);
5dd44dce 692 if (conf.maxfilesize == 0) {
693 for (currnode = topnode; currnode; currnode = currnode->listnext)
91f93b94 694 fputs(currnode->text.output.text, fp);
5dd44dce 695 } else {
696 int filenum = 0;
697 fprintf(fp, "\037\nIndirect:\n");
698 for (currnode = topnode; currnode; currnode = currnode->listnext)
699 if (filenum != currnode->filenum) {
700 filenum = currnode->filenum;
701 fprintf(fp, "%s-%d: %d\n", conf.filename, filenum,
702 currnode->pos);
703 }
704 }
705 fprintf(fp, "\037\nTag Table:\n");
706 if (conf.maxfilesize > 0)
707 fprintf(fp, "(Indirect)\n");
708 for (currnode = topnode; currnode; currnode = currnode->listnext)
709 fprintf(fp, "Node: %s\177%d\n", currnode->name, currnode->pos);
710 fprintf(fp, "\037\nEnd Tag Table\n");
711 fclose(fp);
712
713 /*
714 * Write the subfiles.
715 */
716 if (conf.maxfilesize > 0) {
717 int filenum = 0;
718 fp = NULL;
719
720 for (currnode = topnode; currnode; currnode = currnode->listnext) {
721 if (filenum != currnode->filenum) {
722 char *fname;
723
724 filenum = currnode->filenum;
725
726 if (fp)
727 fclose(fp);
f1530049 728 fname = snewn(strlen(conf.filename) + 40, char);
5dd44dce 729 sprintf(fname, "%s-%d", conf.filename, filenum);
730 fp = fopen(fname, "w");
731 if (!fp) {
732 error(err_cantopenw, fname);
733 return;
734 }
735 sfree(fname);
91f93b94 736 fputs(intro_text.output.text, fp);
5dd44dce 737 }
91f93b94 738 fputs(currnode->text.output.text, fp);
5dd44dce 739 }
740
741 if (fp)
742 fclose(fp);
743 }
744}
745
746static int info_check_index(word *w, node *n, indexdata *idx)
747{
748 int ret = 0;
749
750 for (; w; w = w->next) {
751 if (w->type == word_IndexRef) {
752 indextag *tag;
753 int i;
754
755 tag = index_findtag(idx, w->text);
756 if (!tag)
757 break;
758
759 for (i = 0; i < tag->nrefs; i++) {
760 indexentry *entry = tag->refs[i];
761 info_idx *ii = (info_idx *)entry->backend_data;
762
763 if (ii->nnodes > 0 && ii->nodes[ii->nnodes-1] == n) {
764 /*
765 * If the same index term is indexed twice
766 * within the same section, we only want to
767 * mention it once in the index. So do nothing
768 * here.
769 */
770 continue;
771 }
772
773 if (ii->nnodes >= ii->nodesize) {
774 ii->nodesize += 32;
f1530049 775 ii->nodes = sresize(ii->nodes, ii->nodesize, node *);
5dd44dce 776 }
777
778 ii->nodes[ii->nnodes++] = n;
779
780 ret = 1;
781 }
782 }
783 }
784
785 return ret;
786}
787
5dd44dce 788static word *info_transform_wordlist(word *words, keywordlist *keywords)
789{
790 word *ret = dup_word_list(words);
791 word *w;
792 keyword *kwl;
793
794 for (w = ret; w; w = w->next) {
795 w->private_data = NULL;
796 if (w->type == word_UpperXref || w->type == word_LowerXref) {
797 kwl = kw_lookup(keywords, w->text);
798 if (kwl) {
799 if (kwl->para->type == para_NumberedList ||
800 kwl->para->type == para_BiblioCited) {
801 /*
802 * In Info, we do nothing special for xrefs to
803 * numbered list items or bibliography entries.
804 */
90a0531e 805 continue;
5dd44dce 806 } else {
807 /*
808 * An xref to a different section has its text
809 * completely replaced.
810 */
811 word *w2, *w3, *w4;
812 w2 = w3 = w->next;
813 w4 = NULL;
814 while (w2) {
815 if (w2->type == word_XrefEnd) {
816 w4 = w2->next;
817 w2->next = NULL;
818 break;
819 }
820 w2 = w2->next;
821 }
822 free_word_list(w3);
823
824 /*
825 * Now w is the UpperXref / LowerXref we
826 * started with, and w4 is the next word after
827 * the corresponding XrefEnd (if any). The
828 * simplest thing is just to stick a pointer to
829 * the target node structure in the private
830 * data field of the xref word, and let
831 * info_rdaddwc and friends read the node name
832 * out from there.
833 */
834 w->next = w4;
835 w->private_data = kwl->para->private_data;
836 assert(w->private_data);
837 }
838 }
839 }
840 }
841
842 return ret;
843}
844
5b1d0032 845static int info_rdaddwc(info_data *id, word *words, word *end, int xrefs,
846 infoconfig *cfg) {
91f93b94 847 int ret = 0;
5dd44dce 848
849 for (; words && words != end; words = words->next) switch (words->type) {
850 case word_HyperLink:
851 case word_HyperEnd:
852 case word_XrefEnd:
853 case word_IndexRef:
854 break;
855
856 case word_Normal:
857 case word_Emph:
858 case word_Code:
859 case word_WeakCode:
860 case word_WhiteSpace:
861 case word_EmphSpace:
862 case word_CodeSpace:
863 case word_WkCodeSpace:
864 case word_Quote:
865 case word_EmphQuote:
866 case word_CodeQuote:
867 case word_WkCodeQuote:
868 assert(words->type != word_CodeQuote &&
869 words->type != word_WkCodeQuote);
870 if (towordstyle(words->type) == word_Emph &&
871 (attraux(words->aux) == attr_First ||
872 attraux(words->aux) == attr_Only))
5b1d0032 873 ret += info_rdadds(id, cfg->startemph);
5dd44dce 874 else if (towordstyle(words->type) == word_Code &&
875 (attraux(words->aux) == attr_First ||
876 attraux(words->aux) == attr_Only))
5b1d0032 877 ret += info_rdadds(id, cfg->lquote);
5dd44dce 878 if (removeattr(words->type) == word_Normal) {
91f93b94 879 if (cvt_ok(id->charset, words->text) || !words->alt)
880 ret += info_rdadds(id, words->text);
5dd44dce 881 else
5b1d0032 882 ret += info_rdaddwc(id, words->alt, NULL, FALSE, cfg);
5dd44dce 883 } else if (removeattr(words->type) == word_WhiteSpace) {
91f93b94 884 ret += info_rdadd(id, L' ');
5dd44dce 885 } else if (removeattr(words->type) == word_Quote) {
5b1d0032 886 ret += info_rdadds(id, quoteaux(words->aux) == quote_Open ?
887 cfg->lquote : cfg->rquote);
5dd44dce 888 }
889 if (towordstyle(words->type) == word_Emph &&
890 (attraux(words->aux) == attr_Last ||
891 attraux(words->aux) == attr_Only))
5b1d0032 892 ret += info_rdadds(id, cfg->endemph);
5dd44dce 893 else if (towordstyle(words->type) == word_Code &&
894 (attraux(words->aux) == attr_Last ||
895 attraux(words->aux) == attr_Only))
5b1d0032 896 ret += info_rdadds(id, cfg->rquote);
5dd44dce 897 break;
898
899 case word_UpperXref:
900 case word_LowerXref:
901 if (xrefs && words->private_data) {
91f93b94 902 /*
903 * This bit is structural and so must be done in char
904 * rather than wchar_t.
905 */
906 ret += info_rdaddsc(id, "*Note ");
907 ret += info_rdaddsc(id, ((node *)words->private_data)->name);
908 ret += info_rdaddsc(id, "::");
5dd44dce 909 }
910 break;
911 }
91f93b94 912
913 return ret;
5dd44dce 914}
915
5b1d0032 916static int info_width_internal(word *words, int xrefs, infoconfig *cfg);
5dd44dce 917
5b1d0032 918static int info_width_internal_list(word *words, int xrefs, infoconfig *cfg) {
5dd44dce 919 int w = 0;
920 while (words) {
5b1d0032 921 w += info_width_internal(words, xrefs, cfg);
5dd44dce 922 words = words->next;
923 }
924 return w;
925}
926
5b1d0032 927static int info_width_internal(word *words, int xrefs, infoconfig *cfg) {
928 int wid;
929 int attr;
930
5dd44dce 931 switch (words->type) {
932 case word_HyperLink:
933 case word_HyperEnd:
934 case word_XrefEnd:
935 case word_IndexRef:
936 return 0;
937
5b1d0032 938 case word_UpperXref:
939 case word_LowerXref:
940 if (xrefs && words->private_data) {
941 /* "*Note " plus "::" comes to 8 characters */
942 return 8 + strwid(((node *)words->private_data)->name,
943 cfg->charset);
944 } else
945 return 0;
946 }
947
948 assert(words->type < word_internal_endattrs);
949
950 wid = 0;
951 attr = towordstyle(words->type);
952
953 if (attr == word_Emph || attr == word_Code) {
954 if (attraux(words->aux) == attr_Only ||
955 attraux(words->aux) == attr_First)
956 wid += ustrwid(attr == word_Emph ? cfg->startemph : cfg->lquote,
957 cfg->charset);
958 }
959 if (attr == word_Emph || attr == word_Code) {
960 if (attraux(words->aux) == attr_Only ||
961 attraux(words->aux) == attr_Last)
962 wid += ustrwid(attr == word_Emph ? cfg->startemph : cfg->lquote,
963 cfg->charset);
964 }
965
966 switch (words->type) {
5dd44dce 967 case word_Normal:
968 case word_Emph:
969 case word_Code:
970 case word_WeakCode:
5b1d0032 971 if (cvt_ok(cfg->charset, words->text) || !words->alt)
972 wid += ustrwid(words->text, cfg->charset);
973 else
974 wid += info_width_internal_list(words->alt, xrefs, cfg);
975 return wid;
5dd44dce 976
977 case word_WhiteSpace:
978 case word_EmphSpace:
979 case word_CodeSpace:
980 case word_WkCodeSpace:
981 case word_Quote:
982 case word_EmphQuote:
983 case word_CodeQuote:
984 case word_WkCodeQuote:
985 assert(words->type != word_CodeQuote &&
986 words->type != word_WkCodeQuote);
5b1d0032 987 if (removeattr(words->type) == word_Quote) {
988 if (quoteaux(words->aux) == quote_Open)
989 wid += ustrwid(cfg->lquote, cfg->charset);
990 else
991 wid += ustrwid(cfg->rquote, cfg->charset);
992 } else
993 wid++; /* space */
5dd44dce 994 }
5b1d0032 995 return wid;
5dd44dce 996}
997
43341922 998static int info_width_noxrefs(void *ctx, word *words)
5dd44dce 999{
5b1d0032 1000 return info_width_internal(words, FALSE, (infoconfig *)ctx);
5dd44dce 1001}
43341922 1002static int info_width_xrefs(void *ctx, word *words)
5dd44dce 1003{
5b1d0032 1004 return info_width_internal(words, TRUE, (infoconfig *)ctx);
5dd44dce 1005}
1006
91f93b94 1007static void info_heading(info_data *text, word *tprefix,
e32df3e7 1008 word *words, alignstruct align,
1009 int width, infoconfig *cfg) {
91f93b94 1010 int length;
5dd44dce 1011 int firstlinewidth, wrapwidth;
5dd44dce 1012 wrappedline *wrapping, *p;
1013
91f93b94 1014 length = 0;
5dd44dce 1015 if (tprefix) {
5b1d0032 1016 length += info_rdaddwc(text, tprefix, NULL, FALSE, cfg);
1017 length += info_rdadds(text, cfg->sectsuffix);
5dd44dce 1018 }
5dd44dce 1019
5dd44dce 1020 wrapwidth = width;
91f93b94 1021 firstlinewidth = width - length;
5dd44dce 1022
43341922 1023 wrapping = wrap_para(words, firstlinewidth, wrapwidth,
5b1d0032 1024 info_width_noxrefs, cfg, 0);
5dd44dce 1025 for (p = wrapping; p; p = p->next) {
5b1d0032 1026 length += info_rdaddwc(text, p->begin, p->end, FALSE, cfg);
91f93b94 1027 info_rdadd(text, L'\n');
e32df3e7 1028 if (*align.underline) {
1029 while (length > 0) {
1030 info_rdadds(text, align.underline);
1031 length -= ustrwid(align.underline, cfg->charset);
1032 }
1033 info_rdadd(text, L'\n');
5b1d0032 1034 }
91f93b94 1035 length = 0;
5dd44dce 1036 }
1037 wrap_free(wrapping);
91f93b94 1038 info_rdadd(text, L'\n');
5dd44dce 1039}
1040
5b1d0032 1041static void info_rule(info_data *text, int indent, int width, infoconfig *cfg)
1042{
91f93b94 1043 while (indent--) info_rdadd(text, L' ');
5b1d0032 1044 while (width > 0) {
1045 info_rdadds(text, cfg->rule);
1046 width -= ustrwid(cfg->rule, cfg->charset);
1047 }
91f93b94 1048 info_rdadd(text, L'\n');
1049 info_rdadd(text, L'\n');
5dd44dce 1050}
1051
91f93b94 1052static void info_para(info_data *text, word *prefix, wchar_t *prefixextra,
5b1d0032 1053 word *input, keywordlist *keywords, int indent,
1054 int extraindent, int width, infoconfig *cfg) {
5dd44dce 1055 wrappedline *wrapping, *p;
1056 word *words;
5dd44dce 1057 int e;
1058 int i;
1059 int firstlinewidth = width;
1060
1061 words = info_transform_wordlist(input, keywords);
1062
1063 if (prefix) {
5dd44dce 1064 for (i = 0; i < indent; i++)
91f93b94 1065 info_rdadd(text, L' ');
5b1d0032 1066 e = info_rdaddwc(text, prefix, NULL, FALSE, cfg);
91f93b94 1067 if (prefixextra)
1068 e += info_rdadds(text, prefixextra);
5dd44dce 1069 /* If the prefix is too long, shorten the first line to fit. */
91f93b94 1070 e = extraindent - e;
5dd44dce 1071 if (e < 0) {
1072 firstlinewidth += e; /* this decreases it, since e < 0 */
1073 if (firstlinewidth < 0) {
1074 e = indent + extraindent;
1075 firstlinewidth = width;
91f93b94 1076 info_rdadd(text, L'\n');
5dd44dce 1077 } else
1078 e = 0;
1079 }
5dd44dce 1080 } else
1081 e = indent + extraindent;
1082
43341922 1083 wrapping = wrap_para(words, firstlinewidth, width, info_width_xrefs,
5b1d0032 1084 cfg, 0);
5dd44dce 1085 for (p = wrapping; p; p = p->next) {
1086 for (i = 0; i < e; i++)
91f93b94 1087 info_rdadd(text, L' ');
5b1d0032 1088 info_rdaddwc(text, p->begin, p->end, TRUE, cfg);
91f93b94 1089 info_rdadd(text, L'\n');
5dd44dce 1090 e = indent + extraindent;
1091 }
1092 wrap_free(wrapping);
91f93b94 1093 info_rdadd(text, L'\n');
5dd44dce 1094
1095 free_word_list(words);
1096}
1097
91f93b94 1098static void info_codepara(info_data *text, word *words,
5dd44dce 1099 int indent, int width) {
1100 int i;
1101
1102 for (; words; words = words->next) if (words->type == word_WeakCode) {
91f93b94 1103 for (i = 0; i < indent; i++)
1104 info_rdadd(text, L' ');
1105 if (info_rdadds(text, words->text) > width) {
5dd44dce 1106 /* FIXME: warn */
1107 }
91f93b94 1108 info_rdadd(text, L'\n');
5dd44dce 1109 }
1110
91f93b94 1111 info_rdadd(text, L'\n');
5dd44dce 1112}
1113
5b1d0032 1114static void info_versionid(info_data *text, word *words, infoconfig *cfg) {
1115 info_rdadd(text, L'[');
1116 info_rdaddwc(text, words, NULL, FALSE, cfg);
91f93b94 1117 info_rdadds(text, L"]\n");
5dd44dce 1118}
1119
91f93b94 1120static node *info_node_new(char *name, int charset)
5dd44dce 1121{
1122 node *n;
1123
f1530049 1124 n = snew(node);
91f93b94 1125 n->text = empty_info_data;
1126 n->text.charset = charset;
5dd44dce 1127 n->up = n->next = n->prev = n->lastchild = n->listnext = NULL;
1128 n->name = dupstr(name);
1129 n->started_menu = FALSE;
1130
1131 return n;
1132}
1133
f6220253 1134static char *info_node_name_core(info_data *id, filepos *fpos)
5dd44dce 1135{
f4551933 1136 char *p, *q;
91f93b94 1137
f4551933 1138 /*
f6220253 1139 * We cannot have commas, colons or parentheses in a node name.
1140 * Remove any that we find, with a warning.
f4551933 1141 */
f6220253 1142 p = q = id->output.text;
f4551933 1143 while (*p) {
f6220253 1144 if (*p == ':' || *p == ',' || *p == '(' || *p == ')') {
1145 error(err_infonodechar, fpos, *p);
f4551933 1146 } else {
1147 *q++ = *p;
1148 }
1149 p++;
1150 }
f6220253 1151 *q = '\0';
1152
1153 return id->output.text;
1154}
1155
1156static char *info_node_name_for_para(paragraph *par, infoconfig *cfg)
1157{
1158 info_data id = EMPTY_INFO_DATA;
1159
1160 id.charset = cfg->charset;
1161 info_rdaddwc(&id, par->kwtext ? par->kwtext : par->words,
1162 NULL, FALSE, cfg);
1163 info_rdaddsc(&id, NULL);
1164
1165 return info_node_name_core(&id, &par->fpos);
1166}
1167
1168static char *info_node_name_for_text(wchar_t *text, infoconfig *cfg)
1169{
1170 info_data id = EMPTY_INFO_DATA;
1171
1172 id.charset = cfg->charset;
1173 info_rdadds(&id, text);
1174 info_rdaddsc(&id, NULL);
f4551933 1175
f6220253 1176 return info_node_name_core(&id, NULL);
5dd44dce 1177}
1178
5b1d0032 1179static void info_menu_item(info_data *text, node *n, paragraph *p,
1180 infoconfig *cfg)
5dd44dce 1181{
1182 /*
1183 * FIXME: Depending on how we're doing node names in this info
1184 * file, we might want to do
1185 *
1186 * * Node name:: Chapter title
1187 *
1188 * _or_
1189 *
1190 * * Chapter number: Node name.
1191 *
91f93b94 1192 * This function mostly works in char rather than wchar_t,
1193 * because a menu item is a structural component.
5dd44dce 1194 */
91f93b94 1195 info_rdaddsc(text, "* ");
1196 info_rdaddsc(text, n->name);
1197 info_rdaddsc(text, "::");
5dd44dce 1198 if (p) {
91f93b94 1199 info_rdaddc(text, ' ');
5b1d0032 1200 info_rdaddwc(text, p->words, NULL, FALSE, cfg);
5dd44dce 1201 }
91f93b94 1202 info_rdaddc(text, '\n');
1203}
1204
1205/*
1206 * These functions implement my wrapper on the rdadd* calls which
1207 * allows me to switch arbitrarily between literal octet-string
1208 * text and charset-translated Unicode. (Because no matter what
1209 * character set I write the actual text in, I expect info readers
1210 * to treat node names and file names literally and to expect
1211 * keywords like `*Note' in their canonical form, so I have to take
1212 * steps to ensure that those structural elements of the file
1213 * aren't messed with.)
1214 */
1215static int info_rdadds(info_data *d, wchar_t const *wcs)
1216{
1217 if (!d->wcmode) {
1218 d->state = charset_init_state;
1219 d->wcmode = TRUE;
1220 }
1221
1222 if (wcs) {
1223 char buf[256];
e5cd393f 1224 int len, width, ret;
1225
1226 width = ustrwid(wcs, d->charset);
91f93b94 1227
e5cd393f 1228 len = ustrlen(wcs);
91f93b94 1229 while (len > 0) {
1230 int prevlen = len;
1231
1232 ret = charset_from_unicode(&wcs, &len, buf, lenof(buf),
1233 d->charset, &d->state, NULL);
1234
1235 assert(len < prevlen);
1236
1237 if (ret > 0) {
1238 buf[ret] = '\0';
1239 rdaddsc(&d->output, buf);
1240 }
1241 }
1242
e5cd393f 1243 return width;
91f93b94 1244 } else
1245 return 0;
1246}
1247
1248static int info_rdaddsc(info_data *d, char const *cs)
1249{
1250 if (d->wcmode) {
1251 char buf[256];
1252 int ret;
1253
1254 ret = charset_from_unicode(NULL, 0, buf, lenof(buf),
1255 d->charset, &d->state, NULL);
1256 if (ret > 0) {
1257 buf[ret] = '\0';
1258 rdaddsc(&d->output, buf);
1259 }
1260
1261 d->wcmode = FALSE;
1262 }
1263
1264 if (cs) {
1265 rdaddsc(&d->output, cs);
5b1d0032 1266 return strwid(cs, d->charset);
91f93b94 1267 } else
1268 return 0;
1269}
1270
1271static int info_rdadd(info_data *d, wchar_t wc)
1272{
1273 wchar_t wcs[2];
1274 wcs[0] = wc;
1275 wcs[1] = L'\0';
1276 return info_rdadds(d, wcs);
1277}
1278
1279static int info_rdaddc(info_data *d, char c)
1280{
1281 char cs[2];
1282 cs[0] = c;
1283 cs[1] = '\0';
1284 return info_rdaddsc(d, cs);
5dd44dce 1285}