/* "inform" : The top level of Inform: switches, pathnames, filenaming */
/* conventions, ICL (Inform Command Line) files, main */
/* */
-/* Copyright (c) Graham Nelson 1993 - 2020 */
-/* */
-/* This file is part of Inform. */
+/* 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 */
#define MAIN_INFORM_FILE
#include "header.h"
+#define CMD_BUF_SIZE (256)
+
/* ------------------------------------------------------------------------- */
/* Compiler progress */
/* ------------------------------------------------------------------------- */
WORDSIZE = 2;
MAXINTWORD = 0x7FFF;
+ MAX_LOCAL_VARIABLES = 16; /* including "sp" */
+
if (INDIV_PROP_START != 64) {
INDIV_PROP_START = 64;
fatalerror("You cannot change INDIV_PROP_START in Z-code");
NUM_ATTR_BYTES = 6;
fatalerror("You cannot change NUM_ATTR_BYTES in Z-code");
}
- if (MAX_LOCAL_VARIABLES != 16) {
- MAX_LOCAL_VARIABLES = 16;
- fatalerror("You cannot change MAX_LOCAL_VARIABLES in Z-code");
- }
- if (MAX_GLOBAL_VARIABLES != 240) {
- MAX_GLOBAL_VARIABLES = 240;
- fatalerror("You cannot change MAX_GLOBAL_VARIABLES in Z-code");
- }
- if (MAX_VERBS > 255) {
- MAX_VERBS = 255;
- fatalerror("MAX_VERBS can only go above 255 when Glulx is used");
- }
}
else {
/* Glulx */
MAXINTWORD = 0x7FFFFFFF;
scale_factor = 0; /* It should never even get used in Glulx */
+ /* This could really be 120, since the practical limit is the size
+ of local_variables.keywords. But historically it's been 119. */
+ MAX_LOCAL_VARIABLES = 119; /* including "sp" */
+
if (INDIV_PROP_START < 256) {
INDIV_PROP_START = 256;
warning_numbered("INDIV_PROP_START should be at least 256 in Glulx. Setting to", INDIV_PROP_START);
}
}
- if (MAX_LOCAL_VARIABLES >= 120) {
- MAX_LOCAL_VARIABLES = 119;
- warning("MAX_LOCAL_VARIABLES cannot exceed 119; resetting to 119");
- /* This is because the keyword table in the lexer only has 120
- entries. */
+ if (MAX_LOCAL_VARIABLES > MAX_KEYWORD_GROUP_SIZE) {
+ compiler_error("MAX_LOCAL_VARIABLES cannot exceed MAX_KEYWORD_GROUP_SIZE");
+ MAX_LOCAL_VARIABLES = MAX_KEYWORD_GROUP_SIZE;
}
+
if (DICT_WORD_SIZE > MAX_DICT_WORD_SIZE) {
DICT_WORD_SIZE = MAX_DICT_WORD_SIZE;
warning_numbered(
if (!targ) {
/* Z-machine */
DICT_WORD_BYTES = DICT_WORD_SIZE;
- /* The Z-code generator doesn't use the following variables, although
- it would be a little cleaner if it did. */
OBJECT_BYTE_LENGTH = 0;
- DICT_ENTRY_BYTE_LENGTH = (version_number==3)?7:9;
+ DICT_ENTRY_BYTE_LENGTH = ((version_number==3)?7:9) - (ZCODE_LESS_DICT_DATA?1:0);
DICT_ENTRY_FLAG_POS = 0;
}
else {
DICT_ENTRY_FLAG_POS = (4+DICT_WORD_BYTES);
}
}
+
+ if (!targ) {
+ /* Z-machine */
+ /* The Z-machine's 96 abbreviations are used for these two purposes.
+ Make sure they are set consistently. If exactly one has been
+ set non-default, set the other to match. */
+ if (MAX_DYNAMIC_STRINGS == 32 && MAX_ABBREVS != 64) {
+ MAX_DYNAMIC_STRINGS = 96 - MAX_ABBREVS;
+ }
+ if (MAX_ABBREVS == 64 && MAX_DYNAMIC_STRINGS != 32) {
+ MAX_ABBREVS = 96 - MAX_DYNAMIC_STRINGS;
+ }
+ if (MAX_ABBREVS + MAX_DYNAMIC_STRINGS != 96
+ || MAX_ABBREVS < 0
+ || MAX_DYNAMIC_STRINGS < 0) {
+ warning("MAX_ABBREVS plus MAX_DYNAMIC_STRINGS must be 96 in Z-code; resetting both");
+ MAX_DYNAMIC_STRINGS = 32;
+ MAX_ABBREVS = 64;
+ }
+ }
}
/* ------------------------------------------------------------------------- */
/* Tracery: output control variables */
+/* (These are initially set to foo_trace_setting, but the Trace directive */
+/* can change them on the fly) */
/* ------------------------------------------------------------------------- */
int asm_trace_level, /* trace assembly: 0 for off, 1 for assembly
- only, 2 for full assembly tracing with hex dumps */
- line_trace_level, /* line tracing: 0 off, 1 on */
- expr_trace_level, /* expression tracing: 0 off, 1 full, 2 brief */
- linker_trace_level, /* set by -y: 0 to 4 levels of tracing */
- tokens_trace_level; /* lexer output tracing: 0 off, 1 on */
+ only, 2 for full assembly tracing with hex dumps,
+ 3 for branch shortening info, 4 for verbose
+ branch info */
+ expr_trace_level, /* expression tracing: 0 off, 1 on, 2/3 more */
+ linker_trace_level, /* linker tracing: 0 to 4 levels */
+ tokens_trace_level; /* lexer output tracing: 0 off, 1 on, 2/3 more */
/* ------------------------------------------------------------------------- */
/* On/off switch variables (by default all FALSE); other switch settings */
+/* (Some of these have become numerical settings now) */
/* ------------------------------------------------------------------------- */
-int bothpasses_switch, /* -b */
- concise_switch, /* -c */
+int concise_switch, /* -c */
economy_switch, /* -e */
- frequencies_switch, /* -f */
+ frequencies_setting, /* $!FREQ, -f */
ignore_switches_switch, /* -i */
- listobjects_switch, /* -j */
debugfile_switch, /* -k */
- listing_switch, /* -l */
- memout_switch, /* -m */
- printprops_switch, /* -n */
- offsets_switch, /* -o */
- percentages_switch, /* -p */
+ memout_switch, /* $!MEM */
+ printprops_switch, /* $!PROPS */
+ printactions_switch, /* $!ACTIONS */
obsolete_switch, /* -q */
transcript_switch, /* -r */
- statistics_switch, /* -s */
+ statistics_switch, /* $!STATS, -s */
optimise_switch, /* -u */
version_set_switch, /* -v */
nowarnings_switch, /* -w */
hash_switch, /* -x */
- memory_map_switch, /* -z */
+ memory_map_setting, /* $!MAP, -z */
oddeven_packing_switch, /* -B */
define_DEBUG_switch, /* -D */
- temporary_files_switch, /* -F */
module_switch, /* -M */
runtime_error_checking_switch, /* -S */
define_USE_MODULES_switch, /* -U */
int character_set_setting, /* set by -C0 through -C9 */
character_set_unicode, /* set by -Cu */
error_format, /* set by -E */
- asm_trace_setting, /* set by -a and -t: value of
- asm_trace_level to use when tracing */
+ asm_trace_setting, /* $!ASM, -a: initial value of
+ asm_trace_level */
+ bpatch_trace_setting, /* $!BPATCH */
+ symdef_trace_setting, /* $!SYMDEF */
+ expr_trace_setting, /* $!EXPR: initial value of
+ expr_trace_level */
+ tokens_trace_setting, /* $!TOKENS: initial value of
+ tokens_trace_level */
+ optabbrevs_trace_setting, /* $!FINDABBREVS */
double_space_setting, /* set by -d: 0, 1 or 2 */
- trace_fns_setting, /* set by -g: 0, 1 or 2 */
- linker_trace_setting, /* set by -y: ditto for linker_... */
+ trace_fns_setting, /* $!RUNTIME, -g: 0, 1, 2, or 3 */
+ files_trace_setting, /* $!FILES */
+ linker_trace_setting, /* $!LINKER: initial value of
+ linker_trace_level */
+ list_verbs_setting, /* $!VERBS */
+ list_dict_setting, /* $!DICT */
+ list_objects_setting, /* $!OBJECTS */
+ list_symbols_setting, /* $!SYMBOLS */
store_the_text; /* when set, record game text to a chunk
- of memory (used by both -r & -k) */
+ of memory (used by -u) */
static int r_e_c_s_set; /* has -S been explicitly set? */
int glulx_mode; /* -G */
static void reset_switch_settings(void)
-{ asm_trace_setting=0;
- linker_trace_level=0;
- tokens_trace_level=0;
+{ asm_trace_setting = 0;
+ linker_trace_setting = 0;
+ tokens_trace_setting = 0;
+ expr_trace_setting = 0;
+ bpatch_trace_setting = 0;
+ symdef_trace_setting = 0;
+ list_verbs_setting = 0;
+ list_dict_setting = 0;
+ list_objects_setting = 0;
+ list_symbols_setting = 0;
store_the_text = FALSE;
- bothpasses_switch = FALSE;
concise_switch = FALSE;
double_space_setting = 0;
economy_switch = FALSE;
- frequencies_switch = FALSE;
+ files_trace_setting = 0;
+ frequencies_setting = 0;
trace_fns_setting = 0;
ignore_switches_switch = FALSE;
- listobjects_switch = FALSE;
debugfile_switch = FALSE;
- listing_switch = FALSE;
- memout_switch = FALSE;
- printprops_switch = FALSE;
- offsets_switch = FALSE;
- percentages_switch = FALSE;
+ memout_switch = 0;
+ printprops_switch = 0;
+ printactions_switch = 0;
obsolete_switch = FALSE;
transcript_switch = FALSE;
statistics_switch = FALSE;
optimise_switch = FALSE;
+ optabbrevs_trace_setting = 0;
version_set_switch = FALSE;
nowarnings_switch = FALSE;
hash_switch = FALSE;
- memory_map_switch = FALSE;
+ memory_map_setting = 0;
oddeven_packing_switch = FALSE;
define_DEBUG_switch = FALSE;
-#ifdef USE_TEMPORARY_FILES
- temporary_files_switch = TRUE;
-#else
- temporary_files_switch = FALSE;
-#endif
define_USE_MODULES_switch = FALSE;
module_switch = FALSE;
#ifdef ARC_THROWBACK
compression_switch = TRUE;
glulx_mode = FALSE;
requested_glulx_version = 0;
+
+ /* These aren't switches, but for clarity we reset them too. */
+ asm_trace_level = 0;
+ expr_trace_level = 0;
+ linker_trace_level = 0;
+ tokens_trace_level = 0;
}
/* ------------------------------------------------------------------------- */
files_begin_pass();
endofpass_flag = FALSE;
- line_trace_level = 0; expr_trace_level = 0;
+ expr_trace_level = expr_trace_setting;
asm_trace_level = asm_trace_setting;
+ tokens_trace_level = tokens_trace_setting;
linker_trace_level = linker_trace_setting;
- if (listing_switch) line_trace_level=1;
lexer_begin_pass();
linker_begin_pass();
static char Include_Path[PATHLEN];
static char Code_Path[PATHLEN];
static char Module_Path[PATHLEN];
-static char Temporary_Path[PATHLEN];
static char current_source_path[PATHLEN];
char Debugging_Name[PATHLEN];
char Transcript_Name[PATHLEN];
set_path_value(Code_Path, Code_Directory);
set_path_value(Module_Path, Module_Directory);
set_path_value(ICL_Path, ICL_Directory);
- set_path_value(Temporary_Path, Temporary_Directory);
set_path_value(Debugging_Name, Debugging_File);
set_path_value(Transcript_Name, Transcript_File);
- set_path_value(Language_Name, "english");
+ set_path_value(Language_Name, Default_Language);
set_path_value(Charset_Map, "");
}
if (strcmp(pathname, "code_path")==0) path_to_set=Code_Path;
if (strcmp(pathname, "module_path")==0) path_to_set=Module_Path;
if (strcmp(pathname, "icl_path")==0) path_to_set=ICL_Path;
- if (strcmp(pathname, "temporary_path")==0) path_to_set=Temporary_Path;
if (strcmp(pathname, "debugging_name")==0) path_to_set=Debugging_Name;
if (strcmp(pathname, "transcript_name")==0) path_to_set=Transcript_Name;
if (strcmp(pathname, "language_name")==0) path_to_set=Language_Name;
name_or_unset(Code_Path));
printf(
-" Temporary file (out) temporary_path %s\n\
- ICL command file (in) icl_path %s\n\
+" ICL command file (in) icl_path %s\n\
Module (in & out) module_path %s\n\n",
- name_or_unset(Temporary_Path),
name_or_unset(ICL_Path), name_or_unset(Module_Path));
printf(
Include files: %s\n\
Story files: %s (Version 3), %s (v4), %s (v5, the default),\n\
%s (v6), %s (v7), %s (v8), %s (Glulx)\n\
- Temporary files: .tmp\n\
Modules: %s\n\n",
Source_Extension, Include_Extension,
Code_Extension, V4Code_Extension, V5Code_Extension, V6Code_Extension,
module_switch = save_mm;
}
-/* ------------------------------------------------------------------------- */
-/* Naming temporary files */
-/* (Arguably temporary files should be made using "tmpfile" in */
-/* the ANSI C library, but many supposed ANSI libraries lack it.) */
-/* ------------------------------------------------------------------------- */
-
-extern void translate_temp_filename(int i)
-{ char *p = NULL;
- switch(i)
- { case 1: p=Temp1_Name; break;
- case 2: p=Temp2_Name; break;
- case 3: p=Temp3_Name; break;
- }
- if (strlen(Temporary_Path)+strlen(Temporary_File)+6 >= PATHLEN) {
- printf ("Temporary_Path is too long.\n");
- exit(1);
- }
- sprintf(p,"%s%s%d", Temporary_Path, Temporary_File, i);
-#ifdef INCLUDE_TASK_ID
- sprintf(p+strlen(p), "_proc%08lx", (long int) unique_task_id());
-#endif
-#ifdef FILE_EXTENSIONS
- sprintf(p+strlen(p), ".tmp");
-#endif
-}
-
#ifdef ARCHIMEDES
static char riscos_ft_buffer[4];
lexer_endpass();
if (module_switch) linker_endpass();
+ issue_debug_symbol_warnings();
+
close_all_source();
if (hash_switch && hash_printed_since_newline) printf("\n");
- if (temporary_files_switch)
- { if (module_switch) flush_link_data();
- check_temp_files();
- }
sort_dictionary();
if (track_unused_routines)
locate_dead_functions();
int output_has_occurred;
-static void rennab(int32 time_taken)
+static void rennab(float time_taken)
{ /* rennab = reverse of banner */
-
int t = no_warnings + no_suppressed_warnings;
if (memout_switch) print_memory_usage();
if (no_compiler_errors > 0) print_sorry_message();
if (statistics_switch)
- printf("Completed in %ld seconds\n", (long int) time_taken);
+ {
+ /* Print the duration to a sensible number of decimal places.
+ (We aim for three significant figures.) */
+ if (time_taken >= 10.0)
+ printf("Completed in %.1f seconds\n", time_taken);
+ else if (time_taken >= 1.0)
+ printf("Completed in %.2f seconds\n", time_taken);
+ else
+ printf("Completed in %.3f seconds\n", time_taken);
+ }
}
/* ------------------------------------------------------------------------- */
static int execute_icl_header(char *file1);
static int compile(int number_of_files_specified, char *file1, char *file2)
-{ int32 time_start;
+{
+ TIMEVALUE time_start, time_end;
+ float duration;
if (execute_icl_header(file1))
return 1;
runtime_error_checking_switch = FALSE;
}
- time_start=time(0); no_compilations++;
+ TIMEVALUE_NOW(&time_start);
+
+ no_compilations++;
strcpy(Source_Name, file1); convert_filename_flag = TRUE;
strcpy(Code_Name, file1);
{ end_debug_file();
}
- if (temporary_files_switch && (no_errors>0)) remove_temp_files();
+ if (optimise_switch) {
+ /* Pull out all_text so that it will not be freed. */
+ extract_all_text();
+ }
free_arrays();
- rennab((int32) (time(0)-time_start));
-
- if (optimise_switch) optimise_abbreviations();
+ TIMEVALUE_NOW(&time_end);
+ duration = TIMEVALUE_DIFFERENCE(&time_start, &time_end);
+
+ rennab(duration);
- if (store_the_text) my_free(&all_text,"transcription text");
+ if (optimise_switch) {
+ optimise_abbreviations();
+ ao_free_arrays();
+ }
return (no_errors==0)?0:1;
}
{
printf(
"\nThis program is a compiler of Infocom format (also called \"Z-machine\")\n\
-story files: copyright (c) Graham Nelson 1993 - 2017.\n\n");
+story files, as well as \"Glulx\" story files:\n\
+Copyright (c) Graham Nelson 1993 - 2022.\n\n");
/* For people typing just "inform", a summary only: */
-switches a list of compiler switches, 1 or 2 letter\n\
(see \"inform -h2\" for the full range)\n\n\
+dir set Include_Path to this directory\n\
- +PATH=dir change the PATH to this directory\n\n\
- $... one of the following memory commands:\n");
+ ++dir add this directory to Include_Path\n\
+ +PATH=dir change the PATH to this directory\n\
+ ++PATH=dir add this directory to the PATH\n\n\
+ $... one of the following configuration commands:\n");
+
printf(
-" $list list current memory allocation settings\n\
- $huge make standard \"huge game\" settings %s\n\
- $large make standard \"large game\" settings %s\n\
- $small make standard \"small game\" settings %s\n\
+" $list list current settings\n\
$?SETTING explain briefly what SETTING is for\n\
- $SETTING=number change SETTING to given number\n\n\
- (filename) read in a list of commands (in the format above)\n\
- from this \"setup file\"\n\n",
- (DEFAULT_MEMORY_SIZE==HUGE_SIZE)?"(default)":"",
- (DEFAULT_MEMORY_SIZE==LARGE_SIZE)?"(default)":"",
- (DEFAULT_MEMORY_SIZE==SMALL_SIZE)?"(default)":"");
+ $SETTING=number change SETTING to given number\n\
+ $!TRACEOPT set trace option TRACEOPT\n\
+ (or $!TRACEOPT=2, 3, etc for more tracing;\n\
+ $! by itself to list all trace options)\n\
+ $#SYMBOL=number define SYMBOL as a constant in the story\n\n");
+
+ printf(
+" (filename) read in a list of commands (in the format above)\n\
+ from this \"setup file\"\n\n");
+
+ printf("Alternate command-line formats for the above:\n\
+ --help (this page)\n\
+ --path PATH=dir (set path)\n\
+ --addpath PATH=dir (add to path)\n\
+ --list (list current settings)\n\
+ --helpopt SETTING (explain setting)\n\
+ --opt SETTING=number (change setting)\n\
+ --helptrace (list all trace options)\n\
+ --trace TRACEOPT (set trace option)\n\
+ --trace TRACEOPT=num (more tracing)\n\
+ --define SYMBOL=number (define constant)\n\
+ --config filename (read setup file)\n\n");
#ifndef PROMPT_INPUT
- printf("For example: \"inform -dexs $huge curses\".\n\n");
+ printf("For example: \"inform -dexs curses\".\n");
#endif
return;
/* The -h2 (switches) help information: */
printf("Help on the full list of legal switch commands:\n\n\
- a trace assembly-language (without hex dumps; see -t)\n\
+ a trace assembly-language\n\
+ a2 trace assembly with hex dumps\n\
c more concise error messages\n\
d contract double spaces after full stops in text\n\
d2 contract double spaces after exclamation and question marks, too\n\
printf("\
f frequencies mode: show how useful abbreviations are\n\
- g traces calls to functions (except in the library)\n\
- g2 traces calls to all functions\n\
- h print this information\n");
+ g traces calls to all game functions\n\
+ g2 traces calls to all game and library functions\n\
+ g3 traces calls to all functions (including veneer)\n\
+ h print general help information\n\
+ h1 print help information on filenames and path options\n\
+ h2 print help information on switches (this page)\n");
printf("\
i ignore default switches set within the file\n\
- j list objects as constructed\n\
- k output Infix debugging information to \"%s\" (and switch -D on)\n\
- l list every statement run through Inform\n\
- m say how much memory has been allocated\n\
- n print numbers of properties, attributes and actions\n",
+ k output debugging information to \"%s\"\n",
Debugging_Name);
printf("\
- o print offset addresses\n\
- p give percentage breakdown of story file\n\
q keep quiet about obsolete usages\n\
r record all the text to \"%s\"\n\
- s give statistics\n\
- t trace assembly-language (with full hex dumps; see -a)\n",
+ s give statistics\n",
Transcript_Name);
printf("\
u work out most useful abbreviations (very very slowly)\n\
- v3 compile to version-3 (\"Standard\") story file\n\
- v4 compile to version-4 (\"Plus\") story file\n\
- v5 compile to version-5 (\"Advanced\") story file: the default\n\
- v6 compile to version-6 (graphical) story file\n\
+ v3 compile to version-3 (\"Standard\"/\"ZIP\") story file\n\
+ v4 compile to version-4 (\"Plus\"/\"EZIP\") story file\n\
+ v5 compile to version-5 (\"Advanced\"/\"XZIP\") story file: the default\n\
+ v6 compile to version-6 (graphical/\"YZIP\") story file\n\
+ v7 compile to version-7 (expanded \"Advanced\") story file\n\
v8 compile to version-8 (expanded \"Advanced\") story file\n\
w disable warning messages\n\
x print # for every 100 lines compiled\n\
- y trace linking system\n\
- z print memory map of the Z-machine\n\n");
+ z print memory map of the virtual machine\n\n");
printf("\
B use big memory model (for large V6/V7 files)\n\
(error_format==1)?" (current setting)":"");
printf(" E2 Macintosh MPW-style error messages%s\n",
(error_format==2)?" (current setting)":"");
-#ifdef USE_TEMPORARY_FILES
-printf(" F0 use extra memory rather than temporary files\n");
-#else
-printf(" F1 use temporary files to reduce memory consumption\n");
-#endif
printf(" G compile a Glulx game file\n");
printf(" H use Huffman encoding to compress Glulx strings\n");
printf(" M compile as a Module for future linking\n");
}
switch(p[i])
{
- case 'a': asm_trace_setting = 1; break;
- case 'b': bothpasses_switch = state; break;
+ case 'a': switch(p[i+1])
+ { case '1': asm_trace_setting=1; s=2; break;
+ case '2': asm_trace_setting=2; s=2; break;
+ case '3': asm_trace_setting=3; s=2; break;
+ case '4': asm_trace_setting=4; s=2; break;
+ default: asm_trace_setting=1; break;
+ }
+ break;
case 'c': concise_switch = state; break;
case 'd': switch(p[i+1])
{ case '1': double_space_setting=1; s=2; break;
}
break;
case 'e': economy_switch = state; break;
- case 'f': frequencies_switch = state; break;
+ case 'f': frequencies_setting = (state?1:0); break;
case 'g': switch(p[i+1])
{ case '1': trace_fns_setting=1; s=2; break;
case '2': trace_fns_setting=2; s=2; break;
+ case '3': trace_fns_setting=3; s=2; break;
default: trace_fns_setting=1; break;
}
break;
}
break;
case 'i': ignore_switches_switch = state; break;
- case 'j': listobjects_switch = state; break;
case 'k': if (cmode == 0)
error("The switch '-k' can't be set with 'Switches'");
else
- { debugfile_switch = state;
- if (state) define_DEBUG_switch = TRUE;
- }
+ debugfile_switch = state;
break;
- case 'l': listing_switch = state; break;
- case 'm': memout_switch = state; break;
- case 'n': printprops_switch = state; break;
- case 'o': offsets_switch = state; break;
- case 'p': percentages_switch = state; break;
case 'q': obsolete_switch = state; break;
case 'r': if (cmode == 0)
error("The switch '-r' can't be set with 'Switches'");
else
transcript_switch = state; break;
case 's': statistics_switch = state; break;
- case 't': asm_trace_setting=2; break;
case 'u': if (cmode == 0) {
error("The switch '-u' can't be set with 'Switches'");
break;
break;
case 'w': nowarnings_switch = state; break;
case 'x': hash_switch = state; break;
- case 'y': s=2; linker_trace_setting=p[i+1]-'0'; break;
- case 'z': memory_map_switch = state; break;
+ case 'z': memory_map_setting = (state ? 1 : 0); break;
case 'B': oddeven_packing_switch = state; break;
case 'C': s=2;
if (p[i+1] == 'u') {
default: error_format=1; break;
}
break;
- case 'F': if (cmode == 0) {
- error("The switch '-F' can't be set with 'Switches'");
- break;
- }
- switch(p[i+1])
- { case '0': s=2; temporary_files_switch = FALSE; break;
- case '1': s=2; temporary_files_switch = TRUE; break;
- default: temporary_files_switch = state; break;
- }
- break;
case 'M': module_switch = state;
if (state && (r_e_c_s_set == FALSE))
runtime_error_checking_switch = FALSE;
r_e_c_s_set = TRUE; break;
case 'G': if (cmode == 0)
error("The switch '-G' can't be set with 'Switches'");
+ else if (version_set_switch)
+ error("The '-G' switch cannot follow the '-v' switch");
else
{ glulx_mode = state;
adjust_memory_sizes();
}
}
- if (optimise_switch && (!store_the_text))
- { store_the_text=TRUE;
-#ifdef PC_QUICKC
- if (memout_switch)
- printf("Allocation %ld bytes for transcription text\n",
- (long) MAX_TRANSCRIPT_SIZE);
- all_text = halloc(MAX_TRANSCRIPT_SIZE,1);
- malloced_bytes += MAX_TRANSCRIPT_SIZE;
- if (all_text==NULL)
- fatalerror("Can't hallocate memory for transcription text. Darn.");
-#else
- all_text=my_malloc(MAX_TRANSCRIPT_SIZE,"transcription text");
-#endif
+ if (optimise_switch)
+ {
+ /* store_the_text is equivalent to optimise_switch; -u sets both.
+ We could simplify this. */
+ store_the_text=TRUE;
}
}
+/* Check whether the string looks like an ICL command. */
static int icl_command(char *p)
{ if ((p[0]=='+')||(p[0]=='-')||(p[0]=='$')
|| ((p[0]=='(')&&(p[strlen(p)-1]==')')) ) return TRUE;
return i;
}
+/* Copy a string, converting to uppercase. The to array should be
+ (at least) max characters. Result will be null-terminated, so
+ at most max-1 characters will be copied.
+*/
+static int strcpyupper(char *to, char *from, int max)
+{
+ int ix;
+ for (ix=0; ix<max-1; ix++) {
+ char ch = from[ix];
+ if (islower(ch)) ch = toupper(ch);
+ to[ix] = ch;
+ }
+ to[ix] = 0;
+ return ix;
+}
+
static void execute_icl_command(char *p);
+static int execute_dashdash_command(char *p, char *p2);
static int execute_icl_header(char *argname)
{
FILE *command_file;
- char cli_buff[256], fw[256];
+ char cli_buff[CMD_BUF_SIZE], fw[CMD_BUF_SIZE];
int line = 0;
int errcount = 0;
int i;
}
while (feof(command_file)==0) {
- if (fgets(cli_buff,256,command_file)==0) break;
+ if (fgets(cli_buff,CMD_BUF_SIZE,command_file)==0) break;
line++;
if (!(cli_buff[0] == '!' && cli_buff[1] == '%'))
break;
- i = copy_icl_word(cli_buff+2, fw, 256);
+ i = copy_icl_word(cli_buff+2, fw, CMD_BUF_SIZE);
if (icl_command(fw)) {
execute_icl_command(fw);
- copy_icl_word(cli_buff+2 + i, fw, 256);
+ copy_icl_word(cli_buff+2 + i, fw, CMD_BUF_SIZE);
if ((fw[0] != 0) && (fw[0] != '!')) {
icl_header_error(filename, line);
errcount++;
static void run_icl_file(char *filename, FILE *command_file)
-{ char cli_buff[256], fw[256];
+{ char cli_buff[CMD_BUF_SIZE], fw[CMD_BUF_SIZE];
int i, x, line = 0;
printf("[Running ICL file '%s']\n", filename);
while (feof(command_file)==0)
- { if (fgets(cli_buff,256,command_file)==0) break;
+ { if (fgets(cli_buff,CMD_BUF_SIZE,command_file)==0) break;
line++;
- i = copy_icl_word(cli_buff, fw, 256);
+ i = copy_icl_word(cli_buff, fw, CMD_BUF_SIZE);
if (icl_command(fw))
{ execute_icl_command(fw);
- copy_icl_word(cli_buff + i, fw, 256);
+ copy_icl_word(cli_buff + i, fw, CMD_BUF_SIZE);
if ((fw[0] != 0) && (fw[0] != '!'))
{ icl_error(filename, line);
printf("expected comment or nothing but found '%s'\n", fw);
case 2: printf("[Compiling <%s> to <%s>]\n",
story_name, code_name);
compile(x, story_name, code_name);
- copy_icl_word(cli_buff + i, fw, 256);
+ copy_icl_word(cli_buff + i, fw, CMD_BUF_SIZE);
if (fw[0]!=0)
{ icl_error(filename, line);
printf("Expected comment or nothing but found '%s'\n",
}
}
+/* This should only be called if the argument has been verified to be
+ an ICL command, e.g. by checking icl_command().
+*/
static void execute_icl_command(char *p)
-{ char filename[PATHLEN], cli_buff[256];
+{ char filename[PATHLEN], cli_buff[CMD_BUF_SIZE];
FILE *command_file;
-
+ int len;
+
switch(p[0])
{ case '+': set_path_command(p+1); break;
case '-': switches(p,1); break;
case '$': memory_command(p+1); break;
- case '(': strcpy(cli_buff,p+1); cli_buff[strlen(cli_buff)-1]=0;
+ case '(': len = strlen(p);
+ if (p[len-1] != ')') {
+ printf("Error in ICL: (command) missing closing paren\n");
+ break;
+ }
+ len -= 2; /* omit parens */
+ if (len > CMD_BUF_SIZE-1) len = CMD_BUF_SIZE-1;
+ strncpy(cli_buff, p+1, len);
+ cli_buff[len]=0;
{ int x = 0;
do
{ x = translate_icl_filename(x, filename, cli_buff);
command_file = fopen(filename,"r");
} while ((command_file == NULL) && (x != 0));
}
- if (command_file == NULL)
+ if (command_file == NULL) {
printf("Error in ICL: Couldn't open command file '%s'\n",
filename);
- else
- { run_icl_file(filename, command_file);
- fclose(command_file);
+ break;
}
+ run_icl_file(filename, command_file);
+ fclose(command_file);
break;
}
}
+/* Convert a --command into the equivalent ICL command and call
+ execute_icl_command(). The dashes have already been stripped.
+
+ The second argument is the following command-line argument
+ (or NULL if there was none). This may or may not be consumed.
+ Returns TRUE if it was.
+*/
+static int execute_dashdash_command(char *p, char *p2)
+{
+ char cli_buff[CMD_BUF_SIZE];
+ int consumed2 = FALSE;
+
+ if (!strcmp(p, "help")) {
+ strcpy(cli_buff, "-h");
+ }
+ else if (!strcmp(p, "list")) {
+ strcpy(cli_buff, "$LIST");
+ }
+ else if (!strcmp(p, "size")) {
+ consumed2 = TRUE;
+ /* We accept these arguments even though they've been withdrawn. */
+ if (!(p2 && (!strcmpcis(p2, "HUGE") || !strcmpcis(p2, "LARGE") || !strcmpcis(p2, "SMALL")))) {
+ printf("--size must be followed by \"huge\", \"large\", or \"small\"\n");
+ return consumed2;
+ }
+ strcpy(cli_buff, "$");
+ strcpyupper(cli_buff+1, p2, CMD_BUF_SIZE-1);
+ }
+ else if (!strcmp(p, "opt")) {
+ consumed2 = TRUE;
+ if (!p2 || !strchr(p2, '=')) {
+ printf("--opt must be followed by \"setting=number\"\n");
+ return consumed2;
+ }
+ strcpy(cli_buff, "$");
+ strcpyupper(cli_buff+1, p2, CMD_BUF_SIZE-1);
+ }
+ else if (!strcmp(p, "helpopt")) {
+ consumed2 = TRUE;
+ if (!p2) {
+ printf("--helpopt must be followed by \"setting\"\n");
+ return consumed2;
+ }
+ strcpy(cli_buff, "$?");
+ strcpyupper(cli_buff+2, p2, CMD_BUF_SIZE-2);
+ }
+ else if (!strcmp(p, "define")) {
+ consumed2 = TRUE;
+ if (!p2) {
+ printf("--define must be followed by \"symbol=number\"\n");
+ return consumed2;
+ }
+ strcpy(cli_buff, "$#");
+ strcpyupper(cli_buff+2, p2, CMD_BUF_SIZE-2);
+ }
+ else if (!strcmp(p, "path")) {
+ consumed2 = TRUE;
+ if (!p2 || !strchr(p2, '=')) {
+ printf("--path must be followed by \"name=path\"\n");
+ return consumed2;
+ }
+ snprintf(cli_buff, CMD_BUF_SIZE, "+%s", p2);
+ }
+ else if (!strcmp(p, "addpath")) {
+ consumed2 = TRUE;
+ if (!p2 || !strchr(p2, '=')) {
+ printf("--addpath must be followed by \"name=path\"\n");
+ return consumed2;
+ }
+ snprintf(cli_buff, CMD_BUF_SIZE, "++%s", p2);
+ }
+ else if (!strcmp(p, "config")) {
+ consumed2 = TRUE;
+ if (!p2) {
+ printf("--config must be followed by \"file.icl\"\n");
+ return consumed2;
+ }
+ snprintf(cli_buff, CMD_BUF_SIZE, "(%s)", p2);
+ }
+ else if (!strcmp(p, "trace")) {
+ consumed2 = TRUE;
+ if (!p2) {
+ printf("--trace must be followed by \"traceopt\" or \"traceopt=N\"\n");
+ return consumed2;
+ }
+ snprintf(cli_buff, CMD_BUF_SIZE, "$!%s", p2);
+ }
+ else if (!strcmp(p, "helptrace")) {
+ strcpy(cli_buff, "$!");
+ }
+ else {
+ printf("Option \"--%s\" unknown (try \"inform -h\")\n", p);
+ return FALSE;
+ }
+
+ execute_icl_command(cli_buff);
+ return consumed2;
+}
+
/* ------------------------------------------------------------------------- */
/* Opening and closing banners */
/* ------------------------------------------------------------------------- */
-char banner_line[80];
+char banner_line[CMD_BUF_SIZE];
+/* We store the banner text for use elsewhere (see files.c).
+*/
static void banner(void)
{
- sprintf(banner_line, "Inform %s",
- (VERSION));
+ int len;
+ snprintf(banner_line, CMD_BUF_SIZE, "Inform %d.%d%d",
+ (VNUMBER/100)%10, (VNUMBER/10)%10, VNUMBER%10);
#ifdef RELEASE_SUFFIX
- strcat(banner_line, RELEASE_SUFFIX);
+ len = strlen(banner_line);
+ snprintf(banner_line+len, CMD_BUF_SIZE-len, "%s", RELEASE_SUFFIX);
#endif
#ifdef MACHINE_STRING
- sprintf(banner_line+strlen(banner_line), " for %s", MACHINE_STRING);
+ len = strlen(banner_line);
+ snprintf(banner_line+len, CMD_BUF_SIZE-len, " for %s", MACHINE_STRING);
#endif
+ len = strlen(banner_line);
+ snprintf(banner_line+len, CMD_BUF_SIZE-len, " (%s)", RELEASE_DATE);
+
printf("%s\n", banner_line);
}
if (argc==1) switches("-h",1);
for (i=1, cli_files_specified=0; i<argc; i++)
- if (icl_command(argv[i]))
+ if (argv[i][0] == '-' && argv[i][1] == '-') {
+ char *nextarg = NULL;
+ int consumed2;
+ if (i+1 < argc) nextarg = argv[i+1];
+ consumed2 = execute_dashdash_command(argv[i]+2, nextarg);
+ if (consumed2 && i+1 < argc) {
+ i++;
+ }
+ }
+ else if (icl_command(argv[i])) {
execute_icl_command(argv[i]);
- else
+ }
+ else {
switch(++cli_files_specified)
{ case 1: cli_file1 = argv[i]; break;
case 2: cli_file2 = argv[i]; break;
printf("Command line error: unknown parameter '%s'\n",
argv[i]); return;
}
+ }
}
#endif
banner();
- set_memory_sizes(DEFAULT_MEMORY_SIZE); set_default_paths();
+ set_memory_sizes(); set_default_paths();
reset_switch_settings(); select_version(5);
cli_files_specified = 0; no_compilations = 0;