1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10 ;; terminate c1s with zero
(but don
't increment length)
15 ;; make sure that srccount fits into byte length
16 : clamp-count ( srccount destcount -- srccount-clamped )
19 over + dup 255 u> if 255 - - 0 max else drop endif
25 : copy ( addrsrc addrdest -- )
26 >r dup bcount-only 1+ r> swap cmove
29 ;; copy counted string to c1s
30 : copy-counted ( addrsrc count addrdest -- )
36 ;; cat counted string to c1s
37 : cat-counted ( addr count addrdest -- )
39 dup >r bcount-only clamp-count
40 r@ bcount + swap dup >r cmove
45 ;; cat c1s to another c1s
46 : cat ( addrsrc addrdest -- )
47 swap bcount rot cat-counted
51 : cat-char ( char addr -- )
52 dup bcount-only 255 < if
53 dup >r bcount + c! r> 1+c!
57 ;; append slash to c1s (but only if it doesn't
end with slash
, and is not empty
)
58 ;; useful
for path manipulation
59 : add
-slash
( addr
-- )
60 dup bcount
-only
1 255 within
if
61 dup bcount
+ dup
1- c@
[char
] / = ifnot
[char
] / swap c
! 1+c
! else 2drop
endif
65 : skip
-aligned
( addr
-- nextaddr
) bcount
+ 3 + -4 and
;
66 : skip
-alignedz
( addr
-- nextaddr
) bcount
+ 4+ -4 and
;