+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
__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". */
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);
}
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);
}
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);
}
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
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);
}