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).
static int leavecpp = 1; /* leave preprocessor lines */
static int ignore_shebang = 1; /* Leave out shebang (#!) 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
/* complain(file,line,what)
*
* print error message `what' for `file' at `line'. The error is suppressed
noisy = 0;
else if (strcmp(*argv,"-c")==0)
crunchnl = 1;
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;
ignore_shebang = 0;
else
break;
+ /* 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);
unlit(file, istream, ostream);
if (istream != stdin) fclose(istream);