[commit: ghc] master: Reject spurious \end{code} in literate mode (#8430) (400c260)

git at git.haskell.org git
Fri Oct 11 22:53:42 UTC 2013


Repository : ssh://git at git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/400c260f977f5cd2bf2f2f26deeeecbe37466295/ghc

>---------------------------------------------------------------

commit 400c260f977f5cd2bf2f2f26deeeecbe37466295
Author: Krzysztof Gogolewski <krz.gogolewski at gmail.com>
Date:   Sat Oct 12 00:52:27 2013 +0200

    Reject spurious \end{code} in literate mode (#8430)


>---------------------------------------------------------------

400c260f977f5cd2bf2f2f26deeeecbe37466295
 utils/unlit/unlit.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/utils/unlit/unlit.c b/utils/unlit/unlit.c
index 76877be..4ae64d3 100644
--- a/utils/unlit/unlit.c
+++ b/utils/unlit/unlit.c
@@ -55,6 +55,7 @@
 #define CANNOTWRITESTDOUT "unlit: error writing standard output\n"
 #define DISTINCTNAMES  "unlit: input and output filenames must differ\n"
 #define MISSINGENDCODE "unlit: missing \\end{code}\n"
+#define SPURIOUSENDCODE "unlit: spurious \\end{code}\n"
 
 #define BEGINCODE "\\begin{code}"
 #define LENBEGINCODE 12
@@ -69,7 +70,7 @@
 #define LENENDPSEUDOCODE 16
 #endif
 
-typedef enum { START, BLANK, TEXT, DEFN, BEGIN, /*PSEUDO,*/ END, HASH, SHEBANG } line;
+typedef enum { START, BLANK, TEXT, DEFN, BEGIN, END, /*PSEUDO,*/ ENDFILE, HASH, SHEBANG } line;
 #define isWhitespace(c)  (c==' '  || c=='\t' || c=='\r')
 #define isLineTerm(c)    (c=='\n' || c==EOF)
 
@@ -160,7 +161,8 @@ egetc(FILE *istream)
  *     BEGIN (a \begin{code} line)
  *     PSEUDO (a \begin{pseodocode} line)
  *     HASH  (a preprocessor line)
- * or  END   (indicating an EOF).
+ *     END   (a (spurious) \end{code} line)
+ * or  ENDFILE (indicating an EOF).
  * Lines of type DEFN are copied to the output stream `ostream'
  * (without the leading DEFNCHAR).  BLANK and TEXT lines are
  * replaced by empty (i.e. blank lines) in the output stream, so
@@ -177,7 +179,7 @@ line readline(FILE *istream, FILE *ostream) {
     c = egetc(istream);
 
     if (c==EOF)
-        return END;
+        return ENDFILE;
   
     if ( c == '#' ) {
       if ( ignore_shebang ) {
@@ -224,6 +226,8 @@ line readline(FILE *istream, FILE *ostream) {
     buf[i] = 0;
     if (strcmp(buf, BEGINCODE) == 0)
 	return BEGIN;
+    if (strcmp(buf, ENDCODE) == 0)
+	return END;
 #ifdef PSEUDOCODE
     else if (strcmp(buf, BEGINPSEUDOCODE) == 0)
 	return PSEUDO;
@@ -258,6 +262,8 @@ void unlit(char *file, FILE *istream, FILE *ostream)
             complain(file, linesread-1, MISSINGBLANK);
         if (last==TEXT && this==DEFN)
             complain(file, linesread, MISSINGBLANK);
+        if (this==END)
+            complain(file, linesread, SPURIOUSENDCODE);
 	if (this == BEGIN) {
 	    /* start of code, copy to end */
 	    char lineb[1000];
@@ -291,7 +297,7 @@ void unlit(char *file, FILE *istream, FILE *ostream)
 	    }
 	}
 #endif
-    } while(this!=END);
+    } while(this!=ENDFILE);
 
     if (defnsread==0)
         complain(file,linesread,EMPTYSCRIPT);




More information about the ghc-commits mailing list