Update to commit a469d404a7dc4e87e18f367eb4d8e05fc32d20a7
[inform.git] / src / errors.c
index 195bfe9f90948bee4ef85c2cec4df79979630d11..09efcd28fcb56f85ff5b101f138338adc82da31f 100644 (file)
@@ -2,8 +2,8 @@
 /*   "errors" : Warnings, errors and fatal errors                            */
 /*              (with error throwback code for RISC OS machines)             */
 /*                                                                           */
-/*   Part of Inform 6.35                                                     */
-/*   copyright (c) Graham Nelson 1993 - 2021                                 */
+/*   Part of Inform 6.40                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2022                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -197,11 +197,8 @@ extern void fatalerror(char *s)
 #endif
 #ifdef MAC_FACE
     close_all_source();
-    if (temporary_files_switch) remove_temp_files();
     abort_transcript_file();
     free_arrays();
-    if (store_the_text)
-        my_free(&all_text,"transcription text");
     longjmp(g_fallback, 1);
 #endif
     exit(1);
@@ -225,16 +222,6 @@ extern void memory_out_error(int32 size, int32 howmany, char *name)
     fatalerror(error_message_buff);
 }
 
-extern void memoryerror(char *s, int32 size)
-{
-    snprintf(error_message_buff, ERROR_BUFLEN,
-        "The memory setting %s (which is %ld at present) has been \
-exceeded.  Try running Inform again with $%s=<some-larger-number> on the \
-command line.",s,(long int) size,s);
-    ellipsize_error_message_buff();
-    fatalerror(error_message_buff);
-}
-
 /* ------------------------------------------------------------------------- */
 /*   Survivable diagnostics:                                                 */
 /*      compilation errors   style 1                                         */
@@ -244,8 +231,6 @@ command line.",s,(long int) size,s);
 /*                                    indicate a bug in Inform)              */
 /* ------------------------------------------------------------------------- */
 
-static int errors[MAX_ERRORS];
-
 int no_errors, no_warnings, no_suppressed_warnings, no_link_errors,
     no_compiler_errors;
 
@@ -253,7 +238,7 @@ char *forerrors_buff;
 int  forerrors_pointer;
 
 static void message(int style, char *s)
-{   int throw_style = style;
+{
     if (hash_printed_since_newline) printf("\n");
     hash_printed_since_newline = FALSE;
     print_preamble();
@@ -261,22 +246,19 @@ static void message(int style, char *s)
     {   case 1: printf("Error: "); no_errors++; break;
         case 2: printf("Warning: "); no_warnings++; break;
         case 3: printf("Error:  [linking '%s']  ", current_module_filename);
-                no_link_errors++; no_errors++; throw_style=1; break;
+                no_link_errors++; no_errors++; break;
         case 4: printf("*** Compiler error: ");
-                no_compiler_errors++; throw_style=1; break;
+                no_compiler_errors++; break;
     }
     printf(" %s\n", s);
 #ifdef ARC_THROWBACK
-    throwback(throw_style, s);
+    throwback(((style <= 2) ? style : 1), s);
 #endif
 #ifdef MAC_FACE
     ProcessEvents (&g_proc);
     if (g_proc != true)
     {   free_arrays();
-        if (store_the_text)
-            my_free(&all_text,"transcription text");
         close_all_source ();
-        if (temporary_files_switch) remove_temp_files();
         abort_transcript_file();
         longjmp (g_fallback, 1);
     }
@@ -295,7 +277,6 @@ static void message(int style, char *s)
 extern void error(char *s)
 {   if (no_errors == MAX_ERRORS)
         fatalerror("Too many errors: giving up");
-    errors[no_errors] = no_syntax_lines;
     message(1,s);
 }
 
@@ -395,6 +376,30 @@ extern void unicode_char_error(char *s, int32 uni)
     error(error_message_buff);
 }
 
+extern void error_max_dynamic_strings(int index)
+{
+    if (index >= 96 && !glulx_mode)
+        snprintf(error_message_buff, ERROR_BUFLEN, "Only dynamic strings @(00) to @(95) may be used in Z-code");
+    else if (MAX_DYNAMIC_STRINGS == 0)
+        snprintf(error_message_buff, ERROR_BUFLEN, "Dynamic strings may not be used, because $MAX_DYNAMIC_STRINGS has been set to 0. Increase MAX_DYNAMIC_STRINGS.");
+    else if (MAX_DYNAMIC_STRINGS == 32 && !glulx_mode)
+        snprintf(error_message_buff, ERROR_BUFLEN, "Only dynamic strings @(00) to @(%02d) may be used, because $MAX_DYNAMIC_STRINGS has its default value of %d. Increase MAX_DYNAMIC_STRINGS.", MAX_DYNAMIC_STRINGS-1, MAX_DYNAMIC_STRINGS);
+    else
+        snprintf(error_message_buff, ERROR_BUFLEN, "Only dynamic strings @(00) to @(%02d) may be used, because $MAX_DYNAMIC_STRINGS has been set to %d. Increase MAX_DYNAMIC_STRINGS.", MAX_DYNAMIC_STRINGS-1, MAX_DYNAMIC_STRINGS);
+
+    ellipsize_error_message_buff();
+    error(error_message_buff);
+}
+
+extern void error_max_abbreviations(int index)
+{
+    /* This is only called for Z-code. */
+    if (index >= 96)
+        error("The number of abbreviations has exceeded 96, the limit in Z-code");
+    else
+        error("The number of abbreviations has exceeded MAX_ABBREVS. Increase MAX_ABBREVS.");
+}
+
 /* ------------------------------------------------------------------------- */
 /*   Style 2: Warning message routines                                       */
 /* ------------------------------------------------------------------------- */
@@ -419,6 +424,17 @@ extern void warning_named(char *s1, char *s2)
     message(2,error_message_buff);
 }
 
+extern void symtype_warning(char *context, char *name, char *type, char *wanttype)
+{
+    if (nowarnings_switch) { no_suppressed_warnings++; return; }
+    if (name)
+        snprintf(error_message_buff, ERROR_BUFLEN, "In %s, expected %s but found %s \"%s\"", context, wanttype, type, name);
+    else
+        snprintf(error_message_buff, ERROR_BUFLEN, "In %s, expected %s but found %s", context, wanttype, type);
+    ellipsize_error_message_buff();
+    message(2,error_message_buff);
+}
+
 extern void dbnu_warning(char *type, char *name, brief_location report_line)
 {   int i;
     ErrorPosition E = ErrorReport;
@@ -467,7 +483,6 @@ extern void obsolete_warning(char *s1)
 
 extern void link_error(char *s)
 {   if (no_errors==MAX_ERRORS) fatalerror("Too many errors: giving up");
-    errors[no_errors] = no_syntax_lines;
     message(3,s);
 }
 
@@ -484,11 +499,11 @@ 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\
-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\
+* '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");
 }
 
@@ -580,7 +595,7 @@ extern void errors_begin_pass(void)
 }
 
 extern void errors_allocate_arrays(void)
-{   forerrors_buff = my_malloc(512, "errors buffer");
+{   forerrors_buff = my_malloc(FORERRORS_SIZE, "errors buffer");
 }
 
 extern void errors_free_arrays(void)