added check for absolute paths so current dir is not used as prefix

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@359 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye
2024-03-12 00:11:32 +00:00
parent dbf3cbd61e
commit b15c46e764
6 changed files with 54 additions and 38 deletions

View File

@@ -18,6 +18,7 @@ struct cpu_type {
boolean (*keyword_is_mnemonic)(int); boolean (*keyword_is_mnemonic)(int);
bits flags; // see below for bit meanings bits flags; // see below for bit meanings
unsigned char default_align_value; unsigned char default_align_value;
// TODO - add "reserved_keywords_maxlen"
}; };
#define CPUFLAG_INDIRECTJMPBUGGY (1u << 0) // warn if "jmp ($xxff)" is assembled #define CPUFLAG_INDIRECTJMPBUGGY (1u << 0) // warn if "jmp ($xxff)" is assembled
#define CPUFLAG_SUPPORTSLONGREGS (1u << 1) // allow "!al" and "!rl" pseudo opcodes #define CPUFLAG_SUPPORTSLONGREGS (1u << 1) // allow "!al" and "!rl" pseudo opcodes

View File

@@ -57,7 +57,7 @@ void input_parse_and_close_platform_file(const char *eternal_plat_filename, FILE
// be verbose // be verbose
if (config.process_verbosity >= 3) if (config.process_verbosity >= 3)
printf("Parsing source file '%s'.\n", eternal_plat_filename); printf("Parsing source file \"%s\".\n", eternal_plat_filename);
// set up new input // set up new input
new_input.plat_pathref_filename = eternal_plat_filename; new_input.plat_pathref_filename = eternal_plat_filename;
new_input.location.plat_filename = eternal_plat_filename; new_input.location.plat_filename = eternal_plat_filename;
@@ -666,21 +666,19 @@ static int read_filename_shared_end(void)
// try to read a file name for an input file. // try to read a file name for an input file.
// library access by using <...> quoting is allowed. // library access by using <...> quoting is allowed.
// if library access is used, TRUE will be stored via the "uses_lib" ptr. // flags for "library access" and "absolute path" will be set accordingly.
// if library access is not used, FALSE will be stored via the "uses_lib" ptr.
// The file name given in the assembler source code is converted from // The file name given in the assembler source code is converted from
// UNIX style to platform style. // UNIX style to platform style.
// Returns nonzero on error. Filename in GlobalDynaBuf. // Returns nonzero on error. Filename in GlobalDynaBuf.
// Errors are handled and reported, but caller should call // Errors are handled and reported, but caller should call
// input_skip_remainder() then. // input_skip_remainder() then.
int input_read_input_filename(boolean *uses_lib) int input_read_input_filename(struct filespecflags *flags)
{ {
dynabuf_clear(GlobalDynaBuf); dynabuf_clear(GlobalDynaBuf);
SKIPSPACE(); SKIPSPACE();
if (GotByte == '<') { if (GotByte == '<') {
// library access: // library access:
*uses_lib = TRUE; flags->uses_lib = TRUE;
// read file name string (must be a single string <literal>) // read file name string (must be a single string <literal>)
if (input_quoted_to_dynabuf('>')) if (input_quoted_to_dynabuf('>'))
return 1; // unterminated or escaping error return 1; // unterminated or escaping error
@@ -688,7 +686,7 @@ int input_read_input_filename(boolean *uses_lib)
GetByte(); // eat '>' terminator GetByte(); // eat '>' terminator
} else { } else {
// "normal", non-library access: // "normal", non-library access:
*uses_lib = FALSE; flags->uses_lib = FALSE;
// old algo (do not merge with similar parts from "if" block!): // old algo (do not merge with similar parts from "if" block!):
if (GotByte != '"') { if (GotByte != '"') {
Throw_error("File name quotes not found (\"\" or <>)."); Throw_error("File name quotes not found (\"\" or <>).");
@@ -705,6 +703,14 @@ int input_read_input_filename(boolean *uses_lib)
// FIXME - use expression parser to read filename string! // FIXME - use expression parser to read filename string!
// see lines 416 and 1317 in pseudoopcodes.c for two more possible callers! // see lines 416 and 1317 in pseudoopcodes.c for two more possible callers!
} }
// check if absolute
if ((GlobalDynaBuf->size)
&& (GlobalDynaBuf->buffer[0] == '/'))
flags->absolute = TRUE;
else
flags->absolute = FALSE;
// check length, unescape, terminate, do platform conversion // check length, unescape, terminate, do platform conversion
return read_filename_shared_end(); return read_filename_shared_end();
} }
@@ -852,6 +858,8 @@ void includepaths_add(const char *path)
// add filename (from GlobalDynaBuf) to pathbuf and try to open file: // add filename (from GlobalDynaBuf) to pathbuf and try to open file:
static FILE *combine_and_open_ro(void) static FILE *combine_and_open_ro(void)
{ {
FILE *stream;
// if path does not end with directory separator, add one: // if path does not end with directory separator, add one:
if (pathbuf->size if (pathbuf->size
&& (pathbuf->buffer[pathbuf->size - 1] != DIRECTORY_SEPARATOR) && (pathbuf->buffer[pathbuf->size - 1] != DIRECTORY_SEPARATOR)
@@ -863,26 +871,32 @@ static FILE *combine_and_open_ro(void)
// terminate // terminate
dynabuf_append(pathbuf, '\0'); dynabuf_append(pathbuf, '\0');
// try to open for reading // try to open for reading
return fopen(pathbuf->buffer, FILE_READBINARY); stream = fopen(pathbuf->buffer, FILE_READBINARY);
if (config.process_verbosity >= 9)
printf("Trying \"%s\"...%s\n", pathbuf->buffer, stream ? " OK!" : "");
return stream;
} }
// open file for reading // open file for reading
// "uses_lib" tells whether to use library prefix or to use search paths // "flags" decide whether library access, search paths or absolute path is wanted.
// file name is expected in GlobalDynaBuf, in platform style and terminated // file name is expected in GlobalDynaBuf, in platform style and terminated.
// returns NULL or open stream // returns NULL or open stream
// on success, GlobalDynaBuf contains full file name in platform style // on success, GlobalDynaBuf contains full file name in platform style
FILE *includepaths_open_ro(boolean uses_lib) FILE *includepaths_open_ro(struct filespecflags *flags)
{ {
FILE *stream; FILE *stream;
struct ipi *ipi; struct ipi *ipi;
if (uses_lib) { if (flags->uses_lib) {
// use library prefix // use library prefix
library_path_to_pathbuf(); library_path_to_pathbuf();
stream = combine_and_open_ro(); stream = combine_and_open_ro();
} else { } else {
// first try current default prefix // first try current default prefix
default_path_to_pathbuf(); if (flags->absolute)
dynabuf_clear(pathbuf); // which is "" if absolute
else
default_path_to_pathbuf(); // or current path if relative
stream = combine_and_open_ro(); stream = combine_and_open_ro();
if (stream == NULL) { if (stream == NULL) {
// default prefix failed, so try list entries: // default prefix failed, so try list entries:
@@ -890,12 +904,8 @@ FILE *includepaths_open_ro(boolean uses_lib)
dynabuf_clear(pathbuf); dynabuf_clear(pathbuf);
dynabuf_add_string(pathbuf, ipi->path); dynabuf_add_string(pathbuf, ipi->path);
stream = combine_and_open_ro(); stream = combine_and_open_ro();
//printf("trying <<%s>> - ", pathbuf->buffer);
if (stream) { if (stream) {
//printf("ok\n");
break; break;
} else {
//printf("failed\n");
} }
} }
} }
@@ -908,9 +918,11 @@ FILE *includepaths_open_ro(boolean uses_lib)
} else { } else {
// CAUTION, I'm re-using the path dynabuf to assemble the error message: // CAUTION, I'm re-using the path dynabuf to assemble the error message:
dynabuf_clear(pathbuf); dynabuf_clear(pathbuf);
dynabuf_add_string(pathbuf, "Cannot open input file \""); dynabuf_add_string(pathbuf, "Cannot open input file ");
dynabuf_append(pathbuf, flags->uses_lib ? '<' : '\"');
dynabuf_add_string(pathbuf, GLOBALDYNABUF_CURRENT); dynabuf_add_string(pathbuf, GLOBALDYNABUF_CURRENT);
dynabuf_add_string(pathbuf, "\"."); dynabuf_append(pathbuf, flags->uses_lib ? '>' : '\"');
dynabuf_append(pathbuf, '.');
dynabuf_append(pathbuf, '\0'); dynabuf_append(pathbuf, '\0');
Throw_error(pathbuf->buffer); Throw_error(pathbuf->buffer);
} }

View File

@@ -44,6 +44,10 @@ struct input {
char *ram_ptr; // RAM read ptr (loop or macro block) char *ram_ptr; // RAM read ptr (loop or macro block)
} src; } src;
}; };
struct filespecflags {
boolean uses_lib; // file name was given in <...> instead of "..."
boolean absolute; // file name started with '/'
};
// Constants // Constants
@@ -126,14 +130,13 @@ extern int input_read_and_lower_keyword(void);
// try to read a file name for an input file. // try to read a file name for an input file.
// library access by using <...> quoting is allowed. // library access by using <...> quoting is allowed.
// if library access is used, TRUE will be stored via the "uses_lib" ptr. // flags for "library access" and "absolute path" will be set accordingly.
// if library access is not used, FALSE will be stored via the "uses_lib" ptr.
// The file name given in the assembler source code is converted from // The file name given in the assembler source code is converted from
// UNIX style to platform style. // UNIX style to platform style.
// Returns nonzero on error. Filename in GlobalDynaBuf. // Returns nonzero on error. Filename in GlobalDynaBuf.
// Errors are handled and reported, but caller should call // Errors are handled and reported, but caller should call
// input_skip_remainder() then. // input_skip_remainder() then.
extern int input_read_input_filename(boolean *uses_lib); extern int input_read_input_filename(struct filespecflags *flags);
// try to read a file name for an output file ("!to" and "!sl" only). // try to read a file name for an output file ("!to" and "!sl" only).
// library access by using <...> quoting is forbidden. // library access by using <...> quoting is forbidden.
@@ -161,11 +164,11 @@ extern bits input_get_force_bit(void);
extern void includepaths_add(const char *path); extern void includepaths_add(const char *path);
// open file for reading // open file for reading
// "uses_lib" tells whether to use library prefix or to use search paths // "flags" decide whether library access, search paths or absolute path is wanted.
// file name is expected in GlobalDynaBuf, in platform style and terminated // file name is expected in GlobalDynaBuf, in platform style and terminated.
// returns NULL or open stream // returns NULL or open stream
// on success, GlobalDynaBuf contains full file name in platform style // on success, GlobalDynaBuf contains full file name in platform style
extern FILE *includepaths_open_ro(boolean uses_lib); extern FILE *includepaths_open_ro(struct filespecflags *flags);
#endif #endif

View File

@@ -1168,13 +1168,13 @@ static boolean check_mnemo_tree(struct ronode *tree, struct dynabuf *dyna_buf)
if (!tree_easy_scan(tree, &node_body, dyna_buf)) if (!tree_easy_scan(tree, &node_body, dyna_buf))
return FALSE; return FALSE;
code = ((int) node_body) & CODEMASK; // get opcode or table index code = ((intval_t) node_body) & CODEMASK; // get opcode or table index
flags = ((int) node_body) & FLAGSMASK; // get immediate mode flags and prefix flags flags = ((intval_t) node_body) & FLAGSMASK; // get immediate mode flags and prefix flags
if (flags & PREFIX_NEGNEG) { if (flags & PREFIX_NEGNEG) {
output_byte(0x42); output_byte(0x42);
output_byte(0x42); output_byte(0x42);
} }
switch (GROUP((long) node_body)) { switch (GROUP((intval_t) node_body)) {
case GROUP_ACCU: // main accumulator stuff case GROUP_ACCU: // main accumulator stuff
group_main(code, flags); group_main(code, flags);
break; break;

View File

@@ -362,18 +362,18 @@ static enum eos po_cbm(void)
// (allows for block, so must be reentrant) // (allows for block, so must be reentrant)
static enum eos use_encoding_from_file(void) static enum eos use_encoding_from_file(void)
{ {
boolean uses_lib; struct filespecflags flags;
FILE *stream; FILE *stream;
unsigned char local_table[256], unsigned char local_table[256],
*buffered_table; *buffered_table;
const struct encoder *buffered_encoder; const struct encoder *buffered_encoder;
// read file name and convert from UNIX style to platform style // read file name and convert from UNIX style to platform style
if (input_read_input_filename(&uses_lib)) if (input_read_input_filename(&flags))
return SKIP_REMAINDER; // if missing or unterminated, give up return SKIP_REMAINDER; // if missing or unterminated, give up
// read from file // read from file
stream = includepaths_open_ro(uses_lib); stream = includepaths_open_ro(&flags);
if (stream) { if (stream) {
// try to load encoding table from given file // try to load encoding table from given file
if (fread(local_table, sizeof(char), 256, stream) != 256) if (fread(local_table, sizeof(char), 256, stream) != 256)
@@ -538,7 +538,7 @@ static enum eos po_scrxor(void)
// FIXME - split this into "parser" and "worker" fn and move worker fn somewhere else. // FIXME - split this into "parser" and "worker" fn and move worker fn somewhere else.
static enum eos po_binary(void) static enum eos po_binary(void)
{ {
boolean uses_lib; struct filespecflags flags;
FILE *stream; FILE *stream;
int byte; int byte;
struct number size, struct number size,
@@ -548,11 +548,11 @@ static enum eos po_binary(void)
skip.val.intval = 0; skip.val.intval = 0;
// read file name and convert from UNIX style to platform style // read file name and convert from UNIX style to platform style
if (input_read_input_filename(&uses_lib)) if (input_read_input_filename(&flags))
return SKIP_REMAINDER; // if missing or unterminated, give up return SKIP_REMAINDER; // if missing or unterminated, give up
// try to open file // try to open file
stream = includepaths_open_ro(uses_lib); stream = includepaths_open_ro(&flags);
if (stream == NULL) if (stream == NULL)
return SKIP_REMAINDER; return SKIP_REMAINDER;
@@ -924,7 +924,7 @@ static enum eos po_subzone(void)
// include source file ("!source" or "!src"). has to be re-entrant. // include source file ("!source" or "!src"). has to be re-entrant.
static enum eos po_source(void) // now GotByte = illegal char static enum eos po_source(void) // now GotByte = illegal char
{ {
boolean uses_lib; struct filespecflags flags;
FILE *stream; FILE *stream;
const char *eternal_plat_filename; const char *eternal_plat_filename;
char local_gotbyte; char local_gotbyte;
@@ -935,11 +935,11 @@ static enum eos po_source(void) // now GotByte = illegal char
Throw_serious_error("Too deeply nested. Recursive \"!source\"?"); Throw_serious_error("Too deeply nested. Recursive \"!source\"?");
// read file name and convert from UNIX style to platform style // read file name and convert from UNIX style to platform style
if (input_read_input_filename(&uses_lib)) if (input_read_input_filename(&flags))
return SKIP_REMAINDER; // if missing or unterminated, give up return SKIP_REMAINDER; // if missing or unterminated, give up
// if file could be opened, parse it. otherwise, complain // if file could be opened, parse it. otherwise, complain
stream = includepaths_open_ro(uses_lib); stream = includepaths_open_ro(&flags);
if (stream) { if (stream) {
eternal_plat_filename = dynabuf_get_copy(GlobalDynaBuf); eternal_plat_filename = dynabuf_get_copy(GlobalDynaBuf);
local_gotbyte = GotByte; // CAUTION - ugly kluge local_gotbyte = GotByte; // CAUTION - ugly kluge

View File

@@ -9,7 +9,7 @@
#define RELEASE "0.97" // update before release FIXME #define RELEASE "0.97" // update before release FIXME
#define CODENAME "Zem" // update before release #define CODENAME "Zem" // update before release
#define CHANGE_DATE "2 Mar" // update before release FIXME #define CHANGE_DATE "3 Mar" // update before release FIXME
#define CHANGE_YEAR "2024" // update before release #define CHANGE_YEAR "2024" // update before release
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/"
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME