mirror of
https://github.com/uffejakobsen/acme.git
synced 2025-02-12 09:30:34 +00:00
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
This commit is contained in:
parent
5b0989ac31
commit
916bf9cbc8
@ -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)
|
||||
|
19
src/_dos.c
19
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 '/'
|
||||
|
@ -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?
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
60
src/input.c
60
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user