From 916bf9cbc80e0ec2524fdaf5d5efe44ce7e7bc26 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Tue, 19 May 2020 16:28:36 +0000 Subject: [PATCH] part 4 of 4 of preparations for backslash escaping git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@179 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/_amiga.h | 4 +-- src/_dos.c | 19 ++++++++------ src/_dos.h | 8 +++--- src/_riscos.c | 25 ++++++++++--------- src/_riscos.h | 6 ++--- src/_std.h | 4 +-- src/alu.c | 2 +- src/cpu.c | 2 +- src/encoding.c | 4 +-- src/flow.c | 2 +- src/input.c | 60 +++++++++++++++++++++++++-------------------- src/input.h | 4 +-- src/pseudoopcodes.c | 4 +-- src/section.c | 2 +- src/symbol.c | 2 +- 15 files changed, 80 insertions(+), 68 deletions(-) diff --git a/src/_amiga.h b/src/_amiga.h index 474c4ef..05016b0 100644 --- a/src/_amiga.h +++ b/src/_amiga.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for AmigaOS) @@ -13,7 +13,7 @@ #define PLATFORM_INIT // convert UNIX-style pathname to Amiga-style pathname (no change) -#define PLATFORM_CONVERTPATHCHAR(a) (a) +//#define PLATFORM_CONVERTPATH(p) // directory separator for include paths #define DIRECTORY_SEPARATOR '\0' // actually '/', but paths ending on ':' are ok, so auto-adding '/' is bad) diff --git a/src/_dos.c b/src/_dos.c index 6ba973a..8006d62 100644 --- a/src/_dos.c +++ b/src/_dos.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for DOS, OS/2 and Windows) @@ -34,14 +34,17 @@ void DOS_entry(void) } -// convert UNIX-style pathname character to DOS-style pathname character -char DOS_convert_path_char(char byte) +// convert UNIX-style pathname to DOS-style pathname +void DOS_convert_path(char *p) { - if (byte == '/') - return '\\'; - if (byte == '\\') - return '/'; - return byte; + while (*p) { + if (*p == '/') { + *p = '\\'; + } else if (*p == '\\') { + *p = '/'; + } + ++p; + } } diff --git a/src/_dos.h b/src/_dos.h index ab9515e..71c8810 100644 --- a/src/_dos.h +++ b/src/_dos.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for DOS, OS/2 and Windows) @@ -16,7 +16,7 @@ #define PLATFORM_INIT DOS_entry() // convert UNIX-style pathname to DOS-style pathname -#define PLATFORM_CONVERTPATHCHAR(a) DOS_convert_path_char(a) +#define PLATFORM_CONVERTPATH(p) DOS_convert_path(p) // directory separator for include paths #define DIRECTORY_SEPARATOR '\\' @@ -57,8 +57,8 @@ extern char *DOS_lib_prefix; // header string of library tree // used as PLATFORM_INIT: reads "ACME" environment variable extern void DOS_entry(void); -// Convert UNIX-style pathname character to DOS-style pathname character -extern char DOS_convert_path_char(char); +// Convert UNIX-style pathname to DOS-style pathname +extern void DOS_convert_path(char *p); #endif diff --git a/src/_riscos.c b/src/_riscos.c index ce28753..b9357c9 100644 --- a/src/_riscos.c +++ b/src/_riscos.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for RISC OS) @@ -46,17 +46,20 @@ void RISCOS_entry(void) // convert UNIX-style pathname to RISC OS-style pathname -char RISCOS_convert_path_char(char byte) +void RISCOS_convert_path(char *p) { - if (byte == '.') - return '/'; - if (byte == '/') - return '.'; - if (byte == '?') - return '#'; - if (byte == '#') - return '?'; - return byte; + while (*p) { + if (*p == '.') { + *p = '/'; + } else if (*p == '/') { + *p = '.'; + } else if (*p == '?') { + *p = '#'; + } else if (*p == '#') { + *p = '?'; + } + ++p; + } } diff --git a/src/_riscos.h b/src/_riscos.h index 945dcba..6ccf248 100644 --- a/src/_riscos.h +++ b/src/_riscos.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for RISC OS) @@ -15,7 +15,7 @@ #define PLATFORM_INIT RISCOS_entry() // convert UNIX-style pathname to RISC OS-style pathname -#define PLATFORM_CONVERTPATHCHAR(a) RISCOS_convert_path_char(a) +#define PLATFORM_CONVERTPATH(p) RISCOS_convert_path(p) // directory separator for include paths #define DIRECTORY_SEPARATOR '\0' // actually '.', but paths ending on ':' are ok, so auto-adding '.' is bad) @@ -66,7 +66,7 @@ extern int RISCOS_flags; // Holds platform-specific flags // used as PLATFORM_INIT: registers exit handler extern void RISCOS_entry(void); // convert UNIX-style pathname to RISC OS-style pathname -extern char RISCOS_convert_path_char(char); +extern void RISCOS_convert_path(char *p); // setting the created files' types extern void RISCOS_set_filetype(const char *, int); // use DDEUtils module's "Throwback" protocol diff --git a/src/_std.h b/src/_std.h index 826d811..677e860 100644 --- a/src/_std.h +++ b/src/_std.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Platform specific stuff (in this case, for unknown OSes) @@ -13,7 +13,7 @@ #define PLATFORM_INIT AnyOS_entry() // convert UNIX-style pathname to AnyOS-style pathname (no change) -#define PLATFORM_CONVERTPATHCHAR(a) (a) +//#define PLATFORM_CONVERTPATH(p) // directory separator for include paths #define DIRECTORY_SEPARATOR '/' diff --git a/src/alu.c b/src/alu.c index 7b7c6f5..0a70980 100644 --- a/src/alu.c +++ b/src/alu.c @@ -387,7 +387,7 @@ static void parse_quoted_character(char closing_quote) // eat closing quote GetByte(); // now convert to unescaped version - if (Input_unescape_dynabuf()) + if (Input_unescape_dynabuf(0)) goto fail; // escaping error // } // too short? diff --git a/src/cpu.c b/src/cpu.c index 74a1385..87adb5d 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -7,7 +7,7 @@ #include "config.h" #include "alu.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "input.h" #include "mnemo.h" #include "output.h" diff --git a/src/encoding.c b/src/encoding.c index 658272d..5581982 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Character encoding stuff @@ -9,7 +9,7 @@ #include "alu.h" #include "acme.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "output.h" #include "input.h" #include "tree.h" diff --git a/src/flow.c b/src/flow.c index d965b73..2fcb236 100644 --- a/src/flow.c +++ b/src/flow.c @@ -17,7 +17,7 @@ #include "alu.h" #include "config.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "input.h" #include "mnemo.h" #include "symbol.h" diff --git a/src/input.c b/src/input.c index 1863122..6e47832 100644 --- a/src/input.c +++ b/src/input.c @@ -9,7 +9,7 @@ #include "config.h" #include "alu.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "platform.h" #include "section.h" #include "symbol.h" @@ -280,6 +280,7 @@ char GetByte(void) // This function delivers the next byte from the currently active byte source // in un-shortened high-level format. // This function complains if CHAR_EOS (end of statement) is read. +// TODO - check if return value is actually used static char GetQuotedByte(void) { int from_file; // must be an int to catch EOF @@ -368,13 +369,14 @@ int Input_quoted_to_dynabuf(char closing_quote) // process backslash escapes in GlobalDynaBuf (so size might shrink) // returns 1 on errors (escaping errors) // TODO - check: if this is only ever called directly after Input_quoted_to_dynabuf, integrate that call here? -int Input_unescape_dynabuf(void) +int Input_unescape_dynabuf(int start_index) { if (!config.backslash_escaping) return 0; // ok // FIXME - implement backslash escaping! // TODO - shorten GlobalDynaBuf->size accordingly + // CAUTION - contents of dynabuf are not terminated! return 0; // ok } @@ -502,13 +504,14 @@ int Input_read_and_lower_keyword(void) // usage is stored there. // The file name given in the assembler source code is converted from // UNIX style to platform style. -// Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. +// Returns nonzero on error. Filename in GlobalDynaBuf. // Errors are handled and reported, but caller should call // Input_skip_remainder() then. int Input_read_filename(boolean allow_library, boolean *uses_lib) { + int start_of_string; char *lib_prefix, - end_quote; + terminator; DYNABUF_CLEAR(GlobalDynaBuf); SKIPSPACE(); @@ -519,7 +522,7 @@ int Input_read_filename(boolean allow_library, boolean *uses_lib) // if library access forbidden, complain if (!allow_library) { Throw_error("Writing to library not supported."); - return TRUE; + return 1; // error } // read platform's lib prefix @@ -528,43 +531,45 @@ int Input_read_filename(boolean allow_library, boolean *uses_lib) // if lib prefix not set, complain if (lib_prefix == NULL) { Throw_error("\"ACME\" environment variable not found."); - return TRUE; + return 1; // error } #endif // copy lib path and set quoting char DynaBuf_add_string(GlobalDynaBuf, lib_prefix); - end_quote = '>'; + terminator = '>'; } else { if (uses_lib) *uses_lib = FALSE; - if (GotByte == '"') { - end_quote = '"'; - } else { + if (GotByte != '"') { Throw_error("File name quotes not found (\"\" or <>)."); - return TRUE; + return 1; // error } + terminator = '"'; } - // read first character, complain if closing quote - if (GetQuotedByte() == end_quote) { + // remember border between optional library prefix and string from assembler source file + start_of_string = GlobalDynaBuf->size; + // read file name string + if (Input_quoted_to_dynabuf(terminator)) + return 1; // unterminated or escaping error + + GetByte(); // eat terminator + // check length + if (GlobalDynaBuf->size == start_of_string) { Throw_error("No file name given."); - return TRUE; + return 1; // error } -// FIXME - this will fail with backslash escaping! - // read characters until closing quote (or EOS) is reached - // append platform-converted characters to current string - while ((GotByte != CHAR_EOS) && (GotByte != end_quote)) { - DYNABUF_APPEND(GlobalDynaBuf, PLATFORM_CONVERTPATHCHAR(GotByte)); - GetQuotedByte(); - } - // on error, return - if (GotByte == CHAR_EOS) - return TRUE; + // resolve backslash escapes + if (Input_unescape_dynabuf(start_of_string)) + return 1; // escaping error - GetByte(); // fetch next to forget closing quote // terminate string - DynaBuf_append(GlobalDynaBuf, '\0'); // add terminator - return FALSE; // no error + DynaBuf_append(GlobalDynaBuf, '\0'); +#ifdef PLATFORM_CONVERTPATH + // platform-specific path name conversion + PLATFORM_CONVERTPATH(GLOBALDYNABUF_CURRENT + start_of_string); +#endif + return 0; // ok } // Try to read a comma, skipping spaces before and after. Return TRUE if comma @@ -674,5 +679,6 @@ FILE *includepaths_open_ro(boolean uses_lib) } if (stream == NULL) Throw_error(exception_cannot_open_input_file); + //fprintf(stderr, "File is [%s]\n", GLOBALDYNABUF_CURRENT); return stream; } diff --git a/src/input.h b/src/input.h index c2bb94d..c939917 100644 --- a/src/input.h +++ b/src/input.h @@ -76,7 +76,7 @@ extern int Input_quoted_to_dynabuf(char closing_quote); // process backslash escapes in GlobalDynaBuf (so size might shrink) // returns 1 on errors (escaping errors) -extern int Input_unescape_dynabuf(void); +extern int Input_unescape_dynabuf(int start_index); // Skip or store block (starting with next byte, so call directly after // reading opening brace). @@ -112,7 +112,7 @@ extern int Input_read_and_lower_keyword(void); // usage is stored there. // The file name given in the assembler source code is converted from // UNIX style to platform style. -// Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. +// Returns nonzero on error. Filename in GlobalDynaBuf. // Errors are handled and reported, but caller should call // Input_skip_remainder() then. extern int Input_read_filename(boolean library_allowed, boolean *uses_lib); diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index a23c71c..60359bb 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -380,7 +380,7 @@ static enum eos encode_string(const struct encoder *inner_encoder, char xor) // eat closing quote GetByte(); // now convert to unescaped version - if (Input_unescape_dynabuf()) + if (Input_unescape_dynabuf(0)) return SKIP_REMAINDER; // escaping error // send characters @@ -1208,7 +1208,7 @@ static enum eos throw_string(const char prefix[], void (*fn)(const char *)) // eat closing quote GetByte(); // now convert to unescaped version - if (Input_unescape_dynabuf()) + if (Input_unescape_dynabuf(0)) return SKIP_REMAINDER; // escaping error DynaBuf_append(GlobalDynaBuf, '\0'); // terminate string diff --git a/src/section.c b/src/section.c index 77e9f72..0541ffe 100644 --- a/src/section.c +++ b/src/section.c @@ -6,7 +6,7 @@ #include "section.h" #include "config.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "input.h" #include "symbol.h" #include "tree.h" diff --git a/src/symbol.c b/src/symbol.c index 5fef04b..75800a3 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -12,7 +12,7 @@ #include "acme.h" #include "alu.h" #include "dynabuf.h" -#include "global.h" // FIXME - remove when no longer needed +#include "global.h" #include "input.h" #include "output.h" #include "platform.h"