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