]> icculus.org git repositories - btb/d2x.git/blob - ui/func.c
remove rcs tags
[btb/d2x.git] / ui / func.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 <string.h>
20
21 #include "func.h"
22
23 #define MAX_PARAMS 10
24
25 static FUNCTION * func_table = NULL;
26 static int func_size = 0;
27 static int initialized = 0;
28 static int func_params[MAX_PARAMS];
29
30 int func_howmany()
31 {
32         return func_size;
33 }
34
35 void func_init( FUNCTION * funtable, int size )
36 {
37         if (!initialized)
38         {
39                 initialized = 1;
40                 func_table = funtable;
41                 func_size = size;
42                 atexit( func_close );
43         }
44 }
45
46
47 void func_close()
48 {
49         if (initialized)
50         {
51                 initialized = 0;
52                 func_table = NULL;
53                 func_size = 0;
54         }
55 }
56
57 int (*func_get( char * name, int * numparams ))(void)
58 {
59         int i;
60
61         for (i=0; i<func_size; i++ )
62                 if (!strcmpi( name, func_table[i].name ))
63                 {
64                         *numparams = func_table[i].nparams;
65                         return func_table[i].cfunction;
66                 }
67
68         return NULL;
69 }
70
71 int func_get_index( char * name )
72 {
73         int i;
74
75         for (i=0; i<func_size; i++ )
76                 if (!strcmpi( name, func_table[i].name ))
77                 {
78                         return i;
79                 }
80
81         return -1;
82 }
83
84
85 int (*func_nget( int func_number, int * numparams, char **name ))(void)
86 {
87         if (func_number < func_size )
88         {
89                 *name = func_table[func_number].name;
90                 *numparams = func_table[func_number].nparams;
91                 return func_table[func_number].cfunction;
92         }
93
94         return NULL;
95 }
96
97 void func_set_param( int n, int value )
98 {
99         func_params[n] = value;
100 }
101
102 int func_get_param( int n )
103 {
104         return func_params[n];
105 }
106
107
108
109