X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Ferrors.c;h=c1e62412873f35669fdde5852bfb38fd56ceef0e;hb=8760c1ba6442153afe76bcac742e086f90c59fe8;hp=b76aa7d5658dbe9398b75280a5d9e228259ac73f;hpb=81ffe9a7de1db0b3a318a053b38882d1b7ab304c;p=inform.git diff --git a/src/errors.c b/src/errors.c index b76aa7d..c1e6241 100644 --- a/src/errors.c +++ b/src/errors.c @@ -2,9 +2,8 @@ /* "errors" : Warnings, errors and fatal errors */ /* (with error throwback code for RISC OS machines) */ /* */ -/* Copyright (c) Graham Nelson 1993 - 2018 */ -/* */ -/* This file is part of Inform. */ +/* Part of Inform 6.35 */ +/* copyright (c) Graham Nelson 1993 - 2020 */ /* */ /* Inform is free software: you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ @@ -32,6 +31,8 @@ static char error_message_buff[ERROR_BUFLEN+4]; /* room for ellipsis */ ErrorPosition ErrorReport; /* Maintained by "lexer.c" */ +static char other_pos_buff[ERROR_BUFLEN+1]; /* Used by location_text() */ + static void print_preamble(void) { /* Only really prints the preamble to an error or warning message: @@ -90,6 +91,42 @@ static void print_preamble(void) } } +static char *location_text(brief_location report_line) +{ + /* Convert the location to a brief string. + (Some error messages need to report a secondary location.) + This uses the static buffer other_pos_buff. */ + + ErrorPosition errpos; + errpos.file_number = -1; + errpos.source = NULL; + errpos.line_number = 0; + errpos.main_flag = 0; + errpos.orig_source = NULL; + export_brief_location(report_line, &errpos); + + int j; + char *p; + + j = errpos.file_number; + if (j <= 0 || j > total_files) p = errpos.source; + else p = InputFiles[j-1].filename; + + if (!p) p = ""; + + int len = 0; + + if (!(errpos.main_flag)) { + snprintf(other_pos_buff+len, ERROR_BUFLEN-len, + "\"%s\", ", p); + len = strlen(other_pos_buff); + } + snprintf(other_pos_buff+len, ERROR_BUFLEN-len, + "line %d", errpos.line_number); + + return other_pos_buff; +} + static void ellipsize_error_message_buff(void) { /* If the error buffer was actually filled up by a message, it was @@ -255,6 +292,12 @@ extern void ebf_error(char *s1, char *s2) error(error_message_buff); } +extern void ebf_symbol_error(char *s1, char *name, char *type, brief_location report_line) +{ snprintf(error_message_buff, ERROR_BUFLEN, "\"%s\" is a name already in use and may not be used as a %s (%s \"%s\" was defined at %s)", name, s1, type, name, location_text(report_line)); + ellipsize_error_message_buff(); + error(error_message_buff); +} + extern void char_error(char *s, int ch) { int32 uni; @@ -397,15 +440,12 @@ extern void link_error_named(char *s1, char *s2) extern void print_sorry_message(void) { printf( "***********************************************************************\n\ -* 'Compiler errors' should never occur if Inform is working properly. *\n\ -* This is version %d.%02d of Inform, dated %20s: so *\n\ -* if that was more than six months ago, there may be a more recent *\n\ -* version available, from which the problem may have been removed. *\n\ -* If not, please report this fault to: graham@gnelson.demon.co.uk *\n\ -* and if at all possible, please include your source code, as faults *\n\ -* such as these are rare and often difficult to reproduce. Sorry. *\n\ -***********************************************************************\n", - (RELEASE_NUMBER/100)%10, RELEASE_NUMBER%100, RELEASE_DATE); +Compiler errors should never occur if Inform is working properly.\n\ +Check to see if there is a more recent version available, from which\n\ +the problem may have been removed. If not, please report this fault\n\ +and if at all possible, please include your source code, as faults\n\ +such as these are rare and often difficult to reproduce. Sorry.\n\ +***********************************************************************\n"); } extern int compiler_error(char *s)