/* @(#) pf_text.c 98/01/26 1.3 */
/***************************************************************
** Text Strings for Error Messages
** For PForth based on 'C'
** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
** The pForth software code is dedicated to the public domain,
** and any third party may reproduce, distribute and modify
** the pForth software code or any derivative works thereof
** without any compensation or license. The pForth software
** code is provided on an "as is" basis without any warranty
** of any kind, including, without limitation, the implied
** warranties of merchantability and fitness for a particular
** purpose and their equivalents under the laws of any jurisdiction.
****************************************************************
** 19970702 PLB Fixed ConvertNumberToText for unsigned numbers.
** 19980522 PLB Expand PAD for ConvertNumberToText so "-1 binary .s" doesn't crash.
***************************************************************/
** Define array of error messages.
** These are defined in one place to make it easier to translate them.
/***************************************************************/
void pfReportError( const char *FunctionName
, Err ErrCode
)
case PF_ERR_NO_MEM
& 0xFF:
s
= "insufficient memory"; break;
case PF_ERR_TOO_BIG
& 0xFF:
s
= "data chunk too large"; break;
case PF_ERR_NUM_PARAMS
& 0xFF:
s
= "incorrect number of parameters"; break;
case PF_ERR_OPEN_FILE
& 0xFF:
s
= "could not open file"; break;
case PF_ERR_WRONG_FILE
& 0xFF:
s
= "wrong type of file format"; break;
case PF_ERR_BAD_FILE
& 0xFF:
s
= "badly formatted file"; break;
case PF_ERR_READ_FILE
& 0xFF:
s
= "file read failed"; break;
case PF_ERR_WRITE_FILE
& 0xFF:
s
= "file write failed"; break;
case PF_ERR_CORRUPT_DIC
& 0xFF:
s
= "corrupted dictionary"; break;
case PF_ERR_NOT_SUPPORTED
& 0xFF:
s
= "not supported in this version"; break;
case PF_ERR_VERSION_FUTURE
& 0xFF:
s
= "version from future"; break;
case PF_ERR_VERSION_PAST
& 0xFF:
s
= "version is obsolete. Rebuild new one."; break;
case PF_ERR_COLON_STACK
& 0xFF:
s
= "stack depth changed between : and ; . Probably unbalanced conditional"; break;
case PF_ERR_HEADER_ROOM
& 0xFF:
s
= "no room left in header space"; break;
case PF_ERR_CODE_ROOM
& 0xFF:
s
= "no room left in code space"; break;
case PF_ERR_NO_SHELL
& 0xFF:
s
= "attempt to use names in forth compiled with PF_NO_SHELL"; break;
case PF_ERR_NO_NAMES
& 0xFF:
s
= "dictionary has no names"; break;
case PF_ERR_OUT_OF_RANGE
& 0xFF:
s
= "parameter out of range"; break;
case PF_ERR_ENDIAN_CONFLICT
& 0xFF:
s
= "endian-ness of dictionary does not match code"; break;
case PF_ERR_FLOAT_CONFLICT
& 0xFF:
s
= "float support mismatch between .dic file and code"; break;
case PF_ERR_CELL_SIZE_CONFLICT
& 0xFF:
s
= "cell size mismatch between .dic file and code"; break;
s
= "unrecognized error code!"; break;
void pfReportThrow( ThrowCode code
)
case THROW_STACK_OVERFLOW
:
s
= "Stack overflow!"; break;
case THROW_STACK_UNDERFLOW
:
s
= "Stack underflow!"; break;
s
= "Executing a compile-only word!"; break;
case THROW_FLOAT_STACK_UNDERFLOW
:
s
= "Float Stack underflow!"; break;
case THROW_UNDEFINED_WORD
:
s
= "Undefined word!"; break;
s
= "Conditional control structure mismatch!"; break;
s
= "Stack depth changed between : and ; . Probably unbalanced conditional!"; break;
s
= "Not a DEFERred word!"; break;
s
= "Unrecognized throw code!"; break;
MSG_NUM_D("THROW code = ", code
);
/**************************************************************
** Copy a Forth String to a 'C' string.
char *ForthStringToC( char *dst
, const char *FString
)
pfCopyMemory( dst
, FString
+1, Len
);
/**************************************************************
** Copy a NUL terminated string to a Forth counted string.
char *CStringToForth( char *dst
, const char *CString
)
for( i
=0; *CString
; i
++ )
/**************************************************************
** Compare two test strings, case sensitive.
** Return TRUE if they match.
cell_t
ffCompareText( const char *s1
, const char *s2
, cell_t len
)
DBUGX(("ffCompareText: *s1 = 0x%x, *s2 = 0x%x\n", *s1
, *s2
));
DBUGX(("ffCompareText: return 0x%x\n", Result
));
/**************************************************************
** Compare two test strings, case INsensitive.
** Return TRUE if they match.
cell_t
ffCompareTextCaseN( const char *s1
, const char *s2
, cell_t len
)
c1
= pfCharToLower(*s1
++);
c2
= pfCharToLower(*s2
++);
DBUGX(("ffCompareText: c1 = 0x%x, c2 = 0x%x\n", c1
, c2
));
DBUGX(("ffCompareText: return 0x%x\n", Result
));
/**************************************************************
** Compare two strings, case sensitive.
** Return zero if they match, -1 if s1<s2, +1 is s1>s2;
cell_t
ffCompare( const char *s1
, cell_t len1
, const char *s2
, int32_t len2
)
cell_t i
, result
, n
, diff
;
if( (diff
= (*s2
++ - *s1
++)) != 0 )
result
= (diff
> 0) ? -1 : 1 ;
if( result
== 0 ) /* Match up to MIN(len1,len2) */
/***************************************************************
** Convert number to text.
#define CNTT_PAD_SIZE ((sizeof(cell_t)*8)+2) /* PLB 19980522 - Expand PAD so "-1 binary .s" doesn't crash. */
static char cnttPad
[CNTT_PAD_SIZE
];
char *ConvertNumberToText( cell_t Num
, cell_t Base
, int32_t IfSigned
, int32_t MinChars
)
ucell_t NewNum
, Rem
, uNum
;
/* Convert to positive and keep sign. */
/* Point past end of Pad */
p
= cnttPad
+ CNTT_PAD_SIZE
;
*(--p
) = (char) 0; /* NUL terminate */
while( (i
++<MinChars
) || (uNum
!= 0) )
Rem
= uNum
- (NewNum
* Base
);
c
= (char) (( Rem
< 10 ) ? (Rem
+ '0') : (Rem
- 10 + 'A'));
if( IfNegative
) *(--p
) = '-';
/***************************************************************
** Diagnostic routine that prints memory in table format.
void DumpMemory( void *addr
, cell_t cnt
)
unsigned char *ptr
, *cptr
, c
;
nlines
= (cnt
+ 15) / 16;
ptr
= (unsigned char *) addr
;
for (ln
=0; ln
<nlines
; ln
++)
MSG( ConvertNumberToText( (cell_t
) ptr
, 16, FALSE
, 8 ) );
MSG( ConvertNumberToText( (cell_t
) *cptr
++, 16, FALSE
, 2 ) );
if ((c
< ' ') || (c
> '}')) c
= '.';
/* Print name, mask off any dictionary bits. */
void TypeName( const char *Name
)
ioType( FirstChar
, Len
);