zchar wordset

description

LGPL (C) 2000 - 2001 Guido Draheim <guidod@gmx.de>

description:: ZCHAR-EXT wordset - defines words for zero-terminated strings, the datatype prefix is called "Z" which is usually a simple CHAR. And CHAR can be either BCHAR or WCHAR depending on your platform. Anyway, the words in this wordset should be largely modelled after the examples found in other forth implementations - most prominently MPE's forths.

FORTH

Z" ( [chars<">] -- z* )();
p4:"z-quote";

scan the input to the next doublequote and create a buffer that holds the chars - return the address of that zero-terminated string-buffer, either POCKET-PAD or ALLOTed into the dictionary.

FORTH

ZCOUNT ( z* -- z* len )();
p4:"zcount";

push length of z-string, additionally to the string addr itself.

 : ZSTRLEN ZCOUNT NIP ;

(see libc strlen(3)) / compare with COUNT / ZSTRLEN

FORTH

ZSTRLEN ( z* -- len )();
p4:"zstrlen";

push length of z-string.

 : ZSTRLEN ZCOUNT NIP ;

(see libc strlen(3)) / compare with ZMOVE / CMOVE

FORTH

ZMOVE ( zsrc* zdest* -- )();
p4:"zmove";

copy a zero terminated string (see libc strcpy(3)) / compare with ZSTRLEN / COUNT

FORTH
ZPLACE ( addr* len zaddr* -- )(); 
 ;

copy string and place as 0 terminated (see libc strncpy(3)) / see also +ZPLACE / Z+PLACE

FORTH
+ZPLACE ( caddr* u zdest* -- )(); 
 ;

Add the string defined by CADDR LEN to the zero terminated string at ZDEST - (for older scripts the SYNONYM named APPENDZ exists) (see libc strncat(3)) / compare with ZPLACE / +PLACE

FORTH

APPENDZ ( .. )();
as:"appendz";

forthword synonym APPENDZ

is doing the same as +ZPLACE

this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.

FORTH
S\" ( [backslashed-strings_<">] -- str cnt )(); 
 ;

scan the following text to create a literal just like S" does, but backslashes can be used to escape special chars. The rules for the backslashes follow C literals, implemented techniques are \n \r \b \a \f \v \e \777 and all non-alnum chars represent themselves, esp. \" \' \ \? \! \% \( \) \[ \] \{ \} etcetera. most importantly the doublequote itself can be escaped. but be also informed that the usage of \' and \" is not portable as some systems preferred to map [\'] into ["]. Here I use the experimental addition to map [\q] to ["] and [\i] to [']

FORTH
C\" ( [backslashed-strings_<">] -- bstr* )(); 
 ;

scan the following text to create a literal just like C" does, but backslashes can be used to escape special chars. The rules for the backslashes follow C literals, implemented techniques are \n \r \b \a \f \v \e \777 and all non-alnum chars represent themselves, esp. \" \' \ \? \! \% \( \) \[ \] \{ \} etcetera. most importantly the doublequote itself can be escaped. but be also informed that the usage of \' and \" is not portable as some systems preferred to map [\'] into ["]. Here I use the experimental addition to map [\q] to ["] and [\i] to [']

FORTH
Z\" ( [backslashed-strings_<">] -- zstr* )(); 
 ;

scan the following text to create a literal just like Z" does, but backslashes can be used to escape special chars. The rules for the backslashes follow C literals, implemented techniques are \n \r \b \a \f \v \e \777 and all non-alnum chars represent themselves, esp. \" \' \ \? \! \% \( \) \[ \] \{ \} etcetera. most importantly the doublequote itself can be escaped but be also informed that the usage of \' and \" is not portable as some systems preferred to map [\'] into ["]. Here I use the experimental addition to map [\q] to ["] and [\i] to [']

ENVIRONMENT

ZCHAR-EXT ( .. )();
as:"zchar-minus-ext";

( 2000  )  constant ZCHAR-EXT

an ordinary constant (no special usage info)