( Title: Measured strings null termination File: mstrings-0end.fs Author: David N. Williams License: LGPL Version: 0.8.4 Test file: mstrings-test.fs Change log: mstrings.log Revised: August 26, 2008 Copyright [C] 2002, 2007, 2008 David N. Williams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or at your option any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. If you take advantage of the option in the LGPL to put a particular version of this library under the GPL, the author[s] would regard it as polite if you would put any direct modifications under the LGPL as well, and include a copy of this request near the beginning of the modified library source. A "direct modification" is one that enhances or extends the library in line with its original concept, as opposed to developing a distinct application or library which might use it. This is a library in the mstrings collection. It is mostly ANS Forth compatible up to case dependence, [UNDEFINED], and REQUIRED. The code is intended to be character clean. Please see the file mstrings.txt for terminology and more detailed word specifications. ) decimal s" mstrings-srep.fs" required \ *** NULL TERMINATION WORDS \ (null-m+) null-m+ null-m+, \ *** UTILITY WORDS \ DEBUGGING \ : .# ( n -- ) cr ." #" . cr ; [UNDEFINED] chars+ [IF] : chars+ ( x n -- x+c[n] ) chars + ; [THEN] \ *** DEFINITIONS ( These words append a null character to an mstring, without changing its count. Assuming no other embedded nulls, the resulting string body is a C string when the C size of a char is the same as 1 CHARS. The action of NULL-M+, agrees with its name when the next available slot in data space is contiguous with the end of an mstring, and that is not checked. ) : (null-m+) ( m -- ) mcount chars+ 0 swap c! ; : null-m+ ( mbuf /mbuf -- flag ) over @ /m u> IF mcount chars+ 0 swap c! true ELSE drop false THEN ; : null-m+, ( -- ) 0 c, ;