home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / src / cost_parse.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-11  |  80.5 KB  |  2,933 lines

  1. /* A Bison parser, made by GNU Bison 2.3.  */
  2.  
  3. /* Skeleton implementation for Bison's Yacc-like parsers in C
  4.  
  5.    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  6.    Free Software Foundation, Inc.
  7.  
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21.    Boston, MA 02110-1301, USA.  */
  22.  
  23. /* As a special exception, you may create a larger work that contains
  24.    part or all of the Bison parser skeleton and distribute that work
  25.    under terms of your choice, so long as that work isn't itself a
  26.    parser generator using the skeleton or a modified version thereof
  27.    as a parser skeleton.  Alternatively, if you modify or redistribute
  28.    the parser skeleton itself, you may (at your option) remove this
  29.    special exception, which will cause the skeleton and the resulting
  30.    Bison output files to be licensed under the GNU General Public
  31.    License without this special exception.
  32.  
  33.    This special exception was added by the Free Software Foundation in
  34.    version 2.2 of Bison.  */
  35.  
  36. /* C LALR(1) parser skeleton written by Richard Stallman, by
  37.    simplifying the original so-called "semantic" parser.  */
  38.  
  39. /* All symbols defined below should begin with yy or YY, to avoid
  40.    infringing on user name space.  This should be done even for local
  41.    variables, as they might otherwise be expanded by user macros.
  42.    There are some unavoidable exceptions within include files to
  43.    define necessary library symbols; they are noted "INFRINGES ON
  44.    USER NAME SPACE" below.  */
  45.  
  46. /* Identify Bison output.  */
  47. #define YYBISON 1
  48.  
  49. /* Bison version.  */
  50. #define YYBISON_VERSION "2.3"
  51.  
  52. /* Skeleton name.  */
  53. #define YYSKELETON_NAME "yacc.c"
  54.  
  55. /* Pure parsers.  */
  56. #define YYPURE 0
  57.  
  58. /* Using locations.  */
  59. #define YYLSP_NEEDED 1
  60.  
  61.  
  62.  
  63. /* Tokens.  */
  64. #ifndef YYTOKENTYPE
  65. # define YYTOKENTYPE
  66.    /* Put the tokens into the symbol table, so that GDB and other debuggers
  67.       know about them.  */
  68.    enum yytokentype {
  69.      PALETTE = 258,
  70.      FLAGS = 259,
  71.      LOOP = 260,
  72.      FLIP = 261,
  73.      PICTURE = 262,
  74.      LIMB = 263,
  75.      ANIM = 264,
  76.      INTEGER = 265,
  77.      STRING = 266,
  78.      SYM = 267,
  79.      PATH = 268,
  80.      GLOB = 269,
  81.      POSITION = 270,
  82.      MOVE = 271,
  83.      START = 272,
  84.      STOP = 273,
  85.      HIDE = 274,
  86.      SKIP = 275,
  87.      SOUND = 276,
  88.      ERROR = 277
  89.    };
  90. #endif
  91. /* Tokens.  */
  92. #define PALETTE 258
  93. #define FLAGS 259
  94. #define LOOP 260
  95. #define FLIP 261
  96. #define PICTURE 262
  97. #define LIMB 263
  98. #define ANIM 264
  99. #define INTEGER 265
  100. #define STRING 266
  101. #define SYM 267
  102. #define PATH 268
  103. #define GLOB 269
  104. #define POSITION 270
  105. #define MOVE 271
  106. #define START 272
  107. #define STOP 273
  108. #define HIDE 274
  109. #define SKIP 275
  110. #define SOUND 276
  111. #define ERROR 277
  112.  
  113.  
  114.  
  115.  
  116. /* Copy the first part of user declarations.  */
  117. #line 26 "/usr/tmp/cost_parse.y"
  118.  
  119.  
  120. #include "config.h"
  121.  
  122. #include <stdlib.h>
  123. #include <stdio.h>
  124. #include <string.h>
  125. #include <inttypes.h>
  126. #include <errno.h>
  127. #ifndef IS_MINGW
  128. #include <glob.h>
  129. #endif
  130.  
  131.  
  132. #include <sys/types.h>
  133. #include <sys/stat.h>
  134. #include <fcntl.h>
  135. #include "scc_fd.h"
  136. #include "scc_util.h"
  137. #include "scc_param.h"
  138. #include "scc_img.h"
  139. #include "cost_parse.tab.h"
  140. #include "scc_lex.h"
  141.  
  142. #include "cost_help.h"
  143.  
  144. #define YYERROR_VERBOSE 1
  145.  
  146.   int yylex(void);
  147.   int yyerror (const char *s);
  148.  
  149. #define COST_ABORT(at,msg...)  { \
  150.   printf("Line %d, column %d: ",at.first_line,at.first_column); \
  151.   printf(msg); \
  152.   YYABORT; \
  153. }
  154.  
  155.   typedef struct cost_pic cost_pic_t;
  156.   struct cost_pic {
  157.     cost_pic_t* next;
  158.     // name from the sym
  159.     char* name;
  160.     // number of references from limbs
  161.     unsigned ref;
  162.     // offset where it will be written
  163.     unsigned offset;
  164.     // global index for akos
  165.     unsigned idx;
  166.     // path/glob
  167.     char* path;
  168.     int is_glob;
  169.     // params, they will be copied for globs
  170.     int16_t rel_x,rel_y;
  171.     int16_t move_x,move_y;
  172.  
  173.     uint16_t width,height;
  174.     uint8_t* data;
  175.     uint32_t data_size;
  176.   };
  177.  
  178.   static cost_pic_t* cur_pic = NULL;
  179.   static cost_pic_t* pic_list = NULL;
  180.  
  181. #define COST_MAX_LIMBS 16
  182. #define LIMB_MAX_PICTURES 0x70
  183. #define COST_MAX_DIR 4
  184.  
  185.   typedef struct cost_limb {
  186.     char* name;
  187.     unsigned num_pic;
  188.     cost_pic_t* pic[LIMB_MAX_PICTURES];
  189.   } cost_limb_t;
  190.   
  191.  
  192.   static cost_limb_t limbs[COST_MAX_LIMBS];
  193.   static cost_limb_t* cur_limb = NULL;
  194.  
  195. #define COST_MAX_ANIMS 0x3F
  196. #define COST_MAX_LIMB_CMDS 0x7F
  197.  
  198.   typedef struct cost_limb_anim {
  199.     unsigned len;
  200.     unsigned flags;
  201.     uint8_t cmd[COST_MAX_LIMB_CMDS];
  202.   } cost_limb_anim_t;
  203.  
  204.   typedef struct cost_anim_dir {
  205.     unsigned limb_mask;
  206.     cost_limb_anim_t limb[COST_MAX_LIMBS];
  207.   } cost_anim_dir_t;
  208.  
  209.   typedef struct cost_anim {
  210.     char* name;
  211.     cost_anim_dir_t dir[COST_MAX_DIR];
  212.   } cost_anim_t;
  213.   
  214.   static cost_anim_t anims[COST_MAX_ANIMS];
  215.   static cost_anim_t* cur_anim = NULL;
  216.   static cost_anim_dir_t* cur_dir = NULL;
  217.  
  218. #define COST_MAX_PALETTE_SIZE 32
  219.   static unsigned pal_size = 0;
  220.   static uint8_t pal[COST_MAX_PALETTE_SIZE];
  221.  
  222.   // Default to no flip
  223.   static unsigned cost_flags = 0x80;
  224.  
  225.   static char* img_path = NULL;
  226.   static char* cost_output = NULL;
  227.   static scc_fd_t* out_fd = NULL;
  228.  
  229.   // Output a AKOS instead of COST
  230.   static int akos = 0;
  231.  
  232.   // Ouput a header
  233.   static char* header_name = NULL;
  234.   static char* symbol_prefix = NULL;
  235.  
  236.   static int cost_pic_load(cost_pic_t* pic,char* file);
  237.  
  238.   static cost_pic_t* find_pic(char* name) {
  239.     cost_pic_t* p;
  240.     for(p = pic_list ; p ; p = p->next)
  241.       if(!strcmp(name,p->name)) break;
  242.     return p;
  243.   }
  244.  
  245.   struct dir_map {
  246.     char* name;
  247.     unsigned id;
  248.   } dir_map[] = {
  249.     { "W",   0 },
  250.     { "E",   1 },
  251.     { "S",   2 },
  252.     { "N",   3 },
  253.     { NULL,  0 }
  254.   };
  255.  
  256.   struct anim_map {
  257.     char* name;
  258.     unsigned id;
  259.   } anim_map[] = {
  260.     { "init",       1 },
  261.     { "walk",       2 },
  262.     { "stand",      3 },
  263.     { "talkStart",  4 },
  264.     { "talkStop",   5 },
  265.     { NULL, 0 }
  266.   };
  267.   
  268. #define ANIM_USER_START 6
  269.  
  270. #define COST_CMD_SOUND 0x70
  271. #define COST_CMD_STOP  0x79
  272. #define COST_CMD_START 0x7A
  273. #define COST_CMD_HIDE  0x7B
  274. #define COST_CMD_SKIP  0x7C
  275.   
  276.  
  277.  
  278. /* Enabling traces.  */
  279. #ifndef YYDEBUG
  280. # define YYDEBUG 0
  281. #endif
  282.  
  283. /* Enabling verbose error messages.  */
  284. #ifdef YYERROR_VERBOSE
  285. # undef YYERROR_VERBOSE
  286. # define YYERROR_VERBOSE 1
  287. #else
  288. # define YYERROR_VERBOSE 0
  289. #endif
  290.  
  291. /* Enabling the token table.  */
  292. #ifndef YYTOKEN_TABLE
  293. # define YYTOKEN_TABLE 0
  294. #endif
  295.  
  296. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  297. typedef union YYSTYPE
  298. #line 187 "/usr/tmp/cost_parse.y"
  299. {
  300.   int integer;    // INTEGER, number
  301.   char* str;      // STRING, ID
  302.   int intpair[2];
  303.   uint8_t* intlist;
  304. }
  305. /* Line 187 of yacc.c.  */
  306. #line 307 "cost_parse.tab.c"
  307.     YYSTYPE;
  308. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  309. # define YYSTYPE_IS_DECLARED 1
  310. # define YYSTYPE_IS_TRIVIAL 1
  311. #endif
  312.  
  313. #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  314. typedef struct YYLTYPE
  315. {
  316.   int first_line;
  317.   int first_column;
  318.   int last_line;
  319.   int last_column;
  320. } YYLTYPE;
  321. # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
  322. # define YYLTYPE_IS_DECLARED 1
  323. # define YYLTYPE_IS_TRIVIAL 1
  324. #endif
  325.  
  326.  
  327. /* Copy the second part of user declarations.  */
  328.  
  329.  
  330. /* Line 216 of yacc.c.  */
  331. #line 332 "cost_parse.tab.c"
  332.  
  333. #ifdef short
  334. # undef short
  335. #endif
  336.  
  337. #ifdef YYTYPE_UINT8
  338. typedef YYTYPE_UINT8 yytype_uint8;
  339. #else
  340. typedef unsigned char yytype_uint8;
  341. #endif
  342.  
  343. #ifdef YYTYPE_INT8
  344. typedef YYTYPE_INT8 yytype_int8;
  345. #elif (defined __STDC__ || defined __C99__FUNC__ \
  346.      || defined __cplusplus || defined _MSC_VER)
  347. typedef signed char yytype_int8;
  348. #else
  349. typedef short int yytype_int8;
  350. #endif
  351.  
  352. #ifdef YYTYPE_UINT16
  353. typedef YYTYPE_UINT16 yytype_uint16;
  354. #else
  355. typedef unsigned short int yytype_uint16;
  356. #endif
  357.  
  358. #ifdef YYTYPE_INT16
  359. typedef YYTYPE_INT16 yytype_int16;
  360. #else
  361. typedef short int yytype_int16;
  362. #endif
  363.  
  364. #ifndef YYSIZE_T
  365. # ifdef __SIZE_TYPE__
  366. #  define YYSIZE_T __SIZE_TYPE__
  367. # elif defined size_t
  368. #  define YYSIZE_T size_t
  369. # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  370.      || defined __cplusplus || defined _MSC_VER)
  371. #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  372. #  define YYSIZE_T size_t
  373. # else
  374. #  define YYSIZE_T unsigned int
  375. # endif
  376. #endif
  377.  
  378. #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  379.  
  380. #ifndef YY_
  381. # if YYENABLE_NLS
  382. #  if ENABLE_NLS
  383. #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  384. #   define YY_(msgid) dgettext ("bison-runtime", msgid)
  385. #  endif
  386. # endif
  387. # ifndef YY_
  388. #  define YY_(msgid) msgid
  389. # endif
  390. #endif
  391.  
  392. /* Suppress unused-variable warnings by "using" E.  */
  393. #if ! defined lint || defined __GNUC__
  394. # define YYUSE(e) ((void) (e))
  395. #else
  396. # define YYUSE(e) /* empty */
  397. #endif
  398.  
  399. /* Identity function, used to suppress warnings about constant conditions.  */
  400. #ifndef lint
  401. # define YYID(n) (n)
  402. #else
  403. #if (defined __STDC__ || defined __C99__FUNC__ \
  404.      || defined __cplusplus || defined _MSC_VER)
  405. static int
  406. YYID (int i)
  407. #else
  408. static int
  409. YYID (i)
  410.     int i;
  411. #endif
  412. {
  413.   return i;
  414. }
  415. #endif
  416.  
  417. #if ! defined yyoverflow || YYERROR_VERBOSE
  418.  
  419. /* The parser invokes alloca or malloc; define the necessary symbols.  */
  420.  
  421. # ifdef YYSTACK_USE_ALLOCA
  422. #  if YYSTACK_USE_ALLOCA
  423. #   ifdef __GNUC__
  424. #    define YYSTACK_ALLOC __builtin_alloca
  425. #   elif defined __BUILTIN_VA_ARG_INCR
  426. #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  427. #   elif defined _AIX
  428. #    define YYSTACK_ALLOC __alloca
  429. #   elif defined _MSC_VER
  430. #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  431. #    define alloca _alloca
  432. #   else
  433. #    define YYSTACK_ALLOC alloca
  434. #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  435.      || defined __cplusplus || defined _MSC_VER)
  436. #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  437. #     ifndef _STDLIB_H
  438. #      define _STDLIB_H 1
  439. #     endif
  440. #    endif
  441. #   endif
  442. #  endif
  443. # endif
  444.  
  445. # ifdef YYSTACK_ALLOC
  446.    /* Pacify GCC's `empty if-body' warning.  */
  447. #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  448. #  ifndef YYSTACK_ALLOC_MAXIMUM
  449.     /* The OS might guarantee only one guard page at the bottom of the stack,
  450.        and a page size can be as small as 4096 bytes.  So we cannot safely
  451.        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
  452.        to allow for a few compiler-allocated temporary stack slots.  */
  453. #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  454. #  endif
  455. # else
  456. #  define YYSTACK_ALLOC YYMALLOC
  457. #  define YYSTACK_FREE YYFREE
  458. #  ifndef YYSTACK_ALLOC_MAXIMUM
  459. #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  460. #  endif
  461. #  if (defined __cplusplus && ! defined _STDLIB_H \
  462.        && ! ((defined YYMALLOC || defined malloc) \
  463.          && (defined YYFREE || defined free)))
  464. #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  465. #   ifndef _STDLIB_H
  466. #    define _STDLIB_H 1
  467. #   endif
  468. #  endif
  469. #  ifndef YYMALLOC
  470. #   define YYMALLOC malloc
  471. #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  472.      || defined __cplusplus || defined _MSC_VER)
  473. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  474. #   endif
  475. #  endif
  476. #  ifndef YYFREE
  477. #   define YYFREE free
  478. #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  479.      || defined __cplusplus || defined _MSC_VER)
  480. void free (void *); /* INFRINGES ON USER NAME SPACE */
  481. #   endif
  482. #  endif
  483. # endif
  484. #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  485.  
  486.  
  487. #if (! defined yyoverflow \
  488.      && (! defined __cplusplus \
  489.      || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  490.          && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  491.  
  492. /* A type that is properly aligned for any stack member.  */
  493. union yyalloc
  494. {
  495.   yytype_int16 yyss;
  496.   YYSTYPE yyvs;
  497.     YYLTYPE yyls;
  498. };
  499.  
  500. /* The size of the maximum gap between one aligned stack and the next.  */
  501. # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  502.  
  503. /* The size of an array large to enough to hold all stacks, each with
  504.    N elements.  */
  505. # define YYSTACK_BYTES(N) \
  506.      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  507.       + 2 * YYSTACK_GAP_MAXIMUM)
  508.  
  509. /* Copy COUNT objects from FROM to TO.  The source and destination do
  510.    not overlap.  */
  511. # ifndef YYCOPY
  512. #  if defined __GNUC__ && 1 < __GNUC__
  513. #   define YYCOPY(To, From, Count) \
  514.       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  515. #  else
  516. #   define YYCOPY(To, From, Count)        \
  517.       do                    \
  518.     {                    \
  519.       YYSIZE_T yyi;                \
  520.       for (yyi = 0; yyi < (Count); yyi++)    \
  521.         (To)[yyi] = (From)[yyi];        \
  522.     }                    \
  523.       while (YYID (0))
  524. #  endif
  525. # endif
  526.  
  527. /* Relocate STACK from its old location to the new one.  The
  528.    local variables YYSIZE and YYSTACKSIZE give the old and new number of
  529.    elements in the stack, and YYPTR gives the new location of the
  530.    stack.  Advance YYPTR to a properly aligned location for the next
  531.    stack.  */
  532. # define YYSTACK_RELOCATE(Stack)                    \
  533.     do                                    \
  534.       {                                    \
  535.     YYSIZE_T yynewbytes;                        \
  536.     YYCOPY (&yyptr->Stack, Stack, yysize);                \
  537.     Stack = &yyptr->Stack;                        \
  538.     yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  539.     yyptr += yynewbytes / sizeof (*yyptr);                \
  540.       }                                    \
  541.     while (YYID (0))
  542.  
  543. #endif
  544.  
  545. /* YYFINAL -- State number of the termination state.  */
  546. #define YYFINAL  6
  547. /* YYLAST -- Last index in YYTABLE.  */
  548. #define YYLAST   127
  549.  
  550. /* YYNTOKENS -- Number of terminals.  */
  551. #define YYNTOKENS  36
  552. /* YYNNTS -- Number of nonterminals.  */
  553. #define YYNNTS  33
  554. /* YYNRULES -- Number of rules.  */
  555. #define YYNRULES  65
  556. /* YYNRULES -- Number of states.  */
  557. #define YYNSTATES  128
  558.  
  559. /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
  560. #define YYUNDEFTOK  2
  561. #define YYMAXUTOK   277
  562.  
  563. #define YYTRANSLATE(YYX)                        \
  564.   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  565.  
  566. /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
  567. static const yytype_uint8 yytranslate[] =
  568. {
  569.        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  570.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  571.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  572.        2,     2,     2,    33,     2,     2,     2,     2,     2,     2,
  573.       28,    29,     2,    34,    27,    31,     2,     2,     2,     2,
  574.        2,     2,     2,     2,     2,     2,     2,     2,     2,    23,
  575.        2,    24,     2,     2,    35,     2,     2,     2,     2,     2,
  576.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  577.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  578.        2,    30,     2,    32,     2,     2,     2,     2,     2,     2,
  579.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  580.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  581.        2,     2,     2,    25,     2,    26,     2,     2,     2,     2,
  582.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  583.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  584.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  585.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  586.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  587.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  588.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  589.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  590.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  591.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  592.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  593.        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  594.        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
  595.        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
  596.       15,    16,    17,    18,    19,    20,    21,    22
  597. };
  598.  
  599. #if YYDEBUG
  600. /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  601.    YYRHS.  */
  602. static const yytype_uint8 yyprhs[] =
  603. {
  604.        0,     0,     3,     4,     6,    10,    12,    15,    19,    21,
  605.       23,    25,    27,    29,    31,    33,    39,    42,    44,    48,
  606.       52,    56,    60,    64,    70,    74,    76,    80,    86,    90,
  607.       93,    97,   103,   105,   107,   111,   117,   122,   124,   128,
  608.      130,   132,   134,   136,   138,   143,   149,   151,   155,   157,
  609.      163,   164,   169,   170,   172,   174,   178,   180,   183,   185,
  610.      187,   193,   195,   198,   201,   202
  611. };
  612.  
  613. /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
  614. static const yytype_int8 yyrhs[] =
  615. {
  616.       37,     0,    -1,    -1,    38,    -1,    58,    61,    39,    -1,
  617.       23,    -1,    40,    23,    -1,    39,    40,    23,    -1,    41,
  618.       -1,    42,    -1,    46,    -1,    49,    -1,    43,    -1,    47,
  619.       -1,    50,    -1,    43,    24,    25,    44,    26,    -1,     7,
  620.       12,    -1,    45,    -1,    44,    27,    45,    -1,    13,    24,
  621.       11,    -1,    14,    24,    11,    -1,    15,    24,    66,    -1,
  622.       16,    24,    66,    -1,    47,    24,    25,    48,    26,    -1,
  623.        8,    12,    68,    -1,    12,    -1,    48,    27,    12,    -1,
  624.       50,    24,    25,    51,    26,    -1,     9,    12,    68,    -1,
  625.       52,    23,    -1,    51,    52,    23,    -1,    53,    24,    25,
  626.       54,    26,    -1,    12,    -1,    55,    -1,    54,    27,    55,
  627.       -1,    12,    28,    56,    29,    62,    -1,    12,    28,    29,
  628.       62,    -1,    57,    -1,    56,    27,    57,    -1,    60,    -1,
  629.       17,    -1,    18,    -1,    19,    -1,    20,    -1,    21,    28,
  630.       10,    29,    -1,     3,    28,    59,    29,    23,    -1,    60,
  631.       -1,    59,    27,    60,    -1,    10,    -1,    30,    10,    31,
  632.       10,    32,    -1,    -1,     4,    24,    63,    23,    -1,    -1,
  633.       63,    -1,    64,    -1,    63,    27,    64,    -1,    65,    -1,
  634.       33,    65,    -1,     6,    -1,     5,    -1,    25,    67,    27,
  635.       67,    26,    -1,    10,    -1,    31,    10,    -1,    34,    10,
  636.       -1,    -1,    35,    10,    -1
  637. };
  638.  
  639. /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
  640. static const yytype_uint16 yyrline[] =
  641. {
  642.        0,   216,   216,   217,   222,   225,   226,   227,   230,   231,
  643.      232,   233,   236,   240,   244,   250,   320,   337,   338,   341,
  644.      351,   365,   370,   378,   381,   419,   430,   448,   454,   500,
  645.      501,   504,   507,   520,   521,   524,   548,   566,   567,   578,
  646.      579,   585,   591,   597,   603,   614,   625,   626,   637,   646,
  647.      667,   668,   676,   680,   683,   684,   691,   696,   703,   708,
  648.      715,   722,   723,   727,   734,   737
  649. };
  650. #endif
  651.  
  652. #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
  653. /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  654.    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
  655. static const char *const yytname[] =
  656. {
  657.   "$end", "error", "$undefined", "PALETTE", "FLAGS", "LOOP", "FLIP",
  658.   "PICTURE", "LIMB", "ANIM", "INTEGER", "STRING", "SYM", "PATH", "GLOB",
  659.   "POSITION", "MOVE", "START", "STOP", "HIDE", "SKIP", "SOUND", "ERROR",
  660.   "';'", "'='", "'{'", "'}'", "','", "'('", "')'", "'['", "'-'", "']'",
  661.   "'!'", "'+'", "'@'", "$accept", "srcfile", "costume", "statementlist",
  662.   "statement", "dec", "picture", "picturedec", "picparamlist", "picparam",
  663.   "limb", "limbdec", "piclist", "anim", "animdec", "animdirlist",
  664.   "animdir", "animdirname", "limbanimlist", "limbanim", "cmdlist",
  665.   "cmdlistitem", "palette", "intlist", "intlistitem", "costflags",
  666.   "limbanimflags", "flaglist", "flag", "flagvalue", "numberpair", "number",
  667.   "location", 0
  668. };
  669. #endif
  670.  
  671. # ifdef YYPRINT
  672. /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  673.    token YYLEX-NUM.  */
  674. static const yytype_uint16 yytoknum[] =
  675. {
  676.        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
  677.      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
  678.      275,   276,   277,    59,    61,   123,   125,    44,    40,    41,
  679.       91,    45,    93,    33,    43,    64
  680. };
  681. # endif
  682.  
  683. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
  684. static const yytype_uint8 yyr1[] =
  685. {
  686.        0,    36,    37,    37,    38,    39,    39,    39,    40,    40,
  687.       40,    40,    41,    41,    41,    42,    43,    44,    44,    45,
  688.       45,    45,    45,    46,    47,    48,    48,    49,    50,    51,
  689.       51,    52,    53,    54,    54,    55,    55,    56,    56,    57,
  690.       57,    57,    57,    57,    57,    58,    59,    59,    60,    60,
  691.       61,    61,    62,    62,    63,    63,    64,    64,    65,    65,
  692.       66,    67,    67,    67,    68,    68
  693. };
  694.  
  695. /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
  696. static const yytype_uint8 yyr2[] =
  697. {
  698.        0,     2,     0,     1,     3,     1,     2,     3,     1,     1,
  699.        1,     1,     1,     1,     1,     5,     2,     1,     3,     3,
  700.        3,     3,     3,     5,     3,     1,     3,     5,     3,     2,
  701.        3,     5,     1,     1,     3,     5,     4,     1,     3,     1,
  702.        1,     1,     1,     1,     4,     5,     1,     3,     1,     5,
  703.        0,     4,     0,     1,     1,     3,     1,     2,     1,     1,
  704.        5,     1,     2,     2,     0,     2
  705. };
  706.  
  707. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  708.    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
  709.    means the default is an error.  */
  710. static const yytype_uint8 yydefact[] =
  711. {
  712.        2,     0,     0,     3,    50,     0,     1,     0,     0,    48,
  713.        0,     0,    46,     0,     0,     0,     0,     5,     4,     0,
  714.        8,     9,    12,    10,    13,    11,    14,     0,     0,     0,
  715.       59,    58,     0,     0,    54,    56,    16,    64,    64,     0,
  716.        6,     0,     0,     0,     0,    47,    45,    57,    51,     0,
  717.        0,    24,    28,     7,     0,     0,     0,     0,    55,    65,
  718.        0,     0,     0,     0,     0,    17,    25,     0,    32,     0,
  719.        0,     0,    49,     0,     0,     0,     0,    15,     0,    23,
  720.        0,    27,     0,    29,     0,    19,    20,     0,    21,    22,
  721.       18,    26,    30,     0,    61,     0,     0,     0,     0,     0,
  722.       33,    62,    63,     0,     0,    31,     0,     0,    40,    41,
  723.       42,    43,     0,    52,     0,    37,    39,    34,    60,     0,
  724.       36,    53,     0,    52,     0,    38,    35,    44
  725. };
  726.  
  727. /* YYDEFGOTO[NTERM-NUM].  */
  728. static const yytype_int8 yydefgoto[] =
  729. {
  730.       -1,     2,     3,    18,    19,    20,    21,    22,    64,    65,
  731.       23,    24,    67,    25,    26,    69,    70,    71,    99,   100,
  732.      114,   115,     4,    11,   116,     8,   120,   121,    34,    35,
  733.       88,    97,    51
  734. };
  735.  
  736. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  737.    STATE-NUM.  */
  738. #define YYPACT_NINF -23
  739. static const yytype_int8 yypact[] =
  740. {
  741.       12,   -19,    47,   -23,    21,     6,   -23,    32,    30,   -23,
  742.       48,    16,   -23,    -5,    45,    49,    50,   -23,    33,    36,
  743.      -23,   -23,    39,   -23,    40,   -23,    41,    29,     6,    43,
  744.      -23,   -23,    44,   -20,   -23,   -23,   -23,    34,    34,    51,
  745.      -23,    42,    46,    52,    58,   -23,   -23,   -23,   -23,    -5,
  746.       60,   -23,   -23,   -23,    -2,    61,    63,    53,   -23,   -23,
  747.       54,    55,    56,    57,   -21,   -23,   -23,    25,   -23,    -4,
  748.       59,    62,   -23,    65,    72,    64,    64,   -23,    -2,   -23,
  749.       75,   -23,    67,   -23,    66,   -23,   -23,    -8,   -23,   -23,
  750.      -23,   -23,   -23,    76,   -23,    74,    82,    68,    69,    28,
  751.      -23,   -23,   -23,    -8,     0,   -23,    76,    70,   -23,   -23,
  752.      -23,   -23,    71,    -5,    19,   -23,   -23,   -23,   -23,    83,
  753.      -23,    73,    14,    -5,    77,   -23,   -23,   -23
  754. };
  755.  
  756. /* YYPGOTO[NTERM-NUM].  */
  757. static const yytype_int8 yypgoto[] =
  758. {
  759.      -23,   -23,   -23,   -23,    80,   -23,   -23,   -23,   -23,    -6,
  760.      -23,   -23,   -23,   -23,   -23,   -23,    35,   -23,   -23,   -12,
  761.      -23,   -17,   -23,   -23,    -1,   -23,   -22,    89,    78,    79,
  762.       27,     4,    81
  763. };
  764.  
  765. /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
  766.    positive, shift that token.  If negative, reduce the rule which
  767.    number is the opposite.  If zero, do what YYDEFACT says.
  768.    If YYTABLE_NINF, syntax error.  */
  769. #define YYTABLE_NINF -1
  770. static const yytype_uint8 yytable[] =
  771. {
  772.       30,    31,    94,    48,    12,    77,    78,    49,    68,     5,
  773.        9,    60,    61,    62,    63,     1,     9,   108,   109,   110,
  774.      111,   112,    81,    95,     9,     7,    96,    45,    32,   113,
  775.       10,   108,   109,   110,   111,   112,    10,    14,    15,    16,
  776.       14,    15,    16,    28,    10,    29,   122,     6,   123,    30,
  777.       31,    79,    80,    17,   105,   106,    13,    36,    27,    40,
  778.       44,    37,    38,    41,    42,    43,    46,    54,    57,    50,
  779.       59,    55,    90,    66,    53,    68,    85,    56,    73,    74,
  780.       75,    76,    83,    86,   101,    72,    84,    91,    98,    87,
  781.       92,    93,   102,   124,   117,   103,   118,   104,    39,   119,
  782.       49,   126,    33,    89,    82,   125,   127,   107,     0,     0,
  783.        0,    47,     0,     0,     0,     0,     0,     0,     0,    52,
  784.        0,     0,     0,     0,     0,     0,     0,    58
  785. };
  786.  
  787. static const yytype_int8 yycheck[] =
  788. {
  789.        5,     6,    10,    23,     5,    26,    27,    27,    12,    28,
  790.       10,    13,    14,    15,    16,     3,    10,    17,    18,    19,
  791.       20,    21,    26,    31,    10,     4,    34,    28,    33,    29,
  792.       30,    17,    18,    19,    20,    21,    30,     7,     8,     9,
  793.        7,     8,     9,    27,    30,    29,    27,     0,    29,     5,
  794.        6,    26,    27,    23,    26,    27,    24,    12,    10,    23,
  795.       31,    12,    12,    24,    24,    24,    23,    25,    10,    35,
  796.       10,    25,    78,    12,    23,    12,    11,    25,    24,    24,
  797.       24,    24,    23,    11,    10,    32,    24,    12,    12,    25,
  798.       23,    25,    10,    10,   106,    27,    26,    28,    18,    28,
  799.       27,   123,    13,    76,    69,   122,    29,   103,    -1,    -1,
  800.       -1,    32,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    38,
  801.       -1,    -1,    -1,    -1,    -1,    -1,    -1,    49
  802. };
  803.  
  804. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  805.    symbol of state STATE-NUM.  */
  806. static const yytype_uint8 yystos[] =
  807. {
  808.        0,     3,    37,    38,    58,    28,     0,     4,    61,    10,
  809.       30,    59,    60,    24,     7,     8,     9,    23,    39,    40,
  810.       41,    42,    43,    46,    47,    49,    50,    10,    27,    29,
  811.        5,     6,    33,    63,    64,    65,    12,    12,    12,    40,
  812.       23,    24,    24,    24,    31,    60,    23,    65,    23,    27,
  813.       35,    68,    68,    23,    25,    25,    25,    10,    64,    10,
  814.       13,    14,    15,    16,    44,    45,    12,    48,    12,    51,
  815.       52,    53,    32,    24,    24,    24,    24,    26,    27,    26,
  816.       27,    26,    52,    23,    24,    11,    11,    25,    66,    66,
  817.       45,    12,    23,    25,    10,    31,    34,    67,    12,    54,
  818.       55,    10,    10,    27,    28,    26,    27,    67,    17,    18,
  819.       19,    20,    21,    29,    56,    57,    60,    55,    26,    28,
  820.       62,    63,    27,    29,    10,    57,    62,    29
  821. };
  822.  
  823. #define yyerrok        (yyerrstatus = 0)
  824. #define yyclearin    (yychar = YYEMPTY)
  825. #define YYEMPTY        (-2)
  826. #define YYEOF        0
  827.  
  828. #define YYACCEPT    goto yyacceptlab
  829. #define YYABORT        goto yyabortlab
  830. #define YYERROR        goto yyerrorlab
  831.  
  832.  
  833. /* Like YYERROR except do call yyerror.  This remains here temporarily
  834.    to ease the transition to the new meaning of YYERROR, for GCC.
  835.    Once GCC version 2 has supplanted version 1, this can go.  */
  836.  
  837. #define YYFAIL        goto yyerrlab
  838.  
  839. #define YYRECOVERING()  (!!yyerrstatus)
  840.  
  841. #define YYBACKUP(Token, Value)                    \
  842. do                                \
  843.   if (yychar == YYEMPTY && yylen == 1)                \
  844.     {                                \
  845.       yychar = (Token);                        \
  846.       yylval = (Value);                        \
  847.       yytoken = YYTRANSLATE (yychar);                \
  848.       YYPOPSTACK (1);                        \
  849.       goto yybackup;                        \
  850.     }                                \
  851.   else                                \
  852.     {                                \
  853.       yyerror (YY_("syntax error: cannot back up")); \
  854.       YYERROR;                            \
  855.     }                                \
  856. while (YYID (0))
  857.  
  858.  
  859. #define YYTERROR    1
  860. #define YYERRCODE    256
  861.  
  862.  
  863. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  864.    If N is 0, then set CURRENT to the empty location which ends
  865.    the previous symbol: RHS[0] (always defined).  */
  866.  
  867. #define YYRHSLOC(Rhs, K) ((Rhs)[K])
  868. #ifndef YYLLOC_DEFAULT
  869. # define YYLLOC_DEFAULT(Current, Rhs, N)                \
  870.     do                                    \
  871.       if (YYID (N))                                                    \
  872.     {                                \
  873.       (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;    \
  874.       (Current).first_column = YYRHSLOC (Rhs, 1).first_column;    \
  875.       (Current).last_line    = YYRHSLOC (Rhs, N).last_line;        \
  876.       (Current).last_column  = YYRHSLOC (Rhs, N).last_column;    \
  877.     }                                \
  878.       else                                \
  879.     {                                \
  880.       (Current).first_line   = (Current).last_line   =        \
  881.         YYRHSLOC (Rhs, 0).last_line;                \
  882.       (Current).first_column = (Current).last_column =        \
  883.         YYRHSLOC (Rhs, 0).last_column;                \
  884.     }                                \
  885.     while (YYID (0))
  886. #endif
  887.  
  888.  
  889. /* YY_LOCATION_PRINT -- Print the location on the stream.
  890.    This macro was not mandated originally: define only if we know
  891.    we won't break user code: when these are the locations we know.  */
  892.  
  893. #ifndef YY_LOCATION_PRINT
  894. # if YYLTYPE_IS_TRIVIAL
  895. #  define YY_LOCATION_PRINT(File, Loc)            \
  896.      fprintf (File, "%d.%d-%d.%d",            \
  897.           (Loc).first_line, (Loc).first_column,    \
  898.           (Loc).last_line,  (Loc).last_column)
  899. # else
  900. #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  901. # endif
  902. #endif
  903.  
  904.  
  905. /* YYLEX -- calling `yylex' with the right arguments.  */
  906.  
  907. #ifdef YYLEX_PARAM
  908. # define YYLEX yylex (YYLEX_PARAM)
  909. #else
  910. # define YYLEX yylex ()
  911. #endif
  912.  
  913. /* Enable debugging if requested.  */
  914. #if YYDEBUG
  915.  
  916. # ifndef YYFPRINTF
  917. #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  918. #  define YYFPRINTF fprintf
  919. # endif
  920.  
  921. # define YYDPRINTF(Args)            \
  922. do {                        \
  923.   if (yydebug)                    \
  924.     YYFPRINTF Args;                \
  925. } while (YYID (0))
  926.  
  927. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)              \
  928. do {                                      \
  929.   if (yydebug)                                  \
  930.     {                                      \
  931.       YYFPRINTF (stderr, "%s ", Title);                      \
  932.       yy_symbol_print (stderr,                          \
  933.           Type, Value, Location); \
  934.       YYFPRINTF (stderr, "\n");                          \
  935.     }                                      \
  936. } while (YYID (0))
  937.  
  938.  
  939. /*--------------------------------.
  940. | Print this symbol on YYOUTPUT.  |
  941. `--------------------------------*/
  942.  
  943. /*ARGSUSED*/
  944. #if (defined __STDC__ || defined __C99__FUNC__ \
  945.      || defined __cplusplus || defined _MSC_VER)
  946. static void
  947. yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  948. #else
  949. static void
  950. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
  951.     FILE *yyoutput;
  952.     int yytype;
  953.     YYSTYPE const * const yyvaluep;
  954.     YYLTYPE const * const yylocationp;
  955. #endif
  956. {
  957.   if (!yyvaluep)
  958.     return;
  959.   YYUSE (yylocationp);
  960. # ifdef YYPRINT
  961.   if (yytype < YYNTOKENS)
  962.     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  963. # else
  964.   YYUSE (yyoutput);
  965. # endif
  966.   switch (yytype)
  967.     {
  968.       default:
  969.     break;
  970.     }
  971. }
  972.  
  973.  
  974. /*--------------------------------.
  975. | Print this symbol on YYOUTPUT.  |
  976. `--------------------------------*/
  977.  
  978. #if (defined __STDC__ || defined __C99__FUNC__ \
  979.      || defined __cplusplus || defined _MSC_VER)
  980. static void
  981. yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  982. #else
  983. static void
  984. yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
  985.     FILE *yyoutput;
  986.     int yytype;
  987.     YYSTYPE const * const yyvaluep;
  988.     YYLTYPE const * const yylocationp;
  989. #endif
  990. {
  991.   if (yytype < YYNTOKENS)
  992.     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  993.   else
  994.     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  995.  
  996.   YY_LOCATION_PRINT (yyoutput, *yylocationp);
  997.   YYFPRINTF (yyoutput, ": ");
  998.   yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
  999.   YYFPRINTF (yyoutput, ")");
  1000. }
  1001.  
  1002. /*------------------------------------------------------------------.
  1003. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  1004. | TOP (included).                                                   |
  1005. `------------------------------------------------------------------*/
  1006.  
  1007. #if (defined __STDC__ || defined __C99__FUNC__ \
  1008.      || defined __cplusplus || defined _MSC_VER)
  1009. static void
  1010. yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
  1011. #else
  1012. static void
  1013. yy_stack_print (bottom, top)
  1014.     yytype_int16 *bottom;
  1015.     yytype_int16 *top;
  1016. #endif
  1017. {
  1018.   YYFPRINTF (stderr, "Stack now");
  1019.   for (; bottom <= top; ++bottom)
  1020.     YYFPRINTF (stderr, " %d", *bottom);
  1021.   YYFPRINTF (stderr, "\n");
  1022. }
  1023.  
  1024. # define YY_STACK_PRINT(Bottom, Top)                \
  1025. do {                                \
  1026.   if (yydebug)                            \
  1027.     yy_stack_print ((Bottom), (Top));                \
  1028. } while (YYID (0))
  1029.  
  1030.  
  1031. /*------------------------------------------------.
  1032. | Report that the YYRULE is going to be reduced.  |
  1033. `------------------------------------------------*/
  1034.  
  1035. #if (defined __STDC__ || defined __C99__FUNC__ \
  1036.      || defined __cplusplus || defined _MSC_VER)
  1037. static void
  1038. yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
  1039. #else
  1040. static void
  1041. yy_reduce_print (yyvsp, yylsp, yyrule)
  1042.     YYSTYPE *yyvsp;
  1043.     YYLTYPE *yylsp;
  1044.     int yyrule;
  1045. #endif
  1046. {
  1047.   int yynrhs = yyr2[yyrule];
  1048.   int yyi;
  1049.   unsigned long int yylno = yyrline[yyrule];
  1050.   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  1051.          yyrule - 1, yylno);
  1052.   /* The symbols being reduced.  */
  1053.   for (yyi = 0; yyi < yynrhs; yyi++)
  1054.     {
  1055.       fprintf (stderr, "   $%d = ", yyi + 1);
  1056.       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  1057.                &(yyvsp[(yyi + 1) - (yynrhs)])
  1058.                , &(yylsp[(yyi + 1) - (yynrhs)])               );
  1059.       fprintf (stderr, "\n");
  1060.     }
  1061. }
  1062.  
  1063. # define YY_REDUCE_PRINT(Rule)        \
  1064. do {                    \
  1065.   if (yydebug)                \
  1066.     yy_reduce_print (yyvsp, yylsp, Rule); \
  1067. } while (YYID (0))
  1068.  
  1069. /* Nonzero means print parse trace.  It is left uninitialized so that
  1070.    multiple parsers can coexist.  */
  1071. int yydebug;
  1072. #else /* !YYDEBUG */
  1073. # define YYDPRINTF(Args)
  1074. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1075. # define YY_STACK_PRINT(Bottom, Top)
  1076. # define YY_REDUCE_PRINT(Rule)
  1077. #endif /* !YYDEBUG */
  1078.  
  1079.  
  1080. /* YYINITDEPTH -- initial size of the parser's stacks.  */
  1081. #ifndef    YYINITDEPTH
  1082. # define YYINITDEPTH 200
  1083. #endif
  1084.  
  1085. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1086.    if the built-in stack extension method is used).
  1087.  
  1088.    Do not make this value too large; the results are undefined if
  1089.    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1090.    evaluated with infinite-precision integer arithmetic.  */
  1091.  
  1092. #ifndef YYMAXDEPTH
  1093. # define YYMAXDEPTH 10000
  1094. #endif
  1095.  
  1096.  
  1097.  
  1098. #if YYERROR_VERBOSE
  1099.  
  1100. # ifndef yystrlen
  1101. #  if defined __GLIBC__ && defined _STRING_H
  1102. #   define yystrlen strlen
  1103. #  else
  1104. /* Return the length of YYSTR.  */
  1105. #if (defined __STDC__ || defined __C99__FUNC__ \
  1106.      || defined __cplusplus || defined _MSC_VER)
  1107. static YYSIZE_T
  1108. yystrlen (const char *yystr)
  1109. #else
  1110. static YYSIZE_T
  1111. yystrlen (yystr)
  1112.     const char *yystr;
  1113. #endif
  1114. {
  1115.   YYSIZE_T yylen;
  1116.   for (yylen = 0; yystr[yylen]; yylen++)
  1117.     continue;
  1118.   return yylen;
  1119. }
  1120. #  endif
  1121. # endif
  1122.  
  1123. # ifndef yystpcpy
  1124. #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1125. #   define yystpcpy stpcpy
  1126. #  else
  1127. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1128.    YYDEST.  */
  1129. #if (defined __STDC__ || defined __C99__FUNC__ \
  1130.      || defined __cplusplus || defined _MSC_VER)
  1131. static char *
  1132. yystpcpy (char *yydest, const char *yysrc)
  1133. #else
  1134. static char *
  1135. yystpcpy (yydest, yysrc)
  1136.     char *yydest;
  1137.     const char *yysrc;
  1138. #endif
  1139. {
  1140.   char *yyd = yydest;
  1141.   const char *yys = yysrc;
  1142.  
  1143.   while ((*yyd++ = *yys++) != '\0')
  1144.     continue;
  1145.  
  1146.   return yyd - 1;
  1147. }
  1148. #  endif
  1149. # endif
  1150.  
  1151. # ifndef yytnamerr
  1152. /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1153.    quotes and backslashes, so that it's suitable for yyerror.  The
  1154.    heuristic is that double-quoting is unnecessary unless the string
  1155.    contains an apostrophe, a comma, or backslash (other than
  1156.    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
  1157.    null, do not copy; instead, return the length of what the result
  1158.    would have been.  */
  1159. static YYSIZE_T
  1160. yytnamerr (char *yyres, const char *yystr)
  1161. {
  1162.   if (*yystr == '"')
  1163.     {
  1164.       YYSIZE_T yyn = 0;
  1165.       char const *yyp = yystr;
  1166.  
  1167.       for (;;)
  1168.     switch (*++yyp)
  1169.       {
  1170.       case '\'':
  1171.       case ',':
  1172.         goto do_not_strip_quotes;
  1173.  
  1174.       case '\\':
  1175.         if (*++yyp != '\\')
  1176.           goto do_not_strip_quotes;
  1177.         /* Fall through.  */
  1178.       default:
  1179.         if (yyres)
  1180.           yyres[yyn] = *yyp;
  1181.         yyn++;
  1182.         break;
  1183.  
  1184.       case '"':
  1185.         if (yyres)
  1186.           yyres[yyn] = '\0';
  1187.         return yyn;
  1188.       }
  1189.     do_not_strip_quotes: ;
  1190.     }
  1191.  
  1192.   if (! yyres)
  1193.     return yystrlen (yystr);
  1194.  
  1195.   return yystpcpy (yyres, yystr) - yyres;
  1196. }
  1197. # endif
  1198.  
  1199. /* Copy into YYRESULT an error message about the unexpected token
  1200.    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
  1201.    including the terminating null byte.  If YYRESULT is null, do not
  1202.    copy anything; just return the number of bytes that would be
  1203.    copied.  As a special case, return 0 if an ordinary "syntax error"
  1204.    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
  1205.    size calculation.  */
  1206. static YYSIZE_T
  1207. yysyntax_error (char *yyresult, int yystate, int yychar)
  1208. {
  1209.   int yyn = yypact[yystate];
  1210.  
  1211.   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
  1212.     return 0;
  1213.   else
  1214.     {
  1215.       int yytype = YYTRANSLATE (yychar);
  1216.       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
  1217.       YYSIZE_T yysize = yysize0;
  1218.       YYSIZE_T yysize1;
  1219.       int yysize_overflow = 0;
  1220.       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1221.       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1222.       int yyx;
  1223.  
  1224. # if 0
  1225.       /* This is so xgettext sees the translatable formats that are
  1226.      constructed on the fly.  */
  1227.       YY_("syntax error, unexpected %s");
  1228.       YY_("syntax error, unexpected %s, expecting %s");
  1229.       YY_("syntax error, unexpected %s, expecting %s or %s");
  1230.       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
  1231.       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
  1232. # endif
  1233.       char *yyfmt;
  1234.       char const *yyf;
  1235.       static char const yyunexpected[] = "syntax error, unexpected %s";
  1236.       static char const yyexpecting[] = ", expecting %s";
  1237.       static char const yyor[] = " or %s";
  1238.       char yyformat[sizeof yyunexpected
  1239.             + sizeof yyexpecting - 1
  1240.             + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
  1241.                * (sizeof yyor - 1))];
  1242.       char const *yyprefix = yyexpecting;
  1243.  
  1244.       /* Start YYX at -YYN if negative to avoid negative indexes in
  1245.      YYCHECK.  */
  1246.       int yyxbegin = yyn < 0 ? -yyn : 0;
  1247.  
  1248.       /* Stay within bounds of both yycheck and yytname.  */
  1249.       int yychecklim = YYLAST - yyn + 1;
  1250.       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1251.       int yycount = 1;
  1252.  
  1253.       yyarg[0] = yytname[yytype];
  1254.       yyfmt = yystpcpy (yyformat, yyunexpected);
  1255.  
  1256.       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1257.     if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1258.       {
  1259.         if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1260.           {
  1261.         yycount = 1;
  1262.         yysize = yysize0;
  1263.         yyformat[sizeof yyunexpected - 1] = '\0';
  1264.         break;
  1265.           }
  1266.         yyarg[yycount++] = yytname[yyx];
  1267.         yysize1 = yysize + yytnamerr (0, yytname[yyx]);
  1268.         yysize_overflow |= (yysize1 < yysize);
  1269.         yysize = yysize1;
  1270.         yyfmt = yystpcpy (yyfmt, yyprefix);
  1271.         yyprefix = yyor;
  1272.       }
  1273.  
  1274.       yyf = YY_(yyformat);
  1275.       yysize1 = yysize + yystrlen (yyf);
  1276.       yysize_overflow |= (yysize1 < yysize);
  1277.       yysize = yysize1;
  1278.  
  1279.       if (yysize_overflow)
  1280.     return YYSIZE_MAXIMUM;
  1281.  
  1282.       if (yyresult)
  1283.     {
  1284.       /* Avoid sprintf, as that infringes on the user's name space.
  1285.          Don't have undefined behavior even if the translation
  1286.          produced a string with the wrong number of "%s"s.  */
  1287.       char *yyp = yyresult;
  1288.       int yyi = 0;
  1289.       while ((*yyp = *yyf) != '\0')
  1290.         {
  1291.           if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
  1292.         {
  1293.           yyp += yytnamerr (yyp, yyarg[yyi++]);
  1294.           yyf += 2;
  1295.         }
  1296.           else
  1297.         {
  1298.           yyp++;
  1299.           yyf++;
  1300.         }
  1301.         }
  1302.     }
  1303.       return yysize;
  1304.     }
  1305. }
  1306. #endif /* YYERROR_VERBOSE */
  1307.  
  1308.  
  1309. /*-----------------------------------------------.
  1310. | Release the memory associated to this symbol.  |
  1311. `-----------------------------------------------*/
  1312.  
  1313. /*ARGSUSED*/
  1314. #if (defined __STDC__ || defined __C99__FUNC__ \
  1315.      || defined __cplusplus || defined _MSC_VER)
  1316. static void
  1317. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  1318. #else
  1319. static void
  1320. yydestruct (yymsg, yytype, yyvaluep, yylocationp)
  1321.     const char *yymsg;
  1322.     int yytype;
  1323.     YYSTYPE *yyvaluep;
  1324.     YYLTYPE *yylocationp;
  1325. #endif
  1326. {
  1327.   YYUSE (yyvaluep);
  1328.   YYUSE (yylocationp);
  1329.  
  1330.   if (!yymsg)
  1331.     yymsg = "Deleting";
  1332.   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1333.  
  1334.   switch (yytype)
  1335.     {
  1336.  
  1337.       default:
  1338.     break;
  1339.     }
  1340. }
  1341.  
  1342.  
  1343. /* Prevent warnings from -Wmissing-prototypes.  */
  1344.  
  1345. #ifdef YYPARSE_PARAM
  1346. #if defined __STDC__ || defined __cplusplus
  1347. int yyparse (void *YYPARSE_PARAM);
  1348. #else
  1349. int yyparse ();
  1350. #endif
  1351. #else /* ! YYPARSE_PARAM */
  1352. #if defined __STDC__ || defined __cplusplus
  1353. int yyparse (void);
  1354. #else
  1355. int yyparse ();
  1356. #endif
  1357. #endif /* ! YYPARSE_PARAM */
  1358.  
  1359.  
  1360.  
  1361. /* The look-ahead symbol.  */
  1362. int yychar;
  1363.  
  1364. /* The semantic value of the look-ahead symbol.  */
  1365. YYSTYPE yylval;
  1366.  
  1367. /* Number of syntax errors so far.  */
  1368. int yynerrs;
  1369. /* Location data for the look-ahead symbol.  */
  1370. YYLTYPE yylloc;
  1371.  
  1372.  
  1373.  
  1374. /*----------.
  1375. | yyparse.  |
  1376. `----------*/
  1377.  
  1378. #ifdef YYPARSE_PARAM
  1379. #if (defined __STDC__ || defined __C99__FUNC__ \
  1380.      || defined __cplusplus || defined _MSC_VER)
  1381. int
  1382. yyparse (void *YYPARSE_PARAM)
  1383. #else
  1384. int
  1385. yyparse (YYPARSE_PARAM)
  1386.     void *YYPARSE_PARAM;
  1387. #endif
  1388. #else /* ! YYPARSE_PARAM */
  1389. #if (defined __STDC__ || defined __C99__FUNC__ \
  1390.      || defined __cplusplus || defined _MSC_VER)
  1391. int
  1392. yyparse (void)
  1393. #else
  1394. int
  1395. yyparse ()
  1396.  
  1397. #endif
  1398. #endif
  1399. {
  1400.   
  1401.   int yystate;
  1402.   int yyn;
  1403.   int yyresult;
  1404.   /* Number of tokens to shift before error messages enabled.  */
  1405.   int yyerrstatus;
  1406.   /* Look-ahead token as an internal (translated) token number.  */
  1407.   int yytoken = 0;
  1408. #if YYERROR_VERBOSE
  1409.   /* Buffer for error messages, and its allocated size.  */
  1410.   char yymsgbuf[128];
  1411.   char *yymsg = yymsgbuf;
  1412.   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  1413. #endif
  1414.  
  1415.   /* Three stacks and their tools:
  1416.      `yyss': related to states,
  1417.      `yyvs': related to semantic values,
  1418.      `yyls': related to locations.
  1419.  
  1420.      Refer to the stacks thru separate pointers, to allow yyoverflow
  1421.      to reallocate them elsewhere.  */
  1422.  
  1423.   /* The state stack.  */
  1424.   yytype_int16 yyssa[YYINITDEPTH];
  1425.   yytype_int16 *yyss = yyssa;
  1426.   yytype_int16 *yyssp;
  1427.  
  1428.   /* The semantic value stack.  */
  1429.   YYSTYPE yyvsa[YYINITDEPTH];
  1430.   YYSTYPE *yyvs = yyvsa;
  1431.   YYSTYPE *yyvsp;
  1432.  
  1433.   /* The location stack.  */
  1434.   YYLTYPE yylsa[YYINITDEPTH];
  1435.   YYLTYPE *yyls = yylsa;
  1436.   YYLTYPE *yylsp;
  1437.   /* The locations where the error started and ended.  */
  1438.   YYLTYPE yyerror_range[2];
  1439.  
  1440. #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  1441.  
  1442.   YYSIZE_T yystacksize = YYINITDEPTH;
  1443.  
  1444.   /* The variables used to return semantic value and location from the
  1445.      action routines.  */
  1446.   YYSTYPE yyval;
  1447.   YYLTYPE yyloc;
  1448.  
  1449.   /* The number of symbols on the RHS of the reduced rule.
  1450.      Keep to zero when no symbol should be popped.  */
  1451.   int yylen = 0;
  1452.  
  1453.   YYDPRINTF ((stderr, "Starting parse\n"));
  1454.  
  1455.   yystate = 0;
  1456.   yyerrstatus = 0;
  1457.   yynerrs = 0;
  1458.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  1459.  
  1460.   /* Initialize stack pointers.
  1461.      Waste one element of value and location stack
  1462.      so that they stay on the same level as the state stack.
  1463.      The wasted elements are never initialized.  */
  1464.  
  1465.   yyssp = yyss;
  1466.   yyvsp = yyvs;
  1467.   yylsp = yyls;
  1468. #if YYLTYPE_IS_TRIVIAL
  1469.   /* Initialize the default location before parsing starts.  */
  1470.   yylloc.first_line   = yylloc.last_line   = 1;
  1471.   yylloc.first_column = yylloc.last_column = 0;
  1472. #endif
  1473.  
  1474.   goto yysetstate;
  1475.  
  1476. /*------------------------------------------------------------.
  1477. | yynewstate -- Push a new state, which is found in yystate.  |
  1478. `------------------------------------------------------------*/
  1479.  yynewstate:
  1480.   /* In all cases, when you get here, the value and location stacks
  1481.      have just been pushed.  So pushing a state here evens the stacks.  */
  1482.   yyssp++;
  1483.  
  1484.  yysetstate:
  1485.   *yyssp = yystate;
  1486.  
  1487.   if (yyss + yystacksize - 1 <= yyssp)
  1488.     {
  1489.       /* Get the current used size of the three stacks, in elements.  */
  1490.       YYSIZE_T yysize = yyssp - yyss + 1;
  1491.  
  1492. #ifdef yyoverflow
  1493.       {
  1494.     /* Give user a chance to reallocate the stack.  Use copies of
  1495.        these so that the &'s don't force the real ones into
  1496.        memory.  */
  1497.     YYSTYPE *yyvs1 = yyvs;
  1498.     yytype_int16 *yyss1 = yyss;
  1499.     YYLTYPE *yyls1 = yyls;
  1500.  
  1501.     /* Each stack pointer address is followed by the size of the
  1502.        data in use in that stack, in bytes.  This used to be a
  1503.        conditional around just the two extra args, but that might
  1504.        be undefined if yyoverflow is a macro.  */
  1505.     yyoverflow (YY_("memory exhausted"),
  1506.             &yyss1, yysize * sizeof (*yyssp),
  1507.             &yyvs1, yysize * sizeof (*yyvsp),
  1508.             &yyls1, yysize * sizeof (*yylsp),
  1509.             &yystacksize);
  1510.     yyls = yyls1;
  1511.     yyss = yyss1;
  1512.     yyvs = yyvs1;
  1513.       }
  1514. #else /* no yyoverflow */
  1515. # ifndef YYSTACK_RELOCATE
  1516.       goto yyexhaustedlab;
  1517. # else
  1518.       /* Extend the stack our own way.  */
  1519.       if (YYMAXDEPTH <= yystacksize)
  1520.     goto yyexhaustedlab;
  1521.       yystacksize *= 2;
  1522.       if (YYMAXDEPTH < yystacksize)
  1523.     yystacksize = YYMAXDEPTH;
  1524.  
  1525.       {
  1526.     yytype_int16 *yyss1 = yyss;
  1527.     union yyalloc *yyptr =
  1528.       (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  1529.     if (! yyptr)
  1530.       goto yyexhaustedlab;
  1531.     YYSTACK_RELOCATE (yyss);
  1532.     YYSTACK_RELOCATE (yyvs);
  1533.     YYSTACK_RELOCATE (yyls);
  1534. #  undef YYSTACK_RELOCATE
  1535.     if (yyss1 != yyssa)
  1536.       YYSTACK_FREE (yyss1);
  1537.       }
  1538. # endif
  1539. #endif /* no yyoverflow */
  1540.  
  1541.       yyssp = yyss + yysize - 1;
  1542.       yyvsp = yyvs + yysize - 1;
  1543.       yylsp = yyls + yysize - 1;
  1544.  
  1545.       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  1546.           (unsigned long int) yystacksize));
  1547.  
  1548.       if (yyss + yystacksize - 1 <= yyssp)
  1549.     YYABORT;
  1550.     }
  1551.  
  1552.   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1553.  
  1554.   goto yybackup;
  1555.  
  1556. /*-----------.
  1557. | yybackup.  |
  1558. `-----------*/
  1559. yybackup:
  1560.  
  1561.   /* Do appropriate processing given the current state.  Read a
  1562.      look-ahead token if we need one and don't already have one.  */
  1563.  
  1564.   /* First try to decide what to do without reference to look-ahead token.  */
  1565.   yyn = yypact[yystate];
  1566.   if (yyn == YYPACT_NINF)
  1567.     goto yydefault;
  1568.  
  1569.   /* Not known => get a look-ahead token if don't already have one.  */
  1570.  
  1571.   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
  1572.   if (yychar == YYEMPTY)
  1573.     {
  1574.       YYDPRINTF ((stderr, "Reading a token: "));
  1575.       yychar = YYLEX;
  1576.     }
  1577.  
  1578.   if (yychar <= YYEOF)
  1579.     {
  1580.       yychar = yytoken = YYEOF;
  1581.       YYDPRINTF ((stderr, "Now at end of input.\n"));
  1582.     }
  1583.   else
  1584.     {
  1585.       yytoken = YYTRANSLATE (yychar);
  1586.       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1587.     }
  1588.  
  1589.   /* If the proper action on seeing token YYTOKEN is to reduce or to
  1590.      detect an error, take that action.  */
  1591.   yyn += yytoken;
  1592.   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1593.     goto yydefault;
  1594.   yyn = yytable[yyn];
  1595.   if (yyn <= 0)
  1596.     {
  1597.       if (yyn == 0 || yyn == YYTABLE_NINF)
  1598.     goto yyerrlab;
  1599.       yyn = -yyn;
  1600.       goto yyreduce;
  1601.     }
  1602.  
  1603.   if (yyn == YYFINAL)
  1604.     YYACCEPT;
  1605.  
  1606.   /* Count tokens shifted since error; after three, turn off error
  1607.      status.  */
  1608.   if (yyerrstatus)
  1609.     yyerrstatus--;
  1610.  
  1611.   /* Shift the look-ahead token.  */
  1612.   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1613.  
  1614.   /* Discard the shifted token unless it is eof.  */
  1615.   if (yychar != YYEOF)
  1616.     yychar = YYEMPTY;
  1617.  
  1618.   yystate = yyn;
  1619.   *++yyvsp = yylval;
  1620.   *++yylsp = yylloc;
  1621.   goto yynewstate;
  1622.  
  1623.  
  1624. /*-----------------------------------------------------------.
  1625. | yydefault -- do the default action for the current state.  |
  1626. `-----------------------------------------------------------*/
  1627. yydefault:
  1628.   yyn = yydefact[yystate];
  1629.   if (yyn == 0)
  1630.     goto yyerrlab;
  1631.   goto yyreduce;
  1632.  
  1633.  
  1634. /*-----------------------------.
  1635. | yyreduce -- Do a reduction.  |
  1636. `-----------------------------*/
  1637. yyreduce:
  1638.   /* yyn is the number of a rule to reduce with.  */
  1639.   yylen = yyr2[yyn];
  1640.  
  1641.   /* If YYLEN is nonzero, implement the default value of the action:
  1642.      `$$ = $1'.
  1643.  
  1644.      Otherwise, the following line sets YYVAL to garbage.
  1645.      This behavior is undocumented and Bison
  1646.      users should not rely upon it.  Assigning to YYVAL
  1647.      unconditionally makes the parser a bit smaller, and it avoids a
  1648.      GCC warning that YYVAL may be used uninitialized.  */
  1649.   yyval = yyvsp[1-yylen];
  1650.  
  1651.   /* Default location.  */
  1652.   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  1653.   YY_REDUCE_PRINT (yyn);
  1654.   switch (yyn)
  1655.     {
  1656.         case 12:
  1657. #line 237 "/usr/tmp/cost_parse.y"
  1658.     {
  1659.   cur_pic = NULL;
  1660. ;}
  1661.     break;
  1662.  
  1663.   case 13:
  1664. #line 241 "/usr/tmp/cost_parse.y"
  1665.     {
  1666.   cur_limb = NULL;
  1667. ;}
  1668.     break;
  1669.  
  1670.   case 14:
  1671. #line 245 "/usr/tmp/cost_parse.y"
  1672.     {
  1673.   cur_anim = NULL;
  1674. ;}
  1675.     break;
  1676.  
  1677.   case 15:
  1678. #line 251 "/usr/tmp/cost_parse.y"
  1679.     {
  1680.   // check that the pic have an image
  1681.   if(!cur_pic->path)
  1682.     COST_ABORT((yylsp[(1) - (5)]),"Picture %s has no path defined.\n",
  1683.                cur_pic->name);
  1684.   
  1685.   if(cur_pic->is_glob) {
  1686.     glob_t gl;
  1687.     int n,nlen = strlen(cur_pic->name);
  1688.     char name[nlen+16];
  1689.     cost_pic_t* p;
  1690.     
  1691.     // expand the glob
  1692.     if(glob(cur_pic->path,0,NULL,&gl))
  1693.       COST_ABORT((yylsp[(1) - (5)]),"Glob pattern error: %s\n",cur_pic->path);
  1694.     if(!gl.gl_pathc)
  1695.       COST_ABORT((yylsp[(1) - (5)]),"Glob pattern didn't match anything: %s\n",cur_pic->path);
  1696.     
  1697.     // detach the current pic from the list
  1698.     if(pic_list == cur_pic)
  1699.       pic_list = cur_pic->next;
  1700.     else {
  1701.       for(p = pic_list ; p && p->next != cur_pic ; p = p->next);
  1702.       if(!p) COST_ABORT((yylsp[(1) - (5)]),"Internal error: failed to find current pic in pic list.\n");
  1703.       p->next = cur_pic->next;
  1704.     }
  1705.     cur_pic->next = NULL;
  1706.     
  1707.     // create the new pictures
  1708.     for(n = 0 ; n < gl.gl_pathc ; n++) {
  1709.       sprintf(name,"%s%02d",cur_pic->name,n);
  1710.       p = find_pic(name);
  1711.       if(p) {
  1712.         if(p->path)
  1713.           COST_ABORT((yylsp[(1) - (5)]),"Glob expansion failed: %s is already defined\n",name);
  1714.       } else {
  1715.         p = calloc(1,sizeof(cost_pic_t));
  1716.         p->name = strdup(name);
  1717.       }
  1718.       // load it up
  1719.       p->path = strdup(gl.gl_pathv[n]);
  1720.       if(!cost_pic_load(p,p->path))
  1721.         COST_ABORT((yylsp[(1) - (5)]),"Failed to load %s.\n",p->path);
  1722.       // copy the position, etc
  1723.       p->rel_x = cur_pic->rel_x;
  1724.       p->rel_y = cur_pic->rel_y;
  1725.       p->move_x = cur_pic->move_x;
  1726.       p->move_y = cur_pic->move_y;
  1727.       
  1728.       // append it to the list
  1729.       p->next = pic_list;
  1730.       pic_list = p;
  1731.     }
  1732.     
  1733.     // free the cur_pic
  1734.     free(cur_pic->name);
  1735.     free(cur_pic->path);
  1736.     free(cur_pic);
  1737.     globfree(&gl);
  1738.   } else {  
  1739.     // load it up
  1740.     if(!cost_pic_load(cur_pic,cur_pic->path))
  1741.       COST_ABORT((yylsp[(1) - (5)]),"Failed to load %s.\n",cur_pic->path);
  1742.   }
  1743.  
  1744.   cur_pic = NULL;
  1745. ;}
  1746.     break;
  1747.  
  1748.   case 16:
  1749. #line 321 "/usr/tmp/cost_parse.y"
  1750.     {
  1751.   cost_pic_t* p = find_pic((yyvsp[(2) - (2)].str));
  1752.  
  1753.   // alloc the pic
  1754.   if(!p) {
  1755.     p = calloc(1,sizeof(cost_pic_t));
  1756.     p->name = (yyvsp[(2) - (2)].str);
  1757.     p->next = pic_list;
  1758.     pic_list = p;
  1759.   } else
  1760.     free((yyvsp[(2) - (2)].str));
  1761.   // set it as the current pic
  1762.   cur_pic = p;
  1763. ;}
  1764.     break;
  1765.  
  1766.   case 19:
  1767. #line 342 "/usr/tmp/cost_parse.y"
  1768.     {
  1769.   if(cur_pic->path)
  1770.     COST_ABORT((yylsp[(1) - (3)]),"This picture already has a path defined.\n");
  1771.  
  1772.   if(img_path)
  1773.     asprintf(&cur_pic->path,"%s/%s",img_path,(yyvsp[(3) - (3)].str));
  1774.   else
  1775.     cur_pic->path = (yyvsp[(3) - (3)].str);
  1776. ;}
  1777.     break;
  1778.  
  1779.   case 20:
  1780. #line 352 "/usr/tmp/cost_parse.y"
  1781.     {
  1782.   if(cur_pic->path)
  1783.     COST_ABORT((yylsp[(1) - (3)]),"This picture already has a path defined.\n");
  1784.  
  1785.   if(cur_pic->ref)
  1786.     COST_ABORT((yylsp[(1) - (3)]),"This picture has already been referenced, we can't expand it to a glob anymore.\n");
  1787.  
  1788.   if(img_path)
  1789.     asprintf(&cur_pic->path,"%s/%s",img_path,(yyvsp[(3) - (3)].str));
  1790.   else
  1791.     cur_pic->path = (yyvsp[(3) - (3)].str);
  1792.   cur_pic->is_glob = 1;
  1793. ;}
  1794.     break;
  1795.  
  1796.   case 21:
  1797. #line 366 "/usr/tmp/cost_parse.y"
  1798.     {
  1799.   cur_pic->rel_x = (yyvsp[(3) - (3)].intpair)[0];
  1800.   cur_pic->rel_y = (yyvsp[(3) - (3)].intpair)[1];
  1801. ;}
  1802.     break;
  1803.  
  1804.   case 22:
  1805. #line 371 "/usr/tmp/cost_parse.y"
  1806.     {
  1807.   cur_pic->move_x = (yyvsp[(3) - (3)].intpair)[0];
  1808.   cur_pic->move_y = (yyvsp[(3) - (3)].intpair)[1];
  1809. ;}
  1810.     break;
  1811.  
  1812.   case 24:
  1813. #line 382 "/usr/tmp/cost_parse.y"
  1814.     {
  1815.   int n;
  1816.  
  1817.   if((yyvsp[(3) - (3)].integer) >= 0) {
  1818.     // valid index ??
  1819.     if((yyvsp[(3) - (3)].integer) >= COST_MAX_LIMBS)
  1820.       COST_ABORT((yylsp[(3) - (3)]),"Limb index %d is invalid. Costumes can only have up to %d limbs.\n",
  1821.                  (yyvsp[(3) - (3)].integer),COST_MAX_LIMBS);
  1822.     n = (yyvsp[(3) - (3)].integer);
  1823.     // name mismatch ???
  1824.     if(limbs[n].name && strcmp(limbs[n].name,(yyvsp[(2) - (3)].str)))
  1825.        COST_ABORT((yylsp[(3) - (3)]),"Limb %d is already defined with the name %s.\n",
  1826.                   n,limbs[n].name);
  1827.   } else {
  1828.     // look if there a limb with that name
  1829.     for(n = 0 ; n < COST_MAX_LIMBS ; n++) {
  1830.       if(!limbs[n].name) continue;
  1831.       if(!strcmp(limbs[n].name,(yyvsp[(2) - (3)].str))) break;
  1832.     }
  1833.     // no limb with that name then look for a free index
  1834.     if(n == COST_MAX_LIMBS) {
  1835.       for(n = 0 ; n < COST_MAX_LIMBS ; n++)
  1836.         if(!limbs[n].name) break;
  1837.       if(n == COST_MAX_LIMBS)
  1838.         COST_ABORT((yylsp[(1) - (3)]),"Too many limbs defined. Costumes can only have up to %d limbs.\n",
  1839.                    COST_MAX_LIMBS);
  1840.     }
  1841.   }
  1842.  
  1843.   // alloc it
  1844.   if(!limbs[n].name)
  1845.     limbs[n].name = strdup((yyvsp[(2) - (3)].str));
  1846.  
  1847.   cur_limb = &limbs[n];
  1848. ;}
  1849.     break;
  1850.  
  1851.   case 25:
  1852. #line 420 "/usr/tmp/cost_parse.y"
  1853.     {
  1854.   cost_pic_t* p = find_pic((yyvsp[(1) - (1)].str));
  1855.  
  1856.   if(!p)
  1857.     COST_ABORT((yylsp[(1) - (1)]),"There is no picture named %s.\n",(yyvsp[(1) - (1)].str));
  1858.     
  1859.   cur_limb->pic[0] = p;
  1860.   cur_limb->num_pic = 1;
  1861.   p->ref++;
  1862. ;}
  1863.     break;
  1864.  
  1865.   case 26:
  1866. #line 431 "/usr/tmp/cost_parse.y"
  1867.     {
  1868.   cost_pic_t* p = find_pic((yyvsp[(3) - (3)].str));
  1869.  
  1870.   if(!p)
  1871.     COST_ABORT((yylsp[(3) - (3)]),"There is no picture named %s.\n",(yyvsp[(3) - (3)].str));
  1872.  
  1873.   if(cur_limb->num_pic >= LIMB_MAX_PICTURES)
  1874.     COST_ABORT((yylsp[(3) - (3)]),"Too many pictures in limb. A limb can only have up to %d pictures.\n",
  1875.                LIMB_MAX_PICTURES);
  1876.  
  1877.   cur_limb->pic[cur_limb->num_pic] = p;
  1878.   cur_limb->num_pic++;
  1879.   p->ref++;
  1880. ;}
  1881.     break;
  1882.  
  1883.   case 27:
  1884. #line 449 "/usr/tmp/cost_parse.y"
  1885.     {
  1886.   cur_anim = NULL;
  1887. ;}
  1888.     break;
  1889.  
  1890.   case 28:
  1891. #line 455 "/usr/tmp/cost_parse.y"
  1892.     {
  1893.   int n;
  1894.  
  1895.   if((yyvsp[(3) - (3)].integer) >= 0) {
  1896.     // valid index ??
  1897.     if((yyvsp[(3) - (3)].integer) >= COST_MAX_ANIMS)
  1898.       COST_ABORT((yylsp[(3) - (3)]),"Anim index %d is invalid. Costumes can only have up to %d anims.\n",
  1899.                  (yyvsp[(3) - (3)].integer),COST_MAX_ANIMS);
  1900.     n = (yyvsp[(3) - (3)].integer);
  1901.     // name mismatch ???
  1902.     if(anims[n].name && strcmp(anims[n].name,(yyvsp[(2) - (3)].str)))
  1903.        COST_ABORT((yylsp[(3) - (3)]),"Anim %d is already defined with the name %s.\n",
  1904.                   n,anims[n].name);
  1905.   } else {
  1906.     // look if there a anim with that name
  1907.     for(n = 0 ; n < COST_MAX_ANIMS ; n++) {
  1908.       if(!anims[n].name) continue;
  1909.       if(!strcmp(anims[n].name,(yyvsp[(2) - (3)].str))) break;
  1910.     }
  1911.     // no anim with that name then look for a free index
  1912.     if(n == COST_MAX_ANIMS) {
  1913.       // look if it's a predefined name
  1914.       for(n = 0 ; anim_map[n].name ; n++)
  1915.         if(!strcmp(anim_map[n].name,(yyvsp[(2) - (3)].str))) break;
  1916.  
  1917.       if(anim_map[n].name) n = anim_map[n].id;
  1918.       else {
  1919.         for(n = ANIM_USER_START ; n < COST_MAX_ANIMS ; n++)
  1920.           if(!anims[n].name) break;
  1921.         if(n == COST_MAX_ANIMS)
  1922.           COST_ABORT((yylsp[(1) - (3)]),"Too many anims defined. Costumes can only have up to %d anims.\n",
  1923.                      COST_MAX_ANIMS);
  1924.       }
  1925.     }
  1926.   }
  1927.  
  1928.   // alloc it
  1929.   if(!anims[n].name)
  1930.     anims[n].name = strdup((yyvsp[(2) - (3)].str));
  1931.  
  1932.   cur_anim = &anims[n];
  1933.  
  1934. ;}
  1935.     break;
  1936.  
  1937.   case 32:
  1938. #line 508 "/usr/tmp/cost_parse.y"
  1939.     {
  1940.   int n;
  1941.   for(n = 0 ; dir_map[n].name ; n++)
  1942.     if(!strcmp(dir_map[n].name,(yyvsp[(1) - (1)].str))) break;
  1943.  
  1944.   if(!dir_map[n].name)
  1945.     COST_ABORT((yylsp[(1) - (1)]),"Bad direction name.\n");
  1946.  
  1947.   cur_dir = cur_anim->dir+dir_map[n].id;
  1948. ;}
  1949.     break;
  1950.  
  1951.   case 35:
  1952. #line 525 "/usr/tmp/cost_parse.y"
  1953.     {
  1954.   int n;
  1955.   // find the limb
  1956.   for(n = 0 ; n < COST_MAX_LIMBS ; n++)
  1957.     if(limbs[n].name && !strcmp(limbs[n].name,(yyvsp[(1) - (5)].str))) break;
  1958.   if(n == COST_MAX_LIMBS)
  1959.     COST_ABORT((yylsp[(1) - (5)]),"There is no limb named %s.\n",(yyvsp[(1) - (5)].str));
  1960.  
  1961.   if((yyvsp[(3) - (5)].intlist)[0] > COST_MAX_LIMB_CMDS)
  1962.     COST_ABORT((yylsp[(3) - (5)]),"Too many commands. A limb anim can have only %d commands.\n",
  1963.                COST_MAX_LIMB_CMDS);
  1964.  
  1965.   if(cur_dir->limb_mask & (1 << n))
  1966.     COST_ABORT((yylsp[(1) - (5)]),"Anim for limb %s is already defined.\n",
  1967.                limbs[n].name);
  1968.  
  1969.   cur_dir->limb_mask |= (1 << n);
  1970.   cur_dir->limb[n].len = (yyvsp[(3) - (5)].intlist)[0];
  1971.   cur_dir->limb[n].flags |=  (yyvsp[(5) - (5)].intpair)[0];
  1972.   cur_dir->limb[n].flags &= ~(yyvsp[(5) - (5)].intpair)[1];
  1973.   memcpy(cur_dir->limb[n].cmd,(yyvsp[(3) - (5)].intlist)+1,(yyvsp[(3) - (5)].intlist)[0]);
  1974.   free((yyvsp[(3) - (5)].intlist));
  1975. ;}
  1976.     break;
  1977.  
  1978.   case 36:
  1979. #line 549 "/usr/tmp/cost_parse.y"
  1980.     {
  1981.   int n;
  1982.   // find the limb
  1983.   for(n = 0 ; n < COST_MAX_LIMBS ; n++)
  1984.     if(limbs[n].name && !strcmp(limbs[n].name,(yyvsp[(1) - (4)].str))) break;
  1985.   if(n == COST_MAX_LIMBS)
  1986.     COST_ABORT((yylsp[(1) - (4)]),"There is no limb named %s.\n",(yyvsp[(1) - (4)].str));
  1987.  
  1988.   if(cur_dir->limb_mask & (1 << n))
  1989.     COST_ABORT((yylsp[(1) - (4)]),"Anim for limb %s is already defined.\n",
  1990.                limbs[n].name);
  1991.   cur_dir->limb_mask |= (1 << n);
  1992.   cur_dir->limb[n].flags |=  (yyvsp[(4) - (4)].intpair)[0];
  1993.   cur_dir->limb[n].flags &= ~(yyvsp[(4) - (4)].intpair)[1];
  1994. ;}
  1995.     break;
  1996.  
  1997.   case 38:
  1998. #line 568 "/usr/tmp/cost_parse.y"
  1999.     {
  2000.   int l = (yyvsp[(1) - (3)].intlist)[0] + (yyvsp[(3) - (3)].intlist)[0];
  2001.  
  2002.   (yyval.intlist) = realloc((yyvsp[(1) - (3)].intlist),l+1);
  2003.   memcpy((yyval.intlist)+(yyval.intlist)[0]+1,(yyvsp[(3) - (3)].intlist)+1,(yyvsp[(3) - (3)].intlist)[0]);
  2004.   (yyval.intlist)[0] = l;
  2005.   free((yyvsp[(3) - (3)].intlist));
  2006. ;}
  2007.     break;
  2008.  
  2009.   case 40:
  2010. #line 580 "/usr/tmp/cost_parse.y"
  2011.     {
  2012.   (yyval.intlist) = malloc(2);
  2013.   (yyval.intlist)[0] = 1;
  2014.   (yyval.intlist)[1] = COST_CMD_START;
  2015. ;}
  2016.     break;
  2017.  
  2018.   case 41:
  2019. #line 586 "/usr/tmp/cost_parse.y"
  2020.     {
  2021.   (yyval.intlist) = malloc(2);
  2022.   (yyval.intlist)[0] = 1;
  2023.   (yyval.intlist)[1] = COST_CMD_STOP;
  2024. ;}
  2025.     break;
  2026.  
  2027.   case 42:
  2028. #line 592 "/usr/tmp/cost_parse.y"
  2029.     {
  2030.   (yyval.intlist) = malloc(2);
  2031.   (yyval.intlist)[0] = 1;
  2032.   (yyval.intlist)[1] = COST_CMD_HIDE;
  2033. ;}
  2034.     break;
  2035.  
  2036.   case 43:
  2037. #line 598 "/usr/tmp/cost_parse.y"
  2038.     {
  2039.   (yyval.intlist) = malloc(2);
  2040.   (yyval.intlist)[0] = 1;
  2041.   (yyval.intlist)[1] = COST_CMD_SKIP;
  2042. ;}
  2043.     break;
  2044.  
  2045.   case 44:
  2046. #line 604 "/usr/tmp/cost_parse.y"
  2047.     {
  2048.   if((yyvsp[(3) - (4)].integer) < 1 || (yyvsp[(3) - (4)].integer) > 8)
  2049.     COST_ABORT((yylsp[(3) - (4)]),"Invalid costume sound index: %d.\n",(yyvsp[(3) - (4)].integer));
  2050.   
  2051.   (yyval.intlist) = malloc(2);
  2052.   (yyval.intlist)[0] = 1;
  2053.   (yyval.intlist)[1] = COST_CMD_SOUND + (yyvsp[(3) - (4)].integer);
  2054. ;}
  2055.     break;
  2056.  
  2057.   case 45:
  2058. #line 615 "/usr/tmp/cost_parse.y"
  2059.     {
  2060.   if((yyvsp[(3) - (5)].intlist)[0] != 16 &&
  2061.      (yyvsp[(3) - (5)].intlist)[0] != 32)
  2062.     COST_ABORT((yylsp[(1) - (5)]),"Invalid palette size. Must be 16 or 32.\n");
  2063.   pal_size = (yyvsp[(3) - (5)].intlist)[0];
  2064.   memcpy(pal,(yyvsp[(3) - (5)].intlist)+1,pal_size);
  2065.   free((yyvsp[(3) - (5)].intlist));
  2066. ;}
  2067.     break;
  2068.  
  2069.   case 47:
  2070. #line 627 "/usr/tmp/cost_parse.y"
  2071.     {
  2072.   int l = (yyvsp[(1) - (3)].intlist)[0] + (yyvsp[(3) - (3)].intlist)[0];
  2073.  
  2074.   (yyval.intlist) = realloc((yyvsp[(1) - (3)].intlist),l+1);
  2075.   memcpy((yyval.intlist)+(yyval.intlist)[0]+1,(yyvsp[(3) - (3)].intlist)+1,(yyvsp[(3) - (3)].intlist)[0]);
  2076.   (yyval.intlist)[0] = l;
  2077.   free((yyvsp[(3) - (3)].intlist));
  2078. ;}
  2079.     break;
  2080.  
  2081.   case 48:
  2082. #line 638 "/usr/tmp/cost_parse.y"
  2083.     {
  2084.   if((yyvsp[(1) - (1)].integer) < 0 || (yyvsp[(1) - (1)].integer) > 255)
  2085.     COST_ABORT((yylsp[(1) - (1)]),"List items can't be greater than 255.\n");
  2086.  
  2087.   (yyval.intlist) = malloc(2);
  2088.   (yyval.intlist)[0] = 1;
  2089.   (yyval.intlist)[1] = (yyvsp[(1) - (1)].integer);
  2090. ;}
  2091.     break;
  2092.  
  2093.   case 49:
  2094. #line 647 "/usr/tmp/cost_parse.y"
  2095.     {
  2096.   int i,s,l = (yyvsp[(4) - (5)].integer)-(yyvsp[(2) - (5)].integer)+1;
  2097.  
  2098.   if((yyvsp[(2) - (5)].integer) < 0 || (yyvsp[(2) - (5)].integer) > 255)
  2099.     COST_ABORT((yylsp[(2) - (5)]),"List items can't be greater than 255.\n");
  2100.   if((yyvsp[(4) - (5)].integer) < 0 || (yyvsp[(4) - (5)].integer) > 255)
  2101.     COST_ABORT((yylsp[(4) - (5)]),"List items can't be greater than 255.\n");
  2102.  
  2103.   if((yyvsp[(4) - (5)].integer) >= (yyvsp[(2) - (5)].integer))
  2104.     l = (yyvsp[(4) - (5)].integer)-(yyvsp[(2) - (5)].integer)+1, s = 1;
  2105.   else
  2106.     l = (yyvsp[(2) - (5)].integer)-(yyvsp[(4) - (5)].integer)+1, s = -1;
  2107.     
  2108.   (yyval.intlist) = malloc(l+1);
  2109.   (yyval.intlist)[0] = l;
  2110.   for(i = 0 ; i < l ; i++)
  2111.     (yyval.intlist)[i+1] = (yyvsp[(2) - (5)].integer)+s*i;
  2112. ;}
  2113.     break;
  2114.  
  2115.   case 51:
  2116. #line 669 "/usr/tmp/cost_parse.y"
  2117.     {
  2118.   cost_flags |=  (yyvsp[(3) - (4)].intpair)[0];
  2119.   cost_flags &= ~(yyvsp[(3) - (4)].intpair)[1];
  2120. ;}
  2121.     break;
  2122.  
  2123.   case 52:
  2124. #line 676 "/usr/tmp/cost_parse.y"
  2125.     {
  2126.   (yyval.intpair)[0] = 0;
  2127.   (yyval.intpair)[1] = 0;
  2128. ;}
  2129.     break;
  2130.  
  2131.   case 55:
  2132. #line 685 "/usr/tmp/cost_parse.y"
  2133.     {
  2134.   (yyval.intpair)[0] |= (yyvsp[(3) - (3)].intpair)[0];
  2135.   (yyval.intpair)[1] |= (yyvsp[(3) - (3)].intpair)[1];
  2136. ;}
  2137.     break;
  2138.  
  2139.   case 56:
  2140. #line 692 "/usr/tmp/cost_parse.y"
  2141.     {
  2142.   (yyval.intpair)[0] = (yyvsp[(1) - (1)].intpair)[0];
  2143.   (yyval.intpair)[1] = (yyvsp[(1) - (1)].intpair)[1];
  2144. ;}
  2145.     break;
  2146.  
  2147.   case 57:
  2148. #line 697 "/usr/tmp/cost_parse.y"
  2149.     {
  2150.   (yyval.intpair)[0] = (yyvsp[(2) - (2)].intpair)[1];
  2151.   (yyval.intpair)[1] = (yyvsp[(2) - (2)].intpair)[0];
  2152. ;}
  2153.     break;
  2154.  
  2155.   case 58:
  2156. #line 704 "/usr/tmp/cost_parse.y"
  2157.     {
  2158.   (yyval.intpair)[0] = 0;
  2159.   (yyval.intpair)[1] = 0x80;
  2160. ;}
  2161.     break;
  2162.  
  2163.   case 59:
  2164. #line 709 "/usr/tmp/cost_parse.y"
  2165.     {
  2166.   (yyval.intpair)[0] = 0;
  2167.   (yyval.intpair)[1] = 0x80;
  2168. ;}
  2169.     break;
  2170.  
  2171.   case 60:
  2172. #line 716 "/usr/tmp/cost_parse.y"
  2173.     {
  2174.   (yyval.intpair)[0] = (yyvsp[(2) - (5)].integer);
  2175.   (yyval.intpair)[1] = (yyvsp[(4) - (5)].integer);
  2176. ;}
  2177.     break;
  2178.  
  2179.   case 62:
  2180. #line 724 "/usr/tmp/cost_parse.y"
  2181.     {
  2182.   (yyval.integer) = - (yyvsp[(2) - (2)].integer);
  2183. ;}
  2184.     break;
  2185.  
  2186.   case 63:
  2187. #line 728 "/usr/tmp/cost_parse.y"
  2188.     {
  2189.   (yyval.integer) = (yyvsp[(2) - (2)].integer);
  2190. ;}
  2191.     break;
  2192.  
  2193.   case 64:
  2194. #line 734 "/usr/tmp/cost_parse.y"
  2195.     {
  2196.   (yyval.integer) = -1;
  2197. ;}
  2198.     break;
  2199.  
  2200.   case 65:
  2201. #line 738 "/usr/tmp/cost_parse.y"
  2202.     {
  2203.   (yyval.integer) = (yyvsp[(2) - (2)].integer);
  2204. ;}
  2205.     break;
  2206.  
  2207.  
  2208. /* Line 1267 of yacc.c.  */
  2209. #line 2210 "cost_parse.tab.c"
  2210.       default: break;
  2211.     }
  2212.   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  2213.  
  2214.   YYPOPSTACK (yylen);
  2215.   yylen = 0;
  2216.   YY_STACK_PRINT (yyss, yyssp);
  2217.  
  2218.   *++yyvsp = yyval;
  2219.   *++yylsp = yyloc;
  2220.  
  2221.   /* Now `shift' the result of the reduction.  Determine what state
  2222.      that goes to, based on the state we popped back to and the rule
  2223.      number reduced by.  */
  2224.  
  2225.   yyn = yyr1[yyn];
  2226.  
  2227.   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  2228.   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  2229.     yystate = yytable[yystate];
  2230.   else
  2231.     yystate = yydefgoto[yyn - YYNTOKENS];
  2232.  
  2233.   goto yynewstate;
  2234.  
  2235.  
  2236. /*------------------------------------.
  2237. | yyerrlab -- here on detecting error |
  2238. `------------------------------------*/
  2239. yyerrlab:
  2240.   /* If not already recovering from an error, report this error.  */
  2241.   if (!yyerrstatus)
  2242.     {
  2243.       ++yynerrs;
  2244. #if ! YYERROR_VERBOSE
  2245.       yyerror (YY_("syntax error"));
  2246. #else
  2247.       {
  2248.     YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
  2249.     if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
  2250.       {
  2251.         YYSIZE_T yyalloc = 2 * yysize;
  2252.         if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
  2253.           yyalloc = YYSTACK_ALLOC_MAXIMUM;
  2254.         if (yymsg != yymsgbuf)
  2255.           YYSTACK_FREE (yymsg);
  2256.         yymsg = (char *) YYSTACK_ALLOC (yyalloc);
  2257.         if (yymsg)
  2258.           yymsg_alloc = yyalloc;
  2259.         else
  2260.           {
  2261.         yymsg = yymsgbuf;
  2262.         yymsg_alloc = sizeof yymsgbuf;
  2263.           }
  2264.       }
  2265.  
  2266.     if (0 < yysize && yysize <= yymsg_alloc)
  2267.       {
  2268.         (void) yysyntax_error (yymsg, yystate, yychar);
  2269.         yyerror (yymsg);
  2270.       }
  2271.     else
  2272.       {
  2273.         yyerror (YY_("syntax error"));
  2274.         if (yysize != 0)
  2275.           goto yyexhaustedlab;
  2276.       }
  2277.       }
  2278. #endif
  2279.     }
  2280.  
  2281.   yyerror_range[0] = yylloc;
  2282.  
  2283.   if (yyerrstatus == 3)
  2284.     {
  2285.       /* If just tried and failed to reuse look-ahead token after an
  2286.      error, discard it.  */
  2287.  
  2288.       if (yychar <= YYEOF)
  2289.     {
  2290.       /* Return failure if at end of input.  */
  2291.       if (yychar == YYEOF)
  2292.         YYABORT;
  2293.     }
  2294.       else
  2295.     {
  2296.       yydestruct ("Error: discarding",
  2297.               yytoken, &yylval, &yylloc);
  2298.       yychar = YYEMPTY;
  2299.     }
  2300.     }
  2301.  
  2302.   /* Else will try to reuse look-ahead token after shifting the error
  2303.      token.  */
  2304.   goto yyerrlab1;
  2305.  
  2306.  
  2307. /*---------------------------------------------------.
  2308. | yyerrorlab -- error raised explicitly by YYERROR.  |
  2309. `---------------------------------------------------*/
  2310. yyerrorlab:
  2311.  
  2312.   /* Pacify compilers like GCC when the user code never invokes
  2313.      YYERROR and the label yyerrorlab therefore never appears in user
  2314.      code.  */
  2315.   if (/*CONSTCOND*/ 0)
  2316.      goto yyerrorlab;
  2317.  
  2318.   yyerror_range[0] = yylsp[1-yylen];
  2319.   /* Do not reclaim the symbols of the rule which action triggered
  2320.      this YYERROR.  */
  2321.   YYPOPSTACK (yylen);
  2322.   yylen = 0;
  2323.   YY_STACK_PRINT (yyss, yyssp);
  2324.   yystate = *yyssp;
  2325.   goto yyerrlab1;
  2326.  
  2327.  
  2328. /*-------------------------------------------------------------.
  2329. | yyerrlab1 -- common code for both syntax error and YYERROR.  |
  2330. `-------------------------------------------------------------*/
  2331. yyerrlab1:
  2332.   yyerrstatus = 3;    /* Each real token shifted decrements this.  */
  2333.  
  2334.   for (;;)
  2335.     {
  2336.       yyn = yypact[yystate];
  2337.       if (yyn != YYPACT_NINF)
  2338.     {
  2339.       yyn += YYTERROR;
  2340.       if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  2341.         {
  2342.           yyn = yytable[yyn];
  2343.           if (0 < yyn)
  2344.         break;
  2345.         }
  2346.     }
  2347.  
  2348.       /* Pop the current state because it cannot handle the error token.  */
  2349.       if (yyssp == yyss)
  2350.     YYABORT;
  2351.  
  2352.       yyerror_range[0] = *yylsp;
  2353.       yydestruct ("Error: popping",
  2354.           yystos[yystate], yyvsp, yylsp);
  2355.       YYPOPSTACK (1);
  2356.       yystate = *yyssp;
  2357.       YY_STACK_PRINT (yyss, yyssp);
  2358.     }
  2359.  
  2360.   if (yyn == YYFINAL)
  2361.     YYACCEPT;
  2362.  
  2363.   *++yyvsp = yylval;
  2364.  
  2365.   yyerror_range[1] = yylloc;
  2366.   /* Using YYLLOC is tempting, but would change the location of
  2367.      the look-ahead.  YYLOC is available though.  */
  2368.   YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
  2369.   *++yylsp = yyloc;
  2370.  
  2371.   /* Shift the error token.  */
  2372.   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  2373.  
  2374.   yystate = yyn;
  2375.   goto yynewstate;
  2376.  
  2377.  
  2378. /*-------------------------------------.
  2379. | yyacceptlab -- YYACCEPT comes here.  |
  2380. `-------------------------------------*/
  2381. yyacceptlab:
  2382.   yyresult = 0;
  2383.   goto yyreturn;
  2384.  
  2385. /*-----------------------------------.
  2386. | yyabortlab -- YYABORT comes here.  |
  2387. `-----------------------------------*/
  2388. yyabortlab:
  2389.   yyresult = 1;
  2390.   goto yyreturn;
  2391.  
  2392. #ifndef yyoverflow
  2393. /*-------------------------------------------------.
  2394. | yyexhaustedlab -- memory exhaustion comes here.  |
  2395. `-------------------------------------------------*/
  2396. yyexhaustedlab:
  2397.   yyerror (YY_("memory exhausted"));
  2398.   yyresult = 2;
  2399.   /* Fall through.  */
  2400. #endif
  2401.  
  2402. yyreturn:
  2403.   if (yychar != YYEOF && yychar != YYEMPTY)
  2404.      yydestruct ("Cleanup: discarding lookahead",
  2405.          yytoken, &yylval, &yylloc);
  2406.   /* Do not reclaim the symbols of the rule which action triggered
  2407.      this YYABORT or YYACCEPT.  */
  2408.   YYPOPSTACK (yylen);
  2409.   YY_STACK_PRINT (yyss, yyssp);
  2410.   while (yyssp != yyss)
  2411.     {
  2412.       yydestruct ("Cleanup: popping",
  2413.           yystos[*yyssp], yyvsp, yylsp);
  2414.       YYPOPSTACK (1);
  2415.     }
  2416. #ifndef yyoverflow
  2417.   if (yyss != yyssa)
  2418.     YYSTACK_FREE (yyss);
  2419. #endif
  2420. #if YYERROR_VERBOSE
  2421.   if (yymsg != yymsgbuf)
  2422.     YYSTACK_FREE (yymsg);
  2423. #endif
  2424.   /* Make sure YYID is used.  */
  2425.   return YYID (yyresult);
  2426. }
  2427.  
  2428.  
  2429. #line 743 "/usr/tmp/cost_parse.y"
  2430.  
  2431.  
  2432. // load an image and encode it with the strange vertical RLE
  2433. static int cost_pic_load(cost_pic_t* pic,char* file) {  
  2434.   scc_img_t* img = scc_img_open(file);
  2435.   int color,rep,shr,max_rep,x,y;
  2436.   uint8_t* dst;
  2437.  
  2438.   if(!img) return 0;
  2439.  
  2440.   if(img->ncol != pal_size)
  2441.     printf("Warning, image %s doesn't have the same number of colors as the palette: %d != %d.\n",file,img->ncol,pal_size);
  2442.  
  2443.   pic->width = img->w;
  2444.   pic->height = img->h;
  2445.  
  2446.   // encode the pic
  2447.   // alloc enouth mem for the worst case
  2448.   dst = pic->data = malloc(img->w*img->h);
  2449.  
  2450.   // set the params
  2451.   switch(pal_size) {
  2452.   case 16:
  2453.     shr = 4;
  2454.     max_rep = 0x0F;
  2455.     break;
  2456.   case 32:
  2457.     shr = 3;
  2458.     max_rep = 0x07;
  2459.     break;
  2460.   }
  2461.  
  2462.   // take the initial color
  2463.   color = img->data[0];
  2464.   if(color >= pal_size) color = pal_size-1;
  2465.   rep = 0;
  2466.   for(x = 0 ; x < img->w ; x++)
  2467.     for(y = 0 ; y < img->h ; y++) {
  2468.       if(rep < 255 && // can repeat ??
  2469.          img->data[y*img->w+x] == color) {
  2470.         rep++;
  2471.         continue;
  2472.       }
  2473.       // write the repetition
  2474.       if(rep > max_rep) {
  2475.         pic->data[pic->data_size] = (color << shr);
  2476.         pic->data_size++;
  2477.         pic->data[pic->data_size] = rep;
  2478.         pic->data_size++;
  2479.       } else {
  2480.         pic->data[pic->data_size] = (color << shr) | rep;
  2481.         pic->data_size++;
  2482.       }
  2483.  
  2484.       color = img->data[y*img->w+x];
  2485.       if(color >= pal_size) color = pal_size-1;
  2486.       rep = 1;
  2487.     }
  2488.   // write the last repetition
  2489.   if(rep > 0) {
  2490.     if(rep > max_rep) {
  2491.       pic->data[pic->data_size] = (color << shr);
  2492.       pic->data_size++;
  2493.       pic->data[pic->data_size] = rep;
  2494.       pic->data_size++;
  2495.     } else {
  2496.       pic->data[pic->data_size] = (color << shr) | rep;
  2497.       pic->data_size++;
  2498.     }
  2499.   }
  2500.  
  2501.   if(pic->data_size < img->w*img->h)
  2502.     pic->data = realloc(pic->data,pic->data_size);
  2503.  
  2504.   scc_img_free(img);
  2505.   return 1;
  2506. }
  2507.  
  2508. // compute the whole size of the costume
  2509. static int cost_get_size(int *na,unsigned* coff,unsigned* aoff,unsigned* loff) {
  2510.   cost_pic_t* p;
  2511.   int i,j,num_anim,clen = 0;
  2512.   int size = 4 + // size
  2513.     2 + // header
  2514.     1 + // num anim
  2515.     1 + // format
  2516.     pal_size + // palette
  2517.     2 + // cmds offset
  2518.     2*16; // limbs offset
  2519.     
  2520.   // get the highest anim id
  2521.   for(i = COST_MAX_ANIMS-1 ; i >= 0 ; i--)
  2522.     if(anims[i].name) break;
  2523.   num_anim = i+1;
  2524.  
  2525.   size += 2*COST_MAX_DIR*num_anim; // anim offsets
  2526.  
  2527.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) {
  2528.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2529.     if(aoff) {
  2530.       if(anim->limb_mask)
  2531.         aoff[i] = size-clen;
  2532.       else
  2533.         aoff[i] = 0;
  2534.     }
  2535.     size += 2; // limb mask
  2536.     if(!anim->limb_mask) continue;
  2537.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2538.       if(!(anim->limb_mask & (1 << j))) continue;
  2539.       if(anim->limb[j].len) {
  2540.         size += 2 + 1 + anim->limb[j].len; // limb start/len + cmds
  2541.         clen += anim->limb[j].len;
  2542.       } else
  2543.         size += 2;
  2544.     }
  2545.   }
  2546.   if(coff) coff[0] = size-clen;
  2547.  
  2548.   // limbs table
  2549.   for(i = COST_MAX_LIMBS-1 ; i >= 0 ; i--) {
  2550.     if(loff) {
  2551.       if(limbs[i].num_pic > 0)
  2552.         loff[i] = size;
  2553.       else
  2554.         loff[i] = 0;
  2555.     }
  2556.     size += 2*limbs[i].num_pic;
  2557.   }
  2558.     
  2559.   // pictures
  2560.   //  for(p = pic_list ; p ; p = p->next)
  2561.   for(i = COST_MAX_LIMBS-1 ; i >= 0 ; i--) // pictures
  2562.     for(j = 0 ; j < limbs[i].num_pic ; j++) {
  2563.       if(!(p = limbs[i].pic[j])) continue;
  2564.       if(p->ref && !p->offset) {
  2565.         p->offset = size;
  2566.         size += p->data_size + 6*2;
  2567.       }
  2568.     }
  2569.  
  2570.   na[0] = num_anim;
  2571.   return size;
  2572. }
  2573.  
  2574. static int cost_write(scc_fd_t* fd) {
  2575.   int size,num_anim,i,j,pad = 0;
  2576.   cost_pic_t* p;
  2577.   uint8_t fmt = 0x58 | cost_flags;
  2578.   unsigned coff,cpos = 0;
  2579.   unsigned aoff[COST_MAX_ANIMS*COST_MAX_DIR];
  2580.   unsigned loff[COST_MAX_LIMBS];
  2581.  
  2582.   if(pal_size == 32) fmt |= 1;
  2583.  
  2584.   size = cost_get_size(&num_anim,&coff,aoff,loff);
  2585.  
  2586.   // round up to next 2 multiple
  2587.   if(size & 1) {
  2588.     size++;
  2589.     pad = 1;
  2590.   }
  2591.  
  2592.   scc_fd_w32(fd,MKID('C','O','S','T'));
  2593.   scc_fd_w32be(fd,size+8);
  2594.  
  2595.  
  2596.   scc_fd_w32le(fd,size);  // size
  2597.  
  2598.   scc_fd_w8(fd,'C'); // header
  2599.   scc_fd_w8(fd,'O');
  2600.  
  2601.   scc_fd_w8(fd,num_anim*COST_MAX_DIR-1); // last anim
  2602.  
  2603.   scc_fd_w8(fd,fmt); // format
  2604.  
  2605.   scc_fd_write(fd,pal,pal_size); // palette
  2606.  
  2607.   scc_fd_w16le(fd,coff); // cmd offset
  2608.  
  2609.   for(i = COST_MAX_LIMBS-1 ; i >= 0 ; i--) // limbs offset
  2610.     scc_fd_w16le(fd,loff[i]);
  2611.  
  2612.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) // anim offsets
  2613.     scc_fd_w16le(fd,aoff[i]);
  2614.  
  2615.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) { // anims
  2616.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2617.     scc_fd_w16le(fd,anim->limb_mask); // limb mask
  2618.     if(!anim->limb_mask) continue;
  2619.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2620.       if(!(anim->limb_mask & (1 << j))) continue;
  2621.       if(anim->limb[j].len) {
  2622.         scc_fd_w16le(fd,cpos);  // cmd start
  2623.         cpos += anim->limb[j].len;
  2624.         // last cmd offset
  2625.         scc_fd_w8(fd,((anim->limb[j].len-1)&0x7F) |
  2626.                     (anim->limb[j].flags&0x80));
  2627.       } else
  2628.         scc_fd_w16le(fd,0xFFFF); // stoped limb
  2629.     }
  2630.   }
  2631.  
  2632.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) { // anim cmds
  2633.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2634.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2635.       if(!anim->limb[j].len ) continue;
  2636.       scc_fd_write(fd,anim->limb[j].cmd,anim->limb[j].len);
  2637.     }
  2638.   }
  2639.  
  2640.   for(i = COST_MAX_LIMBS-1 ; i >= 0 ; i--)  // limbs
  2641.     for(j = 0 ; j < limbs[i].num_pic ; j++) {
  2642.       if(limbs[i].pic[j]) scc_fd_w16le(fd,limbs[i].pic[j]->offset);
  2643.       else scc_fd_w16le(fd,0);
  2644.     }
  2645.  
  2646.   // i would prefer to just go along the list,
  2647.   // but that should give results closer to the original.
  2648.   for(i = COST_MAX_LIMBS-1 ; i >= 0 ; i--) // pictures
  2649.     for(j = 0 ; j < limbs[i].num_pic ; j++) {
  2650.       if(!(p = limbs[i].pic[j])) continue;
  2651.       if(!p->ref) continue;
  2652.       if(!p->width || !p->height) printf("Bad pic?\n");
  2653.       //printf("Write pic: %dx%d\n",p->width,p->height);
  2654.       scc_fd_w16le(fd,p->width);
  2655.       scc_fd_w16le(fd,p->height);
  2656.       scc_fd_w16le(fd,p->rel_x);
  2657.       scc_fd_w16le(fd,p->rel_y);
  2658.       scc_fd_w16le(fd,p->move_x);
  2659.       scc_fd_w16le(fd,p->move_y);
  2660.       scc_fd_write(fd,p->data,p->data_size);
  2661.       p->ref = 0;
  2662.     }
  2663.  
  2664.   if(pad) scc_fd_w8(fd,0);
  2665.  
  2666.   return 1;
  2667. }
  2668.  
  2669.  
  2670. static int akos_write(scc_fd_t* fd) {
  2671.   int akhd_size = 8 + 2 + 1 + 1 + 2 + 2 + 2;
  2672.   int akpl_size = 8 + pal_size;
  2673.   int aksq_size = 8;
  2674.   int akch_size = 8;
  2675.   int akof_size = 8;
  2676.   int akci_size = 8;
  2677.   int akcd_size = 8;
  2678.   int akos_size;
  2679.   int i,j,d;
  2680.   int cpos = 0;
  2681.   int aoff[COST_MAX_DIR*COST_MAX_ANIMS];
  2682.   cost_pic_t* pic;
  2683.   int num_anim = 0, num_pic = 0;
  2684.   int data_off = 0, header_off = 0;
  2685.  
  2686.  
  2687.   // get the highest anim id
  2688.   for(i = COST_MAX_ANIMS-1 ; i >= 0 ; i--)
  2689.     if(anims[i].name) break;
  2690.   num_anim = i+1;
  2691.  
  2692.   // Compute the number of picture and setup the ids
  2693.   for(pic = pic_list ; pic ; pic = pic->next) {
  2694.     if(!pic->ref) continue;
  2695.     pic->idx = num_pic;
  2696.     num_pic++;
  2697.   }
  2698.  
  2699.   // Compute the size needed for all commands
  2700.   for(i = 0 ; i < num_anim ; i++)
  2701.     for(d = 0 ; d < COST_MAX_DIR ; d++)
  2702.       for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--)
  2703.         aksq_size += anims[i].dir[d].limb[j].len;
  2704.  
  2705.   // Compute the size needed for the anim definitions
  2706.   akch_size += 2*COST_MAX_DIR*num_anim;
  2707.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) {
  2708.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2709.     if(!anim->limb_mask) {
  2710.       aoff[i] = 0;
  2711.       continue;
  2712.     }
  2713.     aoff[i] = akch_size-8;
  2714.     akch_size += 2;
  2715.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2716.       if(!(anim->limb_mask & (1 << j))) continue;
  2717.       akch_size += 1 + 2 + 2;
  2718.     }
  2719.   }
  2720.  
  2721.   akof_size += (4 + 2)*num_pic;
  2722.  
  2723.   akci_size += (2+2 + 2+2 + 2+2)*num_pic;
  2724.  
  2725.   // Compute the size needed for the picture data
  2726.   for(pic = pic_list ; pic ; pic = pic->next) {
  2727.     if(!pic->ref) continue;
  2728.     akcd_size += pic->data_size;
  2729.   }
  2730.  
  2731.   akos_size = 8 + akhd_size + akpl_size + aksq_size +
  2732.     akch_size + akof_size + akci_size + akcd_size;
  2733.  
  2734.   scc_fd_w32(fd,MKID('A','K','O','S'));
  2735.   scc_fd_w32be(fd,akos_size);
  2736.  
  2737.   // Write the header
  2738.   scc_fd_w32(fd,MKID('A','K','H','D'));
  2739.   scc_fd_w32be(fd,akhd_size);
  2740.   // Version ?
  2741.   scc_fd_w16le(fd,0x0001);
  2742.   // Flags
  2743.   scc_fd_w8(fd,cost_flags>>7);
  2744.   // Unknown
  2745.   scc_fd_w8(fd,0x80);
  2746.   // Num anim
  2747.   scc_fd_w16le(fd,num_anim*COST_MAX_DIR);
  2748.   // Num frame
  2749.   scc_fd_w16le(fd,num_pic);
  2750.   // Codec
  2751.   scc_fd_w16le(fd,1);
  2752.  
  2753.   // Write the palette
  2754.   scc_fd_w32(fd,MKID('A','K','P','L'));
  2755.   scc_fd_w32be(fd,akpl_size);
  2756.   scc_fd_write(fd,pal,pal_size);
  2757.  
  2758.   // Write the commands, a bit tricky because
  2759.   // need to relocate the picture id from limb picture
  2760.   // to global picture.
  2761.   scc_fd_w32(fd,MKID('A','K','S','Q'));
  2762.   scc_fd_w32be(fd,aksq_size);
  2763.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) {
  2764.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2765.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2766.       int c;
  2767.       for(c = 0 ; c < anim->limb[j].len ; c++) {
  2768.         int cmd = anim->limb[j].cmd[c];
  2769.         // Ignore high id atm, that include commands
  2770.         if(cmd >= 0x80) {
  2771.           scc_fd_w8(fd,cmd), c++;
  2772.           scc_fd_w8(fd,anim->limb[j].cmd[c]);
  2773.           continue;
  2774.         }
  2775.         if(cmd >= limbs[j].num_pic ||
  2776.            !limbs[j].pic[cmd]) {
  2777.           printf("Warning: Bad picture index in anim %s, "
  2778.                  "limb %s at %d: %d\n",
  2779.                  anims[i/COST_MAX_DIR].name,limbs[j].name,c,cmd);
  2780.           scc_fd_w8(fd,0);
  2781.         } else
  2782.           scc_fd_w8(fd,limbs[j].pic[cmd]->idx);
  2783.       }
  2784.     }
  2785.   }
  2786.  
  2787.   // Write the anims
  2788.   scc_fd_w32(fd,MKID('A','K','C','H'));
  2789.   scc_fd_w32be(fd,akch_size);
  2790.   // offsets
  2791.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++)
  2792.     scc_fd_w16le(fd,aoff[i]);
  2793.   // definitions
  2794.   for(i = 0 ; i < num_anim*COST_MAX_DIR ; i++) {
  2795.     cost_anim_dir_t* anim = &anims[i/COST_MAX_DIR].dir[i%COST_MAX_DIR];
  2796.     if(!anim->limb_mask) continue;
  2797.     // limb mask
  2798.     scc_fd_w16le(fd,anim->limb_mask);
  2799.     for(j = COST_MAX_LIMBS-1 ; j >= 0 ; j--) {
  2800.       if(!(anim->limb_mask & (1 << j))) continue;
  2801.       // mode
  2802.       scc_fd_w8(fd,(anim->limb[j].flags&0x80) ? 0x03 : 0x02);
  2803.       // cmd start
  2804.       scc_fd_w16le(fd,cpos);
  2805.       cpos += anim->limb[j].len;
  2806.       // len
  2807.       scc_fd_w16le(fd,anim->limb[j].len-1);
  2808.     }
  2809.   }
  2810.  
  2811.   // Write the offset table
  2812.   scc_fd_w32(fd,MKID('A','K','O','F'));
  2813.   scc_fd_w32be(fd,akof_size);
  2814.   for(pic = pic_list ; pic ; pic = pic->next) {
  2815.     if(!pic->ref) continue;
  2816.     // Data offset
  2817.     scc_fd_w32le(fd,data_off);
  2818.     data_off += pic->data_size;
  2819.     // Header offset
  2820.     scc_fd_w16le(fd,header_off);
  2821.     header_off += 2+2 + 2+2 + 2+2;
  2822.   }
  2823.  
  2824.   // Write the pic headers
  2825.   scc_fd_w32(fd,MKID('A','K','C','I'));
  2826.   scc_fd_w32be(fd,akci_size);
  2827.   for(pic = pic_list ; pic ; pic = pic->next) {
  2828.     if(!pic->ref) continue;
  2829.     // width / height
  2830.     scc_fd_w16le(fd,pic->width);
  2831.     scc_fd_w16le(fd,pic->height);
  2832.     scc_fd_w16le(fd,pic->rel_x);
  2833.     scc_fd_w16le(fd,pic->rel_y);
  2834.     scc_fd_w16le(fd,pic->move_x);
  2835.     scc_fd_w16le(fd,pic->move_y);
  2836.   }
  2837.  
  2838.   // Write the pic data
  2839.   scc_fd_w32(fd,MKID('A','K','C','D'));
  2840.   scc_fd_w32be(fd,akcd_size);
  2841.   for(pic = pic_list ; pic ; pic = pic->next) {
  2842.     if(!pic->ref) continue;
  2843.     scc_fd_write(fd,pic->data,pic->data_size);
  2844.   }
  2845.  
  2846.   return 1;
  2847. }
  2848.  
  2849. static int header_write(scc_fd_t* fd,char *prefix) {
  2850.   int i;
  2851.   scc_fd_printf(fd,"/* This file was generated do not edit */\n\n");
  2852.   for(i = 0 ; i < COST_MAX_ANIMS ; i++) {
  2853.     if(!anims[i].name) continue;
  2854.     scc_fd_printf(fd,"#define %s%s %d\n",prefix,anims[i].name,i);
  2855.   }
  2856.   return 1;
  2857. }
  2858.  
  2859. static scc_lex_t* cost_lex;
  2860. extern int cost_main_lexer(YYSTYPE *lvalp, YYLTYPE *llocp,scc_lex_t* lex);
  2861.  
  2862. static void set_start_pos(YYLTYPE *llocp,int line,int column) {
  2863.   llocp->first_line = line+1;
  2864.   llocp->first_column = column;
  2865. }
  2866.  
  2867. static void set_end_pos(YYLTYPE *llocp,int line,int column) {
  2868.   llocp->last_line = line+1;
  2869.   llocp->last_column = column;
  2870. }
  2871.  
  2872. int yylex(void) {
  2873.   return scc_lex_lex(&yylval,&yylloc,cost_lex);
  2874. }
  2875.  
  2876. int yyerror (const char *s)  /* Called by yyparse on error */
  2877. {
  2878.   scc_log(LOG_ERR,"%s: %s\n",scc_lex_get_file(cost_lex),
  2879.           cost_lex->error ? cost_lex->error : s);
  2880.   return 0;
  2881. }
  2882.  
  2883. static scc_param_t scc_parse_params[] = {
  2884.   { "o", SCC_PARAM_STR, 0, 0, &cost_output },
  2885.   { "I", SCC_PARAM_STR, 0, 0, &img_path },
  2886.   { "akos", SCC_PARAM_FLAG, 0, 1, &akos },
  2887.   { "prefix", SCC_PARAM_STR, 0, 0, &symbol_prefix },
  2888.   { "header", SCC_PARAM_STR, 0, 0, &header_name },
  2889.   { "help", SCC_PARAM_HELP, 0, 0, &cost_help },
  2890.   { NULL, 0, 0, 0, NULL }
  2891. };
  2892.  
  2893. int main (int argc, char** argv) {
  2894.   scc_cl_arg_t* files;
  2895.   char* out;
  2896.  
  2897.   files = scc_param_parse_argv(scc_parse_params,argc-1,&argv[1]);
  2898.  
  2899.   if(!files) scc_print_help(&cost_help,1);
  2900.  
  2901.   out = cost_output ? cost_output : "output.cost";
  2902.   out_fd = new_scc_fd(out,O_WRONLY|O_CREAT|O_TRUNC,0);
  2903.   if(!out_fd) {
  2904.     printf("Failed to open output file %s.\n",out);
  2905.     return -1;
  2906.   }
  2907.  
  2908.   cost_lex = scc_lex_new(cost_main_lexer,set_start_pos,set_end_pos,NULL);
  2909.   if(!scc_lex_push_buffer(cost_lex,files->val)) return -1;
  2910.  
  2911.   if(yyparse()) return -1;
  2912.  
  2913.   if(akos)
  2914.     akos_write(out_fd);
  2915.   else
  2916.     cost_write(out_fd);
  2917.  
  2918.   scc_fd_close(out_fd);
  2919.  
  2920.   if(header_name) {
  2921.     out_fd = new_scc_fd(header_name,O_WRONLY|O_CREAT|O_TRUNC,0);
  2922.     if(!out_fd) {
  2923.       printf("Failed to open output file %s.\n",out);
  2924.       return -1;
  2925.     }
  2926.     header_write(out_fd,symbol_prefix);
  2927.     scc_fd_close(out_fd);
  2928.   }
  2929.  
  2930.   return 0;
  2931. }
  2932.  
  2933.