From e695cb0dd19d1cbce0c49a71a913527a227a9e09 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 6 Dec 2001 12:59:37 +0000 Subject: Allow the user to specify the Help topic ID string for particular sections. Useful if another program needs to jump to a particular topic. (Really we should support the proper CTXOMAP / HELP_WM_HELP system for doing this, but I don't like numeric IDs; you'd have to parse a bunch of #defines in order to sensibly synchronise the IDs between help file and code.) [originally from svn r1457] --- bk_whlp.c | 27 ++++++++++++++++++++++++++- buttress.h | 1 + error.c | 10 +++++++++- inputs/test.but | 6 +++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/bk_whlp.c b/bk_whlp.c index cf4757d..c5ebdb9 100644 --- a/bk_whlp.c +++ b/bk_whlp.c @@ -82,6 +82,23 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords, WHLP_FONT_STRIKEOUT, 0, 0, 0); /* + * Loop over the source form finding out whether the user has + * specified particular help topic names for anything. + */ + for (p = sourceform; p; p = p->next) { + p->private_data = NULL; + if (p->type == para_Config && p->parent) { + if (!ustricmp(p->keyword, L"winhelp-topic")) { + char *topicname; + whlp_convert(uadv(p->keyword), &topicname, 0); + /* Store the topic name in the private_data field of the + * containing section. */ + p->parent->private_data = topicname; + } + } + } + + /* * Loop over the source form registering WHLP_TOPICs for * everything. */ @@ -94,7 +111,15 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords, p->type == para_UnnumberedChapter || p->type == para_Heading || p->type == para_Subsect) { - p->private_data = whlp_register_topic(h, NULL, NULL); + char *topicid = p->private_data; + char *errstr; + + p->private_data = whlp_register_topic(h, topicid, &errstr); + if (!p->private_data) { + p->private_data = whlp_register_topic(h, NULL, NULL); + error(err_winhelp_ctxclash, &p->fpos, topicid, errstr); + } + sfree(topicid); } } diff --git a/buttress.h b/buttress.h index 0fd69a9..19e6cf8 100644 --- a/buttress.h +++ b/buttress.h @@ -205,6 +205,7 @@ enum { err_cantopenw, /* can't open output file for write */ err_macroexists, /* this macro already exists */ err_sectjump, /* jump a heading level, eg \C -> \S */ + err_winhelp_ctxclash, /* WinHelp context ID hash clash */ err_whatever /* random error of another type */ }; diff --git a/error.c b/error.c index c81aa8c..d115073 100644 --- a/error.c +++ b/error.c @@ -16,7 +16,7 @@ static void do_error(int code, va_list ap) { char error[1024]; char auxbuf[256]; - char *sp; + char *sp, *sp2; wchar_t *wsp; filepos fpos; int flags; @@ -167,6 +167,14 @@ static void do_error(int code, va_list ap) { sprintf(error, "expected higher heading levels before this one"); flags = FILEPOS; break; + case err_winhelp_ctxclash: + fpos = *va_arg(ap, filepos *); + sp = va_arg(ap, char *); + sp2 = va_arg(ap, char *); + sprintf(error, "Windows Help context id `%.200s' clashes with " + "previously defined `%.200s'", sp, sp2); + flags = FILEPOS; + break; case err_whatever: sp = va_arg(ap, char *); vsprintf(error, sp, ap); diff --git a/inputs/test.but b/inputs/test.but index d342a8e..9b79903 100644 --- a/inputs/test.but +++ b/inputs/test.but @@ -19,7 +19,7 @@ a bit] \define{coopt} co\u00F6{-o}pt -\versionid $Id: test.but,v 1.15 2001/12/04 19:12:18 simon Exp $ +\versionid $Id: test.but,v 1.16 2001/12/06 12:59:37 simon Exp $ \C{ch\\ap} First chapter title; for similar wrapping reasons this chapter title will be ludicrously long. I wonder how much more @@ -37,6 +37,8 @@ fragments}. guessing the reason why this time, and here's yet more text to pad it out to three lines of output) +\cfg{winhelp-topic}{M359HPEHGW} + Here's a code paragraph: \c No leading spaces @@ -100,6 +102,8 @@ and here's a reference to it: \k{sub-sub}. \A{app} Needless appendix +\# \cfg{winhelp-topic}{Y5VQEXZQVJ} (uncomment this and it clashes) + Here's an \i{appendix}, for no terribly good reason at all. See \k{book}. -- cgit v1.1