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