Arrange for multiple \cfg, \IM and \BR paragraphs to not require
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Aug 2002 11:24:28 +0000 (11:24 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 12 Aug 2002 11:24:28 +0000 (11:24 +0000)
blank-line separators (config directives visually _want_ to be in a
single chunk).

git-svn-id: svn://svn.tartarus.org/sgt/halibut@1837 cda61777-01e9-0310-a592-d414129be87e

input.c
inputs/test.but

diff --git a/input.c b/input.c
index 15e0a97..2e0dabf 100644 (file)
--- a/input.c
+++ b/input.c
@@ -528,11 +528,13 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
 
     t.text = NULL;
     macros = newtree234(macrocmp);
+    already = FALSE;
 
     /*
      * Loop on each paragraph.
      */
     while (1) {
+       int start_cmd = c__invalid;
        par.words = NULL;
        par.keyword = NULL;
        whptr = &par.words;
@@ -540,7 +542,10 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
        /*
         * Get a token.
         */
-       dtor(t), t = get_token(in);
+       if (!already) {
+           dtor(t), t = get_token(in);
+       }
+       already = FALSE;
        if (t.type == tok_eof)
            return;
 
@@ -620,19 +625,22 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                 */
              case c_A: needkw = 2; par.type = para_Appendix; break;
              case c_B: needkw = 2; par.type = para_Biblio; break;
-             case c_BR: needkw = 1; par.type = para_BR; break;
+             case c_BR: needkw = 1; par.type = para_BR;
+               start_cmd = c_BR; break;
              case c_C: needkw = 2; par.type = para_Chapter; break;
              case c_H: needkw = 2; par.type = para_Heading;
                par.aux = 0;
                break;
-             case c_IM: needkw = 2; par.type = para_IM; break;
+             case c_IM: needkw = 2; par.type = para_IM;
+               start_cmd = c_IM; break;
              case c_S: needkw = 2; par.type = para_Subsect;
                par.aux = t.aux; break;
              case c_U: needkw = 32; par.type = para_UnnumberedChapter; break;
                /* For \b and \n the keyword is optional */
              case c_b: needkw = 4; par.type = para_Bullet; break;
              case c_n: needkw = 4; par.type = para_NumberedList; break;
-             case c_cfg: needkw = 8; par.type = para_Config; break;
+             case c_cfg: needkw = 8; par.type = para_Config;
+               start_cmd = c_cfg; break;
              case c_copyright: needkw = 32; par.type = para_Copyright; break;
              case c_define: is_macro = TRUE; needkw = 1; break;
                /* For \nocite the keyword is _everything_ */
@@ -709,12 +717,21 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
 
                /* Move to EOP in case of needkw==8 or 16 (no body) */
                if (needkw & 24) {
-                   if (t.type != tok_eop && t.type != tok_eof) {
+                   /* We allow whitespace even when we expect no para body */
+                   while (t.type == tok_white)
+                       dtor(t), t = get_token(in);
+                   if (t.type != tok_eop && t.type != tok_eof &&
+                       (start_cmd == c__invalid ||
+                        t.type != tok_cmd || t.cmd != start_cmd)) {
                        error(err_bodyillegal, &t.pos);
                        /* Error recovery: eat the rest of the paragraph */
-                       while (t.type != tok_eop && t.type != tok_eof)
+                       while (t.type != tok_eop && t.type != tok_eof &&
+                              (start_cmd == c__invalid ||
+                               t.type != tok_cmd || t.cmd != start_cmd))
                            dtor(t), t = get_token(in);
                    }
+                   if (t.type == tok_cmd)
+                       already = TRUE;/* inhibit get_token at top of loop */
                    addpara(par, ret);
                    continue;          /* next paragraph */
                }
@@ -745,6 +762,14 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
        while (t.type != tok_eop && t.type != tok_eof) {
            iswhite = FALSE;
            already = FALSE;
+
+           /* Handle implicit paragraph breaks after \IM, \BR etc */
+           if (start_cmd != c__invalid &&
+               t.type == tok_cmd && t.cmd == start_cmd) {
+               already = TRUE;        /* inhibit get_token at top of loop */
+               break;
+           }
+
            if (t.type == tok_cmd && t.cmd == c__escaped) {
                t.type = tok_word;     /* nice and simple */
                t.aux = 0;             /* even if `\-' - nonbreaking! */
@@ -765,6 +790,19 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                wd.aux = 0;
                wd.fpos = t.pos;
                wd.breaks = FALSE;
+
+               /*
+                * Inhibit use of whitespace if it's (probably the
+                * newline) before a repeat \IM / \BR type
+                * directive.
+                */
+               if (start_cmd != c__invalid) {
+                   dtor(t), t = get_token(in);
+                   already = TRUE;
+                   if (t.type == tok_cmd && t.cmd == start_cmd)
+                       break;
+               }
+
                if (indexing)
                    rdadd(&indexstr, ' ');
                if (!indexing || index_visible)
index 5849e52..8ac6e86 100644 (file)
@@ -19,7 +19,7 @@ a bit]
 
 \define{coopt} co\u00F6{-o}pt
 
-\versionid $Id: test.but,v 1.18 2002/08/05 10:31:33 simon Exp $
+\versionid $Id: test.but,v 1.19 2002/08/12 11:24:28 simon Exp $
 
 \C{ch\\ap} First chapter title; for similar wrapping reasons this
 chapter title will be ludicrously long. I wonder how much more
@@ -105,7 +105,8 @@ and here's a reference to it: \k{sub-sub}.
 \# \cfg{winhelp-topic}{Y5VQEXZQVJ} (uncomment this and it clashes)
 
 Here's an \i{appendix}, for no terribly good reason at all. See
-\k{book}.
+__\k{book}__ (please excuse those underscores, I'm testing
+whitespace).
 
 It also contains a \W{http://www.tartarus.org/}{hyperlink}.
 
@@ -117,6 +118,7 @@ It also contains a \W{http://www.tartarus.org/}{hyperlink}.
 the document even though there is no \cw{\\k} citing it.
 
 \BR{book} [SillyCitation]
+\BR{uncited} Badger.
 
 \nocite{nocite}