Hex Artifact Content
Not logged in

Artifact 0f1556b262c2403a6f55c6428ecc1400b4d85437:


0000: 5c 20 66 69 6c 65 20 73 74 61 74 65 73 0a 0a 5c  \ file states..\
0010: 20 43 6f 70 79 72 69 67 68 74 20 28 43 29 20 32   Copyright (C) 2
0020: 30 31 30 2d 32 30 31 34 20 20 20 42 65 72 6e 64  010-2014   Bernd
0030: 20 50 61 79 73 61 6e 0a 0a 5c 20 54 68 69 73 20   Paysan..\ This 
0040: 70 72 6f 67 72 61 6d 20 69 73 20 66 72 65 65 20  program is free 
0050: 73 6f 66 74 77 61 72 65 3a 20 79 6f 75 20 63 61  software: you ca
0060: 6e 20 72 65 64 69 73 74 72 69 62 75 74 65 20 69  n redistribute i
0070: 74 20 61 6e 64 2f 6f 72 20 6d 6f 64 69 66 79 0a  t and/or modify.
0080: 5c 20 69 74 20 75 6e 64 65 72 20 74 68 65 20 74  \ it under the t
0090: 65 72 6d 73 20 6f 66 20 74 68 65 20 47 4e 55 20  erms of the GNU 
00a0: 41 66 66 65 72 6f 20 47 65 6e 65 72 61 6c 20 50  Affero General P
00b0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 61 73  ublic License as
00c0: 20 70 75 62 6c 69 73 68 65 64 20 62 79 0a 5c 20   published by.\ 
00d0: 74 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72  the Free Softwar
00e0: 65 20 46 6f 75 6e 64 61 74 69 6f 6e 2c 20 65 69  e Foundation, ei
00f0: 74 68 65 72 20 76 65 72 73 69 6f 6e 20 33 20 6f  ther version 3 o
0100: 66 20 74 68 65 20 4c 69 63 65 6e 73 65 2c 20 6f  f the License, o
0110: 72 0a 5c 20 28 61 74 20 79 6f 75 72 20 6f 70 74  r.\ (at your opt
0120: 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65 72 20 76  ion) any later v
0130: 65 72 73 69 6f 6e 2e 0a 0a 5c 20 54 68 69 73 20  ersion...\ This 
0140: 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 74 72  program is distr
0150: 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 68 6f  ibuted in the ho
0160: 70 65 20 74 68 61 74 20 69 74 20 77 69 6c 6c 20  pe that it will 
0170: 62 65 20 75 73 65 66 75 6c 2c 0a 5c 20 62 75 74  be useful,.\ but
0180: 20 57 49 54 48 4f 55 54 20 41 4e 59 20 57 41 52   WITHOUT ANY WAR
0190: 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 74 20 65  RANTY; without e
01a0: 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 65 64 20  ven the implied 
01b0: 77 61 72 72 61 6e 74 79 20 6f 66 0a 5c 20 4d 45  warranty of.\ ME
01c0: 52 43 48 41 4e 54 41 42 49 4c 49 54 59 20 6f 72  RCHANTABILITY or
01d0: 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20 50   FITNESS FOR A P
01e0: 41 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f 53  ARTICULAR PURPOS
01f0: 45 2e 20 20 53 65 65 20 74 68 65 0a 5c 20 47 4e  E.  See the.\ GN
0200: 55 20 41 66 66 65 72 6f 20 47 65 6e 65 72 61 6c  U Affero General
0210: 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20   Public License 
0220: 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73  for more details
0230: 2e 0a 0a 5c 20 59 6f 75 20 73 68 6f 75 6c 64 20  ...\ You should 
0240: 68 61 76 65 20 72 65 63 65 69 76 65 64 20 61 20  have received a 
0250: 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e 55 20  copy of the GNU 
0260: 41 66 66 65 72 6f 20 47 65 6e 65 72 61 6c 20 50  Affero General P
0270: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 0a 5c 20  ublic License.\ 
0280: 61 6c 6f 6e 67 20 77 69 74 68 20 74 68 69 73 20  along with this 
0290: 70 72 6f 67 72 61 6d 2e 20 20 49 66 20 6e 6f 74  program.  If not
02a0: 2c 20 73 65 65 20 3c 68 74 74 70 3a 2f 2f 77 77  , see <http://ww
02b0: 77 2e 67 6e 75 2e 6f 72 67 2f 6c 69 63 65 6e 73  w.gnu.org/licens
02c0: 65 73 2f 3e 2e 0a 0a 53 65 6d 61 20 66 69 6c 65  es/>...Sema file
02d0: 2d 73 65 6d 61 0a 0a 63 6d 64 2d 63 6c 61 73 73  -sema..cmd-class
02e0: 20 63 6c 61 73 73 0a 20 20 20 20 36 34 76 61 6c   class.    64val
02f0: 75 65 3a 20 66 73 2d 73 69 7a 65 0a 20 20 20 20  ue: fs-size.    
0300: 36 34 76 61 6c 75 65 3a 20 66 73 2d 73 65 65 6b  64value: fs-seek
0310: 0a 20 20 20 20 36 34 76 61 6c 75 65 3a 20 66 73  .    64value: fs
0320: 2d 73 65 65 6b 74 6f 0a 20 20 20 20 36 34 76 61  -seekto.    64va
0330: 6c 75 65 3a 20 66 73 2d 6c 69 6d 69 74 0a 20 20  lue: fs-limit.  
0340: 20 20 36 34 76 61 6c 75 65 3a 20 66 73 2d 74 69    64value: fs-ti
0350: 6d 65 0a 20 20 20 20 66 69 65 6c 64 3a 20 66 73  me.    field: fs
0360: 2d 66 69 64 0a 20 20 20 20 66 69 65 6c 64 3a 20  -fid.    field: 
0370: 66 73 2d 70 61 74 68 0a 20 20 20 20 66 69 65 6c  fs-path.    fiel
0380: 64 3a 20 66 73 2d 69 64 0a 20 20 20 20 66 69 65  d: fs-id.    fie
0390: 6c 64 3a 20 74 65 72 6d 2d 77 0a 20 20 20 20 66  ld: term-w.    f
03a0: 69 65 6c 64 3a 20 74 65 72 6d 2d 68 0a 20 20 20  ield: term-h.   
03b0: 20 66 69 65 6c 64 3a 20 66 73 2d 69 6e 62 75 66   field: fs-inbuf
03c0: 0a 20 20 20 20 66 69 65 6c 64 3a 20 66 73 2d 6f  .    field: fs-o
03d0: 75 74 62 75 66 0a 20 20 20 20 66 69 65 6c 64 3a  utbuf.    field:
03e0: 20 66 73 2d 74 65 72 6d 74 61 73 6b 0a 20 20 20   fs-termtask.   
03f0: 20 64 65 66 65 72 3a 20 66 69 6c 65 2d 78 74 20   defer: file-xt 
0400: 20 20 20 20 5c 20 63 61 6c 6c 62 61 63 6b 20 66      \ callback f
0410: 6f 72 20 6f 70 65 72 61 74 69 6f 6e 20 63 6f 6d  or operation com
0420: 70 6c 65 74 65 64 0a 20 20 20 20 66 69 65 6c 64  pleted.    field
0430: 3a 20 66 73 2d 63 72 79 70 74 6b 65 79 20 5c 20  : fs-cryptkey \ 
0440: 66 6f 72 20 65 6e 2f 64 65 63 72 79 70 74 69 6e  for en/decryptin
0450: 67 20 61 20 66 69 6c 65 20 6f 6e 20 74 68 65 20  g a file on the 
0460: 66 6c 79 0a 20 20 20 20 66 69 65 6c 64 3a 20 66  fly.    field: f
0470: 73 2d 72 65 6e 61 6d 65 2b 20 20 5c 20 74 65 6d  s-rename+  \ tem
0480: 70 6f 72 61 72 79 20 70 61 74 68 20 66 6f 72 20  porary path for 
0490: 64 6f 77 6e 6c 6f 61 64 73 0a 20 20 20 20 6d 65  downloads.    me
04a0: 74 68 6f 64 20 66 73 2d 72 65 61 64 0a 20 20 20  thod fs-read.   
04b0: 20 6d 65 74 68 6f 64 20 66 73 2d 77 72 69 74 65   method fs-write
04c0: 0a 20 20 20 20 6d 65 74 68 6f 64 20 66 73 2d 6f  .    method fs-o
04d0: 70 65 6e 0a 20 20 20 20 6d 65 74 68 6f 64 20 66  pen.    method f
04e0: 73 2d 63 72 65 61 74 65 0a 20 20 20 20 6d 65 74  s-create.    met
04f0: 68 6f 64 20 66 73 2d 63 6c 6f 73 65 0a 20 20 20  hod fs-close.   
0500: 20 6d 65 74 68 6f 64 20 66 73 2d 66 6c 75 73 68   method fs-flush
0510: 0a 20 20 20 20 6d 65 74 68 6f 64 20 66 73 2d 70  .    method fs-p
0520: 6f 6c 6c 0a 20 20 20 20 6d 65 74 68 6f 64 20 66  oll.    method f
0530: 73 2d 70 65 72 6d 3f 0a 20 20 20 20 6d 65 74 68  s-perm?.    meth
0540: 6f 64 20 66 73 2d 67 65 74 2d 73 74 61 74 0a 20  od fs-get-stat. 
0550: 20 20 20 6d 65 74 68 6f 64 20 66 73 2d 73 65 74     method fs-set
0560: 2d 73 74 61 74 0a 65 6e 64 2d 63 6c 61 73 73 20  -stat.end-class 
0570: 66 73 2d 63 6c 61 73 73 0a 0a 56 61 72 69 61 62  fs-class..Variab
0580: 6c 65 20 66 73 2d 74 61 62 6c 65 0a 0a 5c 20 66  le fs-table..\ f
0590: 69 6c 65 20 65 76 65 6e 74 73 0a 3a 20 66 69 6c  ile events.: fil
05a0: 65 3a 65 72 72 20 28 20 2d 2d 20 29 0a 20 20 20  e:err ( -- ).   
05b0: 20 3c 65 72 72 3e 20 2e 22 20 69 6e 76 61 6c 69   <err> ." invali
05c0: 64 20 66 69 6c 65 2d 64 6f 6e 65 20 78 74 22 20  d file-done xt" 
05d0: 3c 64 65 66 61 75 6c 74 3e 20 7e 7e 62 74 20 3b  <default> ~~bt ;
05e0: 0a 3a 20 66 69 6c 65 3a 64 6f 6e 65 20 28 20 2d  .: file:done ( -
05f0: 2d 20 29 0a 20 20 20 20 70 61 72 65 6e 74 20 3e  - ).    parent >
0600: 6f 20 2d 31 20 66 69 6c 65 2d 63 6f 75 6e 74 20  o -1 file-count 
0610: 2b 21 40 20 31 20 3d 20 49 46 0a 09 77 61 69 74  +!@ 1 = IF..wait
0620: 2d 74 61 73 6b 20 40 20 3f 64 75 70 2d 49 46 20  -task @ ?dup-IF 
0630: 20 3c 65 76 65 6e 74 0a 09 20 20 20 20 77 61 6b   <event..    wak
0640: 65 23 20 6f 76 65 72 20 27 73 20 40 20 31 2b 20  e# over 's @ 1+ 
0650: 65 6c 69 74 2c 20 3a 3e 77 61 6b 65 20 20 65 76  elit, :>wake  ev
0660: 65 6e 74 3e 20 20 54 48 45 4e 0a 20 20 20 20 54  ent>  THEN.    T
0670: 48 45 4e 20 6f 3e 0a 20 20 20 20 5b 3a 20 2e 74  HEN o>.    [: .t
0680: 69 6d 65 20 2e 22 20 64 6f 77 6e 6c 6f 61 64 20  ime ." download 
0690: 64 6f 6e 65 3a 20 22 20 66 73 2d 69 64 20 3f 20  done: " fs-id ? 
06a0: 66 73 2d 70 61 74 68 20 24 40 20 74 79 70 65 20  fs-path $@ type 
06b0: 63 72 20 3b 5d 20 64 6f 2d 64 65 62 75 67 20 3b  cr ;] do-debug ;
06c0: 0a 65 76 65 6e 74 3a 20 3a 3e 66 69 6c 65 2d 64  .event: :>file-d
06d0: 6f 6e 65 20 28 20 66 69 6c 65 2d 6f 20 2d 2d 20  one ( file-o -- 
06e0: 29 20 5c 20 2e 66 69 6c 65 2d 78 74 20 3b 0a 20  ) \ .file-xt ;. 
06f0: 20 20 20 3e 6f 20 61 63 74 69 6f 6e 2d 6f 66 20     >o action-of 
0700: 66 69 6c 65 2d 78 74 20 49 46 20 20 66 69 6c 65  file-xt IF  file
0710: 2d 78 74 20 20 45 4c 53 45 20 20 66 69 6c 65 3a  -xt  ELSE  file:
0720: 65 72 72 20 20 54 48 45 4e 20 6f 3e 20 3b 0a 0a  err  THEN o> ;..
0730: 5c 20 69 64 20 68 61 6e 64 6c 69 6e 67 0a 0a 3a  \ id handling..:
0740: 20 69 64 3e 61 64 64 72 20 28 20 69 64 20 2d 2d   id>addr ( id --
0750: 20 61 64 64 72 20 72 65 6d 61 69 6e 64 65 72 20   addr remainder 
0760: 29 0a 20 20 20 20 5b 3a 20 3e 72 20 66 69 6c 65  ).    [: >r file
0770: 2d 73 74 61 74 65 20 24 40 20 72 3e 20 63 65 6c  -state $@ r> cel
0780: 6c 73 20 2f 73 74 72 69 6e 67 20 3e 72 20 64 75  ls /string >r du
0790: 70 20 49 46 20 20 40 20 20 54 48 45 4e 20 72 3e  p IF  @  THEN r>
07a0: 20 3b 5d 0a 20 20 20 20 66 69 6c 65 73 74 61 74   ;].    filestat
07b0: 65 2d 73 65 6d 61 20 63 2d 73 65 63 74 69 6f 6e  e-sema c-section
07c0: 20 3b 0a 3a 20 69 64 3e 61 64 64 72 3f 20 28 20   ;.: id>addr? ( 
07d0: 69 64 20 2d 2d 20 61 64 64 72 20 29 0a 20 20 20  id -- addr ).   
07e0: 20 69 64 3e 61 64 64 72 20 63 65 6c 6c 20 3c 20   id>addr cell < 
07f0: 21 21 66 69 6c 65 69 64 21 21 20 3b 0a 3a 20 6e  !!fileid!! ;.: n
0800: 65 77 3e 66 69 6c 65 20 28 20 69 64 20 2d 2d 20  ew>file ( id -- 
0810: 29 0a 20 20 20 20 5b 3a 20 66 73 2d 63 6c 61 73  ).    [: fs-clas
0820: 73 20 6e 65 77 20 7b 20 77 5e 20 66 73 70 20 7d  s new { w^ fsp }
0830: 20 66 73 70 20 63 65 6c 6c 20 66 69 6c 65 2d 73   fsp cell file-s
0840: 74 61 74 65 20 24 2b 21 0a 20 20 20 20 20 20 6f  tate $+!.      o
0850: 20 66 73 70 20 40 20 3e 6f 20 70 61 72 65 6e 74   fsp @ >o parent
0860: 21 20 66 73 2d 69 64 20 21 20 5b 27 5d 20 66 69  ! fs-id ! ['] fi
0870: 6c 65 3a 64 6f 6e 65 20 69 73 20 66 69 6c 65 2d  le:done is file-
0880: 78 74 0a 20 20 20 20 20 20 66 73 2d 74 61 62 6c  xt.      fs-tabl
0890: 65 20 40 20 74 6f 6b 65 6e 2d 74 61 62 6c 65 20  e @ token-table 
08a0: 21 20 36 34 23 2d 31 20 74 6f 20 66 73 2d 6c 69  ! 64#-1 to fs-li
08b0: 6d 69 74 20 6f 3e 20 3b 5d 0a 20 20 20 20 66 69  mit o> ;].    fi
08c0: 6c 65 73 74 61 74 65 2d 73 65 6d 61 20 63 2d 73  lestate-sema c-s
08d0: 65 63 74 69 6f 6e 20 3b 0a 0a 3a 20 6c 61 73 74  ection ;..: last
08e0: 66 69 6c 65 40 20 28 20 2d 2d 20 66 73 2d 73 74  file@ ( -- fs-st
08f0: 61 74 65 20 29 20 66 69 6c 65 2d 73 74 61 74 65  ate ) file-state
0900: 20 24 40 20 2b 20 63 65 6c 6c 2d 20 40 20 3b 0a   $@ + cell- @ ;.
0910: 3a 20 73 74 61 74 65 2d 61 64 64 72 20 28 20 69  : state-addr ( i
0920: 64 20 2d 2d 20 61 64 64 72 20 29 0a 20 20 20 20  d -- addr ).    
0930: 64 75 70 20 3e 72 20 69 64 3e 61 64 64 72 20 64  dup >r id>addr d
0940: 75 70 20 30 3c 20 21 21 67 61 70 21 21 0a 20 20  up 0< !!gap!!.  
0950: 20 20 30 3d 20 49 46 20 20 64 72 6f 70 20 72 40    0= IF  drop r@
0960: 20 6e 65 77 3e 66 69 6c 65 20 6c 61 73 74 66 69   new>file lastfi
0970: 6c 65 40 20 20 54 48 45 4e 20 20 72 64 72 6f 70  le@  THEN  rdrop
0980: 20 3b 0a 0a 63 65 6c 6c 20 38 20 3d 20 5b 49 46   ;..cell 8 = [IF
0990: 5d 0a 20 20 20 20 27 20 6e 6f 6f 70 20 61 6c 69  ].    ' noop ali
09a0: 61 73 20 36 34 3e 75 73 61 74 0a 5b 45 4c 53 45  as 64>usat.[ELSE
09b0: 5d 0a 20 20 20 20 3a 20 36 34 3e 75 73 61 74 20  ].    : 64>usat 
09c0: 28 20 36 34 20 2d 2d 20 75 20 29 20 30 3c 3e 20  ( 64 -- u ) 0<> 
09d0: 6f 72 20 3b 0a 5b 54 48 45 4e 5d 0a 0a 3a 20 3e  or ;.[THEN]..: >
09e0: 73 65 65 6b 20 28 20 73 69 7a 65 20 36 34 74 6f  seek ( size 64to
09f0: 20 36 34 73 65 65 6b 20 2d 2d 20 73 69 7a 65 27   64seek -- size'
0a00: 20 29 0a 20 20 20 20 36 34 64 75 70 20 36 34 3e   ).    64dup 64>
0a10: 64 20 66 73 2d 66 69 64 20 40 20 72 65 70 6f 73  d fs-fid @ repos
0a20: 69 74 69 6f 6e 2d 66 69 6c 65 20 74 68 72 6f 77  ition-file throw
0a30: 20 36 34 2d 20 36 34 3e 75 73 61 74 20 75 6d 69   64- 64>usat umi
0a40: 6e 20 3b 0a 3a 20 3e 72 65 6e 61 6d 65 2b 20 28  n ;.: >rename+ (
0a50: 20 61 64 64 72 20 75 20 2d 2d 20 29 0a 20 20 20   addr u -- ).   
0a60: 20 66 73 2d 72 65 6e 61 6d 65 2b 20 24 21 0a 20   fs-rename+ $!. 
0a70: 20 20 20 3c 3c 23 20 67 65 74 70 69 64 20 30 20     <<# getpid 0 
0a80: 23 73 20 27 2b 27 20 68 6f 6c 64 20 23 3e 20 66  #s '+' hold #> f
0a90: 73 2d 72 65 6e 61 6d 65 2b 20 24 2b 21 20 23 3e  s-rename+ $+! #>
0aa0: 3e 0a 20 20 20 20 66 73 2d 72 65 6e 61 6d 65 2b  >.    fs-rename+
0ab0: 20 24 40 20 3b 0a 3a 20 66 73 2d 74 69 6d 65 73   $@ ;.: fs-times
0ac0: 74 61 6d 70 21 20 28 20 6d 74 69 6d 65 20 66 69  tamp! ( mtime fi
0ad0: 64 20 2d 2d 20 29 20 66 69 6c 65 6e 6f 20 3e 72  d -- ) fileno >r
0ae0: 0a 20 20 20 20 5b 49 46 44 45 46 5d 20 61 6e 64  .    [IFDEF] and
0af0: 72 6f 69 64 20 20 72 64 72 6f 70 20 36 34 64 72  roid  rdrop 64dr
0b00: 6f 70 0a 20 20 20 20 5b 45 4c 53 45 5d 20 20 5c  op.    [ELSE]  \
0b10: 20 2e 22 20 53 65 74 20 74 69 6d 65 3a 20 22 20   ." Set time: " 
0b20: 72 40 20 2e 20 36 34 64 75 70 20 36 34 3e 64 20  r@ . 64dup 64>d 
0b30: 64 2e 20 63 72 0a 09 36 34 3e 64 20 32 64 75 70  d. cr..64>d 2dup
0b40: 20 73 74 61 74 62 75 66 20 6e 74 69 6d 65 21 0a   statbuf ntime!.
0b50: 09 73 74 61 74 62 75 66 20 32 20 63 65 6c 6c 73  .statbuf 2 cells
0b60: 20 2b 20 6e 74 69 6d 65 21 0a 09 72 3e 20 73 74   + ntime!..r> st
0b70: 61 74 62 75 66 20 66 75 74 69 6d 65 6e 73 20 3f  atbuf futimens ?
0b80: 69 6f 72 20 5b 54 48 45 4e 5d 20 3b 0a 3a 20 66  ior [THEN] ;.: f
0b90: 73 2d 73 69 7a 65 21 20 28 20 36 34 73 69 7a 65  s-size! ( 64size
0ba0: 20 2d 2d 20 29 0a 20 20 20 20 36 34 64 75 70 20   -- ).    64dup 
0bb0: 74 6f 20 66 73 2d 73 69 7a 65 20 74 6f 20 66 73  to fs-size to fs
0bc0: 2d 6c 69 6d 69 74 0a 20 20 20 20 36 34 23 30 20  -limit.    64#0 
0bd0: 74 6f 20 66 73 2d 73 65 65 6b 20 36 34 23 30 20  to fs-seek 64#0 
0be0: 74 6f 20 66 73 2d 73 65 65 6b 74 6f 20 36 34 23  to fs-seekto 64#
0bf0: 30 20 74 6f 20 66 73 2d 74 69 6d 65 20 3b 0a 0a  0 to fs-time ;..
0c00: 56 6f 63 61 62 75 6c 61 72 79 20 66 73 0a 0a 69  Vocabulary fs..i
0c10: 6e 20 66 73 20 3a 20 66 73 2d 72 65 61 64 20 28  n fs : fs-read (
0c20: 20 61 64 64 72 20 75 20 2d 2d 20 75 20 29 0a 20   addr u -- u ). 
0c30: 20 20 20 66 73 2d 6c 69 6d 69 74 20 66 73 2d 73     fs-limit fs-s
0c40: 65 65 6b 74 6f 20 3e 73 65 65 6b 0a 20 20 20 20  eekto >seek.    
0c50: 66 73 2d 66 69 64 20 40 20 72 65 61 64 2d 66 69  fs-fid @ read-fi
0c60: 6c 65 20 74 68 72 6f 77 0a 20 20 20 20 64 75 70  le throw.    dup
0c70: 20 6e 3e 36 34 20 2b 74 6f 20 66 73 2d 73 65 65   n>64 +to fs-see
0c80: 6b 74 6f 0a 3b 20 27 20 66 73 3a 66 73 2d 72 65  kto.; ' fs:fs-re
0c90: 61 64 20 66 73 2d 63 6c 61 73 73 20 74 6f 20 66  ad fs-class to f
0ca0: 73 2d 72 65 61 64 0a 69 6e 20 66 73 20 3a 20 66  s-read.in fs : f
0cb0: 73 2d 77 72 69 74 65 20 28 20 61 64 64 72 20 75  s-write ( addr u
0cc0: 20 2d 2d 20 75 20 29 0a 20 20 20 20 64 75 70 20   -- u ).    dup 
0cd0: 30 3d 20 49 46 20 20 6e 69 70 20 20 45 58 49 54  0= IF  nip  EXIT
0ce0: 20 20 54 48 45 4e 0a 20 20 20 20 66 73 2d 6c 69    THEN.    fs-li
0cf0: 6d 69 74 20 66 73 2d 73 69 7a 65 20 36 34 75 6d  mit fs-size 64um
0d00: 69 6e 0a 20 20 20 20 36 34 64 75 70 20 66 73 2d  in.    64dup fs-
0d10: 73 65 65 6b 20 36 34 75 3c 3d 20 49 46 20 20 36  seek 64u<= IF  6
0d20: 34 64 72 6f 70 20 32 64 72 6f 70 20 30 20 20 45  4drop 2drop 0  E
0d30: 58 49 54 20 20 54 48 45 4e 0a 20 20 20 20 66 73  XIT  THEN.    fs
0d40: 2d 73 65 65 6b 20 3e 73 65 65 6b 0a 20 20 20 20  -seek >seek.    
0d50: 74 75 63 6b 20 66 73 2d 66 69 64 20 40 20 77 72  tuck fs-fid @ wr
0d60: 69 74 65 2d 66 69 6c 65 20 74 68 72 6f 77 0a 20  ite-file throw. 
0d70: 20 20 20 64 75 70 20 6e 3e 36 34 20 2b 74 6f 20     dup n>64 +to 
0d80: 66 73 2d 73 65 65 6b 20 20 66 73 2d 73 65 65 6b  fs-seek  fs-seek
0d90: 20 74 6f 20 66 73 2d 73 65 65 6b 74 6f 0a 20 20   to fs-seekto.  
0da0: 20 20 66 73 2d 73 69 7a 65 20 66 73 2d 73 65 65    fs-size fs-see
0db0: 6b 20 36 34 3d 20 49 46 0a 09 66 73 2d 66 6c 75  k 64= IF..fs-flu
0dc0: 73 68 0a 09 3c 65 76 65 6e 74 20 6f 20 65 6c 69  sh..<event o eli
0dd0: 74 2c 20 3a 3e 66 69 6c 65 2d 64 6f 6e 65 20 70  t, :>file-done p
0de0: 61 72 65 6e 74 20 2e 77 61 69 74 2d 74 61 73 6b  arent .wait-task
0df0: 20 40 20 65 76 65 6e 74 3e 0a 20 20 20 20 54 48   @ event>.    TH
0e00: 45 4e 0a 3b 20 27 20 66 73 3a 66 73 2d 77 72 69  EN.; ' fs:fs-wri
0e10: 74 65 20 66 73 2d 63 6c 61 73 73 20 74 6f 20 66  te fs-class to f
0e20: 73 2d 77 72 69 74 65 0a 69 6e 20 66 73 20 3a 20  s-write.in fs : 
0e30: 66 73 2d 63 6c 65 61 72 20 28 20 2d 2d 20 29 0a  fs-clear ( -- ).
0e40: 20 20 20 20 36 34 23 30 0a 20 20 20 20 36 34 64      64#0.    64d
0e50: 75 70 20 74 6f 20 66 73 2d 6c 69 6d 69 74 20 20  up to fs-limit  
0e60: 36 34 64 75 70 20 74 6f 20 66 73 2d 73 65 65 6b  64dup to fs-seek
0e70: 74 6f 20 20 36 34 64 75 70 20 74 6f 20 66 73 2d  to  64dup to fs-
0e80: 73 65 65 6b 0a 20 20 20 20 36 34 64 75 70 20 74  seek.    64dup t
0e90: 6f 20 66 73 2d 73 69 7a 65 20 20 74 6f 20 66 73  o fs-size  to fs
0ea0: 2d 74 69 6d 65 20 20 66 73 2d 70 61 74 68 20 24  -time  fs-path $
0eb0: 66 72 65 65 20 20 66 73 2d 72 65 6e 61 6d 65 2b  free  fs-rename+
0ec0: 20 24 66 72 65 65 0a 20 20 20 20 5b 27 5d 20 6e   $free.    ['] n
0ed0: 6f 6f 70 20 74 6f 20 66 69 6c 65 2d 78 74 20 3b  oop to file-xt ;
0ee0: 0a 69 6e 20 66 73 20 3a 20 66 73 2d 66 6c 75 73  .in fs : fs-flus
0ef0: 68 20 28 20 2d 2d 20 29 0a 20 20 20 20 66 73 2d  h ( -- ).    fs-
0f00: 66 69 64 20 40 20 66 6c 75 73 68 2d 66 69 6c 65  fid @ flush-file
0f10: 20 74 68 72 6f 77 0a 20 20 20 20 5c 20 77 72 69   throw.    \ wri
0f20: 74 65 20 61 77 61 79 20 61 6c 6c 20 62 75 66 66  te away all buff
0f30: 65 72 65 64 20 73 74 75 66 66 2c 20 73 6f 20 74  ered stuff, so t
0f40: 68 61 74 20 73 65 74 74 69 6e 67 20 74 68 65 0a  hat setting the.
0f50: 20 20 20 20 5c 20 74 69 6d 65 73 74 61 6d 70 20      \ timestamp 
0f60: 77 6f 72 6b 73 0a 20 20 20 20 66 73 2d 74 69 6d  works.    fs-tim
0f70: 65 20 36 34 2d 30 3c 3e 20 49 46 0a 09 66 73 2d  e 64-0<> IF..fs-
0f80: 74 69 6d 65 20 66 73 2d 66 69 64 20 40 20 66 73  time fs-fid @ fs
0f90: 2d 74 69 6d 65 73 74 61 6d 70 21 0a 20 20 20 20  -timestamp!.    
0fa0: 54 48 45 4e 0a 20 20 20 20 66 73 2d 72 65 6e 61  THEN.    fs-rena
0fb0: 6d 65 2b 20 24 40 20 64 75 70 20 49 46 0a 09 66  me+ $@ dup IF..f
0fc0: 73 2d 70 61 74 68 20 24 40 20 72 65 6e 61 6d 65  s-path $@ rename
0fd0: 2d 66 69 6c 65 20 74 68 72 6f 77 0a 09 66 73 2d  -file throw..fs-
0fe0: 72 65 6e 61 6d 65 2b 20 24 66 72 65 65 0a 20 20  rename+ $free.  
0ff0: 20 20 45 4c 53 45 20 20 32 64 72 6f 70 20 20 54    ELSE  2drop  T
1000: 48 45 4e 0a 3b 20 27 20 66 73 3a 66 73 2d 66 6c  HEN.; ' fs:fs-fl
1010: 75 73 68 20 66 73 2d 63 6c 61 73 73 20 74 6f 20  ush fs-class to 
1020: 66 73 2d 66 6c 75 73 68 0a 69 6e 20 66 73 20 3a  fs-flush.in fs :
1030: 20 66 73 2d 63 6c 6f 73 65 20 28 20 2d 2d 20 29   fs-close ( -- )
1040: 0a 20 20 20 20 66 73 2d 66 69 64 20 40 20 30 3d  .    fs-fid @ 0=
1050: 20 3f 45 58 49 54 0a 20 20 20 20 66 73 2d 66 6c   ?EXIT.    fs-fl
1060: 75 73 68 0a 20 20 20 20 66 73 2d 66 69 64 20 40  ush.    fs-fid @
1070: 20 63 6c 6f 73 65 2d 66 69 6c 65 20 74 68 72 6f   close-file thro
1080: 77 0a 20 20 20 20 66 73 2d 66 69 64 20 6f 66 66  w.    fs-fid off
1090: 0a 20 20 20 20 66 73 3a 66 73 2d 63 6c 65 61 72  .    fs:fs-clear
10a0: 0a 3b 20 27 20 66 73 3a 66 73 2d 63 6c 6f 73 65  .; ' fs:fs-close
10b0: 20 66 73 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d   fs-class to fs-
10c0: 63 6c 6f 73 65 0a 3a 6e 6f 6e 61 6d 65 20 28 20  close.:noname ( 
10d0: 2d 2d 20 36 34 73 69 7a 65 20 29 0a 20 20 20 20  -- 64size ).    
10e0: 66 73 2d 66 69 64 20 40 20 66 69 6c 65 2d 73 69  fs-fid @ file-si
10f0: 7a 65 20 74 68 72 6f 77 20 64 3e 36 34 0a 3b 20  ze throw d>64.; 
1100: 66 73 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 70  fs-class to fs-p
1110: 6f 6c 6c 0a 3a 6e 6f 6e 61 6d 65 20 28 20 61 64  oll.:noname ( ad
1120: 64 72 20 75 20 6d 6f 64 65 20 2d 2d 20 29 20 66  dr u mode -- ) f
1130: 73 2d 63 6c 6f 73 65 0a 20 20 20 20 6d 73 67 28  s-close.    msg(
1140: 20 64 75 70 20 32 6f 76 65 72 20 2e 22 20 6f 70   dup 2over ." op
1150: 65 6e 20 66 69 6c 65 3a 20 22 20 66 6f 72 74 68  en file: " forth
1160: 3a 74 79 70 65 20 2e 22 20 20 77 69 74 68 20 6d  :type ."  with m
1170: 6f 64 65 20 22 20 2e 20 66 6f 72 74 68 3a 63 72  ode " . forth:cr
1180: 20 29 0a 20 20 20 20 3e 72 20 3f 73 61 6e 65 2d   ).    >r ?sane-
1190: 66 69 6c 65 0a 20 20 20 20 63 6f 6e 66 69 67 3a  file.    config:
11a0: 72 6f 6f 74 64 69 72 73 24 20 6f 70 65 6e 2d 70  rootdirs$ open-p
11b0: 61 74 68 2d 66 69 6c 65 20 74 68 72 6f 77 20 66  ath-file throw f
11c0: 73 2d 70 61 74 68 20 24 21 20 66 73 2d 66 69 64  s-path $! fs-fid
11d0: 20 21 0a 20 20 20 20 72 40 20 72 2f 6f 20 3c 3e   !.    r@ r/o <>
11e0: 20 49 46 20 20 30 20 66 73 2d 66 69 64 20 21 40   IF  0 fs-fid !@
11f0: 20 63 6c 6f 73 65 2d 66 69 6c 65 20 74 68 72 6f   close-file thro
1200: 77 0a 09 66 73 2d 70 61 74 68 20 24 40 20 72 40  w..fs-path $@ r@
1210: 20 6f 70 65 6e 2d 66 69 6c 65 20 74 68 72 6f 77   open-file throw
1220: 20 66 73 2d 66 69 64 20 20 21 20 20 54 48 45 4e   fs-fid  !  THEN
1230: 20 20 72 64 72 6f 70 0a 20 20 20 20 66 73 2d 70    rdrop.    fs-p
1240: 6f 6c 6c 20 66 73 2d 73 69 7a 65 21 0a 3b 20 66  oll fs-size!.; f
1250: 73 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 6f 70  s-class to fs-op
1260: 65 6e 0a 3a 6e 6f 6e 61 6d 65 20 28 20 61 64 64  en.:noname ( add
1270: 72 20 75 20 2d 2d 20 29 20 20 66 73 2d 63 6c 6f  r u -- )  fs-clo
1280: 73 65 0a 20 20 20 20 6d 73 67 28 20 32 64 75 70  se.    msg( 2dup
1290: 20 2e 22 20 63 72 65 61 74 65 20 66 69 6c 65 3a   ." create file:
12a0: 20 22 20 66 6f 72 74 68 3a 74 79 70 65 20 66 6f   " forth:type fo
12b0: 72 74 68 3a 63 72 20 29 0a 20 20 20 20 3f 73 61  rth:cr ).    ?sa
12c0: 6e 65 2d 66 69 6c 65 0a 20 20 20 20 32 64 75 70  ne-file.    2dup
12d0: 20 66 73 2d 70 61 74 68 20 24 21 20 3e 72 65 6e   fs-path $! >ren
12e0: 61 6d 65 2b 20 72 2f 77 20 63 72 65 61 74 65 2d  ame+ r/w create-
12f0: 66 69 6c 65 20 74 68 72 6f 77 20 66 73 2d 66 69  file throw fs-fi
1300: 64 20 21 0a 3b 20 66 73 2d 63 6c 61 73 73 20 74  d !.; fs-class t
1310: 6f 20 66 73 2d 63 72 65 61 74 65 0a 3a 6e 6f 6e  o fs-create.:non
1320: 61 6d 65 20 28 20 70 65 72 6d 20 2d 2d 20 29 0a  ame ( perm -- ).
1330: 20 20 20 20 70 65 72 6d 25 66 69 6c 65 6e 61 6d      perm%filenam
1340: 65 20 61 6e 64 20 30 3d 20 21 21 66 69 6c 65 6e  e and 0= !!filen
1350: 61 6d 65 2d 70 65 72 6d 21 21 0a 3b 20 66 73 2d  ame-perm!!.; fs-
1360: 63 6c 61 73 73 20 74 6f 20 66 73 2d 70 65 72 6d  class to fs-perm
1370: 3f 0a 0a 5c 20 61 63 63 65 73 73 20 74 6f 20 65  ?..\ access to e
1380: 6e 63 72 79 70 74 65 64 20 68 61 73 68 20 66 69  ncrypted hash fi
1390: 6c 65 73 0a 0a 3a 20 3e 66 69 6c 65 2d 68 61 73  les..: >file-has
13a0: 68 20 28 20 61 64 64 72 20 75 20 2d 2d 20 61 64  h ( addr u -- ad
13b0: 64 72 68 61 73 68 20 75 20 29 0a 20 20 20 20 63  drhash u ).    c
13c0: 3a 30 6b 65 79 20 63 3a 68 61 73 68 20 6b 65 79  :0key c:hash key
13d0: 65 64 2d 68 61 73 68 2d 6f 75 74 20 68 61 73 68  ed-hash-out hash
13e0: 23 31 32 38 20 32 64 75 70 20 63 3a 68 61 73 68  #128 2dup c:hash
13f0: 40 20 3b 0a 3a 20 65 6e 63 68 61 73 68 20 28 20  @ ;.: enchash ( 
1400: 2d 2d 20 61 64 64 72 20 75 20 29 0a 20 20 20 20  -- addr u ).    
1410: 73 6b 73 69 67 20 6b 65 79 65 64 2d 68 61 73 68  sksig keyed-hash
1420: 2d 6f 75 74 20 68 61 73 68 23 31 32 38 20 2b 20  -out hash#128 + 
1430: 6b 65 79 73 69 7a 65 20 6d 6f 76 65 0a 20 20 20  keysize move.   
1440: 20 6b 65 79 65 64 2d 68 61 73 68 2d 6f 75 74 20   keyed-hash-out 
1450: 68 61 73 68 23 32 35 36 20 3e 66 69 6c 65 2d 68  hash#256 >file-h
1460: 61 73 68 20 3b 0a 0a 66 73 2d 63 6c 61 73 73 20  ash ;..fs-class 
1470: 63 6c 61 73 73 0a 65 6e 64 2d 63 6c 61 73 73 20  class.end-class 
1480: 68 61 73 68 66 73 2d 63 6c 61 73 73 0a 0a 3a 20  hashfs-class..: 
1490: 68 61 73 68 66 73 3e 66 69 6c 65 20 28 20 61 64  hashfs>file ( ad
14a0: 64 72 68 61 73 68 20 75 31 20 2d 2d 20 61 64 64  drhash u1 -- add
14b0: 72 66 69 6c 65 20 75 32 20 29 0a 20 20 20 20 63  rfile u2 ).    c
14c0: 3a 6b 65 79 40 20 3e 72 20 20 6b 65 63 63 61 6b  :key@ >r  keccak
14d0: 23 20 66 73 2d 63 72 79 70 74 6b 65 79 20 24 21  # fs-cryptkey $!
14e0: 6c 65 6e 0a 20 20 20 20 66 73 2d 63 72 79 70 74  len.    fs-crypt
14f0: 6b 65 79 20 24 40 20 64 72 6f 70 20 63 3a 6b 65  key $@ drop c:ke
1500: 79 21 0a 20 20 20 20 6d 73 67 28 20 2e 22 20 6f  y!.    msg( ." o
1510: 70 65 6e 20 68 61 73 68 3a 20 22 20 32 64 75 70  pen hash: " 2dup
1520: 20 38 35 74 79 70 65 20 63 72 20 29 0a 20 20 20   85type cr ).   
1530: 20 6b 65 79 65 64 2d 68 61 73 68 2d 6f 75 74 20   keyed-hash-out 
1540: 68 61 73 68 23 31 32 38 20 73 6d 6f 76 65 0a 20  hash#128 smove. 
1550: 20 20 20 65 6e 63 68 61 73 68 20 68 61 73 68 3e     enchash hash>
1560: 66 69 6c 65 6e 61 6d 65 0a 20 20 20 20 6d 73 67  filename.    msg
1570: 28 20 2e 22 20 6f 70 65 6e 20 66 69 6c 65 3a 20  ( ." open file: 
1580: 22 20 32 64 75 70 20 74 79 70 65 20 63 72 20 29  " 2dup type cr )
1590: 0a 20 20 20 20 32 64 75 70 20 66 73 2d 70 61 74  .    2dup fs-pat
15a0: 68 20 24 21 0a 20 20 20 20 72 3e 20 63 3a 6b 65  h $!.    r> c:ke
15b0: 79 21 20 3b 0a 0a 3a 6e 6f 6e 61 6d 65 20 28 20  y! ;..:noname ( 
15c0: 61 64 64 72 20 75 20 6d 6f 64 65 20 2d 2d 20 29  addr u mode -- )
15d0: 20 20 66 73 2d 63 6c 6f 73 65 0a 20 20 20 20 3e    fs-close.    >
15e0: 72 20 68 61 73 68 66 73 3e 66 69 6c 65 20 72 3e  r hashfs>file r>
15f0: 20 6f 70 65 6e 2d 66 69 6c 65 20 74 68 72 6f 77   open-file throw
1600: 20 66 73 2d 66 69 64 20 21 20 66 73 2d 70 6f 6c   fs-fid ! fs-pol
1610: 6c 20 66 73 2d 73 69 7a 65 21 0a 3b 20 68 61 73  l fs-size!.; has
1620: 68 66 73 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d  hfs-class to fs-
1630: 6f 70 65 6e 0a 3a 6e 6f 6e 61 6d 65 20 28 20 61  open.:noname ( a
1640: 64 64 72 20 75 20 2d 2d 20 29 20 20 66 73 2d 63  ddr u -- )  fs-c
1650: 6c 6f 73 65 0a 20 20 20 20 68 61 73 68 66 73 3e  lose.    hashfs>
1660: 66 69 6c 65 20 3e 72 65 6e 61 6d 65 2b 20 72 2f  file >rename+ r/
1670: 77 20 63 72 65 61 74 65 2d 66 69 6c 65 20 74 68  w create-file th
1680: 72 6f 77 20 66 73 2d 66 69 64 20 21 0a 3b 20 68  row fs-fid !.; h
1690: 61 73 68 66 73 2d 63 6c 61 73 73 20 74 6f 20 66  ashfs-class to f
16a0: 73 2d 63 72 65 61 74 65 0a 3a 6e 6f 6e 61 6d 65  s-create.:noname
16b0: 20 28 20 70 65 72 6d 20 2d 2d 20 29 0a 20 20 20   ( perm -- ).   
16c0: 20 70 65 72 6d 25 66 69 6c 65 68 61 73 68 20 61   perm%filehash a
16d0: 6e 64 20 30 3d 20 21 21 66 69 6c 65 68 61 73 68  nd 0= !!filehash
16e0: 2d 70 65 72 6d 21 21 0a 3b 20 68 61 73 68 66 73  -perm!!.; hashfs
16f0: 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 70 65 72  -class to fs-per
1700: 6d 3f 0a 3a 6e 6f 6e 61 6d 65 20 28 20 61 64 64  m?.:noname ( add
1710: 72 20 75 20 2d 2d 20 6e 20 29 0a 20 20 20 20 63  r u -- n ).    c
1720: 3a 6b 65 79 40 20 3e 72 0a 20 20 20 20 6f 76 65  :key@ >r.    ove
1730: 72 20 3e 72 20 66 73 3a 66 73 2d 72 65 61 64 0a  r >r fs:fs-read.
1740: 20 20 20 20 66 73 2d 63 72 79 70 74 6b 65 79 20      fs-cryptkey 
1750: 24 40 20 64 72 6f 70 20 63 3a 6b 65 79 21 0a 20  $@ drop c:key!. 
1760: 20 20 20 72 3e 20 6f 76 65 72 20 63 3a 64 65 63     r> over c:dec
1770: 72 79 70 74 0a 20 20 20 20 72 3e 20 63 3a 6b 65  rypt.    r> c:ke
1780: 79 21 20 3b 20 68 61 73 68 66 73 2d 63 6c 61 73  y! ; hashfs-clas
1790: 73 20 74 6f 20 66 73 2d 72 65 61 64 0a 3a 6e 6f  s to fs-read.:no
17a0: 6e 61 6d 65 20 28 20 61 64 64 72 20 75 20 2d 2d  name ( addr u --
17b0: 20 6e 20 29 0a 20 20 20 20 64 75 70 20 30 3d 20   n ).    dup 0= 
17c0: 49 46 20 20 6e 69 70 20 20 45 58 49 54 20 20 54  IF  nip  EXIT  T
17d0: 48 45 4e 0a 20 20 20 20 24 6d 61 6b 65 20 7b 20  HEN.    $make { 
17e0: 77 5e 20 66 69 6c 65 2d 70 61 64 24 20 7d 20 66  w^ file-pad$ } f
17f0: 69 6c 65 2d 70 61 64 24 20 24 40 0a 20 20 20 20  ile-pad$ $@.    
1800: 63 3a 6b 65 79 40 20 3e 72 20 20 66 73 2d 63 72  c:key@ >r  fs-cr
1810: 79 70 74 6b 65 79 20 24 40 20 64 72 6f 70 20 63  yptkey $@ drop c
1820: 3a 6b 65 79 21 0a 20 20 20 20 32 64 75 70 20 63  :key!.    2dup c
1830: 3a 65 6e 63 72 79 70 74 20 66 73 3a 66 73 2d 77  :encrypt fs:fs-w
1840: 72 69 74 65 20 66 69 6c 65 2d 70 61 64 24 20 24  rite file-pad$ $
1850: 66 72 65 65 0a 20 20 20 20 72 3e 20 63 3a 6b 65  free.    r> c:ke
1860: 79 21 20 3b 20 68 61 73 68 66 73 2d 63 6c 61 73  y! ; hashfs-clas
1870: 73 20 74 6f 20 66 73 2d 77 72 69 74 65 0a 3a 6e  s to fs-write.:n
1880: 6f 6e 61 6d 65 20 28 20 2d 2d 20 29 0a 20 20 20  oname ( -- ).   
1890: 20 66 73 3a 66 73 2d 63 6c 6f 73 65 0a 20 20 20   fs:fs-close.   
18a0: 20 66 73 2d 63 72 79 70 74 6b 65 79 20 24 66 72   fs-cryptkey $fr
18b0: 65 65 20 3b 20 68 61 73 68 66 73 2d 63 6c 61 73  ee ; hashfs-clas
18c0: 73 20 74 6f 20 66 73 2d 63 6c 6f 73 65 0a 0a 5c  s to fs-close..\
18d0: 20 73 75 62 63 6c 61 73 73 69 6e 67 20 66 6f 72   subclassing for
18e0: 20 6f 74 68 65 72 20 73 6f 72 74 73 20 6f 66 20   other sorts of 
18f0: 66 69 6c 65 73 0a 0a 66 73 2d 63 6c 61 73 73 20  files..fs-class 
1900: 63 6c 61 73 73 0a 65 6e 64 2d 63 6c 61 73 73 20  class.end-class 
1910: 73 6f 63 6b 65 74 2d 63 6c 61 73 73 0a 0a 3a 6e  socket-class..:n
1920: 6f 6e 61 6d 65 20 28 20 61 64 64 72 20 75 20 70  oname ( addr u p
1930: 6f 72 74 20 2d 2d 20 29 20 66 73 2d 63 6c 6f 73  ort -- ) fs-clos
1940: 65 20 36 34 3e 6e 0a 20 20 20 20 6d 73 67 28 20  e 64>n.    msg( 
1950: 64 75 70 20 32 6f 76 65 72 20 2e 22 20 6f 70 65  dup 2over ." ope
1960: 6e 20 73 6f 63 6b 65 74 3a 20 22 20 74 79 70 65  n socket: " type
1970: 20 2e 22 20 20 77 69 74 68 20 70 6f 72 74 20 22   ."  with port "
1980: 20 2e 20 63 72 20 29 0a 20 20 20 20 6f 70 65 6e   . cr ).    open
1990: 2d 73 6f 63 6b 65 74 20 66 73 2d 66 69 64 20 21  -socket fs-fid !
19a0: 20 36 34 23 30 20 66 73 2d 73 69 7a 65 21 20 3b   64#0 fs-size! ;
19b0: 0a 64 75 70 20 73 6f 63 6b 65 74 2d 63 6c 61 73  .dup socket-clas
19c0: 73 20 74 6f 20 66 73 2d 6f 70 65 6e 20 20 73 6f  s to fs-open  so
19d0: 63 6b 65 74 2d 63 6c 61 73 73 20 74 6f 20 66 73  cket-class to fs
19e0: 2d 63 72 65 61 74 65 0a 3a 6e 6f 6e 61 6d 65 20  -create.:noname 
19f0: 28 20 2d 2d 20 73 69 7a 65 20 29 0a 20 20 20 20  ( -- size ).    
1a00: 66 73 2d 66 69 64 20 40 20 66 69 6c 65 6e 6f 20  fs-fid @ fileno 
1a10: 63 68 65 63 6b 5f 72 65 61 64 20 64 75 70 20 30  check_read dup 0
1a20: 3c 20 49 46 20 20 2d 35 31 32 20 2b 20 74 68 72  < IF  -512 + thr
1a30: 6f 77 20 20 54 48 45 4e 0a 20 20 20 20 6e 3e 36  ow  THEN.    n>6
1a40: 34 20 66 73 2d 73 69 7a 65 20 36 34 2b 20 3b 20  4 fs-size 64+ ; 
1a50: 73 6f 63 6b 65 74 2d 63 6c 61 73 73 20 74 6f 20  socket-class to 
1a60: 66 73 2d 70 6f 6c 6c 0a 3a 6e 6f 6e 61 6d 65 20  fs-poll.:noname 
1a70: 28 20 70 65 72 6d 20 2d 2d 20 29 0a 20 20 20 20  ( perm -- ).    
1a80: 70 65 72 6d 25 73 6f 63 6b 65 74 20 61 6e 64 20  perm%socket and 
1a90: 30 3d 20 21 21 73 6f 63 6b 65 74 2d 70 65 72 6d  0= !!socket-perm
1aa0: 21 21 0a 3b 20 73 6f 63 6b 65 74 2d 63 6c 61 73  !!.; socket-clas
1ab0: 73 20 74 6f 20 66 73 2d 70 65 72 6d 3f 0a 0a 66  s to fs-perm?..f
1ac0: 73 2d 63 6c 61 73 73 20 63 6c 61 73 73 0a 65 6e  s-class class.en
1ad0: 64 2d 63 6c 61 73 73 20 74 65 72 6d 63 6c 69 65  d-class termclie
1ae0: 6e 74 2d 63 6c 61 73 73 0a 0a 3a 6e 6f 6e 61 6d  nt-class..:nonam
1af0: 65 20 28 20 61 64 64 72 20 75 20 2d 2d 20 75 20  e ( addr u -- u 
1b00: 29 20 74 75 63 6b 20 74 79 70 65 20 3b 20 74 65  ) tuck type ; te
1b10: 72 6d 63 6c 69 65 6e 74 2d 63 6c 61 73 73 20 74  rmclient-class t
1b20: 6f 20 66 73 2d 77 72 69 74 65 0a 3a 6e 6f 6e 61  o fs-write.:nona
1b30: 6d 65 20 28 20 61 64 64 72 20 75 20 2d 2d 20 75  me ( addr u -- u
1b40: 20 29 20 30 20 2d 72 6f 74 20 62 6f 75 6e 64 73   ) 0 -rot bounds
1b50: 20 3f 44 4f 0a 09 6b 65 79 3f 20 30 3d 20 3f 4c   ?DO..key? 0= ?L
1b60: 45 41 56 45 20 20 6b 65 79 20 49 20 63 21 20 31  EAVE  key I c! 1
1b70: 2b 20 20 4c 4f 4f 50 20 3b 20 74 65 72 6d 63 6c  +  LOOP ; termcl
1b80: 69 65 6e 74 2d 63 6c 61 73 73 20 74 6f 20 66 73  ient-class to fs
1b90: 2d 72 65 61 64 0a 3a 6e 6f 6e 61 6d 65 20 28 20  -read.:noname ( 
1ba0: 61 64 64 72 20 75 20 36 34 6e 20 2d 2d 20 29 20  addr u 64n -- ) 
1bb0: 36 34 64 72 6f 70 20 32 64 72 6f 70 20 3b 0a 64  64drop 2drop ;.d
1bc0: 75 70 20 74 65 72 6d 63 6c 69 65 6e 74 2d 63 6c  up termclient-cl
1bd0: 61 73 73 20 74 6f 20 66 73 2d 6f 70 65 6e 20 20  ass to fs-open  
1be0: 74 65 72 6d 63 6c 69 65 6e 74 2d 63 6c 61 73 73  termclient-class
1bf0: 20 74 6f 20 66 73 2d 63 72 65 61 74 65 0a 3a 6e   to fs-create.:n
1c00: 6f 6e 61 6d 65 20 28 20 2d 2d 20 29 20 3b 20 74  oname ( -- ) ; t
1c10: 65 72 6d 63 6c 69 65 6e 74 2d 63 6c 61 73 73 20  ermclient-class 
1c20: 74 6f 20 66 73 2d 63 6c 6f 73 65 0a 3a 6e 6f 6e  to fs-close.:non
1c30: 61 6d 65 20 28 20 70 65 72 6d 20 2d 2d 20 29 0a  ame ( perm -- ).
1c40: 20 20 20 20 70 65 72 6d 25 74 65 72 6d 69 6e 61      perm%termina
1c50: 6c 20 61 6e 64 20 30 3d 20 21 21 74 65 72 6d 69  l and 0= !!termi
1c60: 6e 61 6c 2d 70 65 72 6d 21 21 0a 3b 20 74 65 72  nal-perm!!.; ter
1c70: 6d 63 6c 69 65 6e 74 2d 63 6c 61 73 73 20 74 6f  mclient-class to
1c80: 20 66 73 2d 70 65 72 6d 3f 0a 0a 74 65 72 6d 63   fs-perm?..termc
1c90: 6c 69 65 6e 74 2d 63 6c 61 73 73 20 63 6c 61 73  lient-class clas
1ca0: 73 0a 65 6e 64 2d 63 6c 61 73 73 20 74 65 72 6d  s.end-class term
1cb0: 73 65 72 76 65 72 2d 63 6c 61 73 73 0a 0a 56 61  server-class..Va
1cc0: 72 69 61 62 6c 65 20 74 65 72 6d 73 65 72 76 65  riable termserve
1cd0: 72 2d 74 61 73 6b 73 0a 55 73 65 72 20 74 65 72  r-tasks.User ter
1ce0: 6d 66 69 6c 65 0a 0a 3a 20 74 73 2d 74 79 70 65  mfile..: ts-type
1cf0: 20 28 20 61 64 64 72 20 75 20 2d 2d 20 29 20 74   ( addr u -- ) t
1d00: 65 72 6d 66 69 6c 65 20 40 20 2e 66 73 2d 6f 75  ermfile @ .fs-ou
1d10: 74 62 75 66 20 24 2b 21 20 3b 0a 3a 20 74 73 2d  tbuf $+! ;.: ts-
1d20: 65 6d 69 74 20 28 20 63 20 2d 2d 20 29 20 74 65  emit ( c -- ) te
1d30: 72 6d 66 69 6c 65 20 40 20 2e 66 73 2d 6f 75 74  rmfile @ .fs-out
1d40: 62 75 66 20 63 24 2b 21 20 3b 0a 3a 20 74 73 2d  buf c$+! ;.: ts-
1d50: 66 6f 72 6d 20 28 20 2d 2d 20 77 20 68 20 29 20  form ( -- w h ) 
1d60: 74 65 72 6d 66 69 6c 65 20 40 20 3e 6f 20 74 65  termfile @ >o te
1d70: 72 6d 2d 77 20 40 20 74 65 72 6d 2d 68 20 40 20  rm-w @ term-h @ 
1d80: 6f 3e 20 3b 0a 3a 20 74 73 2d 6b 65 79 3f 20 28  o> ;.: ts-key? (
1d90: 20 2d 2d 20 66 6c 61 67 20 29 20 74 65 72 6d 66   -- flag ) termf
1da0: 69 6c 65 20 40 20 2e 66 73 2d 69 6e 62 75 66 20  ile @ .fs-inbuf 
1db0: 24 40 6c 65 6e 20 30 3c 3e 20 3b 0a 3a 20 74 73  $@len 0<> ;.: ts
1dc0: 2d 6b 65 79 20 28 20 2d 2d 20 6b 65 79 20 29 0a  -key ( -- key ).
1dd0: 20 20 20 20 42 45 47 49 4e 20 20 74 73 2d 6b 65      BEGIN  ts-ke
1de0: 79 3f 20 30 3d 20 20 57 48 49 4c 45 20 20 73 74  y? 0=  WHILE  st
1df0: 6f 70 20 20 52 45 50 45 41 54 0a 20 20 20 20 74  op  REPEAT.    t
1e00: 65 72 6d 66 69 6c 65 20 40 20 3e 6f 20 66 73 2d  ermfile @ >o fs-
1e10: 69 6e 62 75 66 20 24 40 20 64 72 6f 70 20 63 40  inbuf $@ drop c@
1e20: 20 66 73 2d 69 6e 62 75 66 20 30 20 31 20 24 64   fs-inbuf 0 1 $d
1e30: 65 6c 20 6f 3e 20 3b 0a 0a 27 20 74 73 2d 74 79  el o> ;..' ts-ty
1e40: 70 65 20 27 20 74 73 2d 65 6d 69 74 20 77 68 61  pe ' ts-emit wha
1e50: 74 27 73 20 63 72 20 27 20 74 73 2d 66 6f 72 6d  t's cr ' ts-form
1e60: 20 6f 75 74 70 75 74 3a 20 74 65 72 6d 73 65 72   output: termser
1e70: 76 65 72 2d 6f 75 74 0a 77 68 61 74 27 73 20 6e  ver-out.what's n
1e80: 61 6d 65 0a 6f 70 2d 76 65 63 74 6f 72 20 40 0a  ame.op-vector @.
1e90: 77 68 61 74 27 73 20 61 74 2d 78 79 20 77 68 61  what's at-xy wha
1ea0: 74 27 73 20 61 74 2d 64 65 6c 74 61 78 79 20 77  t's at-deltaxy w
1eb0: 68 61 74 27 73 20 70 61 67 65 20 77 68 61 74 27  hat's page what'
1ec0: 73 20 61 74 74 72 21 0a 5b 49 46 44 45 46 5d 20  s attr!.[IFDEF] 
1ed0: 6e 6f 74 72 61 63 65 20 6e 6f 74 72 61 63 65 20  notrace notrace 
1ee0: 5b 54 48 45 4e 5d 0a 74 65 72 6d 73 65 72 76 65  [THEN].termserve
1ef0: 72 2d 6f 75 74 0a 49 53 20 61 74 74 72 21 20 49  r-out.IS attr! I
1f00: 53 20 70 61 67 65 20 49 53 20 61 74 2d 64 65 6c  S page IS at-del
1f10: 74 61 78 79 20 49 53 20 61 74 2d 78 79 0a 6f 70  taxy IS at-xy.op
1f20: 2d 76 65 63 74 6f 72 20 21 0a 69 73 20 6e 61 6d  -vector !.is nam
1f30: 65 0a 27 20 74 73 2d 6b 65 79 20 20 27 20 74 73  e.' ts-key  ' ts
1f40: 2d 6b 65 79 3f 20 69 6e 70 75 74 3a 20 74 65 72  -key? input: ter
1f50: 6d 73 65 72 76 65 72 2d 69 6e 0a 5b 49 46 44 45  mserver-in.[IFDE
1f60: 46 5d 20 74 72 61 63 65 61 6c 6c 20 74 72 61 63  F] traceall trac
1f70: 65 61 6c 6c 20 5b 54 48 45 4e 5d 0a 0a 3a 20 3e  eall [THEN]..: >
1f80: 74 65 72 6d 73 65 72 76 65 72 2d 69 6f 20 28 20  termserver-io ( 
1f90: 2d 2d 20 29 0a 20 20 20 20 5b 3a 20 75 70 40 20  -- ).    [: up@ 
1fa0: 7b 20 77 5e 20 74 20 7d 20 74 20 63 65 6c 6c 20  { w^ t } t cell 
1fb0: 74 65 72 6d 73 65 72 76 65 72 2d 74 61 73 6b 73  termserver-tasks
1fc0: 20 24 2b 21 20 3b 5d 20 66 69 6c 65 2d 73 65 6d   $+! ;] file-sem
1fd0: 61 20 63 2d 73 65 63 74 69 6f 6e 20 3b 0a 0a 65  a c-section ;..e
1fe0: 76 65 6e 74 3a 20 3a 3e 74 65 72 6d 66 69 6c 65  vent: :>termfile
1ff0: 20 28 20 6f 20 2d 2d 20 29 20 64 75 70 20 74 65   ( o -- ) dup te
2000: 72 6d 66 69 6c 65 20 21 20 3e 6f 20 66 6f 72 6d  rmfile ! >o form
2010: 20 74 65 72 6d 2d 77 20 21 20 74 65 72 6d 2d 68   term-w ! term-h
2020: 20 21 20 6f 3e 0a 20 20 20 20 74 65 72 6d 73 65   ! o>.    termse
2030: 72 76 65 72 2d 69 6e 20 74 65 72 6d 73 65 72 76  rver-in termserv
2040: 65 72 2d 6f 75 74 20 3b 0a 65 76 65 6e 74 3a 20  er-out ;.event: 
2050: 3a 3e 74 65 72 6d 63 6c 6f 73 65 20 28 20 2d 2d  :>termclose ( --
2060: 20 29 20 74 65 72 6d 66 69 6c 65 20 6f 66 66 20   ) termfile off 
2070: 20 64 65 66 61 75 6c 74 2d 69 6e 20 64 65 66 61   default-in defa
2080: 75 6c 74 2d 6f 75 74 20 3b 0a 0a 3a 6e 6f 6e 61  ult-out ;..:nona
2090: 6d 65 20 28 20 61 64 64 72 20 75 20 2d 2d 20 75  me ( addr u -- u
20a0: 20 29 0a 20 20 20 20 64 75 70 20 30 3d 20 49 46   ).    dup 0= IF
20b0: 20 20 6e 69 70 20 20 45 58 49 54 20 20 54 48 45    nip  EXIT  THE
20c0: 4e 0a 20 20 20 20 66 73 2d 6c 69 6d 69 74 20 36  N.    fs-limit 6
20d0: 34 3e 6e 20 66 73 2d 69 6e 62 75 66 20 24 40 6c  4>n fs-inbuf $@l
20e0: 65 6e 20 2d 20 6d 69 6e 20 20 74 75 63 6b 20 66  en - min  tuck f
20f0: 73 2d 69 6e 62 75 66 20 24 2b 21 0a 20 20 20 20  s-inbuf $+!.    
2100: 66 73 2d 73 69 7a 65 20 66 73 2d 69 6e 62 75 66  fs-size fs-inbuf
2110: 20 24 40 6c 65 6e 20 75 3e 36 34 20 36 34 3d 20   $@len u>64 64= 
2120: 66 73 2d 69 6e 62 75 66 20 24 40 6c 65 6e 20 30  fs-inbuf $@len 0
2130: 3c 3e 20 61 6e 64 20 49 46 0a 09 3c 65 76 65 6e  <> and IF..<even
2140: 74 20 6f 20 65 6c 69 74 2c 20 3a 3e 66 69 6c 65  t o elit, :>file
2150: 2d 64 6f 6e 65 20 70 61 72 65 6e 74 20 2e 77 61  -done parent .wa
2160: 69 74 2d 74 61 73 6b 20 40 20 65 76 65 6e 74 3e  it-task @ event>
2170: 0a 20 20 20 20 54 48 45 4e 20 3b 20 74 65 72 6d  .    THEN ; term
2180: 73 65 72 76 65 72 2d 63 6c 61 73 73 20 74 6f 20  server-class to 
2190: 66 73 2d 77 72 69 74 65 0a 3a 6e 6f 6e 61 6d 65  fs-write.:noname
21a0: 20 28 20 61 64 64 72 20 75 20 2d 2d 20 75 20 29   ( addr u -- u )
21b0: 20 66 73 2d 6f 75 74 62 75 66 20 24 40 6c 65 6e   fs-outbuf $@len
21c0: 20 75 6d 69 6e 20 3e 72 0a 20 20 20 20 66 73 2d   umin >r.    fs-
21d0: 6f 75 74 62 75 66 20 24 40 20 72 40 20 75 6d 69  outbuf $@ r@ umi
21e0: 6e 20 72 6f 74 20 73 77 61 70 20 6d 6f 76 65 0a  n rot swap move.
21f0: 20 20 20 20 66 73 2d 6f 75 74 62 75 66 20 30 20      fs-outbuf 0 
2200: 72 40 20 24 64 65 6c 20 72 3e 20 3b 20 74 65 72  r@ $del r> ; ter
2210: 6d 73 65 72 76 65 72 2d 63 6c 61 73 73 20 74 6f  mserver-class to
2220: 20 66 73 2d 72 65 61 64 0a 3a 6e 6f 6e 61 6d 65   fs-read.:noname
2230: 20 28 20 61 64 64 72 20 75 20 36 34 6e 20 2d 2d   ( addr u 64n --
2240: 20 29 20 20 36 34 64 72 6f 70 20 32 64 72 6f 70   )  64drop 2drop
2250: 0a 20 20 20 20 5b 3a 20 74 65 72 6d 73 65 72 76  .    [: termserv
2260: 65 72 2d 74 61 73 6b 73 20 24 40 20 30 3d 20 21  er-tasks $@ 0= !
2270: 21 6e 6f 2d 74 65 72 6d 73 65 72 76 65 72 21 21  !no-termserver!!
2280: 0a 09 40 20 74 65 72 6d 73 65 72 76 65 72 2d 74  ..@ termserver-t
2290: 61 73 6b 73 20 30 20 63 65 6c 6c 20 24 64 65 6c  asks 0 cell $del
22a0: 20 64 75 70 20 66 73 2d 74 65 72 6d 74 61 73 6b   dup fs-termtask
22b0: 20 21 0a 09 3c 65 76 65 6e 74 20 6f 20 65 6c 69   !..<event o eli
22c0: 74 2c 20 3a 3e 74 65 72 6d 66 69 6c 65 20 65 76  t, :>termfile ev
22d0: 65 6e 74 3e 0a 20 20 20 20 3b 5d 20 66 69 6c 65  ent>.    ;] file
22e0: 2d 73 65 6d 61 20 63 2d 73 65 63 74 69 6f 6e 0a  -sema c-section.
22f0: 3b 20 64 75 70 20 74 65 72 6d 73 65 72 76 65 72  ; dup termserver
2300: 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 6f 70 65  -class to fs-ope
2310: 6e 20 20 74 65 72 6d 73 65 72 76 65 72 2d 63 6c  n  termserver-cl
2320: 61 73 73 20 74 6f 20 66 73 2d 63 72 65 61 74 65  ass to fs-create
2330: 0a 3a 6e 6f 6e 61 6d 65 20 28 20 2d 2d 20 29 0a  .:noname ( -- ).
2340: 20 20 20 20 5b 3a 20 66 73 2d 74 65 72 6d 74 61      [: fs-termta
2350: 73 6b 20 40 20 3f 64 75 70 2d 49 46 0a 09 20 20  sk @ ?dup-IF..  
2360: 20 20 3c 65 76 65 6e 74 20 3a 3e 74 65 72 6d 63    <event :>termc
2370: 6c 6f 73 65 20 65 76 65 6e 74 3e 0a 09 20 20 20  lose event>..   
2380: 20 66 73 2d 74 65 72 6d 74 61 73 6b 20 63 65 6c   fs-termtask cel
2390: 6c 20 74 65 72 6d 73 65 72 76 65 72 2d 74 61 73  l termserver-tas
23a0: 6b 73 20 24 2b 21 20 66 73 2d 74 65 72 6d 74 61  ks $+! fs-termta
23b0: 73 6b 20 6f 66 66 0a 09 54 48 45 4e 20 3b 5d 20  sk off..THEN ;] 
23c0: 66 69 6c 65 2d 73 65 6d 61 20 63 2d 73 65 63 74  file-sema c-sect
23d0: 69 6f 6e 0a 3b 20 74 65 72 6d 73 65 72 76 65 72  ion.; termserver
23e0: 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 63 6c 6f  -class to fs-clo
23f0: 73 65 0a 3a 6e 6f 6e 61 6d 65 20 28 20 70 65 72  se.:noname ( per
2400: 6d 20 2d 2d 20 29 0a 20 20 20 20 70 65 72 6d 25  m -- ).    perm%
2410: 74 65 72 6d 73 65 72 76 65 72 20 61 6e 64 20 30  termserver and 0
2420: 3d 20 21 21 74 65 72 6d 73 65 72 76 65 72 2d 70  = !!termserver-p
2430: 65 72 6d 21 21 0a 3b 20 74 65 72 6d 73 65 72 76  erm!!.; termserv
2440: 65 72 2d 63 6c 61 73 73 20 74 6f 20 66 73 2d 70  er-class to fs-p
2450: 65 72 6d 3f 0a 0a 43 72 65 61 74 65 20 66 69 6c  erm?..Create fil
2460: 65 2d 63 6c 61 73 73 65 73 0a 66 73 2d 63 6c 61  e-classes.fs-cla
2470: 73 73 20 2c 0a 68 61 73 68 66 73 2d 63 6c 61 73  ss ,.hashfs-clas
2480: 73 20 2c 0a 73 6f 63 6b 65 74 2d 63 6c 61 73 73  s ,.socket-class
2490: 20 2c 0a 74 65 72 6d 63 6c 69 65 6e 74 2d 63 6c   ,.termclient-cl
24a0: 61 73 73 20 2c 0a 74 65 72 6d 73 65 72 76 65 72  ass ,.termserver
24b0: 2d 63 6c 61 73 73 20 2c 0a 0a 68 65 72 65 20 66  -class ,..here f
24c0: 69 6c 65 2d 63 6c 61 73 73 65 73 20 2d 20 63 65  ile-classes - ce
24d0: 6c 6c 2f 0a 24 31 30 20 6f 76 65 72 20 2d 20 63  ll/.$10 over - c
24e0: 65 6c 6c 73 20 61 6c 6c 6f 74 0a 0a 56 61 6c 75  ells allot..Valu
24f0: 65 20 66 69 6c 65 2d 63 6c 61 73 73 65 73 23 0a  e file-classes#.
2500: 0a 3a 20 66 73 2d 63 6c 61 73 73 21 20 28 20 6e  .: fs-class! ( n
2510: 20 2d 2d 20 29 0a 20 20 20 20 64 75 70 20 66 69   -- ).    dup fi
2520: 6c 65 2d 63 6c 61 73 73 65 73 23 20 75 3e 3d 20  le-classes# u>= 
2530: 21 21 66 69 6c 65 63 6c 61 73 73 21 21 0a 20 20  !!fileclass!!.  
2540: 20 20 63 65 6c 6c 73 20 66 69 6c 65 2d 63 6c 61    cells file-cla
2550: 73 73 65 73 20 2b 20 40 20 6f 20 63 65 6c 6c 2d  sses + @ o cell-
2560: 20 21 20 3b 0a 0a 3a 20 2b 66 69 6c 65 2d 63 6c   ! ;..: +file-cl
2570: 61 73 73 65 73 20 28 20 61 64 64 72 20 2d 2d 20  asses ( addr -- 
2580: 29 0a 20 20 20 20 66 69 6c 65 2d 63 6c 61 73 73  ).    file-class
2590: 65 73 20 66 69 6c 65 2d 63 6c 61 73 73 65 73 23  es file-classes#
25a0: 20 64 75 70 20 31 2b 20 74 6f 20 66 69 6c 65 2d   dup 1+ to file-
25b0: 63 6c 61 73 73 65 73 23 20 63 65 6c 6c 73 20 2b  classes# cells +
25c0: 20 21 20 3b 0a 0a 5c 20 73 74 61 74 65 20 68 61   ! ;..\ state ha
25d0: 6e 64 6c 69 6e 67 0a 0a 73 63 6f 70 65 7b 20 6d  ndling..scope{ m
25e0: 61 70 63 0a 0a 3a 20 64 65 73 74 2d 74 6f 70 21  apc..: dest-top!
25f0: 20 28 20 61 64 64 72 20 2d 2d 20 29 0a 20 20 20   ( addr -- ).   
2600: 20 64 75 70 20 64 75 70 20 64 65 73 74 2d 74 6f   dup dup dest-to
2610: 70 20 55 2b 44 4f 0a 09 64 61 74 61 2d 61 63 6b  p U+DO..data-ack
2620: 62 69 74 73 20 40 20 49 20 49 27 20 66 69 78 2d  bits @ I I' fix-
2630: 73 69 7a 65 20 64 75 70 20 7b 20 6c 65 6e 20 7d  size dup { len }
2640: 0a 09 63 68 75 6e 6b 2d 70 32 20 72 73 68 69 66  ..chunk-p2 rshif
2650: 74 20 73 77 61 70 20 63 68 75 6e 6b 2d 70 32 20  t swap chunk-p2 
2660: 72 73 68 69 66 74 20 73 77 61 70 20 62 69 74 2d  rshift swap bit-
2670: 65 72 61 73 65 0a 20 20 20 20 6c 65 6e 20 2b 4c  erase.    len +L
2680: 4f 4f 50 20 20 74 6f 20 64 65 73 74 2d 74 6f 70  OOP  to dest-top
2690: 20 3b 0a 0a 3a 20 61 63 6b 62 69 74 73 2d 65 72   ;..: ackbits-er
26a0: 61 73 65 20 28 20 6f 6c 64 62 61 63 6b 20 6e 65  ase ( oldback ne
26b0: 77 62 61 63 6b 20 2d 2d 20 29 0a 20 20 20 20 73  wback -- ).    s
26c0: 77 61 70 20 55 2b 44 4f 0a 09 64 61 74 61 2d 61  wap U+DO..data-a
26d0: 63 6b 62 69 74 73 20 40 20 49 20 49 27 20 66 69  ckbits @ I I' fi
26e0: 78 2d 73 69 7a 65 20 64 75 70 20 7b 20 6c 65 6e  x-size dup { len
26f0: 20 7d 0a 09 63 68 75 6e 6b 2d 70 32 20 72 73 68   }..chunk-p2 rsh
2700: 69 66 74 20 73 77 61 70 20 63 68 75 6e 6b 2d 70  ift swap chunk-p
2710: 32 20 72 73 68 69 66 74 20 73 77 61 70 20 62 69  2 rshift swap bi
2720: 74 2d 66 69 6c 6c 0a 20 20 20 20 6c 65 6e 20 2b  t-fill.    len +
2730: 4c 4f 4f 50 20 3b 0a 0a 7d 73 63 6f 70 65 0a 0a  LOOP ;..}scope..
2740: 3a 20 73 69 7a 65 21 20 28 20 36 34 20 2d 2d 20  : size! ( 64 -- 
2750: 29 0a 20 20 20 20 36 34 64 75 70 20 74 6f 20 66  ).    64dup to f
2760: 73 2d 73 69 7a 65 20 20 61 64 64 72 20 66 73 2d  s-size  addr fs-
2770: 6c 69 6d 69 74 20 36 34 75 6d 69 6e 21 20 3b 0a  limit 64umin! ;.
2780: 3a 20 73 65 65 6b 2d 6f 66 66 20 28 20 2d 2d 20  : seek-off ( -- 
2790: 29 0a 20 20 20 20 36 34 23 30 20 74 6f 20 66 73  ).    64#0 to fs
27a0: 2d 73 65 65 6b 74 6f 20 36 34 23 30 20 74 6f 20  -seekto 64#0 to 
27b0: 66 73 2d 73 65 65 6b 20 3b 0a 3a 20 73 65 65 6b  fs-seek ;.: seek
27c0: 74 6f 21 20 28 20 36 34 20 2d 2d 20 29 0a 20 20  to! ( 64 -- ).  
27d0: 20 20 66 73 2d 73 69 7a 65 20 36 34 75 6d 69 6e    fs-size 64umin
27e0: 20 61 64 64 72 20 66 73 2d 73 65 65 6b 74 6f 20   addr fs-seekto 
27f0: 36 34 75 6d 61 78 21 20 3b 0a 3a 20 6c 69 6d 69  64umax! ;.: limi
2800: 74 2d 6d 69 6e 21 20 28 20 36 34 20 69 64 20 2d  t-min! ( 64 id -
2810: 2d 20 29 0a 20 20 20 20 66 73 2d 73 69 7a 65 20  - ).    fs-size 
2820: 36 34 75 6d 69 6e 20 74 6f 20 66 73 2d 6c 69 6d  64umin to fs-lim
2830: 69 74 20 3b 0a 3a 20 69 6e 69 74 2d 6c 69 6d 69  it ;.: init-limi
2840: 74 21 20 28 20 36 34 20 69 64 20 2d 2d 20 29 20  t! ( 64 id -- ) 
2850: 20 73 74 61 74 65 2d 61 64 64 72 20 3e 6f 20 74   state-addr >o t
2860: 6f 20 66 73 2d 6c 69 6d 69 74 20 6f 3e 20 3b 0a  o fs-limit o> ;.
2870: 3a 20 70 6f 6c 6c 21 20 28 20 36 34 20 2d 2d 20  : poll! ( 64 -- 
2880: 36 34 20 29 0a 20 20 20 20 74 6f 20 66 73 2d 6c  64 ).    to fs-l
2890: 69 6d 69 74 20 66 73 2d 70 6f 6c 6c 20 36 34 64  imit fs-poll 64d
28a0: 75 70 20 73 69 7a 65 21 20 3b 0a 0a 3a 20 66 69  up size! ;..: fi
28b0: 6c 65 2b 20 28 20 61 64 64 72 20 2d 2d 20 29 20  le+ ( addr -- ) 
28c0: 3e 72 20 31 20 72 40 20 2b 21 0a 20 20 20 20 72  >r 1 r@ +!.    r
28d0: 40 20 40 20 69 64 3e 61 64 64 72 20 6e 69 70 20  @ @ id>addr nip 
28e0: 30 3c 3d 20 49 46 20 20 72 40 20 6f 66 66 20 20  0<= IF  r@ off  
28f0: 54 48 45 4e 20 20 72 64 72 6f 70 20 3b 0a 0a 3a  THEN  rdrop ;..:
2900: 20 66 73 74 61 74 65 73 20 28 20 2d 2d 20 6e 20   fstates ( -- n 
2910: 29 20 20 66 69 6c 65 2d 73 74 61 74 65 20 24 40  )  file-state $@
2920: 6c 65 6e 20 63 65 6c 6c 2f 20 3b 0a 0a 56 61 72  len cell/ ;..Var
2930: 69 61 62 6c 65 20 66 2d 72 69 64 20 2d 31 20 66  iable f-rid -1 f
2940: 2d 72 69 64 20 21 0a 56 61 72 69 61 62 6c 65 20  -rid !.Variable 
2950: 66 2d 72 61 6d 6f 75 6e 74 0a 56 61 72 69 61 62  f-ramount.Variab
2960: 6c 65 20 66 2d 77 69 64 20 2d 31 20 66 2d 77 69  le f-wid -1 f-wi
2970: 64 20 21 0a 56 61 72 69 61 62 6c 65 20 66 2d 77  d !.Variable f-w
2980: 61 6d 6f 75 6e 74 0a 0a 3a 20 66 73 74 61 74 65  amount..: fstate
2990: 73 2d 66 72 65 65 20 28 20 2d 2d 20 29 0a 20 20  s-free ( -- ).  
29a0: 20 20 20 66 69 6c 65 2d 73 74 61 74 65 20 24 40     file-state $@
29b0: 20 62 6f 75 6e 64 73 20 3f 44 4f 20 20 49 20 40   bounds ?DO  I @
29c0: 20 2e 64 69 73 70 6f 73 65 20 20 63 65 6c 6c 20   .dispose  cell 
29d0: 2b 4c 4f 4f 50 20 3b 0a 3a 20 66 73 74 61 74 65  +LOOP ;.: fstate
29e0: 2d 66 72 65 65 20 28 20 2d 2d 20 29 20 20 66 69  -free ( -- )  fi
29f0: 6c 65 2d 73 74 61 74 65 20 40 20 30 3d 20 3f 45  le-state @ 0= ?E
2a00: 58 49 54 0a 20 20 20 20 5b 3a 20 66 73 74 61 74  XIT.    [: fstat
2a10: 65 73 2d 66 72 65 65 20 66 69 6c 65 2d 73 74 61  es-free file-sta
2a20: 74 65 20 24 66 72 65 65 20 3b 5d 20 66 69 6c 65  te $free ;] file
2a30: 2d 73 65 6d 61 20 63 2d 73 65 63 74 69 6f 6e 20  -sema c-section 
2a40: 3b 0a 69 6e 20 6e 65 74 32 6f 20 3a 20 73 61 76  ;.in net2o : sav
2a50: 65 2d 62 6c 6f 63 6b 20 28 20 62 61 63 6b 20 74  e-block ( back t
2a60: 61 69 6c 20 69 64 20 2d 2d 20 64 65 6c 74 61 20  ail id -- delta 
2a70: 29 20 7b 20 69 64 20 2d 2d 20 64 65 6c 74 61 20  ) { id -- delta 
2a80: 7d 0a 20 20 20 20 64 61 74 61 2d 72 6d 61 70 20  }.    data-rmap 
2a90: 77 69 74 68 20 6d 61 70 63 20 66 69 78 2d 73 69  with mapc fix-si
2aa0: 7a 65 20 72 61 64 64 72 2b 20 65 6e 64 77 69 74  ze raddr+ endwit
2ab0: 68 20 72 65 73 69 64 75 61 6c 77 72 69 74 65 20  h residualwrite 
2ac0: 40 20 75 6d 69 6e 0a 20 20 20 20 69 64 20 69 64  @ umin.    id id
2ad0: 3e 61 64 64 72 3f 20 2e 66 73 2d 77 72 69 74 65  >addr? .fs-write
2ae0: 0a 20 20 20 20 66 69 6c 65 31 28 20 69 64 20 66  .    file1( id f
2af0: 2d 77 69 64 20 40 20 3d 20 49 46 20 20 64 75 70  -wid @ = IF  dup
2b00: 20 66 2d 77 61 6d 6f 75 6e 74 20 2b 21 0a 20 20   f-wamount +!.  
2b10: 20 20 45 4c 53 45 20 20 66 2d 77 69 64 20 40 20    ELSE  f-wid @ 
2b20: 30 3e 3d 20 66 2d 77 61 6d 6f 75 6e 74 20 40 20  0>= f-wamount @ 
2b30: 30 3e 20 61 6e 64 20 49 46 0a 09 20 20 20 20 2e  0> and IF..    .
2b40: 22 20 73 70 6c 69 74 3a 20 22 20 66 2d 77 69 64  " split: " f-wid
2b50: 20 40 20 2e 20 66 2d 77 61 6d 6f 75 6e 74 20 40   @ . f-wamount @
2b60: 20 68 65 78 2e 20 63 72 20 20 54 48 45 4e 0a 20   hex. cr  THEN. 
2b70: 20 20 20 20 20 20 20 69 64 20 66 2d 77 69 64 20         id f-wid 
2b80: 21 20 64 75 70 20 66 2d 77 61 6d 6f 75 6e 74 20  ! dup f-wamount 
2b90: 21 20 20 54 48 45 4e 20 29 0a 20 20 20 20 3e 62  !  THEN ).    >b
2ba0: 6c 6f 63 6b 61 6c 69 67 6e 20 64 75 70 20 6e 65  lockalign dup ne
2bb0: 67 61 74 65 20 72 65 73 69 64 75 61 6c 77 72 69  gate residualwri
2bc0: 74 65 20 2b 21 20 3b 0a 0a 5c 20 63 61 72 65 66  te +! ;..\ caref
2bd0: 75 6c 3a 20 6d 75 73 74 20 66 6f 6c 6c 6f 77 20  ul: must follow 
2be0: 65 78 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65  exactly the same
2bf0: 20 6c 6f 67 69 63 20 61 73 20 73 6c 75 72 70 20   logic as slurp 
2c00: 28 73 65 65 20 62 65 6c 6f 77 29 0a 0a 69 6e 20  (see below)..in 
2c10: 6e 65 74 32 6f 20 3a 20 73 70 69 74 20 7b 20 62  net2o : spit { b
2c20: 61 63 6b 20 74 61 69 6c 20 2d 2d 20 6e 65 77 62  ack tail -- newb
2c30: 61 63 6b 20 7d 0a 20 20 20 20 62 61 63 6b 20 74  ack }.    back t
2c40: 61 69 6c 20 62 61 63 6b 20 75 3c 3d 20 3f 45 58  ail back u<= ?EX
2c50: 49 54 20 66 73 74 61 74 65 73 20 30 3d 20 3f 45  IT fstates 0= ?E
2c60: 58 49 54 20 64 72 6f 70 0a 20 20 20 20 73 6c 75  XIT drop.    slu
2c70: 72 70 28 20 2e 22 20 73 70 69 74 3a 20 22 20 74  rp( ." spit: " t
2c80: 61 69 6c 20 72 64 61 74 61 2d 62 61 63 6b 40 20  ail rdata-back@ 
2c90: 64 72 6f 70 20 64 61 74 61 2d 72 6d 61 70 20 77  drop data-rmap w
2ca0: 69 74 68 20 6d 61 70 63 20 64 65 73 74 2d 72 61  ith mapc dest-ra
2cb0: 64 64 72 20 2d 20 65 6e 64 77 69 74 68 20 68 65  ddr - endwith he
2cc0: 78 2e 0a 20 20 20 20 77 72 69 74 65 2d 66 69 6c  x..    write-fil
2cd0: 65 23 20 3f 20 72 65 73 69 64 75 61 6c 77 72 69  e# ? residualwri
2ce0: 74 65 20 40 20 68 65 78 2e 20 66 6f 72 74 68 3a  te @ hex. forth:
2cf0: 63 72 20 29 20 62 61 63 6b 20 74 61 69 6c 0a 20  cr ) back tail. 
2d00: 20 20 20 5b 3a 20 2b 63 61 6c 63 20 66 73 74 61     [: +calc fsta
2d10: 74 65 73 20 30 20 7b 20 62 61 63 6b 20 74 61 69  tes 0 { back tai
2d20: 6c 20 73 74 61 74 65 73 20 66 61 69 6c 73 20 7d  l states fails }
2d30: 0a 09 42 45 47 49 4e 20 20 74 61 69 6c 20 62 61  ..BEGIN  tail ba
2d40: 63 6b 20 75 3e 20 20 57 48 49 4c 45 0a 09 09 62  ck u>  WHILE...b
2d50: 61 63 6b 20 74 61 69 6c 20 77 72 69 74 65 2d 66  ack tail write-f
2d60: 69 6c 65 23 20 40 20 6e 65 74 32 6f 3a 73 61 76  ile# @ net2o:sav
2d70: 65 2d 62 6c 6f 63 6b 20 64 75 70 20 2b 74 6f 20  e-block dup +to 
2d80: 62 61 63 6b 0a 09 09 49 46 20 30 20 45 4c 53 45  back...IF 0 ELSE
2d90: 20 66 61 69 6c 73 20 31 2b 20 72 65 73 69 64 75   fails 1+ residu
2da0: 61 6c 77 72 69 74 65 20 6f 66 66 20 54 48 45 4e  alwrite off THEN
2db0: 20 74 6f 20 66 61 69 6c 73 0a 09 09 72 65 73 69   to fails...resi
2dc0: 64 75 61 6c 77 72 69 74 65 20 40 20 30 3d 20 49  dualwrite @ 0= I
2dd0: 46 0a 09 09 20 20 20 20 77 72 69 74 65 2d 66 69  F...    write-fi
2de0: 6c 65 23 20 66 69 6c 65 2b 20 62 6c 6f 63 6b 73  le# file+ blocks
2df0: 69 7a 65 20 40 20 72 65 73 69 64 75 61 6c 77 72  ize @ residualwr
2e00: 69 74 65 20 21 20 20 54 48 45 4e 0a 09 20 20 20  ite !  THEN..   
2e10: 20 66 61 69 6c 73 20 73 74 61 74 65 73 20 75 3e   fails states u>
2e20: 3d 20 55 4e 54 49 4c 0a 09 54 48 45 4e 0a 09 6d  = UNTIL..THEN..m
2e30: 73 67 28 20 2e 22 20 57 72 69 74 65 20 65 6e 64  sg( ." Write end
2e40: 22 20 63 72 20 29 20 2b 66 69 6c 65 0a 09 62 61  " cr ) +file..ba
2e50: 63 6b 20 20 66 61 69 6c 73 20 73 74 61 74 65 73  ck  fails states
2e60: 20 75 3e 3d 20 49 46 20 20 3e 6d 61 78 61 6c 69   u>= IF  >maxali
2e70: 67 6e 20 20 54 48 45 4e 20 20 5c 20 69 66 20 61  gn  THEN  \ if a
2e80: 6c 6c 20 66 69 6c 65 73 20 61 72 65 20 64 6f 6e  ll files are don
2e90: 65 2c 20 61 6c 69 67 6e 0a 20 20 20 20 3b 5d 20  e, align.    ;] 
2ea0: 66 69 6c 65 2d 73 65 6d 61 20 63 2d 73 65 63 74  file-sema c-sect
2eb0: 69 6f 6e 0a 20 20 20 20 73 6c 75 72 70 28 20 2e  ion.    slurp( .
2ec0: 22 20 20 6c 65 66 74 3a 20 22 20 74 61 69 6c 20  "  left: " tail 
2ed0: 72 64 61 74 61 2d 62 61 63 6b 40 20 64 72 6f 70  rdata-back@ drop
2ee0: 20 64 61 74 61 2d 72 6d 61 70 20 77 69 74 68 20   data-rmap with 
2ef0: 6d 61 70 63 20 64 65 73 74 2d 72 61 64 64 72 20  mapc dest-raddr 
2f00: 2d 20 65 6e 64 77 69 74 68 20 68 65 78 2e 0a 20  - endwith hex.. 
2f10: 20 20 20 77 72 69 74 65 2d 66 69 6c 65 23 20 3f     write-file# ?
2f20: 20 72 65 73 69 64 75 61 6c 77 72 69 74 65 20 40   residualwrite @
2f30: 20 68 65 78 2e 20 66 6f 72 74 68 3a 63 72 20 29   hex. forth:cr )
2f40: 20 3b 0a 0a 3a 20 73 61 76 65 2d 74 6f 20 28 20   ;..: save-to ( 
2f50: 61 64 64 72 20 75 20 6e 20 2d 2d 20 29 20 20 73  addr u n -- )  s
2f60: 74 61 74 65 2d 61 64 64 72 20 2e 66 73 2d 63 72  tate-addr .fs-cr
2f70: 65 61 74 65 20 3b 0a 3a 20 73 61 76 65 2d 74 6f  eate ;.: save-to
2f80: 23 20 28 20 61 64 64 72 20 75 20 6e 20 2d 2d 20  # ( addr u n -- 
2f90: 29 20 20 73 74 61 74 65 2d 61 64 64 72 20 3e 6f  )  state-addr >o
2fa0: 20 20 31 20 66 73 2d 63 6c 61 73 73 21 20 20 66    1 fs-class!  f
2fb0: 73 2d 63 72 65 61 74 65 20 6f 3e 20 3b 0a 0a 5c  s-create o> ;..\
2fc0: 20 66 69 6c 65 20 73 74 61 74 75 73 20 73 74 75   file status stu
2fd0: 66 66 0a 0a 73 63 6f 70 65 7b 20 6e 65 74 32 6f  ff..scope{ net2o
2fe0: 0a 0a 3a 20 67 65 74 2d 73 74 61 74 20 28 20 2d  ..: get-stat ( -
2ff0: 2d 20 6d 74 69 6d 65 20 6d 6f 64 20 29 0a 20 20  - mtime mod ).  
3000: 20 20 66 73 2d 66 69 64 20 40 20 66 69 6c 65 6e    fs-fid @ filen
3010: 6f 20 73 74 61 74 62 75 66 20 66 73 74 61 74 20  o statbuf fstat 
3020: 3f 69 6f 72 0a 20 20 20 20 73 74 61 74 62 75 66  ?ior.    statbuf
3030: 20 73 74 5f 6d 74 69 6d 65 20 6e 74 69 6d 65 40   st_mtime ntime@
3040: 20 64 3e 36 34 0a 20 20 20 20 73 74 61 74 62 75   d>64.    statbu
3050: 66 20 73 74 5f 6d 6f 64 65 20 5b 20 73 69 7a 65  f st_mode [ size
3060: 6f 66 20 73 74 5f 6d 6f 64 65 20 32 20 3d 20 5d  of st_mode 2 = ]
3070: 20 5b 49 46 5d 20 77 40 20 5b 45 4c 53 45 5d 20   [IF] w@ [ELSE] 
3080: 6c 40 20 5b 54 48 45 4e 5d 20 24 46 46 46 20 61  l@ [THEN] $FFF a
3090: 6e 64 20 3b 0a 27 20 6e 65 74 32 6f 3a 67 65 74  nd ;.' net2o:get
30a0: 2d 73 74 61 74 20 66 73 2d 63 6c 61 73 73 20 74  -stat fs-class t
30b0: 6f 20 66 73 2d 67 65 74 2d 73 74 61 74 0a 27 20  o fs-get-stat.' 
30c0: 6e 65 74 32 6f 3a 67 65 74 2d 73 74 61 74 20 68  net2o:get-stat h
30d0: 61 73 68 66 73 2d 63 6c 61 73 73 20 74 6f 20 66  ashfs-class to f
30e0: 73 2d 67 65 74 2d 73 74 61 74 0a 0a 3a 20 74 72  s-get-stat..: tr
30f0: 61 63 6b 2d 6d 6f 64 20 28 20 6d 6f 64 20 66 69  ack-mod ( mod fi
3100: 6c 65 6e 6f 20 2d 2d 20 29 0a 20 20 20 20 5b 49  leno -- ).    [I
3110: 46 44 45 46 5d 20 61 6e 64 72 6f 69 64 20 32 64  FDEF] android 2d
3120: 72 6f 70 0a 20 20 20 20 5b 45 4c 53 45 5d 20 73  rop.    [ELSE] s
3130: 77 61 70 20 66 63 68 6d 6f 64 20 3f 69 6f 72 20  wap fchmod ?ior 
3140: 5b 54 48 45 4e 5d 20 3b 0a 0a 3a 20 73 65 74 2d  [THEN] ;..: set-
3150: 73 74 61 74 20 28 20 6d 74 69 6d 65 20 6d 6f 64  stat ( mtime mod
3160: 20 2d 2d 20 29 0a 20 20 20 20 66 73 2d 66 69 64   -- ).    fs-fid
3170: 20 40 20 66 69 6c 65 6e 6f 20 6e 65 74 32 6f 3a   @ fileno net2o:
3180: 74 72 61 63 6b 2d 6d 6f 64 20 74 6f 20 66 73 2d  track-mod to fs-
3190: 74 69 6d 65 20 3b 0a 27 20 6e 65 74 32 6f 3a 73  time ;.' net2o:s
31a0: 65 74 2d 73 74 61 74 20 66 73 2d 63 6c 61 73 73  et-stat fs-class
31b0: 20 74 6f 20 66 73 2d 73 65 74 2d 73 74 61 74 0a   to fs-set-stat.
31c0: 27 20 6e 65 74 32 6f 3a 73 65 74 2d 73 74 61 74  ' net2o:set-stat
31d0: 20 68 61 73 68 66 73 2d 63 6c 61 73 73 20 74 6f   hashfs-class to
31e0: 20 66 73 2d 73 65 74 2d 73 74 61 74 0a 0a 5c 20   fs-set-stat..\ 
31f0: 6f 70 65 6e 2f 63 6c 6f 73 65 20 61 20 66 69 6c  open/close a fil
3200: 65 20 2d 20 74 68 69 73 20 6e 65 65 64 73 20 2a  e - this needs *
3210: 77 61 79 20 6d 6f 72 65 20 63 68 65 63 6b 69 6e  way more checkin
3220: 67 2a 21 20 21 21 46 49 58 4d 45 21 21 0a 0a 3a  g*! !!FIXME!!..:
3230: 20 63 6c 6f 73 65 2d 66 69 6c 65 20 28 20 69 64   close-file ( id
3240: 20 2d 2d 20 29 0a 20 20 20 20 69 64 3e 61 64 64   -- ).    id>add
3250: 72 3f 20 2e 66 73 2d 63 6c 6f 73 65 20 3b 0a 0a  r? .fs-close ;..
3260: 3a 20 62 6c 6f 63 6b 73 69 7a 65 73 21 20 28 20  : blocksizes! ( 
3270: 6e 20 2d 2d 20 29 0a 20 20 20 20 64 75 70 20 62  n -- ).    dup b
3280: 6c 6f 63 6b 73 69 7a 65 20 21 0a 20 20 20 20 66  locksize !.    f
3290: 69 6c 65 28 20 2e 22 20 66 69 6c 65 20 72 65 61  ile( ." file rea
32a0: 64 3a 20 3d 3d 3d 3d 3d 3d 3d 20 22 20 64 75 70  d: ======= " dup
32b0: 20 2e 20 66 6f 72 74 68 3a 63 72 0a 20 20 20 20   . forth:cr.    
32c0: 2e 22 20 66 69 6c 65 20 77 72 69 74 65 3a 20 3d  ." file write: =
32d0: 3d 3d 3d 3d 3d 3d 20 22 20 64 75 70 20 2e 20 66  ====== " dup . f
32e0: 6f 72 74 68 3a 63 72 20 29 0a 20 20 20 20 64 75  orth:cr ).    du
32f0: 70 20 72 65 73 69 64 75 61 6c 72 65 61 64 20 21  p residualread !
3300: 20 20 72 65 73 69 64 75 61 6c 77 72 69 74 65 20    residualwrite 
3310: 21 20 3b 0a 0a 3a 20 63 6c 6f 73 65 2d 61 6c 6c  ! ;..: close-all
3320: 20 28 20 2d 2d 20 29 0a 20 20 20 20 6d 73 67 28   ( -- ).    msg(
3330: 20 2e 22 20 43 6c 6f 73 69 6e 67 20 61 6c 6c 20   ." Closing all 
3340: 66 69 6c 65 73 22 20 66 6f 72 74 68 3a 63 72 20  files" forth:cr 
3350: 29 0a 20 20 20 20 66 73 74 61 74 65 73 20 30 20  ).    fstates 0 
3360: 3f 44 4f 20 20 49 20 6e 65 74 32 6f 3a 63 6c 6f  ?DO  I net2o:clo
3370: 73 65 2d 66 69 6c 65 20 20 4c 4f 4f 50 0a 20 20  se-file  LOOP.  
3380: 20 20 66 69 6c 65 2d 72 65 67 23 20 6f 66 66 20    file-reg# off 
3390: 20 66 73 74 61 74 65 2d 66 72 65 65 0a 20 20 20   fstate-free.   
33a0: 20 62 6c 6f 63 6b 73 69 7a 65 20 40 20 62 6c 6f   blocksize @ blo
33b0: 63 6b 73 69 7a 65 73 21 0a 20 20 20 20 72 65 61  cksizes!.    rea
33c0: 64 2d 66 69 6c 65 23 20 6f 66 66 20 20 77 72 69  d-file# off  wri
33d0: 74 65 2d 66 69 6c 65 23 20 6f 66 66 20 3b 0a 0a  te-file# off ;..
33e0: 3a 20 6f 70 65 6e 2d 66 69 6c 65 20 28 20 61 64  : open-file ( ad
33f0: 64 72 20 75 20 6d 6f 64 65 20 69 64 20 2d 2d 20  dr u mode id -- 
3400: 29 0a 20 20 20 20 73 74 61 74 65 2d 61 64 64 72  ).    state-addr
3410: 20 2e 66 73 2d 6f 70 65 6e 20 3b 0a 0a 5c 20 72   .fs-open ;..\ r
3420: 65 61 64 20 69 6e 20 66 72 6f 6d 20 66 69 6c 65  ead in from file
3430: 73 0a 0a 3a 20 73 6c 75 72 70 2d 62 6c 6f 63 6b  s..: slurp-block
3440: 20 7b 20 69 64 20 2d 2d 20 64 65 6c 74 61 20 7d   { id -- delta }
3450: 0a 20 20 20 20 64 61 74 61 2d 68 65 61 64 40 20  .    data-head@ 
3460: 69 64 20 69 64 3e 61 64 64 72 3f 20 2e 66 73 2d  id id>addr? .fs-
3470: 72 65 61 64 20 64 75 70 20 2f 68 65 61 64 0a 20  read dup /head. 
3480: 20 20 20 66 69 6c 65 31 28 20 69 64 20 66 2d 72     file1( id f-r
3490: 69 64 20 40 20 3d 20 49 46 20 20 64 75 70 20 66  id @ = IF  dup f
34a0: 2d 72 61 6d 6f 75 6e 74 20 2b 21 0a 20 20 20 20  -ramount +!.    
34b0: 45 4c 53 45 20 20 66 2d 72 69 64 20 40 20 30 3e  ELSE  f-rid @ 0>
34c0: 3d 20 20 66 2d 72 61 6d 6f 75 6e 74 20 40 20 30  =  f-ramount @ 0
34d0: 3e 20 61 6e 64 20 49 46 0a 09 20 20 20 20 2e 22  > and IF..    ."
34e0: 20 73 70 6c 69 74 3a 20 22 20 66 2d 72 69 64 20   split: " f-rid 
34f0: 40 20 2e 20 66 2d 72 61 6d 6f 75 6e 74 20 40 20  @ . f-ramount @ 
3500: 68 65 78 2e 20 63 72 20 20 54 48 45 4e 0a 20 20  hex. cr  THEN.  
3510: 20 20 20 20 20 20 69 64 20 66 2d 72 69 64 20 21        id f-rid !
3520: 20 64 75 70 20 66 2d 72 61 6d 6f 75 6e 74 20 21   dup f-ramount !
3530: 20 20 54 48 45 4e 20 29 20 3b 0a 0a 5c 20 63 61    THEN ) ;..\ ca
3540: 72 65 66 75 6c 3a 20 6d 75 73 74 20 66 6f 6c 6c  reful: must foll
3550: 6f 77 20 65 78 61 63 74 70 79 20 74 68 65 20 73  ow exactpy the s
3560: 61 6d 65 20 6c 6f 67 69 63 20 61 73 20 6e 65 74  ame logic as net
3570: 32 6f 3a 73 70 69 74 20 28 73 65 65 20 61 62 6f  2o:spit (see abo
3580: 76 65 29 0a 3a 20 73 6c 75 72 70 20 28 20 2d 2d  ve).: slurp ( --
3590: 20 68 65 61 64 20 65 6e 64 2d 66 6c 61 67 20 29   head end-flag )
35a0: 0a 20 20 20 20 64 61 74 61 2d 68 65 61 64 3f 20  .    data-head? 
35b0: 30 3d 20 66 73 74 61 74 65 73 20 30 3d 20 6f 72  0= fstates 0= or
35c0: 20 20 49 46 20 20 68 65 61 64 40 20 30 20 20 45    IF  head@ 0  E
35d0: 58 49 54 20 20 54 48 45 4e 0a 20 20 20 20 73 6c  XIT  THEN.    sl
35e0: 75 72 70 28 20 2e 22 20 73 6c 75 72 70 3a 20 22  urp( ." slurp: "
35f0: 20 64 61 74 61 2d 68 65 61 64 40 20 64 72 6f 70   data-head@ drop
3600: 20 64 61 74 61 2d 6d 61 70 20 77 69 74 68 20 6d   data-map with m
3610: 61 70 63 20 64 65 73 74 2d 72 61 64 64 72 20 2d  apc dest-raddr -
3620: 20 65 6e 64 77 69 74 68 20 68 65 78 2e 0a 20 20   endwith hex..  
3630: 20 20 72 65 61 64 2d 66 69 6c 65 23 20 3f 20 72    read-file# ? r
3640: 65 73 69 64 75 61 6c 72 65 61 64 20 40 20 68 65  esidualread @ he
3650: 78 2e 20 66 6f 72 74 68 3a 63 72 20 29 0a 20 20  x. forth:cr ).  
3660: 20 20 5b 3a 20 2b 63 61 6c 63 20 66 73 74 61 74    [: +calc fstat
3670: 65 73 20 30 20 7b 20 73 74 61 74 65 73 20 66 61  es 0 { states fa
3680: 69 6c 73 20 7d 0a 09 30 20 42 45 47 49 4e 20 20  ils }..0 BEGIN  
3690: 64 61 74 61 2d 68 65 61 64 3f 20 20 57 48 49 4c  data-head?  WHIL
36a0: 45 0a 09 09 72 65 61 64 2d 66 69 6c 65 23 20 40  E...read-file# @
36b0: 20 6e 65 74 32 6f 3a 73 6c 75 72 70 2d 62 6c 6f   net2o:slurp-blo
36c0: 63 6b 0a 09 09 49 46 20 30 20 45 4c 53 45 20 66  ck...IF 0 ELSE f
36d0: 61 69 6c 73 20 31 2b 20 72 65 73 69 64 75 61 6c  ails 1+ residual
36e0: 72 65 61 64 20 6f 66 66 20 54 48 45 4e 20 74 6f  read off THEN to
36f0: 20 66 61 69 6c 73 0a 09 09 72 65 73 69 64 75 61   fails...residua
3700: 6c 72 65 61 64 20 40 20 30 3d 20 49 46 0a 09 09  lread @ 0= IF...
3710: 20 20 20 20 72 65 61 64 2d 66 69 6c 65 23 20 66      read-file# f
3720: 69 6c 65 2b 20 20 62 6c 6f 63 6b 73 69 7a 65 20  ile+  blocksize 
3730: 40 20 72 65 73 69 64 75 61 6c 72 65 61 64 20 21  @ residualread !
3740: 20 20 54 48 45 4e 0a 09 20 20 20 20 66 61 69 6c    THEN..    fail
3750: 73 20 73 74 61 74 65 73 20 75 3e 3d 20 55 4e 54  s states u>= UNT
3760: 49 4c 0a 09 54 48 45 4e 20 20 2b 66 69 6c 65 0a  IL..THEN  +file.
3770: 09 66 61 69 6c 73 20 73 74 61 74 65 73 20 75 3e  .fails states u>
3780: 3d 20 64 75 70 20 49 46 20 20 6d 61 78 2f 68 65  = dup IF  max/he
3790: 61 64 20 20 54 48 45 4e 20 5c 20 69 66 20 61 6c  ad  THEN \ if al
37a0: 6c 20 66 69 6c 65 73 20 61 72 65 20 64 6f 6e 65  l files are done
37b0: 2c 20 61 6c 69 67 6e 0a 09 68 65 61 64 40 20 73  , align..head@ s
37c0: 77 61 70 0a 09 6d 73 67 28 20 2e 22 20 52 65 61  wap..msg( ." Rea
37d0: 64 20 65 6e 64 3a 20 22 20 6f 76 65 72 20 68 65  d end: " over he
37e0: 78 2e 20 66 6f 72 74 68 3a 63 72 20 29 20 3b 5d  x. forth:cr ) ;]
37f0: 0a 20 20 20 20 66 69 6c 65 2d 73 65 6d 61 20 63  .    file-sema c
3800: 2d 73 65 63 74 69 6f 6e 0a 20 20 20 20 73 6c 75  -section.    slu
3810: 72 70 28 20 2e 22 20 20 6c 65 66 74 3a 20 22 20  rp( ."  left: " 
3820: 64 61 74 61 2d 68 65 61 64 40 20 64 72 6f 70 20  data-head@ drop 
3830: 64 61 74 61 2d 6d 61 70 20 77 69 74 68 20 6d 61  data-map with ma
3840: 70 63 20 64 65 73 74 2d 72 61 64 64 72 20 2d 20  pc dest-raddr - 
3850: 65 6e 64 77 69 74 68 20 68 65 78 2e 0a 20 20 20  endwith hex..   
3860: 20 72 65 61 64 2d 66 69 6c 65 23 20 3f 20 72 65   read-file# ? re
3870: 73 69 64 75 61 6c 72 65 61 64 20 40 20 68 65 78  sidualread @ hex
3880: 2e 20 66 6f 72 74 68 3a 63 72 20 29 0a 0a 20 20  . forth:cr )..  
3890: 20 20 66 69 6c 65 28 20 64 75 70 20 49 46 20 20    file( dup IF  
38a0: 2e 22 20 64 61 74 61 20 65 6e 64 3a 20 22 20 6f  ." data end: " o
38b0: 76 65 72 20 68 65 78 2e 20 64 75 70 20 66 6f 72  ver hex. dup for
38c0: 74 68 3a 2e 20 66 6f 72 74 68 3a 63 72 20 20 54  th:. forth:cr  T
38d0: 48 45 4e 20 29 20 3b 0a 20 20 20 20 0a 3a 20 74  HEN ) ;.    .: t
38e0: 72 61 63 6b 2d 73 65 65 6b 73 20 28 20 69 64 62  rack-seeks ( idb
38f0: 69 74 73 20 78 74 20 2d 2d 20 29 20 5c 20 78 74  its xt -- ) \ xt
3900: 3a 20 28 20 69 20 73 65 65 6b 6c 65 6e 20 2d 2d  : ( i seeklen --
3910: 20 29 0a 20 20 20 20 5b 3a 20 7b 20 78 74 20 7d   ).    [: { xt }
3920: 20 38 20 63 65 6c 6c 73 20 30 20 44 4f 0a 09 20   8 cells 0 DO.. 
3930: 20 20 20 64 75 70 20 31 20 61 6e 64 20 49 46 0a     dup 1 and IF.
3940: 09 09 49 20 64 75 70 20 69 64 3e 61 64 64 72 3f  ..I dup id>addr?
3950: 20 3e 6f 20 66 73 2d 73 65 65 6b 20 66 73 2d 73   >o fs-seek fs-s
3960: 65 65 6b 74 6f 20 36 34 3c 3e 20 49 46 0a 09 09  eekto 64<> IF...
3970: 20 20 20 20 66 73 2d 73 65 65 6b 74 6f 20 36 34      fs-seekto 64
3980: 64 75 70 20 74 6f 20 66 73 2d 73 65 65 6b 20 6f  dup to fs-seek o
3990: 3e 0a 09 09 20 20 20 20 78 74 20 65 78 65 63 75  >...    xt execu
39a0: 74 65 20 20 45 4c 53 45 20 20 64 72 6f 70 20 6f  te  ELSE  drop o
39b0: 3e 20 20 54 48 45 4e 0a 09 20 20 20 20 54 48 45  >  THEN..    THE
39c0: 4e 20 20 32 2f 0a 09 4c 4f 4f 50 20 20 64 72 6f  N  2/..LOOP  dro
39d0: 70 20 3b 5d 20 66 69 6c 65 2d 73 65 6d 61 20 63  p ;] file-sema c
39e0: 2d 73 65 63 74 69 6f 6e 20 3b 0a 0a 3a 20 74 72  -section ;..: tr
39f0: 61 63 6b 2d 61 6c 6c 2d 73 65 65 6b 73 20 28 20  ack-all-seeks ( 
3a00: 78 74 20 2d 2d 20 29 20 5c 20 78 74 3a 20 28 20  xt -- ) \ xt: ( 
3a10: 69 20 73 65 65 6b 6c 65 6e 20 2d 2d 20 29 0a 20  i seeklen -- ). 
3a20: 20 20 20 5b 3a 20 7b 20 78 74 20 7d 20 66 73 74     [: { xt } fst
3a30: 61 74 65 73 20 30 20 3f 44 4f 0a 09 20 20 20 20  ates 0 ?DO..    
3a40: 49 20 64 75 70 20 69 64 3e 61 64 64 72 3f 20 3e  I dup id>addr? >
3a50: 6f 20 66 73 2d 73 65 65 6b 20 66 73 2d 73 65 65  o fs-seek fs-see
3a60: 6b 74 6f 20 36 34 3c 3e 20 49 46 0a 09 09 66 73  kto 64<> IF...fs
3a70: 2d 73 65 65 6b 74 6f 20 36 34 64 75 70 20 74 6f  -seekto 64dup to
3a80: 20 66 73 2d 73 65 65 6b 20 6f 3e 0a 09 09 78 74   fs-seek o>...xt
3a90: 20 65 78 65 63 75 74 65 20 20 45 4c 53 45 20 20   execute  ELSE  
3aa0: 64 72 6f 70 20 6f 3e 20 20 54 48 45 4e 0a 09 4c  drop o>  THEN..L
3ab0: 4f 4f 50 20 3b 5d 20 66 69 6c 65 2d 73 65 6d 61  OOP ;] file-sema
3ac0: 20 63 2d 73 65 63 74 69 6f 6e 20 3b 0a 0a 7d 73   c-section ;..}s
3ad0: 63 6f 70 65 0a 0a 5c 20 70 65 72 6d 69 73 73 69  cope..\ permissi
3ae0: 6f 6e 20 63 68 65 63 6b 73 0a 0a 43 72 65 61 74  on checks..Creat
3af0: 65 20 3e 66 69 6c 65 2d 70 65 72 6d 0a 70 65 72  e >file-perm.per
3b00: 6d 25 66 69 6c 65 72 64 20 77 2c 20 70 65 72 6d  m%filerd w, perm
3b10: 25 66 69 6c 65 72 64 20 70 65 72 6d 25 66 69 6c  %filerd perm%fil
3b20: 65 77 72 20 6f 72 20 77 2c 20 70 65 72 6d 25 66  ewr or w, perm%f
3b30: 69 6c 65 77 72 20 77 2c 0a 44 4f 45 53 3e 20 20  ilewr w,.DOES>  
3b40: 2b 20 77 40 20 3b 0a 3a 20 3f 72 64 2d 70 65 72  + w@ ;.: ?rd-per
3b50: 6d 20 28 20 6e 20 2d 2d 20 29 20 70 65 72 6d 25  m ( n -- ) perm%
3b60: 66 69 6c 65 72 64 20 61 6e 64 20 30 3c 3e 20 21  filerd and 0<> !
3b70: 21 66 69 6c 65 72 64 2d 70 65 72 6d 21 21 20 3b  !filerd-perm!! ;
3b80: 0a 3a 20 3f 77 72 2d 70 65 72 6d 20 28 20 6e 20  .: ?wr-perm ( n 
3b90: 2d 2d 20 29 20 70 65 72 6d 25 66 69 6c 65 77 72  -- ) perm%filewr
3ba0: 20 61 6e 64 20 30 3c 3e 20 21 21 66 69 6c 65 77   and 0<> !!filew
3bb0: 72 2d 70 65 72 6d 21 21 20 3b 0a 3a 20 3f 72 77  r-perm!! ;.: ?rw
3bc0: 2d 70 65 72 6d 20 28 20 6e 20 70 65 72 6d 20 2d  -perm ( n perm -
3bd0: 2d 20 29 0a 20 20 20 20 3e 72 20 3e 66 69 6c 65  - ).    >r >file
3be0: 2d 70 65 72 6d 20 72 3e 20 69 6e 76 65 72 74 20  -perm r> invert 
3bf0: 61 6e 64 20 64 75 70 20 3f 72 64 2d 70 65 72 6d  and dup ?rd-perm
3c00: 20 3f 77 72 2d 70 65 72 6d 20 3b 0a 0a 5c 5c 5c   ?wr-perm ;..\\\
3c10: 0a 4c 6f 63 61 6c 20 56 61 72 69 61 62 6c 65 73  .Local Variables
3c20: 3a 0a 66 6f 72 74 68 2d 6c 6f 63 61 6c 2d 77 6f  :.forth-local-wo
3c30: 72 64 73 3a 0a 20 20 20 20 28 0a 20 20 20 20 20  rds:.    (.     
3c40: 28 28 22 65 76 65 6e 74 3a 22 29 20 64 65 66 69  (("event:") defi
3c50: 6e 69 74 69 6f 6e 2d 73 74 61 72 74 65 72 20 28  nition-starter (
3c60: 66 6f 6e 74 2d 6c 6f 63 6b 2d 6b 65 79 77 6f 72  font-lock-keywor
3c70: 64 2d 66 61 63 65 20 2e 20 31 29 0a 20 20 20 20  d-face . 1).    
3c80: 20 20 22 5b 20 5c 74 5c 6e 5d 22 20 74 20 6e 61    "[ \t\n]" t na
3c90: 6d 65 20 28 66 6f 6e 74 2d 6c 6f 63 6b 2d 66 75  me (font-lock-fu
3ca0: 6e 63 74 69 6f 6e 2d 6e 61 6d 65 2d 66 61 63 65  nction-name-face
3cb0: 20 2e 20 33 29 29 0a 20 20 20 20 20 28 28 22 64   . 3)).     (("d
3cc0: 65 62 75 67 3a 22 20 22 66 69 65 6c 64 3a 22 20  ebug:" "field:" 
3cd0: 22 32 66 69 65 6c 64 3a 22 20 22 73 66 66 69 65  "2field:" "sffie
3ce0: 6c 64 3a 22 20 22 64 66 66 69 65 6c 64 3a 22 20  ld:" "dffield:" 
3cf0: 22 36 34 66 69 65 6c 64 3a 22 20 22 36 34 76 61  "64field:" "64va
3d00: 6c 75 65 3a 22 29 20 6e 6f 6e 2d 69 6d 6d 65 64  lue:") non-immed
3d10: 69 61 74 65 20 28 66 6f 6e 74 2d 6c 6f 63 6b 2d  iate (font-lock-
3d20: 74 79 70 65 2d 66 61 63 65 20 2e 20 32 29 0a 20  type-face . 2). 
3d30: 20 20 20 20 20 22 5b 20 5c 74 5c 6e 5d 22 20 74       "[ \t\n]" t
3d40: 20 6e 61 6d 65 20 28 66 6f 6e 74 2d 6c 6f 63 6b   name (font-lock
3d50: 2d 76 61 72 69 61 62 6c 65 2d 6e 61 6d 65 2d 66  -variable-name-f
3d60: 61 63 65 20 2e 20 33 29 29 0a 20 20 20 20 20 28  ace . 3)).     (
3d70: 22 5b 61 2d 7a 5c 2d 30 2d 39 5d 2b 28 22 20 69  "[a-z\-0-9]+(" i
3d80: 6d 6d 65 64 69 61 74 65 20 28 66 6f 6e 74 2d 6c  mmediate (font-l
3d90: 6f 63 6b 2d 63 6f 6d 6d 65 6e 74 2d 66 61 63 65  ock-comment-face
3da0: 20 2e 20 31 29 0a 20 20 20 20 20 20 22 29 22 20   . 1).      ")" 
3db0: 6e 69 6c 20 63 6f 6d 6d 65 6e 74 20 28 66 6f 6e  nil comment (fon
3dc0: 74 2d 6c 6f 63 6b 2d 63 6f 6d 6d 65 6e 74 2d 66  t-lock-comment-f
3dd0: 61 63 65 20 2e 20 31 29 29 0a 20 20 20 20 29 0a  ace . 1)).    ).
3de0: 66 6f 72 74 68 2d 6c 6f 63 61 6c 2d 69 6e 64 65  forth-local-inde
3df0: 6e 74 2d 77 6f 72 64 73 3a 0a 20 20 20 20 28 0a  nt-words:.    (.
3e00: 20 20 20 20 20 28 28 22 65 76 65 6e 74 3a 22 29       (("event:")
3e10: 20 28 30 20 2e 20 32 29 20 28 30 20 2e 20 32 29   (0 . 2) (0 . 2)
3e20: 20 6e 6f 6e 2d 69 6d 6d 65 64 69 61 74 65 29 0a   non-immediate).
3e30: 20 20 20 20 29 0a 45 6e 64 3a 0a 5b 54 48 45 4e      ).End:.[THEN
3e40: 5d 0a                                            ].