X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=files.c;h=4e7377e4cb9c661db45c0abbb59c484333063aab;hb=37041256066b0f4023b2664ae4932a23b9b09d55;hp=fc0ad8ce23422b64b0b9f64f4c7f93a11143041e;hpb=5154191043a9b7227ef0eee1a2b40299fc188655;p=inform.git
diff --git a/files.c b/files.c
index fc0ad8c..4e7377e 100644
--- a/files.c
+++ b/files.c
@@ -28,7 +28,12 @@
#include "header.h"
-int input_file; /* Number of source files so far */
+int total_files; /* Number of files so far, including
+ #include and #origsource files */
+int total_input_files; /* Number of source files so far
+ (excludes #origsource) */
+int current_input_file; /* Most recently-opened source file */
+static int current_origsource_file; /* Most recently-used #origsource */
int32 total_chars_read; /* Characters read in (from all
source files put together) */
@@ -114,12 +119,12 @@ extern void load_sourcefile(char *filename_given, int same_directory_flag)
int x = 0;
FILE *handle;
- if (input_file == MAX_SOURCE_FILES)
+ if (total_files == MAX_SOURCE_FILES)
memoryerror("MAX_SOURCE_FILES", MAX_SOURCE_FILES);
do
{ x = translate_in_filename(x, name, filename_given, same_directory_flag,
- (input_file==0)?1:0);
+ (total_files==0)?1:0);
handle = fopen(name,"r");
} while ((handle == NULL) && (x != 0));
@@ -128,12 +133,12 @@ extern void load_sourcefile(char *filename_given, int same_directory_flag)
filename_storage_left -= strlen(name)+1;
strcpy(filename_storage_p, name);
- InputFiles[input_file].filename = filename_storage_p;
+ InputFiles[total_files].filename = filename_storage_p;
filename_storage_p += strlen(name)+1;
if (debugfile_switch)
- { debug_file_printf("", input_file);
+ { debug_file_printf("", total_files);
debug_file_printf("");
debug_file_print_with_entities(filename_given);
debug_file_printf("");
@@ -148,13 +153,17 @@ extern void load_sourcefile(char *filename_given, int same_directory_flag)
debug_file_printf("");
}
- InputFiles[input_file].handle = handle;
- if (InputFiles[input_file].handle==NULL)
+ InputFiles[total_files].handle = handle;
+ if (InputFiles[total_files].handle==NULL)
fatalerror_named("Couldn't open source file", name);
+ InputFiles[total_files].is_input = TRUE;
+
if (line_trace_level > 0) printf("\nOpening file \"%s\"\n",name);
- input_file++;
+ total_files++;
+ total_input_files++;
+ current_input_file = total_files;
}
static void close_sourcefile(int file_number)
@@ -176,7 +185,67 @@ static void close_sourcefile(int file_number)
extern void close_all_source(void)
{ int i;
- for (i=0; i 0 && current_origsource_file <= total_files) {
+ if (!strcmp(filename, InputFiles[current_origsource_file-1].filename))
+ return current_origsource_file;
+ }
+
+ for (ix=0; ix", total_files);
+ debug_file_printf("");
+ debug_file_print_with_entities(filename);
+ debug_file_printf("");
+ debug_file_printf("Inform 7");
+ debug_file_printf("");
+ }
+
+ InputFiles[total_files].handle = NULL;
+ InputFiles[total_files].is_input = FALSE;
+
+ total_files++;
+ current_origsource_file = total_files;
+ return current_origsource_file;
}
/* ------------------------------------------------------------------------- */
@@ -188,7 +257,7 @@ extern int file_load_chars(int file_number, char *buffer, int length)
{
int read_in; FILE *handle;
- if (file_number-1 > input_file)
+ if (file_number-1 > total_files)
{ buffer[0] = 0; return 1; }
handle = InputFiles[file_number-1].handle;
@@ -1369,12 +1438,28 @@ static void write_debug_location_internals(debug_location location)
}
}
+static void write_debug_location_origsource_internals(debug_location location)
+{ debug_file_printf
+ ("%d", location.orig_file_index - 1);
+ if (location.orig_beg_line_number)
+ debug_file_printf
+ ("%d", location.orig_beg_line_number);
+ if (location.orig_beg_char_number)
+ debug_file_printf
+ ("%d", location.orig_beg_char_number);
+}
+
extern void write_debug_location(debug_location location)
{ if (location.file_index && location.file_index != 255)
{ debug_file_printf("");
write_debug_location_internals(location);
debug_file_printf("");
}
+ if (location.orig_file_index)
+ { debug_file_printf("");
+ write_debug_location_origsource_internals(location);
+ debug_file_printf("");
+ }
}
extern void write_debug_locations(debug_locations locations)
@@ -1386,6 +1471,11 @@ extern void write_debug_locations(debug_locations locations)
write_debug_location_internals(current->location);
debug_file_printf("");
}
+ if (locations.location.orig_file_index)
+ { debug_file_printf("");
+ write_debug_location_origsource_internals(locations.location);
+ debug_file_printf("");
+ }
}
else
{ write_debug_location(locations.location);
@@ -1725,7 +1815,11 @@ extern void init_files_vars(void)
}
extern void files_begin_prepass(void)
-{ input_file = 0;
+{
+ total_files = 0;
+ total_input_files = 0;
+ current_input_file = 0;
+ current_origsource_file = 0;
}
extern void files_begin_pass(void)