revert between 56095 -> 55830 in arch
[AROS.git] / rom / filesys / pfs3 / fs / assroutines.c
blob0a7a2701660a3955d55c7ce77025c1fdf68aadcb
1 #include <exec/types.h>
3 #include "blocks.h"
4 #include "struct.h"
7 /* StackSwap is not used (or required) for NG systems (at least not MorphOS), thus dummy */
8 void AfsDie(void)
12 /* Let MorphOS know that this is a native MorphOS ELF and not PowerUP binary */
13 #ifdef __MORPHOS__
14 const LONG __READONLY__ __abox__ __USED__ = 1;
15 #endif
18 ;-----------------------------------------------------------------------------
19 ; ULONG divide (ULONG d0, UWORD d1)
20 ;-----------------------------------------------------------------------------
22 ULONG divide(ULONG d0, UWORD d1)
24 ULONG q = d0 / d1;
25 /* NOTE: I doubt anything depends on this, but lets simulate 68k divu overflow anyway - Piru */
26 if (q > 65535UL) return d0;
27 return ((d0 % d1) << 16) | q;
31 ;-----------------------------------------------------------------------------
32 ; void ctodstr(cstring *a0, dstring *a1)
34 ; converts cstring a0 to dstring a1
35 ;-----------------------------------------------------------------------------
37 void ctodstr(const unsigned char *a0, unsigned char *a1)
39 unsigned char *lenp = a1++;
40 unsigned int len = 0;
41 while ((*a1++ = *a0++))
42 len++;
43 *lenp = len;
46 /* SAS/C compatibility routines - only included if not SAS/C */
47 #ifndef __SASC
49 int stcu_d(char *out, unsigned int val)
51 char tmp[11];
52 char *p = &tmp[sizeof(tmp)];
53 int len;
54 *--p = '\0';
57 *--p = '0' + (val % 10);
58 val = val / 10;
60 while (val);
61 for (len = 0; (*out++ = *p++); len++)
63 return len;
67 * Note: Since the value converted in directory.c is always positive without sign,
68 * I disabled the sign support. - Piru
70 int stcd_i(const char *in, int *ivalue)
72 const char *orig_in = in;
73 /*int n = 0;*/
74 int v = 0;
76 /*if (*in == '-' || *in == '+')
77 n = *in++ == '-';*/
79 while (*in)
81 if (*in < '0' || *in > '9')
82 break;
83 v = v * 10 + (*in++ - '0');
85 /* *ivalue = (n ? (v == 0 ? -2147483648L : -v) : v);*/
86 *ivalue = v;
87 return (in - orig_in);
90 /* SAS/C function - similar to strcpy but return ptr to terminating \0 */
91 char *stpcpy(char *dst, const char *src)
93 while ((*dst++ = *src++))
95 return dst - 1;
97 #endif
101 ;-----------------------------------------------------------------------------
102 ; void intltoupper(dstr *a0)
104 ; converts dstring a0 to uppercase in international mode
105 ; zie intlcmp
106 ;-----------------------------------------------------------------------------
108 void intltoupper(unsigned char *a0)
110 unsigned char len = *a0++;
111 while (len--)
113 #ifdef __GNUC__
114 switch (*a0)
116 case 0x61 ... 0x7a:
117 case 0xe0 ... 0xf6:
118 case 0xf8 ... 0xfe:
119 *a0 -= 0x20;
120 /* fall thru */
121 default:
122 a0++;
123 break;
125 #else
126 unsigned char c = *a0++;
127 if ((c >= 0x61 && c <= 0x7a) ||
128 (c >= 0xe0 && c <= 0xf6) ||
129 (c >= 0xf8 && c <= 0xfe))
131 a0[-1] = c - 0x20;
133 #endif
138 ;-----------------------------------------------------------------------------
139 ; bool intlcmp(dstr *a0, dstr *a1)
141 ; compares dstring a with dstring b in international mode.
142 ; a0 must be 'uppercased' as follows:
144 ; 0x00 - 0x60 -> 0x00 - 0x60
145 ; 0x61 - 0x7a -> 0x41 - 0x5a diff 0x20
146 ; 0x7b - 0xdf -> 0x7b - 0xdf
147 ; 0xe0 - 0xf6 -> 0xc0 - 0xd6 diff 0x20
148 ; 0xf7 -> 0xf7
149 ; 0xf8 - 0xfe -> 0xd8 - 0xde diff 0x20
150 ; 0xff -> 0xff
152 ; So if match then (d0 = d1) \/ (d1-d0 = 0x20)
153 ;-----------------------------------------------------------------------------
155 int intlcmp(const unsigned char *a0, const unsigned char *a1)
157 unsigned char len = *a0++;
158 if (len != *a1++)
159 return 0; /* different size, can't match */
161 while (len--)
163 unsigned char c = *a0++;
164 unsigned char d = *a1++;
165 if ((d - c) > d) return 0; /* carry set */
166 if (c == d) continue;
167 if (d - c != 0x20) return 0;
168 #ifdef __GNUC__
169 switch (c)
171 case 0x41 ... 0x5a:
172 case 0xc0 ... 0xd6:
173 case 0xd8 ... 0xde:
174 break;
175 default:
176 return 0;
178 #else
179 if (!((c >= 0x41 && c <= 0x5a) ||
180 (c >= 0xc0 && c <= 0xd6) ||
181 (c >= 0xd8 && c <= 0xde)))
183 return 0;
185 #endif
187 return 1;
191 ;-----------------------------------------------------------------------------
192 ; bool intlcdcmp(cstr *a0, dstr *a1)
194 ; compares cstring a with dstring b in international mode.
195 ; a0 must be 'uppercased' as follows:
197 ; 0x00 - 0x60 -> 0x00 - 0x60
198 ; 0x61 - 0x7a -> 0x41 - 0x5a diff 0x20
199 ; 0x7b - 0xdf -> 0x7b - 0xdf
200 ; 0xe0 - 0xf6 -> 0xc0 - 0xd6 diff 0x20
201 ; 0xf7 -> 0xf7
202 ; 0xf8 - 0xfe -> 0xd8 - 0xde diff 0x20
203 ; 0xff -> 0xff
205 ; So if match then (d0 = d1) \/ (d1-d0 = 0x20)
206 ;-----------------------------------------------------------------------------
208 int intlcdcmp(const unsigned char *a0, const unsigned char *a1)
210 unsigned char len = *a1++;
211 if (len == 0)
212 return *a0 == '\0'; /* zero length string */
214 while (len--)
216 unsigned char c = *a0++;
217 unsigned char d;
218 if (c == '\0') return 0;
219 d = *a1++;
220 if ((d - c) > d) return 0; /* carry set */
221 if (c == d) continue;
222 if (d - c != 0x20) return 0;
223 #ifdef __GNUC__
224 switch (c)
226 case 0x41 ... 0x5a:
227 case 0xc0 ... 0xd6:
228 case 0xd8 ... 0xde:
229 break;
230 default:
231 return 0;
233 #else
234 if (!((c >= 0x41 && c <= 0x5a) ||
235 (c >= 0xc0 && c <= 0xd6) ||
236 (c >= 0xd8 && c <= 0xde)))
238 return 0;
240 #endif
242 return *a0 == '\0';