Update to commit e33eef4f8fab800eaf4a32b2d159cde6c4bbb38e
[inform.git] / src / files.c
index 6e4bec4314c757805640562a28cb57b75041902d..b027dd40f97916e74b90e2a8d28bf2279fa72189 100644 (file)
@@ -7,9 +7,8 @@
 /*             routines in "inform.c", since they are tied up with ICL       */
 /*             settings and are very host OS-dependent.                      */
 /*                                                                           */
-/*  Copyright (c) Graham Nelson 1993 - 2018                                  */
-/*                                                                           */
-/* This file is part of Inform.                                              */
+/*   Part of Inform 6.35                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2021                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -196,6 +195,7 @@ extern void close_all_source(void)
 extern int register_orig_sourcefile(char *filename)
 {
     int ix;
+    char *name;
 
     /* If the filename has already been used as an origsource filename,
        return that entry. We check the most-recently-used file first, and
@@ -217,7 +217,7 @@ extern int register_orig_sourcefile(char *filename)
     /* This filename has never been used before. Allocate a new InputFiles
        entry. */
 
-    char *name = filename; /* no translation */
+    name = filename; /* no translation */
 
     if (total_files == MAX_SOURCE_FILES)
         memoryerror("MAX_SOURCE_FILES", MAX_SOURCE_FILES);
@@ -1184,12 +1184,57 @@ game features require version 0x%08lx", (long)requested_glulx_version, (long)Ver
 
     }
     
-    /*  (4.5)  Output any null bytes (required to reach a GPAGESIZE address)
+    /*  (5)  Output static arrays (if any). */
+    {
+        /* We have to backpatch entries mentioned in staticarray_backpatch_table. */
+        int32 size_before_arrays = size;
+        int32 val, ix, jx;
+        for (ix=0, jx=0; ix<staticarray_backpatch_size; ix += 5) {
+            backpatch_error_flag = FALSE;
+            backpatch_marker = read_byte_from_memory_block(&staticarray_backpatch_table, ix);
+            /* datalen is always 4 for array backpatching */
+            offset = 
+                (read_byte_from_memory_block(&staticarray_backpatch_table, ix+1) << 24)
+                | (read_byte_from_memory_block(&staticarray_backpatch_table, ix+2) << 16)
+                | (read_byte_from_memory_block(&staticarray_backpatch_table, ix+3) << 8)
+                | (read_byte_from_memory_block(&staticarray_backpatch_table, ix+4));
+            while (jx<offset) {
+                sf_put(static_array_area[jx]);
+                size++;
+                jx++;
+            }
+
+            /* Write out the converted value of the backpatch marker. */
+            val = static_array_area[jx++];
+            val = (val << 8) | static_array_area[jx++];
+            val = (val << 8) | static_array_area[jx++];
+            val = (val << 8) | static_array_area[jx++];
+            val = backpatch_value(val);
+            sf_put((val >> 24) & 0xFF);
+            sf_put((val >> 16) & 0xFF);
+            sf_put((val >> 8) & 0xFF);
+            sf_put((val) & 0xFF);
+            size += 4;
+        }
+
+        /* Flush out the last bit of static_array_area, after the last backpatch marker. */
+        offset = static_array_area_size;
+        while (jx<offset) {
+            sf_put(static_array_area[jx]);
+            size++;
+            jx++;
+        }
+
+        if (size_before_arrays + static_array_area_size != size)
+            compiler_error("Static array output length did not match");
+    }
+
+    /*  (5.5)  Output any null bytes (required to reach a GPAGESIZE address)
              before RAMSTART. */
 
     while (size % GPAGESIZE) { sf_put(0); size++; }
 
-    /*  (5)  Output RAM. */
+    /*  (6)  Output RAM. */
 
     for (i=0; i<RAM_Size; i++)
     {   sf_put(zmachine_paged_memory[i]); size++;
@@ -1258,8 +1303,38 @@ extern void output_file(void)
 
 FILE *transcript_file_handle; int transcript_open;
 
-extern void write_to_transcript_file(char *text)
-{   fputs(text, transcript_file_handle);
+extern void write_to_transcript_file(char *text, int linetype)
+{
+    if (TRANSCRIPT_FORMAT == 1) {
+        char ch = '?';
+        switch (linetype) {
+            case STRCTX_INFO:
+                ch = 'I'; break;
+            case STRCTX_GAME:
+                ch = 'G'; break;
+            case STRCTX_GAMEOPC:
+                ch = 'H'; break;
+            case STRCTX_VENEER:
+                ch = 'V'; break;
+            case STRCTX_VENEEROPC:
+                ch = 'W'; break;
+            case STRCTX_LOWSTRING:
+                ch = 'L'; break;
+            case STRCTX_ABBREV:
+                ch = 'A'; break;
+            case STRCTX_DICT:
+                ch = 'D'; break;
+            case STRCTX_OBJNAME:
+                ch = 'O'; break;
+            case STRCTX_SYMBOL:
+                ch = 'S'; break;
+            case STRCTX_INFIX:
+                ch = 'X'; break;
+        }
+        fputc(ch, transcript_file_handle);
+        fputs(": ", transcript_file_handle);
+    }
+    fputs(text, transcript_file_handle);
     fputc('\n', transcript_file_handle);
 }
 
@@ -1273,9 +1348,16 @@ extern void open_transcript_file(char *what_of)
 
     transcript_open = TRUE;
 
-    sprintf(topline_buffer, "Transcript of the text of \"%s\"\n\
-[From %s]\n", what_of, banner_line);
-    write_to_transcript_file(topline_buffer);
+    sprintf(topline_buffer, "Transcript of the text of \"%s\"", what_of);
+    write_to_transcript_file(topline_buffer, STRCTX_INFO);
+    sprintf(topline_buffer, "[From %s]", banner_line);
+    write_to_transcript_file(topline_buffer, STRCTX_INFO);
+    if (TRANSCRIPT_FORMAT == 1) {
+        write_to_transcript_file("[I:info, G:game text, V:veneer text, L:lowmem string, A:abbreviation, D:dict word, O:object name, S:symbol, X:infix]", STRCTX_INFO);
+        if (!glulx_mode)
+            write_to_transcript_file("[H:game text inline in opcode, W:veneer text inline in opcode]", STRCTX_INFO);
+    }
+    write_to_transcript_file("",  STRCTX_INFO);
 }
 
 extern void abort_transcript_file(void)
@@ -1289,9 +1371,11 @@ extern void close_transcript_file(void)
     char sn_buffer[7];
 
     write_serial_number(sn_buffer);
-    sprintf(botline_buffer, "\n[End of transcript: release %d.%s]\n",
+    sprintf(botline_buffer, "[End of transcript: release %d, serial %s]",
         release_number, sn_buffer);
-    write_to_transcript_file(botline_buffer);
+    write_to_transcript_file("",  STRCTX_INFO);
+    write_to_transcript_file(botline_buffer, STRCTX_INFO);
+    write_to_transcript_file("",  STRCTX_INFO);
 
     if (ferror(transcript_file_handle))
         fatalerror("I/O failure: couldn't write to transcript file");