ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/make_nodes.c
(Generate patch)

Comparing:
branches/mmeineke/OOPSE/libBASS/make_nodes.c (file contents), Revision 377 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
trunk/OOPSE/libBASS/make_nodes.c (file contents), Revision 1153 by gezelter, Tue May 11 04:21:52 2004 UTC

# Line 2 | Line 2
2   #include <stdlib.h>
3   #include <string.h>
4  
5 < #include <node_list.h>
6 < #include <make_nodes.h>
7 < #include <simError.h>
5 > #include "node_list.h"
6 > #include "make_nodes.h"
7 > #include "simError.h"
8  
9   /*
10    walks to to the top of a stmt_list. Needed when assigning the
# Line 20 | Line 20 | struct node_tag* walk_to_top( struct node_tag* walk_me
20   }
21  
22   /*
23 <  the next three functions are for creating and initialing the
23 >  the next three functions are for creating and initializing the
24    assignment statements.
25   */
26  
# Line 79 | Line 79 | struct node_tag* assign_s( char* lhs, char* rhs ){
79   }
80  
81   /*
82 <  The next three functions deal with creating and initializing of the
83 <  members statements used by the bonds, bends, and torsions.
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_2( int a, int b ){
87 > struct node_tag* members( char* list_str ){
88  
89    struct node_tag* the_node;
90    the_node = ( struct node_tag* )malloc( sizeof( node ) );
91    
92 <  the_node->type = MEMBER_STMT;
92 >  the_node->type = MEMBERS_STMT;
93    the_node->index = 0;
94    the_node->next_stmt = NULL;
95    the_node->prev_stmt = NULL;
96    the_node->stmt_list = NULL;
97    
98 <  the_node->the_data.mbr.a = a;
99 <  the_node->the_data.mbr.b = b;
99 <  the_node->the_data.mbr.c = 0;
100 <  the_node->the_data.mbr.d = 0;
98 >  int nTokens, i;
99 >  char *foo;
100  
101 <  return the_node;
103 < }
101 >  nTokens = count_tokens(list_str, " ,;\t");
102  
103 < struct node_tag* members_3( int a, int b, int c ){
103 >  if (nTokens < 1) {
104 >    yyerror("can't find any members in this members statement");
105 >  }
106  
107 <  struct node_tag* the_node;
108 <  the_node = ( struct node_tag* )malloc( sizeof( node ) );
109 <  
110 <  the_node->type = MEMBER_STMT;
111 <  the_node->index = 0;
112 <  the_node->next_stmt = NULL;
113 <  the_node->prev_stmt = NULL;
114 <  the_node->stmt_list = NULL;
115 <  
116 <  the_node->the_data.mbr.a = a;
117 <  the_node->the_data.mbr.b = b;
118 <  the_node->the_data.mbr.c = c;
119 <  the_node->the_data.mbr.d = 0;
107 >  the_node->the_data.mbrs.nMembers = nTokens;
108  
109 <  return the_node;
122 < }
109 >  the_node->the_data.mbrs.memberList = (int *) calloc(nTokens, sizeof(int));
110  
111 < struct node_tag* members_4( int a, int b, int c, int d ){
111 >  foo = strtok(list_str, " ,;\t");
112 >  the_node->the_data.mbrs.memberList[0] = atoi( foo );
113  
114 <  struct node_tag* the_node;
115 <  the_node = ( struct node_tag* )malloc( sizeof( node ) );
116 <  
117 <  the_node->type = MEMBER_STMT;
130 <  the_node->index = 0;
131 <  the_node->next_stmt = NULL;
132 <  the_node->prev_stmt = NULL;
133 <  the_node->stmt_list = NULL;
134 <  
135 <  the_node->the_data.mbr.a = a;
136 <  the_node->the_data.mbr.b = b;
137 <  the_node->the_data.mbr.c = c;
138 <  the_node->the_data.mbr.d = d;
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   }
# Line 144 | Line 123 | struct node_tag* constraint( double constraint_val ){
123    This function does the C & I of the constraint statements
124   */
125  
126 < struct node_tag* constraint( double constraint_val ){
126 > struct node_tag* constraint( char* list_str ){
127  
128    struct node_tag* the_node;
129    the_node = ( struct node_tag* )malloc( sizeof( node ) );
# Line 155 | Line 134 | struct node_tag* constraint( double constraint_val ){
134    the_node->prev_stmt = NULL;
135    the_node->stmt_list = NULL;
136    
137 <  the_node->the_data.cnstr.constraint_val = constraint_val;
137 >  int nTokens;
138 >  char *foo;
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  
# Line 164 | Line 152 | struct node_tag* orientation( double x, double y, doub
152    This function does the C & I for the orientation statements
153   */
154  
155 < struct node_tag* orientation( double x, double y, double z ){
155 > struct node_tag* orientation( char* list_str ){
156  
157    struct node_tag* the_node;
158    the_node = ( struct node_tag* )malloc( sizeof( node ) );
# Line 174 | Line 162 | struct node_tag* orientation( double x, double y, doub
162    the_node->next_stmt = NULL;
163    the_node->prev_stmt = NULL;
164    the_node->stmt_list = NULL;
165 <  
166 <  the_node->the_data.pos.x = x;
167 <  the_node->the_data.pos.y = y;
168 <  the_node->the_data.pos.z = z;
169 <  
165 >
166 >  int nTokens;
167 >  char *foo;
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  
# Line 186 | Line 187 | struct node_tag* position( double x, double y, double
187    This function does the C & I for the position statements
188   */
189  
190 < struct node_tag* position( double x, double y, double z ){
190 > struct node_tag* position( char* list_str ){
191  
192    struct node_tag* the_node;
193    the_node = ( struct node_tag* )malloc( sizeof( node ) );
# Line 196 | Line 197 | struct node_tag* position( double x, double y, double
197    the_node->next_stmt = NULL;
198    the_node->prev_stmt = NULL;
199    the_node->stmt_list = NULL;
200 <  
201 <  the_node->the_data.pos.x = x;
202 <  the_node->the_data.pos.y = y;
203 <  the_node->the_data.pos.z = z;
200 >
201 >  int nTokens;
202 >  char *foo;
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 <   Does the C & I for the start_index statement
223 >  The following six functions initialize the statement nodes
224 >  coresponding to the different code block types.
225   */
226  
227 < struct node_tag* start_index( struct integer_list_tag* the_list ){
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 = START_INDEX_STMT;
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 = 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 <  the_node->the_data.il_head = the_list;
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 = 0;
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 < }  
253 > }
254  
255 < /*
228 <  The following six functions initialize the statement nodes
229 <  coresponding to the different code block types.
230 < */
231 <
232 < struct node_tag* molecule_blk( struct node_tag* stmt_list ){
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_node->type = MOLECULE_HEAD;
260 >  // The guillotine statement:
261 >  the_node->type = CUTOFFGROUP_HEAD;
262    the_node->index = 0;
263    the_node->next_stmt = NULL;
264    the_node->prev_stmt = NULL;
# Line 298 | Line 322 | struct node_tag* torsion_blk( int index, struct node_t
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    
# Line 312 | Line 350 | struct node_tag* component_blk( struct node_tag* stmt_
350    
351    return the_node;
352   }
315
316 /*
317   the next two functions handle the integer list nodes.
318 */
319
320 struct integer_list_tag* il_node( int the_int ){
353  
322  struct integer_list_tag* the_il_node;
323  the_il_node = ( struct integer_list_tag* )malloc( sizeof( integer_list ) );
354  
355 <  the_il_node->prev = NULL;
356 <  the_il_node->next = NULL;
327 <  
328 <  the_il_node->the_int = the_int;
355 > int count_tokens(char *line, char *delimiters) {
356 > /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
357  
358 <  return the_il_node;
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   }
332
333 struct integer_list_tag* il_top( struct integer_list_tag* the_list ){
334
335  while( the_list->prev != NULL ){
336    the_list = the_list->prev;
337  }
338  return the_list;
339 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines