-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstrings.txt
87 lines (72 loc) · 1.58 KB
/
strings.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
\ *********************************************************************
\ STRINGS management for FlashForth
\ Filename: strings.txt
\ Date: 12/10/2020
\ Updated: 12/10/2020
\ File Version: 1.0
\ MCU: ARDUINO all models
\ Copyright: Marc PETREMANN
\ Author: Marc PETREMANN
\ GNU General Public License
\ *********************************************************************
-strings
marker -strings
\ compare two strings
\ n = 0 if strings are equals | otherwise n <> 0
: compare ( str1 str2 --- n)
drop swap >r
begin
r> 1- >r
r@
while
over r@ + c@
over r@ + c@
<>
if
2drop
1
exit
then
repeat
r> drop
2drop
0
;
: $= ( addr1 len1 addr2 len2 --- fl)
compare
0 =
if true
else false then
;
\ define a strvar
: string ( n --- names_strvar)
create
dup
c, \ n is maxlength
0 c, \ 0 is real length
allot
does>
2 +
dup 1 - c@
;
\ store str into strvar
: $! ( str strvar ---)
drop
dup 2- c@ \ get maxlength of strvar
rot min \ keep min length
2dup swap 1- c! \ store real length
cmove \ copy string
;
\ *** Example: **********
: constStr
s" this is constant string" ;
\ create variable varStr
32 string varStr
\ copy constStr into varStr
constStr varStr $!
varStr type \ display: this is constant string
: tst2 ( --- fl)
s" +RCB"
s" +RCB" $=
;
tst2 \ leave true