- assert( filename != 0 ); /* Filename may not be NULL. */
- if (filename [0])
- { /* We have a file name. Suck it and see. */
- file_handle = open (filename, O_RDONLY, 0);
- file_name = filename;
- }
- else
- { /* use stdin for the input file. */
- file_handle = fileno (stdin);
- file_name = "{standard input}"; /* For error messages. */
- }
- if (file_handle < 0)
- as_perror ("Can't open %s for reading", file_name);
- if ( preprocess )
- {
- /*
- * This code was written in haste for a frobbed BSD 4.2.
- * I have a flight to catch: will someone please do proper
- * error checks? - Dean.
- */
- int pid;
- char temporary_file_name [12];
- int fd;
- union wait status;
-
- (void)strcpy (temporary_file_name, "#appXXXXXX");
- (void)mktemp (temporary_file_name);
- pid = vfork ();
- if (pid == -1)
- {
- as_perror ("Vfork failed", file_name);
- _exit (144);
- }
- if (pid == 0)
- {
- (void)dup2 (file_handle, fileno(stdin));
- fd = open (temporary_file_name, O_WRONLY + O_TRUNC + O_CREAT, 0666);
- if (fd == -1)
- {
- (void)write(2,"Can't open temporary\n",21);
- _exit (99);
- }
- (void)dup2 (fd, fileno(stdout));
- /* JF for testing #define PREPROCESSOR "/lib/app" */
-#define PREPROCESSOR "./app"
- execl (PREPROCESSOR, PREPROCESSOR, 0);
- execl ("app","app",0);
- (void)write(2,"Exec of app failed. Get help.\n",31);
- (void)unlink(temporary_file_name);
- _exit (11);
- }
- (void)wait (& status);
- if (status.w_status & 0xFF00) /* JF was 0xF000, was wrong */
- {
- file_handle = -1;
- as_bad( "Can't preprocess file \"%s\", status = %xx", file_name, status.w_status );
- }
- else
- {
- file_handle = open (temporary_file_name, O_RDONLY, 0);
- if ( ! debugging && unlink(temporary_file_name))
- as_perror ("Can't delete temp file %s", temporary_file_name);
- }
- if (file_handle == -1)
- as_perror ("Can't retrieve temp file %s", temporary_file_name);
- }
+ int c;
+ char buf[80];
+
+ preprocess = pre;
+
+ assert (filename != 0); /* Filename may not be NULL. */
+ if (filename[0])
+ { /* We have a file name. Suck it and see. */
+ f_in = fopen (filename, "r");
+ file_name = filename;
+ }
+ else
+ { /* use stdin for the input file. */
+ f_in = stdin;
+ file_name = _("{standard input}"); /* For error messages. */
+ }
+ if (f_in == (FILE *) 0)
+ {
+ as_bad (_("Can't open %s for reading."), file_name);
+ as_perror ("%s", file_name);
+ return;
+ }
+
+ c = getc (f_in);
+ if (c == '#')
+ { /* Begins with comment, may not want to preprocess */
+ c = getc (f_in);
+ if (c == 'N')
+ {
+ fgets (buf, 80, f_in);
+ if (!strcmp (buf, "O_APP\n"))
+ preprocess = 0;
+ if (!strchr (buf, '\n'))
+ ungetc ('#', f_in); /* It was longer */
+ else
+ ungetc ('\n', f_in);
+ }
+ else if (c == '\n')
+ ungetc ('\n', f_in);
+ else
+ ungetc ('#', f_in);
+ }
+ else
+ ungetc (c, f_in);