Commit 87557722 by Jerry DeLisle

re PR libfortran/32456 (IO error message should show Unit/Filename)

2007-06-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/32456
	* runtime/error.c (show_locus): Update to emit the unit number
	and file name involved with the error.  Use new function
	filename_from_unit.
	* libgfortran.h (filename_from_unit): Declare new function.
	* io/unit.c (init_units): Set the unit file name for stdin, stdout,
	and stderr for use later in error reporting.
	(filename_from_unit): Add this new function.

From-SVN: r125989
parent a49c5793
2007-06-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/32456
* runtime/error.c (show_locus): Update to emit the unit number
and file name involved with the error. Use new function
filename_from_unit.
* libgfortran.h (filename_from_unit): Declare new function.
* io/unit.c (init_units): Set the unit file name for stdin, stdout,
and stderr for use later in error reporting.
(filename_from_unit): Add this new function.
2007-06-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/32446
* io/write.c (output_float): Calculate ndigits correctly for large
numbered formats that must pad zeros before the decimal point.
......
......@@ -84,6 +84,12 @@ __gthread_mutex_t unit_lock = __GTHREAD_MUTEX_INIT;
__gthread_mutex_t unit_lock;
#endif
/* We use these filenames for error reporting. */
static char stdin_name[] = "stdin";
static char stdout_name[] = "stdout";
static char stderr_name[] = "stderr";
/* This implementation is based on Stefan Nilsson's article in the
* July 1997 Doctor Dobb's Journal, "Treaps in Java". */
......@@ -506,6 +512,10 @@ init_units (void)
u->recl = options.default_recl;
u->endfile = NO_ENDFILE;
u->file_len = strlen (stdin_name);
u->file = get_mem (u->file_len);
memmove (u->file, stdin_name, u->file_len);
__gthread_mutex_unlock (&u->lock);
}
......@@ -524,6 +534,10 @@ init_units (void)
u->recl = options.default_recl;
u->endfile = AT_ENDFILE;
u->file_len = strlen (stdout_name);
u->file = get_mem (u->file_len);
memmove (u->file, stdout_name, u->file_len);
__gthread_mutex_unlock (&u->lock);
}
......@@ -544,6 +558,10 @@ init_units (void)
u->recl = options.default_recl;
u->endfile = AT_ENDFILE;
u->file_len = strlen (stderr_name);
u->file = get_mem (u->file_len);
memmove (u->file, stderr_name, u->file_len);
__gthread_mutex_unlock (&u->lock);
}
......@@ -665,3 +683,24 @@ update_position (gfc_unit *u)
else
u->flags.position = POSITION_ASIS;
}
/* filename_from_unit()-- If the unit_number exists, return a pointer to the
name of the associated file, otherwise return the empty string. The caller
must free memory allocated for the filename string. */
char *
filename_from_unit (int unit_number)
{
char *filename;
gfc_unit *u = NULL;
u = find_unit (unit_number);
if (u != NULL)
{
filename = (char *) get_mem (u->file_len + 1);
unpack_filename (filename, u->file, u->file_len);
return filename;
}
else
return (char *) NULL;
}
\ No newline at end of file
......@@ -683,6 +683,9 @@ extern int st_printf (const char *, ...)
__attribute__ ((format (printf, 1, 2)));
internal_proto(st_printf);
extern char * filename_from_unit (int);
internal_proto(filename_from_unit);
/* stop.c */
extern void stop_numeric (GFC_INTEGER_4) __attribute__ ((noreturn));
......
......@@ -248,8 +248,22 @@ st_sprintf (char *buffer, const char *format, ...)
void
show_locus (st_parameter_common *cmp)
{
static char *filename;
if (!options.locus || cmp == NULL || cmp->filename == NULL)
return;
if (cmp->unit > 0)
{
filename = filename_from_unit (cmp->unit);
if (filename != NULL)
{
st_printf ("At line %d of file %s (unit = %d, file = '%s')\n",
(int) cmp->line, cmp->filename, cmp->unit, filename);
free_mem (filename);
}
return;
}
st_printf ("At line %d of file %s\n", (int) cmp->line, cmp->filename);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment