paragraph *whlp_config_filename(char *filename)
{
- paragraph *p;
- wchar_t *ufilename, *up;
- int len;
-
- p = mknew(paragraph);
- memset(p, 0, sizeof(*p));
- p->type = para_Config;
- p->next = NULL;
- p->fpos.filename = "<command line>";
- p->fpos.line = p->fpos.col = -1;
-
- ufilename = ufroma_dup(filename);
- len = ustrlen(ufilename) + 2 + lenof(L"winhelp-filename");
- p->keyword = mknewa(wchar_t, len);
- up = p->keyword;
- ustrcpy(up, L"winhelp-filename");
- up = uadv(up);
- ustrcpy(up, ufilename);
- up = uadv(up);
- *up = L'\0';
- assert(up - p->keyword < len);
- sfree(ufilename);
-
- return p;
+ return cmdline_cfg_simple("winhelp-filename", filename, NULL);
}
void whlp_backend(paragraph *sourceform, keywordlist *keywords,
- indexdata *idx) {
+ indexdata *idx, void *unused) {
WHLP h;
char *filename, *cntname;
paragraph *p, *lastsect;
indexentry *ie;
int done_contents_topic = FALSE;
+ IGNORE(unused);
+
h = state.h = whlp_new();
state.keywords = keywords;
state.idx = idx;
p->parent->private_data = topicname;
} else if (!ustricmp(p->keyword, L"winhelp-filename")) {
sfree(filename);
- filename = utoa_dup(uadv(p->keyword));
+ filename = dupstr(adv(p->origkeyword));
}
}
}
filename = newf;
len = strlen(newf);
}
- cntname = mknewa(char, len);
+ cntname = mknewa(char, len+1);
sprintf(cntname, "%.*s.cnt", len-4, filename);
}
whlp_set_font(state->h, newfont);
}
if (removeattr(text->type) == word_Normal) {
- if (whlp_convert(text->text, 0, &c, TRUE))
+ if (whlp_convert(text->text, 0, &c, TRUE) || !text->alt)
whlp_text(state->h, c);
else
whlp_mkparagraph(state, deffont, text->alt, FALSE);
assert(text->type != word_CodeQuote &&
text->type != word_WkCodeQuote);
if (removeattr(text->type) == word_Normal) {
- if (whlp_convert(text->text, 0, &c, FALSE))
+ if (whlp_convert(text->text, 0, &c, FALSE) || !text->alt)
rdaddsc(rs, c);
else
whlp_rdaddwc(rs, text->alt);
*/
static int whlp_convert(wchar_t *s, int maxlen,
char **result, int hard_spaces) {
+ wchar_t *s2;
+ char *ret;
+ int ok;
+
/*
- * FIXME. Currently this is ISO8859-1 only.
+ * Enforce maxlen.
*/
- int doing = (result != 0);
- int ok = TRUE;
- char *p = NULL;
- int plen = 0, psize = 0;
-
- if (maxlen <= 0)
- maxlen = -1;
-
- for (; *s && maxlen != 0; s++, maxlen--) {
- wchar_t c = *s;
- char outc;
-
- if ((c >= 32 && c <= 126) ||
- (c >= 160 && c <= 255)) {
- /* Char is OK. */
- if (c == 32 && hard_spaces)
- outc = '\240';
- else
- outc = (char)c;
- } else {
- /* Char is not OK. */
- ok = FALSE;
- outc = 0xBF; /* approximate the good old DEC `uh?' */
- }
- if (doing) {
- if (plen >= psize) {
- psize = plen + 256;
- p = resize(p, psize);
- }
- p[plen++] = outc;
- }
- }
- if (doing) {
- p = resize(p, plen+1);
- p[plen] = '\0';
- *result = p;
+ if (maxlen > 0 && ustrlen(s) > maxlen) {
+ s2 = mknewa(wchar_t, maxlen+1);
+ memcpy(s2, s, maxlen * sizeof(wchar_t));
+ s2[maxlen] = L'\0';
+ s = s2;
+ } else
+ s2 = NULL;
+
+ /*
+ * We currently only support Win1252 in Windows Help files,
+ * because I don't know how to fiddle the character set
+ * designation in the |SYSTEM file to indicate anything else.
+ */
+
+ ret = utoa_careful_dup(s, CS_CP1252);
+ if (!ret) {
+ ok = FALSE;
+ ret = utoa_dup(s, CS_CP1252);
+ } else
+ ok = TRUE;
+
+ /*
+ * Enforce hard_spaces.
+ */
+ if (hard_spaces) {
+ char *p;
+
+ for (p = ret; *p; p++)
+ if (*p == ' ')
+ *p = '\240';
}
+
+ if (s2)
+ sfree(s2);
+
+ *result = ret;
+
return ok;
}