1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "interface.h" |
6 |
#include "../headers/BASS_interface.h" |
7 |
|
8 |
void interface_error( event* the_event ); |
9 |
|
10 |
void init_component( int comp_index ){ |
11 |
event* the_event; |
12 |
|
13 |
the_event = (event* )malloc( sizeof( event ) ); |
14 |
|
15 |
the_event->event_type = COMPONENT; |
16 |
the_event->err_msg = NULL; |
17 |
the_event->evt.blk_index = comp_index; |
18 |
|
19 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
20 |
|
21 |
free( the_event ); |
22 |
} |
23 |
|
24 |
void init_molecule( int mol_index ){ |
25 |
event* the_event; |
26 |
|
27 |
the_event = (event* )malloc( sizeof( event ) ); |
28 |
|
29 |
the_event->event_type = MOLECULE; |
30 |
the_event->err_msg = NULL; |
31 |
the_event->evt.blk_index = mol_index; |
32 |
|
33 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
34 |
|
35 |
free( the_event ); |
36 |
} |
37 |
|
38 |
void init_atom( int atom_index ){ |
39 |
event* the_event; |
40 |
|
41 |
the_event = (event* )malloc( sizeof( event ) ); |
42 |
|
43 |
the_event->event_type = ATOM; |
44 |
the_event->err_msg = NULL; |
45 |
the_event->evt.blk_index = atom_index; |
46 |
|
47 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
48 |
|
49 |
free( the_event ); |
50 |
} |
51 |
|
52 |
void init_bond( int bond_index ){ |
53 |
event* the_event; |
54 |
|
55 |
the_event = (event* )malloc( sizeof( event ) ); |
56 |
|
57 |
the_event->event_type = BOND; |
58 |
the_event->err_msg = NULL; |
59 |
the_event->evt.blk_index = bond_index; |
60 |
|
61 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
62 |
|
63 |
free( the_event ); |
64 |
} |
65 |
|
66 |
void init_bend( int bend_index ){ |
67 |
event* the_event; |
68 |
|
69 |
the_event = (event* )malloc( sizeof( event ) ); |
70 |
|
71 |
the_event->event_type = BEND; |
72 |
the_event->err_msg = NULL; |
73 |
the_event->evt.blk_index = bend_index; |
74 |
|
75 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
76 |
|
77 |
free( the_event ); |
78 |
} |
79 |
|
80 |
void init_torsion( int torsion_index ){ |
81 |
event* the_event; |
82 |
|
83 |
the_event = (event* )malloc( sizeof( event ) ); |
84 |
|
85 |
the_event->event_type = TORSION; |
86 |
the_event->err_msg = NULL; |
87 |
the_event->evt.blk_index = torsion_index; |
88 |
|
89 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
90 |
|
91 |
free( the_event ); |
92 |
} |
93 |
|
94 |
|
95 |
/* |
96 |
* the next few deal with the statement initializations |
97 |
*/ |
98 |
|
99 |
void init_members( struct node_tag* the_node, |
100 |
struct namespc the_namespc ){ |
101 |
event* the_event; |
102 |
|
103 |
the_event = (event* )malloc( sizeof( event ) ); |
104 |
|
105 |
the_event->event_type = MEMBER; |
106 |
the_event->err_msg = NULL; |
107 |
the_event->evt.mbr.a = the_node->the_data.mbr.a; |
108 |
the_event->evt.mbr.b = the_node->the_data.mbr.b; |
109 |
the_event->evt.mbr.c = the_node->the_data.mbr.c; |
110 |
the_event->evt.mbr.d = the_node->the_data.mbr.d; |
111 |
|
112 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
113 |
|
114 |
free( the_event ); |
115 |
} |
116 |
|
117 |
void init_constraint( struct node_tag* the_node, |
118 |
struct namespc the_namespc ){ |
119 |
event* the_event; |
120 |
|
121 |
the_event = (event* )malloc( sizeof( event ) ); |
122 |
|
123 |
the_event->event_type = CONSTRAINT; |
124 |
the_event->err_msg = NULL; |
125 |
the_event->evt.cnstr = the_node->the_data.cnstr.constraint_val; |
126 |
|
127 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
128 |
|
129 |
free( the_event ); |
130 |
} |
131 |
|
132 |
void init_assignment( struct node_tag* the_node, |
133 |
struct namespc the_namespc ){ |
134 |
event* the_event; |
135 |
|
136 |
the_event = (event* )malloc( sizeof( event ) ); |
137 |
|
138 |
the_event->event_type = ASSIGNMENT; |
139 |
the_event->err_msg = NULL; |
140 |
|
141 |
strcpy( the_event->evt.asmt.lhs, the_node->the_data.asmt.identifier ); |
142 |
switch( the_node->the_data.asmt.type ){ |
143 |
|
144 |
case STR_ASSN: |
145 |
the_event->evt.asmt.asmt_type = STRING; |
146 |
strcpy( the_event->evt.asmt.rhs.sval, |
147 |
the_node->the_data.asmt.rhs.str_ptr ); |
148 |
break; |
149 |
|
150 |
case INT_ASSN: |
151 |
the_event->evt.asmt.asmt_type = INT; |
152 |
the_event->evt.asmt.rhs.ival = the_node->the_data.asmt.rhs.i_val; |
153 |
break; |
154 |
|
155 |
case DOUBLE_ASSN: |
156 |
the_event->evt.asmt.asmt_type = DOUBLE; |
157 |
the_event->evt.asmt.rhs.dval = the_node->the_data.asmt.rhs.d_val; |
158 |
break; |
159 |
} |
160 |
|
161 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
162 |
|
163 |
free( the_event ); |
164 |
} |
165 |
|
166 |
void init_position( struct node_tag* the_node, |
167 |
struct namespc the_namespc ){ |
168 |
event* the_event; |
169 |
|
170 |
the_event = (event* )malloc( sizeof( event ) ); |
171 |
|
172 |
the_event->event_type = POSITION; |
173 |
the_event->err_msg = NULL; |
174 |
the_event->evt.pos.x = the_node->the_data.pos.x; |
175 |
the_event->evt.pos.y = the_node->the_data.pos.y; |
176 |
the_event->evt.pos.z = the_node->the_data.pos.z; |
177 |
|
178 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
179 |
|
180 |
free( the_event ); |
181 |
} |
182 |
|
183 |
void init_orientation( struct node_tag* the_node, |
184 |
struct namespc the_namespc ){ |
185 |
event* the_event; |
186 |
|
187 |
the_event = (event* )malloc( sizeof( event ) ); |
188 |
|
189 |
the_event->event_type = ORIENTATION; |
190 |
the_event->err_msg = NULL; |
191 |
the_event->evt.ornt.x = the_node->the_data.ort.x; |
192 |
the_event->evt.ornt.y = the_node->the_data.ort.y; |
193 |
the_event->evt.ornt.z = the_node->the_data.ort.z; |
194 |
|
195 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
196 |
|
197 |
free( the_event ); |
198 |
} |
199 |
|
200 |
void init_start_index( struct node_tag* the_node, |
201 |
struct namespc the_namespc ){ |
202 |
event* the_event; |
203 |
int* si_array; |
204 |
int n_elements = 0; |
205 |
int index = 0; |
206 |
|
207 |
struct integer_list_tag* head; |
208 |
struct integer_list_tag* current; |
209 |
|
210 |
the_event = (event* )malloc( sizeof( event ) ); |
211 |
|
212 |
the_event->event_type = ORIENTATION; |
213 |
the_event->err_msg = NULL; |
214 |
|
215 |
head = the_node->the_data.il_head; |
216 |
n_elements++; |
217 |
|
218 |
current = head->next; |
219 |
while( current != NULL ){ |
220 |
n_elements++; |
221 |
current = current->next; |
222 |
} |
223 |
|
224 |
the_event->evt.si.n_elements = n_elements; |
225 |
si_array = ( int* ) calloc( n_elements, sizeof( int ) ); |
226 |
|
227 |
si_array[index] = head->the_int; |
228 |
|
229 |
current = head->next; |
230 |
while( current != NULL ){ |
231 |
index++; |
232 |
si_array[index] = current->the_int; |
233 |
current = current->next; |
234 |
} |
235 |
the_event->evt.si.array = si_array; |
236 |
|
237 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
238 |
|
239 |
free( the_event ); |
240 |
} |
241 |
|
242 |
void end_of_block( void ){ |
243 |
event* the_event; |
244 |
|
245 |
the_event = (event* )malloc( sizeof( event ) ); |
246 |
|
247 |
the_event->event_type = BLOCK_END; |
248 |
the_event->err_msg = NULL; |
249 |
|
250 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
251 |
|
252 |
free( the_event ); |
253 |
} |
254 |
|
255 |
void interface_error( event* the_event ){ |
256 |
|
257 |
fprintf( stderr, |
258 |
"**Interface event error**\n" |
259 |
"%s\n", |
260 |
the_event->err_msg ); |
261 |
exit(1); |
262 |
} |