Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * |
||
22 | * . |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | |||
27 | #include <stdlib.h> |
||
28 | #include <string.h> |
||
29 | |||
30 | #include "func.h" |
||
31 | #include "strutil.h" |
||
32 | |||
33 | namespace dcx { |
||
34 | |||
35 | #define MAX_PARAMS 10 |
||
36 | |||
37 | static const FUNCTION * func_table = NULL; |
||
38 | static int func_size = 0; |
||
39 | static int initialized = 0; |
||
40 | static int func_params[MAX_PARAMS]; |
||
41 | |||
42 | void func_init( const FUNCTION * funtable, int size ) |
||
43 | { |
||
44 | if (!initialized) |
||
45 | { |
||
46 | initialized = 1; |
||
47 | func_table = funtable; |
||
48 | func_size = size; |
||
49 | atexit( func_close ); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | |||
54 | void func_close() |
||
55 | { |
||
56 | if (initialized) |
||
57 | { |
||
58 | initialized = 0; |
||
59 | func_table = NULL; |
||
60 | func_size = 0; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | int (*func_get( char * name, int * numparams ))(void) |
||
65 | { |
||
66 | for (int i=0; i<func_size; i++ ) |
||
67 | if (!d_stricmp( 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 | for (int i=0; i<func_size; i++ ) |
||
79 | if (!d_stricmp( name, func_table[i].name )) |
||
80 | { |
||
81 | return i; |
||
82 | } |
||
83 | |||
84 | return -1; |
||
85 | } |
||
86 | |||
87 | |||
88 | int (*func_nget( int func_number, int * numparams, const char **name ))(void) |
||
89 | { |
||
90 | if (func_number < func_size ) |
||
91 | { |
||
92 | *name = func_table[func_number].name; |
||
93 | *numparams = func_table[func_number].nparams; |
||
94 | return func_table[func_number].cfunction; |
||
95 | } |
||
96 | |||
97 | return NULL; |
||
98 | } |
||
99 | |||
100 | int func_get_param( int n ) |
||
101 | { |
||
102 | return func_params[n]; |
||
103 | } |
||
104 | |||
105 | |||
106 | } |