delint for clang
[AROS.git] / compiler / alib / invertstringforward.c
blob0c3b1e8f609f72360b3437d0a79923cdbcf454d6
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <libraries/commodities.h>
7 #include <proto/commodities.h>
8 #include <proto/exec.h>
9 #include <proto/alib.h>
10 #include <exec/memory.h>
11 #include <devices/keymap.h>
12 #include <devices/inputevent.h>
14 extern struct Library *CxBase;
16 /*****************************************************************************
18 NAME */
20 struct InputEvent *InvertStringForwd(
22 /* SYNOPSIS */
24 STRPTR str,
25 struct KeyMap *km
27 /* FUNCTION
28 Return a linked list of input events which would produce the string
29 'str' with the keymap 'km'.
31 INPUTS
32 str -- pointer to a (NULL-terminated) string that may contain
33 * ANSI character codes
34 * backslash-escaped characters:
35 \n -- carriage return
36 \r -- carriage return
37 \t -- tab
38 \\ -- backslash
39 * a description of an input event a la ParseIX() surrounded
40 by angle brackets
42 km -- keymap to use for the conversion or NULL to use the default
43 keymap
45 RESULT
46 A linked list of input events or NULL if something went wrong.
48 NOTES
50 EXAMPLE
51 An example string: "Hello <shift alt a>\n"
53 BUGS
55 SEE ALSO
56 commodities.library/ParseIX(), InvertString(), FreeIEvents()
58 INTERNALS
59 Ought to have an extra \< for < not starting an IX expression.
61 HISTORY
63 ******************************************************************************/
65 struct InputEvent *ieChain = NULL;
66 struct InputEvent *ie;
67 struct InputEvent *first = NULL;
68 UBYTE ansiCode;
69 UBYTE *start;
71 while(str && *str != '\0')
73 ie = AllocMem(sizeof(struct InputEvent), MEMF_PUBLIC | MEMF_CLEAR);
74 if (!ie)
76 if (first)
77 FreeIEvents(first);
78 return NULL;
81 if (!first)
82 first = ie;
84 if(ieChain != NULL)
85 ieChain->ie_NextEvent = ie;
87 ieChain = ie;
89 ie->ie_Class = IECLASS_RAWKEY;
90 ie->ie_EventAddress = NULL;
92 switch(*str)
94 case '\\' :
95 str++;
96 switch(*str)
98 case 't':
99 ansiCode = '\t';
100 break;
101 case 'r':
102 case 'n':
103 ansiCode = '\n';
104 break;
105 case '\\':
106 ansiCode = '\\';
107 break;
108 default :
109 /* FIXME: What to do if "\x" comes? */
110 /* stegerg: This? */
111 ansiCode = *str;
112 break;
115 if(InvertKeyMap(ansiCode, ie, km) == FALSE)
117 FreeIEvents(first);
118 return NULL;
121 str++;
123 break;
125 case '<' :
126 start = ++str;
128 while(*str && (*str != '>')) str++;
131 IX ix = {0};
132 LONG err;
134 *str = '\0';
135 err = ParseIX(start, &ix);
136 *str++ = '>';
138 if (err < 0)
140 FreeIEvents(first);
141 return NULL;
144 ie->ie_Class = ix.ix_Class;
145 ie->ie_Code = ix.ix_Code;
146 ie->ie_Qualifier = ix.ix_Qualifier;
148 break;
150 default :
151 if(InvertKeyMap(*str++, ie, km) == FALSE)
153 FreeIEvents(first);
154 return NULL;
157 break;
162 return first;
163 } /* InvertStringForwd */