Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / commodities / parseix.c
blob36bf9dc052e488708dde4b9b9711ec39253d319d
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #ifndef DEBUG
10 #define DEBUG 0
11 #endif
13 #include "cxintern.h"
15 #include <aros/debug.h>
17 #include <libraries/commodities.h>
18 #include <proto/commodities.h>
19 #include <proto/utility.h>
20 #define __NOLIBBASE__ 1
21 #include <proto/keymap.h>
22 #undef __NOLIBBASE__
23 #include <devices/inputevent.h>
24 #include <devices/keymap.h>
25 #include <string.h>
27 #include "parse.h"
29 #define DEBUG_PARSEIX(x) ;
30 #define DEBUG_PMATCH(x) ;
32 BOOL pMatch(pix_S[], CONST_STRPTR, LONG *, BOOL *, struct Library *CxBase);
33 VOID GetNext(CONST_STRPTR *);
34 BOOL IsSeparator(char);
36 /*****************************************************************************
38 NAME */
40 AROS_LH2(LONG, ParseIX,
42 /* SYNOPSIS */
44 AROS_LHA(CONST_STRPTR, desc, A0),
45 AROS_LHA(IX * , ix , A1),
47 /* LOCATION */
49 struct Library *, CxBase, 22, Commodities)
51 /* FUNCTION
53 Fill in an InputXpression 'ix' according to the specifications given
54 in the string pointed to by 'desc'.
56 The string should be formatted according to:
58 [class] {[-] (qualifier|synonym)} [[-] upstroke] [HighMap|ANSICode]
60 For more information on this, consult "xxx/CxParse.doc".
62 INPUTS
64 desc -- pointer to the string specifying the conditions and codes of
65 the InputXpression.
66 ix -- pointer to an (uninitizlized) InputXpression structure that
67 will be filled according to 'desc'.
69 RESULT
71 0 -- Everything went OK.
72 -1 -- Tokens after end
73 -2 -- 'desc' was NULL
75 NOTES
77 EXAMPLE
79 BUGS
81 SEE ALSO
83 MatchIX(), <libraries/commodities.h>
85 INTERNALS
87 HISTORY
89 10.05.97 SDuvan implemented
91 ******************************************************************************/
94 AROS_LIBFUNC_INIT
96 LONG val;
97 BOOL dash, upstrdash = TRUE;
98 BOOL upstroke = FALSE;
100 struct InputEvent event;
102 /* Set as standard if no class is specified in the description */
103 #if 0
104 /* Caller is expected to set this! */
105 ix->ix_Version = IX_VERSION;
106 #endif
107 ix->ix_Class = IECLASS_RAWKEY;
108 ix->ix_Code = 0;
109 ix->ix_CodeMask = 0xFFFF;
110 ix->ix_Qualifier = 0;
111 ix->ix_QualMask = IX_NORMALQUALS & ~(IEQUALIFIER_INTERRUPT | IEQUALIFIER_MULTIBROADCAST);
112 ix->ix_QualSame = 0;
114 if (desc == NULL)
116 ix->ix_Code = 0xFFFF;
118 return -2;
121 DEBUG_PARSEIX(dprintf("ParseIX: ix = 0x%lx, desc = \"%s\"\n", ix, desc));
123 while (IsSeparator(*desc))
125 desc++;
128 dash = FALSE;
130 if (pMatch(pix_Class, desc, &val, &dash, CxBase))
132 ix->ix_Class = val;
133 GetNext(&desc);
136 while (TRUE)
138 dash = TRUE;
140 if (pMatch(pix_IEvent, desc, &val, &dash, CxBase))
142 if (dash)
144 ix->ix_QualMask &= ~val;
146 else
148 ix->ix_Qualifier |= val;
151 GetNext(&desc);
153 else
155 dash = TRUE;
157 if (pMatch(pix_Synonyms, desc, &val, &dash, CxBase))
159 ix->ix_QualSame |= val;
161 if (dash)
163 switch (val)
165 case IXSYM_SHIFT:
166 ix->ix_QualMask &= ~IXSYM_SHIFTMASK;
167 break;
169 case IXSYM_ALT:
170 ix->ix_QualMask &= ~IXSYM_ALTMASK;
171 break;
173 case IXSYM_CAPS:
174 ix->ix_QualMask &= ~IXSYM_CAPSMASK;
175 break;
178 else
180 switch (val)
182 case IXSYM_SHIFT:
183 ix->ix_Qualifier |= IXSYM_SHIFTMASK;
184 break;
186 case IXSYM_ALT:
187 ix->ix_Qualifier |= IXSYM_ALTMASK;
188 break;
190 case IXSYM_CAPS:
191 ix->ix_Qualifier |= IXSYM_CAPSMASK;
192 break;
196 GetNext(&desc);
198 else
200 break;
205 if (pMatch(pix_Upstroke, desc, &val, &upstrdash, CxBase))
207 upstroke = TRUE;
208 GetNext(&desc);
211 dash = FALSE;
213 if (pMatch(pix_Highmap, desc, &val, &dash, CxBase))
215 ix->ix_Code = val;
217 else
219 if (*desc != '\0')
221 if (InvertKeyMap(*desc, &event, NULL))
223 ix->ix_Code = event.ie_Code;
228 if (upstroke)
230 if (upstrdash)
232 ix->ix_CodeMask &= ~IECODE_UP_PREFIX;
234 else
236 ix->ix_Code |= IECODE_UP_PREFIX;
240 while (!(IsSeparator(*desc)))
242 desc++;
245 DEBUG_PARSEIX(dprintf("ParseIX: Class 0x%lx Code 0x%lx CodeMask 0x%lx\n"
246 "ParseIX: Qualifier 0x%lx QualMask 0x%lx QualSame 0x%lx\n",
247 ix->ix_Class,
248 ix->ix_Code,
249 ix->ix_CodeMask,
250 ix->ix_Qualifier,
251 ix->ix_QualMask,
252 ix->ix_QualSame));
254 if (*desc == '\0')
256 return 0;
258 else
260 DEBUG_PARSEIX(dprintf("ParseIX: fail, desc 0x%lx *desc 0x%lx\n", desc, *desc));
261 return -1;
264 AROS_LIBFUNC_EXIT
265 } /* ParseIX */
268 BOOL pMatch(pix_S words[], CONST_STRPTR string, LONG *v, BOOL *dash,
269 struct Library *CxBase)
271 CONST_STRPTR nstr = string;
272 int i;
274 DEBUG_PMATCH(dprintf("pMatch: words[0] = \"%s\" string \"%s\" dash %d\n",
275 words[0].name, string, *dash));
277 if (*dash)
279 if (*nstr == '-')
281 nstr++;
282 *dash = TRUE;
284 else
286 *dash = FALSE;
290 for (i = 0; words[i].name != NULL; i++)
292 if (Strnicmp(nstr, words[i].name, strlen(words[i].name)) == 0)
294 *v = words[i].value;
295 DEBUG_PMATCH(dprintf("pMatch: value 0x%lx\n", *v));
296 return TRUE;
300 DEBUG_PMATCH(dprintf("pMatch: not found\n"));
301 return FALSE;
305 VOID GetNext(CONST_STRPTR *str)
307 while (!(IsSeparator(**str)))
309 (*str)++;
312 while (IsSeparator(**str) && !(**str=='\0'))
314 (*str)++;
319 BOOL IsSeparator(char a)
321 if (a == ' ' || a == '\n' || a == '\t' || a == ',' || a == '\0')
323 return TRUE;
325 else
327 return FALSE;