*/
#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#define NULLSTR ((char *)0)
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
*
* 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.
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;
exit(1);
}
+ /* Prefix the output with line pragmas */
+ if (prefix_str) {
+ /* Both GHC and CPP understand the #line pragma.
+ * We used to throw in both a #line and a {-# LINE #-} pragma
+ * here, but CPP doesn't understand {-# LINE #-} so it thought
+ * the line numbers were off by one. We could put the {-# LINE
+ * #-} before the #line, but there's no point since GHC
+ * understands #line anyhow. --SDM 8/2003
+ */
+ fprintf(ostream, "#line 1 \"%s\"\n", prefix_str, prefix_str);
+ }
+
unlit(file, istream, ostream);
if (istream != stdin) fclose(istream);