Annotation of gforth/kernel/xchars.fs, revision 1.1
1.1 ! anton 1: \ extended characters (either 8bit or UTF-8, possibly other encodings)
! 2: \ and their fixed-size variant
! 3:
! 4: \ Copyright (C) 2005 Free Software Foundation, Inc.
! 5:
! 6: \ This file is part of Gforth.
! 7:
! 8: \ Gforth is free software; you can redistribute it and/or
! 9: \ modify it under the terms of the GNU General Public License
! 10: \ as published by the Free Software Foundation; either version 2
! 11: \ of the License, or (at your option) any later version.
! 12:
! 13: \ This program is distributed in the hope that it will be useful,
! 14: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
! 15: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 16: \ GNU General Public License for more details.
! 17:
! 18: \ You should have received a copy of the GNU General Public License
! 19: \ along with this program; if not, write to the Free Software
! 20: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
! 21:
! 22: \ We can do some of these (and possibly faster) by just using the
! 23: \ utf-8 words with an appropriate setting of max-single-byte, but I
! 24: \ like to see how an 8bit setting without UTF-8 stuff looks like.
! 25:
! 26: DEFER XEMIT ( xc -- )
! 27: DEFER XKEY ( -- xc )
! 28: DEFER XCHAR+ ( xc-addr1 -- xc-addr2 )
! 29: DEFER XCHAR- ( xc-addr1 -- xc-addr2 )
! 30: DEFER +X/STRING ( xc-addr1 u1 -- xc-addr2 u2 )
! 31: DEFER -X/STRING ( xc-addr1 u1 -- xc-addr2 u2 )
! 32: DEFER XC@ ( xc-addr -- xc )
! 33: DEFER XC!+? ( xc xc-addr1 u1 -- xc-addr2 u2 f ) \ f if operation succeeded
! 34: DEFER XC@+ ( xc-addr1 -- xc-addr2 xc )
! 35: DEFER XC-SIZE ( xc -- u ) \ size in cs
! 36: DEFER -TRAILING-GARBAGE ( addr u1 -- addr u2 ) \ remove trailing incomplete xc
! 37:
! 38: \ fixed-size versions of these words
! 39:
! 40: : char- ( c-addr1 -- c-addr2 )
! 41: [ 1 chars ] literal - ;
! 42:
! 43: : 1/string ( c-addr1 u1 -- c-addr2 u2 )
! 44: 1 /string ;
! 45:
! 46: : -1/string ( c-addr1 u1 -- c-addr2 u2 )
! 47: -1 /string ;
! 48:
! 49: : c!+? ( c c-addr1 u1 -- c-addr2 u2 f )
! 50: 1 chars u< if \ or use < ?
! 51: >r dup >r c!
! 52: 1 r> r> /string true
! 53: else
! 54: rot drop false
! 55: then ;
! 56:
! 57: : c-size ( c -- 1 )
! 58: drop 1 ;
! 59:
! 60: : set-encoding-fixed-width ( -- )
! 61: ['] emit is xemit
! 62: ['] key is xkey
! 63: ['] char+ is xchar+
! 64: ['] char- is xchar-
! 65: ['] 1/string is +x/string
! 66: ['] -1/string is -x/string
! 67: ['] c@ is xc@
! 68: ['] c!+? is xc!+?
! 69: ['] count is xc@+
! 70: ['] c-size is xc-size
! 71: ['] noop is -trailing-garbage
! 72: ;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>