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