Forth utilities?



For Lisp there is a collection of small utilities:

http://common-lisp.net/project/cl-utilities/
http://common-lisp.net/project/cl-utilities/doc/

Do you know something like this for Forth? In the spirit of Forth it should
be a collection of small words or code snippets, for combining to bigger
solutions or for modifying to fit similar problems.

One example is a function, which I needed: Create a unicode (only for ASCII
input) string in memory:

\ Parse ccc delimited by " (double-quote) and store the characters as
\ unicode in memory. Return the number of characters stored.
: unicode" ( "ccc<quote>" -- u )
[char] " parse
dup if
tuck ( addr u -- u addr u )
over + swap ( addr u -- addr+u addr )
do
i @ c, 0 c,
loop
else
swap drop
then
;

Usage examples:

here unicode" Hello World!" 2 * dump
44EE52 | 48 00 65 00 6C 00 6C 00 6F 00 20 00 57 00 6F 00 |H.e.l.l.o. .W.o.|
44EE62 | 72 00 6C 00 64 00 21 00 |r.l.d.!.|

3 constant DESC_STRING

: usb-string-descriptor" ( "ccc<quote>" -- )
here 0 c, DESC_STRING c,
unicode"
swap c!
;

here usb-string-descriptor" LPC-2148" 18 dump
43BED0 | 08 03 4C 00 50 00 43 00 2D 00 32 00 31 00 34 00 |..L.P.C.-.2.1.4.|
43BEE0 | 38 00 |8.|


The utilities collection should show good Forth coding style, too, which is
useful if newbies like me wants to learn Forth, and every utility should
have at least one example how to use it.

BTW: Is there already a function for pasting normal strings to memory? I
found just s" , which is defined for compilation mode, only. But this is a
problem, if you need the string as part of an in-memory structure.

--
Frank Buss, fb@xxxxxxxxxxxxx
http://www.frank-buss.de, http://www.it4-systems.de
.



Relevant Pages

  • Re: Forth utilities?
    ... which I needed: Create a unicode (only for ASCII ... input) string in memory: ... swap drop ... if you need the string as part of an in-memory structure. ...
    (comp.lang.forth)
  • Re: Can someone explain the time command?
    ... If you looked under "The default format string is" paragraph ... swap is virtual memory stored on disk. ... When you run out of memory, the OS will swap unused/idle ...
    (comp.os.linux)
  • Re: Shell Alloc and UNICODE
    ... > allocate memory while using UNICODE!? ... All memory allocation uses byte counts, ... So there is nothing special about the UNICODE part. ... If the string uses generic data types, ...
    (microsoft.public.vc.mfc)
  • Re: Shell Alloc and UNICODE
    ... >> allocate memory while using UNICODE!? ... > All memory allocation uses byte counts, ... > So there is nothing special about the UNICODE part. ... If the string uses generic data types, ...
    (microsoft.public.vc.mfc)
  • Re: [Full-disclosure] ***ULTRALAME*** Microsoft Excel Unicode Overflow ***ULTRALAME***
    ... Very nice that you found that, since unicode overflows are not that easy to exploit. ... I didn't know that Spreadsheet-Perl converted the string into unicode and then put it ... It's just a simple stack overflow that overwrites the memory after the ...
    (Full-Disclosure)