ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/BASS_parse/interface.c
Revision: 11
Committed: Tue Jul 9 18:40:59 2002 UTC (22 years ago) by mmeineke
Content type: text/plain
File size: 6166 byte(s)
Log Message:
This commit was generated by cvs2svn to compensate for changes in r10, which
included commits to RCS files with non-trunk default branches.

File Contents

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