ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/make_nodes.c
Revision: 1683
Committed: Thu Oct 28 22:34:02 2004 UTC (19 years, 8 months ago)
Content type: text/plain
File size: 8917 byte(s)
Log Message:
This commit was manufactured by cvs2svn to create branch 'new_design'.

File Contents

# User Rev Content
1 gezelter 1490 #include <stdio.h>
2     #include <stdlib.h>
3     #include <string.h>
4    
5 tim 1492 #include "io/node_list.h"
6     #include "io/make_nodes.h"
7     #include "utils/simError.h"
8 gezelter 1490
9     /*
10     walks to to the top of a stmt_list. Needed when assigning the
11     statment list to a block of code.
12     */
13    
14     struct node_tag* walk_to_top( struct node_tag* walk_me ){
15    
16     while( walk_me->prev_stmt != NULL ){
17     walk_me = walk_me->prev_stmt;
18     }
19     return walk_me;
20     }
21    
22     /*
23     the next three functions are for creating and initializing the
24     assignment statements.
25     */
26    
27     struct node_tag* assign_i( char* lhs, int rhs ){
28    
29     struct node_tag* the_node;
30     the_node = ( struct node_tag* )malloc( sizeof( node ) );
31    
32     the_node->type = ASSIGNMENT_STMT;
33     the_node->index = 0;
34     the_node->next_stmt = NULL;
35     the_node->prev_stmt = NULL;
36     the_node->stmt_list = NULL;
37    
38     the_node->the_data.asmt.type = INT_ASSN;
39     the_node->the_data.asmt.identifier = lhs;
40     the_node->the_data.asmt.rhs.i_val = rhs;
41    
42     return the_node;
43     }
44    
45     struct node_tag* assign_d( char* lhs, double rhs ){
46    
47     struct node_tag* the_node;
48     the_node = ( struct node_tag* )malloc( sizeof( node ) );
49    
50     the_node->type = ASSIGNMENT_STMT;
51     the_node->index = 0;
52     the_node->next_stmt = NULL;
53     the_node->prev_stmt = NULL;
54     the_node->stmt_list = NULL;
55    
56     the_node->the_data.asmt.type = DOUBLE_ASSN;
57     the_node->the_data.asmt.identifier = lhs;
58     the_node->the_data.asmt.rhs.d_val = rhs;
59    
60     return the_node;
61     }
62    
63     struct node_tag* assign_s( char* lhs, char* rhs ){
64    
65     struct node_tag* the_node;
66     the_node = ( struct node_tag* )malloc( sizeof( node ) );
67    
68     the_node->type = ASSIGNMENT_STMT;
69     the_node->index = 0;
70     the_node->next_stmt = NULL;
71     the_node->prev_stmt = NULL;
72     the_node->stmt_list = NULL;
73    
74     the_node->the_data.asmt.type = STR_ASSN;
75     the_node->the_data.asmt.identifier = lhs;
76     the_node->the_data.asmt.rhs.str_ptr = rhs;
77    
78     return the_node;
79     }
80    
81     /*
82     The next function deals with creating and initializing of the
83     members statements used by the bonds, bends, torsions, rigid bodies,
84     and cutoff groups.
85     */
86    
87     struct node_tag* members( char* list_str ){
88    
89     int nTokens, i;
90     char *foo;
91    
92     struct node_tag* the_node;
93     the_node = ( struct node_tag* )malloc( sizeof( node ) );
94    
95     the_node->type = MEMBERS_STMT;
96     the_node->index = 0;
97     the_node->next_stmt = NULL;
98     the_node->prev_stmt = NULL;
99     the_node->stmt_list = NULL;
100    
101     nTokens = count_tokens(list_str, " ,;\t");
102    
103     if (nTokens < 1) {
104     yyerror("can't find any members in this members statement");
105     }
106    
107     the_node->the_data.mbrs.nMembers = nTokens;
108    
109     the_node->the_data.mbrs.memberList = (int *) calloc(nTokens, sizeof(int));
110    
111     foo = strtok(list_str, " ,;\t");
112     the_node->the_data.mbrs.memberList[0] = atoi( foo );
113    
114     for (i = 1; i < nTokens; i++) {
115     foo = strtok(NULL, " ,;\t");
116     the_node->the_data.mbrs.memberList[i] = atoi( foo );
117     }
118    
119     return the_node;
120     }
121    
122     /*
123     This function does the C & I of the constraint statements
124     */
125    
126     struct node_tag* constraint( char* list_str ){
127    
128     int nTokens;
129     char *foo;
130    
131     struct node_tag* the_node;
132     the_node = ( struct node_tag* )malloc( sizeof( node ) );
133    
134     the_node->type = CONSTRAINT_STMT;
135     the_node->index = 0;
136     the_node->next_stmt = NULL;
137     the_node->prev_stmt = NULL;
138     the_node->stmt_list = NULL;
139    
140     nTokens = count_tokens(list_str, " ,;\t");
141     if (nTokens != 1) {
142     yyerror("wrong number of arguments given in constraint statement");
143     }
144    
145     foo = strtok(list_str, " ,;\t");
146     the_node->the_data.cnstr.constraint_val = atof( foo );
147    
148     return the_node;
149     }
150    
151     /*
152     This function does the C & I for the orientation statements
153     */
154    
155     struct node_tag* orientation( char* list_str ){
156    
157     int nTokens;
158     char *foo;
159    
160     struct node_tag* the_node;
161     the_node = ( struct node_tag* )malloc( sizeof( node ) );
162    
163     the_node->type = ORIENTATION_STMT;
164     the_node->index = 0;
165     the_node->next_stmt = NULL;
166     the_node->prev_stmt = NULL;
167     the_node->stmt_list = NULL;
168    
169     nTokens = count_tokens(list_str, " ,;\t");
170     if (nTokens != 3) {
171     yyerror("wrong number of arguments given in orientation");
172     }
173    
174     foo = strtok(list_str, " ,;\t");
175     the_node->the_data.ort.phi = atof( foo );
176    
177     foo = strtok(NULL, " ,;\t");
178     the_node->the_data.ort.theta = atof( foo );
179    
180     foo = strtok(NULL, " ,;\t");
181     the_node->the_data.ort.psi = atof( foo );
182    
183     return the_node;
184     }
185    
186     /*
187     This function does the C & I for the position statements
188     */
189    
190     struct node_tag* position( char* list_str ){
191    
192     int nTokens;
193     char *foo;
194    
195     struct node_tag* the_node;
196     the_node = ( struct node_tag* )malloc( sizeof( node ) );
197    
198     the_node->type = POSITION_STMT;
199     the_node->index = 0;
200     the_node->next_stmt = NULL;
201     the_node->prev_stmt = NULL;
202     the_node->stmt_list = NULL;
203    
204     nTokens = count_tokens(list_str, " ,;\t");
205     if (nTokens != 3) {
206     yyerror("wrong number of arguments given in position");
207     }
208    
209     foo = strtok(list_str, " ,;\t");
210     the_node->the_data.pos.x = atof( foo );
211    
212     foo = strtok(NULL, " ,;\t");
213     the_node->the_data.pos.y = atof( foo );
214    
215     foo = strtok(NULL, " ,;\t");
216     the_node->the_data.pos.z = atof( foo );
217    
218    
219     return the_node;
220     }
221    
222     /*
223     The following six functions initialize the statement nodes
224     coresponding to the different code block types.
225     */
226    
227     struct node_tag* molecule_blk( struct node_tag* stmt_list ){
228    
229     struct node_tag* the_node;
230     the_node = ( struct node_tag* )malloc( sizeof( node ) );
231    
232     the_node->type = MOLECULE_HEAD;
233     the_node->index = 0;
234     the_node->next_stmt = NULL;
235     the_node->prev_stmt = NULL;
236     the_node->stmt_list = walk_to_top( stmt_list );
237    
238     return the_node;
239     }
240    
241     struct node_tag* rigidbody_blk( int index, struct node_tag* stmt_list ){
242    
243     struct node_tag* the_node;
244     the_node = ( struct node_tag* )malloc( sizeof( node ) );
245    
246     the_node->type = RIGIDBODY_HEAD;
247     the_node->index = index;
248     the_node->next_stmt = NULL;
249     the_node->prev_stmt = NULL;
250     the_node->stmt_list = walk_to_top( stmt_list );
251    
252     return the_node;
253     }
254    
255     struct node_tag* cutoffgroup_blk( int index, struct node_tag* stmt_list ){
256    
257     struct node_tag* the_node;
258     the_node = ( struct node_tag* )malloc( sizeof( node ) );
259    
260     // The guillotine statement:
261     the_node->type = CUTOFFGROUP_HEAD;
262     the_node->index = index;
263     the_node->next_stmt = NULL;
264     the_node->prev_stmt = NULL;
265     the_node->stmt_list = walk_to_top( stmt_list );
266    
267     return the_node;
268     }
269    
270     struct node_tag* atom_blk( int index, struct node_tag* stmt_list ){
271    
272     struct node_tag* the_node;
273     the_node = ( struct node_tag* )malloc( sizeof( node ) );
274    
275     the_node->type = ATOM_HEAD;
276     the_node->index = index;
277     the_node->next_stmt = NULL;
278     the_node->prev_stmt = NULL;
279     the_node->stmt_list = walk_to_top( stmt_list );
280    
281     return the_node;
282     }
283    
284     struct node_tag* bond_blk( int index, struct node_tag* stmt_list ){
285    
286     struct node_tag* the_node;
287     the_node = ( struct node_tag* )malloc( sizeof( node ) );
288    
289     the_node->type = BOND_HEAD;
290     the_node->index = index;
291     the_node->next_stmt = NULL;
292     the_node->prev_stmt = NULL;
293     the_node->stmt_list = walk_to_top( stmt_list );
294    
295     return the_node;
296     }
297    
298     struct node_tag* bend_blk( int index, struct node_tag* stmt_list ){
299    
300     struct node_tag* the_node;
301     the_node = ( struct node_tag* )malloc( sizeof( node ) );
302    
303     the_node->type = BEND_HEAD;
304     the_node->index = index;
305     the_node->next_stmt = NULL;
306     the_node->prev_stmt = NULL;
307     the_node->stmt_list = walk_to_top( stmt_list );
308    
309     return the_node;
310     }
311    
312     struct node_tag* torsion_blk( int index, struct node_tag* stmt_list ){
313    
314     struct node_tag* the_node;
315     the_node = ( struct node_tag* )malloc( sizeof( node ) );
316    
317     the_node->type = TORSION_HEAD;
318     the_node->index = index;
319     the_node->next_stmt = NULL;
320     the_node->prev_stmt = NULL;
321     the_node->stmt_list = walk_to_top( stmt_list );
322    
323     return the_node;
324     }
325    
326     struct node_tag* zconstraint_blk( int index, struct node_tag* stmt_list ){
327    
328     struct node_tag* the_node;
329     the_node = ( struct node_tag* )malloc( sizeof( node ) );
330    
331     the_node->type = ZCONSTRAINT_HEAD;
332     the_node->index = index;
333     the_node->next_stmt = NULL;
334     the_node->prev_stmt = NULL;
335     the_node->stmt_list = walk_to_top( stmt_list );
336    
337     return the_node;
338     }
339    
340     struct node_tag* component_blk( struct node_tag* stmt_list ){
341    
342     struct node_tag* the_node;
343     the_node = ( struct node_tag* )malloc( sizeof( node ) );
344    
345     the_node->type = COMPONENT_HEAD;
346     the_node->index = 0;
347     the_node->next_stmt = NULL;
348     the_node->prev_stmt = NULL;
349     the_node->stmt_list = walk_to_top( stmt_list );
350    
351     return the_node;
352     }
353    
354    
355     int count_tokens(char *line, char *delimiters) {
356     /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
357    
358     char *working_line; /* WORKING COPY OF LINE. */
359     int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */
360     char *strtok_ptr; /* POINTER FOR STRTOK. */
361    
362     strtok_ptr= working_line= strdup(line);
363    
364     ntokens=0;
365     while (strtok(strtok_ptr,delimiters)!=NULL)
366     {
367     ntokens++;
368     strtok_ptr=NULL;
369     }
370    
371     free(working_line);
372     return(ntokens);
373     }