- Tabs to spaces.
[AROS.git] / workbench / libs / locale / rexxhost.c
blobf65a31b398bc4aa0970dcd5c42bf95d9900914dd
1 #include <exec/types.h>
3 #ifdef __MORPHOS__
4 #define CVa2i(__p0) \
5 LP1(300, LONG , CVa2i, \
6 STRPTR , __p0, a0, \
7 , RexxSysBase, 0, 0, 0, 0, 0, 0)
9 #define CVi2az(__p0, __p1, __p2) \
10 LP3(318, LONG , CVi2az, \
11 STRPTR , __p0, a0, \
12 LONG , __p1, d0, \
13 LONG , __p2, d1, \
14 , RexxSysBase, 0, 0, 0, 0, 0, 0)
15 #endif
17 #include <proto/exec.h>
18 #include <proto/rexxsyslib.h>
19 #include <rexx/errors.h>
20 #include <aros/asmcall.h>
21 #include "locale_intern.h"
22 #include <proto/locale.h>
24 #include <string.h>
25 #include <stdlib.h>
28 static LONG rxGetCatalogStr(struct LocaleBase *LocaleBase,
29 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
31 *resstr =
32 GetCatalogStr((struct Catalog *)CVa2i(rxmsg->rm_Args[1]),
33 atol(rxmsg->rm_Args[2]), rxmsg->rm_Args[3]);
34 return strlen(*resstr);
37 static LONG rxGetLocaleStr(struct LocaleBase *LocaleBase,
38 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
40 *resstr = GetLocaleStr(locale, atol(rxmsg->rm_Args[1]));
41 return strlen(*resstr);
44 static LONG rxOpenCatalog(struct LocaleBase *LocaleBase,
45 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
47 APTR cat =
48 OpenCatalog(locale, rxmsg->rm_Args[1], OC_BuiltInLanguage,
49 (ULONG) rxmsg->rm_Args[2], OC_Version, atol(rxmsg->rm_Args[3]),
50 TAG_DONE);
51 return CVi2az(*resstr, (LONG) cat, 12);
54 static LONG rxCloseCatalog(struct LocaleBase *LocaleBase,
55 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
57 CloseCatalog((struct Catalog *)CVa2i(rxmsg->rm_Args[1]));
58 return 0;
61 static LONG rxStrnCmp(struct LocaleBase *LocaleBase, struct Locale *locale,
62 struct RexxMsg *rxmsg, STRPTR * resstr)
64 LONG reslen =
65 StrnCmp(locale, rxmsg->rm_Args[1], rxmsg->rm_Args[2], -1,
66 atol(rxmsg->rm_Args[3]));
68 if (reslen < 0)
70 *resstr[0] = '-';
71 *resstr[1] = '1';
72 reslen = 2;
74 else if (reslen > 0)
76 *resstr[0] = '1';
77 reslen = 1;
79 else
81 *resstr[0] = '0';
82 reslen = 1;
85 return reslen;
88 static LONG rxConvToLower(struct LocaleBase *LocaleBase,
89 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
91 *resstr[0] = (UBYTE) ConvToLower(locale, *rxmsg->rm_Args[1]);
92 return 1;
95 static LONG rxConvToUpper(struct LocaleBase *LocaleBase,
96 struct Locale *locale, struct RexxMsg *rxmsg, STRPTR * resstr)
98 *resstr[0] = (UBYTE) ConvToUpper(locale, *rxmsg->rm_Args[1]);
99 return 1;
102 static LONG rxIsAlpha(struct LocaleBase *LocaleBase, struct Locale *locale,
103 struct RexxMsg *rxmsg, STRPTR * resstr)
105 if (IsAlpha(locale, *rxmsg->rm_Args[1]))
106 *resstr[0] = '1';
107 else
108 *resstr[0] = '0';
109 return 1;
112 static LONG rxIsSpace(struct LocaleBase *LocaleBase, struct Locale *locale,
113 struct RexxMsg *rxmsg, STRPTR * resstr)
115 if (IsSpace(locale, *rxmsg->rm_Args[1]))
116 *resstr[0] = '1';
117 else
118 *resstr[0] = '0';
119 return 1;
122 static LONG rxIsDigit(struct LocaleBase *LocaleBase, struct Locale *locale,
123 struct RexxMsg *rxmsg, STRPTR * resstr)
125 if (IsDigit(locale, *rxmsg->rm_Args[1]))
126 *resstr[0] = '1';
127 else
128 *resstr[0] = '0';
129 return 1;
132 static LONG rxIsGraph(struct LocaleBase *LocaleBase, struct Locale *locale,
133 struct RexxMsg *rxmsg, STRPTR * resstr)
135 if (IsGraph(locale, *rxmsg->rm_Args[1]))
136 *resstr[0] = '1';
137 else
138 *resstr[0] = '0';
139 return 1;
142 static LONG rxIsAlNum(struct LocaleBase *LocaleBase, struct Locale *locale,
143 struct RexxMsg *rxmsg, STRPTR * resstr)
145 if (IsAlNum(locale, *rxmsg->rm_Args[1]))
146 *resstr[0] = '1';
147 else
148 *resstr[0] = '0';
149 return 1;
152 static LONG rxIsCntrl(struct LocaleBase *LocaleBase, struct Locale *locale,
153 struct RexxMsg *rxmsg, STRPTR * resstr)
155 if (IsCntrl(locale, *rxmsg->rm_Args[1]))
156 *resstr[0] = '1';
157 else
158 *resstr[0] = '0';
159 return 1;
162 static LONG rxIsLower(struct LocaleBase *LocaleBase, struct Locale *locale,
163 struct RexxMsg *rxmsg, STRPTR * resstr)
165 if (IsLower(locale, *rxmsg->rm_Args[1]))
166 *resstr[0] = '1';
167 else
168 *resstr[0] = '0';
169 return 1;
172 static LONG rxIsPunct(struct LocaleBase *LocaleBase, struct Locale *locale,
173 struct RexxMsg *rxmsg, STRPTR * resstr)
175 if (IsPunct(locale, *rxmsg->rm_Args[1]))
176 *resstr[0] = '1';
177 else
178 *resstr[0] = '0';
179 return 1;
182 static LONG rxIsUpper(struct LocaleBase *LocaleBase, struct Locale *locale,
183 struct RexxMsg *rxmsg, STRPTR * resstr)
185 if (IsUpper(locale, *rxmsg->rm_Args[1]))
186 *resstr[0] = '1';
187 else
188 *resstr[0] = '0';
189 return 1;
192 static LONG rxIsPrint(struct LocaleBase *LocaleBase, struct Locale *locale,
193 struct RexxMsg *rxmsg, STRPTR * resstr)
195 if (IsPrint(locale, *rxmsg->rm_Args[1]))
196 *resstr[0] = '1';
197 else
198 *resstr[0] = '0';
199 return 1;
202 static LONG rxIsXDigit(struct LocaleBase *LocaleBase, struct Locale *locale,
203 struct RexxMsg *rxmsg, STRPTR * resstr)
205 if (IsXDigit(locale, *rxmsg->rm_Args[1]))
206 *resstr[0] = '1';
207 else
208 *resstr[0] = '0';
209 return 1;
212 struct dispentry
214 CONST_STRPTR FuncName;
215 LONG(*Function) (struct LocaleBase *, struct Locale *,
216 struct RexxMsg *, STRPTR *);
217 ULONG NumArgs;
220 /* MUST be alphabetically sorted! */
221 struct dispentry disptable[] = {
222 {"CLOSECATALOG", rxCloseCatalog, 1},
223 {"CONVTOLOWER", rxConvToLower, 1},
224 {"CONVTOUPPER", rxConvToUpper, 1},
225 {"GETCATALOGSTR", rxGetCatalogStr, 3},
226 {"GETLOCALESTR", rxGetLocaleStr, 1}, /*** NEW ***/
227 {"ISALNUM", rxIsAlNum, 1},
228 {"ISALPHA", rxIsAlpha, 1},
229 {"ISCNTRL", rxIsCntrl, 1},
230 {"ISDIGIT", rxIsDigit, 1},
231 {"ISGRAPH", rxIsGraph, 1},
232 {"ISLOWER", rxIsLower, 1},
233 {"ISPRINT", rxIsPrint, 1},
234 {"ISPUNCT", rxIsPunct, 1},
235 {"ISSPACE", rxIsSpace, 1},
236 {"ISUPPER", rxIsUpper, 1},
237 {"ISXDIGIT", rxIsXDigit, 1},
238 {"OPENCATALOG", rxOpenCatalog, 3},
239 {"STRNCMP", rxStrnCmp, 3}
242 int dispcomp(const void *name, const void *dispentry)
244 return stricmp(name, ((const struct dispentry *)dispentry)->FuncName);
248 /*****************************************************************************
250 NAME */
252 AROS_LH1(ULONG, RexxHost,
254 /* SYNOPSIS */
255 AROS_LHA(struct RexxMsg *, rxmsg, A0),
257 /* LOCATION */
258 struct LocaleBase *, LocaleBase, 5, Locale)
260 /* FUNCTION
261 locale.library rexxhost interface
263 *****************************************************************************/
266 AROS_LIBFUNC_INIT
268 struct Locale *locale =
269 (struct Locale *)IntLB(LocaleBase)->lb_CurrentLocale;
270 struct dispentry *dispentry;
271 LONG reslen;
272 UBYTE resbuf[12];
273 STRPTR argstr = resbuf;
275 if (!RexxSysBase)
276 return (ERR10_014);
277 if (!rxmsg || !IsRexxMsg(rxmsg) || !(rxmsg->rm_Action & RXFUNC)
278 || !rxmsg->rm_Args[0])
279 return (ERR10_010);
281 if (!(dispentry =
282 bsearch(rxmsg->rm_Args[0], disptable,
283 sizeof(disptable) / sizeof(struct dispentry),
284 sizeof(struct dispentry), dispcomp)))
285 return (ERR10_001);
286 if ((rxmsg->rm_Action & RXARGMASK) != dispentry->NumArgs)
287 return (ERR10_017);
289 reslen = dispentry->Function(LocaleBase, locale, rxmsg, &argstr);
291 if (!(argstr = CreateArgstring(argstr, reslen)))
292 return (ERR10_003);
294 #ifdef __MORPHOS__
295 REG_A0 = (ULONG) argstr;
296 #else
297 #error register a0 must be set to argstr before returning...
298 #endif
300 return 0;
302 AROS_LIBFUNC_EXIT