[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/src/Attic/input.c,v [branch-1_4]
From: |
Eric Blake |
Subject: |
Changes to m4/src/Attic/input.c,v [branch-1_4] |
Date: |
Thu, 07 Sep 2006 22:48:17 +0000 |
CVSROOT: /sources/m4
Module name: m4
Branch: branch-1_4
Changes by: Eric Blake <ericb> 06/09/07 22:48:15
Index: src/input.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/input.c,v
retrieving revision 1.1.1.1.2.22
retrieving revision 1.1.1.1.2.23
diff -u -b -r1.1.1.1.2.22 -r1.1.1.1.2.23
--- src/input.c 4 Sep 2006 13:35:10 -0000 1.1.1.1.2.22
+++ src/input.c 7 Sep 2006 22:48:15 -0000 1.1.1.1.2.23
@@ -82,10 +82,11 @@
struct
{
FILE *file; /* input file handle */
+ boolean end; /* true if peek has seen EOF */
+ boolean close; /* true if we should close file on pop */
const char *name; /* name of PREVIOUS input file */
- int lineno; /* current line number for do */
- /* Yet another attack of "The curse of global variables" (sic) */
- int out_lineno; /* current output line number do */
+ int lineno; /* current line of previous file */
+ int out_lineno; /* current output line of previous file */
boolean advance_line; /* start_of_input_line from next_char () */
}
u_f;
@@ -156,14 +157,16 @@
#endif
-/*-------------------------------------------------------------------------.
-| push_file () pushes an input file on the input stack, saving the current |
-| file name and line number. If next is non-NULL, this push invalidates a |
-| call to push_string_init (), whose storage are consequentely released. |
-`-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------.
+| push_file () pushes an input file on the input stack, saving the |
+| current file name and line number. If next is non-NULL, this push |
+| invalidates a call to push_string_init (), whose storage is |
+| consequently released. If CLOSE, then close FP after EOF is |
+| detected. |
+`-------------------------------------------------------------------*/
void
-push_file (FILE *fp, const char *title)
+push_file (FILE *fp, const char *title, boolean close)
{
input_block *i;
@@ -180,6 +183,8 @@
sizeof (struct input_block));
i->type = INPUT_FILE;
+ i->u.u_f.end = FALSE;
+ i->u.u_f.close = close;
i->u.u_f.name = current_file;
i->u.u_f.lineno = current_line;
i->u.u_f.out_lineno = output_current_line;
@@ -325,7 +330,7 @@
fclose (isp->u.u_f.file);
retcode = EXIT_FAILURE;
}
- else if (fclose (isp->u.u_f.file) == EOF)
+ else if (isp->u.u_f.close && fclose (isp->u.u_f.file) == EOF)
{
M4ERROR ((warning_status, errno, "error reading file"));
retcode = EXIT_FAILURE;
@@ -445,6 +450,7 @@
ungetc (ch, isp->u.u_f.file);
return ch;
}
+ isp->u.u_f.end = TRUE;
break;
case INPUT_MACRO:
@@ -504,7 +510,10 @@
break;
case INPUT_FILE:
- ch = getc (isp->u.u_f.file);
+ /* If stdin is a terminal, calling getc after peek_input
+ already called it would make the user have to hit ^D
+ twice to quit. */
+ ch = isp->u.u_f.end ? EOF : getc (isp->u.u_f.file);
if (ch != EOF)
{
if (ch == '\n')