2 * Windows Help backend for Halibut
13 struct bk_whlp_state
{
16 keywordlist
*keywords
;
17 WHLP_TOPIC curr_topic
;
21 int cnt_last_level
, cnt_workaround
;
26 wchar_t *bullet
, *lquote
, *rquote
, *titlepage
, *sectsuffix
, *listsuffix
;
31 * Indexes of fonts in our standard font descriptor set.
45 static void whlp_rdaddwc(rdstringc
*rs
, word
*text
, whlpconf
*conf
,
46 charset_state
*state
);
47 static void whlp_rdadds(rdstringc
*rs
, const wchar_t *text
, whlpconf
*conf
,
48 charset_state
*state
);
49 static void whlp_mkparagraph(struct bk_whlp_state
*state
,
50 int font
, word
*text
, int subsidiary
,
52 static void whlp_navmenu(struct bk_whlp_state
*state
, paragraph
*p
,
54 static void whlp_contents_write(struct bk_whlp_state
*state
,
55 int level
, char *text
, WHLP_TOPIC topic
);
56 static void whlp_wtext(struct bk_whlp_state
*state
, const wchar_t *text
);
58 paragraph
*whlp_config_filename(char *filename
)
60 return cmdline_cfg_simple("winhelp-filename", filename
, NULL
);
63 static whlpconf
whlp_configure(paragraph
*source
) {
70 ret
.charset
= CS_CP1252
;
71 ret
.bullet
= L
"\x2022\0-\0\0";
72 ret
.lquote
= L
"\x2018\0\x2019\0\"\0\"\0\0";
73 ret
.rquote
= uadv(ret
.lquote
);
74 ret
.filename
= dupstr("output.hlp");
75 ret
.titlepage
= L
"Title page";
76 ret
.sectsuffix
= L
": ";
77 ret
.listsuffix
= L
".";
80 * Two-pass configuration so that we can pick up global config
81 * (e.g. `quotes') before having it overridden by specific
82 * config (`win-quotes'), irrespective of the order in which
85 for (p
= source
; p
; p
= p
->next
) {
86 if (p
->type
== para_Config
) {
87 if (!ustricmp(p
->keyword
, L
"quotes")) {
88 if (*uadv(p
->keyword
) && *uadv(uadv(p
->keyword
))) {
89 ret
.lquote
= uadv(p
->keyword
);
90 ret
.rquote
= uadv(ret
.lquote
);
96 for (p
= source
; p
; p
= p
->next
) {
97 p
->private_data
= NULL
;
98 if (p
->type
== para_Config
) {
100 * In principle we should support a `winhelp-charset'
101 * here. We don't, because my WinHelp output code
102 * doesn't know how to change character set. Once I
103 * find out, I'll support it.
105 if (p
->parent
&& !ustricmp(p
->keyword
, L
"winhelp-topic")) {
106 /* Store the topic name in the private_data field of the
107 * containing section. */
108 p
->parent
->private_data
= uadv(p
->keyword
);
109 } else if (!ustricmp(p
->keyword
, L
"winhelp-filename")) {
111 ret
.filename
= dupstr(adv(p
->origkeyword
));
112 } else if (!ustricmp(p
->keyword
, L
"winhelp-bullet")) {
113 ret
.bullet
= uadv(p
->keyword
);
114 } else if (!ustricmp(p
->keyword
, L
"winhelp-section-suffix")) {
115 ret
.sectsuffix
= uadv(p
->keyword
);
116 } else if (!ustricmp(p
->keyword
, L
"winhelp-list-suffix")) {
117 ret
.listsuffix
= uadv(p
->keyword
);
118 } else if (!ustricmp(p
->keyword
, L
"winhelp-contents-titlepage")) {
119 ret
.titlepage
= uadv(p
->keyword
);
120 } else if (!ustricmp(p
->keyword
, L
"winhelp-quotes")) {
121 if (*uadv(p
->keyword
) && *uadv(uadv(p
->keyword
))) {
122 ret
.lquote
= uadv(p
->keyword
);
123 ret
.rquote
= uadv(ret
.lquote
);
130 * Now process fallbacks on quote characters and bullets.
132 while (*uadv(ret
.rquote
) && *uadv(uadv(ret
.rquote
)) &&
133 (!cvt_ok(ret
.charset
, ret
.lquote
) ||
134 !cvt_ok(ret
.charset
, ret
.rquote
))) {
135 ret
.lquote
= uadv(ret
.rquote
);
136 ret
.rquote
= uadv(ret
.lquote
);
139 while (*ret
.bullet
&& *uadv(ret
.bullet
) &&
140 !cvt_ok(ret
.charset
, ret
.bullet
))
141 ret
.bullet
= uadv(ret
.bullet
);
146 void whlp_backend(paragraph
*sourceform
, keywordlist
*keywords
,
147 indexdata
*idx
, void *unused
) {
150 paragraph
*p
, *lastsect
;
151 struct bk_whlp_state state
;
152 WHLP_TOPIC contents_topic
;
156 int done_contents_topic
= FALSE
;
161 h
= state
.h
= whlp_new();
162 state
.keywords
= keywords
;
165 whlp_start_macro(h
, "CB(\"btn_about\",\"&About\",\"About()\")");
166 whlp_start_macro(h
, "CB(\"btn_up\",\"&Up\",\"Contents()\")");
167 whlp_start_macro(h
, "BrowseButtons()");
169 whlp_create_font(h
, "Times New Roman", WHLP_FONTFAM_SERIF
, 24,
171 whlp_create_font(h
, "Times New Roman", WHLP_FONTFAM_SERIF
, 24,
172 WHLP_FONT_ITALIC
, 0, 0, 0);
173 whlp_create_font(h
, "Courier New", WHLP_FONTFAM_FIXED
, 24,
175 whlp_create_font(h
, "Courier New", WHLP_FONTFAM_FIXED
, 24,
176 WHLP_FONT_ITALIC
, 0, 0, 0);
177 whlp_create_font(h
, "Courier New", WHLP_FONTFAM_FIXED
, 24,
178 WHLP_FONT_BOLD
, 0, 0, 0);
179 whlp_create_font(h
, "Arial", WHLP_FONTFAM_SERIF
, 30,
180 WHLP_FONT_BOLD
, 0, 0, 0);
181 whlp_create_font(h
, "Arial", WHLP_FONTFAM_SERIF
, 30,
182 WHLP_FONT_BOLD
|WHLP_FONT_ITALIC
, 0, 0, 0);
183 whlp_create_font(h
, "Courier New", WHLP_FONTFAM_FIXED
, 30,
184 WHLP_FONT_BOLD
, 0, 0, 0);
185 whlp_create_font(h
, "Courier New", WHLP_FONTFAM_SANS
, 18,
186 WHLP_FONT_STRIKEOUT
, 0, 0, 0);
188 conf
= whlp_configure(sourceform
);
190 state
.charset
= conf
.charset
;
193 * Ensure the output file name has a .hlp extension. This is
194 * required since we must create the .cnt file in parallel with
198 int len
= strlen(conf
.filename
);
199 if (len
< 4 || conf
.filename
[len
-4] != '.' ||
200 tolower(conf
.filename
[len
-3] != 'h') ||
201 tolower(conf
.filename
[len
-2] != 'l') ||
202 tolower(conf
.filename
[len
-1] != 'p')) {
204 newf
= snewn(len
+ 5, char);
205 sprintf(newf
, "%s.hlp", conf
.filename
);
206 sfree(conf
.filename
);
207 conf
.filename
= newf
;
210 cntname
= snewn(len
+1, char);
211 sprintf(cntname
, "%.*s.cnt", len
-4, conf
.filename
);
214 state
.cntfp
= fopen(cntname
, "wb");
215 state
.cnt_last_level
= -1; state
.cnt_workaround
= 0;
218 * Loop over the source form registering WHLP_TOPICs for
222 contents_topic
= whlp_register_topic(h
, "Top", NULL
);
223 whlp_primary_topic(h
, contents_topic
);
224 for (p
= sourceform
; p
; p
= p
->next
) {
225 if (p
->type
== para_Chapter
||
226 p
->type
== para_Appendix
||
227 p
->type
== para_UnnumberedChapter
||
228 p
->type
== para_Heading
||
229 p
->type
== para_Subsect
) {
231 rdstringc rs
= { 0, 0, NULL
};
234 whlp_rdadds(&rs
, (wchar_t *)p
->private_data
, &conf
, NULL
);
236 p
->private_data
= whlp_register_topic(h
, rs
.text
, &errstr
);
237 if (!p
->private_data
) {
238 p
->private_data
= whlp_register_topic(h
, NULL
, NULL
);
239 error(err_winhelp_ctxclash
, &p
->fpos
, rs
.text
, errstr
);
246 * Loop over the index entries, preparing final text forms for
250 indexentry
*ie_prev
= NULL
;
253 for (i
= 0; (ie
= index234(idx
->entries
, i
)) != NULL
; i
++) {
254 rdstringc rs
= {0, 0, NULL
};
255 charset_state state
= CHARSET_INIT_STATE
;
256 whlp_rdaddwc(&rs
, ie
->text
, &conf
, &state
);
260 * It appears that Windows Help's index mechanism
261 * is inherently case-insensitive. Therefore, if two
262 * adjacent index terms compare equal apart from
263 * case, I'm going to append nonbreaking spaces to
264 * the end of the second one so that Windows will
265 * treat them as distinct.
267 * This is nasty because we're depending on our
268 * case-insensitive comparison having the same
269 * semantics as the Windows one :-/ but I see no
274 a
= ufroma_dup((char *)ie_prev
->backend_data
, conf
.charset
);
275 b
= ufroma_dup(rs
.text
, conf
.charset
);
276 if (!ustricmp(a
, b
)) {
278 for (j
= 0; j
< nspaces
; j
++)
279 whlp_rdadds(&rs
, L
"\xA0", &conf
, &state
);
281 * Add one to nspaces, so that if another term
282 * appears which is equivalent to the previous
283 * two it'll acquire one more space.
292 whlp_rdadds(&rs
, NULL
, &conf
, &state
);
294 ie
->backend_data
= rs
.text
;
297 * Only move ie_prev on if nspaces==1 (since when we
298 * have three or more adjacent terms differing only in
299 * case, we will want to compare with the _first_ of
300 * them because that won't have had any extra spaces
301 * added on which will foul up the comparison).
310 /* ------------------------------------------------------------------
311 * Begin the contents page.
314 whlp_begin_topic(h
, contents_topic
, "Contents", "DB(\"btn_up\")", NULL
);
315 state
.curr_topic
= contents_topic
;
318 * The manual title goes in the non-scroll region, and also
319 * goes into the system title slot.
322 rdstringc rs
= {0, 0, NULL
};
323 for (p
= sourceform
; p
; p
= p
->next
) {
324 if (p
->type
== para_Title
) {
325 whlp_begin_para(h
, WHLP_PARA_NONSCROLL
);
326 state
.cstate
= charset_init_state
;
327 whlp_mkparagraph(&state
, FONT_TITLE
, p
->words
, FALSE
, &conf
);
328 whlp_wtext(&state
, NULL
);
330 whlp_rdaddwc(&rs
, p
->words
, &conf
, NULL
);
334 whlp_title(h
, rs
.text
);
335 fprintf(state
.cntfp
, ":Title %s\r\n", rs
.text
);
339 rdstringc rs2
= {0,0,NULL
};
340 whlp_rdadds(&rs2
, conf
.titlepage
, &conf
, NULL
);
341 whlp_contents_write(&state
, 1, rs2
.text
, contents_topic
);
347 * Put the copyright into the system section.
350 rdstringc rs
= {0, 0, NULL
};
351 for (p
= sourceform
; p
; p
= p
->next
) {
352 if (p
->type
== para_Copyright
)
353 whlp_rdaddwc(&rs
, p
->words
, &conf
, NULL
);
356 whlp_copyright(h
, rs
.text
);
363 /* ------------------------------------------------------------------
364 * Now we've done the contents page, we're ready to go through
365 * and do the main manual text. Ooh.
368 for (p
= sourceform
; p
; p
= p
->next
) switch (p
->type
) {
370 * Things we ignore because we've already processed them or
371 * aren't going to touch them in this pass.
375 case para_Biblio
: /* only touch BiblioCited */
392 * Chapter and section titles: start a new Help topic.
396 case para_UnnumberedChapter
:
400 if (!done_contents_topic
) {
404 * If this is the first section title we've seen, then
405 * we're currently still in the contents topic. We
406 * should therefore finish up the contents page by
407 * writing a nav menu.
409 for (p
= sourceform
; p
; p
= p
->next
) {
410 if (p
->type
== para_Chapter
||
411 p
->type
== para_Appendix
||
412 p
->type
== para_UnnumberedChapter
)
413 whlp_navmenu(&state
, p
, &conf
);
416 done_contents_topic
= TRUE
;
419 if (lastsect
&& lastsect
->child
) {
422 * Do a navigation menu for the previous section we
425 for (q
= lastsect
->child
; q
; q
= q
->sibling
)
426 whlp_navmenu(&state
, q
, &conf
);
429 rdstringc rs
= {0, 0, NULL
};
430 WHLP_TOPIC new_topic
, parent_topic
;
431 char *macro
, *topicid
;
432 charset_state cstate
= CHARSET_INIT_STATE
;
434 new_topic
= p
->private_data
;
435 whlp_browse_link(h
, state
.curr_topic
, new_topic
);
436 state
.curr_topic
= new_topic
;
439 whlp_rdaddwc(&rs
, p
->kwtext
, &conf
, &cstate
);
440 whlp_rdadds(&rs
, conf
.sectsuffix
, &conf
, &cstate
);
442 whlp_rdaddwc(&rs
, p
->words
, &conf
, &cstate
);
443 whlp_rdadds(&rs
, NULL
, &conf
, &cstate
);
445 if (p
->parent
== NULL
)
446 parent_topic
= contents_topic
;
448 parent_topic
= (WHLP_TOPIC
)p
->parent
->private_data
;
449 topicid
= whlp_topic_id(parent_topic
);
450 macro
= smalloc(100+strlen(topicid
));
452 "CBB(\"btn_up\",\"JI(`',`%s')\");EB(\"btn_up\")",
454 whlp_begin_topic(h
, new_topic
,
455 rs
.text ? rs
.text
: "",
461 * Output the .cnt entry.
463 * WinHelp has a bug involving having an internal
464 * node followed by a leaf at the same level: the
465 * leaf is output at the wrong level. We can mostly
466 * work around this by modifying the leaf level
467 * itself (see whlp_contents_write), but this
468 * doesn't work for top-level sections since we
469 * can't turn a level-1 leaf into a level-0 one. So
470 * for top-level leaf sections (Bibliography
471 * springs to mind), we output an internal node
472 * containing only the leaf for that section.
477 /* Count up the level. */
479 for (q
= p
; q
->parent
; q
= q
->parent
) i
++;
481 if (p
->child
|| !p
->parent
) {
483 * If p has children then it needs to be a
484 * folder; if it has no parent then it needs to
485 * be a folder to work around the bug.
487 whlp_contents_write(&state
, i
, rs
.text
, NULL
);
490 whlp_contents_write(&state
, i
, rs
.text
, new_topic
);
495 whlp_begin_para(h
, WHLP_PARA_NONSCROLL
);
496 state
.cstate
= charset_init_state
;
498 whlp_mkparagraph(&state
, FONT_TITLE
, p
->kwtext
, FALSE
, &conf
);
499 whlp_set_font(h
, FONT_TITLE
);
500 whlp_wtext(&state
, conf
.sectsuffix
);
502 whlp_mkparagraph(&state
, FONT_TITLE
, p
->words
, FALSE
, &conf
);
503 whlp_wtext(&state
, NULL
);
511 whlp_para_attr(h
, WHLP_PARA_SPACEBELOW
, 12);
512 whlp_para_attr(h
, WHLP_PARA_ALIGNMENT
, WHLP_ALIGN_CENTRE
);
513 whlp_begin_para(h
, WHLP_PARA_SCROLL
);
514 whlp_set_font(h
, FONT_RULE
);
515 state
.cstate
= charset_init_state
;
516 #define TEN L"\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0"
517 #define TWENTY TEN TEN
518 #define FORTY TWENTY TWENTY
519 #define EIGHTY FORTY FORTY
520 state
.cstate
= charset_init_state
;
521 whlp_wtext(&state
, EIGHTY
);
522 whlp_wtext(&state
, NULL
);
532 case para_DescribedThing
:
533 case para_Description
:
534 case para_BiblioCited
:
536 case para_NumberedList
:
537 whlp_para_attr(h
, WHLP_PARA_SPACEBELOW
, 12);
538 if (p
->type
== para_Bullet
|| p
->type
== para_NumberedList
) {
539 whlp_para_attr(h
, WHLP_PARA_LEFTINDENT
, 72*nesting
+ 72);
540 whlp_para_attr(h
, WHLP_PARA_FIRSTLINEINDENT
, -36);
541 whlp_set_tabstop(h
, 72, WHLP_ALIGN_LEFT
);
542 whlp_begin_para(h
, WHLP_PARA_SCROLL
);
543 whlp_set_font(h
, FONT_NORMAL
);
544 state
.cstate
= charset_init_state
;
545 if (p
->type
== para_Bullet
) {
546 whlp_wtext(&state
, conf
.bullet
);
548 whlp_mkparagraph(&state
, FONT_NORMAL
, p
->kwtext
, FALSE
, &conf
);
549 whlp_wtext(&state
, conf
.listsuffix
);
551 whlp_wtext(&state
, NULL
);
554 whlp_para_attr(h
, WHLP_PARA_LEFTINDENT
,
555 72*nesting
+ (p
->type
==para_Description ?
72 : 0));
556 whlp_begin_para(h
, WHLP_PARA_SCROLL
);
559 state
.cstate
= charset_init_state
;
561 if (p
->type
== para_BiblioCited
) {
562 whlp_mkparagraph(&state
, FONT_NORMAL
, p
->kwtext
, FALSE
, &conf
);
563 whlp_wtext(&state
, L
" ");
566 whlp_mkparagraph(&state
, FONT_NORMAL
, p
->words
, FALSE
, &conf
);
567 whlp_wtext(&state
, NULL
);
573 * In a code paragraph, each individual word is a line. For
574 * Help files, we will have to output this as a set of
575 * paragraphs, all but the last of which don't set
580 wchar_t *t
, *e
, *tmp
;
582 for (w
= p
->words
; w
; w
= w
->next
) if (w
->type
== word_WeakCode
) {
584 if (w
->next
&& w
->next
->type
== word_Emph
) {
591 whlp_para_attr(h
, WHLP_PARA_SPACEBELOW
, 12);
593 whlp_para_attr(h
, WHLP_PARA_LEFTINDENT
, 72*nesting
);
594 whlp_begin_para(h
, WHLP_PARA_SCROLL
);
595 state
.cstate
= charset_init_state
;
596 while (e
&& *e
&& *t
) {
600 for (n
= 0; t
[n
] && e
[n
] && e
[n
] == ec
; n
++);
602 whlp_set_font(h
, FONT_ITAL_CODE
);
604 whlp_set_font(h
, FONT_BOLD_CODE
);
606 whlp_set_font(h
, FONT_CODE
);
607 tmp
= snewn(n
+1, wchar_t);
610 whlp_wtext(&state
, tmp
);
611 whlp_wtext(&state
, NULL
);
612 state
.cstate
= charset_init_state
;
617 whlp_set_font(h
, FONT_CODE
);
618 whlp_wtext(&state
, t
);
619 whlp_wtext(&state
, NULL
);
627 whlp_close(h
, conf
.filename
);
630 * Loop over the index entries, cleaning up our final text
633 for (i
= 0; (ie
= index234(idx
->entries
, i
)) != NULL
; i
++) {
634 sfree(ie
->backend_data
);
637 sfree(conf
.filename
);
641 static void whlp_contents_write(struct bk_whlp_state
*state
,
642 int level
, char *text
, WHLP_TOPIC topic
) {
644 * Horrifying bug in WinHelp. When dropping a section level or
645 * more without using a folder-type entry, WinHelp accidentally
646 * adds one to the section level. So we correct for that here.
648 if (state
->cnt_last_level
> level
&& topic
)
649 state
->cnt_workaround
= -1;
651 state
->cnt_workaround
= 0;
652 state
->cnt_last_level
= level
;
654 fprintf(state
->cntfp
, "%d ", level
+ state
->cnt_workaround
);
657 fputc('\\', state
->cntfp
);
658 fputc(*text
, state
->cntfp
);
662 fprintf(state
->cntfp
, "=%s", whlp_topic_id(topic
));
663 fputc('\n', state
->cntfp
);
666 static void whlp_navmenu(struct bk_whlp_state
*state
, paragraph
*p
,
668 whlp_begin_para(state
->h
, WHLP_PARA_SCROLL
);
669 whlp_start_hyperlink(state
->h
, (WHLP_TOPIC
)p
->private_data
);
670 state
->cstate
= charset_init_state
;
672 whlp_mkparagraph(state
, FONT_NORMAL
, p
->kwtext
, TRUE
, conf
);
673 whlp_set_font(state
->h
, FONT_NORMAL
);
674 whlp_wtext(state
, conf
->sectsuffix
);
676 whlp_mkparagraph(state
, FONT_NORMAL
, p
->words
, TRUE
, conf
);
677 whlp_wtext(state
, NULL
);
678 whlp_end_hyperlink(state
->h
);
679 whlp_end_para(state
->h
);
683 static void whlp_mkparagraph(struct bk_whlp_state
*state
,
684 int font
, word
*text
, int subsidiary
,
690 paragraph
*xref_target
= NULL
;
692 for (; text
; text
= text
->next
) switch (text
->type
) {
698 if (subsidiary
) break; /* disabled in subsidiary bits */
700 indextag
*tag
= index_findtag(state
->idx
, text
->text
);
704 for (i
= 0; i
< tag
->nrefs
; i
++)
705 whlp_index_term(state
->h
, tag
->refs
[i
]->backend_data
,
712 if (subsidiary
) break; /* disabled in subsidiary bits */
713 kwl
= kw_lookup(state
->keywords
, text
->text
);
714 assert(xref_target
== NULL
);
716 if (kwl
->para
->type
== para_NumberedList
) {
717 break; /* don't xref to numbered list items */
718 } else if (kwl
->para
->type
== para_BiblioCited
) {
720 * An xref to a bibliography item jumps to the section
723 if (kwl
->para
->parent
)
724 xref_target
= kwl
->para
->parent
;
728 xref_target
= kwl
->para
;
730 whlp_start_hyperlink(state
->h
,
731 (WHLP_TOPIC
)xref_target
->private_data
);
736 if (subsidiary
) break; /* disabled in subsidiary bits */
738 whlp_end_hyperlink(state
->h
);
746 case word_WhiteSpace
:
749 case word_WkCodeSpace
:
753 case word_WkCodeQuote
:
754 if (towordstyle(text
->type
) == word_Emph
)
755 newfont
= deffont
+ FONT_EMPH
;
756 else if (towordstyle(text
->type
) == word_Code
||
757 towordstyle(text
->type
) == word_WeakCode
)
758 newfont
= deffont
+ FONT_CODE
;
761 if (newfont
!= currfont
) {
763 whlp_set_font(state
->h
, newfont
);
765 if (removeattr(text
->type
) == word_Normal
) {
766 if (cvt_ok(conf
->charset
, text
->text
) || !text
->alt
)
767 whlp_wtext(state
, text
->text
);
769 whlp_mkparagraph(state
, deffont
, text
->alt
, FALSE
, conf
);
770 } else if (removeattr(text
->type
) == word_WhiteSpace
) {
771 whlp_wtext(state
, L
" ");
772 } else if (removeattr(text
->type
) == word_Quote
) {
774 quoteaux(text
->aux
) == quote_Open ?
775 conf
->lquote
: conf
->rquote
);
781 static void whlp_rdaddwc(rdstringc
*rs
, word
*text
, whlpconf
*conf
,
782 charset_state
*state
) {
783 charset_state ourstate
= CHARSET_INIT_STATE
;
788 for (; text
; text
= text
->next
) switch (text
->type
) {
801 case word_WhiteSpace
:
804 case word_WkCodeSpace
:
808 case word_WkCodeQuote
:
809 assert(text
->type
!= word_CodeQuote
&&
810 text
->type
!= word_WkCodeQuote
);
811 if (removeattr(text
->type
) == word_Normal
) {
812 if (cvt_ok(conf
->charset
, text
->text
) || !text
->alt
)
813 whlp_rdadds(rs
, text
->text
, conf
, state
);
815 whlp_rdaddwc(rs
, text
->alt
, conf
, state
);
816 } else if (removeattr(text
->type
) == word_WhiteSpace
) {
817 whlp_rdadds(rs
, L
" ", conf
, state
);
818 } else if (removeattr(text
->type
) == word_Quote
) {
819 whlp_rdadds(rs
, quoteaux(text
->aux
) == quote_Open ?
820 conf
->lquote
: conf
->rquote
, conf
, state
);
825 if (state
== &ourstate
)
826 whlp_rdadds(rs
, NULL
, conf
, state
);
829 static void whlp_rdadds(rdstringc
*rs
, const wchar_t *text
, whlpconf
*conf
,
830 charset_state
*state
)
832 charset_state ourstate
= CHARSET_INIT_STATE
;
833 int textlen
= text ?
ustrlen(text
) : 0;
840 while (textlen
> 0 &&
841 (ret
= charset_from_unicode(&text
, &textlen
, outbuf
,
843 conf
->charset
, state
, NULL
)) > 0) {
848 if (text
== NULL
|| state
== &ourstate
) {
849 if ((ret
= charset_from_unicode(NULL
, 0, outbuf
, lenof(outbuf
)-1,
850 conf
->charset
, state
, NULL
)) > 0) {
857 static void whlp_wtext(struct bk_whlp_state
*state
, const wchar_t *text
)
859 int textlen
= text ?
ustrlen(text
) : 0;
863 while (textlen
> 0 &&
864 (ret
= charset_from_unicode(&text
, &textlen
, outbuf
,
866 state
->charset
, &state
->cstate
,
869 whlp_text(state
->h
, outbuf
);
873 if ((ret
= charset_from_unicode(NULL
, 0, outbuf
, lenof(outbuf
)-1,
874 state
->charset
, &state
->cstate
,
877 whlp_text(state
->h
, outbuf
);