chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Quartz / 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 Quartz library.
12 ;
13 ; Quartz 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 ; Quartz 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 Quartz.  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_subst
36 ;   str_error
37 ;
38 ; Notes:
39 ;
40 ;   All strings written by these routines are output as NULL-terminated,
41 ;   regardless of the original terminator.
42
43 ; --- str_cpy ---
44 ;
45 ; On entry:     R0 == destination string
46 ;               R1 == source string
47 ;
48 ; On exit:      R0 == pointer to terminator of destination
49 ;
50 ; Use:          Copies a string from one block to another.  It leaves the
51 ;               destination pointer at the end of the string so that any
52 ;               subsequent copies concatenate other bits on the same string.
53 ;               Single characters can of course be appended with
54 ;
55 ;                       MOV     Rx,#&cc
56 ;                       STRB    Rx,[R0],#1
57
58                 IMPORT  str_cpy
59
60 ; --- str_len ---
61 ;
62 ; On entry:     R0 == pointer to string
63 ;
64 ; On exit:      R0 == length of the string
65 ;
66 ; Use:          Calculates the length of a string.
67
68                 IMPORT  str_len
69
70 ; --- str_cmp ---
71 ;
72 ; On entry:     R0 == pointer to string A
73 ;               R1 == pointer to string B
74 ;
75 ; On exit:      Flags as appropriate
76 ;
77 ; Use:          Case-sensitively compares two strings.  You can use the
78 ;               normal ARM conditio codes after the compare, so you can treat
79 ;               this as a normal CMP type thing (except the arguments must
80 ;               be in R0 and R1, and it mangles R14).
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_subst ---
96 ;
97 ; On entry:     R0 == Pointer to skeleton
98 ;               R1 == Pointer to output buffer
99 ;               R2-R11 == Pointer to filler strings (optional)
100 ;
101 ; On exit:      R0 == Pointer to start of buffer
102 ;               R1 == Pointer to terminating null
103 ;
104 ; Use:          Performs string substitution, filling in a skeleton string
105 ;               containing placeholders with `filler' strings.  The
106 ;               placeholders are actually rather powerful.  The syntax of
107 ;               these is as follows:
108 ;
109 ;                       `%' [<type>] <digit>
110 ;
111 ;               (spaces are for clarity -- in fact you must not include
112 ;               spaces in the format string.)
113 ;
114 ;               <digit> is any charater between `0' and `9'.  It refers to
115 ;               registers R2-R11 (so `0' means R2, `5' is R7 etc.)  How the
116 ;               value is interpreted is determined by <type>.
117 ;
118 ;               <type> is one of:
119 ;
120 ;               s       String.  This is the default.  The register is
121 ;                       considered to be a pointer to an ASCII string
122 ;                       (control terminated).
123 ;
124 ;               i       Integer.  The (signed) decimal representation is
125 ;                       inserted.  Leading zeros are suppressed.
126 ;
127 ;               x       Hex fullword.  The hexadecimal representation of the
128 ;                       register is inserted.  Leading zeros are included.
129 ;
130 ;               b       Hex byte.  The hexadecimal representation of the
131 ;                       least significant byte is inserted.  Leading zeros
132 ;                       are included.
133 ;
134 ;               c       Character.  The ASCII character corresponding to the
135 ;                       least significant byte is inserted.
136
137                 IMPORT  str_subst
138
139 ; --- str_error ---
140 ;
141 ; On entry:     R0 == Pointer to skeleton
142 ;               R2-R11 == Pointers to fillin strings
143 ;
144 ; On exit:      R0 == Pointer to error in buffer
145 ;               R1 == Pointer to terminator
146 ;
147 ; Use:          Fills in an error skeleton (like a substitution skeleton in
148 ;               str_subst above with an error number on the front) and
149 ;               returns a pointer to it.  The buffer used is found by calling
150 ;               str_buffer (see below), so you can safely use the result of
151 ;               one call as a filler string for the next.
152 ;
153 ;               Filler strings may be held in the scratchpad.
154
155                 IMPORT  str_error
156
157 ; ---- str_buffer ---
158 ;
159 ; On entry:     --
160 ;
161 ; On exit:      R1 == pointer to the next free buffer
162 ;
163 ; Use:          Returns a pointer to a 256-byte buffer.  There are at present
164 ;               2 buffers, which are returned alternately.
165
166                 IMPORT  str_buffer
167
168 ;----- That's all folks -----------------------------------------------------
169
170                 END