Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/toolbelt.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - TOOLBELT - Copyright 2003,2005 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] [VOID] [IF]
FALSE CONSTANT [VOID] IMMEDIATE

\ ==========
\ Common Use
\ ==========
[DEFINED] 4TH# [IF]
: APPEND-CHAR COUNT CHARS + DUP CHAR+ >R C! 0 R> C! ;
[THEN]

[UNDEFINED] 4TH# [IF]
: APPEND-CHAR DUP >R COUNT DUP 1+ R> C! + C! ;
[THEN]

\ ==============
\ Stack Handling
\ ==============
: THIRD  ( x y z -- x y z x )     >R OVER R> SWAP ;
: FOURTH ( w x y z -- w x y z w ) >R >R OVER R> R> ROT ;
: 3DROP  ( x y z -- )             DROP DROP DROP ;
: 2NIP   ( w x y z -- y z )       >R >R DROP DROP R> R> ;

\ ================
\ Common Constants
\ ================
 8 CONSTANT #BACKSPACE-CHAR
62 VALUE    #CHARS/LINE
13 CONSTANT #EOL-CHAR
 9 CONSTANT #TAB-CHAR
-1 CELLS CONSTANT -CELL

\ ===============
\ Filter Handling
\ ===============
VARIABLE TEMP
: NEXT-WORD  ( -- str len )
  BEGIN BL PARSE-WORD DUP IF EXIT THEN REFILL WHILE DROP DROP REPEAT ;

\ ==============
\ Error Checking
\ ==============
: FILE-CHECK      ( n -- ) 0= ABORT" File Access Error " ;

\ ================
\ Generally Useful
\ ================
: ++  ( addr -- )  1 SWAP +! ;

\ =============
\ Miscellaneous
\ =============
: HIWORD  ( xxyy -- xx )  16 RSHIFT ;
: LOWORD  ( xxyy -- yy )  65535 AND ;
[THEN]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].