Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sh / string
1 ;
2 ; string.sh
3 ;
4 ; String handling routines (control terminated)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ; str_cpy
32 ; str_len
33 ; str_cmp
34 ; str_icmp
35 ; str_index
36 ; str_match
37 ; str_subst
38 ; str_error
39 ; str_buffer
40
41 [ :LNOT::DEF:string__dfn
42 GBLL string__dfn
43
44 ; --- str_cpy ---
45 ;
46 ; On entry: R0 == destination string
47 ; R1 == source string
48 ;
49 ; On exit: R0 == pointer to terminator of destination
50 ;
51 ; Use: Copies a string from one block to another. It leaves the
52 ; destination pointer at the end of the string so that any
53 ; subsequent copies concatenate other bits on the same string.
54 ; Single characters can of course be appended with
55 ;
56 ; MOV Rx,#&cc
57 ; STRB Rx,[R0],#1
58
59 IMPORT str_cpy
60
61 ; --- str_len ---
62 ;
63 ; On entry: R0 == pointer to string
64 ;
65 ; On exit: R0 == length of the string
66 ;
67 ; Use: Calculates the length of a string.
68
69 IMPORT str_len
70
71 ; --- str_cmp ---
72 ;
73 ; On entry: R0 == pointer to string A
74 ; R1 == pointer to string B
75 ;
76 ; On exit: Flags as appropriate
77 ;
78 ; Use: Case-sensitively compares two strings. You can use the
79 ; normal ARM condition codes after the compare, so you can
80 ; treat this fairly much like a normal CMP.
81
82 IMPORT str_cmp
83
84 ; --- str_icmp ---
85 ;
86 ; On entry: R0 == pointer to string A
87 ; R1 == pointer to string B
88 ;
89 ; On exit: Flags as appropriate
90 ;
91 ; Use: As for str_cmp above, but case-insensitive.
92
93 IMPORT str_icmp
94
95 ; --- str_index ---
96 ;
97 ; On entry: R0 == pointer to name table
98 ; R1 == index into name table
99 ;
100 ; On exit: CS if index good, and
101 ; R0 == address of R0th string in table
102 ; else CC and
103 ; R0 corrupted
104 ;
105 ; Use: Finds an indexed string in a table. The table consists of
106 ; ctrl-terminated strings, with no separation. The table is
107 ; terminated by a zero-length entry.
108
109 IMPORT str_index
110
111 ; --- str_find ---
112 ;
113 ; On entry: R0 == pointer to name table
114 ; R1 == string to match in table
115 ;
116 ; On exit: CS if match found, and
117 ; R0 == index of string matched
118 ; else CC and
119 ; R0 corrupted
120 ;
121 ; Use: Looks up a string in a table. The table consists of
122 ; ctrl-terminated strings, with no separation. The table is
123 ; terminated by a zero-length entry.
124
125 IMPORT str_match
126
127 ; --- str_subst ---
128 ;
129 ; On entry: R0 == Pointer to skeleton
130 ; R1 == Pointer to output buffer
131 ; R2-R11 == Pointer to filler strings (optional)
132 ;
133 ; On exit: R0 == Pointer to start of buffer
134 ; R1 == Pointer to terminating null
135 ;
136 ; Use: Performs string substitution, filling in a skeleton string
137 ; containing placeholders with `filler' strings. The
138 ; placeholders are actually rather powerful. The syntax of
139 ; these is as follows:
140 ;
141 ; `%' [<type>] <digit>
142 ;
143 ; (spaces are for clarity -- in fact you must not include
144 ; spaces in the format string.)
145 ;
146 ; <digit> is any charater between `0' and `9'. It refers to
147 ; registers R2-R11 (so `0' means R2, `5' is R7 etc.) How the
148 ; value is interpreted is determined by <type>.
149 ;
150 ; <type> is one of:
151 ;
152 ; s String. This is the default. The register is
153 ; considered to be a pointer to an ASCII string
154 ; (control terminated).
155 ;
156 ; i Integer. The (signed) decimal representation is
157 ; inserted. Leading zeros are suppressed.
158 ;
159 ; x Hex fullword. The hexadecimal representation of the
160 ; register is inserted. Leading zeros are included.
161 ;
162 ; b Hex byte. The hexadecimal representation of the
163 ; least significant byte is inserted. Leading zeros
164 ; are included.
165 ;
166 ; c Character. The ASCII character corresponding to the
167 ; least significant byte is inserted.
168
169 IMPORT str_subst
170
171 ; --- str_error ---
172 ;
173 ; On entry: R0 == Pointer to skeleton
174 ; R2-R11 == Pointers to fillin strings
175 ;
176 ; On exit: R0 == Pointer to error in buffer
177 ; R1 == Pointer to terminator
178 ;
179 ; Use: Fills in an error skeleton (containing a 4 byte error number
180 ; and a control terminated skeleton string as for str_subst)
181 ; and returns the address of the filled in error block. The
182 ; error block is stored in a buffer obtained from str_buffer.
183 ;
184 ; Filler strings may be held in the scratchpad.
185
186 IMPORT str_error
187
188 ; --- str_buffer ---
189 ;
190 ; On entry: --
191 ;
192 ; On exit: R1 == pointer to the next free buffer
193 ;
194 ; Use: Returns a pointer to a 256-byte buffer. There are at present
195 ; 2 buffers, which are returned alternately.
196
197 IMPORT str_buffer
198
199 ]
200
201 ;----- That's all, folks ----------------------------------------------------
202
203 END