]> icculus.org git repositories - btb/d2x.git/blob - ui/keypad.c
use PhysicsFS for saving levels
[btb/d2x.git] / ui / keypad.c
1 /* $Id: keypad.c,v 1.8 2005-02-26 11:17:01 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "conf.h"
17 #endif
18
19 #include <stdlib.h>
20 #include <math.h>
21 #include <string.h>
22
23
24 #include "fix.h"
25 #include "pstypes.h"
26 #include "gr.h"
27 #include "key.h"
28 #include "cfile.h"
29
30 #include "mono.h"
31
32 #include "ui.h"
33
34 #include "u_mem.h"
35 //#include "cflib.h"
36 #include "func.h"
37 #include "error.h"
38
39 #define MAX_NUM_PADS 20
40
41 static UI_GADGET_BUTTON * Pad[17];
42 static UI_KEYPAD * KeyPad[MAX_NUM_PADS];
43 static int active_pad;
44
45 static int desc_x, desc_y;
46
47 static int HotKey[17];
48 static int HotKey1[17];
49
50 #define REMOVE_EOL(s)     (*(strstr( (s), "\n" ))='\0')
51
52 int ui_pad_get_current()
53 {
54         return active_pad;
55 }
56
57 void ui_pad_init()
58 {
59         int i;
60
61         for (i=0; i< MAX_NUM_PADS; i++ )
62                 KeyPad[i] = NULL;
63
64         active_pad = -1;
65 }
66
67 void ui_pad_close()
68 {
69         int i, j;
70
71         for (i=0; i< MAX_NUM_PADS; i++ )
72                 if (KeyPad[i])
73                 {
74                         for (j=0; j<17; j++ )
75                                 d_free(KeyPad[i]->buttontext[j]);
76                         d_free( KeyPad[i] );
77                         KeyPad[i] = NULL;       
78                 }
79
80 }
81
82
83 void LineParse( int n, char * dest, char * source )
84 {
85         int i = 0, j=0, cn = 0;
86
87         // Go to the n'th line
88         while (cn < n )
89                 if ((unsigned char) source[i++] == 179)
90                         cn++;
91
92         // Read up until the next comma
93         while ((unsigned char) source[i] != 179)
94         {
95                 dest[j] = source[i++];
96                 j++;            
97         }
98
99         // Null-terminate       
100         dest[j++] = 0;
101 }
102
103 void ui_pad_activate( UI_WINDOW * wnd, int x, int y )
104 {
105         int w,h,row,col, n;
106         int bh, bw;
107
108         bw = 56; bh = 30;
109
110         gr_set_current_canvas( wnd->canvas );
111         ui_draw_box_in( x, y, x+(bw*4)+10 + 200, y+(bh*5)+45 );
112
113         x += 5;
114         y += 20;
115
116         desc_x = x+2;
117         desc_y = y-17;
118                 
119         n=0; row = 0; col = 0; w = 1; h = 1;
120         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
121         Pad[n]->canvas->cv_font = ui_small_font;
122         n=1; row = 0; col = 1; w = 1; h = 1;
123         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
124         Pad[n]->canvas->cv_font = ui_small_font;
125         n=2; row = 0; col = 2; w = 1; h = 1;
126         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
127         Pad[n]->canvas->cv_font = ui_small_font;
128         n=3; row = 0; col = 3; w = 1; h = 1;
129         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
130         Pad[n]->canvas->cv_font = ui_small_font;
131         n=4; row = 1; col = 0; w = 1; h = 1; 
132         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
133         Pad[n]->canvas->cv_font = ui_small_font;
134         n=5; row = 1; col = 1; w = 1; h = 1; 
135         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
136         Pad[n]->canvas->cv_font = ui_small_font;
137         n=6; row = 1; col = 2; w = 1; h = 1; 
138         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
139         Pad[n]->canvas->cv_font = ui_small_font;
140         n=7; row = 1; col = 3; w = 1; h = 2; 
141         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
142         Pad[n]->canvas->cv_font = ui_small_font;
143         n=8; row = 2; col = 0; w = 1; h = 1; 
144         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
145         Pad[n]->canvas->cv_font = ui_small_font;
146         n=9; row = 2; col = 1; w = 1; h = 1; 
147         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
148         Pad[n]->canvas->cv_font = ui_small_font;
149         n=10; row = 2; col = 2; w = 1; h = 1;
150         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
151         Pad[n]->canvas->cv_font = ui_small_font;
152         n=11; row = 3; col = 0; w = 1; h = 1;
153         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
154         Pad[n]->canvas->cv_font = ui_small_font;
155         n=12; row = 3; col = 1; w = 1; h = 1;
156         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
157         Pad[n]->canvas->cv_font = ui_small_font;
158         n=13; row = 3; col = 2; w = 1; h = 1;
159         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
160         Pad[n]->canvas->cv_font = ui_small_font;
161         n=14; row = 3; col = 3; w = 1; h = 2; 
162         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
163         Pad[n]->canvas->cv_font = ui_small_font;
164         n=15; row = 4; col = 0; w = 2; h = 1;
165         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
166         Pad[n]->canvas->cv_font = ui_small_font;
167         n=16; row = 4; col = 2; w = 1; h = 1; 
168         Pad[n] = ui_add_gadget_button( wnd, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL );
169         Pad[n]->canvas->cv_font = ui_small_font;
170
171         HotKey[0] = KEY_CTRLED + KEY_NUMLOCK;
172         HotKey[1] = KEY_CTRLED + KEY_PADDIVIDE;
173         HotKey[2] = KEY_CTRLED + KEY_PADMULTIPLY;
174         HotKey[3] = KEY_CTRLED + KEY_PADMINUS;
175         HotKey[4] = KEY_CTRLED + KEY_PAD7;
176         HotKey[5] = KEY_CTRLED + KEY_PAD8;
177         HotKey[6] = KEY_CTRLED + KEY_PAD9;
178         HotKey[7] = KEY_CTRLED + KEY_PADPLUS;
179         HotKey[8] = KEY_CTRLED + KEY_PAD4;
180         HotKey[9] = KEY_CTRLED + KEY_PAD5;
181         HotKey[10] = KEY_CTRLED + KEY_PAD6;
182         HotKey[11] = KEY_CTRLED + KEY_PAD1;
183         HotKey[12] = KEY_CTRLED + KEY_PAD2;
184         HotKey[13] = KEY_CTRLED + KEY_PAD3;
185         HotKey[14] = KEY_CTRLED + KEY_PADENTER;
186         HotKey[15] = KEY_CTRLED + KEY_PAD0;
187         HotKey[16] = KEY_CTRLED + KEY_PADPERIOD;
188
189         HotKey1[0] = KEY_SHIFTED + KEY_CTRLED + KEY_NUMLOCK;
190         HotKey1[1] = KEY_SHIFTED + KEY_CTRLED + KEY_PADDIVIDE;
191         HotKey1[2] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMULTIPLY;
192         HotKey1[3] = KEY_SHIFTED + KEY_CTRLED + KEY_PADMINUS;
193         HotKey1[4] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD7;
194         HotKey1[5] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD8;
195         HotKey1[6] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD9;
196         HotKey1[7] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPLUS;
197         HotKey1[8] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD4;
198         HotKey1[9] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD5;
199         HotKey1[10] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD6;
200         HotKey1[11] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD1;
201         HotKey1[12] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD2;
202         HotKey1[13] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD3;
203         HotKey1[14] = KEY_SHIFTED + KEY_CTRLED + KEY_PADENTER;
204         HotKey1[15] = KEY_SHIFTED + KEY_CTRLED + KEY_PAD0;
205         HotKey1[16] = KEY_SHIFTED + KEY_CTRLED + KEY_PADPERIOD;
206
207         active_pad = -1;
208
209 }
210
211
212 void ui_pad_deactivate()
213 {
214         int i;
215
216         for (i=0; i<17; i++ )
217         {
218                 Pad[i]->text = NULL;
219         }
220 }
221
222 static void ui_pad_set_active( int n )
223 {
224         int np;
225         char * name;
226         int i, j;
227
228         
229
230         gr_set_current_canvas( NULL );
231         gr_setcolor( CWHITE );
232         gr_urect( desc_x, desc_y, desc_x+ 56*4-1, desc_y+15 );
233         gr_set_fontcolor( CBLACK, CWHITE );
234         gr_ustring( desc_x, desc_y, KeyPad[n]->description );
235                 
236         for (i=0; i<17; i++ )
237         {
238                 Pad[i]->text = KeyPad[n]->buttontext[i];
239                 Pad[i]->status = 1;
240                 Pad[i]->user_function = NULL;
241                 Pad[i]->dim_if_no_function = 1;
242                 Pad[i]->hotkey = -1;
243                                 
244                 for (j=0; j< KeyPad[n]->numkeys; j++ )
245                 {
246                         if (HotKey[i] == KeyPad[n]->keycode[j] )
247                         {
248                                 Pad[i]->hotkey =  HotKey[i];
249                                 Pad[i]->user_function = func_nget( KeyPad[n]->function_number[j], &np, &name );
250                         }
251                         if (HotKey1[i] == KeyPad[n]->keycode[j] )
252                         {
253                                 Pad[i]->hotkey1 =  HotKey1[i];
254                                 Pad[i]->user_function1 = func_nget( KeyPad[n]->function_number[j], &np, &name );
255                         }
256                 }
257         }
258
259         active_pad = n;
260 }
261
262 void ui_pad_goto(int n)
263 {
264         if ( KeyPad[n] != NULL )
265                 ui_pad_set_active(n);
266 }
267
268 void ui_pad_goto_next()
269 {
270         int i, si;
271
272         i = active_pad + 1;
273         si = i;
274         
275         while( KeyPad[i]==NULL )
276         {
277                 i++;
278                 if (i >= MAX_NUM_PADS)
279                         i = 0;
280                 if (i == si )
281                         break;
282         }
283         ui_pad_set_active(i);
284 }
285
286 void ui_pad_goto_prev()
287 {
288         int i, si;
289
290         if (active_pad == -1 ) 
291                 active_pad = MAX_NUM_PADS;
292         
293         i = active_pad - 1;
294         if (i<0) i= MAX_NUM_PADS - 1;
295         si = i;
296         
297         while( KeyPad[i]==NULL )
298         {
299                 i--;
300                 if (i < 0)
301                         i = MAX_NUM_PADS-1;
302                 if (i == active_pad )
303                         break;
304         }
305         ui_pad_set_active(i);
306 }
307
308 void ui_pad_read( int n, char * filename )
309 {
310         char * ptr;
311         char buffer[100];
312         char text[100];
313         char line_buffer[200];
314         CFILE * infile;
315         int linenumber = 0;
316         int i;
317         int keycode, functionnumber;
318
319         infile = cfopen( filename, "rt" );
320         if (!infile) {
321                 Warning( "Couldn't find %s", filename );
322                 return;
323         }
324                                           
325         MALLOC( KeyPad[n], UI_KEYPAD, 1 );
326                         
327         for (i=0; i < 17; i++ ) {
328                 MALLOC( KeyPad[n]->buttontext[i], char, 100 );
329         }
330
331         KeyPad[n]->numkeys = 0;
332
333         for (i=0; i<100; i++ )
334         {
335                 KeyPad[n]->keycode[i] = -1;
336                 KeyPad[n]->function_number[i] = 0;
337         }
338
339         while ( linenumber < 22)
340         {
341                 cfgets( buffer, 100, infile );
342
343                 switch( linenumber+1 )
344                 {
345                 case 1:
346                         strncpy( KeyPad[n]->description, buffer, 100 );
347                         break;
348                 //===================== ROW 0 ==============================
349                 case 3:
350                         LineParse( 1, text, buffer );
351                         sprintf( KeyPad[n]->buttontext[0], "%s\n", text );
352                         LineParse( 2, text, buffer );
353                         sprintf( KeyPad[n]->buttontext[1], "%s\n", text );
354                         LineParse( 3, text, buffer );
355                         sprintf( KeyPad[n]->buttontext[2], "%s\n", text );
356                         LineParse( 4, text, buffer );
357                         sprintf( KeyPad[n]->buttontext[3], "%s\n", text );
358                         break;
359                 case 4:
360                         LineParse( 1, text, buffer );
361                         sprintf( KeyPad[n]->buttontext[0], "%s%s\n", KeyPad[n]->buttontext[0],text );
362                         LineParse( 2, text, buffer );    
363                         sprintf( KeyPad[n]->buttontext[1], "%s%s\n", KeyPad[n]->buttontext[1],text );
364                         LineParse( 3, text, buffer );
365                         sprintf( KeyPad[n]->buttontext[2], "%s%s\n", KeyPad[n]->buttontext[2],text );
366                         LineParse( 4, text, buffer );
367                         sprintf( KeyPad[n]->buttontext[3], "%s%s\n", KeyPad[n]->buttontext[3],text );
368                         break;
369                 case 5:
370                         LineParse( 1, text, buffer );
371                         sprintf( KeyPad[n]->buttontext[0], "%s%s", KeyPad[n]->buttontext[0],text );
372                         LineParse( 2, text, buffer );    
373                         sprintf( KeyPad[n]->buttontext[1], "%s%s", KeyPad[n]->buttontext[1],text );
374                         LineParse( 3, text, buffer );
375                         sprintf( KeyPad[n]->buttontext[2], "%s%s", KeyPad[n]->buttontext[2],text );
376                         LineParse( 4, text, buffer );
377                         sprintf( KeyPad[n]->buttontext[3], "%s%s", KeyPad[n]->buttontext[3],text );
378                         break;
379                 //===================== ROW 1 ==============================
380                 case 7:
381                         LineParse( 1, text, buffer );
382                         sprintf( KeyPad[n]->buttontext[4], "%s\n", text );
383                         LineParse( 2, text, buffer );    
384                         sprintf( KeyPad[n]->buttontext[5], "%s\n", text );
385                         LineParse( 3, text, buffer);       
386                         sprintf( KeyPad[n]->buttontext[6], "%s\n", text );
387                         LineParse( 4, text, buffer );
388                         sprintf( KeyPad[n]->buttontext[7], "%s\n", text );
389                         break;
390                 case 8:
391                         LineParse( 1, text, buffer );
392                         sprintf( KeyPad[n]->buttontext[4], "%s%s\n", KeyPad[n]->buttontext[4],text );
393                         LineParse( 2, text, buffer );    
394                         sprintf( KeyPad[n]->buttontext[5], "%s%s\n", KeyPad[n]->buttontext[5],text );
395                         LineParse( 3, text, buffer );
396                         sprintf( KeyPad[n]->buttontext[6], "%s%s\n", KeyPad[n]->buttontext[6],text );
397                         LineParse( 4, text, buffer );
398                         sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
399                         break;
400                 case 9:
401                         LineParse( 1, text, buffer );
402                         sprintf( KeyPad[n]->buttontext[4], "%s%s", KeyPad[n]->buttontext[4],text );
403                         LineParse( 2, text, buffer );    
404                         sprintf( KeyPad[n]->buttontext[5], "%s%s", KeyPad[n]->buttontext[5],text );
405                         LineParse( 3, text, buffer );
406                         sprintf( KeyPad[n]->buttontext[6], "%s%s", KeyPad[n]->buttontext[6],text );
407                         LineParse( 4, text, buffer );
408                         sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
409                         break;
410                 case 10:
411                         ptr = strrchr( buffer, (char) 179 );
412                         *ptr = 0;
413                         ptr = strrchr( buffer, (char) 180 );    ptr++;
414                         sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],ptr );
415                         break;
416                 //======================= ROW 2 ==============================
417                 case 11:
418                         LineParse( 1, text, buffer );
419                         sprintf( KeyPad[n]->buttontext[8], "%s\n", text );
420                         LineParse( 2, text, buffer );    
421                         sprintf( KeyPad[n]->buttontext[9], "%s\n", text );
422                         LineParse( 3, text, buffer);       
423                         sprintf( KeyPad[n]->buttontext[10], "%s\n", text );
424                         LineParse( 4, text, buffer );
425                         sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
426                         break;
427                 case 12:
428                         LineParse( 1, text, buffer );
429                         sprintf( KeyPad[n]->buttontext[8], "%s%s\n", KeyPad[n]->buttontext[8],text );
430                         LineParse( 2, text, buffer );    
431                         sprintf( KeyPad[n]->buttontext[9], "%s%s\n", KeyPad[n]->buttontext[9],text );
432                         LineParse( 3, text, buffer );
433                         sprintf( KeyPad[n]->buttontext[10], "%s%s\n", KeyPad[n]->buttontext[10],text );
434                         LineParse( 4, text, buffer );
435                         sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text );
436                         break;
437                 case 13:
438                         LineParse( 1, text, buffer );
439                         sprintf( KeyPad[n]->buttontext[8], "%s%s", KeyPad[n]->buttontext[8],text );
440                         LineParse( 2, text, buffer );    
441                         sprintf( KeyPad[n]->buttontext[9], "%s%s", KeyPad[n]->buttontext[9],text );
442                         LineParse( 3, text, buffer );
443                         sprintf( KeyPad[n]->buttontext[10], "%s%s", KeyPad[n]->buttontext[10],text );
444                         LineParse( 4, text, buffer );
445                         sprintf( KeyPad[n]->buttontext[7], "%s%s", KeyPad[n]->buttontext[7],text );
446                         break;
447                 // ====================== ROW 3 =========================
448                 case 15:
449                         LineParse( 1, text, buffer );
450                         sprintf( KeyPad[n]->buttontext[11], "%s\n", text );
451                         LineParse( 2, text, buffer );    
452                         sprintf( KeyPad[n]->buttontext[12], "%s\n", text );
453                         LineParse( 3, text, buffer);       
454                         sprintf( KeyPad[n]->buttontext[13], "%s\n", text );
455                         LineParse( 4, text, buffer );
456                         sprintf( KeyPad[n]->buttontext[14], "%s\n", text );
457                         break;
458                 case 16:
459                         LineParse( 1, text, buffer );
460                         sprintf( KeyPad[n]->buttontext[11], "%s%s\n", KeyPad[n]->buttontext[11],text );
461                         LineParse( 2, text, buffer );    
462                         sprintf( KeyPad[n]->buttontext[12], "%s%s\n", KeyPad[n]->buttontext[12],text );
463                         LineParse( 3, text, buffer );
464                         sprintf( KeyPad[n]->buttontext[13], "%s%s\n", KeyPad[n]->buttontext[13],text );
465                         LineParse( 4, text, buffer );
466                         sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
467                         break;
468                 case 17:
469                         LineParse( 1, text, buffer );
470                         sprintf( KeyPad[n]->buttontext[11], "%s%s", KeyPad[n]->buttontext[11],text );
471                         LineParse( 2, text, buffer );    
472                         sprintf( KeyPad[n]->buttontext[12], "%s%s", KeyPad[n]->buttontext[12],text );
473                         LineParse( 3, text, buffer );
474                         sprintf( KeyPad[n]->buttontext[13], "%s%s", KeyPad[n]->buttontext[13],text );
475                         LineParse( 4, text, buffer );
476                         sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
477                         break;
478                 case 18:
479                         ptr = strrchr( buffer, (char) 179 );
480                         *ptr = 0;
481                         ptr = strrchr( buffer, (char) 180 ); ptr++;
482                         sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14], ptr );
483                         break;
484                 //======================= ROW 4 =========================
485                 case 19:
486                         LineParse( 1, text, buffer );
487                         sprintf( KeyPad[n]->buttontext[15], "%s\n", text );
488                         LineParse( 2, text, buffer );    
489                         sprintf( KeyPad[n]->buttontext[16], "%s\n", text );
490                         LineParse( 3, text, buffer );
491                         sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
492                         break;
493                 case 20:
494                         LineParse( 1, text, buffer );
495                         sprintf( KeyPad[n]->buttontext[15], "%s%s\n", KeyPad[n]->buttontext[15],text );
496                         LineParse( 2, text, buffer );    
497                         sprintf( KeyPad[n]->buttontext[16], "%s%s\n", KeyPad[n]->buttontext[16],text );
498                         LineParse( 3, text, buffer );
499                         sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text );
500                         break;
501                 case 21:
502                         LineParse( 1, text, buffer );
503                         sprintf( KeyPad[n]->buttontext[15], "%s%s", KeyPad[n]->buttontext[15],text );
504                         LineParse( 2, text, buffer );    
505                         sprintf( KeyPad[n]->buttontext[16], "%s%s", KeyPad[n]->buttontext[16],text );
506                         LineParse( 3, text, buffer );
507                         sprintf( KeyPad[n]->buttontext[14], "%s%s", KeyPad[n]->buttontext[14],text );
508                         break;
509                 }
510                                                                                 
511                 linenumber++;   
512         }
513
514         // Get the keycodes...
515
516         while (cfgets(line_buffer, 200, infile))
517         {
518                 sscanf(line_buffer, " %s %s ", text, buffer);
519                 keycode = DecodeKeyText(text);
520                 functionnumber = func_get_index(buffer);
521                 if (functionnumber==-1)
522                 {
523                         Error( "Unknown function, %s, in %s\n", buffer, filename );
524                 } else if (keycode==-1)
525                 {
526                         Error( "Unknown keystroke, %s, in %s\n", text, filename );
527                         //MessageBox( -2, -2, 1, buffer, "Ok" );
528
529                 } else {
530                         KeyPad[n]->keycode[KeyPad[n]->numkeys] = keycode;
531                         KeyPad[n]->function_number[KeyPad[n]->numkeys] = functionnumber;
532                         KeyPad[n]->numkeys++;
533                 }
534         }
535         
536         cfclose(infile);
537
538 }