X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Futils%2Funlit%2Funlit.c;h=ab3186aa42ee5c7ad04ebe874bd404be6c5fcf75;hb=c1f476b8170112aaf0a1377ec40eced327c78e9b;hp=b15e56829b8a66903c48b17e16d4db22243697b2;hpb=d581d5932888204df3f1b7f5b9e5516159b90213;p=ghc-hetmet.git diff --git a/ghc/utils/unlit/unlit.c b/ghc/utils/unlit/unlit.c index b15e568..ab3186a 100644 --- a/ghc/utils/unlit/unlit.c +++ b/ghc/utils/unlit/unlit.c @@ -41,6 +41,7 @@ */ #include +#include #include #define NULLSTR ((char *)0) @@ -75,6 +76,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 @@ -281,7 +284,7 @@ FILE *ostream; { * * Main program. Processes command line arguments, looking for leading: * -q quiet mode - do not complain about bad literate script files - * -n noisy mpde - complain about bad literate script files. + * -n noisy mode - complain about bad literate script files. * -r remove cpp droppings in output. * Expects two additional arguments, a file name for the input and a file * name for the output file. These two names must normally be distinct. @@ -302,7 +305,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,10 +348,15 @@ char **argv; { exit(1); } + /* Prefix the output with line pragmas */ + if (prefix_str) { + fprintf(ostream, "#line 1 \"%s\"\n{-# LINE 1 \"%s\" #-}\n", prefix_str, prefix_str); + } + unlit(file, istream, ostream); - fclose(istream); - fclose(ostream); + if (istream != stdin) fclose(istream); + if (ostream != stdout) fclose(ostream); exit(errors==0 ? 0 : 1); }