MODULES := main malloc ustring error help licence version misc tree234
MODULES += input keywords contents index style biblio
-MODULES += bk_text bk_xhtml bk_whlp bk_man bk_info
+MODULES += bk_text bk_xhtml bk_whlp bk_man bk_info bk_paper bk_ps bk_pdf
MODULES += winhelp
OBJECTS := $(addsuffix .o,$(MODULES))
static wchar_t *gentext(int num) {
wchar_t text[22];
- wchar_t *p = text + sizeof(text);
+ wchar_t *p = text + lenof(text);
*--p = L'\0';
*--p = L']';
while (num != 0) {
}
void info_backend(paragraph *sourceform, keywordlist *keywords,
- indexdata *idx) {
+ indexdata *idx, void *unused) {
paragraph *p;
infoconfig conf;
word *prefix, *body, *wp;
int width = 70, listindentbefore = 1, listindentafter = 3;
int indent_code = 2, index_width = 40;
- IGNORE(keywords); /* we don't happen to need this */
- IGNORE(idx); /* or this */
+ IGNORE(unused);
conf = info_configure(sourceform);
#define QUOTE_QUOTES 2 /* quote double quotes by doubling them */
void man_backend(paragraph *sourceform, keywordlist *keywords,
- indexdata *idx) {
+ indexdata *idx, void *unused) {
paragraph *p;
FILE *fp;
manconfig conf;
- IGNORE(keywords); /* we don't happen to need this */
- IGNORE(idx); /* or this */
+ IGNORE(unused);
+ IGNORE(keywords);
+ IGNORE(idx);
conf = man_configure(sourceform);
--- /dev/null
+/*
+ * Paper printing pre-backend for Halibut.
+ *
+ * This module does all the processing common to both PostScript
+ * and PDF output: selecting fonts, line wrapping and page breaking
+ * in accordance with font metrics, laying out the contents and
+ * index pages, generally doing all the page layout. After this,
+ * bk_ps.c and bk_pdf.c should only need to do linear translations
+ * into their literal output format.
+ */
+
+#include "halibut.h"
+
+void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
+ indexdata *idx) {
+ /*
+ * FIXME
+ */
+ return "hello, world";
+}
--- /dev/null
+/*
+ * PDF backend for Halibut
+ */
+
+#include "halibut.h"
+
+paragraph *pdf_config_filename(char *filename)
+{
+ return NULL;
+}
+
+void pdf_backend(paragraph *sourceform, keywordlist *keywords,
+ indexdata *idx, void *unused) {
+ /*
+ * FIXME
+ */
+ printf("[pdf] %p = %s\n", unused, unused);
+}
--- /dev/null
+/*
+ * PostScript backend for Halibut
+ */
+
+#include "halibut.h"
+
+paragraph *ps_config_filename(char *filename)
+{
+ return NULL;
+}
+
+void ps_backend(paragraph *sourceform, keywordlist *keywords,
+ indexdata *idx, void *unused) {
+ /*
+ * FIXME
+ */
+ printf("[ps] %p = %s\n", unused, unused);
+}
}
void text_backend(paragraph *sourceform, keywordlist *keywords,
- indexdata *idx) {
+ indexdata *idx, void *unused) {
paragraph *p;
textconfig conf;
word *prefix, *body, *wp;
int nesting, nestindent;
int indentb, indenta;
+ IGNORE(unused);
IGNORE(keywords); /* we don't happen to need this */
IGNORE(idx); /* or this */
}
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;
* Main function.
*/
void xhtml_backend(paragraph *sourceform, keywordlist *in_keywords,
- indexdata *in_idx)
+ indexdata *in_idx, void *unused)
{
/* int i;*/
indexentry *ientry;
int ti;
xhtmlsection *xsect;
+ IGNORE(unused);
+
sourceparas = sourceform;
conf = xhtml_configure(sourceform);
keywords = in_keywords;
/*
* bk_text.c
*/
-void text_backend(paragraph *, keywordlist *, indexdata *);
+void text_backend(paragraph *, keywordlist *, indexdata *, void *);
paragraph *text_config_filename(char *filename);
/*
* bk_xhtml.c
*/
-void xhtml_backend(paragraph *, keywordlist *, indexdata *);
+void xhtml_backend(paragraph *, keywordlist *, indexdata *, void *);
paragraph *xhtml_config_filename(char *filename);
/*
* bk_whlp.c
*/
-void whlp_backend(paragraph *, keywordlist *, indexdata *);
+void whlp_backend(paragraph *, keywordlist *, indexdata *, void *);
paragraph *whlp_config_filename(char *filename);
/*
* bk_man.c
*/
-void man_backend(paragraph *, keywordlist *, indexdata *);
+void man_backend(paragraph *, keywordlist *, indexdata *, void *);
paragraph *man_config_filename(char *filename);
/*
* bk_info.c
*/
-void info_backend(paragraph *, keywordlist *, indexdata *);
+void info_backend(paragraph *, keywordlist *, indexdata *, void *);
paragraph *info_config_filename(char *filename);
+/*
+ * bk_paper.c
+ */
+void *paper_pre_backend(paragraph *, keywordlist *, indexdata *);
+
+/*
+ * bk_ps.c
+ */
+void ps_backend(paragraph *, keywordlist *, indexdata *, void *);
+paragraph *ps_config_filename(char *filename);
+
+/*
+ * bk_pdf.c
+ */
+void pdf_backend(paragraph *, keywordlist *, indexdata *, void *);
+paragraph *pdf_config_filename(char *filename);
+
#endif
" --winhelp[=filename] generate Windows Help output",
" --man[=filename] generate man page output",
" --info[=filename] generate GNU info output",
+ " --ps[=filename] generate PostScript output",
+ " --pdf[=filename] generate PDF output",
" -Cfoo:bar:baz append \\cfg{foo}{bar}{baz} to input",
" --precise report column numbers in error messages",
" --help display this text",
static void dbg_prtwordlist(int level, word *w);
static void dbg_prtkws(keywordlist *kws);
+static const struct pre_backend {
+ void *(*func)(paragraph *, keywordlist *, indexdata *);
+ int bitfield;
+} pre_backends[] = {
+ {paper_pre_backend, 0x0001}
+};
+
static const struct backend {
char *name;
- void (*func)(paragraph *, keywordlist *, indexdata *);
+ void (*func)(paragraph *, keywordlist *, indexdata *, void *);
paragraph *(*filename)(char *filename);
- int bitfield;
+ int bitfield, prebackend_bitfield;
} backends[] = {
- {"text", text_backend, text_config_filename, 0x0001},
- {"xhtml", xhtml_backend, xhtml_config_filename, 0x0002},
- {"html", xhtml_backend, xhtml_config_filename, 0x0002},
- {"hlp", whlp_backend, whlp_config_filename, 0x0004},
- {"whlp", whlp_backend, whlp_config_filename, 0x0004},
- {"winhelp", whlp_backend, whlp_config_filename, 0x0004},
- {"man", man_backend, man_config_filename, 0x0008},
- {"info", info_backend, info_config_filename, 0x0010},
+ {"text", text_backend, text_config_filename, 0x0001, 0},
+ {"xhtml", xhtml_backend, xhtml_config_filename, 0x0002, 0},
+ {"html", xhtml_backend, xhtml_config_filename, 0x0002, 0},
+ {"hlp", whlp_backend, whlp_config_filename, 0x0004, 0},
+ {"whlp", whlp_backend, whlp_config_filename, 0x0004, 0},
+ {"winhelp", whlp_backend, whlp_config_filename, 0x0004, 0},
+ {"man", man_backend, man_config_filename, 0x0008, 0},
+ {"info", info_backend, info_config_filename, 0x0010, 0},
+ {"ps", ps_backend, ps_config_filename, 0x0020, 0x0001},
+ {"pdf", pdf_backend, pdf_config_filename, 0x0040, 0x0001},
};
int main(int argc, char **argv) {
int errs;
int reportcols;
int debug;
- int backendbits;
+ int backendbits, prebackbits;
int k, b;
paragraph *cfg, *cfg_tail;
+ void *pre_backend_data[16];
/*
* Set up initial (default) parameters.
assert(opt[0] == '-');
for (k = 0; k < (int)lenof(backends); k++)
if (!strcmp(opt+1, backends[k].name)) {
+printf("%d\n", backendbits);
backendbits |= backends[k].bitfield;
+printf("%d\n", backendbits);
if (val) {
paragraph *p = backends[k].filename(val);
assert(p);
infiles[nfiles++] = p;
}
}
+printf("%d\n", backendbits);
if (errs)
exit(EXIT_FAILURE);
}
/*
+ * Select and run the pre-backends.
+ */
+ prebackbits = 0;
+ for (k = 0; k < (int)lenof(backends); k++)
+ if (backendbits == 0 || (backendbits & backends[k].bitfield))
+ prebackbits |= backends[k].prebackend_bitfield;
+ for (k = 0; k < (int)lenof(pre_backends); k++)
+ if (prebackbits & pre_backends[k].bitfield) {
+ assert(k < (int)lenof(pre_backend_data));
+ pre_backend_data[k] =
+ pre_backends[k].func(sourceform, keywords, idx);
+ }
+
+ /*
* Run the selected set of backends.
*/
+printf("%d\n", backendbits);
for (k = b = 0; k < (int)lenof(backends); k++)
if (b != backends[k].bitfield) {
b = backends[k].bitfield;
- if (backendbits == 0 || (backendbits & b))
- backends[k].func(sourceform, keywords, idx);
+ if (backendbits == 0 || (backendbits & b)) {
+ void *pbd = NULL;
+ int pbb = backends[k].prebackend_bitfield;
+ int m;
+
+ for (m = 0; m < (int)lenof(pre_backends); m++)
+ if (pbb & pre_backends[m].bitfield) {
+ assert(m < (int)lenof(pre_backend_data));
+ pbd = pre_backend_data[m];
+ break;
+ }
+
+ backends[k].func(sourceform, keywords, idx, pbd);
+ }
}
free_para_list(sourceform);