/* $Header: jetasmf.c,v 3.18 96/04/25 08:56:35 barry Exp $ */ /************************************************************************** * * (c) Copyright Hewlett-Packard Company, 1995. All rights are * reserved. Copying or other reproduction of this program except * for archival purposes is prohibited without the prior written * consent of Hewlett-Packard Company. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the Government is subject to * restrictions as set forth in paragraph (b) (3) (B) of the Rights * in Technical Data and Computer Software clause in DAR 7-104.9(a). * * HEWLETT-PACKARD COMPANY * Boise, Idaho, USA ***************************************************************************/ /* ******************************* NOTICE *************************************** HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE SOFTWARE OR TECHNICAL INFORMATION. HEWLETT-PACKARD COMPANY DOES NOT WARRANT, GUARANTEE OR MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE SOFTWARE OR TECHNICAL INFORMATION IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY, CURRENTNESS, OR OTHERWISE. THE ENTIRE RISK AS TO THE RESULTS AND PERFORMANCE OF THE SOFTWARE OR TECHNICAL INFORMATION IS ASSUMED BY YOU. The exclusion of implied warranties is not permitted by some jurisdictions. The above exclusion may not apply to you. IN NO EVENT WILL HEWLETT-PACKARD COMPANY BE LIABLE TO YOU FOR ANY CONSEQUENTIAL, INCIDENTAL OR INDIRECT DAMAGES (INCLUDING DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION AND THE LIKE) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE OR TECHNICAL INFORMATION EVEN IF HEWLETT-PACKARD HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Because some jurisdictions do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitations may not apply to you. Hewlett-Packard liability to you for actual damages from any cause whatsoever, and regardless of the form of the action (whether in contract, tort including negligence, product liability or otherwise), will be limited to US $50. Copyright (c) 1995 Hewlett-Packard Company. All rights reserved. ****************************************************************************** */ #include #include #include #include #include #include /* PCL XL Stream library header and basic data types */ #include /* PCL XL Stream assembler function header */ extern HP_StdFuncPrefix HP_FlushOutBuffer(HP_StreamHandleType pStream, unsigned long cookie, HP_pUByte pOutBuffer, HP_SInt32 outBufferLen); long GlobalSymbolCount=0; long int operationTagged=0, nextOpCount=1; extern int TagOperations; /* #define DEBUG_JETASM */ /* debug flag */ /* #define DOS_MEM_MODEL on command line is a must for Windows or MS-DOS memory models */ #ifdef DOS_MEM_MODEL /* a must for Windows or MS-DOS memory models */ typedef void far *HP_pVoid; typedef HP_pVoid pVoidFuncReturnType; #else typedef void *HP_pVoid; typedef HP_pVoid pVoidFuncReturnType; #endif /* more function return types */ typedef HP_UByte UByteFuncReturnType; typedef HP_UInt16 UInt16FuncReturnType; typedef HP_UInt32 UInt32FuncReturnType; typedef HP_Real32 Real32FuncReturnType; /* basic type definitions: */ typedef HP_pVoid DataBufferPtrType; typedef HP_UInt16 BufferIndexType; typedef HP_pChar SrcStringPtrType; typedef SrcStringPtrType TokenPtrType; typedef FILE *FileFuncReturnType; /* #define MEMORY_DEBUG */ #ifdef MEMORY_DEBUG static unsigned long int memFuncCount = 0; void *malloc_log(size_t size, unsigned long int lineNumber, char* fileName) { void *ptr = malloc(size); FILE *file; file = fopen("tmp.mem", "a"); fprintf(file, "%p %07ld HP_MEMALLOC; LINE %ld; FILE %s.\n", ptr, (++memFuncCount), lineNumber, fileName); fclose(file); return(ptr); } void free_log(void *ptr, unsigned long int lineNumber, char* fileName) { FILE *file; file = fopen("tmp.mem", "a"); fprintf(file, "%p %07ld HP_FREE; LINE %ld; FILE %s.\n", ptr, (++memFuncCount), lineNumber, fileName); free(ptr); fclose(file); } void *realloc_log(void* ptr, size_t size, unsigned long int lineNumber, char* fileName) { void *ptr2 = realloc(ptr, size); FILE *file; file = fopen("tmp.mem", "a"); fprintf(file, "%p %07ld HP_FREE (HP_REALLOC); LINE %ld; FILE %s.\n", ptr, (++memFuncCount), lineNumber, fileName); fprintf(file, "%p %07ld HP_MEMALLOC (HP_REALLOC); LINE %ld; FILE %s.\n", ptr2, (++memFuncCount), lineNumber, fileName); fclose(file); return(ptr2); } #endif /* MEMORY_DEBUG */ #ifndef MEMORY_DEBUG #define HP_MEMALLOC(size) malloc(size) #else #define HP_MEMALLOC(size) malloc_log(size, __LINE__, __FILE__) #endif #ifndef MEMORY_DEBUG #define HP_MEMDEALLOC(ptr) free(ptr) #else #define HP_MEMDEALLOC(ptr) free_log(ptr, __LINE__, __FILE__) #endif #ifndef MEMORY_DEBUG #define HP_MEMREALLOC(ptr, size) realloc(ptr, size) #else #define HP_MEMREALLOC(ptr, size) realloc_log(ptr, size, __LINE__, __FILE__) #endif #define CH_startOfNumArraySymbol '[' #define CH_endOfNumArraySymbol ']' #define CH_startOfByteArraySymbol '(' #define CH_endOfByteArraySymbol ')' #define CH_startOfCommentSymbol '/' static const HP_pUByte endLoopString = "$endloop"; static const HP_pUByte endIfString = "$endif"; static const HP_pUByte calcString = "$calc"; static const HP_pUByte stringOpString = "$string"; static const HP_pUByte startIfString = "$if"; static const HP_pUByte startLoopString = "$loop"; static const HP_pUByte stopString = "$stop"; static const HP_pUByte abortString = "$abort"; static const HP_pUByte lineString = "$line"; static const HP_pUByte printString = "$print"; static const HP_pUByte highByteString = "$highByteFirst"; static const HP_pUByte lowByteString = "$lowByteFirst"; static const HP_pUByte inputString = "$input"; static const HP_pUByte defineString = "$define"; static const HP_pUByte escapeString = "$escape"; static const HP_pUByte beginSubString = "$beginsub"; static const HP_pUByte endSubString = "$endsub"; static const HP_pUByte execSubString = "$execsub"; static const HP_pUByte inputEscapeString = "$input-12345ZYX"; #define MAX_LINE_LENGTH 2048 /* the maximum character allocation size for a string, * this includes input strings */ #define MAX_STRING_SIZE (MAX_LINE_LENGTH - 2) /* the max size a string or token can * be in bytes, the (-2) is for a carriage return and * null character at the end of a string */ #define MAX_PRINT_BUFF 256 /* the maximum size of any buffer used for * printing messages */ #define MAX_DISASM_STRING 80 /* the maximum string size for disassembly * output */ #define MAX_RECOVERIES 100 /* the maximum recover attempts allowed */ #define TOKEN_NOT_FOUND 0 /* no more tokens in a string */ #define NOT_LOOP_OR_IF 0 #define NO_LOCAL_MACRO_TABLE 0 #define MAX_DISASM_HEX_COUNT 16 /* the maximum number of hex bytes to be printed * on a hex dump */ /* error codes (must positive values for assembler errors since */ /* all PCL XL stream library internal errors are negative values): */ #define HPERR_CannotOpenInput 1 /* cannot open input file */ #define HPERR_CannotOpenOutput 2 /* cannot open output file */ #define HPERR_SourceStringOverflow 3 /* overflowed source string while looking * for token: a fatal error */ #define HPERR_UnknownActualDataType 4 /* the actual data type assigned for a token * was illegal (i.e. not uint16, not * sint32xy, etc.) */ #define HPERR_FileReadError 5 /* An error occured reading the input file */ #define HPERR_ExpectedOpOrDataId 6 /* Expecting an operator or data identifier * and got something else */ #define HPERR_ExpectedAttrId 7 /* Expecting an attribute ID and got something * else (possibly eof) */ #define HPERR_InvalidDataId 8 /* A data identifer pulled out of the symbol * table was invalid */ #define HPERR_UnknownDataFormat 9 /* A data value was expected in the data stream * but the format of the data was incorrect for * the assembler */ #define HPERR_NotAnEnumeration 10 /* An enumeration name was given for a data value * but the name did not map to an enumeration */ #define HPERR_MissingOpenBracket 11 /* An open bracket to start an array was missing */ #define HPERR_MissingCloseBracket 12 /* A close bracket for an array was missing */ #define HPERR_UnknownInternalDataFormat 13 /* The internal value for a data format associated * with a symbol was unknown */ #define HPERR_IllegalAssemblerState 15 /* An illegal assembler state was attempted */ #define HPERR_TooManyRecoveryAttempts 16 /* Too many recoveries were attempted */ #define HPERR_AsmOutOfMemory 17 /* Assembler Out Of Memory */ #define HPERR_DataCountExceeded 18 /* The number of data values implied * by the data identifier was exceeded */ #define HPERR_MacroValueConversionError 19 /* A number conversion for a macro value * in a macro arithmetic operation failed */ #define HPERR_MacroNameMustStartWithAlpha 20 /* A macro name was given in a macro operator * that did not start with an alpha character */ #define HPERR_UnknownMacroOperator 21 /* An unrecognized "$calc" operator was * received by the assembler */ #define HPERR_EndIfNotFound 22 /* An $if was detected without a matching * $endif */ #define HPERR_EndLoopNotFound 23 /* A $loop was detected without a matching * $endloop */ #define HPERR_FileWriteError 24 /* An error was detected during the process of * writing to a file */ #define HPERR_UnknownMacroName 25 /* A macro name was given that does not exist */ #define HPERR_FileNameLengthExceeded 26 /* A file name provided to the assembler exceeded * the maximum length allowed */ #define HPERR_PathLengthExceeded 27 /* An $include file path give to the assembler * exceeded the maximum length allowed */ #define HPERR_EndLoopNoMatch 28 /* An $endloop macro was found with no matching * $loop */ #define HPERR_EndIfNoMatch 29 /* An $endif macro was found with no matching * $if or $ifnot */ #define HPERR_EscapeStringTooLong 30 /* The $escape string returned from the * HP_EscapeMacro function was too long */ #define HPERR_EscapeMacroFailed 31 /* The $escape macro returned a non-zero value */ #define HPERR_InputStringTooLong 32 /* The $input string returned from the * HP_EscapeMacro function was too long */ #define HPERR_UndefinedTag 33 /* An undefined tag was found in the stream being disassembled. */ #define HPERR_SymbolMissing 34 /* A symbol needed for disassembly was * missing (an internal error) */ #define HPERR_BeyondEOF 35 /* An attempt was made to read beyond the * end of the current input file */ #define HPERR_UndefinedArrayLengthType 36 /* An array length type was read from the stream * that is not defined as a valid type */ #define HPERR_UndefinedMacroTable 37 /* Macro Operation Performed with Undefined * macro table */ #define HPERR_EndSubNotFound 38 /* End of Subroutine Not Found * */ #define HPERR_NestedSubroutine 39 /* Nested Subroutines Not Allowed */ #define HPERR_SubroutineAlreadyExists 40 /* Subroutine with name already defined */ #define HPERR_UnknownStringOperator 41 /* Unknown string operation */ #define HPERR_UserAbort 42 /* User Abort */ #define HPERR_ExceededMaxNesting 43 /* User Abort */ #define HPERR_DataBufferOverflow 44 /* reading data caused an overflow of the internal data buffer */ /* the following are type definitions for the * input file and $include file stack */ typedef char FileNameType[MAX_FILE_NAME]; /* include file names */ typedef HP_pVoid loopOrIfMacroNameType; /* typedef for pointer * to the $loop or $if * macro name used in * the path list */ /* macro table typedefs: */ typedef HP_pChar MacroStringPtrType; /* typedef for macro table record entry */ typedef struct { MacroStringPtrType pMacro; MacroStringPtrType pBody; } MacroRecType; typedef struct { MacroRecType *macroRecords; HP_UInt16 numMacroEntries; HP_UInt16 maxMacroEntries; } MacroTableType; typedef MacroRecType *MacroRecPtrType; typedef MacroTableType *MacroTablePtrType; /* the file stack array allocation is 1 plus the number of open files * because file stack location zero is not used */ #define FSTACK_ARRAY_ALLOC (MAX_NESTED_FILES + 1) /* the following is the typedef for the input and $include * file stack */ typedef struct { int numOpenFiles; /* 1 = original input file */ FILE *fileArray[FSTACK_ARRAY_ALLOC]; /* array of file handles */ unsigned long int lineCountArray[FSTACK_ARRAY_ALLOC]; /* array of file line counts */ FileNameType fileNameArray[FSTACK_ARRAY_ALLOC]; /* array of file names */ FileNameType aliasNameArray[FSTACK_ARRAY_ALLOC]; /* array of file aliases for temporary files */ /* name of $if or $loop macro name for temporary file: */ loopOrIfMacroNameType macroNameArray[FSTACK_ARRAY_ALLOC]; /* following tells if we're testing for true or false on end of * if or loop (non-zero entry if we're checking for true): */ unsigned char loopEndCheck[FSTACK_ARRAY_ALLOC]; /* the following holds the local macro table ptr for subroutines: */ MacroTablePtrType localMacroTableArray[FSTACK_ARRAY_ALLOC]; HP_UInt32 byteCountArray[FSTACK_ARRAY_ALLOC]; /* for disassembler only */ /* current temporary file suffix: */ /* (i.e. tempFileSuffix=2 would infer file name of asm002.tmp) */ int tempFileSuffix; } FileStack; typedef FileStack *FileStackPtrType; /* type def for file stack pointers */ /* values for loopEndCheck entry of FileStack */ #define LOOP_EndOnTrue 1 #define LOOP_EndOnFalse 0 #define NOT_LOOPING 3 /* file stack access macros: */ #define FSTACK_GetNumOpenFiles(pFileStack) (pFileStack)->numOpenFiles #define FSTACK_SetNumOpenFiles(pFileStack, value) (pFileStack)->numOpenFiles = value #define FSTACK_GetTempFileSuffix(pFileStack) (pFileStack)->tempFileSuffix #define FSTACK_IncrementTempFileSuffix(pFileStack) (pFileStack)->tempFileSuffix++ #define FSTACK_LoopEndOnTrue(pFileStack) \ (pFileStack->loopEndCheck[FSTACK_GetNumOpenFiles(pFileStack)] == \ LOOP_EndOnTrue) #define FSTACK_SetLoopEndFlag(pFileStack, value) \ pFileStack->loopEndCheck[FSTACK_GetNumOpenFiles(pFileStack)] = value #define FSTACK_GetLoopEndFlag(pFileStack) \ pFileStack->loopEndCheck[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_GetMacroNamePtr(pFileStack) \ pFileStack->macroNameArray[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_SetLocalMacroTable(pFileStack, ptrValue) \ pFileStack->localMacroTableArray[FSTACK_GetNumOpenFiles(pFileStack)] = ptrValue #define FSTACK_GetLocalMacroTable(pFileStack) \ pFileStack->localMacroTableArray[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_SetMacroNamePtr(pFileStack, ptrValue) \ pFileStack->macroNameArray[FSTACK_GetNumOpenFiles(pFileStack)] = ptrValue #define FSTACK_TopOfFileStack(pFileStack) \ pFileStack->fileArray[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_GetCurrentLineNumber(pFileStack) \ pFileStack->lineCountArray[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_SetCurrentLineNumber(pFileStack, value) \ pFileStack->lineCountArray[FSTACK_GetNumOpenFiles(pFileStack)] = value #define FSTACK_IncrementLineNumber(pFileStack) \ pFileStack->lineCountArray[(FSTACK_GetNumOpenFiles(pFileStack))]++ #define FSTACK_GetFileNamePtr(pFileStack) \ (pFileStack->fileNameArray[(FSTACK_GetNumOpenFiles(pFileStack))]) #define FSTACK_SetFilePtr(pFileStack, ptrValue) \ pFileStack->fileArray[(FSTACK_GetNumOpenFiles(pFileStack))] = ptrValue #define FSTACK_GetFilePtr(pFileStack) \ pFileStack->fileArray[(FSTACK_GetNumOpenFiles(pFileStack))] #define FSTACK_EndOfFile(pFileStack) \ feof(FSTACK_TopOfFileStack(pFileStack)) #define FSTACK_GetAliasNamePtr(pFileStack) \ (pFileStack->aliasNameArray[(FSTACK_GetNumOpenFiles(pFileStack))]) #define FSTACK_SetTempFileSuffix(pFileStack, value) \ pFileStack->tempFileSuffix = value #define FSTACK_IncrementByteCount(pFileStack) \ pFileStack->byteCountArray[(FSTACK_GetNumOpenFiles(pFileStack))]++ #define FSTACK_GetByteCount(pFileStack) \ pFileStack->byteCountArray[FSTACK_GetNumOpenFiles(pFileStack)] #define FSTACK_SetByteCount(pFileStack, value) \ pFileStack->byteCountArray[FSTACK_GetNumOpenFiles(pFileStack)] = value SInt16FuncReturnType FSTACK_NextByte(FileStackPtrType pFileStack) { HP_SInt16 intByteBuff; intByteBuff = fgetc(pFileStack->fileArray[(FSTACK_GetNumOpenFiles(pFileStack))]); if (intByteBuff != EOF) { FSTACK_IncrementByteCount(pFileStack); } return(intByteBuff); } FileStackPtrType FSTACK_NewFileStack(void) { FileStackPtrType pFileStack = 0; pFileStack = (FileStackPtrType) HP_MEMALLOC (sizeof(FileStack)); if (pFileStack) { FSTACK_SetNumOpenFiles(pFileStack, 0); FSTACK_SetFilePtr(pFileStack, 0); FSTACK_SetMacroNamePtr(pFileStack, 0); FSTACK_SetTempFileSuffix(pFileStack, 0); FSTACK_SetByteCount(pFileStack, 0); } return(pFileStack); } /* typedef for union used to extract various data types */ typedef union { unsigned char aByte; unsigned int anInt16; unsigned long anInt32; float aReal32; } DataUnionType; /* typedef for symbol table record entry */ typedef struct { TokenPtrType symbol; HP_UInt16 tokenClass; HP_UInt32 tokenInstance; HP_UInt16 tokenExtension; } SymbolRecType; typedef struct { SymbolRecType *symbolRecPtr; HP_UInt16 numSymbolEntries; } SymbolTableType; typedef SymbolRecType *SymbolRecPtrType; typedef SymbolTableType *SymbolTablePtrType; #define SYMBOL_GetSymbolStringPtr(symbolRecPtr) \ symbolRecPtr->symbol #define SYMBOL_SetSymbolStringPtr(symbolRecPtr, ptrValue) \ symbolRecPtr->symbol = ptrValue #define SYMBOL_GetTokenInstance(symbolRecPtr) \ symbolRecPtr->tokenInstance #define SYMBOL_SetTokenInstance(symbolRecPtr, value) \ symbolRecPtr->tokenInstance = value #define SYMBOL_GetTokenClass(symbolRecPtr) \ symbolRecPtr->tokenClass #define SYMBOL_SetTokenClass(symbolRecPtr, value) \ symbolRecPtr->tokenClass = value #include /* PCL XL Stream Assembler/Disassembler * symbols and "E_" defines (i.e. * "E_Operator). */ #define E_DisAsm_Operator 1 #define E_DisAsm_DataVal 2 #define E_DisAsm_Escape 3 #define E_DisAsm_PJL_At 4 /* PJL @ Symbol */ #define E_DisAsm_BindingId 5 #define E_DisAsm_EmbeddedData 6 #define E_DisAsm_EmbeddedDataByte 7 #define E_DisAsm_AttrUByte 8 #define HP_MaxNumberOfAttrs 256 /* maximum number of attributes */ #define HP_MaxNumberOfTags 256 /* maximum number of tags */ const HP_UByte HP_tagValueMap[HP_MaxNumberOfTags]= { /* not used 0x00 - 0x2f*/ /* 0x00 nul */ 0x00, /* 0x01 soh */ 0x00, /* 0x02 stx */ 0x00, /* 0x03 etx */ 0x00, /* 0x04 eot */ 0x00, /* 0x05 enq */ 0x00, /* 0x06 ack */ 0x00, /* 0x07 bel */ 0x00, /* 0x08 bs */ 0x00, /* 0x09 ht */ 0x00, /* 0x0a nl */ 0x00, /* 0x0b vt */ 0x00, /* 0x0c np */ 0x00, /* 0x0d cr */ 0x00, /* 0x0e so */ 0x00, /* 0x0f si */ 0x00, /* 0x10 dle */ 0x00, /* 0x11 dc1 */ 0x00, /* 0x12 dc2 */ 0x00, /* 0x13 dc3 */ 0x00, /* 0x14 dc4 */ 0x00, /* 0x15 nak */ 0x00, /* 0x16 syn */ 0x00, /* 0x17 etb */ 0x00, /* 0x18 can */ 0x00, /* 0x19 em */ 0x00, /* 0x1a sub */ 0x00, /* 0x1b esc */ E_DisAsm_Escape, /* 0x1c fs */ 0x00, /* 0x1d gs */ 0x00, /* 0x1e rs */ 0x00, /* 0x1f us */ 0x00, /* 0x20 sp */ 0x00, /* 0x21 ! */ 0x00, /* 0x22 " */ 0x00, /* 0x23 # */ 0x00, /* 0x24 $ */ 0x00, /* 0x25 % */ 0x00, /* 0x26 & */ 0x00, /* 0x27 ' */ E_DisAsm_BindingId, /* 0x28 ( */ E_DisAsm_BindingId, /* 0x29 ) */ E_DisAsm_BindingId, /* 0x2a * */ 0x00, /* 0x2b + */ 0x00, /* 0x2c , */ 0x00, /* 0x2d - */ 0x00, /* 0x2e . */ 0x00, /* 0x2f / */ 0x00, /* 0x30 0 */ 0x00, /* 0x31 1 */ 0x00, /* 0x32 2 */ 0x00, /* 0x32 - 0x40 not used */ /* 0x33 3 */ 0x00, /* 0x34 4 */ 0x00, /* 0x35 5 */ 0x00, /* 0x36 6 */ 0x00, /* 0x37 7 */ 0x00, /* 0x38 8 */ 0x00, /* 0x39 9 */ 0x00, /* 0x3a : */ 0x00, /* 0x3b ; */ 0x00, /* 0x3c < */ 0x00, /* 0x3d = */ 0x00, /* 0x3e > */ 0x00, /* 0x3f ? */ 0x00, /* 0x40 @ */ E_DisAsm_PJL_At, /* PJL @ Symbol */ /* 0x41 A */ E_DisAsm_Operator, /* BeginSession */ /* 0x42 B */ E_DisAsm_Operator, /* EndSession */ /* 0x43 C */ E_DisAsm_Operator, /* BeginPage */ /* 0x44 D */ E_DisAsm_Operator, /* EndPage */ /* 0x45 E */ 0x00, /* 0x46 F */ E_DisAsm_Operator, /* SelfTest */ /* 0x47 G */ E_DisAsm_Operator, /* Comment */ /* 0x48 H */ E_DisAsm_Operator, /* OpenDataSource */ /* 0x49 I */ E_DisAsm_Operator, /* CloseDataSource */ /* 0x4a J */ E_DisAsm_Operator, /* EchoComment */ /* 0x4b K */ E_DisAsm_Operator, /* Query */ /* 0x4c L */ 0x00, /* Diagnostic3 */ /* 0x4d M */ 0x00, /* 0x4e N */ 0x00, /* 0x4f O */ E_DisAsm_Operator, /* BeginFontHeader */ /* 0x50 P */ E_DisAsm_Operator, /* ReadFontHeader */ /* 0x51 Q */ E_DisAsm_Operator, /* EndFontHeader */ /* 0x52 R */ E_DisAsm_Operator, /* BeginChar */ /* 0x53 S */ E_DisAsm_Operator, /* ReadChar */ /* 0x54 T */ E_DisAsm_Operator, /* EndChar */ /* 0x55 U */ E_DisAsm_Operator, /* RemoveFont */ /* 0x56 V */ 0x00, /* BeginOpenFont Reserved */ /* 0x57 W */ 0x00, /* EndOpenFont Reserved */ /* 0x58 X */ 0x00, /* BeginGlyph Reserved */ /* 0x59 Y */ 0x00, /* ReadGlyph Reserved */ /* 0x5a Z */ 0x00, /* Reserved */ /* 0x5b [ */ E_DisAsm_Operator, /* HP_BeginStream */ /* 0x5c \ */ E_DisAsm_Operator, /* HP_ReadStream */ /* 0x5d ] */ E_DisAsm_Operator, /* HP_EndStream */ /* 0x5e ^ */ E_DisAsm_Operator, /* HP_ExecStream */ /* 0x5f _ */ 0x00, /* 0x60 ` */ E_DisAsm_Operator, /* PopGS */ /* 0x61 a */ E_DisAsm_Operator, /* PushGS */ /* 0x62 b */ E_DisAsm_Operator, /* HP_SetClipReplace */ /* 0x63 c */ E_DisAsm_Operator, /* SetBrushSource */ /* 0x64 d */ E_DisAsm_Operator, /* SetCharAngle */ /* 0x65 e */ E_DisAsm_Operator, /* SetCharScale */ /* 0x66 f */ E_DisAsm_Operator, /* SetCharShear */ /* 0x67 g */ E_DisAsm_Operator, /* SetClipIntersect */ /* 0x68 h */ E_DisAsm_Operator, /* SetClipRectangle */ /* 0x69 i */ E_DisAsm_Operator, /* SetClipClipToPage */ /* 0x6a j */ E_DisAsm_Operator, /* SetColorSpace */ /* 0x6b k */ E_DisAsm_Operator, /* SetCursor */ /* 0x6c l */ E_DisAsm_Operator, /* SetCursorRel */ /* 0x6d m */ E_DisAsm_Operator, /* SetHalftoneMethod */ /* 0x6e n */ E_DisAsm_Operator, /* SetFillMode */ /* 0x6f o */ E_DisAsm_Operator, /* SetFont */ /* 0x70 p */ E_DisAsm_Operator, /* SetLineDash */ /* 0x71 q */ E_DisAsm_Operator, /* SetLineEnd */ /* 0x72 r */ E_DisAsm_Operator, /* SetLineJoin */ /* 0x73 s */ E_DisAsm_Operator, /* SetMiterLimit */ /* 0x74 t */ E_DisAsm_Operator, /* SetDefaultPageCTM */ /* 0x75 u */ E_DisAsm_Operator, /* SetPageOrigin */ /* 0x76 v */ E_DisAsm_Operator, /* SetPageRotation */ /* 0x77 w */ E_DisAsm_Operator, /* SetPageScale */ /* 0x78 x */ E_DisAsm_Operator, /* SetPaintTXMode */ /* 0x79 y */ E_DisAsm_Operator, /* SetPenSource */ /* 0x7a z */ E_DisAsm_Operator, /* SetPenWidth */ /* 0x7b { */ E_DisAsm_Operator, /* SetROP */ /* 0x7c | */ E_DisAsm_Operator, /* SetSourceTXMode */ /* 0x7d } */ E_DisAsm_Operator, /* SetCharBoldValue */ /* 0x7e ~ */ 0x00, /* 0x7f del */ E_DisAsm_Operator, /* SetClipMode */ /* 0x80 */ E_DisAsm_Operator, /* SetPathToClip */ /* 0x81 */ E_DisAsm_Operator, /* SetCharSubMode */ /* 0x82 */ 0x00, /* 0x83 */ 0x00, /* 0x84 */ E_DisAsm_Operator, /* CloseSubPath */ /* 0x85 */ E_DisAsm_Operator, /* NewPath */ /* 0x86 */ E_DisAsm_Operator, /* PaintPath */ /* 0x87 */ 0x00, /* 0x88 */ 0x00, /* 0x89 */ 0x00, /* 0x8a */ 0x00, /* 0x8b */ 0x00, /* 0x8c */ 0x00, /* 0x8d */ 0x00, /* 0x8e */ 0x00, /* 0x8f */ 0x00, /* 0x90 */ 0x00, /* 0x91 */ E_DisAsm_Operator, /* ArcPath */ /* 0x92 */ 0x00, /* 0x93 */ E_DisAsm_Operator, /* BezierPath */ /* 0x94 */ 0x00, /* 0x95 */ E_DisAsm_Operator, /* BezierRelPath */ /* 0x96 */ E_DisAsm_Operator, /* Chord */ /* 0x97 */ E_DisAsm_Operator, /* ChordPath */ /* 0x98 */ E_DisAsm_Operator, /* Ellipse */ /* 0x99 */ E_DisAsm_Operator, /* EllipsePath */ /* 0x9a */ 0x00, /* 0x9b */ E_DisAsm_Operator, /* LinePath */ /* 0x9c */ 0x00, /* 0x9d */ E_DisAsm_Operator, /* LineRelPath */ /* 0x9e */ E_DisAsm_Operator, /* Pie */ /* 0x9f */ E_DisAsm_Operator, /* PiePath */ /* 0xa0 */ E_DisAsm_Operator, /* Rectangle */ /* 0xa1 */ E_DisAsm_Operator, /* RectanglePath */ /* 0xa2 */ E_DisAsm_Operator, /* RoundRectangle */ /* 0xa3 */ E_DisAsm_Operator, /* RoundRectanglePage */ /* 0xa4 */ 0x00, /* 0xa5 */ 0x00, /* 0xa6 */ 0x00, /* 0xa7 */ 0x00, /* 0xa8 */ E_DisAsm_Operator, /* Text */ /* 0xa9 */ E_DisAsm_Operator, /* TextPath */ /* 0xaa */ E_DisAsm_Operator, /* SystemText */ /* 0xab */ 0x00, /* 0xac */ 0x00, /* 0xad */ 0x00, /* 0xae */ 0x00, /* 0xaf */ 0x00, /* 0xb0 */ E_DisAsm_Operator, /* BeginImage */ /* 0xb1 */ E_DisAsm_Operator, /* ReadImage */ /* 0xb2 */ E_DisAsm_Operator, /* EndImage */ /* 0xb3 */ E_DisAsm_Operator, /* BeginRastPattern */ /* 0xb4 */ E_DisAsm_Operator, /* ReadRastPattern */ /* 0xb5 */ E_DisAsm_Operator, /* EndRastPattern */ /* 0xb6 */ E_DisAsm_Operator, /* BeginScan */ /* 0xb7 */ 0x00, /* 0xb8 */ E_DisAsm_Operator, /* EndScan */ /* 0xb9 */ E_DisAsm_Operator, /* ScanLineRel, /* 0xba */ 0x00, /* 0xbb */ 0x00, /* 0xbc */ 0x00, /* 0xbd */ 0x00, /* 0xbe */ 0x00, /* 0xbf */ E_DisAsm_Operator, /* Hidden PassThrough Operator */ /* 0xc0 */ E_DisAsm_DataVal, /* 0xc1 */ E_DisAsm_DataVal, /* 0xc2 */ E_DisAsm_DataVal, /* 0xc3 */ E_DisAsm_DataVal, /* 0xc4 */ E_DisAsm_DataVal, /* 0xc5 */ E_DisAsm_DataVal, /* 0xc6 */ 0x00, /* 0xc7 */ 0x00, /* 0xc8 */ E_DisAsm_DataVal, /* 0xc9 */ E_DisAsm_DataVal, /* 0xca */ E_DisAsm_DataVal, /* 0xcb */ E_DisAsm_DataVal, /* 0xcc */ E_DisAsm_DataVal, /* 0xcd */ E_DisAsm_DataVal, /* 0xce */ 0x00, /* 0xcf */ 0x00, /* 0xd0 */ E_DisAsm_DataVal, /* 0xd1 */ E_DisAsm_DataVal, /* 0xd2 */ E_DisAsm_DataVal, /* 0xd3 */ E_DisAsm_DataVal, /* 0xd4 */ E_DisAsm_DataVal, /* 0xd5 */ E_DisAsm_DataVal, /* 0xd6 */ 0x00, /* 0xd7 */ 0x00, /* 0xd8 */ E_DisAsm_DataVal, /* 0xd9 */ E_DisAsm_DataVal, /* 0xda */ E_DisAsm_DataVal, /* 0xdb */ E_DisAsm_DataVal, /* 0xdc */ E_DisAsm_DataVal, /* 0xdd */ E_DisAsm_DataVal, /* 0xde */ 0x00, /* 0xdf */ 0x00, /* 0xe0 */ E_DisAsm_DataVal, /* 0xe1 */ E_DisAsm_DataVal, /* 0xe2 */ E_DisAsm_DataVal, /* 0xe3 */ E_DisAsm_DataVal, /* 0xe4 */ E_DisAsm_DataVal, /* 0xe5 */ E_DisAsm_DataVal, /* 0xe6 */ 0x00, /* 0xe7 */ 0x00, /* 0xe8 */ E_DisAsm_DataVal, /* 0xe9 */ E_DisAsm_DataVal, /* 0xea */ E_DisAsm_DataVal, /* 0xeb */ E_DisAsm_DataVal, /* 0xec */ E_DisAsm_DataVal, /* 0xed */ E_DisAsm_DataVal, /* 0xee */ 0x00, /* 0xef */ 0x00, /* 0xf0 */ 0x00, /* 0xf1 */ 0x00, /* 0xf2 */ 0x00, /* 0xf3 */ 0x00, /* 0xf4 */ 0x00, /* 0xf5 */ 0x00, /* 0xf6 */ 0x00, /* 0xf7 */ 0x00, /* 0xf8 */ E_DisAsm_AttrUByte, /* 0xf9 */ 0x00, /* 0xfa */ E_DisAsm_EmbeddedData, /* 0xfb */ E_DisAsm_EmbeddedDataByte, /* 0xfc */ 0x00, /* Reserved */ /* 0xfd */ 0x00, /* Reserved */ /* 0xfe */ 0x00, /* Reserved */ /* 0xff */ 0x00 /* Reserved */ }; const HP_UByte HP_dataTagMap[HP_MaxNumberOfTags]= { /* not used 0x00 - 0x2f*/ /* 0x00 nul */ 0x00, /* 0x01 soh */ 0x00, /* 0x02 stx */ 0x00, /* 0x03 etx */ 0x00, /* 0x04 eot */ 0x00, /* 0x05 enq */ 0x00, /* 0x06 ack */ 0x00, /* 0x07 bel */ 0x00, /* 0x08 bs */ 0x00, /* 0x09 ht */ 0x00, /* 0x0a nl */ 0x00, /* 0x0b vt */ 0x00, /* 0x0c np */ 0x00, /* 0x0d cr */ 0x00, /* 0x0e so */ 0x00, /* 0x0f si */ 0x00, /* 0x10 dle */ 0x00, /* 0x11 dc1 */ 0x00, /* 0x12 dc2 */ 0x00, /* 0x13 dc3 */ 0x00, /* 0x14 dc4 */ 0x00, /* 0x15 nak */ 0x00, /* 0x16 syn */ 0x00, /* 0x17 etb */ 0x00, /* 0x18 can */ 0x00, /* 0x19 em */ 0x00, /* 0x1a sub */ 0x00, /* 0x1b esc */ 0x00, /* 0x1c fs */ 0x00, /* 0x1d gs */ 0x00, /* 0x1e rs */ 0x00, /* 0x1f us */ 0x00, /* 0x20 sp */ 0x00, /* 0x21 ! */ 0x00, /* 0x22 " */ 0x00, /* 0x23 # */ 0x00, /* 0x24 $ */ 0x00, /* 0x25 % */ 0x00, /* 0x26 & */ 0x00, /* 0x27 ' */ 0x00, /* 0x28 ( */ 0x00, /* 0x29 ) */ 0x00, /* 0x2a * */ 0x00, /* 0x2b + */ 0x00, /* 0x2c , */ 0x00, /* 0x2d - */ 0x00, /* 0x2e . */ 0x00, /* 0x2f / */ 0x00, /* 0x30 0 */ 0x00, /* 0x31 1 */ 0x00, /* 0x32 2 */ 0x00, /* 0x33 3 */ 0x00, /* 0x34 4 */ 0x00, /* 0x35 5 */ 0x00, /* 0x36 6 */ 0x00, /* 0x37 7 */ 0x00, /* 0x38 8 */ 0x00, /* 0x39 9 */ 0x00, /* 0x3a : */ 0x00, /* 0x3b ; */ 0x00, /* 0x3c < */ 0x00, /* 0x3d = */ 0x00, /* 0x3e > */ 0x00, /* 0x3f ? */ 0x00, /* 0x40 @ */ 0x00, /* 0x41 A */ 0x00, /* 0x42 B */ 0x00, /* 0x43 C */ 0x00, /* 0x44 D */ 0x00, /* 0x45 E */ 0x00, /* 0x46 F */ 0x00, /* 0x47 G */ 0x00, /* 0x48 H */ 0x00, /* 0x49 I */ 0x00, /* 0x4a J */ 0x00, /* 0x4b K */ 0x00, /* 0x4c L */ 0x00, /* 0x4d M */ 0x00, /* 0x4e N */ 0x00, /* 0x4f O */ 0x00, /* 0x50 P */ 0x00, /* 0x51 Q */ 0x00, /* 0x52 R */ 0x00, /* 0x53 S */ 0x00, /* 0x54 T */ 0x00, /* 0x55 U */ 0x00, /* 0x56 V */ 0x00, /* 0x57 W */ 0x00, /* 0x58 X */ 0x00, /* 0x59 Y */ 0x00, /* 0x5a Z */ 0x00, /* 0x5b [ */ 0x00, /* 0x5c \ */ 0x00, /* 0x5d ] */ 0x00, /* 0x5e ^ */ 0x00, /* 0x5f _ */ 0x00, /* 0x60 ` */ 0x00, /* 0x61 a */ 0x00, /* 0x62 b */ 0x00, /* 0x63 c */ 0x00, /* 0x64 d */ 0x00, /* 0x65 e */ 0x00, /* 0x66 f */ 0x00, /* 0x67 g */ 0x00, /* 0x68 h */ 0x00, /* 0x69 i */ 0x00, /* 0x6a j */ 0x00, /* 0x6b k */ 0x00, /* 0x6c l */ 0x00, /* 0x6d m */ 0x00, /* 0x6e n */ 0x00, /* 0x6f o */ 0x00, /* 0x70 p */ 0x00, /* 0x71 q */ 0x00, /* 0x72 r */ 0x00, /* 0x73 s */ 0x00, /* 0x74 t */ 0x00, /* 0x75 u */ 0x00, /* 0x76 v */ 0x00, /* 0x77 w */ 0x00, /* 0x78 x */ 0x00, /* 0x79 y */ 0x00, /* 0x7a z */ 0x00, /* 0x7b { */ 0x00, /* 0x7c | */ 0x00, /* 0x7d } */ 0x00, /* 0x7e ~ */ 0x00, /* 0x7f del */ 0x00, /* 0x80 */ 0x00, /* 0x81 */ 0x00, /* 0x82 */ 0x00, /* 0x83 */ 0x00, /* 0x84 */ 0x00, /* 0x85 */ 0x00, /* 0x86 */ 0x00, /* 0x87 */ 0x00, /* 0x88 */ 0x00, /* 0x89 */ 0x00, /* 0x8a */ 0x00, /* 0x8b */ 0x00, /* 0x8c */ 0x00, /* 0x8d */ 0x00, /* 0x8e */ 0x00, /* 0x8f */ 0x00, /* 0x90 */ 0x00, /* 0x91 */ 0x00, /* 0x92 */ 0x00, /* 0x93 */ 0x00, /* 0x94 */ 0x00, /* 0x95 */ 0x00, /* 0x96 */ 0x00, /* 0x97 */ 0x00, /* 0x98 */ 0x00, /* 0x99 */ 0x00, /* 0x9a */ 0x00, /* 0x9b */ 0x00, /* 0x9c */ 0x00, /* 0x9d */ 0x00, /* 0x9e */ 0x00, /* 0x9f */ 0x00, /* 0xa0 */ 0x00, /* 0xa1 */ 0x00, /* 0xa2 */ 0x00, /* 0xa3 */ 0x00, /* 0xa4 */ 0x00, /* 0xa5 */ 0x00, /* 0xa6 */ 0x00, /* 0xa7 */ 0x00, /* 0xa8 */ 0x00, /* 0xa9 */ 0x00, /* 0xaa */ 0x00, /* 0xab */ 0x00, /* 0xac */ 0x00, /* 0xad */ 0x00, /* 0xae */ 0x00, /* 0xaf */ 0x00, /* 0xb0 */ 0x00, /* 0xb1 */ 0x00, /* 0xb2 */ 0x00, /* 0xb3 */ 0x00, /* 0xb4 */ 0x00, /* 0xb5 */ 0x00, /* 0xb6 */ 0x00, /* 0xb7 */ 0x00, /* 0xb8 */ 0x00, /* 0xb9 */ 0x00, /* 0xba */ 0x00, /* 0xbb */ 0x00, /* 0xbc */ 0x00, /* 0xbd */ 0x00, /* 0xbe */ 0x00, /* 0xbf */ 0x00, /* 0xc0 */ E_ActualUByte, /* 0xc1 */ E_ActualUInt16, /* 0xc2 */ E_ActualUInt32, /* 0xc3 */ E_ActualSInt16, /* 0xc4 */ E_ActualSInt32, /* 0xc5 */ E_ActualReal32, /* 0xc6 */ 0x00, /* 0xc7 */ 0x00, /* 0xc8 */ E_ActualUByteArray, /* 0xc9 */ E_ActualUInt16Array, /* 0xca */ E_ActualUInt32Array, /* 0xcb */ E_ActualSInt16Array, /* 0xcc */ E_ActualSInt32Array, /* 0xcd */ E_ActualReal32Array, /* 0xce */ 0x00, /* 0xcf */ 0x00, /* 0xd0 */ E_ActualXyUByte, /* 0xd1 */ E_ActualXyUInt16, /* 0xd2 */ E_ActualXyUInt32, /* 0xd3 */ E_ActualXySInt16, /* 0xd4 */ E_ActualXySInt32, /* 0xd5 */ E_ActualXyReal32, /* 0xd6 */ 0x00, /* 0xd7 */ 0x00, /* 0xd8 */ 0x00, /* 0xd9 */ 0x00, /* 0xda */ 0x00, /* 0xdb */ 0x00, /* 0xdc */ 0x00, /* 0xdd */ 0x00, /* 0xde */ 0x00, /* 0xdf */ 0x00, /* 0xe0 */ E_ActualBoxUByte, /* 0xe1 */ E_ActualBoxUInt16, /* 0xe2 */ E_ActualBoxUInt32, /* 0xe3 */ E_ActualBoxSInt16, /* 0xe4 */ E_ActualBoxSInt32, /* 0xe5 */ E_ActualBoxReal32, /* 0xe6 */ 0x00, /* 0xe7 */ 0x00, /* 0xe8 */ 0x00, /* 0xe9 */ 0x00, /* 0xea */ 0x00, /* 0xeb */ 0x00, /* 0xec */ 0x00, /* 0xed */ 0x00, /* 0xee */ 0x00, /* 0xef */ 0x00, /* 0xf0 */ 0x00, /* 0xf1 */ 0x00, /* 0xf2 */ 0x00, /* 0xf3 */ 0x00, /* 0xf4 */ 0x00, /* 0xf5 */ 0x00, /* 0xf6 */ 0x00, /* 0xf7 */ 0x00, /* 0xf8 */ 0x00, /* 0xf9 */ 0x00, /* 0xfa */ 0x00, /* 0xfb */ 0x00, /* 0xfc */ 0x00, /* Reserved */ /* 0xfd */ 0x00, /* Reserved */ /* 0xfe */ 0x00, /* Reserved */ /* 0xff */ 0x00 /* Reserved */ }; const HP_UByte HP_pointOperatorMap[HP_MaxNumberOfTags]= { /* not used 0x00 - 0x2f*/ /* 0x00 nul */ 0x00, /* 0x01 soh */ 0x00, /* 0x02 stx */ 0x00, /* 0x03 etx */ 0x00, /* 0x04 eot */ 0x00, /* 0x05 enq */ 0x00, /* 0x06 ack */ 0x00, /* 0x07 bel */ 0x00, /* 0x08 bs */ 0x00, /* 0x09 ht */ 0x00, /* 0x0a nl */ 0x00, /* 0x0b vt */ 0x00, /* 0x0c np */ 0x00, /* 0x0d cr */ 0x00, /* 0x0e so */ 0x00, /* 0x0f si */ 0x00, /* 0x10 dle */ 0x00, /* 0x11 dc1 */ 0x00, /* 0x12 dc2 */ 0x00, /* 0x13 dc3 */ 0x00, /* 0x14 dc4 */ 0x00, /* 0x15 nak */ 0x00, /* 0x16 syn */ 0x00, /* 0x17 etb */ 0x00, /* 0x18 can */ 0x00, /* 0x19 em */ 0x00, /* 0x1a sub */ 0x00, /* 0x1b esc */ 0x00, /* 0x1c fs */ 0x00, /* 0x1d gs */ 0x00, /* 0x1e rs */ 0x00, /* 0x1f us */ 0x00, /* 0x20 sp */ 0x00, /* 0x21 ! */ 0x00, /* 0x22 " */ 0x00, /* 0x23 # */ 0x00, /* 0x24 $ */ 0x00, /* 0x25 % */ 0x00, /* 0x26 & */ 0x00, /* 0x27 ' */ 0x00, /* 0x28 ( */ 0x00, /* 0x29 ) */ 0x00, /* 0x2a * */ 0x00, /* 0x2b + */ 0x00, /* 0x2c , */ 0x00, /* 0x2d - */ 0x00, /* 0x2e . */ 0x00, /* 0x2f / */ 0x00, /* 0x30 0 */ 0x00, /* 0x31 1 */ 0x00, /* 0x32 2 */ 0x00, /* 0x33 3 */ 0x00, /* 0x34 4 */ 0x00, /* 0x35 5 */ 0x00, /* 0x36 6 */ 0x00, /* 0x37 7 */ 0x00, /* 0x38 8 */ 0x00, /* 0x39 9 */ 0x00, /* 0x3a : */ 0x00, /* 0x3b ; */ 0x00, /* 0x3c < */ 0x00, /* 0x3d = */ 0x00, /* 0x3e > */ 0x00, /* 0x3f ? */ 0x00, /* 0x40 @ */ 0x00, /* 0x41 A */ 0x00, /* 0x42 B */ 0x00, /* 0x43 C */ 0x00, /* 0x44 D */ 0x00, /* 0x45 E */ 0x00, /* 0x46 F */ 0x00, /* 0x47 G */ 0x00, /* 0x48 H */ 0x00, /* 0x49 I */ 0x00, /* 0x4a J */ 0x00, /* 0x4b K */ 0x00, /* 0x4c L */ 0x00, /* 0x4d M */ 0x00, /* 0x4e N */ 0x00, /* 0x4f O */ 0x00, /* 0x50 P */ 0x00, /* 0x51 Q */ 0x00, /* 0x52 R */ 0x00, /* 0x53 S */ 0x00, /* 0x54 T */ 0x00, /* 0x55 U */ 0x00, /* 0x56 V */ 0x00, /* 0x57 W */ 0x00, /* 0x58 X */ 0x00, /* 0x59 Y */ 0x00, /* 0x5a Z */ 0x00, /* 0x5b [ */ 0x00, /* 0x5c \ */ 0x00, /* 0x5d ] */ 0x00, /* 0x5e ^ */ 0x00, /* 0x5f _ */ 0x00, /* 0x60 ` */ 0x00, /* 0x61 a */ 0x00, /* 0x62 b */ 0x00, /* 0x63 c */ 0x00, /* 0x64 d */ 0x00, /* 0x65 e */ 0x00, /* 0x66 f */ 0x00, /* 0x67 g */ 0x00, /* 0x68 h */ 0x00, /* 0x69 i */ 0x00, /* 0x6a j */ 0x00, /* 0x6b k */ 0x00, /* 0x6c l */ 0x00, /* 0x6d m */ 0x00, /* 0x6e n */ 0x00, /* 0x6f o */ 0x00, /* 0x70 p */ 0x00, /* 0x71 q */ 0x00, /* 0x72 r */ 0x00, /* 0x73 s */ 0x00, /* 0x74 t */ 0x00, /* 0x75 u */ 0x00, /* 0x76 v */ 0x00, /* 0x77 w */ 0x00, /* 0x78 x */ 0x00, /* 0x79 y */ 0x00, /* 0x7a z */ 0x00, /* 0x7b { */ 0x00, /* 0x7c | */ 0x00, /* 0x7d } */ 0x00, /* 0x7e ~ */ 0x00, /* 0x7f del */ 0x00, /* 0x80 */ 0x00, /* 0x81 */ 0x00, /* 0x82 */ 0x00, /* 0x83 */ 0x00, /* 0x84 */ 0x00, /* 0x85 */ 0x00, /* 0x86 */ 0x00, /* 0x87 */ 0x00, /* 0x88 */ 0x00, /* 0x89 */ 0x00, /* 0x8a */ 0x00, /* 0x8b */ 0x00, /* 0x8c */ 0x00, /* 0x8d */ 0x00, /* 0x8e */ 0x00, /* 0x8f */ 0x00, /* 0x90 */ 0x00, /* 0x91 */ 0x00, /* 0x92 */ 0x00, /* 0x93 */ E_DisAsm_Operator, /* BezierPath */ /* 0x94 */ 0x00, /* 0x95 */ E_DisAsm_Operator, /* BezierRelPath */ /* 0x96 */ 0x00, /* 0x97 */ 0x00, /* 0x98 */ 0x00, /* 0x99 */ 0x00, /* 0x9a */ 0x00, /* 0x9b */ E_DisAsm_Operator, /* LinePath */ /* 0x9c */ 0x00, /* 0x9d */ E_DisAsm_Operator, /* LineRelPath */ /* 0x9e */ 0x00, /* 0x9f */ 0x00, /* 0xa0 */ 0x00, /* 0xa1 */ 0x00, /* 0xa2 */ 0x00, /* 0xa3 */ 0x00, /* 0xa4 */ 0x00, /* 0xa5 */ 0x00, /* 0xa6 */ 0x00, /* 0xa7 */ 0x00, /* 0xa8 */ 0x00, /* 0xa9 */ 0x00, /* 0xaa */ 0x00, /* 0xab */ 0x00, /* 0xac */ 0x00, /* 0xad */ 0x00, /* 0xae */ 0x00, /* 0xaf */ 0x00, /* 0xb0 */ 0x00, /* 0xb1 */ 0x00, /* 0xb2 */ 0x00, /* 0xb3 */ 0x00, /* 0xb4 */ 0x00, /* 0xb5 */ 0x00, /* 0xb6 */ 0x00, /* 0xb7 */ 0x00, /* 0xb8 */ 0x00, /* 0xb9 */ E_DisAsm_Operator, /* ScanLineRel */ /* 0xba */ 0x00, /* 0xbb */ 0x00, /* 0xbc */ 0x00, /* 0xbd */ 0x00, /* 0xbe */ 0x00, /* 0xbf */ 0x00, /* 0xc0 */ 0x00, /* 0xc1 */ 0x00, /* 0xc2 */ 0x00, /* 0xc3 */ 0x00, /* 0xc4 */ 0x00, /* 0xc5 */ 0x00, /* 0xc6 */ 0x00, /* 0xc7 */ 0x00, /* 0xc8 */ 0x00, /* 0xc9 */ 0x00, /* 0xca */ 0x00, /* 0xcb */ 0x00, /* 0xcc */ 0x00, /* 0xcd */ 0x00, /* 0xce */ 0x00, /* 0xcf */ 0x00, /* 0xd0 */ 0x00, /* 0xd1 */ 0x00, /* 0xd2 */ 0x00, /* 0xd3 */ 0x00, /* 0xd4 */ 0x00, /* 0xd5 */ 0x00, /* 0xd6 */ 0x00, /* 0xd7 */ 0x00, /* 0xd8 */ 0x00, /* 0xd9 */ 0x00, /* 0xda */ 0x00, /* 0xdb */ 0x00, /* 0xdc */ 0x00, /* 0xdd */ 0x00, /* 0xde */ 0x00, /* 0xdf */ 0x00, /* 0xe0 */ 0x00, /* 0xe1 */ 0x00, /* 0xe2 */ 0x00, /* 0xe3 */ 0x00, /* 0xe4 */ 0x00, /* 0xe5 */ 0x00, /* 0xe6 */ 0x00, /* 0xe7 */ 0x00, /* 0xe8 */ 0x00, /* 0xe9 */ 0x00, /* 0xea */ 0x00, /* 0xeb */ 0x00, /* 0xec */ 0x00, /* 0xed */ 0x00, /* 0xee */ 0x00, /* 0xef */ 0x00, /* 0xf0 */ 0x00, /* 0xf1 */ 0x00, /* 0xf2 */ 0x00, /* 0xf3 */ 0x00, /* 0xf4 */ 0x00, /* 0xf5 */ 0x00, /* 0xf6 */ 0x00, /* 0xf7 */ 0x00, /* 0xf8 */ 0x00, /* 0xf9 */ 0x00, /* 0xfa */ 0x00, /* 0xfb */ 0x00, /* 0xfc */ 0x00, /* Reserved */ /* 0xfd */ 0x00, /* Reserved */ /* 0xfe */ 0x00, /* Reserved */ /* 0xff */ 0x00 /* Reserved */ }; #define MAX_NUMBER_OF_TYPES 256 /* the following table maps actual data types to * the basic data types (see the #defines above * for more details) */ const HP_UByte actualTypeMap[MAX_NUMBER_OF_TYPES]= { /* 0 */ E_BasicTypeUByte, /* 1 */ E_BasicTypeSByte, /* 2 */ E_BasicTypeUInt16, /* 3 */ E_BasicTypeSInt16, /* 4 */ E_BasicTypeUInt32, /* 5 */ E_BasicTypeSInt32, /* 6 */ E_BasicTypeReal32, /* 7 */ E_BasicTypeUByte, /* 8 */ E_BasicTypeSByte, /* 9 */ E_BasicTypeUInt16, /* 10 */ E_BasicTypeSInt16, /* 11 */ E_BasicTypeUInt32, /* 12 */ E_BasicTypeSInt32, /* 13 */ E_BasicTypeReal32, /* 14 */ E_BasicTypeUInt32, /* 15 */ E_BasicTypeUInt32, /* 16 */ E_BasicTypeUByte, /* 17 */ E_BasicTypeSByte, /* 18 */ E_BasicTypeUInt16, /* 19 */ E_BasicTypeSInt16, /* 20 */ E_BasicTypeUInt32, /* 21 */ E_BasicTypeSInt32, /* 22 */ E_BasicTypeReal32, /* 23 */ 0x00, /* 24 */ 0x00, /* 25 */ 0x00, /* 26 */ 0x00, /* 27 */ 0x00, /* 28 */ 0x00, /* 29 */ 0x00, /* 30 */ 0x00, /* 31 */ 0x00, /* 32 */ E_BasicTypeUByte, /* 33 */ E_BasicTypeSByte, /* 34 */ E_BasicTypeUInt16, /* 35 */ E_BasicTypeSInt16, /* 36 */ E_BasicTypeUInt32, /* 37 */ E_BasicTypeSInt32, /* 38 */ E_BasicTypeReal32, /* 39 */ 0x00, /* 40 */ 0x00, /* 41 */ 0x00, /* 42 */ 0x00, /* 43 */ 0x00, /* 44 */ 0x00, /* 45 */ 0x00, /* 46 */ 0x00, /* 47 */ 0x00, /* 48 */ E_BasicTypeUByte, /* 49 */ E_BasicTypeSByte, /* 50 */ E_BasicTypeUInt16, /* 51 */ E_BasicTypeSInt16, /* 52 */ E_BasicTypeUInt32, /* 53 */ E_BasicTypeSInt32, /* 54 */ E_BasicTypeReal32, /* 55 */ 0x00, /* 56 */ 0x00, /* 57 */ 0x00, /* 58 */ 0x00, /* 59 */ 0x00, /* 60 */ 0x00, /* 61 */ 0x00, /* 62 */ 0x00, /* 63 */ 0x00, /* 64 */ E_BasicTypeUByte, /* 65 */ E_BasicTypeSByte, /* 66 */ E_BasicTypeUInt16, /* 67 */ E_BasicTypeSInt16, /* 68 */ E_BasicTypeUInt32, /* 69 */ E_BasicTypeSInt32, /* 70 */ E_BasicTypeReal32, /* 71 */ 0x00, /* 72 */ 0x00, /* 73 */ 0x00, /* 74 */ 0x00, /* 75 */ 0x00, /* 76 */ 0x00, /* 77 */ 0x00, /* 78 */ 0x00, /* 79 */ 0x00, /* 80 */ E_BasicTypeUByte, /* 81 */ E_BasicTypeSByte, /* 82 */ E_BasicTypeUInt16, /* 83 */ E_BasicTypeSInt16, /* 84 */ E_BasicTypeUInt32, /* 85 */ E_BasicTypeSInt32, /* 86 */ E_BasicTypeReal32, /* 87 */ 0x00, /* 88 */ 0x00, /* 89 */ 0x00, /* 90 */ 0x00, /* 91 */ 0x00, /* 92 */ 0x00, /* 93 */ 0x00, /* 94 */ 0x00, /* 95 */ 0x00, /* 96 */ E_BasicTypeUByte, /* 97 */ E_BasicTypeSByte, /* 98 */ E_BasicTypeUInt16, /* 99 */ E_BasicTypeSInt16, /* 100 */ E_BasicTypeUInt32, /* 101 */ E_BasicTypeSInt32, /* 102 */ E_BasicTypeReal32, /* 103 */ 0x00, /* 104 */ 0x00, /* 105 */ 0x00, /* 106 */ 0x00, /* 107 */ 0x00, /* 108 */ 0x00, /* 109 */ 0x00, /* 110 */ 0x00, /* 111 */ 0x00, /* 112 */ E_BasicTypeUByte, /* 113 */ E_BasicTypeSByte, /* 114 */ E_BasicTypeUInt16, /* 115 */ E_BasicTypeSInt16, /* 116 */ E_BasicTypeUInt32, /* 117 */ E_BasicTypeSInt32, /* 118 */ E_BasicTypeReal32, /* 119 */ 0x00, /* 120 */ 0x00, /* 121 */ 0x00, /* 122 */ 0x00, /* 123 */ 0x00, /* 124 */ 0x00, /* 125 */ 0x00, /* 126 */ 0x00, /* 127 */ 0x00, /* 128 */ 0x00, /* 129 */ 0x00, /* 130 */ 0x00, /* 131 */ 0x00, /* 132 */ 0x00, /* 133 */ 0x00, /* 134 */ 0x00, /* 135 */ 0x00, /* 136 */ 0x00, /* 137 */ 0x00, /* 138 */ 0x00, /* 139 */ 0x00, /* 140 */ 0x00, /* 141 */ 0x00, /* 142 */ 0x00, /* 143 */ 0x00, /* 144 */ 0x00, /* 145 */ 0x00, /* 146 */ 0x00, /* 147 */ 0x00, /* 148 */ 0x00, /* 149 */ 0x00, /* 150 */ 0x00, /* 151 */ 0x00, /* 152 */ 0x00, /* 153 */ 0x00, /* 154 */ 0x00, /* 155 */ 0x00, /* 156 */ 0x00, /* 157 */ 0x00, /* 158 */ 0x00, /* 159 */ 0x00, /* 160 */ 0x00, /* 161 */ 0x00, /* 162 */ 0x00, /* 163 */ 0x00, /* 164 */ 0x00, /* 165 */ 0x00, /* 166 */ 0x00, /* 167 */ 0x00, /* 168 */ 0x00, /* 169 */ 0x00, /* 170 */ 0x00, /* 171 */ 0x00, /* 172 */ 0x00, /* 173 */ 0x00, /* 174 */ 0x00, /* 175 */ 0x00, /* 176 */ 0x00, /* 177 */ 0x00, /* 178 */ 0x00, /* 179 */ 0x00, /* 180 */ 0x00, /* 181 */ 0x00, /* 182 */ 0x00, /* 183 */ 0x00, /* 184 */ 0x00, /* 185 */ 0x00, /* 186 */ 0x00, /* 187 */ 0x00, /* 188 */ 0x00, /* 189 */ 0x00, /* 190 */ 0x00, /* 191 */ 0x00, /* 192 */ 0x00, /* 193 */ 0x00, /* 194 */ 0x00, /* 195 */ 0x00, /* 196 */ 0x00, /* 197 */ 0x00, /* 198 */ 0x00, /* 199 */ 0x00, /* 200 */ 0x00, /* 201 */ 0x00, /* 202 */ 0x00, /* 203 */ 0x00, /* 204 */ 0x00, /* 205 */ 0x00, /* 206 */ 0x00, /* 207 */ 0x00, /* 208 */ 0x00, /* 209 */ 0x00, /* 210 */ 0x00, /* 211 */ 0x00, /* 212 */ 0x00, /* 213 */ 0x00, /* 214 */ 0x00, /* 215 */ 0x00, /* 216 */ 0x00, /* 217 */ 0x00, /* 218 */ 0x00, /* 219 */ 0x00, /* 220 */ 0x00, /* 221 */ 0x00, /* 222 */ 0x00, /* 223 */ 0x00, /* 224 */ 0x00, /* 225 */ 0x00, /* 226 */ 0x00, /* 227 */ 0x00, /* 228 */ 0x00, /* 229 */ 0x00, /* 230 */ 0x00, /* 231 */ 0x00, /* 232 */ 0x00, /* 233 */ 0x00, /* 234 */ 0x00, /* 235 */ 0x00, /* 236 */ 0x00, /* 237 */ 0x00, /* 238 */ 0x00, /* 239 */ 0x00, /* 240 */ 0x00, /* 241 */ 0x00, /* 242 */ 0x00, /* 243 */ 0x00, /* 244 */ 0x00, /* 245 */ 0x00, /* 246 */ 0x00, /* 247 */ 0x00, /* 248 */ 0x00, /* 249 */ 0x00, /* 250 */ 0x00, /* 251 */ 0x00, /* 252 */ 0x00, /* 253 */ 0x00, /* 254 */ 0x00, /* 255 */ 0x00 }; /* above is the end of the actual data type map */ #define XY_Multiplier 2 #define Box_Multiplier 4 #define Array_Multiplier 1000 /* The following are data size constants which will determine * the input data buffer size for each data value parsed. */ const HP_UInt16 dataTypeLenMap[MAX_NUMBER_OF_TYPES]= { /* 0 */ sizeof(HP_UByte), /* 1 */ 0x00, /* 2 */ sizeof(HP_UInt16), /* 3 */ sizeof(HP_SInt16), /* 4 */ sizeof(HP_UInt32), /* 5 */ sizeof(HP_SInt32), /* 6 */ sizeof(HP_Real32), /* 7 */ sizeof(HP_UByte), /* 8 */ 0x00, /* 9 */ sizeof(HP_UInt16), /* 10 */ sizeof(HP_SInt16), /* 11 */ sizeof(HP_UInt32), /* 12 */ sizeof(HP_SInt32), /* 13 */ sizeof(HP_Real32), /* 14 */ sizeof(HP_UInt32), /* 15 */ 0x00, /* 16 */ sizeof(HP_UByte) * XY_Multiplier, /* 17 */ 0x00, /* 18 */ sizeof(HP_UInt16) * XY_Multiplier, /* 19 */ sizeof(HP_SInt16) * XY_Multiplier, /* 20 */ sizeof(HP_UInt32) * XY_Multiplier, /* 21 */ sizeof(HP_SInt32) * XY_Multiplier, /* 22 */ sizeof(HP_Real32) * XY_Multiplier, /* 23 */ 0x00, /* 24 */ 0x00, /* 25 */ 0x00, /* 26 */ 0x00, /* 27 */ 0x00, /* 28 */ 0x00, /* 29 */ 0x00, /* 30 */ 0x00, /* 31 */ 0x00, /* 32 */ sizeof(HP_UByte) * Box_Multiplier, /* 33 */ 0x00, /* 34 */ sizeof(HP_UInt16) * Box_Multiplier, /* 35 */ sizeof(HP_UInt16) * Box_Multiplier, /* 36 */ sizeof(HP_UInt32) * Box_Multiplier, /* 37 */ sizeof(HP_UInt32) * Box_Multiplier, /* 38 */ sizeof(HP_Real32) * Box_Multiplier, /* 39 */ 0x00, /* 40 */ 0x00, /* 41 */ 0x00, /* 42 */ 0x00, /* 43 */ 0x00, /* 44 */ 0x00, /* 45 */ 0x00, /* 46 */ 0x00, /* 47 */ 0x00, /* 48 */ sizeof(HP_UByte) * Array_Multiplier, /* 49 */ 0x00, /* 50 */ sizeof(HP_UInt16) * Array_Multiplier, /* 51 */ sizeof(HP_SInt16) * Array_Multiplier, /* 52 */ sizeof(HP_UInt32) * Array_Multiplier, /* 53 */ sizeof(HP_SInt32) * Array_Multiplier, /* 54 */ sizeof(HP_Real32) * Array_Multiplier, /* 55 */ 0x00, /* 56 */ 0x00, /* 57 */ 0x00, /* 58 */ 0x00, /* 59 */ 0x00, /* 60 */ 0x00, /* 61 */ 0x00, /* 62 */ 0x00, /* 63 */ 0x00, /* 64 */ sizeof(HP_UByte) * XY_Multiplier * Array_Multiplier, /* 65 */ 0x00, /* 66 */ sizeof(HP_UInt16) * XY_Multiplier * Array_Multiplier, /* 67 */ sizeof(HP_SInt16) * XY_Multiplier * Array_Multiplier, /* 68 */ sizeof(HP_UInt32) * XY_Multiplier * Array_Multiplier, /* 69 */ sizeof(HP_SInt32) * XY_Multiplier * Array_Multiplier, /* 70 */ sizeof(HP_Real32) * XY_Multiplier * Array_Multiplier, /* 71 */ 0x00, /* 72 */ 0x00, /* 73 */ 0x00, /* 74 */ 0x00, /* 75 */ 0x00, /* 76 */ 0x00, /* 77 */ 0x00, /* 78 */ 0x00, /* 79 */ 0x00, /* 80 */ sizeof(HP_UByte) * Box_Multiplier * Array_Multiplier, /* 81 */ 0x00, /* 82 */ sizeof(HP_UInt16) * Box_Multiplier * Array_Multiplier, /* 83 */ sizeof(HP_SInt16) * Box_Multiplier * Array_Multiplier, /* 84 */ sizeof(HP_UInt32) * Box_Multiplier * Array_Multiplier, /* 85 */ sizeof(HP_SInt32) * Box_Multiplier * Array_Multiplier, /* 86 */ sizeof(HP_Real32) * Box_Multiplier * Array_Multiplier, /* 87 */ 0x00, /* 88 */ 0x00, /* 89 */ 0x00, /* 90 */ 0x00, /* 91 */ 0x00, /* 92 */ 0x00, /* 93 */ 0x00, /* 94 */ 0x00, /* 95 */ 0x00, /* 96 */ sizeof(HP_UByte) * Array_Multiplier, /* 97 */ 0x00, /* 98 */ sizeof(HP_UInt16) * Array_Multiplier, /* 99 */ sizeof(HP_SInt16) * Array_Multiplier, /* 100 */ sizeof(HP_UInt32) * Array_Multiplier, /* 101 */ sizeof(HP_SInt32) * Array_Multiplier, /* 102 */ sizeof(HP_Real32) * Array_Multiplier, /* 103 */ 0x00, /* 104 */ 0x00, /* 105 */ 0x00, /* 106 */ 0x00, /* 107 */ 0x00, /* 108 */ 0x00, /* 109 */ 0x00, /* 110 */ 0x00, /* 111 */ 0x00, /* 112 */ sizeof(HP_UByte) * Array_Multiplier, /* 113 */ 0x00, /* 114 */ sizeof(HP_UInt16) * Array_Multiplier, /* 115 */ sizeof(HP_SInt16) * Array_Multiplier, /* 116 */ sizeof(HP_UInt32) * Array_Multiplier, /* 117 */ sizeof(HP_SInt32) * Array_Multiplier, /* 118 */ sizeof(HP_Real32) * Array_Multiplier, /* 119 */ 0x00, /* 120 */ 0x00, /* 121 */ 0x00, /* 122 */ 0x00, /* 123 */ 0x00, /* 124 */ 0x00, /* 125 */ 0x00, /* 126 */ 0x00, /* 127 */ 0x00, /* 128 */ 0x00, /* 129 */ 0x00, /* 130 */ 0x00, /* 131 */ 0x00, /* 132 */ 0x00, /* 133 */ 0x00, /* 134 */ 0x00, /* 135 */ 0x00, /* 136 */ 0x00, /* 137 */ 0x00, /* 138 */ 0x00, /* 139 */ 0x00, /* 140 */ 0x00, /* 141 */ 0x00, /* 142 */ 0x00, /* 143 */ 0x00, /* 144 */ 0x00, /* 145 */ 0x00, /* 146 */ 0x00, /* 147 */ 0x00, /* 148 */ 0x00, /* 149 */ 0x00, /* 150 */ 0x00, /* 151 */ 0x00, /* 152 */ 0x00, /* 153 */ 0x00, /* 154 */ 0x00, /* 155 */ 0x00, /* 156 */ 0x00, /* 157 */ 0x00, /* 158 */ 0x00, /* 159 */ 0x00, /* 160 */ 0x00, /* 161 */ 0x00, /* 162 */ 0x00, /* 163 */ 0x00, /* 164 */ 0x00, /* 165 */ 0x00, /* 166 */ 0x00, /* 167 */ 0x00, /* 168 */ 0x00, /* 169 */ 0x00, /* 170 */ 0x00, /* 171 */ 0x00, /* 172 */ 0x00, /* 173 */ 0x00, /* 174 */ 0x00, /* 175 */ 0x00, /* 176 */ 0x00, /* 177 */ 0x00, /* 178 */ 0x00, /* 179 */ 0x00, /* 180 */ 0x00, /* 181 */ 0x00, /* 182 */ 0x00, /* 183 */ 0x00, /* 184 */ 0x00, /* 185 */ 0x00, /* 186 */ 0x00, /* 187 */ 0x00, /* 188 */ 0x00, /* 189 */ 0x00, /* 190 */ 0x00, /* 191 */ 0x00, /* 192 */ 0x00, /* 193 */ 0x00, /* 194 */ 0x00, /* 195 */ 0x00, /* 196 */ 0x00, /* 197 */ 0x00, /* 198 */ 0x00, /* 199 */ 0x00, /* 200 */ 0x00, /* 201 */ 0x00, /* 202 */ 0x00, /* 203 */ 0x00, /* 204 */ 0x00, /* 205 */ 0x00, /* 206 */ 0x00, /* 207 */ 0x00, /* 208 */ 0x00, /* 209 */ 0x00, /* 210 */ 0x00, /* 211 */ 0x00, /* 212 */ 0x00, /* 213 */ 0x00, /* 214 */ 0x00, /* 215 */ 0x00, /* 216 */ 0x00, /* 217 */ 0x00, /* 218 */ 0x00, /* 219 */ 0x00, /* 220 */ 0x00, /* 221 */ 0x00, /* 222 */ 0x00, /* 223 */ 0x00, /* 224 */ 0x00, /* 225 */ 0x00, /* 226 */ 0x00, /* 227 */ 0x00, /* 228 */ 0x00, /* 229 */ 0x00, /* 230 */ 0x00, /* 231 */ 0x00, /* 232 */ 0x00, /* 233 */ 0x00, /* 234 */ 0x00, /* 235 */ 0x00, /* 236 */ 0x00, /* 237 */ 0x00, /* 238 */ 0x00, /* 239 */ 0x00, /* 240 */ 0x00, /* 241 */ 0x00, /* 242 */ 0x00, /* 243 */ 0x00, /* 244 */ 0x00, /* 245 */ 0x00, /* 246 */ 0x00, /* 247 */ 0x00, /* 248 */ 0x00, /* 249 */ 0x00, /* 250 */ 0x00, /* 251 */ 0x00, /* 252 */ 0x00, /* 253 */ 0x00, /* 254 */ 0x00, /* 255 */ 0x00 }; /* above is the end of the data type length map */ #define NUM_OF_HEX_VALUE_ENTRIES 256 /* the following table quickly maps ascii hex digits to their corresponding numeric values: */ const HP_UByte hexValueMap[NUM_OF_HEX_VALUE_ENTRIES]= { /* 00 nul */ 0x00, /* 01 soh */ 0x00, /* 02 stx */ 0x00, /* 03 etx */ 0x00, /* 04 eot */ 0x00, /* 05 enq */ 0x00, /* 06 ack */ 0x00, /* 07 bel */ 0x00, /* 08 bs */ 0x00, /* 09 ht */ 0x00, /* 0a nl */ 0x00, /* 0b vt */ 0x00, /* 0c np */ 0x00, /* 0d cr */ 0x00, /* 0e so */ 0x00, /* 0f si */ 0x00, /* 10 dle */ 0x00, /* 11 dc1 */ 0x00, /* 12 dc2 */ 0x00, /* 13 dc3 */ 0x00, /* 14 dc4 */ 0x00, /* 15 nak */ 0x00, /* 16 syn */ 0x00, /* 17 etb */ 0x00, /* 18 can */ 0x00, /* 19 em */ 0x00, /* 1a sub */ 0x00, /* 1b esc */ 0x00, /* 1c fs */ 0x00, /* 1d gs */ 0x00, /* 1e rs */ 0x00, /* 1f us */ 0x00, /* 20 sp */ 0x00, /* 21 ! */ 0x00, /* 22 " */ 0x00, /* 23 # */ 0x00, /* 24 $ */ 0x00, /* 25 % */ 0x00, /* 26 & */ 0x00, /* 27 ' */ 0x00, /* 28 ( */ 0x00, /* 29 ) */ 0x00, /* 2a * */ 0x00, /* 2b + */ 0x00, /* 2c , */ 0x00, /* 2d - */ 0x00, /* 2e . */ 0x00, /* 2f / */ 0x00, /* 30 0 */ 0, /* 31 1 */ 1, /* 32 2 */ 2, /* 33 3 */ 3, /* 34 4 */ 4, /* 35 5 */ 5, /* 36 6 */ 6, /* 37 7 */ 7, /* 38 8 */ 8, /* 39 9 */ 9, /* 3a : */ 0x00, /* 3b ; */ 0x00, /* 3c < */ 0x00, /* 3d = */ 0x00, /* 3e > */ 0x00, /* 3f ? */ 0x00, /* 40 @ */ 0x00, /* 41 A */ 10, /* 42 B */ 11, /* 43 C */ 12, /* 44 D */ 13, /* 45 E */ 14, /* 46 F */ 15, /* 47 G */ 0x00, /* 48 H */ 0x00, /* 49 I */ 0x00, /* 4a J */ 0x00, /* 4b K */ 0x00, /* 4c L */ 0x00, /* 4d M */ 0x00, /* 4e N */ 0x00, /* 4f O */ 0x00, /* 50 P */ 0x00, /* 51 Q */ 0x00, /* 52 R */ 0x00, /* 53 S */ 0x00, /* 54 T */ 0x00, /* 55 U */ 0x00, /* 56 V */ 0x00, /* 57 W */ 0x00, /* 58 X */ 0x00, /* 59 Y */ 0x00, /* 5a Z */ 0x00, /* 5b [ */ 0x00, /* 5c \ */ 0x00, /* 5d ] */ 0x00, /* 5e ^ */ 0x00, /* 5f _ */ 0x00, /* 60 ` */ 0x00, /* 61 a */ 10, /* 62 b */ 11, /* 63 c */ 12, /* 64 d */ 13, /* 65 e */ 14, /* 66 f */ 15, /* 67 g */ 0x00, /* 68 h */ 0x00, /* 69 i */ 0x00, /* 6a j */ 0x00, /* 6b k */ 0x00, /* 6c l */ 0x00, /* 6d m */ 0x00, /* 6e n */ 0x00, /* 6f o */ 0x00, /* 70 p */ 0x00, /* 71 q */ 0x00, /* 72 r */ 0x00, /* 73 s */ 0x00, /* 74 t */ 0x00, /* 75 u */ 0x00, /* 76 v */ 0x00, /* 77 w */ 0x00, /* 78 x */ 0x00, /* 79 y */ 0x00, /* 7a z */ 0x00, /* 7b { */ 0x00, /* 7c | */ 0x00, /* 7d } */ 0x00, /* 7e ~ */ 0x00, /* 7f del */ 0x00, /* 80 */ 0x00, /* 81 */ 0x00, /* 82 */ 0x00, /* 83 */ 0x00, /* 84 */ 0x00, /* 85 */ 0x00, /* 86 */ 0x00, /* 87 */ 0x00, /* 88 */ 0x00, /* 89 */ 0x00, /* 8a */ 0x00, /* 8b */ 0x00, /* 8c */ 0x00, /* 8d */ 0x00, /* 8e */ 0x00, /* 8f */ 0x00, /* 90 */ 0x00, /* 91 */ 0x00, /* 92 */ 0x00, /* 93 */ 0x00, /* 94 */ 0x00, /* 95 */ 0x00, /* 96 */ 0x00, /* 97 */ 0x00, /* 98 */ 0x00, /* 99 */ 0x00, /* 9a */ 0x00, /* 9b */ 0x00, /* 9c */ 0x00, /* 9d */ 0x00, /* 9e */ 0x00, /* 9f */ 0x00, /* a0 */ 0x00, /* a1 */ 0x00, /* a2 */ 0x00, /* a3 */ 0x00, /* a4 */ 0x00, /* a5 */ 0x00, /* a6 */ 0x00, /* a7 */ 0x00, /* a8 */ 0x00, /* a9 */ 0x00, /* aa */ 0x00, /* ab */ 0x00, /* ac */ 0x00, /* ad */ 0x00, /* ae */ 0x00, /* af */ 0x00, /* b0 */ 0x00, /* b1 */ 0x00, /* b2 */ 0x00, /* b3 */ 0x00, /* b4 */ 0x00, /* b5 */ 0x00, /* b6 */ 0x00, /* b7 */ 0x00, /* b8 */ 0x00, /* b9 */ 0x00, /* ba */ 0x00, /* bb */ 0x00, /* bc */ 0x00, /* bd */ 0x00, /* be */ 0x00, /* bf */ 0x00, /* c0 */ 0x00, /* c1 */ 0x00, /* c2 */ 0x00, /* c3 */ 0x00, /* c4 */ 0x00, /* c5 */ 0x00, /* c6 */ 0x00, /* c7 */ 0x00, /* c8 */ 0x00, /* c9 */ 0x00, /* ca */ 0x00, /* cb */ 0x00, /* cc */ 0x00, /* cd */ 0x00, /* ce */ 0x00, /* cf */ 0x00, /* d0 */ 0x00, /* d1 */ 0x00, /* d2 */ 0x00, /* d3 */ 0x00, /* d4 */ 0x00, /* d5 */ 0x00, /* d6 */ 0x00, /* d7 */ 0x00, /* d8 */ 0x00, /* d9 */ 0x00, /* da */ 0x00, /* db */ 0x00, /* dc */ 0x00, /* dd */ 0x00, /* de */ 0x00, /* df */ 0x00, /* e0 */ 0x00, /* e1 */ 0x00, /* e2 */ 0x00, /* e3 */ 0x00, /* e4 */ 0x00, /* e5 */ 0x00, /* e6 */ 0x00, /* e7 */ 0x00, /* e8 */ 0x00, /* e9 */ 0x00, /* ea */ 0x00, /* eb */ 0x00, /* ec */ 0x00, /* ed */ 0x00, /* ee */ 0x00, /* ef */ 0x00, /* f0 */ 0x00, /* f1 */ 0x00, /* f2 */ 0x00, /* f3 */ 0x00, /* f4 */ 0x00, /* f5 */ 0x00, /* f6 */ 0x00, /* f7 */ 0x00, /* f8 */ 0x00, /* f9 */ 0x00, /* fa */ 0x00, /* fb */ 0x00, /* fc */ 0x00, /* fd */ 0x00, /* fe */ 0x00, /* ff */ 0x00 }; /* end of hex value map */ /* a few handy token checking macros */ /* based on the above #defines: */ #define IS_EOF(pParseObj) (pParseObj->tokenClass == E_EndOfFile) #define IS_OPERATOR(pParseObj) (pParseObj->tokenClass == E_Operator) #define IS_DATA_ID(pParseObj) (pParseObj->tokenClass == E_DataId) #define IS_ATTR_ID(pParseObj) (pParseObj->tokenClass == E_AttrId) #define IS_DATA_VALUE(pParseObj) (pParseObj->tokenClass == E_DataValue) #define IS_HEX_ARRAY(pParseObj) \ ((pParseObj->tokenClass == E_HexArray) || (pParseObj->tokenClass == E_Hex32Array)) #define IS_DATA_SOURCE_ID(pParseObj) (pParseObj->tokenClass == E_DataSourceId) #define IS_RAW_DATA_ID(pParseObj) (pParseObj->tokenClass == E_RawDataId) #define IS_EMBEDDED_DATA_PREFIX(pParseObj) \ ((pParseObj->tokenInstance == E_ActualEmbeddedDataPrefix) || (pParseObj->tokenInstance == E_ActualEmbeddedDataPrefixByte)) /* all of the legal states for the assembler: */ #define STATEID_StartingAssembly 0 #define STATEID_ScanningOperatorOrDataId 1 #define STATEID_ScanningDataValues 2 #define STATEID_ScanningHexArray 3 #define STATEID_ScanningAttributeId 4 #define STATEID_RecoveringFromSyntaxError 5 #define STATEID_ScanningAfterRecover 6 #define STATEID_EndingAssembly 7 #define STATEID_ParseNoPrint 8 /*for disassembler*/ #define STATEID_PrintingStats 9 /*for disassembler*/ /* macros to access the main assembler parse object: */ #define PARSEOBJ_GetLibrary(pParseObj) \ pParseObj->pStream #define PARSEOBJ_SetTokenClass(pParseObj, value) \ pParseObj->tokenClass = value #define PARSEOBJ_GetTokenClass(pParseObj) \ pParseObj->tokenClass #define PARSEOBJ_SetTokenInstance(pParseObj, value) \ pParseObj->tokenInstance = value #define PARSEOBJ_GetTokenInstance(pParseObj) \ pParseObj->tokenInstance #define PARSEOBJ_GetTokenPtr(pParseObj) \ pParseObj->pToken #define PARSEOBJ_SetTokenPtr(pParseObj, ptrValue) \ pParseObj->pToken = ptrValue #define PARSEOBJ_GetDataBuffSize(pParseObj) \ pParseObj->dataBuffSize #define PARSEOBJ_SetDataBuffSize(pParseObj, size) \ pParseObj->dataBuffSize = size #define PARSEOBJ_GetSubCount(pParseObj) \ pParseObj->subCount #define PARSEOBJ_SetSubCount(pParseObj, count) \ pParseObj->subCount = count #define PARSEOBJ_IncrementSubCount(pParseObj) \ pParseObj->subCount = pParseObj->subCount + 1 #define PARSEOBJ_GetDataBuffIndex(pParseObj) \ pParseObj->dataBuffIndex #define PARSEOBJ_SetDataBuffIndex(pParseObj, value) \ pParseObj->dataBuffIndex = value #define PARSEOBJ_GetDataBuffPtr(pParseObj) \ pParseObj->pDataBuff #define PARSEOBJ_SetDataBuffPtr(pParseObj, ptrValue) \ pParseObj->pDataBuff = ptrValue #define PARSEOBJ_GetStringPtr(pParseObj) \ pParseObj->pSrcString #define PARSEOBJ_SetStringPtr(pParseObj, ptrValue) \ pParseObj->pSrcString = ptrValue #define PARSEOBJ_GetTagStatPtr(pParseObj) \ pParseObj->pTagStats #define PARSEOBJ_SetTagStatPtr(pParseObj, ptrValue) \ pParseObj->pTagStats = ptrValue #define PARSEOBJ_IncrementTagStats(pParseObj, value) \ pParseObj->pTagStats[value] = pParseObj->pTagStats[value] + 1 #define PARSEOBJ_GetAttrStatPtr(pParseObj) \ pParseObj->pAttrStats #define PARSEOBJ_SetAttrStatPtr(pParseObj, ptrValue) \ pParseObj->pAttrStats = ptrValue #define PARSEOBJ_IncrementAttrStats(pParseObj, value) \ pParseObj->pAttrStats[value] = pParseObj->pAttrStats[value] + 1 #define PARSEOBJ_GetStringLen(pParseObj) \ pParseObj->srcStrLen #define PARSEOBJ_SetStringLen(pParseObj, value) \ pParseObj->srcStrLen = value #define PARSEOBJ_GetPosIndex(pParseObj) \ pParseObj->currentPosIndex #define PARSEOBJ_SetPosIndex(pParseObj, value) \ pParseObj->currentPosIndex = value #define PARSEOBJ_GetPointType(pParseObj) \ pParseObj->pointType #define PARSEOBJ_SetPointType(pParseObj, value) \ pParseObj->pointType = value #define PARSEOBJ_GetDataOrg(pParseObj) \ pParseObj->dataOrg #define PARSEOBJ_SetDataOrg(pParseObj, value) \ pParseObj->dataOrg = value #define PARSEOBJ_GetDataOrgBuff(pParseObj) \ pParseObj->dataOrgBuff #define PARSEOBJ_SetDataOrgBuff(pParseObj, value) \ pParseObj->dataOrgBuff = value #define PARSEOBJ_SetExpectedDataType(pParseObj, value) \ pParseObj->expectedDataType = value #define PARSEOBJ_GetExpectedDataType(pParseObj) \ pParseObj->expectedDataType #define PARSEOBJ_SetExpectedDataLenType(pParseObj, value) \ pParseObj->expectedDataLenType = value #define PARSEOBJ_GetExpectedDataLenType(pParseObj) \ pParseObj->expectedDataLenType #define PARSEOBJ_SetExpectedDataFixedLen(pParseObj, value) \ pParseObj->expectedDataFixedLen = value #define PARSEOBJ_GetExpectedDataFixedLen(pParseObj) \ pParseObj->expectedDataFixedLen #define PARSEOBJ_GetNextState(pParseObj) (pParseObj->nextState) #define PARSEOBJ_GetCurrentState(pParseObj) (pParseObj->currentState) #define PARSEOBJ_SetNextState(pParseObj, nextstate) \ pParseObj->nextState = (HP_UByte) nextstate #define PARSEOBJ_SetCurrentState(pParseObj, currentstate) \ pParseObj->currentState = (HP_UByte) currentstate #define PARSEOBJ_Stop(pParseObj) \ (pParseObj->nextState == STATEID_EndingAssembly) #define PARSEOBJ_GetPathListPtr(pParseObj) \ pParseObj->pPathList #define PARSEOBJ_SetPathListPtr(pParseObj, ptrValue) \ pParseObj->pPathList = ptrValue #define PARSEOBJ_GetOperatorCount(pParseObj) \ pParseObj->operatorCount #define PARSEOBJ_SetOperatorCount(pParseObj, value) \ pParseObj->operatorCount = value #define PARSEOBJ_GetFileStack(pParseObj) \ pParseObj->pFileStack #define PARSEOBJ_GetMacroTable(pParseObj) \ pParseObj->pMacroTable #define PARSEOBJ_GetSymbolTable(pParseObj) \ pParseObj->pSymbolTable #define PARSEOBJ_symbolTableEntries(pParseObj) \ pParseObj->symbolTableEntries #define PARSEOBJ_GetMostSigFirstFlag(pParseObj) (pParseObj->mostSigByteFirst) #define PARSEOBJ_SetMostSigFirstFlag(pParseObj, value) pParseObj->mostSigByteFirst = value #define ASSEMBLY_Continue(pParseObj) \ ((HP_NoErrors(pParseObj->pStream)) && (!PARSEOBJ_Stop(pParseObj))) HP_pChar STRING_NewString(HP_UInt16 maxStringLength) { HP_pChar stringPtr = 0; stringPtr = (HP_pChar) HP_MEMALLOC((size_t) (maxStringLength + 1)); /* one byte at end for null character */ return(stringPtr); } StdFuncReturnType STRING_DeleteString(HP_pChar stringPtr) { if (stringPtr) { HP_MEMDEALLOC(stringPtr); } } /* macro table #defines: */ #define MACRO_GetRecordsPtr(pMacroTable) \ pMacroTable->macroRecords #define MACRO_GetMacroNamePtr(pMacroRec) \ pMacroRec->pMacro #define MACRO_SetMacroNamePtr(pMacroRec, ptrValue) \ pMacroRec->pMacro = ptrValue #define MACRO_GetMacroBodyPtr(pMacroRec) \ pMacroRec->pBody #define MACRO_SetMacroBodyPtr(pMacroRec, ptrValue) \ pMacroRec->pBody = ptrValue #define MACRO_GetCurrentCount(pMacroTable) \ pMacroTable->numMacroEntries #define MACRO_SetMacroCount(pMacroTable, value) \ pMacroTable->numMacroEntries = value #define MACRO_GetMaxEntries(pMacroTable) \ pMacroTable->maxMacroEntries #define MAX_MACRO_ENTRIES 300 /* maximum macro entries for global $defines */ #define MAX_LOCAL_MACRO_ENTRIES 100 /* maximum entries for local $defines */ typedef HP_pUInt32 TagStatPtrType; /* tag statistics array pointer type */ typedef HP_pUInt32 AttrStatPtrType; /* attribute statistics array pointer type */ typedef struct ParseObj /* basic object to be used in all parsing */ { /* routines */ SrcStringPtrType pSrcString;/* pointer to source string being parsed */ int srcStrLen; /* current length of source string */ int currentPosIndex; /* current parsing index to source string */ TokenPtrType pToken; /* pointer to last token found '\0' at end */ HP_UInt16 tokenClass; /* class of token (i.e. operator, attribute id, * data value, etc.) */ HP_UInt32 tokenInstance; /* specific instance (i.e. HP_SetCursor, Point, * real32Box, etc.) or data value for * enumerations */ int expectedDataType; /* ubyte, uint16, uint32, or real32 */ int expectedDataLenType; /* fixed or array type */ int expectedDataFixedLen; /* single = 1, xy = 2, box = 4 */ DataBufferPtrType pDataBuff;/* data buffer for token data */ BufferIndexType dataBuffIndex; /* index to current data buffer element */ HP_UInt32 dataBuffSize; /* current maximum size of the data buffer */ HP_UByte currentState; /* the current state of the assembler for * this parse object */ HP_UByte nextState; /* the next state to be executed */ PathListPtrType pPathList; /* pointer to the $include path list */ FileStackPtrType pFileStack; /* pointer to the file stack */ MacroTablePtrType pMacroTable; /* pointer to the macro table */ SymbolTablePtrType pSymbolTable; /* pointer to the symbol table */ HP_StreamHandleType pStream; /* the following entries are for the disasembler function only */ HP_UByte mostSigByteFirst; /* for disassembler only, nonzero if most * significant byte first for binary data * (reflects stream binding identifier) */ HP_UInt32 operatorCount; TagStatPtrType pTagStats; /* array to hold tag statistics */ AttrStatPtrType pAttrStats; /* array to hold attribute statistics */ HP_UByte pointType; /* holds current data type of points to * be read from embedded data stream */ HP_UByte dataOrgBuff; /* holds value to be potentially used as * data organization value (Assembler and * disassembler */ HP_UByte dataOrg; /* holds the binary data organization * specified by OpenDataSource (Assembler * and Disassembler) */ HP_UInt16 subCount; /* holds the count of subroutines defined */ } ParseObjType; typedef ParseObjType *ParseObjPtrType; /* forward declaration for assembler function DisAsmRawOutput: */ StdFuncReturnType PARSEOBJ_DisAsmRawOutput(ParseObjPtrType pParseObj, HP_pUByte outString, HP_UInt16 stringLength) ; /* forward declaration for assembler function HP_GetStreamErrorText: */ HP_pUByte HP_GetStreamErrorText(HP_SInt16 errorNumber) ; /* forward declaration for disassembler function PrintBadByte: */ StdFuncReturnType PARSEOBJ_PrintBadByte(ParseObjPtrType pParseObj, HP_UByte badByte) ; /* forward declaration for disassembler function DisAsmLineOutput: */ StdFuncReturnType PARSEOBJ_DisAsmLineOutput(ParseObjPtrType pParseObj, HP_pUByte outString, HP_UInt16 stringLength) ; UInt16FuncReturnType PARSEOBJ_GetUInt16(ParseObjPtrType pParseObj, HP_UByte mostSigByteFirst) { #define BYTES_NEEDED 2 int index = 0; unsigned char bytes[BYTES_NEEDED]; HP_UInt16 thisUInt16 = 0; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_SInt16 intByteBuff; for (index = 0; (index < BYTES_NEEDED) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF); index++) { bytes[index] = (HP_UByte) intByteBuff; } if (intByteBuff != EOF) { if(mostSigByteFirst) { thisUInt16 = bytes[1]; thisUInt16 = thisUInt16 | ((HP_UInt16) bytes[0] << 8); } else { thisUInt16 = bytes[0]; thisUInt16 = thisUInt16 | ((HP_UInt16) bytes[1] << 8); } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } return(thisUInt16); #undef BYTES_NEEDED } UInt32FuncReturnType PARSEOBJ_GetUInt32(ParseObjPtrType pParseObj, HP_UByte mostSigByteFirst) { #define BYTES_NEEDED 4 int isEof = 0; int index = 0; unsigned char bytes[BYTES_NEEDED]; HP_UInt32 thisUInt32 = 0; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_SInt16 intByteBuff; for (index = 0; (index < BYTES_NEEDED) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF); index++) { bytes[index] = (HP_UByte) intByteBuff; } if (intByteBuff != EOF) { if(mostSigByteFirst) { thisUInt32 = bytes[3]; thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[2] << 8); thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[1] << 16); thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[0] << 24); } else { thisUInt32 = bytes[0]; thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[1] << 8); thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[2] << 16); thisUInt32 = thisUInt32 | ((HP_UInt32) bytes[3] << 24); } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } return(thisUInt32); #undef BYTES_NEEDED } Real32FuncReturnType PARSEOBJ_GetReal32(ParseObjPtrType pParseObj, HP_UByte mostSigByteFirst) { #define BYTES_NEEDED 4 int index = 0; unsigned char bytes[BYTES_NEEDED]; DataUnionType realUnion; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_SInt16 intByteBuff; realUnion.anInt32 = 0; for (index = 0; (index < BYTES_NEEDED) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF); index++) { bytes[index] = (HP_UByte) intByteBuff; } if (intByteBuff != EOF) { if(mostSigByteFirst) { realUnion.anInt32 = bytes[3]; realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[2] << 8); realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[1] << 16); realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[0] << 24); } else { realUnion.anInt32 = bytes[0]; realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[1] << 8); realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[2] << 16); realUnion.anInt32 = realUnion.anInt32 | ((HP_UInt32) bytes[3] << 24); } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } return(realUnion.aReal32); #undef BYTES_NEEDED } UInt32FuncReturnType PARSEOBJ_GetArrayLength(ParseObjPtrType pParseObj) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_UByte dataLengthType; HP_UInt32 arrayLength = 0; HP_SInt16 intByteBuff; intByteBuff = FSTACK_NextByte(pFileStack); if (intByteBuff != EOF) { dataLengthType = (HP_UByte) intByteBuff; switch (dataLengthType) { case HP_UByteData: intByteBuff = FSTACK_NextByte(pFileStack); if (intByteBuff != EOF) { arrayLength = (HP_UInt32) intByteBuff; } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } break; case HP_UInt16Data: arrayLength = (HP_UInt32) PARSEOBJ_GetUInt16(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); break; case HP_UInt32Data: arrayLength = PARSEOBJ_GetUInt32(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); break; default: /* error */ HP_SetErrorCode(pStream, HPERR_UndefinedArrayLengthType); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } return(arrayLength); } UByteFuncReturnType PARSEOBJ_GetAttributeId(ParseObjPtrType pParseObj) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_UByte attributeIdTag; HP_UByte attributeId = 0; HP_SInt16 intByteBuff = 0; DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); intByteBuff = FSTACK_NextByte(pFileStack); if (intByteBuff != EOF) { attributeIdTag = (HP_UByte) intByteBuff; switch (attributeIdTag) { case HP_8BitAttrId: PARSEOBJ_IncrementTagStats(pParseObj, attributeIdTag); intByteBuff = FSTACK_NextByte(pFileStack); if (intByteBuff != EOF) { attributeId = (HP_UByte) intByteBuff; PARSEOBJ_IncrementAttrStats(pParseObj, attributeId); if ((attributeId == HP_PointType) || (attributeId == HP_XPairType)) { PARSEOBJ_SetPointType(pParseObj, (HP_UByte) ((HP_pUByte) pDataBuff)[0]); } else if (attributeId == HP_DataOrg) { PARSEOBJ_SetDataOrg(pParseObj, (HP_UByte) PARSEOBJ_GetDataOrgBuff(pParseObj)); } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } break; /* only 8-bit attribute ids are supported at this time */ default: /* error */ HP_LogError(HP_GetStreamErrorText(HPERR_ExpectedAttrId)); HP_LogError("\n"); PARSEOBJ_PrintBadByte(pParseObj, attributeIdTag); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } return(attributeId); } StdFuncReturnType PARSEOBJ_DisAsmRawOutput(ParseObjPtrType pParseObj, HP_pUByte outString, HP_UInt16 stringLength) { #define RIGHT_MARGIN 4 HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_UByte currentState = PARSEOBJ_GetCurrentState(pParseObj); HP_pUByte pBuffPtr = HP_GetStreamBuffPtr(pStream); if ((stringLength) && (currentState != STATEID_ParseNoPrint)) { if ((HP_GetStreamBuffLen(pStream) + stringLength + RIGHT_MARGIN) >= MAX_DISASM_STRING) { HP_UByte aCRLF[3]; if (pBuffPtr[HP_GetStreamBuffLen(pStream)-1] != '\n') { sprintf(aCRLF, "\n"); HP_RawUByteArray(pStream, aCRLF, strlen(aCRLF)); } HP_FlushStreamBuffer(pStream); } HP_RawUByteArray(pStream, outString, stringLength); } #undef RIGHT_MARGIN } StdFuncReturnType PARSEOBJ_DisAsmLineOutput(ParseObjPtrType pParseObj, HP_pUByte outString, HP_UInt16 stringLength) { HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_UByte currentState = PARSEOBJ_GetCurrentState(pParseObj); HP_pUByte pBuffPtr = HP_GetStreamBuffPtr(pStream); if ((stringLength) && (currentState != STATEID_ParseNoPrint)) { HP_RawUByteArray(pStream, outString, stringLength); HP_FlushStreamBuffer(pStream); } } StdFuncReturnType PARSEOBJ_PrintBadByte(ParseObjPtrType pParseObj, HP_UByte badByte) { #define MAX_BAD_BYTE_BUFF 128 HP_UByte badByteBuff[MAX_BAD_BYTE_BUFF]; sprintf(badByteBuff, "// Error Found While Processing Byte Value of:\'%02x\' (hex).\n", (unsigned int) badByte); PARSEOBJ_DisAsmLineOutput(pParseObj, badByteBuff, strlen(badByteBuff)); HP_LogError(badByteBuff); } StdFuncReturnType PARSEOBJ_DisAsmPrintAscii(ParseObjPtrType pParseObj, HP_pUByte byteString, HP_UByte stringLength) { #define ASCII_BUFF_LENGTH 10 int index; char asciiBuff[ASCII_BUFF_LENGTH]; for (index = 0; index < stringLength; index++) { if (!isprint(byteString[index])) { byteString[index] = '.'; } } sprintf(asciiBuff, "// "); PARSEOBJ_DisAsmRawOutput(pParseObj, asciiBuff, strlen(asciiBuff)); PARSEOBJ_DisAsmRawOutput(pParseObj, byteString, stringLength); /* add space at end to insure we don't have problem with a backslash that would be interpreted as a continuation character */ PARSEOBJ_DisAsmRawOutput(pParseObj, " ", 1); #undef ASCII_BUFF_LENGTH } #ifndef _USERENTRY #define _USERENTRY #endif static int _USERENTRY sortComp_MacroRec(const void *entry1, const void *entry2) { return(strcmp((const char *)((MacroRecType *)entry1)->pMacro, (const char *)((MacroRecType *)entry2)->pMacro)); } static int _USERENTRY sortComp_SymbolRec(const void *entry1, const void *entry2) { if ((((SymbolRecType *)entry1)->symbol) && (((SymbolRecType *)entry2)->symbol)) { return(strcmp((const char *)(((SymbolRecType *)entry1)->symbol), (const char *)(((SymbolRecType *)entry2)->symbol))); } else return -1; } static int _USERENTRY sortDisAsmComp_SymbolRec(const void *entry1, const void *entry2) { int returnVal = 0; if (((SymbolRecType *)entry1)->tokenInstance > ((SymbolRecType *)entry2)->tokenInstance) { returnVal = 1; } else if (((SymbolRecType *)entry1)->tokenInstance < ((SymbolRecType *)entry2)->tokenInstance) { returnVal = -1; } else { if (((SymbolRecType *)entry1)->tokenExtension == ((SymbolRecType *)entry2)->tokenExtension) { if (((SymbolRecType *)entry1)->tokenClass == ((SymbolRecType *)entry2)->tokenClass) { returnVal = 0; } else if (((SymbolRecType *)entry1)->tokenClass > ((SymbolRecType *)entry2)->tokenClass) { returnVal = 1; } else { returnVal = -1; } } else if (((SymbolRecType *)entry1)->tokenExtension > ((SymbolRecType *)entry2)->tokenExtension) { returnVal = 1; } else { returnVal = -1; } } return(returnVal); } /***************************************************************************** function: HP_GetStreamErrorText purpose: Return a pointer to a constant byte string containing text which explains the error found. If no text is found for the error number passed in, a null pointer is returned. parameters: name data type / description ----------------- ------------------------------------- errorNumber HP_SInt16 / An error code number #defined in the jetasm.c file. comments: *****************************************************************************/ HP_pUByte HP_GetStreamErrorText(HP_SInt16 errorNumber) { HP_pUByte pText; switch (errorNumber) { case HP_NoError: pText = "No Errors Detected"; break; case HPERR_CannotOpenInput: pText = "File Error: Cannot Open the Input File"; break; case HPERR_CannotOpenOutput: pText = "File Error: Cannot Open the Output File"; break; case HPERR_AsmOutOfMemory: pText = "Internal Error: Out of Memory"; break; case HPERR_SourceStringOverflow: pText = "Internal Error: Overran the Input String While Scanning for Tokens"; break; case HPERR_UnknownActualDataType: pText = "Internal Error: Data Type Name Found is Unknown to Assembler"; break; case HPERR_FileReadError: pText = "Internal Error: File Error During Read of Input or Temp File"; break; case HPERR_FileWriteError: pText = "Internal Error: File Error During Write to Output or Temp File"; break; case HPERR_ExpectedOpOrDataId: pText = "Syntax Error: Expected Operator or Data Identifier and Scanned Something Else"; break; case HPERR_ExpectedAttrId: pText = "Syntax Error: Expected Attribute Identifier and Scanned Something Else"; break; case HPERR_InvalidDataId: pText = "Internal Error: Data Identifer From Symbol Table is Invalid"; break; case HPERR_UnknownDataFormat: pText = "Syntax Error: All Required Data Values Not Found For Data Identifier"; break; case HPERR_NotAnEnumeration: pText = "Syntax Error: Enumeration Name Used for Data Value is Undefined"; break; case HPERR_MissingOpenBracket: pText = "Syntax Error: Open Bracket Missing for Data Value Array"; break; case HPERR_MissingCloseBracket: pText = "Syntax Error: Close Bracket Missing for Data Value Array"; break; case HPERR_UnknownInternalDataFormat: pText = "Internal Error: Data Format for Symbol is Unknown"; break; case HPERR_IllegalAssemblerState: pText = "Internal Error: Assembler Was In An Illegal State"; break; case HPERR_DataCountExceeded: pText = "Syntax Error: Too Many Data Values for Current Data Identifier"; break; case HPERR_MacroValueConversionError: pText = "Syntax Error: Undefined Macro Name or Bad Number Format for $calc Operation"; break; case HPERR_MacroNameMustStartWithAlpha: pText = "Syntax Error: Macro Name Did Not Start With Alpha Character or Percent (%)"; break; case HPERR_UnknownMacroOperator: pText = "Syntax Error: An Unknown $macro Operator Format Was Detected"; break; case HPERR_EndIfNotFound: pText = "Syntax Error: $if Defined Without Matching $endif"; break; case HPERR_EndLoopNotFound: pText = "Syntax Error: $loop Defined Without Matching $endloop"; break; case HPERR_UnknownMacroName: pText = "Syntax Error: Macro Name Provided As Operator Parameter Does Not Exist"; break; case HPERR_FileNameLengthExceeded: pText = "Parameter Error: An Input or $include File Name Exceeded the Maximum Length Allowed"; break; case HPERR_PathLengthExceeded: pText = "Parameter Error: An $include File Path Name Exceeded the Maximum Length Allowed"; break; case HPERR_EndLoopNoMatch: pText = "Syntax Error: An $endloop Was Found With No Matching $loop"; break; case HPERR_EndIfNoMatch: pText = "Syntax Error: An $endif Was Found With No Matching $if Or $ifnot"; break; case HPERR_EscapeStringTooLong: pText = "Run-time Error: $escape Macro Return String Too Long"; break; case HPERR_InputStringTooLong: pText = "Run-time Error: $input Macro Return String Too Long"; break; case HPERR_EscapeMacroFailed: pText = "Run-time Error: $escape Macro Failed"; break; case HPERR_UndefinedTag: pText = "Stream Operator/Data Error: Undefined Tag Found in Stream"; break; case HPERR_SymbolMissing: pText = "Internal Error: Assembler is Missing a Needed Symbol for Disassembly"; break; case HPERR_BeyondEOF: pText = "File Error: Data Needed is Beyond the End of the Current Input File"; break; case HPERR_UndefinedArrayLengthType: pText = "Syntax Error: A PCL XL Stream Contained an Undefined Array Length Type"; break; case HPERR_UndefinedMacroTable: pText = "Internal Error: Attempt to Access Macro Value Using Undefined Macro Table"; break; case HPERR_EndSubNotFound: pText = "Syntax Error: Matching $endsub not found for $beginsub"; break; case HPERR_NestedSubroutine: pText = "Syntax Error: Nested subroutines are not allowed"; break; case HPERR_SubroutineAlreadyExists: pText = "Syntax Error: Duplicate subroutine names not allowed"; break; case HPERR_UnknownStringOperator: pText = "Syntax Error: An Unknown $string Operator Format Was Detected"; break; case HPERR_UserAbort: pText = "A User Abort Was Detected."; break; case HPERR_ExceededMaxNesting: pText = "Internal Error: Too many nested user and/or processing files (max=14)"; break; case HPERR_DataBufferOverflow: pText = "Internal Error: More data elements received than expected."; break; default: pText = "Internal Error: Error Number Undefined"; break; } return(pText); } StdFuncReturnType MACRO_DeleteMacroTable(MacroTablePtrType pMacroTable) { if (pMacroTable) { MacroRecPtrType pMacroRec = NULL; if (pMacroTable->macroRecords) { unsigned int index; pMacroRec = pMacroTable->macroRecords; for (index = 0; index != pMacroTable->numMacroEntries; index++) { HP_MEMDEALLOC(pMacroRec->pMacro); HP_MEMDEALLOC(pMacroRec->pBody); pMacroRec++; } HP_MEMDEALLOC(pMacroTable->macroRecords); } HP_MEMDEALLOC(pMacroTable); } } StdFuncReturnType FSTACK_PopFileStack(FileStackPtrType pFileStack) { HP_UInt16 justPoppedLoopOrIf = 0; HP_UInt32 lineNumber = FSTACK_GetCurrentLineNumber(pFileStack); MacroTablePtrType pPoppedMacroTable = NULL; if (FSTACK_GetNumOpenFiles(pFileStack)) { if (FSTACK_TopOfFileStack(pFileStack)) { /* attempt to close file */ fclose(FSTACK_TopOfFileStack(pFileStack)); } if (FSTACK_GetMacroNamePtr(pFileStack)) { { HP_pChar loopOrIfMacroName = (HP_pChar)FSTACK_GetMacroNamePtr(pFileStack); if (loopOrIfMacroName) { HP_MEMDEALLOC(FSTACK_GetMacroNamePtr(pFileStack)); justPoppedLoopOrIf = 1; } } } pPoppedMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_SetMacroNamePtr(pFileStack, 0); /* pop the file info off the stack: */ FSTACK_SetNumOpenFiles(pFileStack, FSTACK_GetNumOpenFiles(pFileStack) - 1); if (pPoppedMacroTable != FSTACK_GetLocalMacroTable(pFileStack)) { MACRO_DeleteMacroTable(pPoppedMacroTable); } } } StdFuncReturnType FSTACK_DeleteFileStack(FileStackPtrType pFileStack) { if (pFileStack) { while (FSTACK_GetNumOpenFiles(pFileStack)) { if (FSTACK_TopOfFileStack(pFileStack)) { /* attempt to close file */ fclose(FSTACK_TopOfFileStack(pFileStack)); } if (FSTACK_GetMacroNamePtr(pFileStack)) { HP_MEMDEALLOC(FSTACK_GetMacroNamePtr(pFileStack)); } FSTACK_SetNumOpenFiles(pFileStack, FSTACK_GetNumOpenFiles(pFileStack) - 1); } HP_MEMDEALLOC(pFileStack); } } StdFuncReturnType FSTACK_StopLooping(FileStackPtrType pFileStack) { if (FSTACK_GetMacroNamePtr(pFileStack)) { fclose(FSTACK_TopOfFileStack(pFileStack)); FSTACK_PopFileStack(pFileStack); } } HP_pChar ReadUntilLineFeed(FILE *inputFile, HP_pChar targetString, int maxChars) { #define IS_NEW_LINE(aChar) ((aChar == '\n') || (aChar == '\r')) HP_pChar returnString = 0; char ch; int count = 0; int done = 0; if (!feof(inputFile)) { targetString[0] = '\0'; ch = getc(inputFile); while ((!done) && (ch != EOF)) { if (count < maxChars) { if (isprint(ch)) { targetString[count] = ch; targetString[++count] = '\0'; } if (IS_NEW_LINE(ch)) { if (count && (targetString[count-1] == '\\')) { /* we have a line continuation character */ /* back up one character */ count--; } else { /* we have a new line with no continuation */ /* we're done with the current line */ ch = '\n'; done = 1; } } if (!done) { /* get the next character */ ch = getc(inputFile); } } else { /* character overflow, truncate line */ done = 1; } } returnString = targetString; } return(returnString); #undef A_NEW_LINE } /* the following functions are used to manage file input/output */ HP_pChar catString(ParseObjPtrType pParseObj, HP_pChar prefix, HP_pChar suffix) { /* returns the prefix concatenated with the suffix */ /* original strings untouched */ HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); char catName[MAX_FILE_NAME]; catName[0] = '\0'; if ((strlen(prefix) + strlen(suffix)) >= MAX_FILE_NAME) { HP_SetErrorCode(pStream, HPERR_FileNameLengthExceeded); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else { strcpy(catName, prefix); strcat(catName, suffix); } return(catName); } StdFuncReturnType closeFile(FILE *file) { /* call fclose if file handle is not NULL */ if (file != NULL) { fclose(file); } } FileFuncReturnType openForWrite(ParseObjPtrType pParseObj, HP_pChar aFileName, HP_pChar access) { /* attempts to open a file for write access */ /* if successful, returns non-NULL file handle */ FILE *file; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if ((file = fopen(aFileName, access)) == NULL) { HP_SetErrorCode(pStream, HPERR_CannotOpenOutput); if (pParseObj) { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } return(file); } FileFuncReturnType openForRead(ParseObjPtrType pParseObj, HP_pChar fileName, HP_pChar openMode) { /* attempts to open a file for read access */ /* if successful, returns non-NULL file handle */ FILE *file = NULL; HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); int index; char myFileName[MAX_FILE_NAME]; HP_pChar aFileName = &myFileName[0]; char fileAndPath[MAX_FILE_PATH]; PathListPtrType pPathList = PARSEOBJ_GetPathListPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); if (FSTACK_GetNumOpenFiles(pFileStack) >= MAX_NESTED_FILES) { HP_SetErrorCode(pStream, HPERR_ExceededMaxNesting); if (pParseObj) { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } if (strlen(fileName) < (MAX_FILE_NAME - 3)) { strcpy(aFileName, fileName); } else { HP_SetErrorCode(pStream, HPERR_FileNameLengthExceeded); if (pParseObj) { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } if (ASSEMBLY_Continue(pParseObj)) { if (aFileName[0] == '<') { fileAndPath[0] = '\0'; aFileName = &(aFileName[1]); /* skip over '<' */ /* delete ending '>': */ aFileName[strlen(aFileName)-1] = '\0'; /* search for this include file in the paths defined */ for (index = 0, file = NULL; (index < pPathList->numFilePaths) && (file == NULL); index ++) { fileAndPath[0] = '\0'; strcpy(fileAndPath, pPathList->pathArray[index]); #ifdef UNIX_FILE_SYSTEM strcat(fileAndPath, "/"); #else strcat(fileAndPath, "\\"); #endif strcat(fileAndPath, aFileName); file = fopen(fileAndPath, openMode); } } else { fileAndPath[0] = '\0'; if (aFileName[0] == '\"') { aFileName = &(aFileName[1]); /* skip over '\"' */ /* delete ending '\"': */ aFileName[strlen(aFileName)-1] = '\0'; } file = fopen(aFileName, openMode); } } if (ASSEMBLY_Continue(pParseObj) && (file == NULL)) { HP_SetErrorCode(pStream, HPERR_CannotOpenInput); if (pParseObj) { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } return(file); } StdFuncReturnType FSTACK_PushFileStack(ParseObjPtrType pParseObj, HP_pChar fileName, HP_pChar aliasName, HP_pVoid loopOrIfMacroName, HP_UByte loopEndOnTrue, MacroTablePtrType pLocalMacroTable, HP_UInt32 lineNumber, HP_pChar fileMode) { FILE *file; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (strcmp(fileName, "stdin")) { /* file not "stdin", open in */ file = openForRead(pParseObj, fileName, fileMode); } else { file = stdin; } if (ASSEMBLY_Continue(pParseObj)) { if (FSTACK_GetNumOpenFiles(pFileStack) < MAX_NESTED_FILES) { HP_pChar charLoopOrIfMacroName = (HP_pChar) loopOrIfMacroName; FSTACK_SetNumOpenFiles(pFileStack, FSTACK_GetNumOpenFiles(pFileStack) + 1); if (charLoopOrIfMacroName) { FSTACK_SetMacroNamePtr(pFileStack, HP_MEMALLOC((size_t) strlen(charLoopOrIfMacroName) + 1)); if (FSTACK_GetMacroNamePtr(pFileStack)) { strcpy((HP_pChar)FSTACK_GetMacroNamePtr(pFileStack), charLoopOrIfMacroName); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { FSTACK_SetMacroNamePtr(pFileStack, NULL); FSTACK_SetByteCount(pFileStack, 0); } { pFileStack->fileArray[FSTACK_GetNumOpenFiles(pFileStack)] = file; pFileStack->lineCountArray[FSTACK_GetNumOpenFiles(pFileStack)] = lineNumber; strcpy(FSTACK_GetFileNamePtr(pFileStack), fileName); strcpy(FSTACK_GetAliasNamePtr(pFileStack), aliasName); FSTACK_SetLoopEndFlag(pFileStack, loopEndOnTrue); FSTACK_SetLocalMacroTable(pFileStack, pLocalMacroTable); } } else { HP_SetErrorCode(pStream, HPERR_ExceededMaxNesting); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } SymbolTablePtrType SYMBOL_NewSymbolTable(HP_UInt16 maxSymbolEntries) { SymbolTablePtrType pSymbolTable = 0; /* load the default symbol table */ if (pSymbolTable = (SymbolTableType *)HP_MEMALLOC((size_t) (sizeof(SymbolTableType)))) { pSymbolTable->symbolRecPtr = (SymbolRecType *) HP_MEMALLOC((size_t) (maxSymbolEntries * sizeof(SymbolRecType))); if (pSymbolTable->symbolRecPtr) { HP_UInt16 index = 0; SymbolRecPtrType tempSymbolRecPtr = pSymbolTable->symbolRecPtr; for (index =0; index < maxSymbolEntries; index++) { tempSymbolRecPtr->symbol = defaultSymbolTable[index].symbol; tempSymbolRecPtr->tokenClass = defaultSymbolTable[index].tokenClass; tempSymbolRecPtr->tokenInstance = defaultSymbolTable[index].tokenInstance; tempSymbolRecPtr++; } pSymbolTable->numSymbolEntries = DEFAULT_SYMBOL_COUNT; /* sort the symbol table */ qsort(pSymbolTable->symbolRecPtr, pSymbolTable->numSymbolEntries, sizeof(SymbolRecType), sortComp_SymbolRec); /*#ifdef DEBUG_JETASM*/ #if 0 tempSymbolRecPtr = pSymbolTable->symbolRecPtr; for (index =0; index < pSymbolTable->numSymbolEntries; index++) { printf("%s; class=%d; instance=%d\n", tempSymbolRecPtr->symbol, tempSymbolRecPtr->tokenClass, tempSymbolRecPtr->tokenInstance); tempSymbolRecPtr++; } #endif } else { HP_MEMDEALLOC(pSymbolTable); pSymbolTable = 0; } } return(pSymbolTable); } SymbolTablePtrType SYMBOL_NewDisAsmSymbolTable(HP_UInt16 maxSymbolEntries) { SymbolTablePtrType pSymbolTable = 0; /* load the default symbol table */ if (pSymbolTable = (SymbolTableType *)HP_MEMALLOC((size_t) (sizeof(SymbolTableType)))) { pSymbolTable->symbolRecPtr = (SymbolRecType *) HP_MEMALLOC((size_t) (maxSymbolEntries * sizeof(SymbolRecType))); if (pSymbolTable->symbolRecPtr) { HP_UInt16 index = 0; SymbolRecPtrType tempSymbolRecPtr = pSymbolTable->symbolRecPtr; for (index =0; index < maxSymbolEntries; index++) { tempSymbolRecPtr->symbol = defaultSymbolTable[index].symbol; tempSymbolRecPtr->tokenClass = defaultSymbolTable[index].tokenClass; tempSymbolRecPtr->tokenInstance = defaultSymbolTable[index].tokenInstance; tempSymbolRecPtr->tokenExtension = defaultSymbolTable[index].tokenExtension; tempSymbolRecPtr++; } pSymbolTable->numSymbolEntries = DEFAULT_SYMBOL_COUNT; /* sort the symbol table for the Disassembly function */ qsort(pSymbolTable->symbolRecPtr, pSymbolTable->numSymbolEntries, sizeof(SymbolRecType), sortDisAsmComp_SymbolRec); /*#ifdef DEBUG_JETASM*/ #if 0 tempSymbolRecPtr = pSymbolTable->symbolRecPtr; for (index =0; index < pSymbolTable->numSymbolEntries; index++) { printf("%s; class=%d; instance=%d\n", tempSymbolRecPtr->symbol, tempSymbolRecPtr->tokenClass, tempSymbolRecPtr->tokenInstance); tempSymbolRecPtr++; } #endif } else { HP_MEMDEALLOC(pSymbolTable); pSymbolTable = 0; } } return(pSymbolTable); } StdFuncReturnType SYMBOL_DeleteSymbolTable(SymbolTablePtrType pSymbolTable) { if (pSymbolTable) { HP_MEMDEALLOC(pSymbolTable->symbolRecPtr); HP_MEMDEALLOC(pSymbolTable); } } SymbolRecPtrType FindSymbol( SymbolTablePtrType pSymbolTable, TokenPtrType aToken ) { /* find a token in the symbol table */ SymbolRecPtrType result = NULL; SymbolRecType key; key.symbol = aToken; if (pSymbolTable->numSymbolEntries) { result = (SymbolRecPtrType) bsearch ( (SymbolRecPtrType) &key, (SymbolRecPtrType) pSymbolTable->symbolRecPtr, pSymbolTable->numSymbolEntries, sizeof(SymbolRecType), sortComp_SymbolRec ); } #ifdef DEBUG_JETASM if (result) { printf("Found %s.\n", SYMBOL_GetSymbolStringPtr(result)); } #endif return(result); } SymbolRecPtrType FindDisAsmSymbol( SymbolTablePtrType pSymbolTable, HP_UInt16 tokenClass, HP_UInt32 tokenInstance, HP_SInt16 tokenExtension ) { /* find a token in the symbol table */ SymbolRecPtrType result = NULL; SymbolRecType key; key.tokenInstance = tokenInstance; key.tokenClass = tokenClass; key.tokenExtension = tokenExtension; key.symbol = (TokenPtrType) "FindDisAsm"; if (pSymbolTable->numSymbolEntries) { result = (SymbolRecPtrType) bsearch ( (SymbolRecPtrType) &key, (SymbolRecPtrType) pSymbolTable->symbolRecPtr, pSymbolTable->numSymbolEntries, sizeof(SymbolRecType), sortDisAsmComp_SymbolRec ); } #ifdef DEBUG_JETASM if (result) { printf("Found %s.\n", SYMBOL_GetSymbolStringPtr(result)); } #endif return(result); } MacroRecPtrType FindMacro( MacroTablePtrType pMacroTable, MacroStringPtrType aMacro ) { /* find a token in the macro table */ MacroRecPtrType result = NULL; MacroRecType key; MacroRecPtrType pMacroRec; key.pMacro = aMacro; if (pMacroTable && MACRO_GetCurrentCount(pMacroTable)) { pMacroRec = MACRO_GetRecordsPtr(pMacroTable); result = (MacroRecPtrType) bsearch ( (MacroRecPtrType) &key, (MacroRecPtrType) pMacroRec, MACRO_GetCurrentCount(pMacroTable), sizeof(MacroRecType), sortComp_MacroRec ); } #ifdef DEBUG_JETASM if (result) { printf("Found %s.\n", MACRO_GetMacroNamePtr(result)); } #endif return(result); } MacroTablePtrType MACRO_NewMacroTable(HP_UInt16 maxMacroEntries) { MacroRecPtrType pMacroRec = 0; MacroTablePtrType pMacroTable = 0; pMacroTable = (MacroTablePtrType) HP_MEMALLOC((size_t) sizeof(MacroTableType)); if (pMacroTable) { pMacroRec = (MacroRecPtrType) HP_MEMALLOC((size_t) sizeof(MacroRecType) * maxMacroEntries); if (pMacroRec) { pMacroTable->macroRecords = pMacroRec; pMacroTable->numMacroEntries = 0; pMacroTable->maxMacroEntries = maxMacroEntries; } else { HP_MEMDEALLOC(pMacroRec); } } return(pMacroTable); } StdFuncReturnType EscapeMacro( ParseObjPtrType pParseObj, HP_pUByte escapeName, MacroStringPtrType macroName, MacroStringPtrType macroBody ) { MacroTablePtrType pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); /* define the body of a macro */ if (MACRO_GetCurrentCount(pMacroTable) < MACRO_GetMaxEntries(pMacroTable)) { MacroRecPtrType pMacroRec = MACRO_GetRecordsPtr(pMacroTable); if (pMacroRec) { #define MAX_RETURN_STRING MAX_LINE_LENGTH #define MAX_RETURN_LEN (MAX_RETURN_STRING - 1) HP_pChar returnString = 0; MacroRecPtrType result; MacroStringPtrType pMacro, pBody; int macroLen = strlen(macroName); int bodyLen = strlen(macroBody); int returnStringLength; int escapeReturn; returnString = STRING_NewString(MAX_RETURN_STRING); if (returnString) { returnString[0] = '\0'; /* initialize return string to zero length */ if (strcmp(escapeName, inputEscapeString)) { /* if not $input operator, do regular EscapeMacro */ /* expecting a zero return value for a good operation */ escapeReturn = HP_EscapeMacro(pStream, escapeName, macroBody, returnString, MAX_RETURN_LEN); if (!escapeReturn) { returnStringLength = strlen(returnString); if (returnStringLength > MAX_RETURN_LEN) { HP_SetErrorCode(pStream, HPERR_EscapeStringTooLong); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_EscapeMacroFailed); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { /* inputEscapeString matches, */ /* get return string from user */ HP_LogMsg(inputString); HP_LogMsg(" "); HP_LogMsg(macroBody); HP_ReadInputString(returnString, MAX_RETURN_LEN); returnStringLength = strlen(returnString); if (returnStringLength > MAX_RETURN_LEN) { HP_SetErrorCode(pStream, HPERR_InputStringTooLong); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { MacroTablePtrType pMacroTable; if (macroName[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } if (result = FindMacro(pMacroTable, macroName)) { /* macro name already exists, just replace body */ if ((size_t) returnStringLength >= strlen(MACRO_GetMacroBodyPtr(result))) { pBody = (MacroStringPtrType) HP_MEMREALLOC (MACRO_GetMacroBodyPtr(result), (size_t) returnStringLength + 1/* 1 for null at end */); if (pBody) { strcpy(pBody, returnString); MACRO_SetMacroBodyPtr(result, pBody); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { strcpy(MACRO_GetMacroBodyPtr(result), returnString); } } else { /* new macro name, must allocate space for name * and value */ pMacro = (MacroStringPtrType) HP_MEMALLOC ((size_t) macroLen + 1 /* 1 for null at end */); pBody = (MacroStringPtrType) HP_MEMALLOC ((size_t) returnStringLength + 1 /* 1 for null at end */); if ((pMacro) && (pBody)) { int numMacroEntries = MACRO_GetCurrentCount(pMacroTable); strcpy(pMacro, macroName); strcpy(pBody, returnString); pMacroRec[numMacroEntries].pMacro = pMacro; pMacroRec[numMacroEntries].pBody = pBody; MACRO_SetMacroCount(pMacroTable, ++numMacroEntries); /* sort the macro table */ if (numMacroEntries > 1) { qsort(pMacroRec, numMacroEntries, sizeof(MacroRecType), sortComp_MacroRec); } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } STRING_DeleteString(returnString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } StdFuncReturnType DefineMacro( ParseObjPtrType pParseObj, MacroStringPtrType macroName, MacroStringPtrType macroBody ) { /* define the body of a macro */ MacroTablePtrType pMacroTable = NULL; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (macroName[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } if (MACRO_GetCurrentCount(pMacroTable) < MACRO_GetMaxEntries(pMacroTable)) { MacroRecPtrType pMacroRec = MACRO_GetRecordsPtr(pMacroTable); if (pMacroRec) { MacroRecPtrType result; MacroStringPtrType pMacro, pBody; int macroLen = strlen(macroName); int bodyLen = strlen(macroBody); if (result = FindMacro(pMacroTable, macroName)) { /* macro name already exists, just replace body */ if ((size_t) bodyLen >= strlen(MACRO_GetMacroBodyPtr(result))) { pBody = (MacroStringPtrType) HP_MEMREALLOC (MACRO_GetMacroBodyPtr(result), (size_t) bodyLen + 1/* 1 for null at end */); if (pBody) { strcpy(pBody, macroBody); MACRO_SetMacroBodyPtr(result, pBody); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { strcpy(MACRO_GetMacroBodyPtr(result), macroBody); } } else { /* new macro name, must allocate space for name * and value */ pMacro = (MacroStringPtrType) HP_MEMALLOC ((size_t) macroLen + 1 /* 1 for null at end */); pBody = (MacroStringPtrType) HP_MEMALLOC ((size_t) bodyLen + 1 /* 1 for null at end */); if ((pMacro) && (pBody)) { int numMacroEntries = MACRO_GetCurrentCount(pMacroTable); strcpy(pMacro, macroName); strcpy(pBody, macroBody); pMacroRec[numMacroEntries].pMacro = pMacro; pMacroRec[numMacroEntries].pBody = pBody; MACRO_SetMacroCount(pMacroTable, ++numMacroEntries); /* sort the macro table */ if (numMacroEntries > 1) { qsort(pMacroRec, numMacroEntries, sizeof(MacroRecType), sortComp_MacroRec); } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } StdFuncReturnType GetSymbolData(ParseObjPtrType pParseObj) { /* find a token in the symbol table */ SymbolRecPtrType result; PARSEOBJ_SetTokenClass(pParseObj, E_SymbolNotFound); /* symbol not found */ result = FindSymbol(PARSEOBJ_GetSymbolTable(pParseObj), PARSEOBJ_GetTokenPtr(pParseObj)); if (result) { PARSEOBJ_SetTokenClass(pParseObj, SYMBOL_GetTokenClass(result)); PARSEOBJ_SetTokenInstance(pParseObj, SYMBOL_GetTokenInstance(result)); } } SInt16FuncReturnType CalculateFixedLen(ParseObjPtrType pParseObj) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if ((PARSEOBJ_GetTokenInstance(pParseObj) >= SINGLE_ELEMENT_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= SINGLE_ELEMENT_END)) { return(1 /* one element */); } else if ((PARSEOBJ_GetTokenInstance(pParseObj) >= XY_ELEMENT_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= XY_ELEMENT_END)) { return(2 /* two elements */); } else if ((PARSEOBJ_GetTokenInstance(pParseObj) >= BOX_ELEMENT_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= BOX_ELEMENT_END)) { return(4 /* four elements */); } else if ((PARSEOBJ_GetTokenInstance(pParseObj) >= ARRAY_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= ARRAY_END)) { return(0 /* is an array */); } else { /* we should never get here, but here's the setting * if we do */ HP_SetErrorCode(pStream, HPERR_UnknownActualDataType); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } StdFuncReturnType ReAllocParseDataBuff(ParseObjPtrType pParseObj, HP_UInt32 newSize) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (newSize > PARSEOBJ_GetDataBuffSize(pParseObj)) { PARSEOBJ_SetDataBuffPtr(pParseObj, (DataBufferPtrType) HP_MEMREALLOC ((HP_pVoid) PARSEOBJ_GetDataBuffPtr(pParseObj), (size_t) newSize)); if (PARSEOBJ_GetDataBuffPtr(pParseObj)) { PARSEOBJ_SetDataBuffSize(pParseObj, newSize); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } StdFuncReturnType AllocParseDataBuff(ParseObjPtrType pParseObj, HP_UInt32 size) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (PARSEOBJ_GetDataBuffSize(pParseObj)) { /* data buffer exists, let's see if we need to make it bigger */ if (size > PARSEOBJ_GetDataBuffSize(pParseObj)) { ReAllocParseDataBuff(pParseObj, size); } } else { /* first time we've allocated the data buffer */ PARSEOBJ_SetDataBuffPtr(pParseObj, (DataBufferPtrType) HP_MEMALLOC((size_t) size)); if (PARSEOBJ_GetDataBuffPtr(pParseObj)) { PARSEOBJ_SetDataBuffSize(pParseObj, size); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } StdFuncReturnType InitParseDataBuff(ParseObjPtrType pParseObj) { /* initialize the parser object data buffer */ if (PARSEOBJ_GetDataBuffPtr(pParseObj)) { /* data buffer already allocated, just set index to zero */ PARSEOBJ_SetDataBuffIndex(pParseObj, 0); } else { /* data buffer has no data, initialize size also */ PARSEOBJ_SetDataBuffIndex(pParseObj, 0); PARSEOBJ_SetDataBuffSize(pParseObj, 0); } } StdFuncReturnType OutputData(ParseObjPtrType pParseObj) { #define X_INDEX 0 /* index of x value in the data buffer */ #define Y_INDEX 1 /* index of y value in the data buffer */ #define X1_INDEX 0 /* index of x1 value in the data buffer */ #define Y1_INDEX 1 /* index of y1 value in the data buffer */ #define X2_INDEX 2 /* index of x2 value in the data buffer */ #define Y2_INDEX 3 /* index of y2 value in the data buffer */ #define XY_DIVISOR 2 #define BOX_DIVISOR 4 DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualUByte: HP_AttrUByte(pStream, (HP_UByte) ((HP_pUByte) pDataBuff)[0]); break; case E_ActualUInt16: HP_AttrUInt16(pStream, (HP_UInt16) ((HP_pUInt16) pDataBuff)[0]); break; case E_ActualSInt16: HP_AttrSInt16(pStream, (HP_SInt16) ((HP_pSInt16) pDataBuff)[0]); break; case E_ActualUInt32: HP_AttrUInt32(pStream, (HP_UInt32) ((HP_pUInt32) pDataBuff)[0]); break; case E_ActualSInt32: HP_AttrSInt32(pStream, (HP_SInt32) ((HP_pSInt32) pDataBuff)[0]); break; case E_ActualReal32: HP_AttrReal32(pStream, (HP_Real32) ((HP_pReal32) pDataBuff)[0]); break; case E_ActualEmbeddedDataPrefix: HP_EmbeddedDataPrefix32(pStream, (HP_UInt32) ((HP_pUInt32) pDataBuff)[0]); break; case E_ActualEmbeddedDataPrefixByte: HP_EmbeddedDataPrefix(pStream, (HP_UInt32) ((HP_pUInt32) pDataBuff)[0]); break; case E_ActualXyUByte: HP_AttrXyUByte(pStream, (HP_UByte) ((HP_pUByte) pDataBuff)[X_INDEX], (HP_UByte) ((HP_pUByte) pDataBuff)[Y_INDEX]); break; case E_ActualXyUInt16: HP_AttrXyUInt16(pStream, (HP_UInt16) ((HP_pUInt16) pDataBuff)[X_INDEX], (HP_UInt16) ((HP_pUInt16) pDataBuff)[Y_INDEX]); break; case E_ActualXySInt16: HP_AttrXySInt16(pStream, (HP_SInt16) ((HP_pSInt16) pDataBuff)[X_INDEX], (HP_SInt16) ((HP_pSInt16) pDataBuff)[Y_INDEX]); break; case E_ActualXyUInt32: HP_AttrXyUInt32(pStream, (HP_UInt32) ((HP_pUInt32) pDataBuff)[X_INDEX], (HP_UInt32) ((HP_pUInt32) pDataBuff)[Y_INDEX]); break; case E_ActualXySInt32: HP_AttrXySInt32(pStream, (HP_SInt32) ((HP_pSInt32) pDataBuff)[X_INDEX], (HP_SInt32) ((HP_pSInt32) pDataBuff)[Y_INDEX]); break; case E_ActualXyReal32: HP_AttrXyReal32(pStream, (HP_Real32) ((HP_pReal32) pDataBuff)[X_INDEX], (HP_Real32) ((HP_pReal32) pDataBuff)[Y_INDEX]); break; case E_ActualBoxUByte: HP_AttrBoxUByte(pStream, (HP_UByte) ((HP_pUByte) pDataBuff)[X1_INDEX], (HP_UByte) ((HP_pUByte) pDataBuff)[Y1_INDEX], (HP_UByte) ((HP_pUByte) pDataBuff)[X2_INDEX], (HP_UByte) ((HP_pUByte) pDataBuff)[Y2_INDEX]); break; case E_ActualBoxUInt16: HP_AttrBoxUInt16(pStream, (HP_UInt16) ((HP_pUInt16) pDataBuff)[X1_INDEX], (HP_UInt16) ((HP_pUInt16) pDataBuff)[Y1_INDEX], (HP_UInt16) ((HP_pUInt16) pDataBuff)[X2_INDEX], (HP_UInt16) ((HP_pUInt16) pDataBuff)[Y2_INDEX]); break; case E_ActualBoxSInt16: HP_AttrBoxSInt16(pStream, (HP_SInt16) ((HP_pSInt16) pDataBuff)[X1_INDEX], (HP_SInt16) ((HP_pSInt16) pDataBuff)[Y1_INDEX], (HP_SInt16) ((HP_pSInt16) pDataBuff)[X2_INDEX], (HP_SInt16) ((HP_pSInt16) pDataBuff)[Y2_INDEX]); break; case E_ActualBoxUInt32: HP_AttrBoxUInt32(pStream, (HP_UInt32) ((HP_pUInt32) pDataBuff)[X1_INDEX], (HP_UInt32) ((HP_pUInt32) pDataBuff)[Y1_INDEX], (HP_UInt32) ((HP_pUInt32) pDataBuff)[X2_INDEX], (HP_UInt32) ((HP_pUInt32) pDataBuff)[Y2_INDEX]); break; case E_ActualBoxSInt32: HP_AttrBoxSInt32(pStream, (HP_SInt32) ((HP_pSInt32) pDataBuff)[X1_INDEX], (HP_SInt32) ((HP_pSInt32) pDataBuff)[Y1_INDEX], (HP_SInt32) ((HP_pSInt32) pDataBuff)[X2_INDEX], (HP_SInt32) ((HP_pSInt32) pDataBuff)[Y2_INDEX]); break; case E_ActualBoxReal32: HP_AttrBoxReal32(pStream, (HP_Real32) ((HP_pReal32) pDataBuff)[X1_INDEX], (HP_Real32) ((HP_pReal32) pDataBuff)[Y1_INDEX], (HP_Real32) ((HP_pReal32) pDataBuff)[X2_INDEX], (HP_Real32) ((HP_pReal32) pDataBuff)[Y2_INDEX]); break; case E_ActualUByteArray: HP_AttrUByteArray(pStream, (HP_pUByte) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualUInt16Array: HP_AttrUInt16Array(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualSInt16Array: HP_AttrSInt16Array(pStream, (HP_pSInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualUInt32Array: HP_AttrUInt32Array(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualSInt32Array: HP_AttrSInt32Array(pStream, (HP_pSInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualReal32Array: HP_AttrReal32Array(pStream, (HP_pReal32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualUByteSourceArray: case E_ActualSByteSourceArray: HP_DataUByteArray(pStream, (HP_pUByte) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualUInt16SourceArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_DataUInt16Array(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_DataUInt16ArrayMSB(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualSInt16SourceArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_DataUInt16Array(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_DataUInt16ArrayMSB(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualUInt32SourceArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_DataUInt32Array(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_DataUInt32ArrayMSB(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualSInt32SourceArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_DataUInt32Array(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_DataUInt32ArrayMSB(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualReal32SourceArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_DataReal32Array(pStream, (HP_pReal32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_DataReal32ArrayMSB(pStream, (HP_pReal32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualUByteRawArray: HP_RawUByteArray(pStream, (HP_pUByte) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualSByteRawArray: HP_RawUByteArray(pStream, (HP_pUByte) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); break; case E_ActualUInt16RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt16Array(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_RawUInt16ArrayMSB(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualSInt16RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt16Array(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_RawUInt16ArrayMSB(pStream, (HP_pUInt16) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualUInt32RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt32Array(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_RawUInt32ArrayMSB(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualSInt32RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt32Array(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_RawUInt32ArrayMSB(pStream, (HP_pUInt32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; case E_ActualReal32RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawReal32Array(pStream, (HP_pReal32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } else { HP_RawReal32ArrayMSB(pStream, (HP_pReal32) pDataBuff, PARSEOBJ_GetDataBuffIndex(pParseObj)); } break; default: HP_SetErrorCode(pStream, HPERR_UnknownInternalDataFormat); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } } /* end of output data */ StdFuncReturnType PARSEOBJ_InitParseString(ParseObjPtrType pParseObj) { SrcStringPtrType pString; /* initialize the data for the parse object string */ PARSEOBJ_SetStringLen(pParseObj, 0); PARSEOBJ_SetPosIndex(pParseObj, 0); pString = PARSEOBJ_GetStringPtr(pParseObj); pString[0] = '\0'; } ParseObjPtrType PARSEOBJ_NewParseObj(HP_StreamHandleType pStream, PathListPtrType pPathList, int maxStringSize, int isDisassembly) { ParseObjPtrType pParseObj; SrcStringPtrType pString; TokenPtrType pToken; if (pParseObj = (ParseObjPtrType) HP_MEMALLOC (sizeof(ParseObjType))) { pParseObj->pSrcString = 0; pParseObj->pToken = 0; pParseObj->pFileStack = 0; pParseObj->pMacroTable = 0; pParseObj->pSymbolTable = 0; pParseObj->mostSigByteFirst = 0; pParseObj->operatorCount = 0; pParseObj->pStream = pStream; pParseObj->pointType = E_NoPointType; pParseObj->dataOrg = HP_eBinaryLowByteFirst; pParseObj->dataOrgBuff = HP_eBinaryLowByteFirst; pParseObj->subCount = 0; PARSEOBJ_SetStringPtr(pParseObj, (SrcStringPtrType) HP_MEMALLOC((size_t) maxStringSize)); if (!PARSEOBJ_GetStringPtr(pParseObj)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } if (HP_NoErrors(pStream)) { HP_UInt16 statSize = sizeof(HP_UInt32) * HP_MaxNumberOfTags; PARSEOBJ_SetTagStatPtr(pParseObj, (TagStatPtrType) HP_MEMALLOC(statSize)); if (!PARSEOBJ_GetTagStatPtr(pParseObj)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } else { TagStatPtrType pTagStats = PARSEOBJ_GetTagStatPtr(pParseObj); int index; for (index = 0; index < HP_MaxNumberOfTags; index++) { pTagStats[index] = 0; } } } if (HP_NoErrors(pStream)) { HP_UInt16 statSize = sizeof(HP_UInt32) * HP_MaxNumberOfAttrs; PARSEOBJ_SetAttrStatPtr(pParseObj, (AttrStatPtrType) HP_MEMALLOC(statSize)); if (!PARSEOBJ_GetAttrStatPtr(pParseObj)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } else { AttrStatPtrType pAttrStats = PARSEOBJ_GetAttrStatPtr(pParseObj); int index; for (index = 0; index < HP_MaxNumberOfAttrs; index++) { pAttrStats[index] = 0; } } } if (HP_NoErrors(pStream)) { PARSEOBJ_SetTokenPtr(pParseObj, (TokenPtrType) HP_MEMALLOC((size_t) maxStringSize)); if (!PARSEOBJ_GetTokenPtr(pParseObj)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } } if (HP_NoErrors(pStream)) { pParseObj->pFileStack = FSTACK_NewFileStack(); if (!pParseObj->pFileStack) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } } if (HP_NoErrors(pStream)) { if (isDisassembly) { /* sort for the disassembler function */ pParseObj->pSymbolTable = SYMBOL_NewDisAsmSymbolTable(MAX_SYMBOL_ENTRIES); } else { /* sort for the assembler function */ pParseObj->pSymbolTable = SYMBOL_NewSymbolTable(MAX_SYMBOL_ENTRIES); } if (!(pParseObj->pSymbolTable)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } } if (HP_NoErrors(pStream)) { pParseObj->pMacroTable = MACRO_NewMacroTable(MAX_MACRO_ENTRIES); if (!(pParseObj->pMacroTable)) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } } if (HP_NoErrors(pStream)) { { /* initialize parse object values */ PARSEOBJ_SetDataBuffPtr(pParseObj, 0); PARSEOBJ_SetPosIndex(pParseObj, 0); PARSEOBJ_SetDataBuffSize(pParseObj, 0); PARSEOBJ_InitParseString(pParseObj); PARSEOBJ_SetExpectedDataType(pParseObj, 0); PARSEOBJ_SetExpectedDataLenType(pParseObj, 0); PARSEOBJ_SetExpectedDataFixedLen(pParseObj, 0); PARSEOBJ_SetCurrentState(pParseObj, STATEID_StartingAssembly); PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); PARSEOBJ_SetPathListPtr(pParseObj, pPathList); pString = PARSEOBJ_GetStringPtr(pParseObj); pString[0]='\0'; pToken = PARSEOBJ_GetTokenPtr(pParseObj); pToken[0]='\0'; pParseObj->tokenClass = E_SymbolNotFound; } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } return(pParseObj); } StdFuncReturnType PARSEOBJ_DeleteParseObj(ParseObjPtrType pParseObj) { #define SUB_DELETE_STRING_LENGTH 20 HP_pVoid memPtr = 0; char tempString[SUB_DELETE_STRING_LENGTH]; if (pParseObj) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); /* delete any temporary files holding subroutines: */ if (PARSEOBJ_GetSubCount(pParseObj)) { int subCount = PARSEOBJ_GetSubCount(pParseObj); int index; for (index = 1; index <= subCount; index++) { sprintf(tempString, "sub%03d.tmp", index); remove(tempString); } } SYMBOL_DeleteSymbolTable(PARSEOBJ_GetSymbolTable(pParseObj)); MACRO_DeleteMacroTable(PARSEOBJ_GetMacroTable(pParseObj)); FSTACK_DeleteFileStack(pFileStack); if (memPtr = PARSEOBJ_GetStringPtr(pParseObj)) { HP_MEMDEALLOC(memPtr); } if (memPtr = PARSEOBJ_GetTagStatPtr(pParseObj)) { HP_MEMDEALLOC(memPtr); } if (memPtr = PARSEOBJ_GetTokenPtr(pParseObj)) { HP_MEMDEALLOC(memPtr); } if (memPtr = PARSEOBJ_GetDataBuffPtr(pParseObj)) { HP_MEMDEALLOC(memPtr); } if (memPtr = PARSEOBJ_GetAttrStatPtr(pParseObj)) { HP_MEMDEALLOC(memPtr); } HP_MEMDEALLOC(pParseObj); } #undef SUB_DELETE_STRING_LENGTH } #ifdef DOS_MEM_MODEL #pragma code_seg ( "PCLXL_ASSEMBLER" ) #endif SInt16FuncReturnType findTokenInString(ParseObjPtrType pParseObj) { SrcStringPtrType pString = PARSEOBJ_GetStringPtr(pParseObj); TokenPtrType pToken = PARSEOBJ_GetTokenPtr(pParseObj); int currentPosIndex = PARSEOBJ_GetPosIndex(pParseObj); int tokenEndIndex; /* an index to the end of the token found */ int srcStrLen = PARSEOBJ_GetStringLen(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); /* this function finds the next token in the current string being scanned */ /* a macro to add a character to the token string */ #define AddCharToToken(pParseObj)\ pToken[tokenStoreIndex++] = \ pString[tokenEndIndex]; \ pToken[tokenStoreIndex] ='\0'; /* null at end */ pToken[0] = '\0'; if (currentPosIndex < srcStrLen) { /* check for leading spaces before the token: */ while ((currentPosIndex < srcStrLen) && (isspace(pString[currentPosIndex]))) { currentPosIndex++; } if (currentPosIndex < srcStrLen) { /* if the current position index is less than the length, * we found something... let's see what it is */ int done = 0; /* a flag to say we're done */ int tokenStoreIndex = 0; /* an index for storing chars in * the token */ /* loop to get length of token */ tokenEndIndex = currentPosIndex; /* do the following loop while we're not at the end of the * string, not scanning white space, and did not find an * open or close array bracket */ while ((tokenEndIndex < srcStrLen) && (!isspace(pString[tokenEndIndex])) && (!done)) { if (tokenEndIndex == currentPosIndex) { AddCharToToken(pParseObj); /* do a special check for an array start or end bracket * if we're scanning the first character */ switch (pString[tokenEndIndex]) { case CH_startOfNumArraySymbol: done = 1; case CH_endOfNumArraySymbol: done=1; case CH_startOfByteArraySymbol: done=1; default: tokenEndIndex++; /* always increment */ } } else { /* check for an array bracket on the end of a number */ if (pString[tokenEndIndex] == CH_endOfNumArraySymbol) { done = 1; /* let's say we're done without incrementing the token * end index so that we'll see this ending bracket * when we come around again following this token */ } else { AddCharToToken(pParseObj); tokenEndIndex++; /* increment only, end array * bracket is not found */ } } } if (tokenEndIndex <= srcStrLen) { int actualLen = tokenEndIndex - currentPosIndex; /* increment the current position index just beyond the * current token in the string */ PARSEOBJ_SetPosIndex(pParseObj, (currentPosIndex + actualLen)); return(actualLen); } else { /* our token end index somehow went beyond the end of the * string.. this should never happen, but here's the error * setting if it does */ HP_SetErrorCode(pStream, HPERR_SourceStringOverflow); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); return(TOKEN_NOT_FOUND); } } else { /* we scanned out the white space in the string and found no * more tokens */ /* no token found */ return(TOKEN_NOT_FOUND); } } else { /* the string contains no characters */ /* no token found */ return(TOKEN_NOT_FOUND); } } SInt16FuncReturnType findByteArray(ParseObjPtrType pParseObj) { int srcStrLen = PARSEOBJ_GetStringLen(pParseObj); SrcStringPtrType pString = PARSEOBJ_GetStringPtr(pParseObj); int currentPosIndex = PARSEOBJ_GetPosIndex(pParseObj); TokenPtrType pToken = PARSEOBJ_GetTokenPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); /* a macro to add a character to the token string */ #define AddCharToToken(pParseObj)\ pToken[tokenStoreIndex++] = \ pString[tokenEndIndex]; \ pToken[tokenStoreIndex] ='\0'; /* null at end */ int tokenEndIndex; /* an index to the end of the token found */ if (currentPosIndex < srcStrLen) { int done = 0; /* a flag to say we're done */ int tokenStoreIndex = 0; /* an index for storing chars in * the token */ /* loop to get length of token */ tokenEndIndex = currentPosIndex; /* do the following loop while we're not at the end of the * string, not scanning white space, and did not find an * open or close array bracket */ /* get ready to read byte array elements */ InitParseDataBuff(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } while (ASSEMBLY_Continue(pParseObj) && (tokenEndIndex < srcStrLen) && (!done)) { /* check for an byte array ending bracket */ if ((pString[tokenEndIndex] == CH_endOfByteArraySymbol)) { if (pString[tokenEndIndex+1] == CH_endOfByteArraySymbol) { tokenEndIndex++; /* skip over second embedded bracket */ } else { /* found ending bracket, we're done */ tokenEndIndex++; /* skip over end bracket */ done = 1; } } if (!done) { /* here's a byte we want, add it to the buffer and token string */ DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); AddCharToToken(pParseObj); switch (PARSEOBJ_GetExpectedDataType(pParseObj)) { case E_BasicTypeUByte: case E_BasicTypeSByte: ((HP_pUByte)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UByte) pString[tokenEndIndex]; break; case E_BasicTypeUInt16: case E_BasicTypeSInt16: ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) pString[tokenEndIndex]; break; case E_BasicTypeUInt32: case E_BasicTypeSInt32: ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) pString[tokenEndIndex]; break; case E_BasicTypeReal32: ((HP_pReal32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_Real32) (int) pString[tokenEndIndex]; break; default: HP_SetErrorCode(pStream, HPERR_UnknownInternalDataFormat); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); break; } /* end of switch */ PARSEOBJ_SetDataBuffIndex(pParseObj, PARSEOBJ_GetDataBuffIndex(pParseObj) + 1); tokenEndIndex++; /* increment token end index */ } } if (tokenEndIndex <= srcStrLen) { int actualLen = tokenEndIndex - currentPosIndex; /* increment the current position index just beyond the * current token in the string */ PARSEOBJ_SetPosIndex(pParseObj, (currentPosIndex + actualLen)); return(actualLen); } else { /* our token end index somehow went beyond the end of the * string.. this should never happen, but here's the error * setting if it does */ HP_SetErrorCode(pStream, HPERR_SourceStringOverflow); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); return(TOKEN_NOT_FOUND); } } else { /* the string contains no characters */ /* no token found */ return(TOKEN_NOT_FOUND); } } HP_StdFuncPrefix FindMacroValue( MacroTablePtrType pMacroTable, SymbolTablePtrType pSymbolTable, HP_pChar value ) { MacroRecPtrType macroResult; SymbolRecPtrType symbolResult; if (pMacroTable) { if (isalpha(value[0]) || (value[0] == '%')) { /* starts with alpha, must be macro or symbol name */ if (macroResult = FindMacro(pMacroTable, value)) { strcpy(value, MACRO_GetMacroBodyPtr(macroResult)); } else if (symbolResult = FindSymbol(pSymbolTable, value)) { if (SYMBOL_GetTokenClass(symbolResult) == E_DataValue) { sprintf(value, "%lu", SYMBOL_GetTokenInstance(symbolResult)); } } } } else { } } /* forward declaration for GetNextLine */ HP_StdFuncPrefix GetNextLine(ParseObjPtrType pParseObj); /* forward declaration for ReplaceAllMacros */ SInt16FuncReturnType ReplaceAllMacros(ParseObjPtrType pParseObj, SrcStringPtrType pString); HP_StdFuncPrefix ProcessMacroOperators(ParseObjPtrType pParseObj) { /* process any macro operators found in the string */ HP_pChar macroName = 0; HP_pChar escapeName = 0; HP_pChar operand1 = 0; HP_pChar operand2 = 0; HP_pChar operator0 = 0; SrcStringPtrType pString = PARSEOBJ_GetStringPtr(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); enum {real, integer} operationType; float op1Float, op2Float; long int op1Int, op2Int; int scan1Result, scan2Result; int maxStringLength = PARSEOBJ_GetStringLen(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); MacroTablePtrType pMacroTable = NULL; #define MAX_CALC_OPERATOR_LEN 8 macroName = STRING_NewString(maxStringLength); escapeName = STRING_NewString(maxStringLength); operand1 = STRING_NewString(maxStringLength); operand2 = STRING_NewString(MAX_LINE_LENGTH); /* must be max line length since * operand2 used for macro replacement * buffer below */ operator0 = STRING_NewString(maxStringLength); if (macroName && escapeName && operand1 && operand2 && operator0) { /* all strings allocated successfully */ /* now, look for macro operators: */ if (sscanf(pString, "$define %s ", macroName) == 1) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { /* we're okay macro name starts with alpha * or a "%" for local macro name */ operand2[0]='\0'; if (strlen(pString) > ((strlen(defineString) + strlen(macroName) + 2 /*spaces after each token*/))) { strcpy(operand2, &(pString[strlen(defineString) + strlen(macroName) + 2 /* spaces after tokens */])); } /* replace all macros in operand2 */ while (ASSEMBLY_Continue(pParseObj) && ReplaceAllMacros(pParseObj, operand2)); DefineMacro(pParseObj, macroName, operand2); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (sscanf(pString, "$escape %s %s ", escapeName, macroName) == 2) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { /* we're okay macro name starts with alpha */ operand2[0]='\0'; if (strlen(pString) > ((strlen(escapeString)) + strlen(macroName) + 2 /* spaces after each token */)) { strcpy(operand2, &(pString[strlen(escapeString) + strlen(macroName) + 2 /* spaces after tokens */])); } EscapeMacro(pParseObj, escapeName, macroName, operand2); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (sscanf(pString, "$input %s ", macroName) == 1) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { /* we're okay macro name starts with alpha */ strcpy(operand2, &(pString[strlen(inputString) + strlen(macroName) + 2 /* spaces after tokens */])); EscapeMacro(pParseObj, inputEscapeString, macroName, operand2); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (sscanf(pString, "$calc %s = %s %s %s", macroName, operand1, operator0, operand2) == 4) { if (strlen(operator0) <= MAX_CALC_OPERATOR_LEN) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { if (operand1[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } /* this is a macro operation */ FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), operand1); if (ASSEMBLY_Continue(pParseObj)) { if (operand2[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), operand2); } if (ASSEMBLY_Continue(pParseObj)) { if ( strchr((const char *)operand1, '.') || strchr((const char *)operand2, '.') ) { operationType = real; scan1Result = sscanf(operand1, "%f", &op1Float); scan2Result = sscanf(operand2, "%f", &op2Float); } else { operationType = integer; scan1Result = sscanf(operand1, "%li", &op1Int); scan2Result = sscanf(operand2, "%li", &op2Int); } if ((scan1Result) && (scan2Result)) { if (strcmp(operator0, "+")==0) { if (operationType == real) { sprintf(operand1, "%f", op1Float + op2Float); } else { sprintf(operand1, "%li", op1Int + op2Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "-")==0) { if (operationType == real) { sprintf(operand1, "%f", op1Float - op2Float); } else { sprintf(operand1, "%li", op1Int - op2Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "*")==0) { if (operationType == real) { sprintf(operand1, "%f", op1Float * op2Float); } else { sprintf(operand1, "%li", op1Int * op2Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "/")==0) { if (operationType == real) { sprintf(operand1, "%f", op1Float / op2Float); } else { sprintf(operand1, "%li", op1Int / op2Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "==")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float == op2Float)); } else { sprintf(operand1, "%d", (op1Int == op2Int)); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, ">")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float > op2Float)); } else { sprintf(operand1, "%d", (op1Int > op2Int)); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "<")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float < op2Float)); } else { sprintf(operand1, "%d", (op1Int < op2Int)); } DefineMacro(pParseObj, macroName, operand1); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if (strcmp(operator0, "!=")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float != op2Float)); } else { sprintf(operand1, "%d", (op1Int != op2Int)); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, ">=")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float >= op2Float)); } else { sprintf(operand1, "%d", (op1Int >= op2Int)); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "<=")==0) { if (operationType == real) { sprintf(operand1, "%d", (op1Float <= op2Float)); } else { sprintf(operand1, "%d", (op1Int <= op2Int)); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "mod")==0) { if (operationType == real) { sprintf(operand1, "%li", (unsigned long int) op1Float % (unsigned long int) op2Float); } else { sprintf(operand1, "%li", op1Int % op2Int); } DefineMacro(pParseObj, macroName, operand1); } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroValueConversionError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (sscanf(pString, "$calc %s = %s %s", macroName, operator0, operand1) == 3) { if (strlen(operator0) <= MAX_CALC_OPERATOR_LEN) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { if (operand1[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } /* this is a macro operation */ FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), operand1); if (ASSEMBLY_Continue(pParseObj)) { if (strchr((const char *)operand1, '.')) { operationType = real; scan1Result = sscanf(operand1, "%f", &op1Float); } else { operationType = integer; scan1Result = sscanf(operand1, "%li", &op1Int); } if (scan1Result) { if (strcmp(operator0, "-")==0) { if (operationType == real) { sprintf(operand1, "%f", -op1Float); } else { sprintf(operand1, "%li", -op1Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "trunc")==0) { if (operationType == real) { sprintf(operand1, "%li", (long int) op1Float); } else { sprintf(operand1, "%li", op1Int); } DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "round")==0) { if (operationType == real) { long int op1Trunc = (long int) op1Float; if (op1Float >= 0) { if ((op1Float - ((float) op1Trunc)) >= .5) { op1Float = op1Float + ((HP_Real32).5); } } else { if (((-op1Float) - ((float) -op1Trunc)) >= .5) { op1Float = op1Float - ((HP_Real32).5); } } sprintf(operand1, "%li", (long int) op1Float); } else { sprintf(operand1, "%li", (long int) op1Int); } DefineMacro(pParseObj, macroName, operand1); } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroValueConversionError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (sscanf(pString, "$string %s = %s %s %s", macroName, operand1, operator0, operand2) == 4) { if (strlen(operator0) <= 2) { if (isalpha(macroName[0]) || (macroName[0] == '%')) { if (operand1[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } /* this is a macro operation */ FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), operand1); if (ASSEMBLY_Continue(pParseObj)) { if (operand2[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), operand2); } if (ASSEMBLY_Continue(pParseObj)) { if ((strlen(operand1) + strlen(operand2)) < MAX_LINE_LENGTH) { if (strcmp(operator0, "+")==0) { strcat(operand1, operand2); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "==")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) == 0)); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "!=")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) != 0)); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "<")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) < 0)); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, "<=")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) <= 0)); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, ">")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) > 0)); DefineMacro(pParseObj, macroName, operand1); } else if (strcmp(operator0, ">=")==0) { sprintf(operand1, "%d", (strcmp(operand1, operand2) >= 0)); DefineMacro(pParseObj, macroName, operand1); } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else { HP_SetErrorCode(pStream, HPERR_MacroValueConversionError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_MacroNameMustStartWithAlpha); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroOperator); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { /* string allocations failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } STRING_DeleteString(macroName); STRING_DeleteString(escapeName); STRING_DeleteString(operand1); STRING_DeleteString(operand2); STRING_DeleteString(operator0); #undef MAX_CALC_OPERATOR_LEN } SInt16FuncReturnType ReplaceAllMacros(ParseObjPtrType pParseObj, SrcStringPtrType pString) { HP_pChar newInputString = 0; HP_pChar token = 0; int srcStringIndex = 0; int newStringIndex = 0; int done = 0; MacroRecPtrType result; SymbolRecPtrType symbolResult; int tokenLen = 0; int macrosReplaced = 0; int srcStringLength = strlen(pString); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); newInputString = STRING_NewString(MAX_LINE_LENGTH); token = STRING_NewString(MAX_LINE_LENGTH); if (!(newInputString && token)) { /* string allocations failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } else { newInputString[0] = '\0'; } while (ASSEMBLY_Continue(pParseObj) && (srcStringIndex < srcStringLength) && (newStringIndex < (MAX_STRING_SIZE))) { while (isspace(pString[srcStringIndex])) { newInputString[newStringIndex] = pString[srcStringIndex]; srcStringIndex++; newInputString[++newStringIndex]='\0'; } tokenLen = 0; if (srcStringIndex < srcStringLength) /* check for end of string */ { token[0] = '\0'; sscanf(&(pString[srcStringIndex]), "%s", token); tokenLen = strlen(token); /* check for those nasty array start brackets */ switch (token[0]) { case CH_startOfNumArraySymbol: case CH_startOfByteArraySymbol: if (tokenLen > 1) { token[1] = '\0'; tokenLen = 1; } break; default: break; } /* check for those nasty array end brackets */ switch (token[tokenLen - 1]) { case CH_endOfNumArraySymbol: case CH_endOfByteArraySymbol: if (tokenLen > 1) { token[--tokenLen] = '\0'; /* get rid of bracket */ } tokenLen = strlen(token); break; default: break; } if ( (isalpha(token[0]) && (result = FindMacro(PARSEOBJ_GetMacroTable(pParseObj), token)) ) || ((token[0] == '%') && (result = FindMacro(FSTACK_GetLocalMacroTable(pFileStack), token)) ) ) { int bodyIndex; MacroStringPtrType pBody = MACRO_GetMacroBodyPtr(result); int macroBodyLen = strlen(pBody); /* substitute macro into input string */ for (bodyIndex = 0; bodyIndex < macroBodyLen; bodyIndex++) { newInputString[newStringIndex++] = pBody[bodyIndex]; newInputString[newStringIndex] = '\0'; } if (strcmp(pBody, token) != 0) { /* the following check is for cases where someone passed * an unresolved parameter token of something like "%1" * as the first parameter to a subroutine and the "%1" * parameter has a matching body of "%1" */ /* body and token don't match, */ macrosReplaced = 1; } } else if (isalpha(token[0]) && (symbolResult = FindSymbol(PARSEOBJ_GetSymbolTable(pParseObj), token)) && (SYMBOL_GetTokenClass(symbolResult) == E_DataValue)) { #define MAX_UINT32_STRING 10 int valueIndex; char value[MAX_UINT32_STRING]; int valueLen; /* macro undefined, try looking in symbol table */ sprintf(value, "%lu", SYMBOL_GetTokenInstance(symbolResult)); valueLen = strlen(value); for (valueIndex = 0; valueIndex < valueLen; valueIndex++) { newInputString[newStringIndex++] = value[valueIndex]; newInputString[newStringIndex] = '\0'; } macrosReplaced = 1; #undef MAX_UINT32_STRING } else { int tokenIndex = 0; /* just copy raw input string to cooked string */ for (tokenIndex = 0; tokenIndex < tokenLen; tokenIndex++) { newInputString[newStringIndex++] = token[tokenIndex]; newInputString[newStringIndex] = '\0'; } } srcStringIndex = srcStringIndex + tokenLen; } else { newInputString[newStringIndex] = 0; /* add null at end of new input string */ } } /* end of outer while */ if (ASSEMBLY_Continue(pParseObj) && (newStringIndex > (MAX_STRING_SIZE))) { HP_SetErrorCode(pStream, HPERR_SourceStringOverflow); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else if (ASSEMBLY_Continue(pParseObj)) { strcpy(pString, newInputString); PARSEOBJ_SetStringLen(pParseObj, strlen(pString)); } STRING_DeleteString(newInputString); STRING_DeleteString(token); return(macrosReplaced); } HP_StdFuncPrefix PARSEOBJ_SetSubParameters( ParseObjPtrType pParseObj, HP_pChar execSubString, MacroTablePtrType pPrevMacroTable) { #define SUB_PARAM_NAME_LENGTH 10 /* This routine parses the $execsub macro line and extracts the * subroutine parameters. Each parameter is set to a local * macro name of %1, %2, %3... corresponding to its position on * the $execsub line. At then end of the routine a local macro * "%ParamCount" is set with a number representing the number * of paramters passed to the subroutine. */ HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); MacroTablePtrType pGlobalMacroTable = PARSEOBJ_GetMacroTable(pParseObj); MacroTablePtrType pMacroTable = NULL; MacroRecPtrType result = NULL; char strtok_seps[] = " ,\t\n"; /* legal separators for exec parms */ char *token; /* pointer to a token in execSubString */ int subParameterCount = 0; HP_pChar tempString = NULL; HP_pChar paramValue = NULL; tempString = STRING_NewString(SUB_PARAM_NAME_LENGTH); paramValue = STRING_NewString(MAX_LINE_LENGTH); if (tempString && paramValue) { token = strtok(execSubString, strtok_seps); /* skip $execsub macro */ token = strtok(NULL, strtok_seps); /* skip sub file name */ while(ASSEMBLY_Continue(pParseObj) && (token != NULL)) { /* Get next token: */ token = strtok( NULL, strtok_seps ); if (token) { sprintf(tempString, "%%%d", (++subParameterCount)); if (token[0] == '%') { pMacroTable = pPrevMacroTable; } else { pMacroTable = pGlobalMacroTable; } if (result = FindMacro(pMacroTable, token)) { /* macro value exists, replace param with value */ strcpy(paramValue, MACRO_GetMacroBodyPtr(result)); } else if (ASSEMBLY_Continue(pParseObj)) { /* token passed is parameter value */ strcpy(paramValue, token); } if (ASSEMBLY_Continue(pParseObj)) { DefineMacro(pParseObj, tempString, paramValue); } } } if (ASSEMBLY_Continue(pParseObj)) { sprintf(tempString, "%d", subParameterCount); DefineMacro(pParseObj, "%ParamCount", tempString); } STRING_DeleteString(tempString); STRING_DeleteString(paramValue); } else { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } #undef SUB_PARAM_NAME_LENGTH } HP_StdFuncPrefix WriteSubTempFile( ParseObjPtrType pParseObj, HP_pChar fileName, HP_pChar endToken) { HP_pChar localString = 0; FILE *tempFile; int endTokenLen = strlen(endToken); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); localString = STRING_NewString(MAX_LINE_LENGTH); if (!localString) { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } else { tempFile = openForWrite(pParseObj, fileName, "w"); } /* write subroutine strings to temporary file */ if (ASSEMBLY_Continue(pParseObj)) { int loopDone = 0; int foundEndToken = 0; int beginSubStringLength = 0; int endSubStringLength = 0; beginSubStringLength = strlen(beginSubString); endSubStringLength = strlen(endSubString); while (ASSEMBLY_Continue(pParseObj) && (!FSTACK_EndOfFile(pFileStack)) && (!loopDone)) { if (fgets(localString, MAX_LINE_LENGTH, FSTACK_TopOfFileStack(pFileStack))) { HP_pChar findString = localString; FSTACK_IncrementLineNumber(pFileStack); while (isspace(*findString)) { findString++; /* skip leading blanks */ } /* check for nested $beginsub */ if (strncmp(findString, beginSubString, beginSubStringLength) == 0) { /* cannot have nested subroutine */ HP_SetErrorCode(pStream, HPERR_NestedSubroutine); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } else { /* see if we found the ending token */ foundEndToken = (strncmp(findString, endToken, endTokenLen) == 0); if (foundEndToken) { loopDone = 1; } else { fputs(localString, tempFile); if (ferror(tempFile)) { HP_SetErrorCode(pStream, HPERR_FileWriteError); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } } else { HP_SetErrorCode(pStream, HPERR_FileReadError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } /* end of while loop */ fclose(tempFile); if (ASSEMBLY_Continue(pParseObj) && (!loopDone)) { HP_SetErrorCode(pStream, HPERR_EndSubNotFound); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } STRING_DeleteString(localString); } HP_StdFuncPrefix WriteLoopIfTempFile( ParseObjPtrType pParseObj, HP_pChar fileName, HP_pChar endToken) { HP_pChar localString = 0; FILE *tempFile; int endTokenLen = strlen(endToken); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); localString = STRING_NewString(MAX_LINE_LENGTH); if (!localString) { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } else { tempFile = openForWrite(pParseObj, fileName, "w"); } /* write loop strings to temporary file */ if (ASSEMBLY_Continue(pParseObj)) { int loopDone = 0; int nestLevel = 0; int processingLoop = (strcmp(endToken, endLoopString) == 0); int processingIf = !processingLoop; int foundEndToken = 0; int startIfStringLength = 0; int startLoopStringLength = 0; int endIfStringLength = 0; int endLoopStringLength = 0; startIfStringLength = strlen(startIfString); /* for $if and $ifnot */ startLoopStringLength = strlen(startLoopString); /* for $loop and $loopnot */ endIfStringLength = strlen(endIfString); endLoopStringLength = strlen(endLoopString); while (ASSEMBLY_Continue(pParseObj) && (!FSTACK_EndOfFile(pFileStack)) && (!loopDone)) { if (fgets(localString, MAX_LINE_LENGTH, FSTACK_TopOfFileStack(pFileStack))) { HP_pChar findString = localString; while (isspace(*findString)) { findString++; /* skip leading blanks */ } /* check for nested $loop or $if */ if (processingLoop && (strncmp(findString, startLoopString, startLoopStringLength) == 0)) { nestLevel++; } else if (processingIf && (strncmp(findString, startIfString, startIfStringLength) == 0)) { nestLevel++; } /* see if we found the ending token */ foundEndToken = (strncmp(findString, endToken, endTokenLen) == 0); if ((!nestLevel) && (foundEndToken)) { loopDone = 1; } else { fputs(localString, tempFile); if (ferror(tempFile)) { HP_SetErrorCode(pStream, HPERR_FileWriteError); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } if (foundEndToken) { nestLevel--; } } } else { HP_SetErrorCode(pStream, HPERR_FileReadError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } /* end of while loop */ fclose(tempFile); if (ASSEMBLY_Continue(pParseObj) && (!loopDone)) { if (strncmp(endToken, endLoopString, endLoopStringLength) == 0) { HP_SetErrorCode(pStream, HPERR_EndLoopNotFound); } else { HP_SetErrorCode(pStream, HPERR_EndIfNotFound); } PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } STRING_DeleteString(localString); } SInt16FuncReturnType MacroTrue(ParseObjPtrType pParseObj, HP_pChar macroName) { HP_pChar macroValueString; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); int macroValue = 0; macroValueString = STRING_NewString(MAX_LINE_LENGTH); if (macroValueString) { MacroTablePtrType pMacroTable = NULL; if (macroName[0] == '%') { pMacroTable = FSTACK_GetLocalMacroTable(pFileStack); } else { pMacroTable = PARSEOBJ_GetMacroTable(pParseObj); } if (FindMacro(pMacroTable, macroName)) { strcpy(macroValueString, macroName); FindMacroValue(pMacroTable, PARSEOBJ_GetSymbolTable(pParseObj), macroValueString); sscanf(macroValueString, "%i", ¯oValue); } else { HP_SetErrorCode(pStream, HPERR_UnknownMacroName); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } else { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } STRING_DeleteString(macroValueString); return(macroValue); } StdFuncReturnType GetNextLine(ParseObjPtrType pParseObj) { HP_pChar tempString = 0; HP_pChar temp2String = 0; HP_pChar macroValueString = 0; SrcStringPtrType pString = PARSEOBJ_GetStringPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); tempString = STRING_NewString(MAX_LINE_LENGTH); macroValueString = STRING_NewString(MAX_LINE_LENGTH); temp2String = STRING_NewString(MAX_LINE_LENGTH); if (tempString && macroValueString) { PARSEOBJ_InitParseString(pParseObj); /* initialize the parse string */ if (ReadUntilLineFeed( FSTACK_TopOfFileStack(pFileStack), pString, MAX_LINE_LENGTH)) { int srcStrLen; FSTACK_IncrementLineNumber(pFileStack); PARSEOBJ_SetStringLen(pParseObj, (size_t) strlen(pString)); srcStrLen = PARSEOBJ_GetStringLen(pParseObj); if ((srcStrLen > 0) && (pString[srcStrLen-1] == '\n')) { pString[srcStrLen-1] = '\0'; srcStrLen--; PARSEOBJ_SetStringLen(pParseObj, srcStrLen); } tempString[0] = '\0'; /* first, eliminate comments */ { int index = 0; while ((index < srcStrLen) && (!((pString[index]==CH_startOfCommentSymbol) && (pString[index+1]==CH_startOfCommentSymbol)))) { index++; } pString[index] = '\0'; srcStrLen = index; PARSEOBJ_SetStringLen(pParseObj, srcStrLen); } /* next, eliminate leading spaces */ { int firstNonSpace = 0; while (isspace(pString[firstNonSpace])) { firstNonSpace++; } if (firstNonSpace) { int frontIndex = 0; int copyIndex = firstNonSpace; /* shift input string to eliminate leading spaces */ while (copyIndex < srcStrLen) { pString[frontIndex++] = pString[copyIndex++]; } pString[frontIndex] = '\0'; srcStrLen = frontIndex; PARSEOBJ_SetStringLen(pParseObj, srcStrLen); } } #ifdef DEBUG_JETASM printf("GetNextLine: %s\n", pString); #endif srcStrLen = PARSEOBJ_GetStringLen(pParseObj); if (srcStrLen) { if ((sscanf(pString, "$include_raw %s", tempString) == 1)) { /* this is a raw $include file operator */ FILE *rawFile; int count; HP_pChar buffString = 0; buffString = STRING_NewString(MAX_LINE_LENGTH); if (buffString) { rawFile = openForRead(pParseObj, tempString, "rb"); if (rawFile) { while (count = fread(buffString, 1/*byte*/, MAX_LINE_LENGTH, rawFile)) { /* output raw bytes */ HP_RawUByteArray(pStream, buffString, count); } if (ferror(rawFile)) { HP_SetErrorCode(pStream, HPERR_FileReadError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } fclose(rawFile); } STRING_DeleteString(buffString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$include %s", tempString) == 1)) { MacroTablePtrType pLocalMacroTable = NULL; /* this is a standard $include file operator */ pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_PushFileStack(pParseObj, tempString, tempString, NOT_LOOP_OR_IF, NOT_LOOPING, pLocalMacroTable, 0, "r"); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$beginsub %s", tempString) == 1)) { /* begin a subroutine definition */ HP_UInt32 savedLineNumber = FSTACK_GetCurrentLineNumber(pFileStack); /* write the subroutine to a temporary file */ PARSEOBJ_IncrementSubCount(pParseObj); sprintf(temp2String, "sub%03d.tmp", PARSEOBJ_GetSubCount(pParseObj)); WriteSubTempFile(pParseObj, temp2String, endSubString); if (ASSEMBLY_Continue(pParseObj)) { /* use the subroutine name with a special suffix * to define a macro with which we'll find the * temp file name later in $execsub */ strcat(tempString, "_tempFile"); if (FindMacro(PARSEOBJ_GetMacroTable(pParseObj), tempString)) { /* subroutine with same name already exists */ HP_SetErrorCode(pStream, HPERR_SubroutineAlreadyExists); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else { DefineMacro(pParseObj, tempString, temp2String); } } if (ASSEMBLY_Continue(pParseObj)) { /* append the special temp file macro name * and use it to store the starting line * number for the temp file when the * subroutine is executed */ strcat(tempString, "Num"); /* "_tempFileNum" */ sprintf(temp2String, "%d", savedLineNumber); DefineMacro(pParseObj, tempString, temp2String); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$execsub %s", tempString) == 1)) { MacroTablePtrType pNewLocalMacroTable = NULL; MacroTablePtrType pPrevMacroTable = FSTACK_GetLocalMacroTable(pFileStack); MacroRecPtrType fileNameResult = NULL; MacroRecPtrType lineNumberResult = NULL; int lineNumber; /* this is an execsub operator */ /* concatenate a special suffix to the subroutine * name to form the macro name of the subroutine * temporary file */ strcpy(temp2String, tempString); strcat(temp2String, "_tempFile"); /* get the subroutine temporary file name: */ if (temp2String[0] == '%') { fileNameResult = FindMacro(pPrevMacroTable, temp2String); } else { fileNameResult = FindMacro(PARSEOBJ_GetMacroTable(pParseObj), temp2String); } if (!fileNameResult) { HP_SetErrorCode(pStream, HPERR_CannotOpenInput); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { pNewLocalMacroTable = MACRO_NewMacroTable(MAX_LOCAL_MACRO_ENTRIES); } if (ASSEMBLY_Continue(pParseObj)) { /* get the line number to be used * for the subroutine when called */ strcat(temp2String, "Num"); /* get the subroutine temporary file name: */ if (temp2String[0] == '%') { lineNumberResult = FindMacro(pPrevMacroTable, temp2String); } else { lineNumberResult = FindMacro(PARSEOBJ_GetMacroTable(pParseObj), temp2String); } if (!lineNumberResult) { HP_SetErrorCode(pStream, HPERR_CannotOpenInput); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else { sscanf(MACRO_GetMacroBodyPtr(lineNumberResult), "%d", &lineNumber); } } if (ASSEMBLY_Continue(pParseObj)) { /* push the subroutine file name on the stack * so it'll be the next thing parsed by * the assembler */ strcpy(temp2String, FSTACK_GetFileNamePtr(pFileStack)); FSTACK_PushFileStack(pParseObj, MACRO_GetMacroBodyPtr(fileNameResult), temp2String, NOT_LOOP_OR_IF, NOT_LOOPING, pNewLocalMacroTable, lineNumber, "r"); } if (ASSEMBLY_Continue(pParseObj)) { /* set up subroutine parameters */ /* $define all subroutine parameters to local * macros with a prefix of "%" */ PARSEOBJ_SetSubParameters(pParseObj, pString, pPrevMacroTable); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$loopnot %s", macroValueString) == 1)) { /* setup for $loopnot by building temp file */ sprintf(tempString, "asm%03d.tmp", FSTACK_GetTempFileSuffix(pFileStack)); FSTACK_IncrementTempFileSuffix(pFileStack); WriteLoopIfTempFile(pParseObj, tempString, "$endloop"); if (ASSEMBLY_Continue(pParseObj)) { if (!(MacroTrue(pParseObj, macroValueString)) && ASSEMBLY_Continue(pParseObj)) { MacroTablePtrType pLocalMacroTable = NULL; pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_PushFileStack(pParseObj, tempString, FSTACK_GetAliasNamePtr(pFileStack), (HP_pVoid) macroValueString, LOOP_EndOnTrue, pLocalMacroTable, FSTACK_GetCurrentLineNumber(pFileStack), "r"); } else { remove(tempString); } } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$loop %s", macroValueString) == 1)) { /* setup for $loop by building temp file */ sprintf(tempString, "asm%03d.tmp", FSTACK_GetTempFileSuffix(pFileStack)); FSTACK_IncrementTempFileSuffix(pFileStack); WriteLoopIfTempFile(pParseObj, tempString, "$endloop"); if (ASSEMBLY_Continue(pParseObj)) { if (MacroTrue(pParseObj, macroValueString) && ASSEMBLY_Continue(pParseObj)) { MacroTablePtrType pLocalMacroTable = NULL; pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_PushFileStack(pParseObj, tempString, FSTACK_GetAliasNamePtr(pFileStack), (HP_pVoid ) macroValueString, LOOP_EndOnFalse, pLocalMacroTable, FSTACK_GetCurrentLineNumber(pFileStack), "r"); } else { remove(tempString); } } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$ifnot %s", macroValueString) == 1)) { /* setup for $if by building temp file */ sprintf(tempString, "asm%03d.tmp", FSTACK_GetTempFileSuffix(pFileStack)); FSTACK_IncrementTempFileSuffix(pFileStack); WriteLoopIfTempFile(pParseObj, tempString, "$endif"); if (ASSEMBLY_Continue(pParseObj)) { if ((!MacroTrue(pParseObj, macroValueString)) && ASSEMBLY_Continue(pParseObj)) { MacroTablePtrType pLocalMacroTable = NULL; pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_PushFileStack(pParseObj, tempString, FSTACK_GetAliasNamePtr(pFileStack), (HP_pVoid ) "$if", NOT_LOOPING, pLocalMacroTable, FSTACK_GetCurrentLineNumber(pFileStack), "r"); } else { remove(tempString); } } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if ((sscanf(pString, "$if %s", macroValueString) == 1)) { /* setup for $if by building temp file */ sprintf(tempString, "asm%03d.tmp", FSTACK_GetTempFileSuffix(pFileStack)); FSTACK_IncrementTempFileSuffix(pFileStack); WriteLoopIfTempFile(pParseObj, tempString, "$endif"); if (ASSEMBLY_Continue(pParseObj)) { if (MacroTrue(pParseObj, macroValueString) && ASSEMBLY_Continue(pParseObj)) { MacroTablePtrType pLocalMacroTable = NULL; pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); FSTACK_PushFileStack(pParseObj, tempString, FSTACK_GetAliasNamePtr(pFileStack), (HP_pVoid ) "$if", NOT_LOOPING, pLocalMacroTable, FSTACK_GetCurrentLineNumber(pFileStack), "r"); } else { remove(tempString); } } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if (strncmp(pString, stopString, strlen(stopString))==0) { sprintf(temp2String, "$stop Found While Processing Line# %d in ""%s"".\n", FSTACK_GetCurrentLineNumber(pFileStack), FSTACK_GetAliasNamePtr(pFileStack)); HP_LogMsg(temp2String); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else if (strncmp(pString, abortString, strlen(abortString))==0) { sprintf(temp2String, "$abort Found While Processing Line# %d in ""%s"".\n", FSTACK_GetCurrentLineNumber(pFileStack), FSTACK_GetAliasNamePtr(pFileStack)); HP_LogMsg(temp2String); HP_SetErrorCode(pStream, HPERR_UserAbort); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else if (strncmp(pString, endLoopString, strlen(endLoopString))==0) { HP_SetErrorCode(pStream, HPERR_EndLoopNoMatch); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); } else if (strncmp(pString, endIfString, strlen(endIfString))==0) { HP_SetErrorCode(pStream, HPERR_EndIfNoMatch); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); } else if (strncmp(pString, lineString, strlen(lineString))==0) { HP_pChar lineStringBuff = 0; lineStringBuff = STRING_NewString(MAX_LINE_LENGTH); if (!lineStringBuff) { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { lineStringBuff[0] = '\0'; strcpy(lineStringBuff, &(pString[strlen(lineString)])); /* replace all macros in string */ while (ASSEMBLY_Continue(pParseObj) && ReplaceAllMacros(pParseObj, lineStringBuff)); } if (ASSEMBLY_Continue(pParseObj)) { sprintf(temp2String, "$line %ld in file ""%s"": %s\n", (int) FSTACK_GetCurrentLineNumber(pFileStack), (char *) FSTACK_GetAliasNamePtr(pFileStack), (char *) lineStringBuff); HP_LogMsg(temp2String); PARSEOBJ_InitParseString(pParseObj); } STRING_DeleteString(lineStringBuff); } else if (strncmp(pString, printString, strlen(printString))==0) { HP_pChar printStringBuff = 0; printStringBuff = STRING_NewString(MAX_LINE_LENGTH); if (!printStringBuff) { /* string allocation failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { printStringBuff[0]='\0'; strcpy(printStringBuff, pString); /* replace all macros in string */ while (ASSEMBLY_Continue(pParseObj) && ReplaceAllMacros(pParseObj, printStringBuff)); } if (ASSEMBLY_Continue(pParseObj)) { sprintf(temp2String, "%s\n", printStringBuff); HP_LogMsg(temp2String); PARSEOBJ_InitParseString(pParseObj); } STRING_DeleteString(printStringBuff); } else if (strncmp(pString, highByteString, strlen(highByteString))==0) { PARSEOBJ_SetDataOrg(pParseObj, HP_eBinaryHighByteFirst); PARSEOBJ_InitParseString(pParseObj); } else if (strncmp(pString, lowByteString, strlen(lowByteString))==0) { PARSEOBJ_SetDataOrg(pParseObj, HP_eBinaryLowByteFirst); PARSEOBJ_InitParseString(pParseObj); } else if (pString[0] == '$') { ProcessMacroOperators(pParseObj); } else { /* replace all macros in string */ while (ASSEMBLY_Continue(pParseObj) && ReplaceAllMacros(pParseObj, PARSEOBJ_GetStringPtr(pParseObj))); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_SetStringLen(pParseObj, strlen(PARSEOBJ_GetStringPtr(pParseObj))); } } } } else { if (feof(FSTACK_TopOfFileStack(pFileStack))) { if (FSTACK_GetNumOpenFiles(pFileStack) == 1) { /* if this is the only open file in the nest, we * must stop */ fclose(FSTACK_TopOfFileStack(pFileStack)); PARSEOBJ_SetTokenClass(pParseObj, E_EndOfFile); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } else { HP_pChar loopOrIfMacroName = (HP_pChar ) FSTACK_GetMacroNamePtr(pFileStack); fclose(FSTACK_TopOfFileStack(pFileStack)); if (!loopOrIfMacroName) { /* must be a standard $include file */ FSTACK_PopFileStack(pFileStack); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } /* check for temp file for $if or end of $loop: */ else if (ASSEMBLY_Continue(pParseObj) && ((strcmp(loopOrIfMacroName, "$if") == 0) || (MacroTrue(pParseObj, loopOrIfMacroName) && FSTACK_LoopEndOnTrue(pFileStack)) || (!MacroTrue(pParseObj, loopOrIfMacroName) && !FSTACK_LoopEndOnTrue(pFileStack)))) { /* we're done looping on this file or its an $if file */ HP_UInt32 lineNumber = FSTACK_GetCurrentLineNumber(pFileStack); strcpy(tempString, FSTACK_GetFileNamePtr(pFileStack)); FSTACK_PopFileStack(pFileStack); FSTACK_SetCurrentLineNumber(pFileStack, lineNumber); /* remove temp file after pop has closed file */ remove(tempString); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } else if (ASSEMBLY_Continue(pParseObj)) { /* looping on temporary $include file */ HP_UByte endFlag = FSTACK_GetLoopEndFlag(pFileStack); MacroTablePtrType pLocalMacroTable = NULL; pLocalMacroTable = FSTACK_GetLocalMacroTable(pFileStack); strcpy(tempString, FSTACK_GetFileNamePtr(pFileStack)); /* use macroValueString to hold $loop macro name */ strcpy(macroValueString, loopOrIfMacroName); FSTACK_PopFileStack(pFileStack); /* close current file */ /* now restart: */ FSTACK_PushFileStack(pParseObj, tempString, FSTACK_GetAliasNamePtr(pFileStack), (HP_pVoid ) macroValueString, endFlag, pLocalMacroTable, FSTACK_GetCurrentLineNumber(pFileStack), "r"); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_InitParseString(pParseObj); } } } } else { HP_SetErrorCode(pStream, HPERR_FileReadError); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } else { /* string allocations failed */ HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } STRING_DeleteString(tempString); STRING_DeleteString(macroValueString); STRING_DeleteString(temp2String); } SInt16FuncReturnType findTokenInFile(ParseObjPtrType pParseObj) { /* find next token in the file */ int findTokenSuccess = 0; HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); while ((!findTokenSuccess) && ASSEMBLY_Continue(pParseObj) && (!IS_EOF(pParseObj))) { findTokenSuccess = findTokenInString(pParseObj); if (ASSEMBLY_Continue(pParseObj) && (!findTokenSuccess)) { /* give it one more "college try" to get a new string */ GetNextLine(pParseObj); } } return(findTokenSuccess); } StdFuncReturnType GetNextValue(ParseObjPtrType pParseObj) { int elementsScanned = 0; SymbolRecPtrType result; DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); DataUnionType thisValue; /* first, see if token is an enumerated value name */ if (isalpha(PARSEOBJ_GetTokenPtr(pParseObj)[0]) && (result = FindSymbol(PARSEOBJ_GetSymbolTable(pParseObj), PARSEOBJ_GetTokenPtr(pParseObj))) && (SYMBOL_GetTokenClass(result) == E_DataValue)) { switch (PARSEOBJ_GetExpectedDataType(pParseObj)) { case E_BasicTypeUByte: case E_BasicTypeSByte: thisValue.aByte = (HP_UByte) SYMBOL_GetTokenInstance(result); ((HP_pUByte)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UByte) thisValue.aByte; /* set potential data organization (DataOrg) value */ PARSEOBJ_SetDataOrgBuff(pParseObj, (HP_UByte) thisValue.aByte); break; case E_BasicTypeUInt16: case E_BasicTypeSInt16: thisValue.anInt16 = (HP_UInt16) SYMBOL_GetTokenInstance(result); ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) thisValue.anInt16; break; case E_BasicTypeUInt32: case E_BasicTypeSInt32: thisValue.anInt32 = (HP_UInt32) SYMBOL_GetTokenInstance(result); ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) thisValue.anInt32; break; case E_BasicTypeReal32: thisValue.aReal32 = (HP_Real32) SYMBOL_GetTokenInstance(result); ((HP_pReal32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_Real32) thisValue.aReal32; break; default: HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); break; } /* end of switch */ } else if (ASSEMBLY_Continue(pParseObj)) /* must be just ascii digits for a number */ { switch (PARSEOBJ_GetExpectedDataType(pParseObj)) { case E_BasicTypeUByte: if (sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%i", &(thisValue.anInt16))==1) { /* set potential data organization (DataOrg) value */ PARSEOBJ_SetDataOrgBuff(pParseObj, (HP_UByte) thisValue.anInt16); switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualUByteRawArray: HP_RawUByte(pStream, (HP_UByte) thisValue.anInt16); break; case E_ActualSByteRawArray: HP_RawUByte(pStream, (HP_UByte) thisValue.anInt16); break; default: /* add to array by placing in data buffer: */ ((HP_pUByte)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UByte) thisValue.anInt16; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); } break; case E_BasicTypeSByte: if (sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%i", &(thisValue.anInt16))==1) { switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualUByteRawArray: HP_RawUByte(pStream, (HP_UByte) thisValue.anInt16); break; case E_ActualSByteRawArray: HP_RawUByte(pStream, (HP_UByte) thisValue.anInt16); break; default: /* add to array by placing in data buffer: */ ((HP_pUByte)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UByte) thisValue.anInt16; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); } break; case E_BasicTypeUInt16: case E_BasicTypeSInt16: { if (PARSEOBJ_GetExpectedDataType(pParseObj) == E_BasicTypeUInt16) { elementsScanned = sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%i", &(thisValue.anInt16)); } else { elementsScanned = sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%i", &(thisValue.anInt16)); } if (elementsScanned == 1) { switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualUInt16RawArray: case E_ActualSInt16RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt16(pStream, (HP_UInt16) thisValue.anInt16); } else { HP_RawUInt16MSB(pStream, (HP_UInt16) thisValue.anInt16); } break; default: /* add to array by placing in data buffer: */ ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) thisValue.anInt16; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } break; case E_BasicTypeUInt32: case E_BasicTypeSInt32: { if (PARSEOBJ_GetExpectedDataType(pParseObj) == E_BasicTypeUInt32) { elementsScanned = sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%li", &(thisValue.anInt32)); } else { elementsScanned = sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%li", &(thisValue.anInt32)); } if (elementsScanned == 1) { switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualUInt32RawArray: case E_ActualSInt32RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt32(pStream, (HP_UInt32) thisValue.anInt32); } else { HP_RawUInt32MSB(pStream, (HP_UInt32) thisValue.anInt32); } break; default: /* add to array by placing in data buffer: */ ((HP_pUInt32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt32) thisValue.anInt32; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } break; case E_BasicTypeReal32: { elementsScanned = sscanf(PARSEOBJ_GetTokenPtr(pParseObj), "%f", &(thisValue.aReal32)); if (elementsScanned == 1) { switch (PARSEOBJ_GetTokenInstance(pParseObj)) { case E_ActualReal32RawArray: if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawReal32(pStream, (HP_Real32) thisValue.aReal32); } else { HP_RawReal32MSB(pStream, (HP_Real32) thisValue.aReal32); } break; default: /* add to array by placing in data buffer: */ ((HP_pReal32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_Real32) thisValue.aReal32; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } break; default: HP_SetErrorCode(pStream, HPERR_UnknownInternalDataFormat); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } /* end of switch */ } /* end of if */ if (ASSEMBLY_Continue(pParseObj)) { /* increment the data buffer element index */ /* note that this index points to the next "element" not "byte" * in the buffer based on the basic data type of the number(s) * being scanned */ if (!IS_RAW_DATA_ID(pParseObj)) { PARSEOBJ_SetDataBuffIndex(pParseObj, PARSEOBJ_GetDataBuffIndex(pParseObj) + 1); } } } StdFuncReturnType GetDataValues(ParseObjPtrType pParseObj) { int done = 0; HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); PARSEOBJ_SetExpectedDataType(pParseObj, actualTypeMap[PARSEOBJ_GetTokenInstance(pParseObj)]); if ((PARSEOBJ_GetTokenInstance(pParseObj) >= ARRAY_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= ARRAY_END)) { PARSEOBJ_SetExpectedDataLenType(pParseObj, E_TokenLenArray); } else if ((PARSEOBJ_GetTokenInstance(pParseObj) >= SINGLE_ELEMENT_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= BOX_ELEMENT_END)) { PARSEOBJ_SetExpectedDataLenType(pParseObj, E_TokenLenFixed); PARSEOBJ_SetExpectedDataFixedLen(pParseObj, CalculateFixedLen(pParseObj)); } else { HP_SetErrorCode(pStream, HPERR_InvalidDataId); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { int fixedLenCount = 0; int findTokenSuccess = 0; if (PARSEOBJ_GetExpectedDataLenType(pParseObj) == E_TokenLenFixed) { InitParseDataBuff(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } if (ASSEMBLY_Continue(pParseObj)) { do /* outer do-while loop to get next string from input file if we run to */ /* the end of the string while scanning data */ { findTokenSuccess = 1; /* done before this routine called */ while ((!done) && (ASSEMBLY_Continue(pParseObj)) && (findTokenSuccess)) { GetNextValue(pParseObj); /* get next data element from stream */ if (ASSEMBLY_Continue(pParseObj)) { fixedLenCount++; if (fixedLenCount == PARSEOBJ_GetExpectedDataFixedLen(pParseObj)) { done = 1; } else if (fixedLenCount > PARSEOBJ_GetExpectedDataFixedLen(pParseObj)) { HP_SetErrorCode(pStream, HPERR_DataCountExceeded); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } else { findTokenSuccess = findTokenInString(pParseObj); } } } /* end of while loop */ if (ASSEMBLY_Continue(pParseObj) && (!done) && (!findTokenSuccess)) { /* lets try reading another string and loop again */ GetNextLine(pParseObj); } } while (ASSEMBLY_Continue(pParseObj) && (!done) && (!IS_EOF(pParseObj))); /* outer do-while loop */ } /* end of if just before do-while loop */ if (ASSEMBLY_Continue(pParseObj) && (done)) { OutputData(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { if (IS_DATA_SOURCE_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else if (IS_RAW_DATA_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else if (IS_EMBEDDED_DATA_PREFIX(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningAttributeId); } } else { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } else /* not a fixed length type, must be array */ { if ((strlen(PARSEOBJ_GetTokenPtr(pParseObj)) == 1) && (PARSEOBJ_GetTokenPtr(pParseObj)[0] == CH_startOfNumArraySymbol)) { /* get ready to do number array */ InitParseDataBuff(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } if (ASSEMBLY_Continue(pParseObj)) { do /* outer do-while loop to get next string from input file if we run to */ /* the end of the string while scanning data */ { while ((!done) && (ASSEMBLY_Continue(pParseObj)) && (findTokenSuccess = findTokenInString(pParseObj))) { if ((strlen(PARSEOBJ_GetTokenPtr(pParseObj)) == 1) && (PARSEOBJ_GetTokenPtr(pParseObj)[0] == CH_endOfNumArraySymbol)) { /* end of number array found */ done = 1; } else { GetNextValue(pParseObj); /* get next data element from string */ } } /* end of while loop */ if (ASSEMBLY_Continue(pParseObj) && (!findTokenSuccess) && (!done)) { /* lets try reading another string and loop again */ GetNextLine(pParseObj); } } while (ASSEMBLY_Continue(pParseObj) && (!done) && (!IS_EOF(pParseObj))); /* outer do-while loop */ } if (ASSEMBLY_Continue(pParseObj) && (done)) { /* next, only output data if not raw data array */ /* raw data arrays get output to the stream value by value */ /* all other data arrays are buffered */ if (!IS_RAW_DATA_ID(pParseObj)) OutputData(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { if (IS_DATA_SOURCE_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else if (IS_RAW_DATA_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningAttributeId); } } else { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } /* end of if to check for start of number array bracket */ else if ((strlen(PARSEOBJ_GetTokenPtr(pParseObj)) == 1) && (PARSEOBJ_GetTokenPtr(pParseObj)[0] == CH_startOfByteArraySymbol)) { /* we have the beginning of a byte (string) array */ InitParseDataBuff(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } if (ASSEMBLY_Continue(pParseObj)) { findByteArray(pParseObj); } if (ASSEMBLY_Continue(pParseObj)) { /* go ahead and output the data */ OutputData(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { if (IS_DATA_SOURCE_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else if (IS_RAW_DATA_ID(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningAttributeId); } } } } else { HP_SetErrorCode(pStream, HPERR_MissingOpenBracket); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } /* end of if to check for number array */ } /* end of no errors if */ } StdFuncReturnType DisAsmGetNextValue(ParseObjPtrType pParseObj) { int elementsScanned = 0; DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_SInt16 intByteBuff; DataUnionType thisValue; switch (PARSEOBJ_GetExpectedDataType(pParseObj)) { case E_BasicTypeUByte: case E_BasicTypeSByte: intByteBuff = FSTACK_NextByte(pFileStack); if (intByteBuff != EOF) { thisValue.aByte = (HP_UByte) intByteBuff; /* set potential data organization (DataOrg) value */ PARSEOBJ_SetDataOrgBuff(pParseObj, (HP_UByte) thisValue.aByte); if (ASSEMBLY_Continue(pParseObj)) { if (PARSEOBJ_GetDataBuffSize(pParseObj) >= ((PARSEOBJ_GetDataBuffIndex(pParseObj)+1) * sizeof(HP_UByte))) { ((HP_pUByte)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UByte) thisValue.aByte; } else { HP_SetErrorCode(pStream, HPERR_DataBufferOverflow); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } } else { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } break; case E_BasicTypeUInt16: case E_BasicTypeSInt16: thisValue.anInt16 = PARSEOBJ_GetUInt16(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); if (ASSEMBLY_Continue(pParseObj)) { if (PARSEOBJ_GetDataBuffSize(pParseObj) >= ((PARSEOBJ_GetDataBuffIndex(pParseObj)+1) * sizeof(HP_UInt16))) { ((HP_pUInt16)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt16) thisValue.anInt16; } else { HP_SetErrorCode(pStream, HPERR_DataBufferOverflow); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case E_BasicTypeUInt32: case E_BasicTypeSInt32: thisValue.anInt32 = PARSEOBJ_GetUInt32(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); if (ASSEMBLY_Continue(pParseObj)) { if (PARSEOBJ_GetDataBuffSize(pParseObj) >= ((PARSEOBJ_GetDataBuffIndex(pParseObj)+1) * sizeof(HP_UInt32))) { ((HP_pUInt32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_UInt32) thisValue.anInt32; } else { HP_SetErrorCode(pStream, HPERR_DataBufferOverflow); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case E_BasicTypeReal32: thisValue.aReal32 = PARSEOBJ_GetReal32(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); if (ASSEMBLY_Continue(pParseObj)) { if (PARSEOBJ_GetDataBuffSize(pParseObj) >= ((PARSEOBJ_GetDataBuffIndex(pParseObj)+1) * sizeof(HP_Real32))) { ((HP_pReal32)pDataBuff)[PARSEOBJ_GetDataBuffIndex(pParseObj)] = (HP_Real32) thisValue.aReal32; } else { HP_SetErrorCode(pStream, HPERR_DataBufferOverflow); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; default: HP_SetErrorCode(pStream, HPERR_UnknownInternalDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } /* end of switch */ if (ASSEMBLY_Continue(pParseObj)) { /* increment the data buffer element index */ /* note that this index points to the next "element" not "byte" * in the buffer based on the basic data type of the number(s) * being scanned */ PARSEOBJ_SetDataBuffIndex(pParseObj, PARSEOBJ_GetDataBuffIndex(pParseObj) + 1); } } StdFuncReturnType DisAsmGetDataValues(ParseObjPtrType pParseObj, HP_UByte dataValueTag) { HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); PARSEOBJ_SetExpectedDataType(pParseObj, actualTypeMap[HP_dataTagMap[dataValueTag]]); PARSEOBJ_SetTokenInstance(pParseObj, HP_dataTagMap[dataValueTag]); if ((PARSEOBJ_GetTokenInstance(pParseObj) >= ARRAY_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= ARRAY_END)) { PARSEOBJ_SetExpectedDataLenType(pParseObj, E_TokenLenArray); } else if ((PARSEOBJ_GetTokenInstance(pParseObj) >= SINGLE_ELEMENT_START) && (PARSEOBJ_GetTokenInstance(pParseObj) <= BOX_ELEMENT_END)) { PARSEOBJ_SetExpectedDataLenType(pParseObj, E_TokenLenFixed); PARSEOBJ_SetExpectedDataFixedLen(pParseObj, CalculateFixedLen(pParseObj)); } else { HP_SetErrorCode(pStream, HPERR_InvalidDataId); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } if (ASSEMBLY_Continue(pParseObj)) { HP_UInt32 lengthCount = 0; int findTokenSuccess = 0; if (PARSEOBJ_GetExpectedDataLenType(pParseObj) == E_TokenLenFixed) { lengthCount = PARSEOBJ_GetExpectedDataFixedLen(pParseObj); } else /* is an array, get the length */ { lengthCount = PARSEOBJ_GetArrayLength(pParseObj); } if (ASSEMBLY_Continue(pParseObj)) { InitParseDataBuff(pParseObj); } if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } if ((lengthCount>0) && ASSEMBLY_Continue(pParseObj)) { HP_UInt16 currentCount = 0; int done = 0; while ((!done) && ASSEMBLY_Continue(pParseObj)) { DisAsmGetNextValue(pParseObj); /* get next data element from stream */ if (ASSEMBLY_Continue(pParseObj)) { currentCount++; if (currentCount >= lengthCount) { done = 1; } } } /* end of if just before do-while loop */ } } /* end of no errors if */ } StdFuncReturnType ProcessHexData(ParseObjPtrType pParseObj) { int done = 0; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { int fixedLenCount = 0; int findTokenSuccess = 0; findTokenSuccess = findTokenInFile(pParseObj); if ((findTokenSuccess) && (strlen(PARSEOBJ_GetTokenPtr(pParseObj)) == 1) && (PARSEOBJ_GetTokenPtr(pParseObj)[0] == CH_startOfNumArraySymbol)) { /* get ready to do number array */ InitParseDataBuff(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { AllocParseDataBuff(pParseObj, dataTypeLenMap[PARSEOBJ_GetTokenInstance(pParseObj)]); } if (ASSEMBLY_Continue(pParseObj)) { do /* outer do-while loop to get next string from input file if we run to */ /* the end of the string while scanning data */ { findTokenSuccess = 0; while ((!done) && ASSEMBLY_Continue(pParseObj) && (findTokenSuccess = findTokenInString(pParseObj))) { if ((strlen(PARSEOBJ_GetTokenPtr(pParseObj)) == 1) && (PARSEOBJ_GetTokenPtr(pParseObj)[0] == CH_endOfNumArraySymbol)) { /* end of number array found */ done = 1; } else { int tokenScanIndex = 0; int tokenLen = strlen(PARSEOBJ_GetTokenPtr(pParseObj)); HP_UByte hexValue; if (pParseObj->tokenClass == E_HexArray) { if (!(tokenLen % 2)) { tokenScanIndex=0; while (ASSEMBLY_Continue(pParseObj) && (tokenScanIndex < tokenLen)) { if (isxdigit(PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex]) && isxdigit(PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex+1])) { hexValue = hexValueMap[PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex]] * 16; hexValue = hexValue + hexValueMap[PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex+1]]; /* output the data byte: */ HP_RawUByte(pStream, (HP_UByte) hexValue); } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } tokenScanIndex = tokenScanIndex + 2; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } else /* must be hex 32-bit array */ { int shiftCount; HP_UInt32 a32BitValue; if (!(tokenLen % 8)) { tokenScanIndex=0; shiftCount = 24; a32BitValue = 0; while (ASSEMBLY_Continue(pParseObj) && (tokenScanIndex < tokenLen)) { if (isxdigit(PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex]) && isxdigit(PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex+1])) { hexValue = hexValueMap[PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex]] * 16; hexValue = hexValue + hexValueMap[PARSEOBJ_GetTokenPtr(pParseObj)[tokenScanIndex+1]]; /* add byte to local 32-bit value holder */ a32BitValue = a32BitValue + (((HP_UInt32) hexValue) << shiftCount); if (!shiftCount) { if (PARSEOBJ_GetDataOrg(pParseObj) == HP_eBinaryLowByteFirst) { HP_RawUInt32(pStream, (HP_UInt32) a32BitValue); } else { HP_RawUInt32MSB(pStream, (HP_UInt32) a32BitValue); } a32BitValue = 0; shiftCount = 32; } shiftCount = shiftCount - 8; } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } tokenScanIndex = tokenScanIndex + 2; } } else { HP_SetErrorCode(pStream, HPERR_UnknownDataFormat); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } } } /* end of while loop */ if (ASSEMBLY_Continue(pParseObj) && (!findTokenSuccess) && (!done)) { /* lets try reading another string and loop again */ GetNextLine(pParseObj); } } while (ASSEMBLY_Continue(pParseObj) && (!done) && (!IS_EOF(pParseObj))); /* outer do-while loop */ } /* end of if statement just in front of do-while loop */ if (ASSEMBLY_Continue(pParseObj) && (done)) { /* data already output above, setup for next state */ /* if no errors: */ PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } } /* end of if to check for start of number array bracket */ else { HP_SetErrorCode(pStream, HPERR_MissingOpenBracket); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } /* end of if to check for number array */ } StdFuncReturnType ProcessOpOrDataId(ParseObjPtrType pParseObj) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); if (IS_OPERATOR(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is an operator.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif /* process operator here */ /* if operator processing went okay, do the * next line to set the next state */ HP_Operator(pStream, (HP_UInt16) PARSEOBJ_GetTokenInstance(pParseObj)); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else if (IS_DATA_ID(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is a data identifier.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningDataValues); } else if (IS_DATA_SOURCE_ID(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is a data source identifier.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningDataValues); } else if (IS_RAW_DATA_ID(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is a raw data identifier.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningDataValues); } else if (IS_HEX_ARRAY(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is a hex array identifier.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif ProcessHexData(pParseObj); } else { HP_SetErrorCode(pStream, HPERR_ExpectedOpOrDataId); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } StdFuncReturnType RecoverToOpOrDataId(ParseObjPtrType pParseObj) { int findTokenSuccess = 0; int done = 0; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); do /* outer do-while loop to get next string from input file if we run to */ /* the end of the string while scanning data */ { findTokenSuccess = 0; while ((!done) && (ASSEMBLY_Continue(pParseObj)) && (findTokenSuccess = findTokenInString(pParseObj))) { GetSymbolData(pParseObj); if (IS_OPERATOR(pParseObj) || IS_DATA_ID(pParseObj) || IS_HEX_ARRAY(pParseObj) || IS_DATA_SOURCE_ID(pParseObj) || IS_RAW_DATA_ID(pParseObj)) { done = 1; } } /* end of while loop */ if (ASSEMBLY_Continue(pParseObj) && (!findTokenSuccess) && (!done)) { /* lets try reading another string and loop again */ GetNextLine(pParseObj); } } while (ASSEMBLY_Continue(pParseObj) && (!done) && (!IS_EOF(pParseObj))); /* outer do-while loop */ if (done) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningAfterRecover); } else { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } StdFuncReturnType ParseAssembly( HP_StreamHandleType pStream, HP_pChar inFileName, PathListPtrType pPathList) { #define ASSEMBLY_FUNCTION 0 ParseObjPtrType pParseObj = 0; int findTokenSuccess = 0; int recoveryAttempts = 0; SrcStringPtrType pString = 0; FileStackPtrType pFileStack = 0; HP_pChar sprintfBuff = 0; if (HP_NoErrors(pStream)) { pParseObj = PARSEOBJ_NewParseObj(pStream, pPathList, MAX_LINE_LENGTH, ASSEMBLY_FUNCTION); sprintfBuff = STRING_NewString(MAX_LINE_LENGTH); if (!sprintfBuff) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } if (HP_NoErrors(pStream)) { MacroTablePtrType localMacroTable = NULL; pFileStack = PARSEOBJ_GetFileStack(pParseObj); pString = PARSEOBJ_GetStringPtr(pParseObj); /* read pointer to parsing string */ localMacroTable = MACRO_NewMacroTable(MAX_LOCAL_MACRO_ENTRIES); if (HP_NoErrors(pStream)) { FSTACK_PushFileStack(pParseObj, inFileName , inFileName, NULL, NOT_LOOPING, localMacroTable, 0, "r"); /* open the input file */ } if (localMacroTable && (!HP_NoErrors(pStream))) { /* open of input file failed */ MACRO_DeleteMacroTable(localMacroTable); } } if (HP_NoErrors(pStream)) { if (ASSEMBLY_Continue(pParseObj)) { /* main assembly parsing loop */ if (ASSEMBLY_Continue(pParseObj) && (!IS_EOF(pParseObj))) { while (PARSEOBJ_GetNextState(pParseObj) != STATEID_EndingAssembly) { /* set up current state to be doing next state */ PARSEOBJ_SetCurrentState(pParseObj, PARSEOBJ_GetNextState(pParseObj)); switch(PARSEOBJ_GetNextState(pParseObj)) { /* actually do next state */ case STATEID_ScanningOperatorOrDataId: findTokenSuccess = findTokenInFile(pParseObj); if (findTokenSuccess) { GetSymbolData(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { ProcessOpOrDataId(pParseObj); } } else { if ((!IS_EOF(pParseObj)) && ASSEMBLY_Continue(pParseObj)) { HP_SetErrorCode(pStream, HPERR_ExpectedOpOrDataId); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case STATEID_ScanningAfterRecover: ProcessOpOrDataId(pParseObj); break; case STATEID_ScanningDataValues: findTokenSuccess = findTokenInFile(pParseObj); if (findTokenSuccess) { GetDataValues(pParseObj); } break; case STATEID_ScanningAttributeId: findTokenSuccess = findTokenInFile(pParseObj); if (findTokenSuccess) { GetSymbolData(pParseObj); if (IS_ATTR_ID(pParseObj)) { #ifdef DEBUG_JETASM printf("%s is an attribute id.\n", PARSEOBJ_GetTokenPtr(pParseObj)); #endif /* process attribute id here */ /* check to see if we have to set data organization value */ if (PARSEOBJ_GetTokenInstance(pParseObj) == HP_DataOrg) { PARSEOBJ_SetDataOrg(pParseObj, PARSEOBJ_GetDataOrgBuff(pParseObj)); } HP_AttrId(pStream, (HP_UInt16) PARSEOBJ_GetTokenInstance(pParseObj)); if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); } else { FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } else { HP_SetErrorCode(pStream, HPERR_ExpectedAttrId); PARSEOBJ_SetNextState(pParseObj, STATEID_RecoveringFromSyntaxError); FSTACK_StopLooping(pFileStack); } } else { if (ASSEMBLY_Continue(pParseObj)) { HP_SetErrorCode(pStream, HPERR_ExpectedOpOrDataId); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case STATEID_RecoveringFromSyntaxError: { HP_SInt16 errorCode = HP_GetErrorCode(pStream); recoveryAttempts++; sprintf(sprintfBuff, "%s\n", pString); HP_LogError(sprintfBuff); sprintf(sprintfBuff, "^^ SYNTAX ERROR AT LINE# %ld IN FILE: ""%s"".\n", FSTACK_GetCurrentLineNumber(pFileStack), FSTACK_GetAliasNamePtr(pFileStack)); HP_LogError(sprintfBuff); sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); if (recoveryAttempts <= MAX_RECOVERIES) { HP_SetErrorCode(pStream, 0); RecoverToOpOrDataId(pParseObj); } else { HP_SetErrorCode(pStream, HPERR_TooManyRecoveryAttempts); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; default: HP_SetErrorCode(pStream, HPERR_IllegalAssemblerState); FSTACK_StopLooping(pFileStack); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } /* end of switch */ } /* end of while loop */ } } if (HP_GetErrorCount(pStream)) { HP_SInt16 errorCode = HP_GetErrorCode(pStream); if (errorCode) { if (pParseObj) { sprintf(sprintfBuff, "%s\n", pString); HP_LogError(sprintfBuff); } sprintf(sprintfBuff, "^^ ERROR AT LINE# %ld IN FILE: ""%s"".\n", FSTACK_GetCurrentLineNumber(pFileStack), FSTACK_GetAliasNamePtr(pFileStack)); HP_LogError(sprintfBuff); if (errorCode > 0) { sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); } else { sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); } } sprintf(sprintfBuff, "%d Error(s) Detected During Assembly.\n", HP_GetErrorCount(pStream)); HP_LogError(sprintfBuff); ASSEMBLY_ABORTED; } } else { HP_SInt16 errorCode = HP_GetErrorCode(pStream); sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); ASSEMBLY_ABORTED; } PARSEOBJ_DeleteParseObj(pParseObj); STRING_DeleteString(sprintfBuff); } else { HP_UByte localPrintBuff[MAX_PRINT_BUFF]; sprintf(localPrintBuff, "Protocol Library Errors Set Prior To Assembly.\n"); HP_LogError(localPrintBuff); ASSEMBLY_ABORTED; } #undef ASSEMBLY_FUNCTION } StdFuncReturnType PARSEOBJ_PrintEnumSymbols(ParseObjPtrType pParseObj, HP_UByte dataValueTag, HP_UByte attributeId) { /* print enumerated data values in disasembler format */ HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_pUByte outString = 0; SymbolTablePtrType pSymbolTable = PARSEOBJ_GetSymbolTable(pParseObj); HP_UInt32 dataValue = 0; int valueIsArray = 0; outString = STRING_NewString(MAX_DISASM_STRING); if (outString) { if (PARSEOBJ_GetExpectedDataLenType(pParseObj) == E_TokenLenArray) { valueIsArray = 1; } if (valueIsArray) { /* print array start bracket */ sprintf(outString, "%c ", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } { SymbolRecPtrType result; DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); /* check here to see if enum symbols are present for * this attribute id */ HP_UInt32 index = 0; HP_UInt32 count = PARSEOBJ_GetDataBuffIndex(pParseObj); for (index = 0; (index != count) && (ASSEMBLY_Continue(pParseObj)); index++) { HP_UByte basicType = actualTypeMap[HP_dataTagMap[dataValueTag]]; switch (basicType) { case E_BasicTypeUByte: dataValue = (HP_UInt32) ((HP_pUByte) pDataBuff)[index]; break; case E_BasicTypeSByte: dataValue = (HP_SInt32) ((HP_pUByte) pDataBuff)[index]; break; case E_BasicTypeUInt16: dataValue = (HP_UInt32) ((HP_pUInt16) pDataBuff)[index]; break; case E_BasicTypeSInt16: dataValue = (HP_SInt32) ((HP_pSInt16) pDataBuff)[index]; break; case E_BasicTypeUInt32: dataValue = (HP_UInt32) ((HP_pUInt32) pDataBuff)[index]; break; case E_BasicTypeSInt32: dataValue = (HP_SInt32) ((HP_pSInt32) pDataBuff)[index]; break; default: HP_LogError(HP_GetStreamErrorText(HPERR_ExpectedOpOrDataId)); HP_LogError("\n"); PARSEOBJ_PrintBadByte(pParseObj, dataValueTag); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } if (ASSEMBLY_Continue(pParseObj)) { result = FindDisAsmSymbol(pSymbolTable, E_DataValue, dataValue /* look for enum value */, attributeId); if (result) { PARSEOBJ_DisAsmRawOutput(pParseObj, result->symbol, strlen(result->symbol)); } else { /* error, enum symbol not found, just print number */ sprintf(outString, "%ld", dataValue); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_DisAsmRawOutput(pParseObj, " ", 1); } } if (!(ASSEMBLY_Continue(pParseObj))) { index = count; } } /* end of for */ } if (valueIsArray) { /* print array end bracket */ sprintf(outString, "%c ", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } STRING_DeleteString(outString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } StdFuncReturnType PARSEOBJ_PrintDataValues(ParseObjPtrType pParseObj, HP_UByte dataValueTag) { /* print data values in disasembler format */ #define MAX_DISASM_BYTEVAL_COUNT 8 /* for printing lines of byte arrays */ #define BYTE_DIGIT_SPACES 4 /* number of spaces needed to print each byte */ HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_pUByte outString = 0; HP_UByte byteBuff[MAX_DISASM_BYTEVAL_COUNT]; HP_UByte byteCount; int valueIsArray = 0; outString = STRING_NewString(MAX_DISASM_STRING); if (outString) { if (PARSEOBJ_GetExpectedDataLenType(pParseObj) == E_TokenLenArray) { valueIsArray = 1; } { DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); HP_UInt16 dataIndex = 0; HP_UInt16 count = (HP_UInt16) PARSEOBJ_GetDataBuffIndex(pParseObj); HP_UByte basicType = actualTypeMap[HP_dataTagMap[dataValueTag]]; if (valueIsArray) { /* print array start bracket */ if (basicType == E_BasicTypeUByte) { sprintf(outString, "%c\n", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { sprintf(outString, "%c ", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } } byteCount = 0; for (dataIndex = 0; (dataIndex != count) && ASSEMBLY_Continue(pParseObj); dataIndex++) { switch (basicType) { case E_BasicTypeUByte: if (valueIsArray) { sprintf(outString, "%3d ", (unsigned int) ((HP_pUByte) pDataBuff)[dataIndex]); } else { sprintf(outString, "%d ", (unsigned int) ((HP_pUByte) pDataBuff)[dataIndex]); } break; case E_BasicTypeSByte: if (valueIsArray) { sprintf(outString, "%3d ", (int) ((HP_pUByte) pDataBuff)[dataIndex]); } else { sprintf(outString, "%d ", (int) ((HP_pUByte) pDataBuff)[dataIndex]); } break; case E_BasicTypeUInt16: sprintf(outString, "%u ", ((HP_pUInt16) pDataBuff)[dataIndex]); break; case E_BasicTypeSInt16: sprintf(outString, "%d ", ((HP_pSInt16) pDataBuff)[dataIndex]); break; case E_BasicTypeUInt32: sprintf(outString, "%lu ", ((HP_pUInt32) pDataBuff)[dataIndex]); break; case E_BasicTypeSInt32: sprintf(outString, "%ld ", ((HP_pSInt32) pDataBuff)[dataIndex]); break; case E_BasicTypeReal32: sprintf(outString, "%f ", ((HP_pReal32) pDataBuff)[dataIndex]); break; default: HP_LogError(HP_GetStreamErrorText(HPERR_ExpectedOpOrDataId)); HP_LogError("\n"); PARSEOBJ_PrintBadByte(pParseObj, dataValueTag); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); if (valueIsArray && (basicType == E_BasicTypeUByte)) { byteBuff[byteCount++] = ((HP_pUByte) pDataBuff)[dataIndex]; if (!((dataIndex+1) % MAX_DISASM_BYTEVAL_COUNT)) { PARSEOBJ_DisAsmPrintAscii(pParseObj, byteBuff, byteCount); byteCount = 0; sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } } } /* end of for */ if (ASSEMBLY_Continue(pParseObj) && (valueIsArray) && (basicType == E_BasicTypeUByte) && (dataIndex % MAX_DISASM_BYTEVAL_COUNT)) { /* print the last ascii dump */ int spacesNeeded = ((MAX_DISASM_BYTEVAL_COUNT - (dataIndex % MAX_DISASM_BYTEVAL_COUNT)) * BYTE_DIGIT_SPACES); int spaceCount; /* do the next block to move to the right margin */ for (spaceCount = 0; spaceCount < spacesNeeded; spaceCount++) { outString[spaceCount] = ' '; outString[spaceCount+1] = '\0'; } PARSEOBJ_DisAsmRawOutput(pParseObj, outString, spaceCount); PARSEOBJ_DisAsmPrintAscii(pParseObj, byteBuff, byteCount); sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (ASSEMBLY_Continue(pParseObj) && valueIsArray) { /* print array end bracket */ if (basicType == E_BasicTypeUByte) { sprintf(outString, "%c\n", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { sprintf(outString, "%c ", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } } } STRING_DeleteString(outString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } #undef MAX_DISASM_BYTEVAL_COUNT #undef BYTE_DIGIT_SPACES } StdFuncReturnType PARSEOBJ_PrintPointValues(ParseObjPtrType pParseObj, HP_UInt32 numberOfBytes) { /* print embedded data points in disasembler format */ HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_pUByte outString = 0; HP_UByte byteCount; HP_UByte basicType = PARSEOBJ_GetPointType(pParseObj); HP_UByte dataOrg = PARSEOBJ_GetDataOrg(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_UByte mostSigByteFirstFlag = 1; HP_UInt32 numberOfValues = 0; outString = STRING_NewString(MAX_DISASM_STRING); if (outString) { { DataBufferPtrType pDataBuff = PARSEOBJ_GetDataBuffPtr(pParseObj); HP_UInt32 dataIndex = 0; sprintf(outString, "dataLength %ld\n", numberOfBytes); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); /* print assembler token for formatted embedded data */ switch (basicType) { case E_BasicTypeUByte: sprintf(outString, "ubyte_raw* "); numberOfValues = numberOfBytes; break; case E_BasicTypeSByte: sprintf(outString, "sbyte_raw* "); numberOfValues = numberOfBytes; break; case E_BasicTypeUInt16: sprintf(outString, "uint16_raw* "); numberOfValues = numberOfBytes / 2; break; case E_BasicTypeSInt16: sprintf(outString, "sint16_raw* "); numberOfValues = numberOfBytes / 2; break; case E_BasicTypeUInt32: sprintf(outString, "uint32_raw* "); numberOfValues = numberOfBytes / 4; break; case E_BasicTypeSInt32: sprintf(outString, "sint32_raw* "); numberOfValues = numberOfBytes / 4; break; case E_BasicTypeReal32: sprintf(outString, "real32_raw* "); numberOfValues = numberOfBytes / 4; break; default: /* error, should not get here */ break; } PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); if (dataOrg == HP_eBinaryLowByteFirst) { mostSigByteFirstFlag = 0; } /* print array start bracket */ sprintf(outString, "%c ", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); byteCount = 0; for (dataIndex = 0; (dataIndex != numberOfValues) && ASSEMBLY_Continue(pParseObj); dataIndex++) { switch (basicType) { case E_BasicTypeUByte: { HP_UByte aByte = FSTACK_NextByte(pFileStack); sprintf(outString, "%d ", (unsigned int) aByte); } break; case E_BasicTypeSByte: { HP_SInt16 anInt = FSTACK_NextByte(pFileStack); if (anInt > 127) anInt = anInt | 0xff00; sprintf(outString, "%d ", (int) anInt); } break; case E_BasicTypeUInt16: sprintf(outString, "%u ", PARSEOBJ_GetUInt16(pParseObj, mostSigByteFirstFlag)); break; case E_BasicTypeSInt16: sprintf(outString, "%d ", (HP_SInt16) PARSEOBJ_GetUInt16(pParseObj, mostSigByteFirstFlag)); break; case E_BasicTypeUInt32: sprintf(outString, "%lu ", PARSEOBJ_GetUInt32(pParseObj, mostSigByteFirstFlag)); break; case E_BasicTypeSInt32: sprintf(outString, "%ld ", (HP_SInt32) PARSEOBJ_GetUInt32(pParseObj, mostSigByteFirstFlag)); break; case E_BasicTypeReal32: sprintf(outString, "%f ", (HP_Real32) PARSEOBJ_GetReal32(pParseObj, mostSigByteFirstFlag)); break; default: /* error, should never get here */ break; } if (ASSEMBLY_Continue(pParseObj)) { PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } } /* end of for */ if (ASSEMBLY_Continue(pParseObj)) { /* print array end bracket */ sprintf(outString, "%c\n\n", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } STRING_DeleteString(outString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } #undef MAX_DISASM_BYTEVAL_COUNT #undef BYTE_DIGIT_SPACES } StdFuncReturnType PARSEOBJ_ProcessAttribute(ParseObjPtrType pParseObj, HP_UByte dataTypeTag) { HP_UByte attributeId; SymbolTablePtrType pSymbolTable = PARSEOBJ_GetSymbolTable(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_pUByte outString = 0; SymbolRecPtrType result = 0; DisAsmGetDataValues(pParseObj, dataTypeTag); if (ASSEMBLY_Continue(pParseObj)) { outString = STRING_NewString(MAX_DISASM_STRING); if (outString) { /* read the Attribute Id */ attributeId = PARSEOBJ_GetAttributeId(pParseObj); if (ASSEMBLY_Continue(pParseObj)) { SymbolRecPtrType result; /* check here to see if enum symbols are present for * this attribute id */ result = FindDisAsmSymbol(pSymbolTable, E_DataValue, 0 /* look for enum zero */, attributeId); if (result) { /* enumeration zero found in symbol table */ /* Note: any attribute having enumerations must have * a zero entry (even if its a dummy symbol) so that the * disassembler will function properly */ PARSEOBJ_PrintEnumSymbols(pParseObj, dataTypeTag, attributeId); } else { PARSEOBJ_PrintDataValues(pParseObj, dataTypeTag); } } /* print the attribute id symbol */ if (ASSEMBLY_Continue(pParseObj)) { result = FindDisAsmSymbol(pSymbolTable, E_AttrId, attributeId, HP_AttributeIdSymbol); if (result) { sprintf(outString, "%s\n", result->symbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { HP_SetErrorCode(pStream, HPERR_SymbolMissing); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } #if 0 { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); sprintf(outString, "\nbyte count=%d\n", FSTACK_GetByteCount(pFileStack)); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } #endif } STRING_DeleteString(outString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } } } StdFuncReturnType ProcessNextByte(ParseObjPtrType pParseObj) { #define HEX_DIGIT_SPACES 3 /* the number of spaces each hex digit * occupies */ HP_UByte thisTag; int tagType; SymbolRecPtrType result = 0; FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); SymbolTablePtrType pSymbolTable = PARSEOBJ_GetSymbolTable(pParseObj); HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); HP_pChar outString = 0; HP_UByte hexBuff[MAX_DISASM_HEX_COUNT]; HP_UByte hexCount; HP_SInt16 intByteBuff; outString = STRING_NewString(MAX_DISASM_STRING); if (outString) { if ((intByteBuff = FSTACK_NextByte(pFileStack)) == EOF) { PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else { thisTag = (HP_UByte) intByteBuff; if ((thisTag > 0) && (thisTag < HP_MaxNumberOfTags)) { tagType = HP_tagValueMap[thisTag]; switch (tagType) { case E_DisAsm_Operator: { PARSEOBJ_IncrementTagStats(pParseObj, thisTag); if (!HP_pointOperatorMap[thisTag]) { /* if not an operator that reads points from * the data stream, ignore the point type * for future embedded data */ PARSEOBJ_SetPointType(pParseObj, E_NoPointType); } result = FindDisAsmSymbol(pSymbolTable, E_Operator, thisTag, HP_OperatorSymbol); if (result) { HP_UInt32 operatorCount = PARSEOBJ_GetOperatorCount(pParseObj) + 1; nextOpCount = operatorCount; PARSEOBJ_SetOperatorCount(pParseObj, operatorCount); if (!operationTagged && TagOperations) sprintf(outString, "//#%06X, %06X\n// Operator Position: %ld\n", pFileStack->byteCountArray[(FSTACK_GetNumOpenFiles(pFileStack))]-1, operatorCount, operatorCount); else sprintf(outString, "// Operator Position: %ld\n", operatorCount); operationTagged=0; PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); sprintf(outString, "%s\n\n", result->symbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { PARSEOBJ_PrintBadByte(pParseObj, thisTag); HP_SetErrorCode(pStream, HPERR_SymbolMissing); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case E_DisAsm_DataVal: { PARSEOBJ_IncrementTagStats(pParseObj, thisTag); result = FindDisAsmSymbol(pSymbolTable, E_DataId, HP_dataTagMap[thisTag], HP_DataSymbol); if (result) { if (!operationTagged && TagOperations) { sprintf(outString, "//#%06X, %06X\n%s ", pFileStack->byteCountArray[(FSTACK_GetNumOpenFiles(pFileStack))]-1, PARSEOBJ_GetOperatorCount(pParseObj) + 1, result->symbol); operationTagged=1; } else sprintf(outString, "%s ", result->symbol); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } else { PARSEOBJ_PrintBadByte(pParseObj, thisTag); HP_SetErrorCode(pStream, HPERR_SymbolMissing); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } PARSEOBJ_ProcessAttribute(pParseObj, thisTag); } break; case E_DisAsm_Escape: case E_DisAsm_PJL_At: { HP_UByte aByte = 0; HP_UInt16 count = 1; HP_SInt16 intByteBuff = 0; HP_UInt16 done = 0; HP_UByte endingCharacter = ' '; if (tagType == E_DisAsm_Escape) { /* must be UEL */ sprintf(outString, "// UEL Should Follow: \n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); PARSEOBJ_SetOperatorCount(pParseObj, 0); /* set operator position to zero */ endingCharacter = 'X'; } else { /* must be PJL statement */ sprintf(outString, "// PJL Should Follow: \n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); endingCharacter = '\n'; } sprintf(outString, "hex_raw* %c\n", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); hexCount = 0; hexBuff[hexCount++] = aByte = thisTag; /* make the escape the first byte */ count = 1; sprintf(outString, "%02x ", (unsigned int) aByte); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); while ((ASSEMBLY_Continue(pParseObj)) && (!done) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF)) { aByte = (HP_UByte) intByteBuff; hexBuff[hexCount++] = aByte; sprintf(outString, "%02x ", (unsigned int) aByte); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); count++; if (!(count % MAX_DISASM_HEX_COUNT)) { PARSEOBJ_DisAsmPrintAscii(pParseObj, hexBuff, hexCount); hexCount = 0; sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (aByte == endingCharacter) { /* at end of UEL or PJL statement, we're done */ done = 1; } } if (ASSEMBLY_Continue(pParseObj) && (count % MAX_DISASM_HEX_COUNT)) { /* print the last ascii dump */ int spacesNeeded = ((MAX_DISASM_HEX_COUNT - (count % MAX_DISASM_HEX_COUNT)) * HEX_DIGIT_SPACES); int index; /* do the next block to move to right margin */ for (index = 0; index < spacesNeeded; index++) { outString[index] = ' '; outString[index+1] = '\0'; } PARSEOBJ_DisAsmRawOutput(pParseObj, outString, index); PARSEOBJ_DisAsmPrintAscii(pParseObj, hexBuff, hexCount); sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (ASSEMBLY_Continue(pParseObj)) { /* output ending bracket */ sprintf(outString, "%c\n\n", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (ASSEMBLY_Continue(pParseObj) && FSTACK_EndOfFile(pFileStack)) { PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } break; case E_DisAsm_BindingId: { HP_UByte aByte = 0; HP_UInt16 count; HP_SInt16 intByteBuff = 0; HP_UInt16 done = 0; sprintf(outString, "// Stream Header Should Follow: \n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); sprintf(outString, "hex_raw* %c\n", CH_startOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); count = 0; hexCount = 0; hexBuff[hexCount++] = aByte = thisTag; /* make the escape the first byte */ count = 1; sprintf(outString, "%02x ", (unsigned int) aByte); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); while ((ASSEMBLY_Continue(pParseObj)) && (!done) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF)) { aByte = (HP_UByte) intByteBuff; hexBuff[hexCount++] = aByte; sprintf(outString, "%02x ", (unsigned int) aByte); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); count++; if (!(count % MAX_DISASM_HEX_COUNT)) { PARSEOBJ_DisAsmPrintAscii(pParseObj, hexBuff, hexCount); hexCount = 0; sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (aByte == '\n') { /* at end of binding id, we're done */ done = 1; } } if (ASSEMBLY_Continue(pParseObj) && (count % MAX_DISASM_HEX_COUNT)) { /* print the last ascii dump */ int spacesNeeded = ((MAX_DISASM_HEX_COUNT - (count % MAX_DISASM_HEX_COUNT)) * HEX_DIGIT_SPACES); int index; /* do the next block to move to right margin */ for (index = 0; index < spacesNeeded; index++) { outString[index] = ' '; outString[index+1] = '\0'; } PARSEOBJ_DisAsmRawOutput(pParseObj, outString, index); PARSEOBJ_DisAsmPrintAscii(pParseObj, hexBuff, hexCount); sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (FSTACK_EndOfFile(pFileStack)) { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else if (ASSEMBLY_Continue(pParseObj)) { /* output ending bracket */ sprintf(outString, "%c\n\n", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } break; case E_DisAsm_EmbeddedDataByte: case E_DisAsm_EmbeddedData: { HP_UInt32 byteLength; if (tagType == E_DisAsm_EmbeddedDataByte) { /* a byte embedded data tag */ byteLength = FSTACK_NextByte(pFileStack); } else { /* a 32-bit embedded data tag */ byteLength = PARSEOBJ_GetUInt32(pParseObj, PARSEOBJ_GetMostSigFirstFlag(pParseObj)); } PARSEOBJ_IncrementTagStats(pParseObj, thisTag); if (TagOperations) sprintf(outString, "//#%06X - Embedded Data Should Follow: \n", pFileStack->byteCountArray[(FSTACK_GetNumOpenFiles(pFileStack))]-1); else sprintf(outString, "// Embedded Data Should Follow: \n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); if (PARSEOBJ_GetPointType(pParseObj) == E_NoPointType) { if (ASSEMBLY_Continue(pParseObj)) { HP_UInt32 count = 0; HP_SInt16 intByteBuff = 0; if (tagType == E_DisAsm_EmbeddedDataByte) { sprintf(outString, "dataLengthByte %ld\nhex_raw* %c\n", byteLength, CH_startOfNumArraySymbol); } else { sprintf(outString, "dataLength %ld\nhex_raw* %c\n", byteLength, CH_startOfNumArraySymbol); } PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); while ((count < byteLength) && (ASSEMBLY_Continue(pParseObj)) && ((intByteBuff = FSTACK_NextByte(pFileStack)) != EOF)) { count++; sprintf(outString, "%02x ", (unsigned int) intByteBuff); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); if (!(count % MAX_DISASM_HEX_COUNT)) { sprintf(outString, "\n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } if (count != byteLength) { HP_SetErrorCode(pStream, HPERR_BeyondEOF); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } else if (ASSEMBLY_Continue(pParseObj)) { /* output ending bracket */ sprintf(outString, "\n%c\n\n", CH_endOfNumArraySymbol); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } } else { PARSEOBJ_PrintPointValues(pParseObj, byteLength); } } break; default: /* DisAsm_Undefined */ { HP_LogError(HP_GetStreamErrorText(HPERR_ExpectedOpOrDataId)); HP_LogError("\n"); PARSEOBJ_PrintBadByte(pParseObj, thisTag); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } break; } } else { HP_LogError(HP_GetStreamErrorText(HPERR_ExpectedOpOrDataId)); HP_LogError("\n"); PARSEOBJ_PrintBadByte(pParseObj, thisTag); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); } } STRING_DeleteString(outString); } else { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); PARSEOBJ_SetNextState(pParseObj,STATEID_EndingAssembly); } #undef HEX_DIGIT_SPACES } StdFuncReturnType PARSEOBJ_PrintStats(ParseObjPtrType pParseObj, DisAsmEnumType disAsmEnum) { TagStatPtrType pTagStats = 0; AttrStatPtrType pAttrStats = 0; HP_pChar outString = 0; HP_StreamHandleType pStream = PARSEOBJ_GetLibrary(pParseObj); SymbolRecPtrType result = 0; SymbolTablePtrType pSymbolTable = PARSEOBJ_GetSymbolTable(pParseObj); FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); HP_UInt16 statTokenCounter = 1; outString = STRING_NewString(MAX_DISASM_STRING); if (outString && HP_NoErrors(pStream) && (pTagStats = PARSEOBJ_GetTagStatPtr(pParseObj)) && (pAttrStats = PARSEOBJ_GetAttrStatPtr(pParseObj))) { int index; HP_UByte tagType; if (disAsmEnum == eDisAsmAndStat) { sprintf(outString, "// PCL XL Stream Operator and Data Statistics: \n"); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } if (HP_NoErrors(pStream)) { /* print the file statistics */ if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { sprintf(outString, "//, "); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } if (disAsmEnum == eDisAsmCoverage) { sprintf(outString, "000000 %-25s %06ld\n", "fileSize", FSTACK_GetByteCount(pFileStack)); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { sprintf(outString, "fileSize, %-25s, %06ld\n", FSTACK_GetFileNamePtr(pFileStack), FSTACK_GetByteCount(pFileStack)); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } /* print operator statistics */ for (index = 0; index < HP_MaxNumberOfTags && HP_NoErrors(pStream); index++) { tagType = HP_tagValueMap[index]; switch (tagType) { case E_DisAsm_Operator: { result = FindDisAsmSymbol(pSymbolTable, E_Operator, index, HP_OperatorSymbol); if (result) { if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { sprintf(outString, "//, "); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } if (disAsmEnum == eDisAsmCoverage) { /* print token with unique line # */ sprintf(outString, "%06u %-25s %06ld\n", statTokenCounter, result->symbol, pTagStats[index]); statTokenCounter++; PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { /* print normal stat line */ sprintf(outString, "opStat, %-25s, %-6ld\n", result->symbol, pTagStats[index]); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } else { sprintf(outString, "Error... No Operator Symbol. Tag Value = %02x (hex). Count=%ld\n", index, pTagStats[index]); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } break; default: break; } /* end of switch */ } /* end of for */ /* print attribute id statistics */ for (index = 0; index < HP_MaxNumberOfAttrs && HP_NoErrors(pStream); index++) { result = FindDisAsmSymbol(pSymbolTable, E_AttrId, index, HP_AttributeIdSymbol); if (result) { if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { sprintf(outString, "//, "); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } if (disAsmEnum == eDisAsmCoverage) { /* print token with unique line # */ sprintf(outString, "%06u %-25s %06ld\n", statTokenCounter, result->symbol, pAttrStats[index]); statTokenCounter++; PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { sprintf(outString, "attrStat, %-25s, %-6ld\n", result->symbol, pAttrStats[index]); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } } /* end of for */ /* print data tag usage statistics */ for (index = 0; index < HP_MaxNumberOfTags && HP_NoErrors(pStream); index++) { tagType = HP_tagValueMap[index]; switch (tagType) { case E_DisAsm_DataVal: { result = FindDisAsmSymbol(pSymbolTable, E_DataId, HP_dataTagMap[index], HP_DataSymbol); if (result) { if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { sprintf(outString, "//, "); PARSEOBJ_DisAsmRawOutput(pParseObj, outString, strlen(outString)); } if (disAsmEnum == eDisAsmCoverage) { /* print token with unique line # */ sprintf(outString, "%06u %-25s %06ld\n", statTokenCounter, result->symbol, pTagStats[index]); statTokenCounter++; PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } else { sprintf(outString, "dataStat, %-25s, %ld\n", result->symbol, pTagStats[index]); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } else { sprintf(outString, "Error... No Data Symbol. Tag Value = %02x (hex). Count=%ld\n", index, pTagStats[index]); PARSEOBJ_DisAsmLineOutput(pParseObj, outString, strlen(outString)); } } break; default: break; } /* end of switch */ } /* end of for */ } if (outString) { STRING_DeleteString(outString); } } StdFuncReturnType ParseStream(HP_StreamHandleType pStream, HP_pChar inFileName, PathListPtrType pPathList, DisAsmEnumType disAsmEnum) { #define DISASSEMBLY_FUNCTION 1 ParseObjPtrType pParseObj = 0; int findTokenSuccess = 0; int recoveryAttempts = 0; SrcStringPtrType pString = 0; HP_pChar sprintfBuff = 0; if (HP_NoErrors(pStream)) { pParseObj = PARSEOBJ_NewParseObj(pStream, pPathList, MAX_LINE_LENGTH, DISASSEMBLY_FUNCTION); sprintfBuff = STRING_NewString(MAX_DISASM_STRING); if (!sprintfBuff) { HP_SetErrorCode(pStream, HPERR_AsmOutOfMemory); } if (HP_NoErrors(pStream)) { FSTACK_PushFileStack(pParseObj, inFileName , inFileName, NULL, NOT_LOOPING, NO_LOCAL_MACRO_TABLE, 0, "rb"); /* open the input file */ if (ASSEMBLY_Continue(pParseObj)) { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); /* main Disassembly parsing loop */ if (ASSEMBLY_Continue(pParseObj) && (1/*!IS_EOF(pParseObj)*/)) { if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { PARSEOBJ_SetNextState(pParseObj, STATEID_ScanningOperatorOrDataId); sprintf(sprintfBuff, "// Disassembler Input File Name = %s\n\n", inFileName); PARSEOBJ_DisAsmLineOutput(pParseObj, sprintfBuff, strlen(sprintfBuff)); } else { PARSEOBJ_SetNextState(pParseObj, STATEID_ParseNoPrint); } while ((PARSEOBJ_GetNextState(pParseObj) != STATEID_EndingAssembly) && (!FSTACK_EndOfFile(pFileStack))) { /* set up current state to be doing next state */ PARSEOBJ_SetCurrentState(pParseObj, PARSEOBJ_GetNextState(pParseObj)); switch (PARSEOBJ_GetCurrentState(pParseObj)) { case STATEID_ScanningOperatorOrDataId: case STATEID_ParseNoPrint: { ProcessNextByte(pParseObj); } break; default: HP_SetErrorCode(pStream, HPERR_IllegalAssemblerState); PARSEOBJ_SetNextState(pParseObj, STATEID_EndingAssembly); break; } /* end of switch */ } /* end of while loop */ } } if (HP_GetErrorCount(pStream)) { HP_SInt16 errorCode = HP_GetErrorCode(pStream); if (errorCode) { if (errorCode > 0) { sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); } else { sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); } } sprintf(sprintfBuff, "%d Error(s) Detected During Disassembly.\n", HP_GetErrorCount(pStream)); HP_LogError(sprintfBuff); DISASSEMBLY_ABORTED; } else { FileStackPtrType pFileStack = PARSEOBJ_GetFileStack(pParseObj); if ((disAsmEnum != eDisAsmStatOnly) && (disAsmEnum != eDisAsmCoverage)) { /* print out the file size stats */ sprintf(sprintfBuff, "\n// Input File Size = %ld bytes\n", FSTACK_GetByteCount(pFileStack)); HP_RawUByteArray(pStream, sprintfBuff, strlen(sprintfBuff)); } if (disAsmEnum != eDisAsmOnly) { PARSEOBJ_SetCurrentState(pParseObj, STATEID_PrintingStats); PARSEOBJ_PrintStats(pParseObj, disAsmEnum); } } } else { HP_SInt16 errorCode = HP_GetErrorCode(pStream); sprintf(sprintfBuff, "%s (code=%d).\n", HP_GetStreamErrorText(errorCode), errorCode); HP_LogError(sprintfBuff); DISASSEMBLY_ABORTED; } PARSEOBJ_DeleteParseObj(pParseObj); STRING_DeleteString(sprintfBuff); } else { HP_UByte localPrintBuff[MAX_PRINT_BUFF]; sprintf(localPrintBuff, "Protocol Library Errors Set Prior To Disassembly.\n"); HP_LogError(localPrintBuff); DISASSEMBLY_ABORTED; } #undef DISASSEMBLY_FUNCTION } StdFuncReturnType printDoc(void) { unsigned int symbolIndex = 0; HP_pUByte pTempString = 0; HP_UByte printfString[MAX_PRINT_BUFF]; HP_UByte sprintfBuff[MAX_PRINT_BUFF]; HP_UInt16 lastTokenClass = 0; sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "jetasm(1)\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "NAME\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " jetasm\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "DESCRIPTION\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " This is the PCL XL Stream Assembler/Disassembler. The purpose of \n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " \'jetasm\' is to create or disassemble a binary stream.\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " The format of operators and attribute lists may be found in\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " the PCL XL Feature Reference or Technical Reference Manual.\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " The following is a Quick Reference Guide to the Assembler. See the\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, " PCL XL Stream Assembler User Manual for more detailed information.\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "Command Line Symbol", "Symbol Description"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "------------------------", "-----------------------------------"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "[]", "Input File Name (stdin default for assembly)."); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "[-man | -h | -?]", "Print the Command Line Usage and Man Page."); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "[-d | -ds | -s ]", "Disassemble without/with/withonly stats."); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "[-o ]", "Output File Name (default is \"jetasm.out\" for"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "assembly or \"stdout\" for disassembly)."); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s %d paths.\n", "[-I ...]", "Define Include File Paths: max is", MAX_PATHS); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "[-cover]", "Print stats compatible with \'jetcover\' utility."); HP_LogMsg(sprintfBuff); for (symbolIndex = 0; symbolIndex < DEFAULT_SYMBOL_COUNT; symbolIndex++) { if (defaultSymbolTable[symbolIndex].tokenClass != lastTokenClass) { HP_pUByte pSymbolNameHeading = 0; HP_pUByte pSymbolDescHeading = 0; switch (defaultSymbolTable[symbolIndex].tokenClass) { case E_SymbolNotFound: break; case E_Operator: pSymbolNameHeading = "Operator Name"; pSymbolDescHeading = "Operator Tag Value"; break; case E_AttrId: pSymbolNameHeading = "Attribute Identifier"; pSymbolDescHeading = "Attribute Id Number"; break; case E_DataSourceId: case E_DataId: if ((defaultSymbolTable[symbolIndex].tokenInstance == E_ActualEmbeddedDataPrefix) || (defaultSymbolTable[symbolIndex].tokenInstance == E_ActualEmbeddedDataPrefixByte)) { pSymbolNameHeading = "Embedded Data Token"; pSymbolDescHeading = "Embedded Data Token Description"; } else { pSymbolNameHeading = "Data Id Name"; pSymbolDescHeading = "Data Id Type"; } break; case E_DataValue: pSymbolNameHeading = "Enumerated Value Name"; pSymbolDescHeading = "Value, Attribute Name"; break; case E_RawDataId: pSymbolNameHeading = "Special Data Id"; pSymbolDescHeading = "Special Data Id Description"; break; case E_HexArray: /* the hex array headings reuse the ones * printed for E_RawDataId */ case E_Hex32Array: default: pSymbolNameHeading = 0; pSymbolDescHeading = 0; break; } if (pSymbolNameHeading) { sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); if (pSymbolDescHeading) { sprintf(sprintfBuff, "%-26s %s\n", pSymbolNameHeading, pSymbolDescHeading); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "---------------------", "-----------------------------------"); HP_LogMsg(sprintfBuff); } else { sprintf(sprintfBuff, "%-26s\n", pSymbolNameHeading); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s\n", "---------------------"); HP_LogMsg(sprintfBuff); } lastTokenClass = defaultSymbolTable[symbolIndex].tokenClass; } } switch (defaultSymbolTable[symbolIndex].tokenClass) { case E_SymbolNotFound: pTempString = 0; break; case E_Operator: sprintf(printfString, "%02x (hex), %3d (decimal)", (unsigned int) defaultSymbolTable[symbolIndex].tokenInstance, (unsigned int) defaultSymbolTable[symbolIndex].tokenInstance); pTempString = printfString; break; case E_AttrId: sprintf(printfString, "%02x (hex), %3d (decimal)", (unsigned int) defaultSymbolTable[symbolIndex].tokenInstance, (unsigned int) defaultSymbolTable[symbolIndex].tokenInstance); pTempString = printfString; break; case E_DataId: if (defaultSymbolTable[symbolIndex].tokenInstance == E_ActualEmbeddedDataPrefix) { pTempString = "usage: dataLength "; } else if (defaultSymbolTable[symbolIndex].tokenInstance == E_ActualEmbeddedDataPrefixByte) { pTempString = "usage: dataLengthByte "; } else if ((defaultSymbolTable[symbolIndex].tokenInstance >= ARRAY_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= ARRAY_END)) { int numValues = 0; if ((defaultSymbolTable[symbolIndex].tokenInstance >= BASIC_ARRAY_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= BASIC_ARRAY_END)) { numValues = 1; } sprintf(printfString, "Array Data: %d Data Value(s) Per Element", numValues); pTempString = printfString; } else { int numValues = 0; if ((defaultSymbolTable[symbolIndex].tokenInstance >= SINGLE_ELEMENT_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= SINGLE_ELEMENT_END)) { numValues = 1; } else if ((defaultSymbolTable[symbolIndex].tokenInstance >= XY_ELEMENT_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= XY_ELEMENT_END)) { numValues = 2; } else if ((defaultSymbolTable[symbolIndex].tokenInstance >= BOX_ELEMENT_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= BOX_ELEMENT_END)) { numValues = 4; } sprintf(printfString, "Fixed Data: %d Data Value(s)", numValues); pTempString = printfString; } break; case E_DataValue: { unsigned int attributeIndex; unsigned char foundEnumsAttribute = 0; for (attributeIndex = 0; (attributeIndex < DEFAULT_SYMBOL_COUNT) && (!foundEnumsAttribute); attributeIndex ++) { if ((defaultSymbolTable[attributeIndex].tokenExtension == HP_AttributeIdSymbol) && (defaultSymbolTable[attributeIndex].tokenInstance == defaultSymbolTable[symbolIndex].tokenExtension)) { sprintf(printfString, "%lu, %s", (HP_UInt32) defaultSymbolTable[symbolIndex].tokenInstance, (char *) defaultSymbolTable[attributeIndex].symbol); pTempString = printfString; foundEnumsAttribute = 1; } } if (!foundEnumsAttribute) { sprintf(printfString, "%lu", (HP_UInt32) defaultSymbolTable[symbolIndex].tokenInstance); pTempString = printfString; } } break; case E_HexArray: pTempString = "Prefix For Hex Array (Raw 8-bit values)"; break; case E_Hex32Array: pTempString = "Prefix For Hex Array (Raw 32-bit values)"; break; case E_RawDataId: pTempString = "Prefix For Raw Data Array"; break; case E_DataSourceId: if ((defaultSymbolTable[symbolIndex].tokenInstance >= ARRAY_START) && (defaultSymbolTable[symbolIndex].tokenInstance <= ARRAY_END)) { pTempString = "Data Source Array Identifier"; } else { pTempString = "Data Source Identifier"; } break; default: pTempString = 0; break; } GlobalSymbolCount = symbolIndex; if (strstr("PassThrough", (const char *)defaultSymbolTable[symbolIndex].symbol)) { pTempString = 0; } if (pTempString) { sprintf(sprintfBuff, "%-26s %s\n", defaultSymbolTable[symbolIndex].symbol, pTempString); HP_LogMsg(sprintfBuff); } } /* end of for */ sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "Macro Symbols", "Macro Description"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "---------------------", "-----------------------------------"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$include", "$include OR "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "$include \"filename\""); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$include_raw", "$include_raw OR "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "$include_raw \"filename\""); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$define", "$define "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "start with alpha for globals"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "start with '%' for locals"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "//", "// comment through end of line"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$if", "$if "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// do until $endif if value non-zero"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$ifnot", "$ifnot "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// do through $endif if value zero"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$loop", "$loop "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// do through $endloop while value non-zero"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$loopnot", "$loopnot "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// do through $endloop while value zero"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$calc", "$calc = "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "where is: +, -, *, /, mod"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", " ==, !=, <=, >=, <, or >"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$calc", "$calc = "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "where is: trunc, round, -"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$string", "$string = "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "where is: +, ==, !=, <=, >=, <, or >"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$beginsub", "$beginsub "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "begin definition of a subroutine"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "where must begin with alpha"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$endsub", "end subroutine definition"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$execsub", "$execsub ... "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "execute subroutine by name where "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "... are any constants or macros passed"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "as parameters to the subroutine"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$stop", "stop assembly immediately"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$abort", "abort assembly immediately"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "sends abort message to stderr"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$input", "$input "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// prompt for user input to macro name"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$line", "print line #, macro values and text thru end-of-line"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$print", "print macro values and text thru end-of-line"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$highByteFirst", "set embedded data tokens for high byte first"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "(i.e. sint16_source*, uint32_raw*, etc.)"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "$lowByteFirst", "set embedded data tokens for low byte first"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "(i.e. sint16_source*, uint32_raw*, etc.)"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); /* sprintf(sprintfBuff, "%-26s %s\n", "$escape", "$escape "); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "// call HP_EscapeMacro function"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); */ sprintf(sprintfBuff, "%-26s %s\n", "Misc. Concepts", "Description"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "---------------------", "-----------------------------------"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "character array", "Array Format: (ascii characters)"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "numeric array", "Array Format: [num1 num2 ... numN]"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "hex data array", "Array Format: hex_raw* [two-digit hex values]"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "subroutine parameters", "parameters are passed as local subroutine"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "macros accessed as %1, %2, %3, ...,%N"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", "parameter count", "number of parameters passed to subroutine may"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "%-26s %s\n", " ", "be accessed through local %ParamCount macro"); HP_LogMsg(sprintfBuff); sprintf(sprintfBuff, "\n"); HP_LogMsg(sprintfBuff); }