[project @ 2001-05-22 19:07:39 by sof]
authorsof <unknown>
Tue, 22 May 2001 19:07:39 +0000 (19:07 +0000)
committersof <unknown>
Tue, 22 May 2001 19:07:39 +0000 (19:07 +0000)
Added the -h (header) option; it prefixes the unlit'ed output with a pair
of line pragmas, e.g.,

  foo$ unlit -h foo.lhs foo.lhs - | head -3
  # 1 "foo.lhs"
  {-# LINE 1 "foo.lhs" #-}
  module Foo where
  foo$

Using -h saves the main user of 'unlit', GHC, from having to do the
prepending of line pragmas via shellular magic. (=> GHC is able to
drop the dependency on there being a UNIX-like shell underneath when
using System.system).

ghc/utils/unlit/unlit.c

index 27688c7..17cac8b 100644 (file)
@@ -75,6 +75,8 @@ static int crunchnl = 0; /* don't print \n for removed lines                 */
 static int leavecpp = 1; /* leave preprocessor lines */
 static int ignore_shebang = 1; /* Leave out shebang (#!) lines */
 
+static char* prefix_str = NULL; /* Prefix output with a string */
+
 /* complain(file,line,what)
  *
  * print error message `what' for `file' at `line'.  The error is suppressed
@@ -302,7 +304,16 @@ char **argv; {
             noisy = 0;
         else if (strcmp(*argv,"-c")==0)
            crunchnl = 1;
-        else if (strcmp(*argv,"-#")==0)
+        else if (strcmp(*argv,"-h")==0) {
+         if (argc > 1) {
+           argc--; argv++;
+           if (prefix_str) 
+             free(prefix_str);
+           prefix_str = (char*)malloc(sizeof(char)*(1+strlen(*argv)));
+           if (prefix_str) 
+             strcpy(prefix_str, *argv);
+         }
+        } else if (strcmp(*argv,"-#")==0)
            ignore_shebang = 0;
         else
             break;
@@ -336,6 +347,11 @@ char **argv; {
             exit(1);
         }
 
+    /* Prefix the output with line pragmas */
+    if (prefix_str) {
+      fprintf(ostream, "# 1 \"%s\"\n{-# LINE 1 \"%s\" #-}\n", prefix_str, prefix_str);
+    }
+
     unlit(file, istream, ostream);
 
     if (istream != stdin)  fclose(istream);