convert line ends
[canaan.git] / prj / cam / src / mschema.y
blobc32e05d70791d2b1001be6c8ec49c75be1a4c24e
1 /*
2 Yacc file for parsing motion schemas.
3 */
5 %union
7 char *strval;
8 int ival;
9 float fval;
10 BOOL bval;
13 /* standard tokens */
14 %token <strval> IDENT
15 %token <strval> STRING
16 %token <ival> INT
17 %token <fval> FLOAT
18 %token <bval> BOOLEAN
19 %token INCLUDE
20 %token DEFINE
21 %token LPAREN
22 %token RPAREN
23 %token EQUAL
24 %token COLON
26 /* motion schema specific tokens */
27 %token SCHEMA
28 %token TAG
29 %token TAG_OPT
30 %token ACTOR
31 %token ACTORS_DECLARE
32 %token ARCHETYPE
33 %token MOTION
34 %token TAGLIST_HEADER
35 %token MOTLIST_HEADER
36 %token STRETCH
37 %token TIMEWARP
38 %token DURATION
39 %token DISTANCE
40 %token MOT_NECK_FIXED
41 %token MOT_NECK_NOT_FIXED
42 %token MOT_BLEND_NONE
43 %token MOT_BLEND_DEFAULT
44 %token MOT_IS_TURN
45 %token MOT_BLEND_LENGTH
46 %token MOT_IN_PLACE
47 %token MOT_IS_LOCO
52 #include <stdio.h>
53 #include <string.h>
54 #include <mprintf.h>
55 #include <inctab.h>
56 #include <cfgdbg.h>
57 #include <config.h>
58 #include <label.h>
59 #include <motdb_.h>
60 #include <motdbase.h>
63 #define FILE_NAME_LEN 100
66 Include file stuff
68 extern void IncParseFile(char *fileName);
69 extern void SchemaParseFile(char *fileName, int (*parseFn)());
71 #define mscherror mprintf
73 #define kDefaultBlendLength 500 // msec
75 #define FreeString(ident) { free(ident); ident = NULL; }
77 /* globals */
78 #define kMaxTagsPerSchema 16
79 #define kMaxMotionsPerSchema 128
81 static sTagDesc g_aSchemaTags[kMaxTagsPerSchema];
82 static sMotDesc g_aSchemaMotions[kMaxMotionsPerSchema];
84 static int g_nSchemaTags=0;
85 static int g_nSchemaMotions=0;
87 static float g_TimeWarp=0;
88 static float g_Stretch=0;
89 static float g_Duration=0;
90 static float g_Distance=0;
92 static BOOL g_TagIsMandatory=TRUE;
93 static float g_TagWeight=0;
95 static int g_TagVal=0;
97 static BOOL g_ArchIsString=FALSE;
98 static int g_ArchInt=0;
99 static Label g_ArchName;
101 static BOOL g_NeckIsFixed=FALSE;
102 static int g_BlendLength=kDefaultBlendLength;
103 static BOOL g_IsTurn=FALSE;
104 static BOOL g_IsLoco=FALSE;
105 static BOOL g_InPlace=FALSE;
112 file: statements;
114 statements: statement | statement statements;
115 statement: include | schema | tag | actors_declare;
117 include: INCLUDE STRING
119 ConfigSpew("yakspew",("include %s\n",$2));
121 IncParseFile($2);
122 FreeString($2);
125 opt_tag_spec: tag_spec | null;
127 tag_spec: TAG_OPT FLOAT
129 g_TagIsMandatory=FALSE;
130 g_TagWeight=$2;
133 tag: TAG IDENT opt_tag_spec
135 sTagInfo info;
137 if(config_is_defined("yakspew"))
139 mprintf("tag %s mand %d",$2,g_TagIsMandatory);
140 if(g_TagIsMandatory)
142 mprintf("\n");
143 } else
145 mprintf(" weight %g\n",g_TagWeight);
148 info.isMandatory=g_TagIsMandatory;
149 info.weight = g_TagWeight;
150 MotDBRegisterTag((Label *)($2),&info);
151 // reset globals
152 g_TagIsMandatory=TRUE;
153 g_TagWeight=0;
155 FreeString($2);
158 actors_declare: ACTORS_DECLARE INT
160 MotDBCreate($2);
163 archetype: arch_string | arch_int;
165 arch_string: ARCHETYPE IDENT
167 g_ArchIsString=TRUE;
168 strncpy(g_ArchName.text,$2,sizeof(g_ArchName));
169 FreeString($2);
172 arch_int: ARCHETYPE INT
174 g_ArchIsString=FALSE;
175 g_ArchInt=$2;
178 schema: SCHEMA IDENT ACTOR INT archetype optparams taglist motlist
180 int i;
181 sMotDesc *pMotDesc;
182 sTagDesc *pTagDesc;
183 sMotSchemaDesc schema;
185 if(config_is_defined("yakspew"))
187 if(g_ArchIsString)
188 mprintf("schema %s\n with actor %d\n with archetype %s\n",$2,$4,g_ArchName.text);
189 else
190 mprintf("schema %s\n with actor %d\n with archetype %d\n",$2,$4,g_ArchInt);
192 // look at params
193 if(g_Duration)
195 mprintf(" duration %g\n",g_Duration);
197 if(g_Distance)
199 mprintf(" distance %g\n",g_Distance);
201 if(g_TimeWarp)
203 mprintf(" timewarp %g\n",g_TimeWarp);
205 if(g_Stretch)
207 mprintf(" stretch %g\n",g_Stretch);
210 // look at tag globals
211 pTagDesc=g_aSchemaTags;
212 for(i=0;i<g_nSchemaTags;i++,pTagDesc++)
214 mprintf(" with tag %s value %d\n",pTagDesc->type.text,pTagDesc->value);
217 // look at motion globals
218 pMotDesc=g_aSchemaMotions;
219 for(i=0;i<g_nSchemaMotions;i++,pMotDesc++)
221 mprintf(" with motion %s,",pMotDesc->name.text);
222 if(pMotDesc->stuff.flags&kMSF_NECK_IS_FIXED)
224 mprintf(" neck_fixed");
226 if(pMotDesc->stuff.blendLength!=kDefaultBlendLength)
228 mprintf(" blend %d",pMotDesc->stuff.blendLength);
230 if(pMotDesc->stuff.flags&kMSF_IS_TURN)
232 mprintf(" is_turn");
234 if(pMotDesc->stuff.flags&kMSF_IS_LOCO)
236 mprintf(" is_loco");
238 if(pMotDesc->stuff.flags&kMSF_WANT_NO_XLAT)
240 mprintf(" in_place");
242 mprintf("\n");
246 schema.nTags=g_nSchemaTags;
247 schema.pTags=g_aSchemaTags;
248 schema.nMots=g_nSchemaMotions;
249 schema.pMots=g_aSchemaMotions;
250 schema.duration=g_Duration;
251 schema.distance=g_Distance;
252 schema.timeWarp=g_TimeWarp;
253 schema.stretch=g_Stretch;
254 schema.actor=$4;
255 strncpy(schema.name.text,$2,15);
257 if(g_ArchIsString)
259 strncpy(schema.archName.text,g_ArchName.text,sizeof(schema.archName));
260 schema.archIsString=TRUE;
261 } else
263 schema.archInt=g_ArchInt;
264 schema.archIsString=FALSE;
266 MotDBAddSchema(&schema);
268 // reset globals
269 g_nSchemaTags=0;
270 g_nSchemaMotions=0;
271 g_TimeWarp=0;
272 g_Stretch=0;
273 g_Duration=0;
274 g_Distance=0;
276 FreeString($2);
279 optparams: paraminsts | null;
281 paraminsts: paraminsts paraminst | paraminst;
283 paraminst: timewarp | duration | stretch | distance;
285 timewarp: TIMEWARP FLOAT
287 g_TimeWarp=$2;
290 duration: DURATION FLOAT
292 g_Duration=$2;
295 stretch: STRETCH FLOAT
297 g_Stretch=$2;
300 distance: DISTANCE FLOAT
302 g_Distance=$2;
306 taglist: TAGLIST_HEADER opttaginsts;
308 opttaginsts: taginsts | null;
310 taginsts: taginsts taginst | taginst;
312 opt_tag_val: tag_val | null;
314 tag_val: INT
316 g_TagVal=$1;
319 taginst: IDENT opt_tag_val
321 int size;
323 if(g_nSchemaTags<kMaxTagsPerSchema)
325 size=sizeof(g_aSchemaTags[0].type);
326 strncpy(g_aSchemaTags[g_nSchemaTags].type.text,$1,size);
327 g_aSchemaTags[g_nSchemaTags].value=g_TagVal;
328 g_nSchemaTags++;
329 } else
331 Warning(("Cannot add tag %s to schema - too many tags\n",$1));
333 // reset globals
334 g_TagVal=0;
335 FreeString($1);
338 motlist: MOTLIST_HEADER optmotions;
340 optmotions: motinsts | null;
342 motinsts: motinsts motinst | motinst;
344 optmotparamlist: motparamlist | null;
346 motparamlist: motparam motparamlist | motparam;
348 motparam: neck_fixed | blend_length | is_turn | MOT_NECK_NOT_FIXED |
349 MOT_BLEND_DEFAULT | blend_none | is_loco | in_place;
351 neck_fixed: MOT_NECK_FIXED
353 g_NeckIsFixed=TRUE;
356 blend_none: MOT_BLEND_NONE
358 g_BlendLength=0;
361 blend_length: MOT_BLEND_LENGTH INT
363 g_BlendLength=$2;
366 in_place: MOT_IN_PLACE
368 g_InPlace=TRUE;
371 is_loco: MOT_IS_LOCO
373 g_IsLoco=TRUE;
376 is_turn: MOT_IS_TURN
378 g_IsTurn=TRUE;
381 motinst: IDENT optmotparamlist
383 int size;
385 if(g_nSchemaMotions<kMaxMotionsPerSchema)
387 size=sizeof(g_aSchemaMotions[0].name);
388 strncpy(g_aSchemaMotions[g_nSchemaMotions].name.text,$1,size);
389 g_aSchemaMotions[g_nSchemaMotions].stuff.flags=NULL;
390 if(g_NeckIsFixed)
391 g_aSchemaMotions[g_nSchemaMotions].stuff.flags|=kMSF_NECK_IS_FIXED;
392 g_aSchemaMotions[g_nSchemaMotions].stuff.blendLength=g_BlendLength;
393 if(g_IsTurn)
394 g_aSchemaMotions[g_nSchemaMotions].stuff.flags|=kMSF_IS_TURN;
395 if(g_IsLoco)
396 g_aSchemaMotions[g_nSchemaMotions].stuff.flags|=kMSF_IS_LOCO;
397 if(g_InPlace)
398 g_aSchemaMotions[g_nSchemaMotions].stuff.flags|=kMSF_WANT_NO_XLAT;
399 g_nSchemaMotions++;
400 } else
402 Warning(("Cannot add motion %s to schema - too many motions\n",$1));
405 // reset motion params
406 g_NeckIsFixed=FALSE;
407 g_BlendLength=kDefaultBlendLength;
408 g_IsTurn=FALSE;
409 g_IsLoco=FALSE;
410 g_InPlace=FALSE;
412 FreeString($1);
415 null: ;
417 motlist:
424 void MotSchemaYaccParse(char *schemaFile)
426 // init globals
428 IncTabsInit();
430 mprintf("parsing file %s!\n",schemaFile);
431 MschParseFile(schemaFile);
433 IncTabsShutdown();