]> icculus.org git repositories - btb/d2x.git/blob - main/editor/func.c
don't use hardcoded descriptions of joystick buttons/axes
[btb/d2x.git] / main / editor / func.c
1 /* $Id: func.c,v 1.4 2005-01-24 22:07:43 schaffner 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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * .
18  *
19  */
20
21 #ifdef RCS
22 static char rcsid[] = "$Id: func.c,v 1.4 2005-01-24 22:07:43 schaffner Exp $";
23 #endif
24
25 #ifdef HAVE_CONFIG_H
26 #include "conf.h"
27 #endif
28
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "func.h"
33 #include "strutil.h"
34
35 #define MAX_PARAMS 10
36
37 static FUNCTION * func_table = NULL;
38 static int func_size = 0;
39 static int initialized = 0;
40 static int func_params[MAX_PARAMS];
41
42 int func_howmany()
43 {
44         return func_size;
45 }
46
47 void func_init( FUNCTION * funtable, int size )
48 {
49         if (!initialized)
50         {
51                 initialized = 1;
52                 func_table = funtable;
53                 func_size = size;
54                 atexit( func_close );
55         }
56 }
57
58
59 void func_close()
60 {
61         if (initialized)
62         {
63                 initialized = 0;
64                 func_table = NULL;
65                 func_size = 0;
66         }
67 }
68
69 int (*func_get( char * name, int * numparams ))(void)
70 {
71         int i;
72
73         for (i=0; i<func_size; i++ )
74                 if (!stricmp( name, func_table[i].name ))
75                 {
76                         *numparams = func_table[i].nparams;
77                         return func_table[i].cfunction;
78                 }
79
80         return NULL;
81 }
82
83 int func_get_index( char * name )
84 {
85         int i;
86
87         for (i=0; i<func_size; i++ )
88                 if (!stricmp( name, func_table[i].name ))
89                 {
90                         return i;
91                 }
92
93         return -1;
94 }
95
96
97 int (*func_nget( int func_number, int * numparams, char **name ))(void)
98 {
99         if (func_number < func_size )
100         {
101                 *name = func_table[func_number].name;
102                 *numparams = func_table[func_number].nparams;
103                 return func_table[func_number].cfunction;
104         }
105
106         return NULL;
107 }
108
109 void func_set_param( int n, int value )
110 {
111         func_params[n] = value;
112 }
113
114 int func_get_param( int n )
115 {
116         return func_params[n];
117 }
118
119