| 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 |
| 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 |
|
|
| 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, and rigid bodies. |
| 84 |
|
*/ |
| 85 |
|
|
| 86 |
< |
struct node_tag* members_2( int a, int b ){ |
| 86 |
> |
struct node_tag* members( char* list_str ){ |
| 87 |
|
|
| 88 |
|
struct node_tag* the_node; |
| 89 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 90 |
|
|
| 91 |
< |
the_node->type = MEMBER_STMT; |
| 91 |
> |
the_node->type = MEMBERS_STMT; |
| 92 |
|
the_node->index = 0; |
| 93 |
|
the_node->next_stmt = NULL; |
| 94 |
|
the_node->prev_stmt = NULL; |
| 95 |
|
the_node->stmt_list = NULL; |
| 96 |
|
|
| 97 |
< |
the_node->the_data.mbr.a = a; |
| 98 |
< |
the_node->the_data.mbr.b = b; |
| 99 |
< |
the_node->the_data.mbr.c = 0; |
| 100 |
< |
the_node->the_data.mbr.d = 0; |
| 97 |
> |
int nTokens, i; |
| 98 |
> |
char *foo; |
| 99 |
|
|
| 100 |
< |
return the_node; |
| 103 |
< |
} |
| 100 |
> |
nTokens = count_tokens(list_str, " ,;\t"); |
| 101 |
|
|
| 102 |
< |
struct node_tag* members_3( int a, int b, int c ){ |
| 102 |
> |
if (nTokens < 1) { |
| 103 |
> |
yyerror("can't find any members in this members statement"); |
| 104 |
> |
} |
| 105 |
|
|
| 106 |
< |
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; |
| 106 |
> |
the_node->the_data.mbrs.nMembers = nTokens; |
| 107 |
|
|
| 108 |
< |
return the_node; |
| 122 |
< |
} |
| 108 |
> |
the_node->the_data.mbrs.memberList = (int *) calloc(nTokens, sizeof(int)); |
| 109 |
|
|
| 110 |
< |
struct node_tag* members_4( int a, int b, int c, int d ){ |
| 110 |
> |
foo = strtok(list_str, " ,;\t"); |
| 111 |
> |
the_node->the_data.mbrs.memberList[0] = atoi( foo ); |
| 112 |
|
|
| 113 |
< |
struct node_tag* the_node; |
| 114 |
< |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 115 |
< |
|
| 116 |
< |
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; |
| 113 |
> |
for (i = 1; i < nTokens; i++) { |
| 114 |
> |
foo = strtok(NULL, " ,;\t"); |
| 115 |
> |
the_node->the_data.mbrs.memberList[i] = atoi( foo ); |
| 116 |
> |
} |
| 117 |
|
|
| 118 |
|
return the_node; |
| 119 |
|
} |
| 122 |
|
This function does the C & I of the constraint statements |
| 123 |
|
*/ |
| 124 |
|
|
| 125 |
< |
struct node_tag* constraint( double constraint_val ){ |
| 125 |
> |
struct node_tag* constraint( char* list_str ){ |
| 126 |
|
|
| 127 |
|
struct node_tag* the_node; |
| 128 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 133 |
|
the_node->prev_stmt = NULL; |
| 134 |
|
the_node->stmt_list = NULL; |
| 135 |
|
|
| 136 |
< |
the_node->the_data.cnstr.constraint_val = constraint_val; |
| 136 |
> |
int nTokens; |
| 137 |
> |
char *foo; |
| 138 |
|
|
| 139 |
+ |
nTokens = count_tokens(list_str, " ,;\t"); |
| 140 |
+ |
if (nTokens != 1) { |
| 141 |
+ |
yyerror("wrong number of arguments given in constraint statement"); |
| 142 |
+ |
} |
| 143 |
+ |
|
| 144 |
+ |
foo = strtok(list_str, " ,;\t"); |
| 145 |
+ |
the_node->the_data.cnstr.constraint_val = atof( foo ); |
| 146 |
+ |
|
| 147 |
|
return the_node; |
| 148 |
|
} |
| 149 |
|
|
| 151 |
|
This function does the C & I for the orientation statements |
| 152 |
|
*/ |
| 153 |
|
|
| 154 |
< |
struct node_tag* orientation( double x, double y, double z ){ |
| 154 |
> |
struct node_tag* orientation( char* list_str ){ |
| 155 |
|
|
| 156 |
|
struct node_tag* the_node; |
| 157 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 161 |
|
the_node->next_stmt = NULL; |
| 162 |
|
the_node->prev_stmt = NULL; |
| 163 |
|
the_node->stmt_list = NULL; |
| 164 |
< |
|
| 165 |
< |
the_node->the_data.pos.x = x; |
| 166 |
< |
the_node->the_data.pos.y = y; |
| 167 |
< |
the_node->the_data.pos.z = z; |
| 168 |
< |
|
| 164 |
> |
|
| 165 |
> |
int nTokens; |
| 166 |
> |
char *foo; |
| 167 |
> |
|
| 168 |
> |
nTokens = count_tokens(list_str, " ,;\t"); |
| 169 |
> |
if (nTokens != 3) { |
| 170 |
> |
yyerror("wrong number of arguments given in orientation"); |
| 171 |
> |
} |
| 172 |
> |
|
| 173 |
> |
foo = strtok(list_str, " ,;\t"); |
| 174 |
> |
the_node->the_data.ort.phi = atof( foo ); |
| 175 |
> |
|
| 176 |
> |
foo = strtok(NULL, " ,;\t"); |
| 177 |
> |
the_node->the_data.ort.theta = atof( foo ); |
| 178 |
> |
|
| 179 |
> |
foo = strtok(NULL, " ,;\t"); |
| 180 |
> |
the_node->the_data.ort.psi = atof( foo ); |
| 181 |
> |
|
| 182 |
|
return the_node; |
| 183 |
|
} |
| 184 |
|
|
| 186 |
|
This function does the C & I for the position statements |
| 187 |
|
*/ |
| 188 |
|
|
| 189 |
< |
struct node_tag* position( double x, double y, double z ){ |
| 189 |
> |
struct node_tag* position( char* list_str ){ |
| 190 |
|
|
| 191 |
|
struct node_tag* the_node; |
| 192 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 196 |
|
the_node->next_stmt = NULL; |
| 197 |
|
the_node->prev_stmt = NULL; |
| 198 |
|
the_node->stmt_list = NULL; |
| 199 |
< |
|
| 200 |
< |
the_node->the_data.pos.x = x; |
| 201 |
< |
the_node->the_data.pos.y = y; |
| 202 |
< |
the_node->the_data.pos.z = z; |
| 199 |
> |
|
| 200 |
> |
int nTokens; |
| 201 |
> |
char *foo; |
| 202 |
> |
|
| 203 |
> |
nTokens = count_tokens(list_str, " ,;\t"); |
| 204 |
> |
if (nTokens != 3) { |
| 205 |
> |
yyerror("wrong number of arguments given in position"); |
| 206 |
> |
} |
| 207 |
> |
|
| 208 |
> |
foo = strtok(list_str, " ,;\t"); |
| 209 |
> |
the_node->the_data.pos.x = atof( foo ); |
| 210 |
> |
|
| 211 |
> |
foo = strtok(NULL, " ,;\t"); |
| 212 |
> |
the_node->the_data.pos.y = atof( foo ); |
| 213 |
> |
|
| 214 |
> |
foo = strtok(NULL, " ,;\t"); |
| 215 |
> |
the_node->the_data.pos.z = atof( foo ); |
| 216 |
> |
|
| 217 |
|
|
| 218 |
|
return the_node; |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
/* |
| 222 |
< |
Does the C & I for the start_index statement |
| 222 |
> |
The following six functions initialize the statement nodes |
| 223 |
> |
coresponding to the different code block types. |
| 224 |
|
*/ |
| 225 |
|
|
| 226 |
< |
struct node_tag* start_index( struct integer_list_tag* the_list ){ |
| 226 |
> |
struct node_tag* molecule_blk( struct node_tag* stmt_list ){ |
| 227 |
|
|
| 228 |
|
struct node_tag* the_node; |
| 229 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 230 |
|
|
| 231 |
< |
the_node->type = START_INDEX_STMT; |
| 231 |
> |
the_node->type = MOLECULE_HEAD; |
| 232 |
|
the_node->index = 0; |
| 233 |
|
the_node->next_stmt = NULL; |
| 234 |
|
the_node->prev_stmt = NULL; |
| 235 |
< |
the_node->stmt_list = NULL; |
| 236 |
< |
|
| 222 |
< |
the_node->the_data.il_head = the_list; |
| 223 |
< |
|
| 235 |
> |
the_node->stmt_list = walk_to_top( stmt_list ); |
| 236 |
> |
|
| 237 |
|
return the_node; |
| 238 |
< |
} |
| 238 |
> |
} |
| 239 |
|
|
| 240 |
< |
/* |
| 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 ){ |
| 240 |
> |
struct node_tag* rigidbody_blk( int index, struct node_tag* stmt_list ){ |
| 241 |
|
|
| 242 |
|
struct node_tag* the_node; |
| 243 |
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 244 |
|
|
| 245 |
< |
the_node->type = MOLECULE_HEAD; |
| 245 |
> |
the_node->type = RIGIDBODY_HEAD; |
| 246 |
|
the_node->index = 0; |
| 247 |
|
the_node->next_stmt = NULL; |
| 248 |
|
the_node->prev_stmt = NULL; |
| 306 |
|
|
| 307 |
|
return the_node; |
| 308 |
|
} |
| 309 |
+ |
|
| 310 |
+ |
struct node_tag* zconstraint_blk( int index, struct node_tag* stmt_list ){ |
| 311 |
+ |
|
| 312 |
+ |
struct node_tag* the_node; |
| 313 |
+ |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
| 314 |
+ |
|
| 315 |
+ |
the_node->type = ZCONSTRAINT_HEAD; |
| 316 |
+ |
the_node->index = index; |
| 317 |
+ |
the_node->next_stmt = NULL; |
| 318 |
+ |
the_node->prev_stmt = NULL; |
| 319 |
+ |
the_node->stmt_list = walk_to_top( stmt_list ); |
| 320 |
+ |
|
| 321 |
+ |
return the_node; |
| 322 |
+ |
} |
| 323 |
|
|
| 324 |
|
struct node_tag* component_blk( struct node_tag* stmt_list ){ |
| 325 |
|
|
| 334 |
|
|
| 335 |
|
return the_node; |
| 336 |
|
} |
| 315 |
– |
|
| 316 |
– |
/* |
| 317 |
– |
the next two functions handle the integer list nodes. |
| 318 |
– |
*/ |
| 319 |
– |
|
| 320 |
– |
struct integer_list_tag* il_node( int the_int ){ |
| 337 |
|
|
| 322 |
– |
struct integer_list_tag* the_il_node; |
| 323 |
– |
the_il_node = ( struct integer_list_tag* )malloc( sizeof( integer_list ) ); |
| 338 |
|
|
| 339 |
< |
the_il_node->prev = NULL; |
| 340 |
< |
the_il_node->next = NULL; |
| 327 |
< |
|
| 328 |
< |
the_il_node->the_int = the_int; |
| 339 |
> |
int count_tokens(char *line, char *delimiters) { |
| 340 |
> |
/* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */ |
| 341 |
|
|
| 342 |
< |
return the_il_node; |
| 342 |
> |
char *working_line; /* WORKING COPY OF LINE. */ |
| 343 |
> |
int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */ |
| 344 |
> |
char *strtok_ptr; /* POINTER FOR STRTOK. */ |
| 345 |
> |
|
| 346 |
> |
strtok_ptr= working_line= strdup(line); |
| 347 |
> |
|
| 348 |
> |
ntokens=0; |
| 349 |
> |
while (strtok(strtok_ptr,delimiters)!=NULL) |
| 350 |
> |
{ |
| 351 |
> |
ntokens++; |
| 352 |
> |
strtok_ptr=NULL; |
| 353 |
> |
} |
| 354 |
> |
|
| 355 |
> |
free(working_line); |
| 356 |
> |
return(ntokens); |
| 357 |
|
} |
| 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 |
– |
} |