CHM documentation generates using Halibut. Thanks Nike!

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3090 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2003-11-03 09:10:19 +00:00
parent 43bd7d565f
commit 2cb320edb5
24 changed files with 268 additions and 57 deletions

View file

@ -76,6 +76,8 @@ typedef struct {
wchar_t *author, *description;
wchar_t *head_end, *body, *body_start, *body_end, *address_start,
*address_end, *nav_attrs;
wchar_t *rlink_prefix, *rlink_suffix;
wchar_t *chm_toc_file, *chm_ind_file;
int suppress_address;
xhtmlheadfmt fchapter, *fsect;
int nfsect;
@ -101,6 +103,8 @@ static void xhtml_para(FILE *, word *);
static void xhtml_codepara(FILE *, word *);
static void xhtml_heading(FILE *, paragraph *);
static void chm_doheader(FILE *, word *);
static void chm_dofooter(FILE *);
/* File-global variables are much easier than passing these things
* all over the place. Evil, but easier. We can replace this with a single
* structure at some point.
@ -115,6 +119,9 @@ static xhtmlfile *lastfile;
static xhtmlfile *xhtml_last_file = NULL;
static int last_level = -1;
static xhtmlsection *currentsection;
static FILE* chm_toc = NULL;
static FILE* chm_ind = NULL;
static xhtmlconfig xhtml_configure(paragraph * source)
{
@ -143,7 +150,10 @@ static xhtmlconfig xhtml_configure(paragraph * source)
ret.address_end = NULL;
ret.nav_attrs = NULL;
ret.suppress_address = FALSE;
ret.chm_toc_file = NULL;
ret.chm_ind_file = NULL;
chm_toc = NULL;
chm_ind = NULL;
ret.fchapter.just_numbers = FALSE;
ret.fchapter.number_suffix = ustrdup(L": ");
ret.nfsect = 2;
@ -152,6 +162,8 @@ static xhtmlconfig xhtml_configure(paragraph * source)
ret.fsect[0].number_suffix = ustrdup(L": ");
ret.fsect[1].just_numbers = TRUE;
ret.fsect[1].number_suffix = ustrdup(L" ");
ret.rlink_prefix = NULL;
ret.rlink_suffix = NULL;
for (; source; source = source->next)
{
@ -195,6 +207,12 @@ static xhtmlconfig xhtml_configure(paragraph * source)
} else if (!ustricmp(source->keyword, L"xhtml-author"))
{
ret.author = uadv(source->keyword);
} else if (!ustricmp(source->keyword, L"chm-toc-file"))
{
ret.chm_toc_file = uadv(source->keyword);
} else if (!ustricmp(source->keyword, L"chm-ind-file"))
{
ret.chm_ind_file = uadv(source->keyword);
} else if (!ustricmp(source->keyword, L"xhtml-description"))
{
ret.description = uadv(source->keyword);
@ -226,6 +244,12 @@ static xhtmlconfig xhtml_configure(paragraph * source)
} else if (!ustricmp(source->keyword, L"xhtml-chapter-suffix"))
{
ret.fchapter.number_suffix = ustrdup(uadv(source->keyword));
} else if (!ustricmp(source->keyword, L"xhtml-rlink-prefix"))
{
ret.rlink_prefix = uadv(source->keyword);
} else if (!ustricmp(source->keyword, L"xhtml-rlink-suffix"))
{
ret.rlink_suffix = uadv(source->keyword);
} else if (!ustricmp(source->keyword, L"xhtml-section-numeric"))
{
wchar_t *p = uadv(source->keyword);
@ -646,11 +670,8 @@ static void xhtml_do_file(xhtmlfile * file);
static void xhtml_do_top_file(xhtmlfile * file, paragraph * sourceform);
static void xhtml_do_paras(FILE * fp, paragraph * p);
static int xhtml_do_contents_limit(FILE * fp, xhtmlfile * file, int limit);
static int xhtml_do_contents_section_limit(FILE * fp,
xhtmlsection * section,
int limit);
static int xhtml_add_contents_entry(FILE * fp, xhtmlsection * section,
int limit);
static int xhtml_do_contents_section_limit(FILE * fp, xhtmlsection * section, int limit);
static int xhtml_add_contents_entry(FILE * fp, xhtmlsection * section, int limit);
static int xhtml_do_contents(FILE * fp, xhtmlfile * file);
static int xhtml_do_naked_contents(FILE * fp, xhtmlfile * file);
static void xhtml_do_sections(FILE * fp, xhtmlsection * sections);
@ -945,17 +966,39 @@ static void xhtml_do_file(xhtmlfile * file)
static void xhtml_do_top_file(xhtmlfile * file, paragraph * sourceform)
{
paragraph *p;
char fname[_MAX_PATH];
int done = FALSE;
FILE *fp = fopen(file->filename, "w");
ustrtoa(conf.chm_toc_file, fname, _MAX_PATH);
if(*fname)
{
chm_toc = fopen(fname, "w");
if (chm_toc == NULL)
fatal(err_cantopenw, fname);
}
else
chm_toc = NULL;
ustrtoa(conf.chm_ind_file, fname, _MAX_PATH);
if(*fname){
chm_ind = fopen(fname, "w");
if (chm_ind == NULL)
fatal(err_cantopenw, fname);
}
else
chm_ind = NULL;
if (fp == NULL)
fatal(err_cantopenw, file->filename);
/* Do the title -- only one allowed */
for (p = sourceform; p && !done; p = p->next)
{
if (p->type == para_Title)
{
xhtml_doheader(fp, p->words);
if(chm_toc)chm_doheader(chm_toc, p->words);
if(chm_ind)chm_doheader(chm_ind, p->words);
done = TRUE;
}
}
@ -1008,7 +1051,11 @@ static void xhtml_do_top_file(xhtmlfile * file, paragraph * sourceform)
}
xhtml_dofooter(fp);
if(chm_toc)chm_dofooter(chm_toc);
if(chm_ind)chm_dofooter(chm_ind);
fclose(fp);
if(chm_toc)fclose(chm_toc);
if(chm_ind)fclose(chm_ind);
}
/* Convert a Unicode string to an ASCII one. '?' is
@ -1053,6 +1100,7 @@ static int xhtml_do_contents(FILE * fp, xhtmlfile * file)
{
last_level--;
fprintf(fp, "</ul>\n");
if(chm_toc)fprintf(chm_toc, "</ul>\n");
}
}
return count;
@ -1077,6 +1125,7 @@ static int xhtml_do_naked_contents(FILE * fp, xhtmlfile * file)
{
last_level--;
fprintf(fp, "</ul>\n");
if(chm_toc)fprintf(chm_toc, "</ul>\n");
}
}
return count;
@ -1125,8 +1174,7 @@ xhtml_do_contents_section_deep_limit(FILE * fp, xhtmlsection * section,
* limit contents depth.
*/
static int
xhtml_do_contents_section_limit(FILE * fp, xhtmlsection * section,
int limit)
xhtml_do_contents_section_limit(FILE * fp, xhtmlsection * section, int limit)
{
int count = 0;
if (!section)
@ -1156,19 +1204,26 @@ xhtml_add_contents_entry(FILE * fp, xhtmlsection * section, int limit)
{
last_level--;
fprintf(fp, "</ul>\n");
if(chm_toc)fprintf(chm_toc, "</ul>\n");
}
while (last_level < section->level)
{
last_level++;
fprintf(fp, "<ul>\n");
if(chm_toc)fprintf(chm_toc, "<ul>\n");
}
fprintf(fp, "<li>");
fprintf(fp, "<a %shref=\"%s#%s\">",
(section->para->type == para_Chapter
|| section->para->type ==
para_Appendix) ? "class=\"btitle\" " : "",
(section->para->type == para_Chapter|| section->para->type == para_Appendix) ? "class=\"btitle\" " : "",
section->file->filename,
(section->para->type == para_Chapter) ? "" : section->fragment);
if(chm_toc)fprintf(chm_toc, "<li><OBJECT type=\"text/sitemap\"><param name=\"Local\" value=\"%s#%s\"><param name=\"Name\" value=\"",
section->file->filename,
(section->para->type == para_Chapter) ? "" : section->fragment);
if(chm_ind)fprintf(chm_ind, "<li><OBJECT type=\"text/sitemap\"><param name=\"Local\" value=\"%s#%s\"><param name=\"Name\" value=\"",
section->file->filename,
(section->para->type == para_Chapter) ? "" : section->fragment);
//%s
if (section->para->type == para_Chapter
|| section->para->type == para_Appendix)
fprintf(fp, "<b>");
@ -1178,8 +1233,11 @@ xhtml_add_contents_entry(FILE * fp, xhtmlsection * section, int limit)
words))
{
xhtml_para(fp, section->para->kwtext);
if (section->para->words)
if(chm_toc)xhtml_para(chm_toc, section->para->kwtext);
if (section->para->words){
fprintf(fp, ": ");
if(chm_toc)fprintf(chm_toc, ": ");
}
}
if (section->para->type == para_Chapter
|| section->para->type == para_Appendix)
@ -1187,8 +1245,12 @@ xhtml_add_contents_entry(FILE * fp, xhtmlsection * section, int limit)
if (section->para->words)
{
xhtml_para(fp, section->para->words);
if(chm_toc)xhtml_para(chm_toc, section->para->words);
if(chm_ind)xhtml_para(chm_ind, section->para->words);
}
fprintf(fp, "</a></li>\n");
if(chm_toc)fprintf(chm_toc,"\"></OBJECT></li>\n");
if(chm_ind)fprintf(chm_ind,"\"></OBJECT></li>\n");
return TRUE;
}
@ -1365,6 +1427,13 @@ static void xhtml_doheader(FILE * fp, word * title)
fprintf(fp, "%ls\n", conf.body_start);
}
static void chm_doheader(FILE * fp, word * title)
{
fprintf(fp, "<HTML><BODY><UL><LI><OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"");
xhtml_para(fp, title);
fprintf(fp,"\"><param name=\"Local\" value=\"Contents.html\"></OBJECT></li>\n");
}
/*
* Output a footer for this XHTML file.
*/
@ -1396,6 +1465,10 @@ static void xhtml_dofooter(FILE * fp)
}
fprintf(fp, "</body>\n\n</html>\n");
}
static void chm_dofooter(FILE * fp)
{
fprintf(fp, "</ul></BODY></HTML>\n");
}
/*
* Output the versionid paragraph. Typically this is a version control
@ -1545,6 +1618,7 @@ static void xhtml_rdaddwc(rdstringc * rs, word * text, word * end)
xhtmlsection *sect;
indextag *itag;
int ti;
wchar_t *s;
for (; text && text != end; text = text->next)
{
@ -1553,7 +1627,32 @@ static void xhtml_rdaddwc(rdstringc * rs, word * text, word * end)
case word_HyperLink:
xhtml_utostr(text->text, &c);
rdaddsc(rs, "<a href=\"");
rdaddsc(rs, c);
if(chm_toc && *c == '.' && *(c+1) == '.')
rdaddsc(rs, c + 1);
else
rdaddsc(rs, c);
rdaddsc(rs, "\">");
sfree(c);
break;
case word_LocalHyperLink:
xhtml_utostr(text->text, &c);
rdaddsc(rs, "<a href=\"");
if (conf.rlink_prefix)
{
char *c2;
xhtml_utostr(conf.rlink_prefix, &c2);
rdaddsc(rs, c2);
sfree(c2);
}
rdaddsc(rs, c);
if (conf.rlink_suffix)
{
char *c2;
xhtml_utostr(conf.rlink_suffix, &c2);
rdaddsc(rs, c2);
sfree(c2);
}
rdaddsc(rs, "\">");
sfree(c);
break;
@ -1698,7 +1797,7 @@ static void xhtml_rdaddwc(rdstringc * rs, word * text, word * end)
{
char buf[2] = " ";
dont_convert = 0;
wchar_t *s = text->text;
s = text->text;
for (; *s; s++)
{
buf[0] = (char) *s;

View file

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <string.h>
#include "halibut.h"
struct numberstate_Tag {

View file

@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "halibut.h"
/*
@ -20,7 +21,7 @@ static void do_error(int code, va_list ap)
char *sp, *sp2;
wchar_t *wsp;
filepos fpos, fpos2;
int flags;
int flags=0;
switch (code)
{

View file

@ -146,6 +146,7 @@ enum {
word_IndexRef, /* (always an invisible one) */
word_HyperLink, /* (invisible) */
word_HyperEnd, /* (also invisible; no text) */
word_LocalHyperLink, /* (invisible) */
word_FreeTextXref /* \R */
};
/* aux values for attributed words */
@ -396,6 +397,7 @@ void gen_citations(paragraph *, keywordlist *);
* style.c
*/
struct userstyle_Tag {
void* empty;
};
/*

View file

@ -191,6 +191,7 @@ enum {
c_S, /* aux field is 0, 1, 2, ... */
c_U, /* unnumbered-chapter heading */
c_W, /* Web hyperlink */
c_L, /* Relative/local hyperlink */
c_b, /* bulletted list */
c_c, /* code */
c_cfg, /* configuration directive */
@ -245,6 +246,8 @@ static void match_kw(token * tok)
/*
* FIXME. The ids are explicit in here so as to allow long-name
* equivalents to the various very short keywords.
*
* This list must be sorted, it's searched using binary search.
*/
static const struct {
char const *name;
@ -281,6 +284,9 @@ static void match_kw(token * tok)
"K", c_K}
, /* capitalised cross-reference */
{
"L", c_L}
, /* Relative/local hyperlink */
{
"R", c_R}
, /* free text cross-reference */
{
@ -468,13 +474,13 @@ token get_token(input * in)
c == '#' || c == '{' || c == '}')
{
/* single-char command */
rdadd(&rs, c);
rdadd(&rs, (wchar_t)c);
} else if (c == 'u')
{
int len = 0;
do
{
rdadd(&rs, c);
rdadd(&rs, (wchar_t)c);
len++;
c = get(in, &cpos);
}
@ -484,7 +490,7 @@ token get_token(input * in)
{
do
{
rdadd(&rs, c);
rdadd(&rs, (wchar_t)c);
c = get(in, &cpos);
}
while (iscmd(c));
@ -527,7 +533,7 @@ token get_token(input * in)
break;
} else
{
rdadd(&rs, c);
rdadd(&rs, (wchar_t)c);
if (c == '-')
{
ret.aux = TRUE;
@ -583,7 +589,7 @@ token get_codepar_token(input * in)
c = get(in, &cpos);
/* Discard \r just before \n. */
if (c2 != 13 || !isnl(c))
rdadd(&rs, c2);
rdadd(&rs, (wchar_t)c2);
}
unget(in, c, &cpos);
ret.text = ustrdup(rs.text);
@ -653,10 +659,10 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
word **idximplicit; /* to restore from \u alternatives */
} *sitem;
stack parsestk;
word *indexword, *uword, *iword;
word *indexword=NULL, *uword=NULL, *iword=NULL;
word *idxwordlist;
rdstring indexstr;
int index_downcase, index_visible, indexing;
int index_downcase=0, index_visible=0, indexing=0;
const rdstring nullrs = { 0, 0, NULL };
wchar_t uchr;
@ -735,7 +741,7 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
par.type = para_Normal;
if (t.type == tok_cmd)
{
int needkw;
int needkw=0;
int is_macro = FALSE;
par.fpos = t.pos;
@ -1065,8 +1071,7 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
style = word_Normal;
spcstyle = word_WhiteSpace;
}
if (sitem->type & stack_idx)
{
if (sitem->type & stack_idx ) {
indexword->text = ustrdup(indexstr.text);
if (index_downcase)
ustrlow(indexword->text);
@ -1179,6 +1184,7 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
case c_k:
case c_R:
case c_W:
case c_L:
case c_date:
/*
* Keyword, hyperlink, or \date. We expect a
@ -1195,6 +1201,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
wd.type = word_FreeTextXref;
else if (t.cmd == c_W)
wd.type = word_HyperLink;
else if (t.cmd == c_L)
wd.type = word_LocalHyperLink;
else
wd.type = word_Normal;
dtor(t), t = get_token(in);
@ -1252,7 +1260,7 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
addword(wd, &idximplicit);
}
sfree(wdtext);
if (wd.type == word_FreeTextXref || wd.type == word_HyperLink)
if (wd.type == word_FreeTextXref || wd.type == word_HyperLink || wd.type == word_LocalHyperLink)
{
/*
* Hyperlinks are different: they then

View file

@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "halibut.h"
static void dbg_prtsource(paragraph * sourceform);
@ -217,6 +218,7 @@ int main(int argc, char **argv)
build_index(idx);
if (debug)
{
index_debug(idx);

View file

@ -2,15 +2,15 @@ OBJS = biblio.o bk_xhtml.o contents.o error.o help.o index.o input.o keywords.o
LIBS =
CC = gcc
RM = del
RM = rm -f
DEFINES = -DVERSION="\"1.0 (NSIS Custom Build)\""
CFLAGS = -Wall -W $(DEFINES)
CFLAGS = -Wall -W $(DEFINES) -mno-cygwin
LFLAGS = -s
all : halibut
halibut : $(OBJS)
$(CC) $(CFLAGS) $(LFLAGS) -o ..\halibut.exe $(OBJS) $(LIBS)
$(CC) $(CFLAGS) $(LFLAGS) -o ../halibut.exe $(OBJS) $(LIBS)
clean ::
$(RM) *.o

View file

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "halibut.h"
#ifdef LOGALLOC

View file

@ -1,7 +1,7 @@
/*
* misc.c: miscellaneous useful items
*/
#include <string.h>
#include "halibut.h"
struct stackTag {

View file

@ -1329,7 +1329,7 @@ static node234 *split234_internal(tree234 * t, int index)
{
node234 *halves[2], *n, *sib, *sub;
node234 *lparent, *rparent;
int ki, pki, i, half, lcount, rcount;
int ki, pki=0, i, half, lcount, rcount;
n = t->root;
LOG(("splitting tree %p at point %d\n", t, index));

View file

@ -30,7 +30,7 @@ char *ustrtoa(wchar_t * s, char *outbuf, int size)
return outbuf;
}
for (p = outbuf; *s && p < outbuf + size; p++, s++)
*p = *s;
*p = *(char*)s;
if (p < outbuf + size)
*p = '\0';
else