diff --git a/struse.h b/struse.h index 7d970dc..75e8f8a 100644 --- a/struse.h +++ b/struse.h @@ -35,6 +35,7 @@ Add this #define to *one* C++ file before #include "struse.h" to create the impl #ifndef __STRUSE_H__ #define __STRUSE_H__ +#include #include // memcpy, memmove #include // printf, vsnprintf #include // va_list @@ -75,13 +76,16 @@ protected: public: strref() { clear(); } strref(const char *str); + strref(char *str) : strref((const char*)str) {} strref(const char *str, strl_t len) : string(str), length(len) {} strref(const char *str, int len) : string(str), length(strl_t(len)) {} + strref(char *str, int len) : string((const char*)str), length(strl_t(len)) {} + strref(char *str, strl_t len) : string((const char*)str), length(len) {} bool valid() const { return string && length; } void clear() { string = nullptr; length = 0; } const char* get() const { return string; } - const unsigned char* get_u() const { return (const unsigned char*)string; } + const uint8_t* get_u() const { return (const uint8_t*)string; } strl_t get_len() const { return length; } char get_first() const { return (string && length) ? *string : 0; } char get_last() const { return (string && length) ? string[length-1] : 0; } @@ -99,12 +103,14 @@ public: unsigned int fnv1a(unsigned int seed = 2166136261) const; unsigned int fnv1a_lower(unsigned int seed = 2166136261) const; unsigned int fnv1a_append(unsigned int base_fnv1a_hash) const { return fnv1a(base_fnv1a_hash); } - + uint64_t fnv1a_64(uint64_t seed = 0xcbf29ce484222325ULL) const; + // whitespace ignore fnv1a (any sequence whitespace is replaced by one space) unsigned int fnv1a_ws(unsigned int seed = 2166136261) const; // convert string to basic integer - int atoi() const; + int64_t atoi() const; + uint64_t atoui() const; // convert string to floating point float atof() const; @@ -125,28 +131,32 @@ public: void writeln(); // is character empty such as space, tab, linefeed etc.? - static bool is_ws(unsigned char c) { return c <= ' '; } + static bool is_ws(uint8_t c) { return c <= ' '; } + static bool is_ws(char c) { return (uint8_t)c <= ' '; } // is character a number? - static bool is_number(unsigned char c) { return c>='0' && c<='9'; } + static bool is_number(uint8_t c) { return c>='0' && c<='9'; } + static bool is_number(char c) { return (uint8_t)c>='0' && (uint8_t)c<='9'; } // is character a hexadecimal number? - static bool is_hex(char c) { return is_number(c) || (c>='A' && c<='F') || (c>='a' && c<='f'); } + static bool is_hex(uint8_t c) { return is_number(c) || (c>='A' && c<='F') || (c>='a' && c<='f'); } + static bool is_hex(char c) { return is_hex(uint8_t(c)); } // is character alphabetic (A-Z or a-z)? - static bool is_alphabetic(unsigned char c) { return (c>='a' && c<='z') || (c>='A' && c<='Z'); } + static bool is_alphabetic(uint8_t c) { return (c>='a' && c<='z') || (c>='A' && c<='Z'); } // is character alphabetic or numeric? - static bool is_alphanumeric(char c) { return is_number(c) || is_alphabetic(c); } + static bool is_alphanumeric(uint8_t c) { return is_number(c) || is_alphabetic(c); } // is character valid as part of a label? (num, _, A-Z, a-z) - static bool is_valid_label(unsigned char c) { return c=='_' || is_alphanumeric(c); } + static bool is_valid_label(uint8_t c) { return c=='_' || is_alphanumeric(c); } // word separators are non-alphanumeric characters except apostrophe. - static bool is_sep_ws(unsigned char c) { return c!='\'' && !is_alphanumeric(c); } + static bool is_sep_ws(uint8_t c) { return c!='\'' && !is_alphanumeric(c); } + static bool is_sep_ws(char c) { return is_sep_ws(uint8_t(c)); } // is control character? (!-/, ?-@, [-^, {-~) - static bool is_control(unsigned char c) { return !is_ws(c) && !is_alphanumeric(c) && c!='_'; } + static bool is_control(uint8_t c) { return !is_ws(c) && !is_alphanumeric(c) && c!='_'; } // choice of upper/lowercase conversions static char tolower(char c); @@ -163,6 +173,7 @@ public: // operators // strref += int: move string forward (skip) void operator+=(const strl_t skip) { if (skip 0; } @@ -300,7 +315,7 @@ public: int find_last(char c, char d) const; // find first after last in string - int find_after_last(char a, char b) const { return find_after(b, find_last(a)+1); } + int find_after_last(char a, char b) const { return find_after(b, (strl_t)(find_last(a)+1)); } int find_after_last(char a1, char a2, char b) const { int w = find_last(a1, a2)+1; int l = strref(string+w, length-w).find(b); return l>=0?l+w:-1; } @@ -382,27 +397,31 @@ public: // number of white space characters from start of string strl_t len_whitespace() const { if (!valid()) return 0; - strl_t o = 0; while (o=0 && len='A')) + const uint8_t *s = get_u(); strl_t l = length; while (l) { + uint8_t c = *s++; if (!(c=='+' || c=='.' || c=='-' || is_number(c) || c>='A')) break; l--; } return strref(string, length-l); } strref before(char c) const { @@ -531,12 +553,13 @@ public: strref after_or_full_case(const strref str) const { int o = find_case(str); if (o<0) return *this; return strref(string+o, length-o); } - strref between(char c, char d) { int s = find(c); if (s>=0) { int e = find_after(d, s); - if (e>=0) return get_substr(s+1, e-s-1); } return strref(); } + strref between(char c, char d) { int s = find(c); if (s>=0) { int e = find_after(d, (strl_t)s); + if (e>=0) return get_substr(strl_t(s+1), strl_t(e-s-1)); } return strref(); } // tokenization strref split(strl_t pos) { pos = limit_pos(pos); strref ret = strref(string, pos); *this += pos; return ret; } - strref split_token(char c) { int t = find(c); if (t<0) t = (int)length; strref r = strref(string, t); *this += t+1; return r; } + strref split(int pos) { split(strl_t(pos)); } + strref split_token(char c) { int t = find(c); if (t<0) t = (int)length; strref r = strref(string, strl_t(t)); *this += t+1; return r; } strref split_token_any(const strref chars) { strref r; int t = find_any_char_of(chars); if (t>=0) { r = strref(string, t); *this += t; } return r; } strref split_token_trim(char c) { strref r = split_token(c); skip_whitespace(); r.trim_whitespace(); return r; } @@ -578,9 +601,9 @@ public: int find_quoted(char d) const; // returns length up to the delimiter d with c/c++ quotation rules, or -1 if delimiter not found strref next_chunk_xml(char open, char close) const { int s = find_quoted_xml(open); - if (s<0) return strref(); strref left = get_skipped(s+1); return left.get_clipped(left.find_quoted_xml(close)); } + if (s<0) return strref(); strref left = get_skipped(strl_t(s+1)); return left.get_clipped(strl_t(left.find_quoted_xml(close))); } strref next_chunk_quoted(char open, char close) const { int s = find_quoted(open); - if (s<0) return strref(); strref left = get_skipped(s+1); return left.get_clipped(left.find_quoted(close)); } + if (s<0) return strref(); strref left = get_skipped(strl_t(s+1)); return left.get_clipped(strl_t(left.find_quoted(close))); } void skip_chunk(const strref chunk) { strl_t add = strl_t(chunk.string-string)+chunk.length+1UL; if (addlen()) set_len(l+pos); va_end(args); return l; } - int sprintf_append(const char *format, ...) { va_list args; va_start(args, format); int l = 0; - if (len()='A' && c<='Z') - return c+'a'-'A'; + return (uint8_t)(c+'a'-'A'); if (c>=0x80) return _aMacOSRomanHigh_ToLower[c&0x7f]; return c; } -unsigned char int_toupper_macos_roman_ascii(unsigned char c) { +uint8_t int_toupper_macos_roman_ascii(uint8_t c) { if (c>='a' && c<='z') - return c+'A'-'a'; + return (uint8_t)(c+'A'-'a'); if (c>=0x80) return _aMacOSRomanHigh_ToUpper[c&0x7f]; return c; } -unsigned char int_tolower_amiga_ascii(unsigned char c) { +uint8_t int_tolower_amiga_ascii(uint8_t c) { if (c>='A' && c<='Z') - return c+'a'-'A'; + return (uint8_t)(c+'a'-'A'); if (c>=0xc0 && c<0xe0) - return c+0x20; + return (uint8_t)(c+0x20); return c; } -unsigned char int_toupper_amiga_ascii(unsigned char c) { +uint8_t int_toupper_amiga_ascii(uint8_t c) { if (c>='a' && c<='z') - return c+'A'-'a'; + return (uint8_t)(c+'A'-'a'); if (c>=0xe0) - return c-0x20; + return (uint8_t)(c-0x20); return c; } -unsigned char int_toupper_win_ascii(unsigned char c) { +uint8_t int_toupper_win_ascii(uint8_t c) { if (c<'a') return c; if (c<='z') - return c+'A'-'a'; + return (uint8_t)(c+'A'-'a'); switch (c) { case 0x84: return 0x83; @@ -1156,11 +1177,11 @@ unsigned char int_toupper_win_ascii(unsigned char c) { return c; } -unsigned char int_tolower_win_ascii(unsigned char c) { +uint8_t int_tolower_win_ascii(uint8_t c) { if (c<'A') return c; if (c<='Z') - return c+'a'-'A'; + return (uint8_t)(c+'a'-'A'); switch (c) { case 0x8e: return 0x84; @@ -1249,40 +1270,40 @@ size_t int_toupper_unicode(size_t c) } // english latin lowercase -unsigned char int_tolower_ascii7(unsigned char c) +uint8_t int_tolower_ascii7(uint8_t c) { if (c<='Z' && c>='A') - return c+'a'-'A'; + return (uint8_t)(c+'a'-'A'); return c; } // english latin uppercase -unsigned char int_toupper_ascii7(unsigned char c) +uint8_t int_toupper_ascii7(uint8_t c) { if (c>='a' && c<='z') - return c+'A'-'a'; + return (uint8_t)(c+'A'-'a'); return c; } // convert escape codes to characters // supports: \a, \b, \f, \n, \r, \t, \v, \000, \x00 // any other character is returned as same -static strl_t int_get_esc_code(const unsigned char *buf, strl_t left, unsigned char &code) +static strl_t int_get_esc_code(const uint8_t *buf, strl_t left, uint8_t &code) { strl_t step = 0; if (!left) return step; - char c = *buf++; + uint8_t c = *buf++; left--; step++; if (c=='x' && left && strref::is_hex(*buf)) { // parse hex char code c = 0; for (int r = 0; r<2 && left; r++) { - char n = *buf++; + uint8_t n = *buf++; if (!strref::is_hex(n)) break; - c = (c<<4) + n - (n<='9' ? '0' : (n<='F'?('A'-0xA) : ('a'-0xa))); + c = (uint8_t)((c<<4) + n - (n<='9' ? '0' : (n<='F'?('A'-0xA) : ('a'-0xa)))); step++; left--; } @@ -1290,10 +1311,10 @@ static strl_t int_get_esc_code(const unsigned char *buf, strl_t left, unsigned c // parse octal char code c -= '0'; for (int r = 0; r<2 && left; r++) { - char n = *buf++; + uint8_t n = *buf++; if (n<'0' || n>'7') break; - c = c*8 + n-'0'; + c = (uint8_t)(c*8 + n-'0'); step++; left--; } @@ -1328,16 +1349,16 @@ static strl_t int_get_esc_code(const unsigned char *buf, strl_t left, unsigned c } // tolower/toupper implementation -char strref::tolower(char c) { return int_tolower_ascii7(c); } -char strref::toupper(char c) { return int_toupper_ascii7(c); } -char strref::tolower_win(char c) { return int_tolower_win_ascii(c); } -char strref::toupper_win(char c) { return int_toupper_win_ascii(c); } -char strref::tolower_amiga(char c) { return int_tolower_amiga_ascii(c); } -char strref::toupper_amiga(char c) { return int_toupper_amiga_ascii(c); } -char strref::tolower_macos(char c) { return int_tolower_macos_roman_ascii(c); } -char strref::toupper_macos(char c) { return int_toupper_macos_roman_ascii(c); } -size_t strref::tolower_unicode(int c) { return int_tolower_unicode(c); } -size_t strref::toupper_unicode(int c) { return int_toupper_unicode(c); } +char strref::tolower(char c) { return (char)int_tolower_ascii7((uint8_t)c); } +char strref::toupper(char c) { return (char)int_toupper_ascii7((uint8_t)c); } +char strref::tolower_win(char c) { return (char)int_tolower_win_ascii((uint8_t)c); } +char strref::toupper_win(char c) { return (char)int_toupper_win_ascii((uint8_t)c); } +char strref::tolower_amiga(char c) { return (char)int_tolower_amiga_ascii((uint8_t)c); } +char strref::toupper_amiga(char c) { return (char)int_toupper_amiga_ascii((uint8_t)c); } +char strref::tolower_macos(char c) { return (char)int_tolower_macos_roman_ascii((uint8_t)c); } +char strref::toupper_macos(char c) { return (char)int_toupper_macos_roman_ascii((uint8_t)c); } +size_t strref::tolower_unicode(int c) { return int_tolower_unicode((size_t)c); } +size_t strref::toupper_unicode(int c) { return int_toupper_unicode((size_t)c); } // use printf to print current string on a single line void strref::writeln() @@ -1376,6 +1397,18 @@ unsigned int strref::fnv1a(unsigned int seed) const return hash; } +uint64_t strref::fnv1a_64(uint64_t seed) const +{ + uint64_t hash = seed; + if (string) { + unsigned const char *scan = (unsigned const char*)string; + strl_t left = length; + while (left--) + hash = (*scan++ ^ hash) * 0x100000001b3ULL; + } + return hash; +} + // get lowercase fnv1a hash of a string unsigned int strref::fnv1a_lower(unsigned int seed) const { @@ -1394,7 +1427,7 @@ unsigned int strref::fnv1a_ws(unsigned int seed) const unsigned int hash = seed; strl_t left = length; while (left--) { - unsigned char c = *scan++; + uint8_t c = *scan++; if (c<' ') c = ' '; hash = (*scan++ ^ hash) * 16777619; @@ -1409,33 +1442,44 @@ unsigned int strref::fnv1a_ws(unsigned int seed) const } // convert numeric string to integer -int strref::atoi() const +int64_t strref::atoi() const { - if (!string) - return 0; - const char *s = string; - strl_t l = length; - while (l && s && *s<=0x20) { - s++; - l--; + if (string) { + const unsigned char *s = get_u(); + const unsigned char *e = s + length; + while (s!=e && *s<=0x20) s++; + if (s'9') break; + v = c-'0' + v*10; + } + return neg ? -v : v; + } } - if (!l) - return 0; - bool neg = false; - if (*s=='-') { - neg = true; - l--; - s++; + return 0; +} + +uint64_t strref::atoui() const +{ + if (string) { + const unsigned char *s = get_u(); + const unsigned char *e = s + length; + while (s!=e && *s<=0x20) s++; + if (s'9') break; + v = c-'0' + v*10; + } + return v; + } } - int v = 0; - while (l) { - char c = *s++; - l--; - if (c<'0' || c>'9') - break; - v = c-'0' + v*10; - } - return neg ? -v : v; + return 0; } // convert numeric string into floating point value @@ -1559,7 +1603,7 @@ size_t strref::abinarytoui_skip() return 0; strl_t bin = 0; while (left) { - unsigned char c = (unsigned char)*scan; + uint8_t c = (uint8_t)*scan; if (c<'0' || c>'1') break; scan++; @@ -1758,7 +1802,7 @@ static bool int_compare_substr_case(const char *scan, strl_t length, const char } // compare a string with a substring case sensitive -static bool int_compare_substr(const char *scan, strl_t length, const char *check, strl_t chk_len) +static bool int_compare_substr(const uint8_t *scan, strl_t length, const uint8_t *check, strl_t chk_len) { if (length < chk_len) return false; @@ -1807,7 +1851,7 @@ int _find_rh_case(const char *text, strl_t length, const char *comp, strl_t comp } // case ignore rolling hash find substring -int _find_rh(const char *text, strl_t length, const char *comp, strl_t comp_length) +int _find_rh(const uint8_t *text, strl_t length, const uint8_t *comp, strl_t comp_length) { if (length < comp_length) return -1; @@ -1815,7 +1859,7 @@ int _find_rh(const char *text, strl_t length, const char *comp, strl_t comp_leng size_t roll_hash = 0; size_t hash = 0; size_t hash_remove = 1; - const char *rem = text; + const uint8_t *rem = text; // generate compare hash for (strl_t cl = 0; cl length) return false; - return int_compare_substr(string + pos, length - pos, str.string, str.length); + return int_compare_substr(get_u() + pos, length - pos, str.get_u(), str.length); } // allow escape codes in search string @@ -1929,11 +1973,11 @@ bool strref::same_substr_esc(const strref str, strl_t pos) const { if (pos >= length) return false; - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); strl_t compare_left = str.length; while (compare_left) { - unsigned char c = (unsigned char)*compare++; + uint8_t c = (uint8_t)*compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -1959,11 +2003,11 @@ bool strref::same_substr_case_esc(const strref str, strl_t pos) const { if (pos >= length) return false; - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); strl_t compare_left = str.length; while (compare_left) { - unsigned char c = (unsigned char)*compare++; + uint8_t c = (uint8_t)*compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -2066,12 +2110,12 @@ bool strref::same_str(const strref str, char same1, char same2) const if (length!=str.length) return false; - const char *scan = string; - const char *compare = str.string; + const uint8_t *scan = get_u(); + const uint8_t *compare = str.get_u(); strl_t left = length; while (left) { - char c1 = int_tolower_ascii7(*scan++); - char c2 = int_tolower_ascii7(*compare++); + uint8_t c1 = int_tolower_ascii7(*scan++); + uint8_t c2 = int_tolower_ascii7(*compare++); if (c1!=c2 && !(c1==same1 && c2==same2) && !(c1==same2 && c2==same1)) return false; left--; @@ -2085,10 +2129,14 @@ bool strref::same_str(const char *compare) const if (!*compare || !valid()) return false; - const char *scan = string; + const uint8_t *scan = get_u(); + const uint8_t *cmp = (const uint8_t*)compare; strl_t left = length; - char c; - while ((c = *compare++) && left) { + uint8_t c; + for (;;) { + c = *cmp++; + if (c == 0 || !left) + break; if (int_tolower_ascii7(*scan++)!=int_tolower_ascii7(c)) return false; left--; @@ -2133,7 +2181,10 @@ bool strref::same_str_case(const char *str) const char *scan = string; strl_t left = length; char c; - while ((c = *str++) && left) { + for (;;) { + c = *str++; + if (c == 0 || !left) + break; if (*scan++!=c) return false; left--; @@ -2144,8 +2195,8 @@ bool strref::same_str_case(const char *str) // count how many characters match from start between two strings strl_t strref::prefix_len(const strref str) const { - const char *scan = string; - const char *compare = str.string; + const uint8_t *scan = get_u(); + const uint8_t *compare = str.get_u(); if (!scan || !compare) return 0; @@ -2165,14 +2216,14 @@ strl_t strref::prefix_len(const strref str) const // character same1 is considered equal to same2 strl_t strref::prefix_len(const strref str, char same1, char same2) const { - const char *scan = string; - const char *compare = str.string; + const uint8_t *scan = get_u(); + const uint8_t *compare = str.get_u(); strl_t left = length=find_len) { if (int_tolower_ascii7(*scan++)==c) { @@ -2296,17 +2347,17 @@ int strref::find_bookend(const strref str, const strref bookend) const if (!str.valid() || !valid() || length= find_len) { - char d = int_tolower_ascii7(*scan++); + uint8_t d = int_tolower_ascii7(*scan++); if (d == c && (left == length || bookend.char_matches_ranges(p)) && (left == find_len || bookend.char_matches_ranges(int_tolower_ascii7(scan[find_len-1])))) { if (int_compare_substr(scan, left - 1, compare, find_len - 1)) @@ -2323,13 +2374,13 @@ int strref::find(const strref str, strl_t pos) const if (!str.valid() || !valid() || length= find_len) { if (int_tolower_ascii7(*scan++) == c) { if (int_compare_substr(scan, left - 1, compare, find_len - 1)) @@ -2348,15 +2399,15 @@ int strref::find_esc(const strref str, strl_t pos) const return -1; // start scan buffer pointers - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); // number of characters left in each buffer strl_t scan_left = length - pos; strl_t compare_left = str.length; // get first character - unsigned char c = (unsigned char)*compare++; + uint8_t c = (uint8_t)*compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -2367,12 +2418,12 @@ int strref::find_esc(const strref str, strl_t pos) const // sweep the scan buffer for the matching string while (scan_left) { if (*scan++ == c) { - const unsigned char *chk_scan = scan; - const unsigned char *chk_compare = compare; + const uint8_t *chk_scan = scan; + const uint8_t *chk_compare = compare; strl_t chk_scan_left = scan_left; strl_t chk_compare_left = compare_left; while (chk_compare_left) { - unsigned char d = *chk_compare++; + uint8_t d = *chk_compare++; chk_compare_left--; if (d=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, d); @@ -2399,21 +2450,22 @@ int strref::find(const char *str) const if (!str || !valid()) return -1; - char c = int_tolower_ascii7(*str++); + const uint8_t *stru = (const uint8_t*)str; + uint8_t c = int_tolower_ascii7(*stru++); if (!c) return 0; - const char *scan = string; - const char *compare = str; + const uint8_t *scan = get_u(); + const uint8_t *compare = stru; strl_t l = length; while (l) { if (int_tolower_ascii7(*scan++)==c) { bool equal = true; - const char *scan_chk = scan; - while (char c2 = *compare++) { + const uint8_t *scan_chk = scan; + while (uint8_t c2 = *compare++) { if (int_tolower_ascii7(*scan_chk++)!=int_tolower_ascii7(c2)) { - compare = str; + compare = stru; equal = false; break; } @@ -2463,15 +2515,15 @@ int strref::find_case_esc(const strref str, strl_t pos) const return -1; // start scan buffer pointers - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); // number of characters left in each buffer strl_t scan_left = length - pos; strl_t compare_left = str.length; // get first character - unsigned char c = *compare++; + uint8_t c = *compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -2482,12 +2534,12 @@ int strref::find_case_esc(const strref str, strl_t pos) const // sweep the scan buffer for the matching string while (scan_left) { if (*scan++ == c) { - const unsigned char *chk_scan = scan; - const unsigned char *chk_compare = compare; + const uint8_t *chk_scan = scan; + const uint8_t *chk_compare = compare; strl_t chk_scan_left = scan_left; strl_t chk_compare_left = compare_left; while (chk_compare_left) { - unsigned char d = *chk_compare++; + uint8_t d = *chk_compare++; chk_compare_left--; if (d=='\\' && chk_compare_left) { strl_t skip = int_get_esc_code(chk_compare, chk_compare_left, d); @@ -2522,12 +2574,12 @@ static strref int_check_exclude(strref range, bool &include) } // checks if character c matches range -static bool int_char_match_range_case(char c, const unsigned char *rng_chk, strl_t rng_lft) +static bool int_char_match_range_case(uint8_t c, const uint8_t *rng_chk, strl_t rng_lft) { // no match yet, check skipped character against allowed range bool match = false; while (rng_lft) { - unsigned char m = *rng_chk++; + uint8_t m = *rng_chk++; rng_lft--; // escape code? if (m == '\\' && rng_lft) { @@ -2539,7 +2591,7 @@ static bool int_char_match_range_case(char c, const unsigned char *rng_chk, strl if (rng_lft>1 && *rng_chk == '-') { rng_chk++; rng_lft--; - unsigned char n = (unsigned char)*rng_chk++; + uint8_t n = (uint8_t)*rng_chk++; rng_lft--; // escape code for range end? if (n == '\\' && rng_lft) { @@ -2561,12 +2613,12 @@ static bool int_char_match_range_case(char c, const unsigned char *rng_chk, strl } // checks if character c matches range -static bool int_char_match_range(char c, const unsigned char *rng_chk, strl_t rng_lft) +static bool int_char_match_range(uint8_t c, const uint8_t *rng_chk, strl_t rng_lft) { // no match yet, check skipped character against allowed range bool match = false; while (rng_lft) { - unsigned char m = (unsigned char)*rng_chk++; + uint8_t m = (uint8_t)*rng_chk++; rng_lft--; // escape code? if (m == '\\' && rng_lft) { @@ -2578,7 +2630,7 @@ static bool int_char_match_range(char c, const unsigned char *rng_chk, strl_t rn if (rng_lft>1 && *rng_chk == '-') { rng_chk++; rng_lft--; - unsigned char n = (unsigned char)*rng_chk++; + uint8_t n = (uint8_t)*rng_chk++; rng_lft--; // escape code for range end? if (n == '\\' && rng_lft) { @@ -2606,15 +2658,15 @@ int strref::find_case_esc_range(const strref str, const strref range, strl_t pos return -1; // start scan buffer pointers - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); // number of characters left in each buffer strl_t scan_left = length - pos; strl_t compare_left = str.length; // get first character - unsigned char c = *compare++; + uint8_t c = *compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -2628,24 +2680,24 @@ int strref::find_case_esc_range(const strref str, const strref range, strl_t pos // sweep the scan buffer for the matching string while (scan_left) { - unsigned char b = (unsigned char)*scan++; + uint8_t b = (uint8_t)*scan++; // check for string match if (b == c) { - const unsigned char *chk_scan = scan; - const unsigned char *chk_compare = compare; + const uint8_t *chk_scan = scan; + const uint8_t *chk_compare = compare; strl_t chk_scan_left = scan_left; strl_t chk_compare_left = compare_left; while (chk_compare_left) { - unsigned char d = *chk_compare++; + uint8_t d = *chk_compare++; chk_compare_left--; - unsigned char e = *chk_scan++; + uint8_t e = *chk_scan++; chk_scan_left--; if (d=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, d); compare += skip; compare_left -= skip; } - if (c!=d) { + if (e!=d) { chk_compare_left = 1; break; } @@ -2672,15 +2724,15 @@ int strref::find_esc_range(const strref str, const strref range, strl_t pos) con return -1; // start scan buffer pointers - const unsigned char *scan = get_u() + pos; - const unsigned char *compare = str.get_u(); + const uint8_t *scan = get_u() + pos; + const uint8_t *compare = str.get_u(); // number of characters left in each buffer strl_t scan_left = length - pos; strl_t compare_left = str.length; // get first character - unsigned char c = *compare++; + uint8_t c = *compare++; compare_left--; if (c=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, c); @@ -2694,24 +2746,24 @@ int strref::find_esc_range(const strref str, const strref range, strl_t pos) con // sweep the scan buffer for the matching string while (scan_left) { - unsigned char b = int_tolower_ascii7(*scan++); + uint8_t b = int_tolower_ascii7(*scan++); // check for string match if (b == c) { - const unsigned char *chk_scan = scan; - const unsigned char *chk_compare = compare; + const uint8_t *chk_scan = scan; + const uint8_t *chk_compare = compare; strl_t chk_scan_left = scan_left; strl_t chk_compare_left = compare_left; while (chk_compare_left) { - unsigned char d = int_tolower_ascii7(*chk_compare++); + uint8_t d = int_tolower_ascii7(*chk_compare++); chk_compare_left--; - unsigned char e = int_tolower_ascii7(*chk_scan++); + uint8_t e = int_tolower_ascii7(*chk_scan++); chk_scan_left--; if (d=='\\' && compare_left) { strl_t skip = int_get_esc_code(compare, compare_left, d); compare += skip; compare_left -= skip; } - if (c!=d) { + if (e!=d) { chk_compare_left = 1; break; } @@ -2771,17 +2823,17 @@ int strref::find_last(const strref str) const if (!str.valid() || !valid() || length0) { left--; if (int_tolower_ascii7(*--scan)==c) { - const char *scan_chk = scan; - const char *cmp_chk = compare; + const uint8_t *scan_chk = scan; + const uint8_t *cmp_chk = compare; strl_t left_check = str.length; while (--left_check) { if (int_tolower_ascii7(*--scan_chk)!=int_tolower_ascii7(*--cmp_chk)) { @@ -2802,18 +2854,18 @@ int strref::find_last_bookend(const strref str, const strref bookend) const if (!str.valid() || !valid() || length0) { left--; - char d = int_tolower_ascii7(*--scan); + uint8_t d = int_tolower_ascii7(*--scan); if (d == c && (left==length || bookend.char_matches_ranges(p))) { - const char *scan_chk = scan; - const char *cmp_chk = compare; + const uint8_t *scan_chk = scan; + const uint8_t *cmp_chk = compare; strl_t left_check = str.length; while (--left_check) { if (int_tolower_ascii7(*--scan_chk) != int_tolower_ascii7(*--cmp_chk)) { @@ -2822,7 +2874,7 @@ int strref::find_last_bookend(const strref str, const strref bookend) const } } if (!left_check) { - if (string == scan_chk || bookend.char_matches_ranges(int_tolower_ascii7(*--scan_chk))) + if (get_u() == scan_chk || bookend.char_matches_ranges(int_tolower_ascii7(*--scan_chk))) return int(left - str.length + 1); } } @@ -2837,23 +2889,23 @@ int strref::find_last(const char *str) const if (!str || !*str || !valid()) return -1; - const char *scan = string+length; - const char *compare = str + strlen(str); - unsigned char c = int_tolower_ascii7(*--compare); + const uint8_t *scan = get_u()+length; + const uint8_t *compare = (const uint8_t*)str + strlen(str); + uint8_t c = int_tolower_ascii7(*--compare); int l = (int)length; while (l>=0) { l--; if (int_tolower_ascii7(*--scan)==c) { - const char *scan_chk = scan; - const char *cmp_chk = compare; - while (cmp_chk>str) { + const uint8_t *scan_chk = scan; + const uint8_t *cmp_chk = compare; + while (cmp_chk>(const uint8_t*)str) { if (int_tolower_ascii7(*--scan_chk)!=int_tolower_ascii7(*--cmp_chk)) { cmp_chk = compare; break; } } - if (cmp_chk==str) - return int(scan_chk-string); + if (cmp_chk==(const uint8_t*)str) + return int(scan_chk-(const uint8_t*)string); } } return -1; @@ -2896,19 +2948,19 @@ int strref::substr_count(const strref str) const return 0; int count = 0; - const char *scan = string; + const uint8_t *scan = get_u(); strl_t left = length; strl_t substrlen = str.length; - char c = int_tolower_ascii7(str.get_first()); + uint8_t c = int_tolower_ascii7((uint8_t)str.get_first()); while (left>=substrlen) { while (left && int_tolower_ascii7(*scan++)!=c) left--; if (left && left>=substrlen) { // first character matches and enough characters remain for a potential match - const char *compare = str.string+1; + const uint8_t *compare = str.get_u()+1; strl_t sr = substrlen-1; - const char *scan_chk = scan; + const uint8_t *scan_chk = scan; while (sr && int_tolower_ascii7(*compare++)==int_tolower_ascii7(*scan_chk++)) sr--; if (sr==0) { @@ -2928,16 +2980,16 @@ int strref::substr_count_bookend(const strref str, const strref bookend) const return 0; int count = 0; - const char *scan = string; + const uint8_t *scan = get_u(); strl_t left = length; strl_t substrlen = str.length; - char c = int_tolower_ascii7(str.get_first()); - char p = 0; + uint8_t c = int_tolower_ascii7((uint8_t)str.get_first()); + uint8_t p = 0; while (left >= substrlen) { while (left) { - char d = int_tolower_ascii7(*scan++); + uint8_t d = int_tolower_ascii7(*scan++); if (d == c && bookend.char_matches_ranges(p)) break; p = d; @@ -2945,12 +2997,12 @@ int strref::substr_count_bookend(const strref str, const strref bookend) const } if (left && left >= substrlen) { // first character matches and enough characters remain for a potential match - const char *compare = str.string + 1; + const uint8_t *compare = str.get_u() + 1; strl_t sr = substrlen - 1; - const char *scan_chk = scan; + const uint8_t *scan_chk = scan; while (sr && int_tolower_ascii7(*compare++) == int_tolower_ascii7(*scan_chk++)) sr--; - if (sr == 0 && (scan_chk == (string + length) || bookend.char_matches_ranges(int_tolower_ascii7(*scan_chk++)))) { + if (sr == 0 && (scan_chk == (get_u() + length) || bookend.char_matches_ranges(int_tolower_ascii7(*scan_chk++)))) { scan = scan_chk; left -= substrlen - 1; count++; @@ -2999,14 +3051,14 @@ int strref::substr_label_case_count(const strref str) const return 0; int count = 0; - const char *scan = string; + const uint8_t *scan = get_u(); strl_t left = length; strl_t substrlen = str.length; - char c = str.get_first(), p=0; + uint8_t c = (uint8_t)str.get_first(), p=0; while (left>=substrlen) { while (left) { - char d = *scan++; + uint8_t d = *scan++; if (d==c) break; left--; @@ -3016,7 +3068,7 @@ int strref::substr_label_case_count(const strref str) const // first character matches and enough characters remain for a potential match const char *compare = str.string+1; strl_t sr = substrlen-1; - const char *scan_chk = scan; + const uint8_t *scan_chk = scan; while (sr && *compare++==*scan_chk++) sr--; if (sr==0) { @@ -3110,7 +3162,7 @@ int strref::find_any_char_of(const strref range, strl_t pos) const { static int int_find_range(const char *scan, strl_t left, strl_t length, strref rng, bool include) { while (left) { - unsigned char c = (unsigned char)*scan++; + uint8_t c = (uint8_t)*scan++; bool match = int_char_match_range_case(c, rng.get_u(), rng.get_len()); if ((match && include) || (!match && !include)) return int(length - left); @@ -3140,7 +3192,7 @@ strref strref::get_range_word(const strref range, strl_t pos) const bool include; strref rng = int_check_exclude(range, include); - return get_substr(0, int_find_range(string + pos, length - pos, length, rng, !include)); + return get_substr(0, (strl_t)int_find_range(string + pos, length - pos, length, rng, !include)); } int strref::find_any_not_in_range(const strref range, strl_t pos) const { @@ -3173,7 +3225,7 @@ int strref::find_range_char_within_range(const strref range_find, const strref r strref rng_w = int_check_exclude(range_within, include_within); while (l) { - unsigned char c = (unsigned char)*scan++; + uint8_t c = (uint8_t)*scan++; bool match_find = int_char_match_range_case(c, rng_f.get_u(), rng_f.get_len()); if ((match_find && include_find) || (!match_find && !include_find)) return int(length - l); @@ -3190,7 +3242,7 @@ int strref::find_range_char_within_range(const strref range_find, const strref r } // check if character matches a given range (this) -bool strref::char_matches_ranges(unsigned char c) const { +bool strref::char_matches_ranges(uint8_t c) const { // check if range is inclusive or exclusive bool include; strref rng = int_check_exclude(*this, include); @@ -3205,11 +3257,11 @@ strl_t strref::match_chars_str(const strref match, const strref term) bool include_match, include_term; strref rng = int_check_exclude(match, include_match); strref trm = int_check_exclude(term, include_term); - int ret = 0; - const char *str = string; + strl_t ret = 0; + const uint8_t *str = get_u(); strl_t left = length; while (left) { - char c = *str++; + uint8_t c = *str++; if (include_match == int_char_match_range_case(c, rng.get_u(), rng.get_len())) { ret++; } else if (!term || include_term == int_char_match_range_case(c, trm.get_u(), trm.get_len())) { @@ -3293,11 +3345,11 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in // check for number of search segments / number of search steps overflow if (numSeg > (MAX_WILDCARD_SEGMENTS-4) || numType > (MAX_WILDCARD_STEPS-2)) return strref(); - int next_pos = wild.find_any_char_of(_wildcard_control, pos); + int next_pos = wild.find_any_char_of(_wildcard_control, (strl_t)pos); if (next_pos<0) { // completed? (found no wildcard token) // add last segment if there was one if (wild.get_len() > (strl_t)last) { - segs[numSeg++] = wild.get_substr(last, wild.get_len()-last); + segs[numSeg++] = wild.get_substr((strl_t)last, wild.get_len()-(strl_t)last); if (search && range) segs[numSeg++] = range; type[numType++] = (char)(search ? (range ? WCST_FIND_SUBSTR_RANGE : WCST_FIND_SUBSTR) : WCST_NEXT_SUBSTR); @@ -3308,10 +3360,10 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in range.clear(); break; } - switch (wild.get_at(next_pos)) { + switch (wild.get_at((strl_t)next_pos)) { case '*': // * => any substring with optional filter if (next_pos > last) { - segs[numSeg++] = wild.get_substr(last, next_pos-last); + segs[numSeg++] = wild.get_substr((strl_t)last, (strl_t)(next_pos-last)); if (search && range) segs[numSeg++] = range; type[numType++] = (char)(search ? (range ? WCST_FIND_SUBSTR_RANGE : WCST_FIND_SUBSTR) : WCST_NEXT_SUBSTR); @@ -3322,9 +3374,9 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in if (strl_t(pos) < wild.get_len()) { switch (wild[pos]) { case '{': { // user defined character filter - int range_end = wild.find_after('}', pos); + int range_end = wild.find_after('}', (strl_t)pos); if (range_end > 0) { - range = wild.get_substr(pos+1, range_end-pos-1); + range = wild.get_substr(strl_t(pos+1), strl_t(range_end-pos-1)); last = pos = range_end + 1; } else pos++; @@ -3349,7 +3401,7 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in case '<': // < = first character of word if (next_pos > last) { - segs[numSeg++] = wild.get_substr(last, next_pos-last); + segs[numSeg++] = wild.get_substr((strl_t)last, strl_t(next_pos-last)); if (search && range) segs[numSeg++] = range; type[numType++] = (char)(search ? (range ? WCST_FIND_SUBSTR_RANGE : WCST_FIND_SUBSTR) : WCST_NEXT_SUBSTR); @@ -3366,7 +3418,7 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in case '>': // > = first character after word if (next_pos > last) { - segs[numSeg++] = wild.get_substr(last, next_pos-last); + segs[numSeg++] = wild.get_substr(strl_t(last), strl_t(next_pos-last)); if (search && range) segs[numSeg++] = range; type[numType++] = (char)(search ? (range ? WCST_FIND_SUBSTR_RANGE : WCST_FIND_SUBSTR) : WCST_NEXT_SUBSTR); @@ -3444,7 +3496,7 @@ static int _build_wildcard_steps(const strref wild, strref *segs, char *type, in break; case '[': { // [..] = limited range character - int close_pos = wild.find_after(']', next_pos+1); + int close_pos = wild.find_after(']', strl_t(next_pos+1)); if (close_pos>=1) { if (next_pos > last) { segs[numSeg++] = wild.get_substr(last, next_pos-last); @@ -3496,7 +3548,7 @@ strref strref::find_wildcard(const strref wild, strl_t start, bool case_sensitiv int step = 0; while (step5) left = 5; - unsigned char f = *scan++; + uint8_t f = *scan++; size_t c = f, mask = 0x80; while ((mask&c) && left) { - unsigned char n = *scan++; + uint8_t n = *scan++; c = (c<<6)|(n&0x3f); mask <<= 5; left--; @@ -3813,22 +3865,22 @@ size_t strref::get_utf8() const size_t strref::pop_utf8() { if (!valid()) -return 0; -const char *scan = string; -strl_t left = length-1; -if (left>5) -left = 5; -unsigned char f = *scan++; -size_t c = f, m = 0x80; -while ((m&c) && left) { - unsigned char n = *scan++; - c = (c<<6)|(n&0x3f); - m <<= 5; - left--; -} -length -= strl_t(scan-string); -string = scan; -return c; + return 0; + const uint8_t *scan = get_u(); + strl_t left = length-1; + if (left>5) + left = 5; + uint8_t f = *scan++; + size_t c = f, m = 0x80; + while ((m&c) && left) { + uint8_t n = *scan++; + c = (c<<6)|(n&0x3f); + m <<= 5; + left--; + } + length -= strl_t((const char*)scan - string); + string = (const char*)scan; + return c; } bool strref::valid_ascii7() const @@ -4127,11 +4179,11 @@ strl_t _strmod_insert(char *string, strl_t length, strl_t cap, const strref sub, *--dst = *--src; } const char *src = sub.get(); - char *dst = string + pos; - const char *e = string + cap; + uint8_t *dst = (uint8_t*)string + pos; + const uint8_t *e = (uint8_t*)string + cap; strl_t left = sub.get_len(); while (left && dst < e) { - unsigned char c = (unsigned char)*src++; + uint8_t c = (uint8_t)*src++; left--; *dst++ = c; } @@ -4140,11 +4192,11 @@ strl_t _strmod_insert(char *string, strl_t length, strl_t cap, const strref sub, } // determine the size of this string with evaluated escape codes -static strl_t int_string_size_esc(const unsigned char *string, strl_t length) +static strl_t int_string_size_esc(const uint8_t *string, strl_t length) { strl_t size = 0; while (length) { - unsigned char c = *string++; + uint8_t c = *string++; length--; if (c=='\\' && length) { strl_t skip = int_get_esc_code(string, length, c); @@ -4182,12 +4234,12 @@ strl_t _strmod_insert_esc(char *string, strl_t length, strl_t cap, const strref for (; move; move--) *--dst = *--src; } - const unsigned char *src = sub.get_u(); - char *dst = string + pos; - const char *e = string + cap; + const uint8_t *src = sub.get_u(); + uint8_t *dst = (uint8_t*)string + pos; + const uint8_t *e = (uint8_t*)string + cap; strl_t left = sub.get_len(); while (left && dst < e) { - unsigned char c = *src++; + uint8_t c = *src++; left--; if (c=='\\' && left) { strl_t skip = int_get_esc_code(src, left, c); @@ -4227,7 +4279,7 @@ strl_t _strmod_format_insert(char *string, strl_t length, strl_t cap, strl_t pos // if there was a {} process that.. if (format.get_first()=='{' && close>0) { - int which = format.get_substr(1, close-ins).atoi(); + int64_t which = format.get_substr(1, close-ins).atoi(); strl_t prev = length; length = _strmod_insert(string, length, cap, args[which], pos); pos += length - prev; @@ -4446,7 +4498,7 @@ strl_t _strmod_inplace_replace_bookend_int(char *string, strl_t length, strl_t c void _strmod_tolower(char *string, strl_t length) { if (string) { - char *s = string; + uint8_t *s = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *s = int_tolower_ascii7(*s); s++; @@ -4458,7 +4510,7 @@ void _strmod_tolower(char *string, strl_t length) void _strmod_tolower_win_ascii(char *string, strl_t length) { if (string) { - char *s = string; + uint8_t *s = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *s = int_tolower_win_ascii(*s); s++; @@ -4470,7 +4522,7 @@ void _strmod_tolower_win_ascii(char *string, strl_t length) void _strmod_tolower_amiga_ascii(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *scan = int_tolower_amiga_ascii(*scan); scan++; @@ -4482,7 +4534,7 @@ void _strmod_tolower_amiga_ascii(char *string, strl_t length) void _strmod_tolower_macos_ascii(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t r = length; r>0; r--) { *scan = int_tolower_macos_roman_ascii(*scan); scan++; @@ -4494,7 +4546,7 @@ void _strmod_tolower_macos_ascii(char *string, strl_t length) void _strmod_toupper(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *scan = int_toupper_ascii7(*scan); scan++; @@ -4506,7 +4558,7 @@ void _strmod_toupper(char *string, strl_t length) void _strmod_toupper_win_ascii(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *scan = int_toupper_win_ascii(*scan); scan++; @@ -4518,7 +4570,7 @@ void _strmod_toupper_win_ascii(char *string, strl_t length) void _strmod_toupper_amiga_ascii(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *scan = int_toupper_amiga_ascii(*scan); scan++; @@ -4531,7 +4583,7 @@ void _strmod_toupper_amiga_ascii(char *string, strl_t length) void _strmod_toupper_macos_ascii(char *string, strl_t length) { if (string) { - char *scan = string; + uint8_t *scan = (uint8_t*)string; for (strl_t left = length; left>0; left--) { *scan = int_toupper_macos_roman_ascii(*scan); scan++; @@ -4625,7 +4677,7 @@ size_t _strmod_read_utf8(char *string, strl_t length, strl_t pos, strl_t &skip) size_t c = (size_t)*string++; c &= 0x7f; for (size_t m = 0x40; (m & c) && string=cap) return 0; - char *write = string + pos; + uint8_t *write = (uint8_t*)string + pos; cap -= pos; if (code < 0x80) { - *write++ = (char)code; + *write++ = (uint8_t)code; return 1; } else if (cap>=2 && code < 0x800) { - *write++ = char(0xc0 | (code >> 6)); + *write++ = uint8_t(0xc0 | (code >> 6)); *write++ = 0x80 | (code & 0x3f); return 2; } else if (cap>=3 && code < 0x10000) { - *write++ = char(0xe0 | (code >> 12)); + *write++ = uint8_t(0xe0 | (code >> 12)); *write++ = 0x80 | ((code >> 6) & 0x3f); *write++ = 0x80 | (code & 0x3f); return 3; @@ -4672,7 +4724,7 @@ strl_t _strmod_utf8_tolower(char *string, strl_t length, strl_t cap) { c = int_tolower_unicode(c); - strl_t add = c<0x80 ? 1 : (c<0x800 ? 2 : (c<0x10000 ? 3 : 4)); + strl_t add = c cap) return (strl_t)(write-string); @@ -4704,7 +4756,7 @@ strl_t _strmod_utf8_toupper(char *string, strl_t length, strl_t cap) { c = int_toupper_unicode(c); - strl_t add = c<0x80 ? 1 : (c<0x800 ? 2 : (c<0x10000 ? 3 : 4)); + strl_t add = c<0x80 ? strl_t(1) : (c<0x800 ? strl_t(2) : (c<0x10000 ? strl_t(3) : strl_t(4))); if (add > cap) return (strl_t)(write-string); diff --git a/x65.cpp b/x65.cpp index 8d01d76..1376f49 100644 --- a/x65.cpp +++ b/x65.cpp @@ -1255,10 +1255,10 @@ typedef struct Section { void AddTriple(int l); void AddBin(const uint8_t *p, int size); void AddText(strref line, strref text_prefix); - void SetByte(size_t offs, int b) { output[offs] = b; } - void SetWord(size_t offs, int w) { output[offs] = w; output[offs+1] = w>>8; } - void SetTriple(size_t offs, int w) { output[offs] = w; output[offs+1] = w>>8; output[offs+2] = w>>16; } - void SetQuad(size_t offs, int w) { output[offs] = w; output[offs+1] = w>>8; output[offs+2] = w>>16; output[offs+3] = w>>24; } + void SetByte(size_t offs, int b) { output[offs] = (uint8_t)b; } + void SetWord(size_t offs, int w) { output[offs] = (uint8_t)w; output[offs+1] = uint8_t(w>>8); } + void SetTriple(size_t offs, int w) { output[offs] = (uint8_t)w; output[offs+1] = uint8_t(w>>8); output[offs+2] = uint8_t(w>>16); } + void SetQuad(size_t offs, int w) { output[offs] = (uint8_t)w; output[offs+1] = uint8_t(w>>8); output[offs+2] = uint8_t(w>>16); output[offs+3] = uint8_t(w>>24); } } Section; // Symbol list entry (in order of parsing) @@ -1423,8 +1423,8 @@ public: context.code_segment = code_seg; context.read_source = code_seg; context.next_source = code_seg; - context.repeat = rept; - context.repeat_total = rept; + context.repeat = (int16_t)rept; + context.repeat_total = (int16_t)rept; stack.push_back(context); currContext = &stack[stack.size()-1]; } @@ -1601,8 +1601,8 @@ public: // Assembler Directives StatusCode ApplyDirective(AssemblerDirective dir, strref line, strref source_file); - StatusCode Directive_Rept(strref line, strref source_file); - StatusCode Directive_Macro(strref line, strref source_file); + StatusCode Directive_Rept(strref line); + StatusCode Directive_Macro(strref line); StatusCode Directive_String(strref line); StatusCode Directive_Undef(strref line); StatusCode Directive_Include(strref line); @@ -1706,7 +1706,7 @@ int sortHashLookup(const void *A, const void *B) { return _A->op_hash > _B->op_hash ? 1 : -1; } -int BuildInstructionTable(OPLookup *pInstr, int maxInstructions, struct mnem *opcodes, +int BuildInstructionTable(OPLookup *pInstr, struct mnem *opcodes, int count, const char **aliases, bool merlin) { // create an instruction table (mnemonic hash lookup) @@ -1714,7 +1714,7 @@ int BuildInstructionTable(OPLookup *pInstr, int maxInstructions, struct mnem *op for (int i = 0; i < count; i++) { OPLookup &op = pInstr[numInstructions++]; op.op_hash = strref(opcodes[i].instr).fnv1a_lower(); - op.index = i; + op.index = (uint8_t)i; op.type = OT_MNEMONIC; } @@ -1727,7 +1727,7 @@ int BuildInstructionTable(OPLookup *pInstr, int maxInstructions, struct mnem *op if (orig.same_str_case(opcodes[o].instr)) { OPLookup &op = pInstr[numInstructions++]; op.op_hash = alias.fnv1a_lower(); - op.index = o; + op.index = (uint8_t)o; op.type = OT_MNEMONIC; break; } @@ -1764,7 +1764,7 @@ void Asm::SetCPU(CPUIndex CPU) { list_cpu = cpu; opcode_table = aCPUs[CPU].opcodes; opcode_count = aCPUs[CPU].num_opcodes; - num_instructions = BuildInstructionTable(aInstructions, MAX_OPCODES_DIRECTIVES, opcode_table, + num_instructions = BuildInstructionTable(aInstructions, opcode_table, opcode_count, aCPUs[CPU].aliases, Merlin()); } @@ -1874,7 +1874,7 @@ void Asm::SetSection(strref line) strref name; while (strref arg = line.split_token_any_trim(",:")) { if (arg.get_first() == '$') { ++arg; align = (int)arg.ahextoui(); } - else if (arg.is_number()) align = arg.atoi(); + else if (arg.is_number()) align = (int)arg.atoi(); else if (arg.get_first() == '"') name = (arg + 1).before_or_full('"'); else if (!name) name = arg; else if (arg.same_str("code")) type = ST_CODE; @@ -1886,7 +1886,7 @@ void Asm::SetSection(strref line) if (type == ST_UNDEFINED) { if (name.find("code") >= 0) type = ST_CODE; else if (name.find("data") >= 0) type = ST_DATA; - else if (name.find("bss" >= 0 || name.same_str("directpage_stack"))) type = ST_BSS; + else if (name.find("bss") >= 0 || name.same_str("directpage_stack")) type = ST_BSS; else if (name.find("zp") >= 0 || name.find("zeropage") >= 0 || name.find("direct") >= 0) type = ST_ZEROPAGE; else type = ST_CODE; @@ -2171,10 +2171,10 @@ StatusCode Asm::LinkZP() if (s->type == ST_ZEROPAGE && !s->IsMergedSection()) { if (s->address_assigned) { has_assigned = true; - if (s->start_address < min_addr) - min_addr = s->start_address; - else if (s->address > max_addr) - max_addr = s->address; + if (s->start_address < (int)min_addr) + min_addr = (uint8_t)s->start_address; + else if ((int)s->address > max_addr) + max_addr = (uint8_t)s->address; } else { has_unassigned = true; first_unassigned = first_unassigned >=0 ? first_unassigned : (int)(&*s - &allSections[0]); @@ -2250,7 +2250,7 @@ void Asm::LinkLabelsToAddress(int section_id, int section_new, int section_addre if (pLabels->mapIndex>=0 && pLabels->mapIndex<(int)map.size()) { struct MapSymbol &msym = map[pLabels->mapIndex]; msym.value = pLabels->value; - msym.section = section_new; + msym.section = (int16_t)section_new; } CheckLateEval(pLabels->label_name); } @@ -2431,14 +2431,14 @@ StatusCode Asm::MergeSections(int section_id, int section_merge) { for (MapSymbolArray::iterator i = map.begin(); i!=map.end(); ++i) { if (i->section == section_merge) { i->value += addr_start; - i->section = section_id; + i->section = (int16_t)section_id; } } // go through all late evals referencing this section for (std::vector::iterator i = lateEval.begin(); i!=lateEval.end(); ++i) { if (i->section == section_merge) { - i->section = section_id; + i->section = (int16_t)section_id; if (i->target >= 0) i->target += addr_start; i->address += addr_start; @@ -2704,7 +2704,7 @@ StatusCode Asm::PushContext(strref src_name, strref src_file, strref code_seg, i conditional_nesting[conditional_depth] = 0; conditional_consumed[conditional_depth] = false; contextStack.push(src_name, src_file, code_seg, rept); - contextStack.curr().conditional_ctx = conditional_depth; + contextStack.curr().conditional_ctx = (int16_t)conditional_depth; if (scope_depth >= (MAX_SCOPE_DEPTH - 1)) return ERROR_TOO_DEEP_SCOPE; else @@ -2890,7 +2890,7 @@ StatusCode Asm::BuildMacro(Macro &m, strref arg_list) bool success = false; strl_t offs = strl_t(tag.get() - macexp.get()); if (!offs || !strref::is_valid_label(macexp[offs])) { - int t = (tag + 1).atoi(); + int t = (int)(tag + 1).atoi(); strref args = arg; if (t > 0) { for (int skip = 1; skip < t; skip++) @@ -2991,7 +2991,7 @@ StatusCode Asm::BuildEnum(strref name, strref declaration) return error; } struct MemberOffset member; - member.offset = value; + member.offset = (uint16_t)value; member.name = name; member.name_hash = member.name.fnv1a(); member.sub_struct = strref(); @@ -3165,7 +3165,7 @@ EvalOperator Asm::RPNToken_Merlin(strref &expression, const struct EvalContext & ++expression; if (expression[0] == '*') return EVOP_STP; // double asterisks indicates comment else if (prev_op==EVOP_VAL || prev_op==EVOP_RPR) return EVOP_MUL; - value = etx.pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + value = etx.pc; section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); return EVOP_VAL; case '/': ++expression; return EVOP_DIV; case '>': if (expression.get_len() >= 2 && expression[1] == '>') { expression += 2; return EVOP_SHR; } ++expression; return EVOP_HIB; @@ -3175,7 +3175,9 @@ EvalOperator Asm::RPNToken_Merlin(strref &expression, const struct EvalContext & if (expression[1]=='0' || expression[1]=='1') { ++expression; value = (int)expression.abinarytoui_skip(); return EVOP_VAL; } if (etx.scope_end_pc<0 || scope_depth != etx.scope_depth) return EVOP_NRY; - ++expression; value = etx.scope_end_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + ++expression; value = etx.scope_end_pc; + section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); + return EVOP_VAL; case '|': case '.': ++expression; return EVOP_OR; // MERLIN: . is or, | is not used case '^': if (prev_op == EVOP_VAL || prev_op == EVOP_RPR) { ++expression; return EVOP_EOR; } @@ -3191,7 +3193,8 @@ EvalOperator Asm::RPNToken_Merlin(strref &expression, const struct EvalContext & if (c == '!' && (prev_op == EVOP_VAL || prev_op == EVOP_RPR)) { ++expression; return EVOP_EOR; } else if (c == '!' && !(expression + 1).len_label()) { if (etx.scope_pc < 0) return EVOP_NRY; // ! by itself is current scope, !+label char is a local label - ++expression; value = etx.scope_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + ++expression; value = etx.scope_pc; + section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); return EVOP_VAL; } else if (expression.match_chars_str("0-9", "!a-zA-Z_")) { if (prev_op == EVOP_VAL) return EVOP_STP; // value followed by value doesn't make sense, stop value = expression.atoi_skip(); return EVOP_VAL; @@ -3208,7 +3211,7 @@ EvalOperator Asm::RPNToken_Merlin(strref &expression, const struct EvalContext & } if (!pLabel && label.same_str("rept")) { value = etx.rept_cnt; return EVOP_VAL; } if (!pLabel || !pLabel->evaluated) return EVOP_NRY; // this label could not be found (yet) - value = pLabel->value; section = pLabel->section; return EVOP_VAL; + value = pLabel->value; section = int16_t(pLabel->section); return EVOP_VAL; } else return EVOP_ERR; break; @@ -3229,7 +3232,7 @@ EvalOperator Asm::RPNToken(strref &exp, const struct EvalContext &etx, EvalOpera ++exp; if (exp[0] == '*') return EVOP_STP; // double asterisks indicates comment else if (prev_op == EVOP_VAL || prev_op == EVOP_RPR) return EVOP_MUL; - value = etx.pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + value = etx.pc; section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); return EVOP_VAL; case '/': ++exp; return EVOP_DIV; case '=': if (exp[1] == '=') { exp += 2; return EVOP_EQU; } return EVOP_STP; case '>': if (exp.get_len() >= 2 && exp[1] == '>') { exp += 2; return EVOP_SHR; } @@ -3243,7 +3246,7 @@ EvalOperator Asm::RPNToken(strref &exp, const struct EvalContext &etx, EvalOpera case '%': // % means both binary and scope closure, disambiguate! if (exp[1] == '0' || exp[1] == '1') { ++exp; value = (int)exp.abinarytoui_skip(); return EVOP_VAL; } if (etx.scope_end_pc<0 || scope_depth != etx.scope_depth) return EVOP_NRY; - ++exp; value = etx.scope_end_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + ++exp; value = etx.scope_end_pc; section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); return EVOP_VAL; case '|': ++exp; return EVOP_OR; case '^': if (prev_op == EVOP_VAL || prev_op == EVOP_RPR) { ++exp; return EVOP_EOR; } ++exp; return EVOP_BAB; @@ -3256,7 +3259,8 @@ EvalOperator Asm::RPNToken(strref &exp, const struct EvalContext &etx, EvalOpera default: { // ! by itself is current scope, !+label char is a local label if (c == '!' && !(exp + 1).len_label()) { if (etx.scope_pc < 0) return EVOP_NRY; - ++exp; value = etx.scope_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL; + ++exp; value = etx.scope_pc; + section = int16_t(CurrSection().IsRelativeSection() ? SectionId() : -1); return EVOP_VAL; } else if (exp.match_chars_str("0-9", "!a-zA-Z_")) { if (prev_op == EVOP_VAL) return EVOP_STP; // value followed by value doesn't make sense, stop value = exp.atoi_skip(); return EVOP_VAL; @@ -3274,7 +3278,7 @@ EvalOperator Asm::RPNToken(strref &exp, const struct EvalContext &etx, EvalOpera if (!pLabel && label.same_str("rept")) { value = etx.rept_cnt; return EVOP_VAL; } if (!pLabel) { if (StringSymbol *pStr = GetString(label)) { subexp = pStr->get(); return EVOP_EXP; } } if (!pLabel || !pLabel->evaluated) return EVOP_NRY; // this label could not be found (yet) - value = pLabel->value; section = pLabel->section; return pLabel->reference ? EVOP_XRF : EVOP_VAL; + value = pLabel->value; section = int16_t(pLabel->section); return pLabel->reference ? EVOP_XRF : EVOP_VAL; } return EVOP_ERR; } @@ -3358,7 +3362,7 @@ StatusCode Asm::EvalExpression(strref expression, const struct EvalContext &etx, } if (section >= 0) { for (int s = 0; sp) break; - ops[numOps++] = p; + ops[numOps++] = (char)p; sp--; } - op_stack[sp++] = op; + op_stack[sp++] = (char)op; } } // check for out of bounds or unexpected input @@ -3567,7 +3571,7 @@ StatusCode Asm::EvalExpression(strref expression, const struct EvalContext &etx, if (section_index>=0 && !curr_relative) { lastEvalSection = section_ids[section_index]; lastEvalValue = prev_val; - lastEvalShift = shift_bits; + lastEvalShift = (int8_t)shift_bits; return STATUS_RELATIVE_SECTION; } } @@ -3585,7 +3589,7 @@ void Asm::AddLateEval(int target, int pc, int scope_pc, strref expression, strre le.scope = scope_pc; le.scope_depth = scope_depth; le.target = target; - le.section = (int)(&CurrSection() - &allSections[0]); + le.section = (int16_t)(&CurrSection() - &allSections[0]); le.rept = contextStack.curr().repeat_total - contextStack.curr().repeat; le.file_ref = -1; // current or xdef'd le.label.clear(); @@ -3604,7 +3608,7 @@ void Asm::AddLateEval(strref label, int pc, int scope_pc, strref expression, Lat le.scope_depth = scope_depth; le.target = -1; le.label = label; - le.section = (int)(&CurrSection() - &allSections[0]); + le.section = (int16_t)(&CurrSection() - &allSections[0]); le.rept = contextStack.curr().repeat_total - contextStack.curr().repeat; le.file_ref = -1; // current or xdef'd le.expression = expression; @@ -3820,7 +3824,7 @@ void Asm::LabelAdded(Label *pLabel, bool local) map.reserve(map.size() + 256); MapSymbol sym; sym.name = pLabel->label_name; - sym.section = pLabel->section; + sym.section = (int16_t)(pLabel->section); sym.value = pLabel->value; sym.local = local; pLabel->mapIndex = pLabel->evaluated ? -1 : (int)map.size(); @@ -3934,8 +3938,8 @@ StatusCode Asm::AddLabelPool(strref name, strref args) if (addr1<=addr0 || addr0<0) return ERROR_POOL_RANGE_EXPRESSION_EVAL; - aRng[ranges++] = addr0; - aRng[ranges++] = addr1; + aRng[ranges++] = (uint16_t)addr0; + aRng[ranges++] = (uint16_t)addr1; num32 += (addr1-addr0+15)>>4; if (ranges >(MAX_POOL_RANGES*2) || @@ -3948,8 +3952,8 @@ StatusCode Asm::AddLabelPool(strref name, strref args) LabelPool pool; pool.pool_name = name; - pool.numRanges = ranges>>1; - pool.scopeDepth = scope_depth; + pool.numRanges = (int16_t)(ranges>>1); + pool.scopeDepth = (int16_t)scope_depth; memset(pool.usedMap, 0, sizeof(uint32_t) * num32); for (int r = 0; r='!' && file[0]<='&' && (buffer = LoadText(file+1, size))) { + if (file[0] >= '!' && file[0] <= '&') + buffer = LoadText(file + 1, size); + if (buffer) { loadedData.push_back(buffer); // MERLIN: prepend with !-& to not auto-prepend with T. strref src(buffer, strl_t(size)); PushContext(file+1, src, src); } else { strown<512> fileadd(file[0]>='!' && file[0]<='&' ? (file+1) : file); fileadd.append(".s"); - if ((buffer = LoadText(fileadd.get_strref(), size))) { + buffer = LoadText(fileadd.get_strref(), size); + if (buffer) { loadedData.push_back(buffer); // MERLIN: !+filename appends .S to filenames strref src(buffer, strl_t(size)); PushContext(file, src, src); } else { fileadd.copy("T."); // MERLIN: just filename prepends T. to filenames fileadd.append(file[0]>='!' && file[0]<='&' ? (file+1) : file); - if ((buffer = LoadText(fileadd.get_strref(), size))) { + buffer = LoadText(fileadd.get_strref(), size); + if (buffer) { loadedData.push_back(buffer); strref src(buffer, strl_t(size)); PushContext(file, src, src); @@ -4814,7 +4821,7 @@ StatusCode Asm::Directive_DC(strref line, int width, strref source_file) width == 1 ? LateEval::LET_BYTE : (width == 2 ? LateEval::LET_ABS_REF : (width == 3 ? LateEval::LET_ABS_L_REF : LateEval::LET_ABS_4_REF))); else if (error == STATUS_RELATIVE_SECTION) { value = 0; - CurrSection().AddReloc(lastEvalValue, CurrSection().DataOffset(), lastEvalSection, width, lastEvalShift); + CurrSection().AddReloc(lastEvalValue, CurrSection().DataOffset(), lastEvalSection, (int8_t)width, (int8_t)lastEvalShift); } } uint8_t bytes[4] = { @@ -5136,7 +5143,7 @@ StatusCode Asm::ApplyDirective(AssemblerDirective dir, strref line, strref sourc break; } case AD_MACRO: - error = Directive_Macro(line, source_file); + error = Directive_Macro(line); break; case AD_INCLUDE: // assemble another file in place @@ -5241,7 +5248,7 @@ StatusCode Asm::ApplyDirective(AssemblerDirective dir, strref line, strref sourc return Directive_ENUM_STRUCT(line, dir); case AD_REPT: - return Directive_Rept(line, source_file); + return Directive_Rept(line); case AD_INCDIR: AddIncludeFolder(line.between('"', '"')); @@ -5948,8 +5955,8 @@ bool Asm::List(strref filename) if (opcode_table[i].modes & (1 << j)) { uint8_t op = opcode_table[i].aCodes[j]; if (addrmode[op]==255) { - mnemonic[op] = i; - addrmode[op] = j; + mnemonic[op] = (uint8_t)i; + addrmode[op] = (uint8_t)j; } } } @@ -6344,7 +6351,7 @@ StatusCode Asm::WriteObjectFile(strref filename) // include space for external protected labels for (std::vector::iterator el = externals.begin(); el != externals.end(); ++el) - hdr.labels += el->labels.count(); + hdr.labels += (int16_t)el->labels.count(); char *stringPool = nullptr; uint32_t stringPoolCap = 0; @@ -6363,7 +6370,7 @@ StatusCode Asm::WriteObjectFile(strref filename) // discard the removed sections by making a table of skipped indices for (std::vector
::iterator si = allSections.begin(); si!=allSections.end(); ++si) { if (si->type != ST_REMOVED) - aRemapSects[&*si-&allSections[0]] = sect++; + aRemapSects[&*si-&allSections[0]] = (int16_t)sect++; } sect = 0; @@ -6399,7 +6406,7 @@ StatusCode Asm::WriteObjectFile(strref filename) } } } - hdr.sections = sect; + hdr.sections = (int16_t)sect; // write out labels if (hdr.labels) { @@ -6410,7 +6417,7 @@ StatusCode Asm::WriteObjectFile(strref filename) l.name.offs = _AddStrPool(lo.label_name, &stringArray, &stringPool, hdr.stringdata, stringPoolCap); l.value = lo.value; l.section = lo.section >=0 ? aRemapSects[lo.section] : -1; - l.mapIndex = lo.mapIndex; + l.mapIndex = (int16_t)lo.mapIndex; l.flags = (lo.constant ? ObjFileLabel::OFL_CNST : 0) | (lo.pc_relative ? ObjFileLabel::OFL_ADDR : 0) | @@ -6430,7 +6437,7 @@ StatusCode Asm::WriteObjectFile(strref filename) l.name.offs = _AddStrPool(lo.label_name, &stringArray, &stringPool, hdr.stringdata, stringPoolCap); l.value = lo.value; l.section = lo.section >= 0 ? aRemapSects[lo.section] : -1; - l.mapIndex = lo.mapIndex; + l.mapIndex = (int16_t)lo.mapIndex; l.flags = (lo.constant ? ObjFileLabel::OFL_CNST : 0) | (lo.pc_relative ? ObjFileLabel::OFL_ADDR : 0) | @@ -6451,8 +6458,8 @@ StatusCode Asm::WriteObjectFile(strref filename) le.rept = lei->rept; le.target = (int16_t)lei->target; le.address = lei->address; - le.scope = lei->scope; - le.type = lei->type; + le.scope = (int16_t)lei->scope; + le.type = (int16_t)lei->type; } } @@ -6612,7 +6619,7 @@ StatusCode Asm::ReadObjectFile(strref filename, int link_to_section) struct ObjFileLabel &l = aLabels[li]; strref name = l.name.offs >= 0 ? strref(str_pool + l.name.offs) : strref(); Label *lbl = GetLabel(name); - int16_t f = l.flags; + int16_t f = (int16_t)l.flags; int external = f & ObjFileLabel::OFL_XDEF; if (external == ObjFileLabel::OFL_XDEF) { if (!lbl) @@ -6847,13 +6854,13 @@ StatusCode Asm::WriteA2GS_OMF(strref filename, bool full_collapse) instructions[inst_curr++] = OMFR_SUPER; int len_offs = inst_curr; inst_curr += 4; - instructions[inst_curr++] = b; // SUPER_RELOC2 / SUPER_RELOC3 + instructions[inst_curr++] = (uint8_t)b; // SUPER_RELOC2 / SUPER_RELOC3 // try all SUPER_RELOC2 (2 bytes self reference, no shift) relocList::iterator r = s.pRelocs->begin(); while (r != s.pRelocs->end()) { if (r->shift == 0 && r->bytes == (b+2) && r->target_section == SectionId(s)) { if ((r->section_offset >> 8) != prev_page) { - instructions[inst_curr++] = 0x80 | ((r->section_offset >> 8) - prev_page - 1); + instructions[inst_curr++] = uint8_t(0x80 | ((r->section_offset >> 8) - prev_page - 1)); count_offs = -1; } // update patch counter for current page or add a new counter if (count_offs < 0) { @@ -6879,7 +6886,7 @@ StatusCode Asm::WriteA2GS_OMF(strref filename, bool full_collapse) if (r->target_section == SectionId(s)) { // this is a reloc, check if cRELOC is ok or if need RELOC bool cRELOC = r->section_offset < 0x10000 && r->base_value < 0x10000; - instructions[instruction_offs++] = cRELOC ? OMFR_cRELOC : OMFR_RELOC; + instructions[instruction_offs++] = uint8_t(cRELOC ? OMFR_cRELOC : OMFR_RELOC); instructions[instruction_offs++] = r->bytes; instructions[instruction_offs++] = r->shift; _writeNBytes(instructions + instruction_offs, cRELOC ? 2 : 4, r->section_offset); @@ -6889,7 +6896,7 @@ StatusCode Asm::WriteA2GS_OMF(strref filename, bool full_collapse) } else { // this is an interseg bool cINTERSEG = r->section_offset < 0x10000 && r->base_value < 0x10000; - instructions[instruction_offs++] = cINTERSEG ? OMFR_cINTERSEG : OMFR_INTERSEG; + instructions[instruction_offs++] = uint8_t(cINTERSEG ? OMFR_cINTERSEG : OMFR_INTERSEG); instructions[instruction_offs++] = r->bytes; instructions[instruction_offs++] = r->shift; _writeNBytes(instructions + instruction_offs, cINTERSEG ? 2 : 4, r->section_offset); @@ -6972,9 +6979,8 @@ int main(int argc, char **argv) const char *sym_file = nullptr, *vs_file = nullptr; strref list_file, allinstr_file; for (int a = 1; a1) assembler.default_org = (int)(arg + 1).ahextoui(); else if (arg.is_number()) - assembler.default_org = arg.atoi(); + assembler.default_org = (int)arg.atoi(); // force the current section to be org'd assembler.AssignAddressToSection(assembler.SectionId(), assembler.default_org); } else if (arg.has_prefix(acc) && arg[acc.get_len()] == '=') { @@ -7053,11 +7059,15 @@ int main(int argc, char **argv) else printf("Unexpected option " STRREF_FMT "\n", STRREF_ARG(arg)); } else if (!source_filename) - source_filename = arg.get(); + source_filename = argv[a]; else if (!binary_out_name) - binary_out_name = arg.get(); + binary_out_name = argv[a]; } + for (int a = 1; a < argc; a++) { + strref arg(argv[a]); + printf(STRREF_FMT "\n", STRREF_ARG(arg)); + } if (gen_allinstr) { assembler.AllOpcodes(allinstr_file); } else if (!source_filename) {