From 1218da79a9ac84a10a49cf2b35a85dd7e8ae5c18 Mon Sep 17 00:00:00 2001 From: stag019 Date: Sun, 22 Dec 2013 20:55:14 -0500 Subject: [PATCH 01/13] Character maps. --- Makefile | 1 + include/asm/charmap.h | 18 +++++ include/asm/output.h | 2 + src/asm/charmap.c | 182 ++++++++++++++++++++++++++++++++++++++++++ src/asm/globlex.c | 1 + src/asm/output.c | 10 +++ src/asm/yaccprt1.y | 17 ++++ src/asm/yaccprt3.y | 23 +++++- 8 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 include/asm/charmap.h create mode 100644 src/asm/charmap.c diff --git a/Makefile b/Makefile index 1934fb77..4f6d6625 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ yacc_pre := \ rgbasm_obj := \ src/asm/alloca.o \ src/asm/asmy.o \ + src/asm/charmap.o \ src/asm/fstack.o \ src/asm/globlex.o \ src/asm/lexer.o \ diff --git a/include/asm/charmap.h b/include/asm/charmap.h new file mode 100644 index 00000000..a9535e54 --- /dev/null +++ b/include/asm/charmap.h @@ -0,0 +1,18 @@ +#ifndef ASMOTOR_ASM_CHARMAP_H +#define ASMOTOR_ASM_CHARMAP_H + +#define MAXCHARMAPS 512 +#define CHARMAPLENGTH 8 + +struct Charmap { + int count; + char input[MAXCHARMAPS][CHARMAPLENGTH + 1]; + char output[MAXCHARMAPS]; +}; + +int readUTF8Char(char *destination, char *source); +void charmap_Sort(); +int charmap_Add(char *input, UBYTE output); +int charmap_Convert(char **input); + +#endif diff --git a/include/asm/output.h b/include/asm/output.h index a6406ca5..e579dde3 100644 --- a/include/asm/output.h +++ b/include/asm/output.h @@ -12,6 +12,7 @@ struct Section { ULONG nBank; struct Section *pNext; struct Patch *pPatches; + struct Charmap *charmap; UBYTE *tData; }; @@ -20,6 +21,7 @@ void out_SetFileName(char *s); void out_NewSection(char *pzName, ULONG secttype); void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank); void out_AbsByte(int b); +void out_AbsByteGroup(char *s, int length); void out_RelByte(struct Expression * expr); void out_RelWord(struct Expression * expr); void out_PCRelByte(struct Expression * expr); diff --git a/src/asm/charmap.c b/src/asm/charmap.c new file mode 100644 index 00000000..973a9f3f --- /dev/null +++ b/src/asm/charmap.c @@ -0,0 +1,182 @@ +#include +#include +#include + +#include "asm/asm.h" +#include "asm/charmap.h" +#include "asm/main.h" +#include "asm/output.h" + +struct Charmap globalCharmap; + +extern struct Section *pCurrentSection; + +int +readUTF8Char(char *destination, char *source) +{ + int size; + UBYTE first; + first = source[0]; + + if(first >= 0xFC) + { + size = 6; + } + else if(first >= 0xF8) + { + size = 5; + } + else if(first >= 0xF0) + { + size = 4; + } + else if(first >= 0xE0) + { + size = 3; + } + else if(first >= 0xC0) + { + size = 2; + } + else + { + size = 1; + } + strncpy(destination, source, size); + destination[size] = 0; + return size; +} + +int +charmap_Add(char *input, UBYTE output) +{ + int i, input_length; + char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o, temp2o; + + struct Charmap *charmap; + + if(pCurrentSection) + { + if(pCurrentSection -> charmap) + { + charmap = pCurrentSection -> charmap; + } + else + { + if((charmap = (struct Charmap *) malloc(sizeof(struct Charmap))) == NULL) + { + fatalerror("Not enough memory for charmap"); + } + pCurrentSection -> charmap = charmap; + } + } + else + { + charmap = &globalCharmap; + } + + if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH) + { + return -1; + } + + input_length = strlen(input); + if(input_length > 1) + { + i = 0; + while(i < charmap -> count) + { + if(input_length > strlen(charmap -> input[i])) + { + memcpy(temp1i, charmap -> input[i], CHARMAPLENGTH + 1); + memcpy(charmap -> input[i], input, CHARMAPLENGTH + 1); + temp1o = charmap -> output[i]; + charmap -> output[i] = output; + i++; + break; + } + i++; + } + while(i < charmap -> count) + { + memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1); + memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1); + memcpy(temp1i, temp2i, CHARMAPLENGTH + 1); + temp2o = charmap -> output[i]; + charmap -> output[i] = temp1o; + temp1o = temp2o; + i++; + } + memcpy(charmap -> input[charmap -> count], temp1i, CHARMAPLENGTH + 1); + charmap -> output[charmap -> count] = temp1o; + } + else + { + memcpy(charmap -> input[charmap -> count - 1], input, CHARMAPLENGTH + 1); + charmap -> output[charmap -> count - 1] = output; + } + return ++charmap -> count; +} + +int +charmap_Convert(char **input) +{ + struct Charmap *charmap; + + char outchar[CHARMAPLENGTH + 1]; + char *input_temp, *buffer; + int i, j, length; + + if(pCurrentSection && pCurrentSection -> charmap) + { + charmap = pCurrentSection -> charmap; + } + else + { + charmap = &globalCharmap; + } + + length = 0; + input_temp = *input; + if((buffer = (char *) malloc(strlen(*input))) == NULL) + { + fatalerror("Not enough memory for buffer"); + } + + length = 0; + while(**input) + { + j = 0; + for(i = 0; i < charmap -> count; i++) + { + j = strlen(charmap -> input[i]); + if(memcmp(*input, charmap -> input[i], j) == 0) + { + outchar[0] = charmap -> output[i]; + outchar[1] = 0; + break; + } + j = 0; + } + if(!j) + { + j = readUTF8Char(outchar, *input); + } + if(!outchar[0]) + { + buffer[length++] = 0; + } + else + { + for(i = 0; outchar[i]; i++) + { + buffer[length++] = outchar[i]; + } + } + *input += j; + } + *input = input_temp; + *input = buffer; + return length; +} + diff --git a/src/asm/globlex.c b/src/asm/globlex.c index c26cdc4d..313007fd 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -298,6 +298,7 @@ struct sLexInitString staticstrings[] = { {"rsset", T_POP_RSSET}, {"incbin", T_POP_INCBIN}, + {"charmap", T_POP_CHARMAP}, {"fail", T_POP_FAIL}, {"warn", T_POP_WARN}, diff --git a/src/asm/output.c b/src/asm/output.c index e39f67d1..318b5fbc 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -11,6 +11,7 @@ #include #include "asm/asm.h" +#include "asm/charmap.h" #include "asm/output.h" #include "asm/symbol.h" #include "asm/mylink.h" @@ -643,6 +644,7 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org, pSect->nBank = bank; pSect->pNext = NULL; pSect->pPatches = NULL; + pSect->charmap = NULL; pPatchSymbols = NULL; if ((pSect->tData = @@ -716,6 +718,14 @@ out_AbsByte(int b) nPC += 1; pPCSymbol->nValue += 1; } + +void +out_AbsByteGroup(char *s, int length) +{ + checkcodesection(length); + while (length--) + out_AbsByte(*s++); +} /* * RGBAsm - OUTPUT.C - Outputs an objectfile * diff --git a/src/asm/yaccprt1.y b/src/asm/yaccprt1.y index ea99ff52..e25e11d0 100644 --- a/src/asm/yaccprt1.y +++ b/src/asm/yaccprt1.y @@ -8,6 +8,7 @@ #include "asm/symbol.h" #include "asm/asm.h" +#include "asm/charmap.h" #include "asm/output.h" #include "asm/mylink.h" #include "asm/fstack.h" @@ -42,6 +43,21 @@ ULONG str2int( char *s ) return( r ); } +ULONG str2int2( char *s, int length ) +{ + int i; + ULONG r=0; + i = (length - 4 < 0 ? 0 : length - 4); + while(i < length) + { + r<<=8; + r|=(UBYTE)(s[i]); + i++; + + } + return( r ); +} + ULONG isWhiteSpace( char s ) { return( s==' ' || s=='\t' || s=='\0' || s=='\n' ); @@ -401,6 +417,7 @@ void if_skip_to_endc( void ) %token T_POP_ENDM %token T_POP_RSRESET T_POP_RSSET %token T_POP_INCBIN T_POP_REPT +%token T_POP_CHARMAP %token T_POP_SHIFT %token T_POP_ENDR %token T_POP_FAIL diff --git a/src/asm/yaccprt3.y b/src/asm/yaccprt3.y index f0a50a90..90c45070 100644 --- a/src/asm/yaccprt3.y +++ b/src/asm/yaccprt3.y @@ -88,6 +88,7 @@ simple_pseudoop : include | rsreset | rsset | incbin + | charmap | rept | shift | fail @@ -280,6 +281,24 @@ incbin : T_POP_INCBIN string } ; +charmap : T_POP_CHARMAP string ',' string + { + if(charmap_Add($2, $4[0] & 0xFF) == -1) + { + fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno)); + yyerror("Error parsing charmap."); + } + } + | T_POP_CHARMAP string ',' const + { + if(charmap_Add($2, $4 & 0xFF) == -1) + { + fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno)); + yyerror("Error parsing charmap."); + } + } +; + printt : T_POP_PRINTT string { if( nPass==1 ) @@ -339,7 +358,7 @@ constlist_8bit : constlist_8bit_entry constlist_8bit_entry : { out_Skip( 1 ); } | const_8bit { out_RelByte( &$1 ); } - | string { out_String( $1 ); } + | string { char *s; int length; s = $1; length = charmap_Convert(&s); out_AbsByteGroup(s, length); free(s); } ; constlist_16bit : constlist_16bit_entry @@ -394,7 +413,7 @@ relocconst : T_ID | T_NUMBER { rpn_Number(&$$,$1); $$.nVal = $1; } | string - { ULONG r; r=str2int($1); rpn_Number(&$$,r); $$.nVal=r; } + { char *s; int length; ULONG r; s = $1; length = charmap_Convert(&s); r = str2int2(s, length); free(s); rpn_Number(&$$,r); $$.nVal=r; } | T_OP_LOGICNOT relocconst %prec NEG { rpn_LOGNOT(&$$,&$2); } | relocconst T_OP_LOGICOR relocconst From 1f9fd0f060801ac351007f4ce8064420a63dfaea Mon Sep 17 00:00:00 2001 From: stag019 Date: Sun, 22 Dec 2013 20:56:31 -0500 Subject: [PATCH 02/13] This fixes an error with using long label names in macros. If the label name you're using is longer than the string length of the literal macro text, a syntax error would occur. This fix makes sure it at least allocates enough bytes for the largest allowed label name. --- src/asm/fstack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index b7c3d489..87a0b7b5 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -275,7 +275,7 @@ fstk_RunMacro(char *s) pCurrentMacro = sym; CurrentFlexHandle = yy_scan_bytes(pCurrentMacro->pMacro, - pCurrentMacro->ulMacroSize); + (pCurrentMacro->ulMacroSize < MAXSYMLEN ? MAXSYMLEN : pCurrentMacro->ulMacroSize)); //Dirty hack to fix small macros using long label names. yy_switch_to_buffer(CurrentFlexHandle); return (1); } else From c65d58c5890c70ffa15054de4bef9c32d005a801 Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:37:56 -0500 Subject: [PATCH 03/13] Move local includes below system includes. --- src/asm/lexer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index ead1ee49..c928d7d6 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -1,3 +1,8 @@ +#include +#include +#include +#include + #include "asm/asm.h" #include "asm/lexer.h" #include "asm/types.h" @@ -7,11 +12,6 @@ #include "asmy.h" -#include -#include -#include -#include - struct sLexString { char *tzName; ULONG nToken; From 7d176245d824031a0d29bd295395ec0fe65f674c Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:40:53 -0500 Subject: [PATCH 04/13] Remove all implicit definitions of compiler provided functions. cause strncasecmp to be define. --- src/asm/lexer.c | 2 ++ src/asm/symbol.c | 1 + src/asm/yaccprt1.y | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index c928d7d6..814da5ba 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -1,6 +1,8 @@ +#define _XOPEN_SOURCE 500 #include #include #include +#include #include #include "asm/asm.h" diff --git a/src/asm/symbol.c b/src/asm/symbol.c index aebe5930..0285e627 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -5,6 +5,7 @@ * */ +#define _XOPEN_SOURCE 500 #include #include #include diff --git a/src/asm/yaccprt1.y b/src/asm/yaccprt1.y index e25e11d0..5f008f2f 100644 --- a/src/asm/yaccprt1.y +++ b/src/asm/yaccprt1.y @@ -1,10 +1,12 @@ %{ +#define _XOPEN_SOURCE 500 #include #include #include #include #include #include +#include #include "asm/symbol.h" #include "asm/asm.h" From 36edec6231256cd4ff40dc03261bbc58385382ea Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:47:37 -0500 Subject: [PATCH 05/13] Add out_BinaryFileSlice() definition to output.h. --- include/asm/output.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/asm/output.h b/include/asm/output.h index e579dde3..0f9ebae4 100644 --- a/include/asm/output.h +++ b/include/asm/output.h @@ -28,6 +28,7 @@ void out_PCRelByte(struct Expression * expr); void out_WriteObject(void); void out_Skip(int skip); void out_BinaryFile(char *s); +void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length); void out_String(char *s); void out_AbsLong(SLONG b); void out_RelLong(struct Expression * expr); From 94005513a4927af6f278a1002ec3fdd0b13b29a9 Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:50:37 -0500 Subject: [PATCH 06/13] Comment out unused variable dest. --- src/asm/globlex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/asm/globlex.c b/src/asm/globlex.c index 313007fd..088076bf 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -109,7 +109,7 @@ ascii2bin(char *s) ULONG ParseFixedPoint(char *s, ULONG size) { - char dest[256]; + //char dest[256]; ULONG i = 0, dot = 0; while (size && dot != 2) { @@ -117,13 +117,13 @@ ParseFixedPoint(char *s, ULONG size) dot += 1; if (dot < 2) { - dest[i] = s[i]; + //dest[i] = s[i]; size -= 1; i += 1; } } - dest[i] = 0; + //dest[i] = 0; yyunputbytes(size); From 55974bc743c8f81e69e37a1a32bad2f316805d55 Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:52:37 -0500 Subject: [PATCH 07/13] Only define _MAX_PATH is it isn't already defined. --- include/asm/types.h | 2 ++ include/lib/types.h | 2 ++ include/link/mylink.h | 2 ++ include/link/types.h | 2 ++ 4 files changed, 8 insertions(+) diff --git a/include/asm/types.h b/include/asm/types.h index 4f2fccbb..a9c07243 100644 --- a/include/asm/types.h +++ b/include/asm/types.h @@ -1,7 +1,9 @@ #ifndef ASMOTOR_ASM_TYPES_H #define ASMOTOR_ASM_TYPES_H +#ifndef _MAX_PATH #define _MAX_PATH 512 +#endif typedef unsigned char UBYTE; typedef signed char SBYTE; diff --git a/include/lib/types.h b/include/lib/types.h index 89c6e34a..997702c0 100644 --- a/include/lib/types.h +++ b/include/lib/types.h @@ -1,7 +1,9 @@ #ifndef ASMOTOR_LIB_TYPES_H #define ASMOTOR_LIB_TYPES_H +#ifndef _MAX_PATH #define _MAX_PATH 512 +#endif typedef unsigned char UBYTE; typedef signed char SBYTE; diff --git a/include/link/mylink.h b/include/link/mylink.h index a3f09e51..837190f4 100644 --- a/include/link/mylink.h +++ b/include/link/mylink.h @@ -1,7 +1,9 @@ #ifndef ASMOTOR_LINK_LINK_H #define ASMOTOR_LINK_LINK_H +#ifndef _MAX_PATH #define _MAX_PATH 512 +#endif #include "link/types.h" diff --git a/include/link/types.h b/include/link/types.h index 4e25047e..60cb29fc 100644 --- a/include/link/types.h +++ b/include/link/types.h @@ -1,7 +1,9 @@ #ifndef ASMOTOR_LINK_TYPES_H #define ASMOTOR_LINK_TYPES_H +#ifndef _MAX_PATH #define _MAX_PATH 512 +#endif typedef unsigned char UBYTE; typedef signed char SBYTE; From c61c11221859da2f7a7180d62cc1f9b4d8244a81 Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 23 Dec 2013 14:57:06 -0500 Subject: [PATCH 08/13] Remove GNU-specific . getopt() is defined in in POSIX, which adding #define _XOPEN_SOURCE 500 causes GCC to include. --- src/asm/main.c | 2 +- src/fix/main.c | 2 +- src/link/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/asm/main.c b/src/asm/main.c index 46194cfd..62ed48f6 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -5,8 +5,8 @@ * */ +#define _XOPEN_SOURCE 500 #include -#include #include #include #include diff --git a/src/fix/main.c b/src/fix/main.c index 36cc2df9..d1d4a35d 100644 --- a/src/fix/main.c +++ b/src/fix/main.c @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#define _XOPEN_SOURCE 500 #include #include #include diff --git a/src/link/main.c b/src/link/main.c index 84ecb8f6..a5e54b60 100644 --- a/src/link/main.c +++ b/src/link/main.c @@ -1,4 +1,4 @@ -#include +#define _XOPEN_SOURCE 500 #include #include #include From 34656f9e5dcbeb5ca36dc812141ddd7a233da43d Mon Sep 17 00:00:00 2001 From: stag019 Date: Sat, 28 Dec 2013 00:35:05 -0500 Subject: [PATCH 09/13] Fix a bug where the first charmap entry wasn't added correctly. --- src/asm/charmap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/asm/charmap.c b/src/asm/charmap.c index 973a9f3f..07b13a33 100644 --- a/src/asm/charmap.c +++ b/src/asm/charmap.c @@ -75,6 +75,11 @@ charmap_Add(char *input, UBYTE output) charmap = &globalCharmap; } + if(nPass == 2) + { + return charmap -> count; + } + if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH) { return -1; @@ -84,7 +89,7 @@ charmap_Add(char *input, UBYTE output) if(input_length > 1) { i = 0; - while(i < charmap -> count) + while(i < charmap -> count + 1) { if(input_length > strlen(charmap -> input[i])) { @@ -97,7 +102,7 @@ charmap_Add(char *input, UBYTE output) } i++; } - while(i < charmap -> count) + while(i < charmap -> count + 1) { memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1); memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1); @@ -107,13 +112,13 @@ charmap_Add(char *input, UBYTE output) temp1o = temp2o; i++; } - memcpy(charmap -> input[charmap -> count], temp1i, CHARMAPLENGTH + 1); - charmap -> output[charmap -> count] = temp1o; + memcpy(charmap -> input[charmap -> count + 1], temp1i, CHARMAPLENGTH + 1); + charmap -> output[charmap -> count + 1] = temp1o; } else { - memcpy(charmap -> input[charmap -> count - 1], input, CHARMAPLENGTH + 1); - charmap -> output[charmap -> count - 1] = output; + memcpy(charmap -> input[charmap -> count], input, CHARMAPLENGTH + 1); + charmap -> output[charmap -> count] = output; } return ++charmap -> count; } From af506985e5019ae540a76d13414cc4d020325d1f Mon Sep 17 00:00:00 2001 From: stag019 Date: Mon, 3 Feb 2014 20:46:52 -0500 Subject: [PATCH 10/13] Added license to charmap.c --- src/asm/charmap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/asm/charmap.c b/src/asm/charmap.c index 07b13a33..e6b3e83e 100644 --- a/src/asm/charmap.c +++ b/src/asm/charmap.c @@ -1,3 +1,19 @@ +/* + * Copyright © 2013 stag019 + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + #include #include #include From 004bc2e50ef04200a559b3ce8e8e6767a6142494 Mon Sep 17 00:00:00 2001 From: stag019 Date: Fri, 31 Oct 2014 10:48:54 -0400 Subject: [PATCH 11/13] Fix a few charmap bugs maybe? --- src/asm/charmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/asm/charmap.c b/src/asm/charmap.c index e6b3e83e..00c632f1 100644 --- a/src/asm/charmap.c +++ b/src/asm/charmap.c @@ -23,7 +23,7 @@ #include "asm/main.h" #include "asm/output.h" -struct Charmap globalCharmap; +struct Charmap globalCharmap = {0}; extern struct Section *pCurrentSection; @@ -67,7 +67,7 @@ int charmap_Add(char *input, UBYTE output) { int i, input_length; - char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o, temp2o; + char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0, temp2o = 0; struct Charmap *charmap; @@ -79,7 +79,7 @@ charmap_Add(char *input, UBYTE output) } else { - if((charmap = (struct Charmap *) malloc(sizeof(struct Charmap))) == NULL) + if((charmap = (struct Charmap *) calloc(1, sizeof(struct Charmap))) == NULL) { fatalerror("Not enough memory for charmap"); } @@ -110,7 +110,7 @@ charmap_Add(char *input, UBYTE output) if(input_length > strlen(charmap -> input[i])) { memcpy(temp1i, charmap -> input[i], CHARMAPLENGTH + 1); - memcpy(charmap -> input[i], input, CHARMAPLENGTH + 1); + memcpy(charmap -> input[i], input, input_length); temp1o = charmap -> output[i]; charmap -> output[i] = output; i++; @@ -133,7 +133,7 @@ charmap_Add(char *input, UBYTE output) } else { - memcpy(charmap -> input[charmap -> count], input, CHARMAPLENGTH + 1); + memcpy(charmap -> input[charmap -> count], input, input_length); charmap -> output[charmap -> count] = output; } return ++charmap -> count; @@ -157,7 +157,6 @@ charmap_Convert(char **input) charmap = &globalCharmap; } - length = 0; input_temp = *input; if((buffer = (char *) malloc(strlen(*input))) == NULL) { From af70f03933abf02f218044ccc954417eb0e94663 Mon Sep 17 00:00:00 2001 From: stag019 Date: Fri, 31 Oct 2014 19:01:21 -0400 Subject: [PATCH 12/13] A few more small changes to charmap.c. --- src/asm/charmap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/asm/charmap.c b/src/asm/charmap.c index 00c632f1..4f2aecf4 100644 --- a/src/asm/charmap.c +++ b/src/asm/charmap.c @@ -54,10 +54,14 @@ readUTF8Char(char *destination, char *source) { size = 2; } - else + else if(first != '\0') { size = 1; } + else + { + size = 0; + } strncpy(destination, source, size); destination[size] = 0; return size; @@ -145,7 +149,7 @@ charmap_Convert(char **input) struct Charmap *charmap; char outchar[CHARMAPLENGTH + 1]; - char *input_temp, *buffer; + char *buffer; int i, j, length; if(pCurrentSection && pCurrentSection -> charmap) @@ -157,7 +161,6 @@ charmap_Convert(char **input) charmap = &globalCharmap; } - input_temp = *input; if((buffer = (char *) malloc(strlen(*input))) == NULL) { fatalerror("Not enough memory for buffer"); @@ -195,7 +198,6 @@ charmap_Convert(char **input) } *input += j; } - *input = input_temp; *input = buffer; return length; } From a64d725a8d9be9686a7495e16209ae9ea86b6cbb Mon Sep 17 00:00:00 2001 From: stag019 Date: Tue, 4 Nov 2014 18:09:22 -0500 Subject: [PATCH 13/13] The actual way the macro bug should have been fixed. --- src/asm/fstack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index da1b10af..c41745d5 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -284,7 +284,7 @@ fstk_RunMacro(char *s) pCurrentMacro = sym; CurrentFlexHandle = yy_scan_bytes(pCurrentMacro->pMacro, - (pCurrentMacro->ulMacroSize < MAXSYMLEN ? MAXSYMLEN : pCurrentMacro->ulMacroSize)); //Dirty hack to fix small macros using long label names. + strlen(pCurrentMacro->pMacro)); yy_switch_to_buffer(CurrentFlexHandle); return (1); } else