Yikes! Stack trash I'd never noticed before. Oops.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Apr 2004 08:29:15 +0000 (08:29 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Apr 2004 08:29:15 +0000 (08:29 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/halibut@4056 cda61777-01e9-0310-a592-d414129be87e

13 files changed:
Makefile
biblio.c
bk_info.c
bk_man.c
bk_paper.c [new file with mode: 0644]
bk_pdf.c [new file with mode: 0644]
bk_ps.c [new file with mode: 0644]
bk_text.c
bk_whlp.c
bk_xhtml.c
halibut.h
help.c
main.c

index 3802c58..f3b59e0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -100,7 +100,7 @@ SRC := ../
 
 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))
index de0b925..7ce163d 100644 (file)
--- a/biblio.c
+++ b/biblio.c
@@ -7,7 +7,7 @@
 
 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) {
index 23f8628..7ed8799 100644 (file)
--- a/bk_info.c
+++ b/bk_info.c
@@ -119,7 +119,7 @@ paragraph *info_config_filename(char *filename)
 }
 
 void info_backend(paragraph *sourceform, keywordlist *keywords,
-                 indexdata *idx) {
+                 indexdata *idx, void *unused) {
     paragraph *p;
     infoconfig conf;
     word *prefix, *body, *wp;
@@ -140,8 +140,7 @@ void info_backend(paragraph *sourceform, keywordlist *keywords,
     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);
 
index a773b60..60157fa 100644 (file)
--- a/bk_man.c
+++ b/bk_man.c
@@ -94,13 +94,14 @@ paragraph *man_config_filename(char *filename)
 #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);
 
diff --git a/bk_paper.c b/bk_paper.c
new file mode 100644 (file)
index 0000000..81661bf
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * 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";
+}
diff --git a/bk_pdf.c b/bk_pdf.c
new file mode 100644 (file)
index 0000000..42a0018
--- /dev/null
+++ b/bk_pdf.c
@@ -0,0 +1,18 @@
+/*
+ * 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);
+}
diff --git a/bk_ps.c b/bk_ps.c
new file mode 100644 (file)
index 0000000..37bc07e
--- /dev/null
+++ b/bk_ps.c
@@ -0,0 +1,18 @@
+/*
+ * 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);
+}
index fdb1055..0c2ce2c 100644 (file)
--- a/bk_text.c
+++ b/bk_text.c
@@ -209,7 +209,7 @@ paragraph *text_config_filename(char *filename)
 }
 
 void text_backend(paragraph *sourceform, keywordlist *keywords,
-                 indexdata *idx) {
+                 indexdata *idx, void *unused) {
     paragraph *p;
     textconfig conf;
     word *prefix, *body, *wp;
@@ -219,6 +219,7 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
     int nesting, nestindent;
     int indentb, indenta;
 
+    IGNORE(unused);
     IGNORE(keywords);                 /* we don't happen to need this */
     IGNORE(idx);                      /* or this */
 
index 9575673..9655b1f 100644 (file)
--- a/bk_whlp.c
+++ b/bk_whlp.c
@@ -72,7 +72,7 @@ paragraph *whlp_config_filename(char *filename)
 }
 
 void whlp_backend(paragraph *sourceform, keywordlist *keywords,
-                 indexdata *idx) {
+                 indexdata *idx, void *unused) {
     WHLP h;
     char *filename, *cntname;
     paragraph *p, *lastsect;
@@ -83,6 +83,8 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
     indexentry *ie;
     int done_contents_topic = FALSE;
 
+    IGNORE(unused);
+
     h = state.h = whlp_new();
     state.keywords = keywords;
     state.idx = idx;
index 5a10137..439f9f9 100644 (file)
@@ -744,13 +744,15 @@ static void xhtml_free_file(xhtmlfile* xfile)
  * 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;
index fd93408..da7a845 100644 (file)
--- a/halibut.h
+++ b/halibut.h
@@ -422,31 +422,48 @@ struct userstyle_Tag {
 /*
  * 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
diff --git a/help.c b/help.c
index 3762a30..8104006 100644 (file)
--- a/help.c
+++ b/help.c
@@ -12,6 +12,8 @@ static char *helptext[] = {
     "         --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",
diff --git a/main.c b/main.c
index 4dec663..24e6077 100644 (file)
--- a/main.c
+++ b/main.c
@@ -11,20 +11,29 @@ static void dbg_prtsource(paragraph *sourceform);
 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) {
@@ -34,9 +43,10 @@ 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.
@@ -84,7 +94,9 @@ int main(int argc, char **argv) {
                        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);
@@ -231,6 +243,7 @@ int main(int argc, char **argv) {
            infiles[nfiles++] = p;
        }
     }
+printf("%d\n", backendbits);
 
     if (errs)
        exit(EXIT_FAILURE);
@@ -307,13 +320,40 @@ int main(int argc, char **argv) {
        }
 
        /*
+        * 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);