Changeset 5522 for trunk/tools


Ignore:
Timestamp:
Apr 16, 2001, 7:11:03 PM (24 years ago)
Author:
sandervl
Message:

updates

Location:
trunk/tools/wrc
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/wrc/Makefile.in

    r882 r5522  
    44SRCDIR    = @srcdir@
    55VPATH     = @srcdir@
     6LEXOPT    = -Cf #-w -b
     7YACCOPT   = #-v
    68
    7 PROGRAMS = wrc@PROGEXT@
     9PROGRAMS = wrc
    810MODULE   = none
    911
     
    1820        writeres.c
    1921
     22GEN_C_SRCS = ppy.tab.c lex.ppl.c
    2023EXTRA_SRCS = parser.y parser.l
    2124EXTRA_OBJS = y.tab.o lex.yy.o
     
    2326all: $(PROGRAMS)
    2427
    25 depend:: y.tab.h
    26 
    2728@MAKE_RULES@
    2829
    29 wrc@PROGEXT@: $(OBJS)
    30         $(CC) $(CFLAGS) -o wrc@PROGEXT@ $(OBJS) $(LEXLIB)
     30wrc: $(OBJS) $(TOPOBJDIR)/unicode/libwine_unicode.$(LIBEXT)
     31        $(CC) $(CFLAGS) -o wrc $(OBJS) $(LIBUNICODE) $(LEXLIB) $(LDFLAGS)
     32
     33$(TOPOBJDIR)/unicode/libwine_unicode.$(LIBEXT):
     34        cd `dirname $@` && $(MAKE) `basename $@`
    3135
    3236y.tab.c y.tab.h: parser.y
    33         $(YACC) -d -t $(SRCDIR)/parser.y
     37        $(YACC) $(YACCOPT) -d -t $(SRCDIR)/parser.y
     38
     39ppy.tab.c ppy.tab.h: ppy.y
     40        $(YACC) $(YACCOPT) -bppy -ppp -d -t $(SRCDIR)/ppy.y
    3441
    3542lex.yy.c: parser.l
    36         $(LEX) -8 $(SRCDIR)/parser.l
     43        $(LEX) $(LEXOPT) -d -8 $(SRCDIR)/parser.l
     44
     45lex.ppl.c: ppl.l
     46        $(LEX) $(LEXOPT) -d -Ppp -8 -olex.ppl.c $(SRCDIR)/ppl.l
    3747
    3848clean::
    39         $(RM) y.tab.c y.tab.h lex.yy.c
     49        $(RM) ppy.tab.h ppy.output parser.output parser.tab.h lex.backup y.output
     50
     51install:: $(PROGRAMS)
     52        [ -d $(bindir) ] || $(MKDIR) $(bindir)
     53        [ -d $(mandir)/man$(prog_manext) ] || $(MKDIR) $(mandir)/man$(prog_manext)
     54        $(INSTALL_DATA) $(SRCDIR)/wrc.man $(mandir)/man$(prog_manext)/wrc.$(prog_manext)
     55        $(INSTALL_PROGRAM) wrc $(bindir)/wrc
     56
     57uninstall::
     58        $(RM) $(bindir)/wrc $(mandir)/man$(prog_manext)/wrc.$(prog_manext)
    4059
    4160### Dependencies:
  • trunk/tools/wrc/README.wrc

    r882 r5522  
    1 Release 1.0.2 of wrc (20-Jun-1998), the wine resource compiler.
     1Release 1.1.8 of wrc (24-Aug-2000), the wine resource compiler.
    22
    33See the file CHANGES for differences between the version and what has been
     
    66Wrc features:
    77
    8 - source preprocessing
     8- full source preprocessing
    99- 16 and 32 bit support
    1010- LANGUAGE support (32 bit only)
    11 - almost all resource types are supported
     11- most resource types are supported
    1212- enhanced expression capabilities and resource naming
    1313- indirect loadable resources
    1414- NE/PE resource directory generation
    1515- binary .res file generation/reading
     16- byte-order conversions
    1617
    1718Wrc generates an assembly file that can be assembled with GNU's gas, or
     
    3536   -D id[=val] Define preprocessor identifier id=val
    3637   -e          Disable recognition of win32 keywords in 16bit compile
     38   -E          Preprocess only
    3739   -g          Add symbols to the global c namespace
    3840   -h          Also generate a .h file
    3941   -H file     Same as -h but written to file
    4042   -I path     Set include search dir to path (multiple -I allowed)
    41    -l lan      Set default language to lan (default is neutral {0})
     43   -l lan      Set default language to lan (default is neutral {0, 0})
    4244   -L          Leave case of embedded filenames as is
     45   -m          Do not remap numerical resource IDs
    4346   -n          Do not generate .s file
     47   -N          Do not preprocess input
    4448   -o file     Output to file (default is infile.[res|s|h]
    4549   -p prefix   Give a prefix for the generated names
     
    5862    * 0x02 Dump internal structures
    5963    * 0x04 Create a parser trace (yydebug=1)
     64    * 0x08 Preprocessor messages
     65    * 0x10 Preprocessor lex messages
     66    * 0x20 Preprocessor yacc trace
    6067
    6168The -o option only applies to the final destination file, which is
     
    6572with -o and/or -H, then the output is written to "wrc.tab.[sh]"
    6673
     74For more info see the wrc manpage.
     75
    6776
    6877Preprocessing
    6978-------------
    70 The build-in preprocessor is not a full implementation of the C counterpart.
    71 Wrc does not understand function-type macros. These are discarded as they
    72 are scanned. This will be a future project. Wrc does understand these:
    73 #define
     79The preprocessor is a fully operational C preprocessor. It handles all
     80directives supported by ANSI-C. It also includes some additions from
     81gcc/egcs.
     82Wrc understands these directives:
     83#define         (both simple and macro)
     84#undef
    7485#if
    7586#ifdef
     
    7990#endif
    8091#error
    81 
    82 Also 'defined' is supported as operator (both with and without parenthesis).
    83 '#if' expressions can be anything valid that evaluates to an integer
    84 expression (where 0 is false and anything else is true). Others (#pragma,
    85 #line) are ignored. A special case '#' generates an error. This is due to
    86 the implementation to enable generation of errors on preprocessing and will
    87 be improved in the future.
     92#warning
     93#line
     94#
     95#pragma         (ignored)
     96#ident          (ignored)
     97
     98The extensions include '#'-line directives.
     99Not handled at the moment are variable argument macros. They are parsed,
     100but not expanded properly. This will be corrected in the future.
     101
     102The preprocessor handles the special defines and aditionally defines an
     103extra set of defines:
     104  Define       | Value         | Comment
     105---------------+---------------+---------------
     106RC_INVOKED     | 1             | Always defined
     107__FLAT__       | 1             | Only defined if win32 compile
     108__WIN32__      | 1             | Only defined if win32 compile
     109__FILE__       | "..."         | Current filename as string
     110__LINE__       | nnn           | Current linenumber as integer
     111__TIME__       | "23:59:59"    | Timestring of compilation
     112__DATE__       | "May  1 2000" | Datestring of compilation
     113__WRC__        | 1             | Wrc's major version
     114__WRC_MINOR__  | 1             | Wrc's minor version
     115__WRC_MICRO__  | 7             | Wrc's minor version
     116__WRC_PATCH__  | 8             | Alias of __WRC_MICRO__
     117
     118Include-files are not read twice if they are protected with this scheme:
     119#ifndef SOME_DEFINE
     120#define SOME_DEFINE
     121...
     122#endif
     123This strategy has been borrowed from gcc/egcs and results in significantly
     124reduced preprocessing times (20..30%). There must not be any junk before
     125the first #ifndef and not after the last #endif; comments and whitespace
     126excepted. Wrc will check the existance of the define prior to inclusion to
     127detect "#undef SOME_DEFINE" (notably poppack.h) and act accordingly.
    88128
    89129
     
    106146compiler runs on.
    107147
    108 Not all resource-types can have local language keywords attached yet
    109 (notably: BITMAP, CURSOR, ICON and usertype). This is due to implementation
    110 of filename-scanning and the complexity that it poses. This will be changed
    111 in the next release. You can work arround this problem by putting a LANGUAGE
    112 statement before (and evt. after) the code in the resource file.
     148Language, version and characteristics can be bound to all resource types that
     149have inline data, such as RCDATA. This is an extension to MS' resource
     150compiler, which lacks this support completely. Only VERSIONINFO cannot have
     151version and characteristics attached, but languages are propagated properly if
     152you declare it correctly before the VERSIONINFO resource starts.
     153
     154Example:
     155
     1561 RCDATA DISCARDABLE
     157LANGUAGE 1, 0
     158VERSION 312
     159CHARACTERISTICS 876
     160{
     161        1, 2, 3, 4, 5, "and whatever more data you want"
     162        '00 01 02 03 04 05 06 07 08'
     163}
    113164
    114165
     
    116167------------------------
    117168All types are supported except for:
    118 - FONT
    119 - MESSAGETABLE
    120 - extensions like TOOLBAR and the like (is this a user-type?)
     169- RT_VXD
     170- RT_PLUGPLAY
     171- RT_HTML
     172- RT_DLGINCLUDE
    121173
    122174These types will be implemented as soon as I get a proper specification of
    123175the layout.
    124176
    125 Note: Usertype resources with character strings as types have a different
    126 layout and do not accept expressions when a numerical type is specified. The
    127 must be enclosed in double quotes. These are examples of valid usertype
    128 resources:
    129 
    130 MyName "MyType" mydata.bin
    131 MyName 12345    mydata.bin
    132 MyName "MyType" "mydata.bin"
    133 MyName 12345    "mydata.bin"
    134 
    135 MyName "MyType"
    136 {
    137   ..., data, ...
    138 }
    139 
    140 or
    141 
    142 MyName 12345
    143 {
    144  ..., data, ...
    145 }
     177Font type resources (RT_FONT, RT_FONTDIR) are partially supported and will
     178be enhanced when I have the complete spec. The font resources work only if
     179you supply the FONTDIR resource yourself.
    146180
    147181
     
    153187*       multiply
    154188/       divide
    155 +       add
     189+       plus/add
    156190-       minus/substract
    157191|       binary or
     
    160194NOT     ... (sigh)
    161195
    162 Minus (-) can both be unary and binary. The NOT operator is (primarily)
    163 used to disable window styles but I strongly suggest to refrain from using
    164 this operator.
    165 There is a shift/reduce conflict on the unary minus, but this is not
    166 problematic. I was too lazy to make a new expression parser (next version or
    167 so). Unary plus (+) would cause another confilct, so I let it out for now.
     196Plus (+) and minus (-) can both be unary and binary. The NOT operator is
     197(primarily) used to disable window styles but I strongly suggest to refrain
     198from using this operator.
    168199
    169200Resource names can be both numerical (expressions) and character typed. Wrc
    170 does supports this insane (deep sigh) construct:
     201does support this insane (deep sigh) construct:
    171202
    172203MENU MENU
     
    248279- No codepage translation
    249280- UNICODE translations are not/not correct implemented
    250 - No documentation ('wrc -?' gives command-line options though)
     281- No documentation ('wrc -?' gives command-line options and a manpage)
    251282- grep for FIXME in the source
    252283- Memory options are wrong under some conditions. There seems to be a
    253   different action for win32 and win16.
    254 - User-type resources have slightly different layout.
    255 - Filename scanning is still hopeless.
     284  different action for win32 and win16
     285- PUSHBOX control is unsupported. The MS docs use it plenty, but neither
     286  MS' nor Borland's compiler supports it.
    256287
    257288Reporting bugs and patches
  • trunk/tools/wrc/dumpres.c

    r3426 r5522  
    4747        case res_dlginit: return "DLGINIT";
    4848        case res_toolbar: return "TOOLBAR";
     49        case res_anicur:  return "CURSOR (animated)";
     50        case res_aniico:  return "ICON (animated)";
    4951        default:        return "Unknown";
    5052        }
     
    153155 *****************************************************************************
    154156*/
    155 void dump_memopt(DWORD memopt)
     157static void dump_memopt(DWORD memopt)
    156158{
    157159        printf("Memory/load options: ");
     
    184186 *****************************************************************************
    185187*/
    186 void dump_lvc(lvc_t *l)
     188static void dump_lvc(lvc_t *l)
    187189{
    188190        if(l->language)
     
    213215 *****************************************************************************
    214216*/
    215 void dump_raw_data(raw_data_t *d)
    216 {
    217         int n;
     217static void dump_raw_data(raw_data_t *d)
     218{
     219        unsigned int n;
    218220        int i;
    219221        int j;
     
    236238                                printf("- ");
    237239                                for(i = 0; i < 16; i++)
    238                                         printf("%c", isprint(d->data[n-16+i]) ? d->data[n-16+i] : '.');
     240                                        printf("%c", isprint(d->data[n-16+i] & 0xff) ? d->data[n-16+i] : '.');
    239241                                printf("\n%08x: ", n);
    240242                        }
     
    249251                j = 16;
    250252        for(i = 0; i < j; i++)
    251                 printf("%c", isprint(d->data[n-j+i]) ? d->data[n-j+i] : '.');
     253                printf("%c", isprint(d->data[n-j+i] & 0xff) ? d->data[n-j+i] : '.');
    252254        printf("\n");
    253255}
     
    264266 *****************************************************************************
    265267*/
    266 void dump_accelerator(accelerator_t *acc)
     268static void dump_accelerator(accelerator_t *acc)
    267269{
    268270        event_t *ev = acc->events;
     
    298300 *****************************************************************************
    299301*/
    300 void dump_cursor(cursor_t *cur)
     302static void dump_cursor(cursor_t *cur)
    301303{
    302304        printf("Id: %d\n", cur->id);
     
    319321 *****************************************************************************
    320322*/
    321 void dump_cursor_group(cursor_group_t *curg)
     323static void dump_cursor_group(cursor_group_t *curg)
    322324{
    323325        dump_memopt(curg->memopt);
     
    336338 *****************************************************************************
    337339*/
    338 void dump_icon(icon_t *ico)
     340static void dump_icon(icon_t *ico)
    339341{
    340342        printf("Id: %d\n", ico->id);
     
    358360 *****************************************************************************
    359361*/
    360 void dump_icon_group(icon_group_t *icog)
     362static void dump_icon_group(icon_group_t *icog)
    361363{
    362364        dump_memopt(icog->memopt);
     
    366368/*
    367369 *****************************************************************************
     370 * Function     : dump_ani_curico
     371 * Syntax       : void dump_ani_curico(ani_curico_t *ani)
     372 * Input        :
     373 *      ani     - Animated object resource descriptor
     374 * Output       : nop
     375 * Description  :
     376 * Remarks      :
     377 *****************************************************************************
     378*/
     379static void dump_ani_curico(ani_curico_t *ani)
     380{
     381        dump_memopt(ani->memopt);
     382        dump_lvc(&ani->data->lvc);
     383        dump_raw_data(ani->data);
     384}
     385
     386/*
     387 *****************************************************************************
    368388 * Function     : dump_font
    369389 * Syntax       : void dump_font(font_t *fnt)
     
    375395 *****************************************************************************
    376396*/
    377 void dump_font(font_t *fnt)
     397static void dump_font(font_t *fnt)
    378398{
    379399        dump_memopt(fnt->memopt);
     400        dump_lvc(&(fnt->data->lvc));
    380401        dump_raw_data(fnt->data);
    381402}
     
    392413 *****************************************************************************
    393414*/
    394 void dump_bitmap(bitmap_t *bmp)
     415static void dump_bitmap(bitmap_t *bmp)
    395416{
    396417        dump_memopt(bmp->memopt);
     418        dump_lvc(&(bmp->data->lvc));
    397419        dump_raw_data(bmp->data);
    398420}
     
    409431 *****************************************************************************
    410432*/
    411 void dump_rcdata(rcdata_t *rdt)
     433static void dump_rcdata(rcdata_t *rdt)
    412434{
    413435        dump_memopt(rdt->memopt);
     436        dump_lvc(&(rdt->data->lvc));
    414437        dump_raw_data(rdt->data);
    415438}
     
    426449 *****************************************************************************
    427450*/
    428 void dump_user(user_t *usr)
     451static void dump_user(user_t *usr)
    429452{
    430453        dump_memopt(usr->memopt);
     454        dump_lvc(&(usr->data->lvc));
    431455        printf("Class %s\n", get_nameid_str(usr->type));
    432456        dump_raw_data(usr->data);
     
    444468 *****************************************************************************
    445469*/
    446 void dump_messagetable(messagetable_t *msg)
    447 {
     470static void dump_messagetable(messagetable_t *msg)
     471{
     472        dump_memopt(msg->memopt);
     473        dump_lvc(&(msg->data->lvc));
    448474        dump_raw_data(msg->data);
    449475}
     
    460486 *****************************************************************************
    461487*/
    462 void dump_stringtable(stringtable_t *stt)
     488static void dump_stringtable(stringtable_t *stt)
    463489{
    464490        int i;
     
    492518 *****************************************************************************
    493519*/
    494 void dump_control(control_t *ctrl)
     520static void dump_control(control_t *ctrl)
    495521{
    496522        printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl->ctlclass));
     
    531557 *****************************************************************************
    532558*/
    533 void dump_dialog(dialog_t *dlg)
     559static void dump_dialog(dialog_t *dlg)
    534560{
    535561        control_t *c = dlg->controls;
     
    581607 *****************************************************************************
    582608*/
    583 void dump_dialogex(dialogex_t *dlgex)
     609static void dump_dialogex(dialogex_t *dlgex)
    584610{
    585611        control_t *c = dlgex->controls;
     
    631657 *****************************************************************************
    632658*/
    633 void dump_menu_item(menu_item_t *item)
     659static void dump_menu_item(menu_item_t *item)
    634660{
    635661        while(item)
     
    669695 *****************************************************************************
    670696*/
    671 void dump_menu(menu_t *men)
     697static void dump_menu(menu_t *men)
    672698{
    673699        dump_memopt(men->memopt);
     
    686712 *****************************************************************************
    687713*/
    688 void dump_menuex_item(menuex_item_t *item)
     714static void dump_menuex_item(menuex_item_t *item)
    689715{
    690716        while(item)
     
    739765 *****************************************************************************
    740766*/
    741 void dump_menuex(menuex_t *menex)
     767static void dump_menuex(menuex_t *menex)
    742768{
    743769        dump_memopt(menex->memopt);
     
    756782 *****************************************************************************
    757783*/
    758 void dump_ver_value(ver_value_t *val)
    759 {
    760         extern void dump_ver_block(ver_block_t *);
     784static void dump_ver_block(ver_block_t *);      /* Forward ref */
     785
     786static void dump_ver_value(ver_value_t *val)
     787{
    761788        if(val->type == val_str)
    762789        {
     
    792819 *****************************************************************************
    793820*/
    794 void dump_ver_block(ver_block_t *blk)
     821static void dump_ver_block(ver_block_t *blk)
    795822{
    796823        ver_value_t *val = blk->values;
     
    817844 *****************************************************************************
    818845*/
    819 void dump_versioninfo(versioninfo_t *ver)
     846static void dump_versioninfo(versioninfo_t *ver)
    820847{
    821848        ver_block_t *blk = ver->blocks;
     849
     850        dump_lvc(&(ver->lvc));
    822851
    823852        if(ver->gotit.fv)
     
    860889 *****************************************************************************
    861890*/
    862 void dump_toolbar_items(toolbar_item_t *items)
     891static void dump_toolbar_items(toolbar_item_t *items)
    863892{
    864893        while(items)
     
    886915 *****************************************************************************
    887916*/
    888 void dump_toolbar(toolbar_t *toolbar)
     917static void dump_toolbar(toolbar_t *toolbar)
    889918{
    890919        dump_memopt(toolbar->memopt);
     
    904933 *****************************************************************************
    905934*/
    906 void dump_dlginit(dlginit_t *dit)
     935static void dump_dlginit(dlginit_t *dit)
    907936{
    908937        dump_memopt(dit->memopt);
    909         dump_lvc(&(dit->lvc));
     938        dump_lvc(&(dit->data->lvc));
    910939        dump_raw_data(dit->data);
    911940}
     
    9971026                        dump_toolbar(top->res.tbt);
    9981027                        break;
     1028                case res_anicur:
     1029                case res_aniico:
     1030                        dump_ani_curico(top->res.ani);
     1031                        break;
    9991032                default:
    10001033                        printf("Report this: Unknown resource type parsed %08x\n", top->type);
  • trunk/tools/wrc/dumpres.h

    r882 r5522  
    1515char *get_typename(resource_t* r);
    1616void dump_resources(resource_t *top);
     17char *get_nameid_str(name_id_t *n);
    1718
    1819#endif
  • trunk/tools/wrc/genres.c

    r3426 r5522  
    44 * Copyright 1998 Bertho A. Stultiens
    55 *
     6 * 05-May-2000 BS       - Added code to support endian conversions. The
     7 *                        extra functions also aid unaligned access, but
     8 *                        this is not yet implemented.
    69 * 25-May-1998 BS       - Added simple unicode -> char conversion for resource
    710 *                        names in .s and .h files. 
     
    2023#include "utils.h"
    2124#include "windef.h"
     25#include "winbase.h"
    2226#include "wingdi.h"
    2327#include "winuser.h"
    2428
    25 #define SetResSize(res, tag)    *(DWORD *)&((res)->data[(tag)]) = \
    26                                 (res)->size - *(DWORD *)&((res)->data[(tag)])
     29#define SetResSize(res, tag)    set_dword((res), (tag), (res)->size - get_dword((res), (tag)))
    2730
    2831res_t *new_res(void)
     
    6467        if(res->allocsize - res->size < sizeof(char))
    6568                grow_res(res, RES_BLOCKSIZE);
    66         *(char *)&(res->data[res->size]) = (char)c;
     69        res->data[res->size] = (char)c;
    6770        res->size += sizeof(char);
    6871}
     
    7275        if(res->allocsize - res->size < sizeof(WORD))
    7376                grow_res(res, RES_BLOCKSIZE);
    74         *(WORD *)&(res->data[res->size]) = (WORD)w;
     77        switch(byteorder)
     78        {
     79#ifdef WORDS_BIGENDIAN
     80        default:
     81#endif
     82        case WRC_BO_BIG:
     83                res->data[res->size+0] = HIBYTE(w);
     84                res->data[res->size+1] = LOBYTE(w);
     85                break;
     86
     87#ifndef WORDS_BIGENDIAN
     88        default:
     89#endif
     90        case WRC_BO_LITTLE:
     91                res->data[res->size+1] = HIBYTE(w);
     92                res->data[res->size+0] = LOBYTE(w);
     93                break;
     94        }
    7595        res->size += sizeof(WORD);
    7696}
     
    80100        if(res->allocsize - res->size < sizeof(DWORD))
    81101                grow_res(res, RES_BLOCKSIZE);
    82         *(DWORD *)&(res->data[res->size]) = (DWORD)d;
     102        switch(byteorder)
     103        {
     104#ifdef WORDS_BIGENDIAN
     105        default:
     106#endif
     107        case WRC_BO_BIG:
     108                res->data[res->size+0] = HIBYTE(HIWORD(d));
     109                res->data[res->size+1] = LOBYTE(HIWORD(d));
     110                res->data[res->size+2] = HIBYTE(LOWORD(d));
     111                res->data[res->size+3] = LOBYTE(LOWORD(d));
     112                break;
     113
     114#ifndef WORDS_BIGENDIAN
     115        default:
     116#endif
     117        case WRC_BO_LITTLE:
     118                res->data[res->size+3] = HIBYTE(HIWORD(d));
     119                res->data[res->size+2] = LOBYTE(HIWORD(d));
     120                res->data[res->size+1] = HIBYTE(LOWORD(d));
     121                res->data[res->size+0] = LOBYTE(LOWORD(d));
     122                break;
     123        }
    83124        res->size += sizeof(DWORD);
    84125}
     
    88129        while(res->size & 0x3)
    89130                put_byte(res, 0);
     131}
     132
     133/*
     134 *****************************************************************************
     135 * Function     : set_word
     136 *                set_dword
     137 * Syntax       : void set_word(res_t *res, int ofs, unsigned w)
     138 *                void set_dword(res_t *res, int ofs, unsigned d)
     139 * Input        :
     140 *      res     - Binary resource to put the data in
     141 *      ofs     - Byte offset in data-array
     142 *      w, d    - Data to put
     143 * Output       : nop
     144 * Description  : Set the value of a binary resource data array to a
     145 *                specific value.
     146 * Remarks      :
     147 *****************************************************************************
     148*/
     149void set_word(res_t *res, int ofs, unsigned w)
     150{
     151        switch(byteorder)
     152        {
     153#ifdef WORDS_BIGENDIAN
     154        default:
     155#endif
     156        case WRC_BO_BIG:
     157                res->data[ofs+0] = HIBYTE(w);
     158                res->data[ofs+1] = LOBYTE(w);
     159                break;
     160
     161#ifndef WORDS_BIGENDIAN
     162        default:
     163#endif
     164        case WRC_BO_LITTLE:
     165                res->data[ofs+1] = HIBYTE(w);
     166                res->data[ofs+0] = LOBYTE(w);
     167                break;
     168        }
     169}
     170
     171void set_dword(res_t *res, int ofs, unsigned d)
     172{
     173        switch(byteorder)
     174        {
     175#ifdef WORDS_BIGENDIAN
     176        default:
     177#endif
     178        case WRC_BO_BIG:
     179                res->data[ofs+0] = HIBYTE(HIWORD(d));
     180                res->data[ofs+1] = LOBYTE(HIWORD(d));
     181                res->data[ofs+2] = HIBYTE(LOWORD(d));
     182                res->data[ofs+3] = LOBYTE(LOWORD(d));
     183                break;
     184
     185#ifndef WORDS_BIGENDIAN
     186        default:
     187#endif
     188        case WRC_BO_LITTLE:
     189                res->data[ofs+3] = HIBYTE(HIWORD(d));
     190                res->data[ofs+2] = LOBYTE(HIWORD(d));
     191                res->data[ofs+1] = HIBYTE(LOWORD(d));
     192                res->data[ofs+0] = LOBYTE(LOWORD(d));
     193                break;
     194        }
     195}
     196
     197/*
     198 *****************************************************************************
     199 * Function     : get_word
     200 *                get_dword
     201 * Syntax       : WORD get_word(res_t *res, int ofs)
     202 *                DWORD get_dword(res_t *res, int ofs)
     203 * Input        :
     204 *      res     - Binary resource to put the data in
     205 *      ofs     - Byte offset in data-array
     206 * Output       : The data in native endian
     207 * Description  : Get the value of a binary resource data array in native
     208 *                endian.
     209 * Remarks      :
     210 *****************************************************************************
     211*/
     212WORD get_word(res_t *res, int ofs)
     213{
     214        switch(byteorder)
     215        {
     216#ifdef WORDS_BIGENDIAN
     217        default:
     218#endif
     219        case WRC_BO_BIG:
     220                return   (res->data[ofs+0] << 8)
     221                       |  res->data[ofs+1];
     222
     223#ifndef WORDS_BIGENDIAN
     224        default:
     225#endif
     226        case WRC_BO_LITTLE:
     227                return   (res->data[ofs+1] << 8)
     228                       |  res->data[ofs+0];
     229        }
     230}
     231
     232DWORD get_dword(res_t *res, int ofs)
     233{
     234        switch(byteorder)
     235        {
     236#ifdef WORDS_BIGENDIAN
     237        default:
     238#endif
     239        case WRC_BO_BIG:
     240                return   (res->data[ofs+0] << 24)
     241                       | (res->data[ofs+1] << 16)
     242                       | (res->data[ofs+2] <<  8)
     243                       |  res->data[ofs+3];
     244
     245#ifndef WORDS_BIGENDIAN
     246        default:
     247#endif
     248        case WRC_BO_LITTLE:
     249                return   (res->data[ofs+3] << 24)
     250                       | (res->data[ofs+2] << 16)
     251                       | (res->data[ofs+1] <<  8)
     252                       |  res->data[ofs+0];
     253        }
    90254}
    91255
     
    137301 *****************************************************************************
    138302*/
    139 void put_string(res_t *res, string_t *str, enum str_e type, int isterm)
     303static void put_string(res_t *res, string_t *str, enum str_e type, int isterm)
    140304{
    141305        int cnt;
     
    149313        }
    150314
     315        str = convert_string(str, type);
    151316        if(str->type == str_unicode && type == str_unicode)
    152317        {
     
    197362                        put_word(res, 0);
    198363        }
     364        free(str);
    199365}
    200366
     
    255421        else
    256422                put_dword(res, 0);
     423        if(lvc && lvc->language)
     424            set_language( lvc->language->id, lvc->language->sub );
     425        else if (currentlanguage)
     426            set_language( currentlanguage->id, currentlanguage->sub );
     427        else
     428            set_language( LANG_NEUTRAL, SUBLANG_NEUTRAL );
    257429}
    258430
     
    314486                put_word(res, memopt);          /* Memory options */
    315487                put_lvc(res, lvc);              /* Language, version and characts */
    316                 ((DWORD *)res->data)[0] = res->size;    /* Set preliminary resource */
    317                 ((DWORD *)res->data)[1] = res->size;    /* Set HeaderSize */
     488                set_dword(res, 0*sizeof(DWORD), res->size);     /* Set preliminary resource */
     489                set_dword(res, 1*sizeof(DWORD), res->size);     /* Set HeaderSize */
    318490                res->dataidx = res->size;
    319491                return 0;
     
    333505                tag = res->size;
    334506                put_dword(res, 0);              /* ResSize overwritten later*/
    335                 *(DWORD *)&(res->data[tag]) = res->size;
     507                set_dword(res, tag, res->size);
    336508                res->dataidx = res->size;
    337509                return tag;
     
    351523 *****************************************************************************
    352524*/
    353 res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
     525static res_t *accelerator2res(name_id_t *name, accelerator_t *acc)
    354526{
    355527        int restag;
     
    402574 *****************************************************************************
    403575*/
    404 res_t *dialog2res(name_id_t *name, dialog_t *dlg)
     576static res_t *dialog2res(name_id_t *name, dialog_t *dlg)
    405577{
    406578        int restag;
     
    478650                }
    479651                /* Set number of controls */
    480                 *(WORD *)&((char *)res->data)[tag_nctrl] = (WORD)nctrl;
     652                set_word(res, tag_nctrl, (WORD)nctrl);
    481653        }
    482654        else /* win16 */
     
    561733 *****************************************************************************
    562734*/
    563 res_t *dialogex2res(name_id_t *name, dialogex_t *dlgex)
     735static res_t *dialogex2res(name_id_t *name, dialogex_t *dlgex)
    564736{
    565737        int restag;
     
    654826                }
    655827                /* Set number of controls */
    656                 *(WORD *)&((char *)res->data)[tag_nctrl] = (WORD)nctrl;
     828                set_word(res, tag_nctrl, (WORD)nctrl);
    657829                /* Set ResourceSize */
    658830                SetResSize(res, restag);
     
    679851 *****************************************************************************
    680852*/
    681 void menuitem2res(res_t *res, menu_item_t *menitem)
     853static void menuitem2res(res_t *res, menu_item_t *menitem)
    682854{
    683855        menu_item_t *itm = menitem;
     
    729901 *****************************************************************************
    730902*/
    731 res_t *menu2res(name_id_t *name, menu_t *men)
     903static res_t *menu2res(name_id_t *name, menu_t *men)
    732904{
    733905        int restag;
     
    758930 *****************************************************************************
    759931*/
    760 void menuexitem2res(res_t *res, menuex_item_t *menitem)
     932static void menuexitem2res(res_t *res, menuex_item_t *menitem)
    761933{
    762934        menuex_item_t *itm = menitem;
     
    795967 *****************************************************************************
    796968*/
    797 res_t *menuex2res(name_id_t *name, menuex_t *menex)
     969static res_t *menuex2res(name_id_t *name, menuex_t *menex)
    798970{
    799971        int restag;
     
    8381010 *****************************************************************************
    8391011*/
    840 res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
     1012static res_t *cursorgroup2res(name_id_t *name, cursor_group_t *curg)
    8411013{
    8421014        int restag;
     
    9461118 *****************************************************************************
    9471119*/
    948 res_t *cursor2res(cursor_t *cur)
     1120static res_t *cursor2res(cursor_t *cur)
    9491121{
    9501122        int restag;
     
    9811153 *****************************************************************************
    9821154*/
    983 res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
     1155static res_t *icongroup2res(name_id_t *name, icon_group_t *icog)
    9841156{
    9851157        int restag;
     
    10491221 *****************************************************************************
    10501222*/
    1051 res_t *icon2res(icon_t *ico)
     1223static res_t *icon2res(icon_t *ico)
    10521224{
    10531225        int restag;
     
    10721244/*
    10731245 *****************************************************************************
     1246 * Function     : anicurico2res
     1247 * Syntax       : res_t *anicurico2res(name_id_t *name, ani_curico_t *ani)
     1248 * Input        :
     1249 *      name    - Name/ordinal of the resource
     1250 *      ani     - The animated object descriptor
     1251 * Output       : New .res format structure
     1252 * Description  :
     1253 * Remarks      : The endian of the object's structures have been converted
     1254 *                by the loader.
     1255 *                There are rumors that win311 could handle animated stuff.
     1256 *                That is why they are generated for both win16 and win32
     1257 *                compile.
     1258 *****************************************************************************
     1259*/
     1260static res_t *anicurico2res(name_id_t *name, ani_curico_t *ani, enum res_e type)
     1261{
     1262        int restag;
     1263        res_t *res;
     1264        assert(name != NULL);
     1265        assert(ani != NULL);
     1266
     1267        res = new_res();
     1268        restag = put_res_header(res, type == res_anicur ? WRC_RT_ANICURSOR : WRC_RT_ANIICON,
     1269                                NULL, name, ani->memopt, NULL);
     1270        put_raw_data(res, ani->data, 0);
     1271        /* Set ResourceSize */
     1272        SetResSize(res, restag);
     1273        if(win32)
     1274                put_pad(res);
     1275        return res;
     1276}
     1277
     1278/*
     1279 *****************************************************************************
    10741280 * Function     : bitmap2res
    10751281 * Syntax       : res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
     
    10791285 * Output       : New .res format structure
    10801286 * Description  :
    1081  * Remarks      :
    1082  *****************************************************************************
    1083 */
    1084 res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
     1287 * Remarks      : The endian of the bitmap structures have been converted
     1288 *                by the loader.
     1289 *****************************************************************************
     1290*/
     1291static res_t *bitmap2res(name_id_t *name, bitmap_t *bmp)
    10851292{
    10861293        int restag;
     
    10891296        assert(bmp != NULL);
    10901297
    1091         HEAPCHECK();
    10921298        res = new_res();
    1093         HEAPCHECK();
    1094         restag = put_res_header(res, WRC_RT_BITMAP, NULL, name, bmp->memopt, NULL);
    1095         HEAPCHECK();
     1299        restag = put_res_header(res, WRC_RT_BITMAP, NULL, name, bmp->memopt, &(bmp->data->lvc));
    10961300        if(bmp->data->data[0] == 'B'
    10971301        && bmp->data->data[1] == 'M'
     
    11061310                put_raw_data(res, bmp->data, 0);
    11071311        }
    1108         HEAPCHECK();
    11091312        /* Set ResourceSize */
    11101313        SetResSize(res, restag);
    1111         HEAPCHECK();
    1112         if(win32)
    1113                 put_pad(res);
    1114         HEAPCHECK();
     1314        if(win32)
     1315                put_pad(res);
    11151316        return res;
    11161317}
     
    11251326 * Output       : New .res format structure
    11261327 * Description  :
    1127  * Remarks      :
    1128  *****************************************************************************
    1129 */
    1130 res_t *font2res(name_id_t *name, font_t *fnt)
    1131 {
     1328 * Remarks      : The data has been prepared just after parsing.
     1329 *****************************************************************************
     1330*/
     1331static res_t *font2res(name_id_t *name, font_t *fnt)
     1332{
     1333        int restag;
     1334        res_t *res;
    11321335        assert(name != NULL);
    11331336        assert(fnt != NULL);
    1134         warning("Fonts not yet implemented");
    1135         return NULL;
     1337
     1338        res = new_res();
     1339        restag = put_res_header(res, WRC_RT_FONT, NULL, name, fnt->memopt, &(fnt->data->lvc));
     1340        put_raw_data(res, fnt->data, 0);
     1341        /* Set ResourceSize */
     1342        SetResSize(res, restag);
     1343        if(win32)
     1344                put_pad(res);
     1345        return res;
     1346}
     1347
     1348/*
     1349 *****************************************************************************
     1350 * Function     : fontdir2res
     1351 * Syntax       : res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
     1352 * Input        :
     1353 *      name    - Name/ordinal of the resource
     1354 *      fntdir  - The fontdir descriptor
     1355 * Output       : New .res format structure
     1356 * Description  :
     1357 * Remarks      : The data has been prepared just after parsing.
     1358 *****************************************************************************
     1359*/
     1360static res_t *fontdir2res(name_id_t *name, fontdir_t *fnd)
     1361{
     1362        int restag;
     1363        res_t *res;
     1364        assert(name != NULL);
     1365        assert(fnd != NULL);
     1366
     1367        res = new_res();
     1368        restag = put_res_header(res, WRC_RT_FONTDIR, NULL, name, fnd->memopt, &(fnd->data->lvc));
     1369        put_raw_data(res, fnd->data, 0);
     1370        /* Set ResourceSize */
     1371        SetResSize(res, restag);
     1372        if(win32)
     1373                put_pad(res);
     1374        return res;
    11361375}
    11371376
     
    11481387 *****************************************************************************
    11491388*/
    1150 res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
     1389static res_t *rcdata2res(name_id_t *name, rcdata_t *rdt)
    11511390{
    11521391        int restag;
     
    11561395
    11571396        res = new_res();
    1158         restag = put_res_header(res, WRC_RT_RCDATA, NULL, name, rdt->memopt, NULL);
     1397        restag = put_res_header(res, WRC_RT_RCDATA, NULL, name, rdt->memopt, &(rdt->data->lvc));
    11591398        put_raw_data(res, rdt->data, 0);
    11601399        /* Set ResourceSize */
     
    11741413 * Output       : New .res format structure
    11751414 * Description  :
    1176  * Remarks      :
    1177  *****************************************************************************
    1178 */
    1179 res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
    1180 {
     1415 * Remarks      : The data has been converted to the appropriate endian
     1416 *                after is was parsed.
     1417 *****************************************************************************
     1418*/
     1419static res_t *messagetable2res(name_id_t *name, messagetable_t *msg)
     1420{
     1421        int restag;
     1422        res_t *res;
    11811423        assert(name != NULL);
    11821424        assert(msg != NULL);
    1183         warning("Messagetable not yet implemented");
    1184         return NULL;
     1425
     1426        res = new_res();
     1427        restag = put_res_header(res, WRC_RT_MESSAGETABLE, NULL, name, msg->memopt, &(msg->data->lvc));
     1428        put_raw_data(res, msg->data, 0);
     1429        /* Set ResourceSize */
     1430        SetResSize(res, restag);
     1431        if(win32)
     1432                put_pad(res);
     1433        return res;
    11851434}
    11861435
     
    11961445 *****************************************************************************
    11971446*/
    1198 res_t *stringtable2res(stringtable_t *stt)
     1447static res_t *stringtable2res(stringtable_t *stt)
    11991448{
    12001449        res_t *res;
     
    12191468                for(i = 0; i < stt->nentries; i++)
    12201469                {
    1221                         if(stt->entries[i].str)
     1470                        if(stt->entries[i].str && stt->entries[i].str->size)
    12221471                        {
    1223                                 if(win32)
    1224                                         put_word(res, stt->entries[i].str->size);
     1472                                string_t *str = convert_string(stt->entries[i].str, win32 ? str_unicode : str_char);
     1473                                if(win32)
     1474                                        put_word(res, str->size);
    12251475                                else
    1226                                         put_byte(res, stt->entries[i].str->size);
    1227                                 put_string(res, stt->entries[i].str, win32 ? str_unicode : str_char, FALSE);
     1476                                        put_byte(res, str->size);
     1477                                put_string(res, str, win32 ? str_unicode : str_char, FALSE);
     1478                                free(str);
    12281479                        }
    12291480                        else
     
    12561507 *****************************************************************************
    12571508*/
    1258 res_t *user2res(name_id_t *name, user_t *usr)
     1509static res_t *user2res(name_id_t *name, user_t *usr)
    12591510{
    12601511        int restag;
     
    12641515
    12651516        res = new_res();
    1266         restag = put_res_header(res, 0, usr->type, name, usr->memopt, NULL);
     1517        restag = put_res_header(res, 0, usr->type, name, usr->memopt, &(usr->data->lvc));
    12671518        put_raw_data(res, usr->data, 0);
    12681519        /* Set ResourceSize */
     
    12851536 *****************************************************************************
    12861537*/
    1287 void versionblock2res(res_t *res, ver_block_t *blk, int level)
     1538static void versionblock2res(res_t *res, ver_block_t *blk, int level)
    12881539{
    12891540        ver_value_t *val;
     
    13181569                        put_string(res, val->value.str, win32 ? str_unicode : str_char, TRUE);
    13191570                        if(win32)
    1320                                 *(WORD *)&(res->data[valvalsizetag]) = (WORD)((res->size - tag) >> 1);
     1571                                set_word(res, valvalsizetag, (WORD)((res->size - tag) >> 1));
    13211572                        else
    1322                                 *(WORD *)&(res->data[valvalsizetag]) = (WORD)(res->size - tag);
    1323                         *(WORD *)&(res->data[valblksizetag]) = (WORD)(res->size - valblksizetag);
     1573                                set_word(res, valvalsizetag, (WORD)(res->size - tag));
     1574                        set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
    13241575                        put_pad(res);
    13251576                }
     
    13411592                                put_word(res, val->value.words->words[i]);
    13421593                        }
    1343                         *(WORD *)&(res->data[valvalsizetag]) = (WORD)(res->size - tag);
    1344                         *(WORD *)&(res->data[valblksizetag]) = (WORD)(res->size - valblksizetag);
     1594                        set_word(res, valvalsizetag, (WORD)(res->size - tag));
     1595                        set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
    13451596                        put_pad(res);
    13461597                }
     
    13561607
    13571608        /* Set blocksize */
    1358         *(WORD *)&(res->data[blksizetag]) = (WORD)(res->size - blksizetag);
     1609        set_word(res, blksizetag, (WORD)(res->size - blksizetag));
    13591610}
    13601611
     
    13711622 *****************************************************************************
    13721623*/
    1373 res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
     1624static res_t *versioninfo2res(name_id_t *name, versioninfo_t *ver)
    13741625{
    13751626        int restag;
     
    13891640
    13901641        res = new_res();
    1391         restag = put_res_header(res, WRC_RT_VERSION, NULL, name, WRC_MO_MOVEABLE | WRC_MO_PURE, NULL);
     1642        restag = put_res_header(res, WRC_RT_VERSION, NULL, name, ver->memopt, &(ver->lvc));
    13921643        rootblocksizetag = res->size;
    13931644        put_word(res, 0);       /* BlockSize filled in later */
     
    14141665        put_dword(res, 0);              /* FileDateLS */
    14151666        /* Set ValueSize */
    1416         *(WORD *)&(res->data[valsizetag]) = (WORD)(res->size - tag);
     1667        set_word(res, valsizetag, (WORD)(res->size - tag));
    14171668        /* Descend into the blocks */
    14181669        for(blk = ver->blocks; blk; blk = blk->next)
    14191670                versionblock2res(res, blk, 0);
    14201671        /* Set root block's size */
    1421         *(WORD *)&(res->data[rootblocksizetag]) = (WORD)(res->size - rootblocksizetag);
     1672        set_word(res, rootblocksizetag, (WORD)(res->size - rootblocksizetag));
    14221673
    14231674        SetResSize(res, restag);
     
    14381689 *****************************************************************************
    14391690*/
    1440 void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
     1691static void toolbaritem2res(res_t *res, toolbar_item_t *tbitem)
    14411692{
    14421693        toolbar_item_t *itm = tbitem;
     
    14621713 *****************************************************************************
    14631714*/
    1464 res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
     1715static res_t *toolbar2res(name_id_t *name, toolbar_t *toolbar)
    14651716{
    14661717        int restag;
     
    15061757 *****************************************************************************
    15071758*/
    1508 res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
     1759static res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
    15091760{
    15101761        int restag;
     
    15141765
    15151766        res = new_res();
    1516         restag = put_res_header(res, WRC_RT_DLGINIT, NULL, name, dit->memopt, &(dit->lvc));
     1767        restag = put_res_header(res, WRC_RT_DLGINIT, NULL, name, dit->memopt, &(dit->data->lvc));
    15171768        put_raw_data(res, dit->data, 0);
    15181769        /* Set ResourceSize */
     
    15491800                for(i = 0; *sptr && i < MAXNAMELEN; i++)
    15501801                {
    1551                         if((unsigned)*sptr < 0x80 && isprint((char)*sptr))
     1802                        if((unsigned)*sptr < 0x80 && isprint(*sptr & 0xff))
    15521803                                buf[i] = *sptr++;
    15531804                        else
     
    15641815                for(i = 0; *cptr && i < MAXNAMELEN; i++)
    15651816                {
    1566                         if((unsigned)*cptr < 0x80 && isprint(*cptr))
     1817                        if((unsigned)*cptr < 0x80 && isprint(*cptr & 0xff))
    15671818                                buf[i] = *cptr++;
    15681819                        else
     
    16311882        {
    16321883        case res_acc:   return "Acc";
     1884        case res_anicur:return "AniCur";
     1885        case res_aniico:return "AniIco";
    16331886        case res_bmp:   return "Bmp";
    16341887        case res_cur:   return "Cur";
     
    16371890        case res_dlgex: return "Dlg";
    16381891        case res_fnt:   return "Fnt";
     1892        case res_fntdir:return "FntDir";
    16391893        case res_ico:   return "Ico";
    16401894        case res_icog:  return "IcoGrp";
     
    16961950                        if(!top->binres)
    16971951                                top->binres = font2res(top->name, top->res.fnt);
     1952                        break;
     1953                case res_fntdir:
     1954                        if(!top->binres)
     1955                                top->binres = fontdir2res(top->name, top->res.fnd);
    16981956                        break;
    16991957                case res_ico:
     
    17411999                            top->binres = dlginit2res(top->name, top->res.dlgi);
    17422000                        break;
    1743 
     2001                case res_anicur:
     2002                case res_aniico:
     2003                        if(!top->binres)
     2004                            top->binres = anicurico2res(top->name, top->res.ani, top->type);
     2005                        break;
    17442006                default:
    17452007                        internal_error(__FILE__, __LINE__, "Unknown resource type encountered %d in binary res generation", top->type);
  • trunk/tools/wrc/lexyy.c

    r3426 r5522  
    22
    33/* Scanner skeleton version:
    4  * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/tools/wrc/lexyy.c,v 1.2 2000-04-19 14:44:58 sandervl Exp $
     4 * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/tools/wrc/lexyy.c,v 1.3 2001-04-16 17:10:49 sandervl Exp $
    55 */
    66
     
    261261#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
    262262
     263
     264#define FLEX_DEBUG
    263265typedef unsigned char YY_CHAR;
    264266FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
    265267typedef int yy_state_type;
     268
     269#define FLEX_DEBUG
    266270extern char *yytext;
    267271#define yytext_ptr yytext
     
    282286        yy_c_buf_p = yy_cp;
    283287
    284 #define YY_NUM_RULES 124
    285 #define YY_END_OF_BUFFER 125
    286 static yyconst short int yy_accept[369] =
     288#define YY_NUM_RULES 84
     289#define YY_END_OF_BUFFER 85
     290static yyconst short int yy_accept[162] =
    287291    {   0,
    288         0,    0,   66,   66,    0,    0,    0,    0,    0,    0,
    289         0,    0,  114,  114,    0,    0,    0,    0,    0,    0,
    290         0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    291         0,    0,   22,   22,    9,    9,    9,    9,   46,   46,
    292         0,    0,   36,   36,   31,   31,   40,   40,   41,   41,
    293       125,  122,  121,  120,  122,   88,  122,  107,  122,   56,
    294        56,  118,  122,  122,  122,   59,   59,   54,  122,   55,
    295       121,  122,   66,  121,   67,   66,   66,   66,   66,   66,
    296        66,  123,   69,   68,  102,   90,   89,  106,   87,   72,
    297        71,  123,  112,  110,  111,  108,  112,  114,  116,  115,
    298 
    299         4,  123,    4,    4,    8,    6,   14,   22,    9,   12,
    300       123,  123,   46,   45,   45,   45,   36,  123,   34,   32,
    301        33,   36,  123,   31,  123,   29,   27,   28,   31,   40,
    302        37,   38,  123,   40,   44,   41,   43,   42,  121,   63,
    303        61,  113,  119,   56,   59,   56,   59,   59,  118,   64,
    304        62,   65,   70,   60,  121,    0,    0,    0,    0,    0,
    305         0,    0,    0,   66,   66,   66,   66,   66,   66,   66,
    306        66,    0,   68,  102,    0,  103,  101,  101,   91,   93,
    307        94,   95,   96,   97,   98,   99,  100,  101,   87,    0,
    308        84,   83,   83,   73,   75,   76,   77,   78,   79,   80,
    309 
    310        81,   82,   83,  110,  109,  114,  115,  115,  117,    0,
    311         0,    7,    6,   14,   22,    9,   10,    0,   11,   46,
    312         0,    0,    0,    0,    0,   36,   35,   36,    0,    0,
    313        31,   30,   31,   40,   39,   40,   41,  119,   58,   57,
    314         0,    0,    0,    0,    0,   15,    0,    0,    0,    0,
    315        66,   66,   66,   66,   66,   66,   66,  105,  104,   91,
    316        93,    0,   86,   85,   73,   75,    0,    3,    2,   10,
    317         0,   58,   57,    0,    0,    0,    0,    0,    0,   15,
    318         0,    0,    0,    0,    0,    0,   66,   66,   66,   66,
    319        66,   66,   53,   91,   92,   73,    0,    0,    0,   18,
    320 
    321        19,    0,    0,    0,    0,    0,    0,   26,    0,    0,
    322        66,   48,   66,   66,   66,   66,   73,    0,    0,    0,
    323        18,   19,   20,   21,   25,   16,    0,    0,   26,    0,
    324        13,   66,   49,   66,   66,   66,   73,   74,   23,    5,
    325        20,   21,   25,   16,   17,    0,   24,   13,   66,   66,
    326        66,   52,   73,   23,    5,   17,    1,   24,   66,   66,
    327        50,    1,   66,   66,   66,   51,   47,    0
     292        0,    0,    0,    0,    0,    0,    0,    0,   74,   74,
     293        0,    0,    7,    7,   12,   12,   14,   14,    2,    2,
     294       85,   82,   81,   80,   46,   67,   24,   24,   20,   20,
     295       78,   23,   23,   18,   19,   81,    1,   62,   66,   48,
     296       83,   44,   45,   27,   83,   72,   70,   71,   68,   72,
     297       74,   76,   75,   83,    7,    8,   83,    5,    3,    4,
     298        7,    1,   12,   13,    9,   10,   83,   12,   17,   14,
     299       16,   15,    2,   81,   24,   73,   24,   20,   23,   20,
     300       23,   23,   78,   25,   81,    1,    1,   62,   47,   63,
     301       60,   60,   60,   49,   52,   53,   54,   55,   56,   57,
     302
     303       58,   59,   60,   44,   26,   41,   39,   39,   39,   28,
     304       31,   32,   33,   34,   35,   36,   37,   38,   39,   70,
     305       69,   74,   75,   75,   77,    7,    6,    7,   12,   11,
     306       12,   14,    2,   79,   24,   22,   21,   65,   61,   64,
     307       49,   52,   51,   43,   40,   42,   28,   31,   30,   22,
     308       21,   49,   50,   28,   30,   28,   30,   28,   29,   28,
     309        0
    328310    } ;
    329311
     
    331313    {   0,
    332314        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
    333         1,    2,    2,    1,    1,    1,    1,    1,    1,    1,
     315        1,    2,    4,    1,    1,    1,    1,    1,    1,    1,
    334316        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    335         1,    2,    4,    5,    6,    1,    1,    7,    8,    9,
    336        10,   11,    1,    1,    1,    1,   12,   13,   14,   14,
    337        14,   14,   14,   14,   14,   15,   15,    1,   16,   17,
    338        18,   19,    1,    1,   20,   21,   22,   23,   24,   25,
    339        26,   26,   27,   26,   26,   28,   29,   30,   31,   32,
    340        26,   33,   34,   26,   35,   36,   26,   37,   26,   26,
    341         1,   38,    1,    1,   26,    1,   39,   40,   41,   42,
    342 
    343        43,   44,   45,   26,   46,   26,   26,   47,   48,   49,
    344        50,   51,   26,   52,   53,   54,   55,   56,   26,   57,
    345        26,   26,   58,   59,   60,    1,    1,    1,    1,    1,
     317        1,    2,    1,    5,    6,    1,    1,    1,    7,    8,
     318        9,   10,    1,    1,    1,   11,   12,   13,   14,   14,
     319       14,   14,   14,   14,   14,   15,   15,    1,   16,    1,
     320        1,    1,    1,    1,   17,   17,   17,   17,   17,   17,
     321       18,   18,   18,   18,   18,   19,   18,   18,   20,   18,
     322       18,   18,   18,   18,   18,   18,   18,   21,   18,   18,
     323        1,   22,    1,    1,   18,    1,   23,   24,   17,   17,
     324
     325       17,   25,   18,   18,   18,   18,   18,   26,   18,   27,
     326       20,   18,   18,   28,   18,   29,   18,   30,   18,   31,
     327       18,   18,   32,    1,   33,    1,    1,    1,    1,    1,
    346328        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    347329        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
     
    360342    } ;
    361343
    362 static yyconst int yy_meta[61] =
     344static yyconst int yy_meta[34] =
    363345    {   0,
    364         1,    2,    3,    1,    4,    5,    1,    1,    6,    7,
    365         8,    9,   10,   10,   10,    5,    1,    1,   11,   10,
    366        10,   10,   10,   10,   10,   12,   12,   12,   12,   12,
    367        12,   12,   12,   12,   12,   12,   12,   13,   10,   10,
    368        10,   10,   10,   10,   12,   12,   12,   12,   12,   12,
    369        12,   12,   12,   12,   12,   12,   12,   14,    1,   14
     346        1,    1,    2,    1,    3,    4,    1,    5,    5,    6,
     347        7,    8,    9,    9,    9,    4,    9,    7,    7,    7,
     348        7,   10,    9,    9,    9,    7,    7,    7,    7,    7,
     349        7,   11,   11
    370350    } ;
    371351
    372 static yyconst short int yy_base[425] =
     352static yyconst short int yy_base[191] =
    373353    {   0,
    374         0,   60,  119,  169,   17,   18,   42,   43,   46,   47,
    375       219,  262,   21,   22,   24,   37,  306,  366,  426,  486,
    376         0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    377         0,    0, 1053, 1048,   79,   87,   89,   90, 1030, 1021,
    378      1020,   28,   94,  127,  120,  187,  323,  339,   41,   92,
    379      1005, 1334,  994, 1334,  977, 1334,  974, 1334,   24,  241,
    380       191,    0,  950,  949,  948,    0,  948, 1334,  619, 1334,
    381        81,  113,    0,  675, 1334,   10,   59,   83,   85,  103,
    382       174,  671, 1334, 1334,    0, 1334,  102,  542,    0, 1334,
    383       109,  595, 1334,  673, 1334, 1334,    0,    0, 1334,  126,
    384 
    385      1334, 1334,    0,    0, 1334,  665,    0,    0,    0, 1334,
    386       129,  147,    0, 1334,  107,  206,    0,  662, 1334, 1334,
    387      1334,  156,  246,    0,  661, 1334, 1334, 1334,  167,    0,
    388      1334, 1334,  660,  173, 1334,  668, 1334, 1334,  667, 1334,
    389      1334, 1334,    0,  253,    0,    0,  163,  640,    0, 1334,
    390      1334, 1334, 1334, 1334,  180,  344,  350,  625,  176,  139,
    391       621,  614,  610,    0,  157,  193,  163,  192,  215,  194,
    392       247,  653, 1334,    0,  325, 1334, 1334,  652,  281,  323,
    393      1334, 1334, 1334, 1334, 1334, 1334, 1334,    0,    0,  326,
    394      1334, 1334,  651,  343,  346, 1334, 1334, 1334, 1334, 1334,
    395 
    396      1334, 1334,    0,  648, 1334,    0,  224,  262, 1334,  643,
    397       627, 1334,  636,    0,    0,    0,    0,  351, 1334,    0,
    398       341,  360,  406,  363,   11,    0, 1334,  392,  412,  419,
    399         0, 1334,  407,    0, 1334,  414,  641,    0,  433,  372,
    400       598,   43,  599,  588,  595,  465,  596,  587,  594,  590,
    401       428,  430,  367,  433,  436,  478,  484, 1334, 1334,  463,
    402       468,    0, 1334, 1334,  496,  502,    0,  626, 1334,    0,
    403       578,    0,    0,  583,  584,  584,  580,  575,  575,  621,
    404       579,  579,  573,  576,  573,  574,  492,  490,  485,  488,
    405       500,  490,    0,  515, 1334,  520,    0,  566,  566,  612,
    406 
    407       611,  568,  559,  553,  561,  561,  546,    0,  549,  548,
    408       489,    0,  499,  513,  527,  529,  537,    0,  538,  546,
    409       586,  573,  534,  524,    0,  469,  424,  409,    0,  409,
    410       421,  530,    0,  532,  530,  536,  550, 1334,    0,  416,
    411       415,  387,    0,  386,  361,  307,    0,  338,  540,  541,
    412       542,    0,  556,    0,  332,  288,  277,    0,  553,  548,
    413         0,  244,  555,  556,  563,    0,    0, 1334,  684,  698,
    414       712,  726,  740,  754,  768,  782,  796,  810,  824,  838,
    415       852,  866,  880,  894,  908,  922,  936,  190,  950,  964,
    416       978,  992, 1006, 1020, 1034,  214, 1048, 1062, 1076, 1090,
    417 
    418      1099,  462, 1111, 1125, 1139, 1153, 1167, 1180, 1194, 1207,
    419      1221, 1235, 1249,  174,  147, 1263,  135,   93,   29, 1277,
    420        16, 1291, 1305, 1319
     354        0,   32,   32,   36,   37,   40,   61,   85,   41,   43,
     355        0,    0,  108,  140,  171,  186,   45,   53,  183,  182,
     356      181,  622,   48,  622,  622,  622,    0,   60,  192,   46,
     357        0,  211,  170,  622,  622,   77,   69,    0,  622,   89,
     358      242,    0,  622,   99,  275,  622,   78,  622,  622,    0,
     359        0,  622,   85,  622,    0,  622,  161,  622,  622,  622,
     360      111,  103,    0,  622,  622,  622,  160,  117,  622,  114,
     361      622,  622,    0,  123,    0,  622,  308,  108,    0,    0,
     362      117,  329,    0,  622,  130,  131,  143,    0,  146,  622,
     363      622,  158,  144,  140,  144,  622,  622,  622,  622,  622,
     364
     365      622,  622,    0,    0,  158,  622,  622,  135,  132,  151,
     366      154,  622,  622,  622,  622,  622,  622,  622,    0,  174,
     367      622,    0,  172,  181,  622,    0,  622,  195,    0,  622,
     368      232,  225,    0,    0,  354,  306,  209,  622,  622,  622,
     369      226,  308,    0,  622,  622,  622,  313,  316,    0,    0,
     370        0,  320,  622,  323,    0,  334,    0,  352,  622,  358,
     371      622,  387,  398,  409,  420,  431,  442,  453,  464,  475,
     372      480,  490,  501,  512,  117,  523,  534,  545,  555,  566,
     373      577,  588,  599,  113,  103,  610,   97,   87,   81,   51
    421374    } ;
    422375
    423 static yyconst short int yy_def[425] =
     376static yyconst short int yy_def[191] =
    424377    {   0,
    425       369,  369,  370,  370,  371,  371,  372,  372,  373,  373,
    426       374,  374,  375,  375,  376,  376,  377,  377,  378,  378,
    427       379,  379,  379,  379,  379,  379,  379,  379,  379,  379,
    428       379,  379,  380,  380,  381,  381,  381,  381,  382,  382,
    429       383,  383,  384,  384,  385,  385,  386,  386,  387,  387,
    430       368,  368,  368,  368,  368,  368,  368,  368,  368,  388,
    431       388,  389,  368,  368,  368,  388,  388,  368,  368,  368,
    432       368,  368,  390,  368,  368,  390,  390,  390,  390,  390,
    433       390,  391,  368,  368,  392,  368,  368,  393,  394,  368,
    434       368,  395,  368,  368,  368,  368,  396,  397,  368,  398,
    435 
    436       368,  368,  399,  400,  368,  401,  402,  403,  404,  368,
    437       405,  368,  406,  368,  368,  368,  407,  408,  368,  368,
    438       368,  407,  368,  409,  410,  368,  368,  368,  409,  411,
    439       368,  368,  412,  411,  368,  368,  368,  368,  368,  368,
    440       368,  368,  413,  388,  388,  388,  388,  388,  389,  368,
    441       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    442       368,  368,  368,  390,  390,  390,  390,  390,  390,  390,
    443       390,  391,  368,  392,  368,  368,  368,  368,  368,  368,
    444       368,  368,  368,  368,  368,  368,  368,  414,  394,  368,
    445       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    446 
    447       368,  368,  415,  368,  368,  397,  398,  398,  368,  399,
    448       400,  368,  401,  402,  403,  404,  416,  368,  368,  406,
    449       368,  368,  368,  368,  368,  407,  368,  407,  368,  368,
    450       409,  368,  409,  411,  368,  411,  368,  413,  388,  148,
    451       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    452       390,  390,  390,  390,  390,  390,  390,  368,  368,  368,
    453       368,  417,  368,  368,  368,  368,  418,  399,  368,  416,
    454       368,  388,  388,  368,  368,  368,  368,  368,  368,  368,
    455       368,  368,  368,  368,  368,  368,  390,  390,  390,  390,
    456       390,  390,  390,  368,  368,  368,  419,  368,  368,  368,
    457 
    458       368,  368,  368,  368,  368,  368,  368,  420,  368,  368,
    459       390,  390,  390,  390,  390,  390,  368,  421,  368,  368,
    460       368,  368,  368,  368,  422,  368,  368,  368,  420,  368,
    461       368,  390,  390,  390,  390,  390,  368,  368,  423,  368,
    462       368,  368,  422,  368,  368,  368,  424,  368,  390,  390,
    463       390,  390,  368,  423,  368,  368,  368,  424,  390,  390,
    464       390,  368,  390,  390,  390,  390,  390,    0,  368,  368,
    465       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    466       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    467       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    468 
    469       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    470       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    471       368,  368,  368,  368
     378      161,    1,  162,  162,  163,  163,  164,  164,  165,  165,
     379      166,  166,  167,  167,  168,  168,  169,  169,  170,  170,
     380      161,  161,  161,  161,  161,  161,  171,  171,  161,   29,
     381      172,   29,   32,  161,  161,  161,  161,  173,  161,  161,
     382      161,  174,  161,  161,  161,  161,  161,  161,  161,  175,
     383      176,  161,  177,  161,  178,  161,  179,  161,  161,  161,
     384      178,  161,  180,  161,  161,  161,  181,  180,  161,  161,
     385      161,  161,  182,  161,  171,  161,  183,   29,   32,   32,
     386       32,   32,  172,  161,  161,  161,  161,  173,  161,  161,
     387      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     388
     389      161,  161,  184,  174,  161,  161,  161,  161,  161,  161,
     390      161,  161,  161,  161,  161,  161,  161,  161,  185,  161,
     391      161,  176,  177,  177,  161,  178,  161,  178,  180,  161,
     392      180,  161,  182,  186,  183,   32,   82,  161,  161,  161,
     393      161,  161,  187,  161,  161,  161,  161,  161,  188,   32,
     394       32,  161,  161,  161,  189,  161,  190,  161,  161,  161,
     395        0,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     396      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     397      161,  161,  161,  161,  161,  161,  161,  161,  161,  161
    472398    } ;
    473399
    474 static yyconst short int yy_nxt[1395] =
     400static yyconst short int yy_nxt[656] =
    475401    {   0,
    476        52,   53,   54,   55,   56,   52,   57,   58,   52,   52,
    477        52,   59,   60,   61,   61,   62,   63,   64,   65,   83,
    478        83,   84,   84,   99,   99,  338,  102,   67,  103,  115,
    479        54,  100,  100,  116,  142,  143,  165,   52,  318,  102,
    480       104,  103,  136,  137,   86,   86,   87,   87,   90,   90,
    481        91,   91,  245,  104,  246,  165,  138,   68,   69,   70,
    482        52,   71,   54,   55,   56,   72,   57,   58,   52,   52,
    483        52,   59,   60,   61,   61,   62,   63,   64,   65,   88,
    484        88,  110,  155,   92,   92,  166,  156,   67,  275,  110,
    485       111,  110,  110,  136,  137,  276,   54,   52,  111,  102,
    486 
    487       111,  111,  297,  175,  166,  118,  176,  138,  221,  119,
    488       190,  167,  222,  191,  157,  168,  112,   68,   69,   70,
    489        74,   54,   54,   75,  112,  102,  112,  112,  122,   54,
    490       167,  125,  123,  169,  168,  126,  208,  209,  118,  142,
    491       143,   76,  119,   77,  295,   78,   79,   80,  218,  219,
    492        81,  120,  169,  121,  158,  159,  267,  228,  160,  161,
    493        76,  229,   77,  162,   78,   79,   80,  163,  233,   81,
    494        74,   54,  229,   75,  236,  239,  239,  127,  229,  128,
    495       245,  155,  246,  262,  120,  156,  121,  247,  129,   54,
    496       251,   76,  123,   77,  253,   78,   79,   80,  125,  145,
    497 
    498        81,  145,  126,  144,  144,  144,  170,  223,  171,  251,
    499        76,  254,   77,  253,   78,   79,   80,  256,  146,   81,
    500        94,   95,  242,  205,  243,  170,   96,  244,  171,  252,
    501       254,   97,   97,   97,  368,  368,  256,  146,   97,   97,
    502        97,   97,   97,   97,  127,  362,  128,  230,  224,  252,
    503       255,  225,  161,  144,  144,  144,  162,   97,   97,   97,
    504        97,   97,   97,   94,   95,  144,  144,  144,  146,   96,
    505       255,  147,  208,  209,   97,   97,   97,  148,  362,  257,
    506       146,   97,   97,   97,   97,   97,   97,  146,  159,  356,
    507       147,  225,  161,  260,  260,  261,  162,  148,  257,  146,
    508 
    509        97,   97,   97,   97,   97,   97,  105,  105,  102,  105,
    510       105,  105,  105,  105,  105,  105,  105,  105,  105,  105,
    511       105,  105,  105,  105,  105,   54,  175,  190,  102,  258,
    512       263,  131,  132,  355,  133,  261,  261,  261,  102,  348,
    513       134,   54,  221,  105,  123,  157,  222,  131,  132,  357,
    514       133,  157,  218,  219,  102,  265,  265,  266,  266,  266,
    515       266,  223,  356,  105,  105,  105,  105,  105,  102,  105,
    516       105,  105,  105,  105,  105,  105,  105,  105,  105,  105,
    517       105,  105,  105,  105,  105,  158,  159,  344,  342,  160,
    518       161,  158,  159,  228,  162,  160,  161,  229,  163,  273,
    519 
    520       162,  289,  224,  105,  163,  225,  161,  223,  233,  242,
    521       162,  243,  229,  230,  271,  236,  341,  355,  273,  229,
    522       230,  289,  348,  105,  105,  105,  102,  102,  102,  102,
    523       102,  102,  102,  102,  102,  102,  102,  102,  102,  102,
    524       102,  102,  102,  102,  102,  239,  239,  347,  224,  287,
    525       346,  225,  161,  288,  159,  290,  162,  225,  161,  291,
    526       272,  159,  162,  102,  225,  161,  280,  345,  287,  162,
    527       344,  214,  288,  214,  290,  294,  294,  261,  291,  272,
    528       261,  261,  261,  102,  102,  102,  102,  102,  102,  102,
    529       102,  102,  102,  102,  102,  102,  102,  102,  102,  102,
    530 
    531       102,  102,  102,  102,  102,  292,  281,  293,  296,  296,
    532       266,  311,  312,  282,  266,  266,  266,  313,  314,  315,
    533       316,  332,  333,  102,  292,  342,  293,  261,  261,  261,
    534       311,  312,  317,  317,  266,  341,  313,  314,  315,  316,
    535       332,  333,  334,  102,  102,  102,  178,  335,  336,  337,
    536       337,  266,  349,  350,  179,  179,  180,  351,  352,  359,
    537       360,  334,  353,  353,  266,  361,  335,  336,  266,  266,
    538       266,  349,  350,  363,  322,  364,  351,  352,  359,  360,
    539       181,  182,  365,  366,  361,  183,  367,  321,  340,  339,
    540       184,  331,  363,  185,  364,  186,  330,  187,  188,  193,
    541 
    542       328,  365,  366,  327,  326,  367,  325,  194,  194,  195,
    543       324,  323,  322,  321,  320,  319,  310,  309,  308,  307,
    544       306,  305,  280,  304,  303,  302,  301,  300,  299,  298,
    545       268,  286,  285,  196,  197,  284,  283,  279,  198,  278,
    546       277,  274,  237,  199,  212,  269,  200,  268,  201,  204,
    547       202,  203,  240,  240,  240,  264,  259,  173,  250,  240,
    548       240,  240,  240,  240,  240,  249,  248,  241,  139,  237,
    549       142,  142,  142,  212,  204,  173,  139,  154,  240,  240,
    550       240,  240,  240,  240,   66,   66,   66,   66,   66,   66,
    551        66,   66,   66,   66,   66,   66,   66,   66,   73,   73,
    552 
    553        73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
    554        73,   73,   82,   82,   82,   82,   82,   82,   82,   82,
    555        82,   82,   82,   82,   82,   82,   85,   85,   85,   85,
    556        85,   85,   85,   85,   85,   85,   85,   85,   85,   85,
    557        89,   89,   89,   89,   89,   89,   89,   89,   89,   89,
    558        89,   89,   89,   89,   93,   93,   93,   93,   93,   93,
    559        93,   93,   93,   93,   93,   93,   93,   93,   98,   98,
    560        98,   98,   98,   98,   98,   98,   98,   98,   98,   98,
    561        98,   98,  101,  101,  101,  101,  101,  101,  101,  101,
    562       101,  101,  101,  101,  101,  101,  106,  106,  106,  106,
    563 
    564       106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
    565       107,  107,  107,  107,  107,  107,  107,  107,  107,  107,
    566       107,  107,  107,  107,  102,  102,  102,  102,  102,  102,
    567       102,  102,  102,  102,  102,  102,  102,  102,  108,  108,
    568       108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
    569       108,  108,  109,  109,  109,  109,  109,  109,  109,  109,
    570       109,  109,  109,  109,  109,  109,  113,  113,  113,  113,
    571       113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
    572       114,  114,  114,  114,  114,  114,  114,  114,  114,  114,
    573       114,  114,  114,  114,  117,  117,  117,  117,  117,  117,
    574 
    575       117,  117,  117,  117,  117,  117,  117,  117,  124,  124,
    576       124,  124,  124,  124,  124,  124,  124,  124,  124,  124,
    577       124,  124,  130,  130,  130,  130,  130,  130,  130,  130,
    578       130,  130,  130,  130,  130,  130,  135,  135,  135,  135,
    579       135,  135,  135,  135,  135,  135,  135,  135,  135,  135,
    580       149,  149,  153,  149,  149,  149,  149,  149,  149,  149,
    581       149,  149,  149,  149,  164,  152,  151,  150,  164,  164,
    582       164,  164,  164,  164,  164,  164,  164,  164,  172,  172,
    583       141,  172,  172,  172,  172,  172,  172,  172,  172,  172,
    584       172,  172,  174,  174,  140,  139,  174,  174,  174,  174,
    585 
    586       174,  174,  174,  174,  368,  174,  177,  177,  177,  177,
    587       177,  177,  177,  177,  177,  177,  177,  177,  177,  177,
    588       189,  189,   54,  102,  189,  189,  189,  189,  189,  189,
    589       189,  189,  102,  189,  192,  192,  192,  192,  192,  192,
    590       192,  192,  192,  192,  192,  192,  192,  192,  206,  206,
    591       102,  206,  206,  206,  206,  102,  206,  206,  206,  206,
    592       206,  206,  207,  207,  368,  207,  207,  207,  207,  207,
    593       207,  207,  207,  207,  207,  207,  210,  210,  368,  210,
    594       210,  210,  210,  210,  210,  210,  368,  210,  210,  210,
    595       211,  211,  368,  211,  211,  211,  211,  211,  211,  211,
    596 
    597       368,  211,  211,  211,  213,  368,  368,  368,  213,  368,
    598       213,  215,  215,  368,  215,  215,  215,  215,  215,  215,
    599       215,  215,  215,  215,  215,  216,  216,  368,  216,  216,
    600       216,  216,  216,  368,  216,  216,  216,  368,  216,  217,
    601       217,  217,  217,  217,  217,  217,  217,  217,  217,  217,
    602       217,  217,  217,  220,  220,  368,  220,  220,  220,  220,
    603       220,  220,  220,  220,  220,  220,  220,  226,  226,  368,
    604       226,  368,  226,  226,  226,  368,  226,  226,  226,  226,
    605       227,  227,  368,  227,  227,  227,  227,  227,  227,  227,
    606       227,  227,  227,  227,  231,  231,  368,  231,  368,  231,
    607 
    608       231,  231,  368,  231,  231,  231,  231,  232,  232,  368,
    609       232,  232,  232,  232,  232,  232,  232,  232,  232,  232,
    610       232,  234,  234,  368,  234,  368,  368,  368,  234,  368,
    611       234,  234,  234,  234,  234,  235,  235,  368,  235,  235,
    612       235,  235,  235,  235,  235,  235,  235,  235,  235,  238,
    613       238,  368,  238,  238,  238,  238,  238,  238,  238,  238,
    614       238,  238,  238,  270,  270,  368,  270,  270,  270,  270,
    615       270,  368,  270,  270,  270,  368,  270,  329,  329,  368,
    616       329,  329,  329,  329,  329,  329,  329,  329,  329,  329,
    617       329,  343,  343,  368,  343,  343,  343,  343,  343,  343,
    618 
    619       343,  343,  343,  343,  343,  354,  354,  368,  354,  354,
    620       354,  354,  354,  354,  354,  354,  354,  354,  354,  358,
    621       358,  368,  358,  358,  358,  358,  358,  358,  358,  358,
    622       358,  358,  358,   51,  368,  368,  368,  368,  368,  368,
    623       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    624       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    625       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    626       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    627       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    628       368,  368,  368,  368
    629 
     402       22,   23,   24,   23,   25,   22,   26,   22,   22,   22,
     403       27,   28,   29,   30,   30,   31,   32,   32,   33,   32,
     404       32,   27,   32,   32,   32,   32,   32,   32,   32,   32,
     405       32,   34,   35,   36,   39,   36,   40,   37,   39,   43,
     406       40,   44,   43,   52,   44,   52,   70,   71,   70,   74,
     407       53,   74,   53,   41,   70,   71,   70,   41,   45,  159,
     408       72,   45,   47,   48,   47,   79,   79,   49,   72,   76,
     409       87,   77,   87,   50,   50,   50,   79,   50,   85,  120,
     410       85,  120,   86,   50,   50,   50,   47,   48,   47,  157,
     411       89,   49,   89,   90,  124,  155,  125,   50,   50,   50,
     412
     413      105,   50,  105,  106,   87,  153,   87,   50,   50,   50,
     414       56,  149,  128,   54,  128,  132,   86,  132,  131,   57,
     415      131,  143,   86,   58,   74,  121,   74,   79,   79,  136,
     416      136,   85,   87,   85,   87,   86,  146,  145,   79,   59,
     417       60,   61,   56,   61,   87,   62,   87,   89,  140,   89,
     418      138,   57,  141,  141,  142,   58,  142,  142,  142,  105,
     419      139,  105,  144,  147,  147,  148,  148,  148,  148,   76,
     420       76,   59,   60,   64,   84,  120,   54,  120,   65,   66,
     421      161,  161,   67,  161,   54,   54,   54,   68,   64,   68,
     422      124,   62,  125,   65,   66,  161,  128,   67,  128,  161,
     423
     424       86,   54,   75,   75,   78,   78,   78,  161,   79,   79,
     425       80,   81,   82,   75,   79,   79,   79,   80,   79,   79,
     426       79,   79,   82,   79,   79,   79,  132,  151,  132,   79,
     427       79,   79,  161,  131,  151,  131,   79,   86,  152,  152,
     428      142,   79,   91,   91,   91,   92,   93,   91,   91,   91,
     429       91,   91,   91,   91,   94,   94,   95,   91,   91,   91,
     430       91,   91,   91,   91,   96,   97,   98,   91,   99,  100,
     431      101,  102,  103,   91,   91,  107,  107,  107,  108,  109,
     432      107,  107,  107,  107,  107,  107,  107,  110,  110,  111,
     433      107,  107,  107,  107,  107,  107,  107,  112,  113,  114,
     434
     435      107,  115,  116,  117,  118,  119,  107,  107,  134,  134,
     436      161,  134,  134,  134,  134,  134,  134,  134,  136,  136,
     437      142,  142,  142,  134,  150,  154,  154,  148,  148,  148,
     438      148,  150,  142,  142,  142,  156,  156,  148,  161,  134,
     439      134,  137,  137,  137,  161,  137,  158,  158,  148,  161,
     440      161,  137,  137,  137,  134,  134,  161,  134,  134,  134,
     441      134,  134,  134,  134,  160,  160,  148,  161,  161,  134,
     442      148,  148,  148,  161,  161,  161,  161,  161,  161,  161,
     443      161,  161,  161,  161,  161,  134,  134,   38,   38,   38,
     444       38,   38,   38,   38,   38,   38,   38,   38,   42,   42,
     445
     446       42,   42,   42,   42,   42,   42,   42,   42,   42,   46,
     447       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
     448       51,   51,   51,   51,   51,   51,   51,   51,   51,   51,
     449       51,   54,   54,   54,   54,   54,   54,   54,   54,   54,
     450       54,   54,   55,   55,   55,   55,   55,   55,   55,   55,
     451       55,   55,   55,   63,   63,   63,   63,   63,   63,   63,
     452       63,   63,   63,   63,   69,   69,   69,   69,   69,   69,
     453       69,   69,   69,   69,   69,   73,   73,   73,   73,   73,
     454       73,   73,   73,   73,   73,   73,   75,   75,   75,   75,
     455       83,  161,   83,   83,   83,   83,   83,   83,   83,   83,
     456
     457       83,   88,  161,  161,   88,   88,   88,   88,   88,   88,
     458      161,   88,  104,  161,  161,  104,  104,  104,  104,  104,
     459      104,  161,  104,  122,  161,  122,  122,  122,  161,  122,
     460      122,  122,  122,  122,  123,  161,  123,  123,  123,  123,
     461      123,  123,  123,  123,  123,  126,  161,  126,  161,  126,
     462      126,  126,  161,  126,  126,  127,  161,  127,  127,  127,
     463      127,  127,  127,  127,  127,  127,  129,  161,  129,  161,
     464      161,  129,  129,  161,  129,  129,  129,  130,  161,  130,
     465      130,  130,  130,  130,  130,  130,  130,  130,  133,  161,
     466      133,  133,  133,  133,  133,  133,  133,  133,  133,  135,
     467
     468      161,  135,  135,  135,  135,  135,  135,  135,  135,  135,
     469      134,  161,  134,  134,  134,  134,  134,  134,  134,  134,
     470      134,   21,  161,  161,  161,  161,  161,  161,  161,  161,
     471      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     472      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     473      161,  161,  161,  161,  161
    630474    } ;
    631475
    632 static yyconst short int yy_chk[1395] =
     476static yyconst short int yy_chk[656] =
    633477    {   0,
    634478        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
    635         1,    1,    1,    1,    1,    1,    1,    1,    1,    5,
    636         6,    5,    6,   13,   14,  421,   15,    1,   15,   42,
    637        42,   13,   14,   42,   59,   59,   76,    1,  419,   16,
    638        15,   16,   49,   49,    7,    8,    7,    8,    9,   10,
    639         9,   10,  225,   16,  225,   76,   49,    1,    1,    1,
    640         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
    641         2,    2,    2,    2,    2,    2,    2,    2,    2,    7,
    642         8,   35,   71,    9,   10,   77,   71,    2,  242,   36,
    643        35,   37,   38,   50,   50,  242,   43,    2,   36,   43,
    644 
    645        37,   38,  418,   87,   77,   43,   87,   50,  115,   43,
    646        91,   78,  115,   91,   72,   79,   35,    2,    2,    2,
    647         3,    3,   45,    3,   36,   45,   37,   38,   44,   44,
    648        78,   45,   44,   80,   79,   45,  100,  100,   44,  111,
    649       111,    3,   44,    3,  417,    3,    3,    3,  112,  112,
    650         3,   43,   80,   43,   72,   72,  415,  122,   72,   72,
    651         3,  122,    3,   72,    3,    3,    3,   72,  129,    3,
    652         4,    4,  129,    4,  134,  147,  147,   45,  134,   45,
    653       160,  155,  160,  414,   44,  155,   44,  160,   46,   46,
    654       165,    4,   46,    4,  167,    4,    4,    4,   46,  388,
    655 
    656         4,  388,   46,   61,   61,   61,   81,  116,   81,  165,
    657         4,  168,    4,  167,    4,    4,    4,  170,   61,    4,
    658        11,   11,  159,  396,  159,   81,   11,  159,   81,  166,
    659       168,   11,   11,   11,  207,  207,  170,   61,   11,   11,
    660        11,   11,   11,   11,   46,  362,   46,  123,  116,  166,
    661       169,  116,  116,   60,   60,   60,  116,   11,   11,   11,
    662        11,   11,   11,   12,   12,  144,  144,  144,   60,   12,
    663       169,   60,  208,  208,   12,   12,   12,   60,  357,  171,
    664       144,   12,   12,   12,   12,   12,   12,   60,  123,  356,
    665        60,  123,  123,  179,  179,  179,  123,   60,  171,  144,
    666 
    667        12,   12,   12,   12,   12,   12,   17,   17,   17,   17,
    668        17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
    669        17,   17,   17,   17,   17,   47,  175,  190,   47,  175,
    670       190,   47,   47,  355,   47,  180,  180,  180,   47,  348,
    671        48,   48,  221,   17,   48,  156,  221,   48,   48,  346,
    672        48,  157,  218,  218,   48,  194,  194,  194,  195,  195,
    673       195,  222,  345,   17,   17,   17,   18,   18,   18,   18,
    674        18,   18,   18,   18,   18,   18,   18,   18,   18,   18,
    675        18,   18,   18,   18,   18,  156,  156,  344,  342,  156,
    676       156,  157,  157,  228,  156,  157,  157,  228,  156,  240,
    677 
    678       157,  253,  222,   18,  157,  222,  222,  223,  233,  224,
    679       222,  224,  233,  229,  224,  236,  341,  340,  240,  236,
    680       230,  253,  331,   18,   18,   18,   19,   19,   19,   19,
    681        19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
    682        19,   19,   19,   19,   19,  239,  239,  330,  223,  251,
    683       328,  223,  223,  252,  229,  254,  223,  229,  229,  255,
    684       239,  230,  229,   19,  230,  230,  246,  327,  251,  230,
    685       326,  402,  252,  402,  254,  260,  260,  260,  255,  239,
    686       261,  261,  261,   19,   19,   19,   20,   20,   20,   20,
    687        20,   20,   20,   20,   20,   20,   20,   20,   20,   20,
    688 
    689        20,   20,   20,   20,   20,  256,  246,  257,  265,  265,
    690       265,  287,  288,  246,  266,  266,  266,  289,  290,  291,
    691       292,  311,  313,   20,  256,  324,  257,  294,  294,  294,
    692       287,  288,  296,  296,  296,  323,  289,  290,  291,  292,
    693       311,  313,  314,   20,   20,   20,   88,  315,  316,  317,
    694       317,  317,  332,  334,   88,   88,   88,  335,  336,  349,
    695       350,  314,  337,  337,  337,  351,  315,  316,  353,  353,
    696       353,  332,  334,  359,  322,  360,  335,  336,  349,  350,
    697        88,   88,  363,  364,  351,   88,  365,  321,  320,  319,
    698        88,  310,  359,   88,  360,   88,  309,   88,   88,   92,
    699 
    700       307,  363,  364,  306,  305,  365,  304,   92,   92,   92,
    701       303,  302,  301,  300,  299,  298,  286,  285,  284,  283,
    702       282,  281,  280,  279,  278,  277,  276,  275,  274,  271,
    703       268,  250,  249,   92,   92,  248,  247,  245,   92,  244,
    704       243,  241,  237,   92,  213,  211,   92,  210,   92,  204,
    705        92,   92,  148,  148,  148,  193,  178,  172,  163,  148,
    706       148,  148,  148,  148,  148,  162,  161,  158,  139,  136,
    707       133,  125,  118,  106,   94,   82,   74,   69,  148,  148,
    708       148,  148,  148,  148,  369,  369,  369,  369,  369,  369,
    709       369,  369,  369,  369,  369,  369,  369,  369,  370,  370,
    710 
    711       370,  370,  370,  370,  370,  370,  370,  370,  370,  370,
    712       370,  370,  371,  371,  371,  371,  371,  371,  371,  371,
    713       371,  371,  371,  371,  371,  371,  372,  372,  372,  372,
    714       372,  372,  372,  372,  372,  372,  372,  372,  372,  372,
    715       373,  373,  373,  373,  373,  373,  373,  373,  373,  373,
    716       373,  373,  373,  373,  374,  374,  374,  374,  374,  374,
    717       374,  374,  374,  374,  374,  374,  374,  374,  375,  375,
    718       375,  375,  375,  375,  375,  375,  375,  375,  375,  375,
    719       375,  375,  376,  376,  376,  376,  376,  376,  376,  376,
    720       376,  376,  376,  376,  376,  376,  377,  377,  377,  377,
    721 
    722       377,  377,  377,  377,  377,  377,  377,  377,  377,  377,
    723       378,  378,  378,  378,  378,  378,  378,  378,  378,  378,
    724       378,  378,  378,  378,  379,  379,  379,  379,  379,  379,
    725       379,  379,  379,  379,  379,  379,  379,  379,  380,  380,
    726       380,  380,  380,  380,  380,  380,  380,  380,  380,  380,
    727       380,  380,  381,  381,  381,  381,  381,  381,  381,  381,
    728       381,  381,  381,  381,  381,  381,  382,  382,  382,  382,
    729       382,  382,  382,  382,  382,  382,  382,  382,  382,  382,
    730       383,  383,  383,  383,  383,  383,  383,  383,  383,  383,
    731       383,  383,  383,  383,  384,  384,  384,  384,  384,  384,
    732 
    733       384,  384,  384,  384,  384,  384,  384,  384,  385,  385,
    734       385,  385,  385,  385,  385,  385,  385,  385,  385,  385,
    735       385,  385,  386,  386,  386,  386,  386,  386,  386,  386,
    736       386,  386,  386,  386,  386,  386,  387,  387,  387,  387,
    737       387,  387,  387,  387,  387,  387,  387,  387,  387,  387,
    738       389,  389,   67,  389,  389,  389,  389,  389,  389,  389,
    739       389,  389,  389,  389,  390,   65,   64,   63,  390,  390,
    740       390,  390,  390,  390,  390,  390,  390,  390,  391,  391,
    741        57,  391,  391,  391,  391,  391,  391,  391,  391,  391,
    742       391,  391,  392,  392,   55,   53,  392,  392,  392,  392,
    743 
    744       392,  392,  392,  392,   51,  392,  393,  393,  393,  393,
    745       393,  393,  393,  393,  393,  393,  393,  393,  393,  393,
    746       394,  394,   41,   40,  394,  394,  394,  394,  394,  394,
    747       394,  394,   39,  394,  395,  395,  395,  395,  395,  395,
    748       395,  395,  395,  395,  395,  395,  395,  395,  397,  397,
    749        34,  397,  397,  397,  397,   33,  397,  397,  397,  397,
    750       397,  397,  398,  398,    0,  398,  398,  398,  398,  398,
    751       398,  398,  398,  398,  398,  398,  399,  399,    0,  399,
    752       399,  399,  399,  399,  399,  399,    0,  399,  399,  399,
    753       400,  400,    0,  400,  400,  400,  400,  400,  400,  400,
    754 
    755         0,  400,  400,  400,  401,    0,    0,    0,  401,    0,
    756       401,  403,  403,    0,  403,  403,  403,  403,  403,  403,
    757       403,  403,  403,  403,  403,  404,  404,    0,  404,  404,
    758       404,  404,  404,    0,  404,  404,  404,    0,  404,  405,
    759       405,  405,  405,  405,  405,  405,  405,  405,  405,  405,
    760       405,  405,  405,  406,  406,    0,  406,  406,  406,  406,
    761       406,  406,  406,  406,  406,  406,  406,  407,  407,    0,
    762       407,    0,  407,  407,  407,    0,  407,  407,  407,  407,
    763       408,  408,    0,  408,  408,  408,  408,  408,  408,  408,
    764       408,  408,  408,  408,  409,  409,    0,  409,    0,  409,
    765 
    766       409,  409,    0,  409,  409,  409,  409,  410,  410,    0,
    767       410,  410,  410,  410,  410,  410,  410,  410,  410,  410,
    768       410,  411,  411,    0,  411,    0,    0,    0,  411,    0,
    769       411,  411,  411,  411,  411,  412,  412,    0,  412,  412,
    770       412,  412,  412,  412,  412,  412,  412,  412,  412,  413,
    771       413,    0,  413,  413,  413,  413,  413,  413,  413,  413,
    772       413,  413,  413,  416,  416,    0,  416,  416,  416,  416,
    773       416,    0,  416,  416,  416,    0,  416,  420,  420,    0,
    774       420,  420,  420,  420,  420,  420,  420,  420,  420,  420,
    775       420,  422,  422,    0,  422,  422,  422,  422,  422,  422,
    776 
    777       422,  422,  422,  422,  422,  423,  423,    0,  423,  423,
    778       423,  423,  423,  423,  423,  423,  423,  423,  423,  424,
    779       424,    0,  424,  424,  424,  424,  424,  424,  424,  424,
    780       424,  424,  424,  368,  368,  368,  368,  368,  368,  368,
    781       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    782       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    783       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    784       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    785       368,  368,  368,  368,  368,  368,  368,  368,  368,  368,
    786       368,  368,  368,  368
    787 
     479        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
     480        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
     481        1,    1,    1,    2,    3,    2,    3,    2,    4,    5,
     482        4,    5,    6,    9,    6,   10,   17,   17,   17,   23,
     483        9,   23,   10,    3,   18,   18,   18,    4,    5,  190,
     484       17,    6,    7,    7,    7,   30,   30,    7,   18,   28,
     485       37,   28,   37,    7,    7,    7,   30,    7,   36,   47,
     486       36,   47,   36,    7,    7,    7,    8,    8,    8,  189,
     487       40,    8,   40,   40,   53,  188,   53,    8,    8,    8,
     488
     489       44,    8,   44,   44,   62,  187,   62,    8,    8,    8,
     490       13,  185,   61,   13,   61,   70,   61,   70,   68,   13,
     491       68,  184,   68,   13,   74,  175,   74,   78,   78,   81,
     492       81,   85,   86,   85,   86,   85,  109,  108,   78,   13,
     493       13,   14,   14,   14,   87,   14,   87,   89,   93,   89,
     494       89,   14,   94,   94,   94,   14,   95,   95,   95,  105,
     495       92,  105,  105,  110,  110,  110,  111,  111,  111,   67,
     496       57,   14,   14,   15,   33,  120,   15,  120,   15,   15,
     497       21,  123,   15,  123,   20,   19,   15,   16,   16,   16,
     498      124,   16,  124,   16,   16,    0,  128,   16,  128,    0,
     499
     500      128,   16,   29,   29,   29,   29,   29,    0,   29,   29,
     501       29,   29,   29,   29,   29,   29,   29,   29,   29,   29,
     502       29,   29,   29,   32,   32,   32,  132,  137,  132,   32,
     503       32,   32,    0,  131,  137,  131,   32,  131,  141,  141,
     504      141,   32,   41,   41,   41,   41,   41,   41,   41,   41,
     505       41,   41,   41,   41,   41,   41,   41,   41,   41,   41,
     506       41,   41,   41,   41,   41,   41,   41,   41,   41,   41,
     507       41,   41,   41,   41,   41,   45,   45,   45,   45,   45,
     508       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
     509       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
     510
     511       45,   45,   45,   45,   45,   45,   45,   45,   77,   77,
     512        0,   77,   77,   77,   77,   77,   77,   77,  136,  136,
     513      142,  142,  142,   77,  136,  147,  147,  147,  148,  148,
     514      148,  136,  152,  152,  152,  154,  154,  154,    0,   77,
     515       77,   82,   82,   82,    0,   82,  156,  156,  156,    0,
     516        0,   82,   82,   82,  135,  135,    0,  135,  135,  135,
     517      135,  135,  135,  135,  158,  158,  158,    0,    0,  135,
     518      160,  160,  160,    0,    0,    0,    0,    0,    0,    0,
     519        0,    0,    0,    0,    0,  135,  135,  162,  162,  162,
     520      162,  162,  162,  162,  162,  162,  162,  162,  163,  163,
     521
     522      163,  163,  163,  163,  163,  163,  163,  163,  163,  164,
     523      164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
     524      165,  165,  165,  165,  165,  165,  165,  165,  165,  165,
     525      165,  166,  166,  166,  166,  166,  166,  166,  166,  166,
     526      166,  166,  167,  167,  167,  167,  167,  167,  167,  167,
     527      167,  167,  167,  168,  168,  168,  168,  168,  168,  168,
     528      168,  168,  168,  168,  169,  169,  169,  169,  169,  169,
     529      169,  169,  169,  169,  169,  170,  170,  170,  170,  170,
     530      170,  170,  170,  170,  170,  170,  171,  171,  171,  171,
     531      172,    0,  172,  172,  172,  172,  172,  172,  172,  172,
     532
     533      172,  173,    0,    0,  173,  173,  173,  173,  173,  173,
     534        0,  173,  174,    0,    0,  174,  174,  174,  174,  174,
     535      174,    0,  174,  176,    0,  176,  176,  176,    0,  176,
     536      176,  176,  176,  176,  177,    0,  177,  177,  177,  177,
     537      177,  177,  177,  177,  177,  178,    0,  178,    0,  178,
     538      178,  178,    0,  178,  178,  179,    0,  179,  179,  179,
     539      179,  179,  179,  179,  179,  179,  180,    0,  180,    0,
     540        0,  180,  180,    0,  180,  180,  180,  181,    0,  181,
     541      181,  181,  181,  181,  181,  181,  181,  181,  182,    0,
     542      182,  182,  182,  182,  182,  182,  182,  182,  182,  183,
     543
     544        0,  183,  183,  183,  183,  183,  183,  183,  183,  183,
     545      186,    0,  186,  186,  186,  186,  186,  186,  186,  186,
     546      186,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     547      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     548      161,  161,  161,  161,  161,  161,  161,  161,  161,  161,
     549      161,  161,  161,  161,  161
    788550    } ;
    789551
    790552static yy_state_type yy_last_accepting_state;
    791553static char *yy_last_accepting_cpos;
     554
     555extern int yy_flex_debug;
     556int yy_flex_debug = 1;
     557
     558static yyconst short int yy_rule_linenum[84] =
     559    {   0,
     560      313,  314,  339,  340,  341,  342,  343,  344,  346,  347,
     561      355,  356,  357,  359,  360,  361,  362,  364,  365,  367,
     562      368,  369,  378,  399,  404,  410,  411,  416,  423,  428,
     563      430,  431,  432,  433,  434,  435,  436,  437,  438,  439,
     564      440,  441,  442,  443,  448,  453,  454,  455,  460,  467,
     565      472,  474,  475,  476,  477,  478,  479,  480,  481,  482,
     566      483,  484,  489,  490,  491,  492,  497,  498,  506,  511,
     567      512,  513,  519,  525,  526,  527,  528,  530,  531,  533,
     568      543,  545,  554
     569    } ;
    792570
    793571/* The intent behind this definition is that it'll catch
     
    802580/* -*-C-*-
    803581 *
    804  * Copyright 1994 Martin von Loewis
    805  * Copyright 1998 Bertho A. Stultiens (BS)
     582 * Copyright 1998-2000  Bertho A. Stultiens (BS)
    806583 *
     584 * 21-May-2000 BS       - Fixed the ident requirement of resource names
     585 *                        which can be keywords.
     586 * 30-Apr-2000 BS       - Reintegration into the wine-tree
     587 * 11-Jan-2000 BS       - Very drastic cleanup because we don't have a
     588 *                        preprocessor in here anymore.
     589 * 02-Jan-2000 BS       - Removed the preprocessor code
     590 * 23-Dec-1999 BS       - Removed the copyright for Martin von Loewis.
     591 *                        There is really nothing left of his code in
     592 *                        this parser.
    807593 * 20-Jun-1998 BS       - Changed the filename conversion. Filenames are
    808594 *                        case-sensitive inder *nix, but not under dos.
     
    845631 *                        escaped '\0'.
    846632 */
    847 /* Exclusive rules when looking for a filename */
    848 #define yywf 1
    849 
    850 #define yywf_s 2
    851 
    852633/* Exclusive string handling */
    853 #define yystr 3
     634#define yystr 1
    854635
    855636/* Exclusive unicode string handling */
    856 #define yylstr 4
     637#define yylstr 2
    857638
    858639/* Exclusive rcdata single quoted data handling */
    859 #define yyrcd 5
     640#define yyrcd 3
    860641
    861642/* Exclusive comment eating... */
    862 #define comment 6
    863 
    864 /* Preprocessor exclusives */
    865 #define pp_incl 7
    866 
    867 #define pp_def 8
    868 
    869 #define pp_undef 9
    870 
    871 #define pp_if 10
    872 
    873 #define pp_ifdef 11
    874 
    875 #define pp_ifndef 12
    876 
    877 #define pp_elif 13
    878 
    879 #define pp_else 14
    880 
    881 #define pp_endif 15
    882 
    883 #define pp_error 16
    884 
    885 /* Set when accumulating #define's expansion text */
    886 #define pp_def_s 17
    887 
    888 /* Set when processing function type defines */
    889 #define pp_ignore 18
    890 
    891 /* Set when need to strip to eol */
    892 #define pp_ignore_eol 19
    893 
    894 /* Set when handling a false #if case */
    895 #define pp_false 20
     643#define comment 4
    896644
    897645/* Set when stripping c-junk */
    898 #define pp_stripe 21
    899 
    900 #define pp_strips 22
    901 
    902 #define pp_stripp 23
    903 
    904 #define pp_stripp_final 24
    905 
    906 /*%option stack*/
     646#define pp_stripe 5
     647
     648#define pp_strips 6
     649
     650#define pp_stripp 7
     651
     652#define pp_stripp_final 8
     653
     654/* Set when scanning #line style directives */
     655#define pp_line 9
     656
     657#define YY_STACK_USED 1
    907658#define YY_NEVER_INTERACTIVE 1
    908 /*%option noyywrap */
    909659/* Some shortcut definitions */
    910 #line 91 "parser.l"
    911 
    912 #if !defined(YY_FLEX_MAJOR_VERSION) || (1000 * YY_FLEX_MAJOR_VERSION + YY_FLEX_MINOR_VERSION < 2005)
    913 #error Must use flex version 2.5.1 or higher (yy_scan_* routines are required).
    914 #endif
     660#line 79 "parser.l"
    915661
    916662/*#define LEX_DEBUG*/
     
    922668#include <string.h>
    923669#include <ctype.h>
     670#include <assert.h>
    924671
    925672#include "wrc.h"
     
    933680#define YY_USE_PROTOS
    934681#define YY_NO_UNPUT
     682#define YY_NO_TOP_STATE
    935683
    936684/* Always update the current character position within a line */
    937 #define YY_USER_ACTION  char_number+=yyleng;
    938 
    939 raw_data_t *new_raw_data(void);
    940 
    941 void addcchar(char c);
    942 void addwchar(short s);
    943 string_t *get_buffered_cstring(void);
    944 string_t *get_buffered_wstring(void);
    945 string_t *make_string(char *s);
    946 string_t *make_filename(char *s, int len);
    947 
    948 int line_number = 1;            /* The current line */
    949 int char_number = 1;            /* The current char pos within the line */
     685#define YY_USER_ACTION  char_number+=yyleng; wanted_id = want_id; want_id = 0;
     686
     687static void addcchar(char c);
     688static void addwchar(short s);
     689static string_t *get_buffered_cstring(void);
     690static string_t *get_buffered_wstring(void);
     691static string_t *make_string(char *s);
     692
    950693static char *cbuffer;           /* Buffers for string collection */
    951694static int cbufidx;
     
    954697static int wbufidx;
    955698static int wbufalloc = 0;
    956 static int want_nl = 0;         /* Set when newline needs to go to parser */
    957 static int want_ident = 0;      /* Set is #ifdef, #ifndef or defined is seen */
    958699static int stripslevel = 0;     /* Count {} during pp_strips/pp_stripe mode */
    959700static int stripplevel = 0;     /* Count () during pp_strips mode */
    960 static char *substtext = NULL;  /* Holds the substition text while getting a define */
    961701static int cjunk_tagline;       /* Where did we start stripping (helps error tracking) */
    962702
    963 #ifdef YY_USE_STACK
    964 void push_to(int start) { yy_push_state(start); }
    965 void pop_start(void)    { yy_pop_state(start); }
    966 #else
    967 #define MAXSTARTSTACK   32
    968 static int startstack[MAXSTARTSTACK];
    969 static int startstackidx = 0;
    970 
    971 void push_to(int start)
    972 {
    973         if(yydebug)
    974                 printf("push_to(%d): %d -> %d\n", line_number, YY_START, start);
    975         if(startstackidx >= MAXSTARTSTACK-1)
    976                 internal_error(__FILE__, __LINE__, "Start condition stack overflow");
    977         startstack[startstackidx++] = YY_START;
    978         BEGIN(start);
    979 }
    980 
    981 void pop_start(void)
    982 {
    983         if(yydebug)
    984                 printf("pop_start(%d): %d <- %d\n", line_number, startstack[startstackidx-1], YY_START);
    985         if(startstackidx <= 0)
    986                 internal_error(__FILE__, __LINE__, "Start condition stack underflow");
    987         --startstackidx;
    988         BEGIN(startstack[startstackidx]);
    989 }
    990 #endif
    991 
    992 
    993 struct bufferstackentry {
    994         YY_BUFFER_STATE bufferstate;    /* Buffer to switch back to */
    995         struct pp_entry *define;        /* Points to expanding define
    996                                            or NULL if handling includes
    997                                          */
    998         int line_number;                /* Line that we were handling */
    999         int char_number;                /* The current position */
    1000         char *filename;                 /* Filename that we were handling */
    1001 };
    1002 
    1003 #define MAXBUFFERSTACK 128
    1004 static struct bufferstackentry bufferstack[MAXBUFFERSTACK];
    1005 static int bufferstackidx = 0;
    1006 
    1007 void push_buffer(YY_BUFFER_STATE buf, struct pp_entry *ppp, char *filename)
    1008 {
    1009         if(yydebug)
    1010                 printf("push_buffer: %p %p %p\n", buf, ppp, filename);
    1011         if(bufferstackidx >= MAXBUFFERSTACK-1)
    1012                 internal_error(__FILE__, __LINE__, "Buffer stack overflow");
    1013         memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
    1014         bufferstack[bufferstackidx].bufferstate = buf;
    1015         bufferstack[bufferstackidx].define = ppp;
    1016         if(ppp)
    1017                 ppp->expanding = 1;
    1018         else if(filename)
    1019         {
    1020                 /* These will track the yyerror to the correct file and line */
    1021                 bufferstack[bufferstackidx].line_number = line_number;
    1022                 bufferstack[bufferstackidx].char_number = char_number;
    1023                 line_number = 1;
    1024                 char_number = 1;
    1025                 bufferstack[bufferstackidx].filename = input_name;
    1026                 input_name = filename;
    1027         }
    1028         else
    1029                 internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
    1030         bufferstackidx++;
    1031 }
    1032 
    1033 YY_BUFFER_STATE pop_buffer(void)
    1034 {
    1035         if(bufferstackidx <= 0)
    1036                 return (YY_BUFFER_STATE)0;
    1037         bufferstackidx--;
    1038         if(bufferstack[bufferstackidx].define)
    1039                 bufferstack[bufferstackidx].define->expanding = 0;
    1040         else
    1041         {
    1042                 line_number = bufferstack[bufferstackidx].line_number;
    1043                 char_number = bufferstack[bufferstackidx].char_number;
    1044                 input_name = bufferstack[bufferstackidx].filename;
    1045                 fclose(yyin);
    1046         }
    1047         if(yydebug)
    1048                 printf("pop_buffer: %p %p (%d, %d) %p\n",
    1049                         bufferstack[bufferstackidx].bufferstate,
    1050                         bufferstack[bufferstackidx].define,
    1051                         bufferstack[bufferstackidx].line_number,
    1052                         bufferstack[bufferstackidx].char_number,
    1053                         bufferstack[bufferstackidx].filename);
    1054         yy_switch_to_buffer(bufferstack[bufferstackidx].bufferstate);
    1055         return bufferstack[bufferstackidx].bufferstate;
    1056 }
    1057 
    1058 void do_include(char *name, int namelen)
    1059 {
    1060         char *cpy = (char *)xmalloc(namelen);
    1061         strcpy(cpy, name+1);    /* strip leading " or < */
    1062         cpy[namelen-2] = '\0';  /* strip trailing " or > */
    1063         if((yyin = open_include(cpy, name[0] == '"')) == NULL)
    1064                 yyerror("Unable to open include file %s", cpy);
    1065         push_buffer(YY_CURRENT_BUFFER, NULL, cpy);
    1066         yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
    1067 }
    1068 
     703/*
     704 * This one is a bit tricky.
     705 * We set 'want_id' in the parser to get the first
     706 * identifier we get across in the scanner, but we
     707 * also want it to be reset at nearly any token we
     708 * see. Exceptions are:
     709 * - newlines
     710 * - comments
     711 * - whitespace
     712 *
     713 * The scanner will automatically reset 'want_id'
     714 * after *each* scanner reduction and puts is value
     715 * into the var below. In this way we can see the
     716 * state after the YY_RULE_SETUP (i.e. the user action;
     717 * see above) and don't have to worry too much when
     718 * it needs to be reset.
     719 */
     720static int wanted_id = 0;
     721static int save_wanted_id;      /* To save across comment reductions */
    1069722
    1070723struct keyword {
     
    1073726        int     isextension;
    1074727        int     needcase;
    1075         int     alwayskeyword;
     728        int     alwayskw;
    1076729};
    1077730
    1078731static struct keyword keywords[] = {
    1079         { "ACCELERATORS", ACCELERATORS, 0, 0, 0},
    1080         { "ALT", ALT, 0, 0, 0},
    1081         { "ASCII", ASCII, 0, 0, 0},
    1082         { "AUTO3STATE", AUTO3STATE, 1, 0, 0},
    1083         { "AUTOCHECKBOX", AUTOCHECKBOX, 1, 0, 0},
    1084         { "AUTORADIOBUTTON", AUTORADIOBUTTON, 1, 0, 0},
    1085         { "BEGIN", tBEGIN, 0, 0, 1},
    1086         { "BITMAP", tBITMAP, 0, 0, 0},
    1087         { "BLOCK", BLOCK, 0, 0, 1},
    1088         { "BUTTON", BUTTON, 1, 0, 0},
    1089         { "CAPTION", CAPTION, 0, 0, 0},
    1090         { "CHARACTERISTICS", CHARACTERISTICS, 1, 0, 0},
    1091         { "CHECKBOX", CHECKBOX, 0, 0, 0},
    1092         { "CHECKED", CHECKED, 0, 0, 0},
    1093         { "CLASS", CLASS, 0, 0, 0},
    1094         { "COMBOBOX", COMBOBOX, 0, 0, 0},
    1095         { "CONTROL", CONTROL, 0, 0, 0},
    1096         { "CTEXT", CTEXT, 0, 0, 0},
    1097         { "CURSOR", CURSOR, 0, 0, 0},
    1098         { "defined", tDEFINED, 0, 1, 1},
    1099         { "DEFPUSHBUTTON", DEFPUSHBUTTON, 0, 0, 1},
    1100         { "DIALOG", DIALOG, 0, 0, 0},
    1101         { "DIALOGEX", DIALOGEX, 1, 0, 0},
    1102         { "DISCARDABLE", DISCARDABLE, 0, 0, 0},
    1103         { "DLGINIT", DLGINIT, 0, 0, 0},
    1104         { "EDITTEXT", EDITTEXT, 0, 0, 0},
    1105         { "END", tEND, 0, 0, 1},
    1106         { "EXSTYLE", EXSTYLE, 0, 0, 0},
    1107         { "extern", tEXTERN, 0, 1, 1},
    1108         { "FILEFLAGS", FILEFLAGS, 0, 0, 0},
    1109         { "FILEFLAGSMASK", FILEFLAGSMASK, 0, 0, 0},
    1110         { "FILEOS", FILEOS, 0, 0, 0},
    1111         { "FILESUBTYPE", FILESUBTYPE, 0, 0, 0},
    1112         { "FILETYPE", FILETYPE, 0, 0, 0},
    1113         { "FILEVERSION", FILEVERSION, 0, 0, 0},
    1114         { "FIXED", tFIXED, 0, 0, 0},
    1115         { "FONT", FONT, 0, 0, 0},
    1116         { "GRAYED", GRAYED, 0, 0, 0},
    1117         { "GROUPBOX", GROUPBOX, 0, 0, 0},
    1118         { "HELP", HELP, 0, 0, 0},
    1119         { "ICON", ICON, 0, 0, 0},
    1120         { "IMPURE", IMPURE, 0, 0, 0},
    1121         { "INACTIVE", INACTIVE, 0, 0, 0},
    1122         { "LANGUAGE", LANGUAGE, 1, 0, 1},
    1123         { "LISTBOX", LISTBOX, 0, 0, 0},
    1124         { "LOADONCALL", LOADONCALL, 0, 0, 0},
    1125         { "LTEXT", LTEXT, 0, 0, 0},
    1126         { "MENU", MENU, 0, 0, 0},
    1127         { "MENUBARBREAK", MENUBARBREAK, 0, 0, 0},
    1128         { "MENUBREAK", MENUBREAK, 0, 0, 0},
    1129         { "MENUEX", MENUEX, 1, 0, 0},
    1130         { "MENUITEM", MENUITEM, 0, 0, 0},
    1131         { "MESSAGETABLE", MESSAGETABLE, 1, 0, 0},
    1132         { "MOVEABLE", MOVEABLE, 0, 0, 0},
    1133         { "NOINVERT", NOINVERT, 0, 0, 0},
    1134         { "NOT", NOT, 0, 0, 0},
    1135         { "POPUP", POPUP, 0, 0, 0},
    1136         { "PRELOAD", PRELOAD, 0, 0, 0},
    1137         { "PRODUCTVERSION", PRODUCTVERSION, 0, 0, 0},
    1138         { "PURE", tPURE, 0, 0, 0},
    1139         { "PUSHBUTTON", PUSHBUTTON, 0, 0, 0},
    1140         { "RADIOBUTTON", RADIOBUTTON, 0, 0, 0},
    1141         { "RCDATA", RCDATA, 0, 0, 0},
    1142         { "RTEXT", RTEXT, 0, 0, 0},
    1143         { "SCROLLBAR", SCROLLBAR, 0, 0, 0},
    1144         { "SEPARATOR", SEPARATOR, 0, 0, 0},
    1145         { "SHIFT", SHIFT, 0, 0, 0},
    1146         { "STATE3", STATE3, 1, 0, 0},
    1147         { "STRING", tSTRING, 0, 0, 0},
    1148         { "STRINGTABLE", STRINGTABLE, 0, 0, 1},
    1149         { "STYLE", STYLE, 0, 0, 0},
    1150         { "TOOLBAR", TOOLBAR, 1, 0, 0},
    1151         { "typedef", tTYPEDEF, 0, 1, 1},
    1152         { "VALUE", VALUE, 0, 0, 0},
    1153         { "VERSION", VERSION, 1, 0, 0},
    1154         { "VERSIONINFO", VERSIONINFO, 0, 0, 0},
    1155         { "VIRTKEY", VIRTKEY, 0, 0, 0}
     732        { "ACCELERATORS",       tACCELERATORS,          0, 0, 0},
     733        { "ALT",                tALT,                   0, 0, 0},
     734        { "ASCII",              tASCII,                 0, 0, 0},
     735        { "AUTO3STATE",         tAUTO3STATE,            1, 0, 0},
     736        { "AUTOCHECKBOX",       tAUTOCHECKBOX,          1, 0, 0},
     737        { "AUTORADIOBUTTON",    tAUTORADIOBUTTON,       1, 0, 0},
     738        { "BEGIN",              tBEGIN,                 0, 0, 0},
     739        { "BITMAP",             tBITMAP,                0, 0, 0},
     740        { "BLOCK",              tBLOCK,                 0, 0, 0},
     741        { "BUTTON",             tBUTTON,                1, 0, 0},
     742        { "CAPTION",            tCAPTION,               0, 0, 0},
     743        { "CHARACTERISTICS",    tCHARACTERISTICS,       1, 0, 0},
     744        { "CHECKBOX",           tCHECKBOX,              0, 0, 0},
     745        { "CHECKED",            tCHECKED,               0, 0, 0},
     746        { "CLASS",              tCLASS,                 0, 0, 0},
     747        { "COMBOBOX",           tCOMBOBOX,              0, 0, 0},
     748        { "CONTROL",            tCONTROL,               0, 0, 0},
     749        { "CTEXT",              tCTEXT,                 0, 0, 0},
     750        { "CURSOR",             tCURSOR,                0, 0, 0},
     751        { "DEFPUSHBUTTON",      tDEFPUSHBUTTON,         0, 0, 0},
     752        { "DIALOG",             tDIALOG,                0, 0, 0},
     753        { "DIALOGEX",           tDIALOGEX,              1, 0, 0},
     754        { "DISCARDABLE",        tDISCARDABLE,           0, 0, 0},
     755        { "DLGINIT",            tDLGINIT,               0, 0, 0},
     756        { "EDITTEXT",           tEDITTEXT,              0, 0, 0},
     757        { "END",                tEND,                   0, 0, 0},
     758        { "enum",               tENUM,                  0, 1, 1},
     759        { "EXSTYLE",            tEXSTYLE,               0, 0, 0},
     760        { "extern",             tEXTERN,                0, 1, 1},
     761        { "FILEFLAGS",          tFILEFLAGS,             0, 0, 0},
     762        { "FILEFLAGSMASK",      tFILEFLAGSMASK,         0, 0, 0},
     763        { "FILEOS",             tFILEOS,                0, 0, 0},
     764        { "FILESUBTYPE",        tFILESUBTYPE,           0, 0, 0},
     765        { "FILETYPE",           tFILETYPE,              0, 0, 0},
     766        { "FILEVERSION",        tFILEVERSION,           0, 0, 0},
     767        { "FIXED",              tFIXED,                 0, 0, 0},
     768        { "FONT",               tFONT,                  0, 0, 0},
     769        { "FONTDIR",            tFONTDIR,               0, 0, 0},       /* This is a Borland BRC extension */
     770        { "GRAYED",             tGRAYED,                0, 0, 0},
     771        { "GROUPBOX",           tGROUPBOX,              0, 0, 0},
     772        { "HELP",               tHELP,                  0, 0, 0},
     773        { "ICON",               tICON,                  0, 0, 0},
     774        { "IMPURE",             tIMPURE,                0, 0, 0},
     775        { "INACTIVE",           tINACTIVE,              0, 0, 0},
     776        { "inline",             tINLINE,                0, 1, 1},
     777        { "LANGUAGE",           tLANGUAGE,              1, 0, 1},
     778        { "LISTBOX",            tLISTBOX,               0, 0, 0},
     779        { "LOADONCALL",         tLOADONCALL,            0, 0, 0},
     780        { "LTEXT",              tLTEXT,                 0, 0, 0},
     781        { "MENU",               tMENU,                  0, 0, 0},
     782        { "MENUBARBREAK",       tMENUBARBREAK,          0, 0, 0},
     783        { "MENUBREAK",          tMENUBREAK,             0, 0, 0},
     784        { "MENUEX",             tMENUEX,                1, 0, 0},
     785        { "MENUITEM",           tMENUITEM,              0, 0, 0},
     786        { "MESSAGETABLE",       tMESSAGETABLE,          1, 0, 0},
     787        { "MOVEABLE",           tMOVEABLE,              0, 0, 0},
     788        { "NOINVERT",           tNOINVERT,              0, 0, 0},
     789        { "NOT",                tNOT,                   0, 0, 0},
     790        { "POPUP",              tPOPUP,                 0, 0, 0},
     791        { "PRELOAD",            tPRELOAD,               0, 0, 0},
     792        { "PRODUCTVERSION",     tPRODUCTVERSION,        0, 0, 0},
     793        { "PURE",               tPURE,                  0, 0, 0},
     794        { "PUSHBUTTON",         tPUSHBUTTON,            0, 0, 0},
     795        { "RADIOBUTTON",        tRADIOBUTTON,           0, 0, 0},
     796        { "RCDATA",             tRCDATA,                0, 0, 0},
     797        { "RTEXT",              tRTEXT,                 0, 0, 0},
     798        { "SCROLLBAR",          tSCROLLBAR,             0, 0, 0},
     799        { "SEPARATOR",          tSEPARATOR,             0, 0, 0},
     800        { "SHIFT",              tSHIFT,                 0, 0, 0},
     801        { "STATE3",             tSTATE3,                1, 0, 0},
     802        { "static",             tSTATIC,                0, 1, 1},
     803        { "STRING",             tSTRING,                0, 0, 0},
     804        { "STRINGTABLE",        tSTRINGTABLE,           0, 0, 1},
     805        { "struct",             tSTRUCT,                0, 1, 1},
     806        { "STYLE",              tSTYLE,                 0, 0, 0},
     807        { "TOOLBAR",            tTOOLBAR,               1, 0, 0},
     808        { "typedef",            tTYPEDEF,               0, 1, 1},
     809        { "VALUE",              tVALUE,                 0, 0, 0},
     810        { "VERSION",            tVERSION,               1, 0, 0},
     811        { "VERSIONINFO",        tVERSIONINFO,           0, 0, 0},
     812        { "VIRTKEY",            tVIRTKEY,               0, 0, 0}
    1156813};
    1157814
    1158815#define NKEYWORDS       (sizeof(keywords)/sizeof(keywords[0]))
    1159816#define KWP(p)          ((struct keyword *)(p))
    1160 int kw_cmp_func(const void *s1, const void *s2)
     817static int kw_cmp_func(const void *s1, const void *s2)
    1161818{
    1162819        int ret;
     
    1170827#define KW_BSEARCH
    1171828#define DO_SORT
    1172 struct keyword *iskeyword(char *kw)
     829static struct keyword *iskeyword(char *kw)
    1173830{
    1174831        struct keyword *kwp;
     
    1204861#endif
    1205862
    1206 #ifdef LEX_DEBUG
    1207         if(kwp && !strcmp(kwp->keyword, "LANGUAGE"))
    1208                 printf("Got Language\n");
    1209 #endif
    1210863        if(kwp == NULL || (kwp->isextension && !extensions))
    1211864                return NULL;
     
    1214867}
    1215868
    1216 void add_to_substtext(char *text, int len)
    1217 {
    1218         if(!substtext)
    1219         {
    1220                 substtext = xstrdup(text);
    1221         }
    1222         else
    1223         {
    1224                 substtext = (char *)xrealloc(substtext, strlen(substtext)+len+1);
    1225                 strcat(substtext, text);
    1226         }
    1227 }
    1228 
    1229 #line 1230 "lexyy.c"
     869/*
     870 **************************************************************************
     871 * The flexer starts here
     872 **************************************************************************
     873 */
     874#line 875 "lexyy.c"
    1230875
    1231876/* Macros after this point can all be overridden by user definitions in
     
    13771022        register int yy_act;
    13781023
    1379 #line 411 "parser.l"
    1380 
    1381         /* #include handling */
    1382 #line 1383 "lexyy.c"
     1024#line 294 "parser.l"
     1025
     1026        /*
     1027         * Catch the GCC-style line statements here and parse them.
     1028         * This has the advantage that you can #include at any
     1029         * stage in the resource file.
     1030         * The preprocessor generates line directives in the format:
     1031         * # <linenum> "filename" <codes>
     1032         *
     1033         * Codes can be a sequence of:
     1034         * - 1 start of new file
     1035         * - 2 returning to previous
     1036         * - 3 system header
     1037         * - 4 interpret as C-code
     1038         *
     1039         * 4 is not used and 1 mutually excludes 2
     1040         * Anyhow, we are not really interested in these at all
     1041         * because we only want to know the linenumber and
     1042         * filename.
     1043         */
     1044#line 1045 "lexyy.c"
    13831045
    13841046        if ( yy_init )
     
    14321094                                {
    14331095                                yy_current_state = (int) yy_def[yy_current_state];
    1434                                 if ( yy_current_state >= 369 )
     1096                                if ( yy_current_state >= 162 )
    14351097                                        yy_c = yy_meta[(unsigned int) yy_c];
    14361098                                }
     
    14381100                        ++yy_cp;
    14391101                        }
    1440                 while ( yy_base[yy_current_state] != 1334 );
     1102                while ( yy_base[yy_current_state] != 622 );
    14411103
    14421104yy_find_action:
     
    14541116do_action:      /* This label is used only to access EOF actions. */
    14551117
     1118                if ( yy_flex_debug )
     1119                        {
     1120                        if ( yy_act == 0 )
     1121                                fprintf( stderr, "--scanner backing up\n" );
     1122                        else if ( yy_act < 84 )
     1123                                fprintf( stderr, "--accepting rule at line %d (\"%s\")\n",
     1124                                         yy_rule_linenum[yy_act], yytext );
     1125                        else if ( yy_act == 84 )
     1126                                fprintf( stderr, "--accepting default rule (\"%s\")\n",
     1127                                         yytext );
     1128                        else if ( yy_act == 85 )
     1129                                fprintf( stderr, "--(end of buffer or a NUL)\n" );
     1130                        else
     1131                                fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
     1132                        }
    14561133
    14571134                switch ( yy_act )
     
    14661143case 1:
    14671144YY_RULE_SETUP
    1468 #line 413 "parser.l"
    1469 push_to(pp_incl);
     1145#line 313 "parser.l"
     1146yy_push_state(pp_line);
    14701147        YY_BREAK
    14711148case 2:
    14721149YY_RULE_SETUP
    1473 #line 414 "parser.l"
    1474 do_include(yytext, yyleng); pop_start();
    1475         YY_BREAK
     1150#line 314 "parser.l"
     1151{
     1152                int lineno;
     1153                char *cptr;
     1154                char *fname;
     1155                yy_pop_state();
     1156                lineno = (int)strtol(yytext, &cptr, 10);
     1157                if(!lineno)
     1158                        yyerror("Malformed '#...' line-directive; invalid linenumber");
     1159                fname = strchr(cptr, '"');
     1160                if(!fname)
     1161                        yyerror("Malformed '#...' line-directive; missing filename");
     1162                fname++;
     1163                cptr = strchr(fname, '"');
     1164                if(!cptr)
     1165                        yyerror("Malformed '#...' line-directive; missing terminating \"");
     1166                *cptr = '\0';
     1167                line_number = lineno - 1;       /* We didn't read the newline */
     1168                input_name = xstrdup(fname);
     1169        }
     1170        YY_BREAK
     1171/*
     1172         * Strip everything until a ';' taking
     1173         * into account braces {} for structures,
     1174         * classes and enums.
     1175         */
    14761176case 3:
    14771177YY_RULE_SETUP
    1478 #line 415 "parser.l"
    1479 do_include(yytext, yyleng); pop_start();
     1178#line 339 "parser.l"
     1179stripslevel++;
    14801180        YY_BREAK
    14811181case 4:
    14821182YY_RULE_SETUP
    1483 #line 416 "parser.l"
    1484 yyerror("Malformed #include");
    1485         YY_BREAK
    1486 /* #define handling */
     1183#line 340 "parser.l"
     1184stripslevel--;
     1185        YY_BREAK
    14871186case 5:
    14881187YY_RULE_SETUP
    1489 #line 419 "parser.l"
    1490 push_to(pp_def);
     1188#line 341 "parser.l"
     1189if(!stripslevel) yy_pop_state();
    14911190        YY_BREAK
    14921191case 6:
    14931192YY_RULE_SETUP
    1494 #line 420 "parser.l"
     1193#line 342 "parser.l"
     1194; /* To catch comments */
     1195        YY_BREAK
     1196case 7:
     1197YY_RULE_SETUP
     1198#line 343 "parser.l"
     1199; /* Ignore rest */
     1200        YY_BREAK
     1201case 8:
     1202YY_RULE_SETUP
     1203#line 344 "parser.l"
     1204line_number++; char_number = 1;
     1205        YY_BREAK
     1206case 9:
     1207YY_RULE_SETUP
     1208#line 346 "parser.l"
     1209stripplevel++;
     1210        YY_BREAK
     1211case 10:
     1212YY_RULE_SETUP
     1213#line 347 "parser.l"
    14951214{
    1496                                 set_define(yytext);
    1497                                 push_to(pp_def_s);
    1498                         }
    1499         YY_BREAK
    1500 case 7:
    1501 YY_RULE_SETUP
    1502 #line 424 "parser.l"
    1503 push_to(pp_ignore); /* Ignore function-like defines for now*/
    1504         YY_BREAK
    1505 case 8:
    1506 YY_RULE_SETUP
    1507 #line 425 "parser.l"
    1508 yyerror("Malformed #define");
    1509         YY_BREAK
    1510 case 9:
    1511 YY_RULE_SETUP
    1512 #line 427 "parser.l"
    1513 {
    1514                         if(YY_START == pp_def_s)
    1515                                 add_to_substtext(yytext, yyleng);
    1516                 }
    1517         YY_BREAK
    1518 case 10:
    1519 YY_RULE_SETUP
    1520 #line 431 "parser.l"
    1521 { /* Comment is handled in normal handling */
    1522                         if(YY_START == pp_def_s)
    1523                                 add_to_substtext(yytext, yyleng);
    1524                 }
    1525         YY_BREAK
    1526 case 11:
    1527 YY_RULE_SETUP
    1528 #line 435 "parser.l"
    1529 line_number++;  char_number = 1; /* Line continuation */
    1530         YY_BREAK
    1531 case 12:
    1532 YY_RULE_SETUP
    1533 #line 436 "parser.l"
    1534 {
    1535                         if(YY_START == pp_def_s)
    1536                         {
    1537                                 add_define(substtext ? substtext : "");
    1538                                 free(substtext);
    1539                                 substtext = NULL;
    1540                         }
    1541                         line_number++;
    1542                         char_number = 1;
    1543                         pop_start();
    1544                         pop_start();
    1545                 }
    1546         YY_BREAK
    1547 /* #undef handling */
    1548 case 13:
    1549 YY_RULE_SETUP
    1550 #line 450 "parser.l"
    1551 push_to(pp_undef);
    1552         YY_BREAK
    1553 case 14:
    1554 YY_RULE_SETUP
    1555 #line 451 "parser.l"
    1556 {
    1557                                 del_define(yytext);
    1558                                 pop_start();
    1559                                 /*push_to(pp_ignore);*/
    1560                         }
    1561         YY_BREAK
    1562 /* Conditional handling */
    1563 case 15:
    1564 YY_RULE_SETUP
    1565 #line 458 "parser.l"
    1566 {
    1567                         if(YY_START == pp_false)
    1568                         {
    1569                                 if(yydebug)
    1570                                         printf("(%d)#if ignored\n", line_number);
    1571                                 push_if(0, 0, 1);
    1572                                 push_to(pp_ignore_eol);
    1573                         }
    1574                         else
    1575                         {
    1576                                 push_to(INITIAL);
    1577                                 want_nl = 1;
    1578                                 return tIF;
    1579                         }
    1580                 }
    1581         YY_BREAK
    1582 case 16:
    1583 YY_RULE_SETUP
    1584 #line 473 "parser.l"
    1585 {
    1586                         if(YY_START == pp_false)
    1587                         {
    1588                                 if(yydebug)
    1589                                         printf("(%d)#ifdef ignored\n", line_number);
    1590                                 push_if(0, 0, 1);
    1591                                 push_to(pp_ignore_eol);
    1592                         }
    1593                         else
    1594                         {
    1595                                 push_to(INITIAL);
    1596                                 want_nl = 1;
    1597                                 want_ident = 1;
    1598                                 return tIFDEF;
    1599                         }
    1600                 }
    1601         YY_BREAK
    1602 case 17:
    1603 YY_RULE_SETUP
    1604 #line 489 "parser.l"
    1605 {
    1606                         if(YY_START == pp_false)
    1607                         {
    1608                                 if(yydebug)
    1609                                         printf("(%d)#ifndef ignored\n", line_number);
    1610                                 push_if(0, 0, 1);
    1611                                 push_to(pp_ignore_eol);
    1612                         }
    1613                         else
    1614                         {
    1615                                 push_to(INITIAL);
    1616                                 want_nl = 1;
    1617                                 want_ident = 1;
    1618                                 return tIFNDEF;
    1619                         }
    1620                 }
    1621         YY_BREAK
    1622 case 18:
    1623 YY_RULE_SETUP
    1624 #line 505 "parser.l"
    1625 {
    1626                         if(!isnevertrue_if())
    1627                         {
    1628                                 push_to(INITIAL);
    1629                                 want_nl = 1;
    1630                                 return tELIF;
    1631                         }
    1632                         else if(YY_START == pp_false)
    1633                                 push_to(pp_ignore_eol);
    1634                         if(yydebug)
    1635                                 printf("(%d)#elif ignored\n", line_number);
    1636                 }
    1637         YY_BREAK
    1638 case 19:
    1639 YY_RULE_SETUP
    1640 #line 517 "parser.l"
    1641 {
    1642                         if(!isnevertrue_if())
    1643                         {
    1644                                 push_to(INITIAL);
    1645                                 want_nl = 1;
    1646                                 return tELSE;
    1647                         }
    1648                         if(yydebug)
    1649                                 printf("(%d)#else ignored\n", line_number);
    1650                 }
    1651         YY_BREAK
    1652 case 20:
    1653 YY_RULE_SETUP
    1654 #line 527 "parser.l"
    1655 {
    1656                         if(!isnevertrue_if())
    1657                         {
    1658                                 want_nl = 1;
    1659                                 return tENDIF;
    1660                         }
    1661                         else
    1662                         {
    1663                                 if(yydebug)
    1664                                         printf("(%d)#endif ignored\n", line_number);
    1665                                 pop_if();
    1666                         }
    1667                 }
    1668         YY_BREAK
    1669 /* The error directive */
    1670 case 21:
    1671 YY_RULE_SETUP
    1672 #line 542 "parser.l"
    1673 push_to(pp_error);
    1674         YY_BREAK
    1675 case 22:
    1676 YY_RULE_SETUP
    1677 #line 543 "parser.l"
    1678 yyerror("Error directive: %s", yytext);
    1679         YY_BREAK
    1680 case 23:
    1681 YY_RULE_SETUP
    1682 #line 544 "parser.l"
    1683 {
    1684                         if(yydebug)
    1685                                 printf("(%d)#error ignored\n", line_number);
    1686                 }
    1687         YY_BREAK
    1688 /* preprocessor junk */
    1689 case 24:
    1690 YY_RULE_SETUP
    1691 #line 550 "parser.l"
    1692 ;       /* Ignore #pragma */
    1693         YY_BREAK
    1694 case 25:
    1695 YY_RULE_SETUP
    1696 #line 551 "parser.l"
    1697 ;       /* Ignore #ident */
    1698         YY_BREAK
    1699 case 26:
    1700 YY_RULE_SETUP
    1701 #line 552 "parser.l"
    1702 ;       /* Ignore #line */
    1703         YY_BREAK
    1704 /* We'll get an error on malformed #xxx statements
    1705   * by not recognising '#' at all. This helps tracking
    1706   * preprocessor errors.
    1707   */
    1708 /*^{ws}*#{ws}*                  ;        Ignore # */
    1709 case 27:
    1710 YY_RULE_SETUP
    1711 #line 559 "parser.l"
    1712 stripslevel++;
    1713         YY_BREAK
    1714 case 28:
    1715 YY_RULE_SETUP
    1716 #line 560 "parser.l"
    1717 stripslevel--;
    1718         YY_BREAK
    1719 case 29:
    1720 YY_RULE_SETUP
    1721 #line 561 "parser.l"
    1722 if(!stripslevel) pop_start();
    1723         YY_BREAK
    1724 case 30:
    1725 YY_RULE_SETUP
    1726 #line 562 "parser.l"
    1727 ; /* To catch comments */
    1728         YY_BREAK
    1729 case 31:
    1730 YY_RULE_SETUP
    1731 #line 563 "parser.l"
    1732 ; /* Ignore rest */
    1733         YY_BREAK
    1734 case 32:
    1735 YY_RULE_SETUP
    1736 #line 565 "parser.l"
    1737 stripslevel++;
    1738         YY_BREAK
    1739 case 33:
    1740 YY_RULE_SETUP
    1741 #line 566 "parser.l"
    1742 {
    1743                         stripslevel--;
    1744                         if(!stripslevel) pop_start();
    1745                 }
    1746         YY_BREAK
    1747 case 34:
    1748 YY_RULE_SETUP
    1749 #line 570 "parser.l"
    1750 if(!stripslevel) pop_start();
    1751         YY_BREAK
    1752 case 35:
    1753 YY_RULE_SETUP
    1754 #line 571 "parser.l"
    1755 ; /* To catch comments */
    1756         YY_BREAK
    1757 case 36:
    1758 YY_RULE_SETUP
    1759 #line 572 "parser.l"
    1760 ; /* Ignore rest */
    1761         YY_BREAK
    1762 case 37:
    1763 YY_RULE_SETUP
    1764 #line 574 "parser.l"
    1765 stripplevel++;
    1766         YY_BREAK
    1767 case 38:
    1768 YY_RULE_SETUP
    1769 #line 575 "parser.l"
    1770 {
    1771                                 stripplevel--;
    1772                                 if(!stripplevel)
    1773                                 {
    1774                                         pop_start();
    1775                                         push_to(pp_stripp_final);
    1776                                 }
    1777                         }
    1778         YY_BREAK
    1779 case 39:
    1780 YY_RULE_SETUP
    1781 #line 583 "parser.l"
    1782 ; /* To catch comments */
    1783         YY_BREAK
    1784 case 40:
    1785 YY_RULE_SETUP
    1786 #line 584 "parser.l"
    1787 ; /* Ignore rest */
    1788         YY_BREAK
    1789 case 41:
    1790 YY_RULE_SETUP
    1791 #line 586 "parser.l"
    1792 ; /* Ignore */
    1793         YY_BREAK
    1794 case 42:
    1795 YY_RULE_SETUP
    1796 #line 587 "parser.l"
    1797 pop_start(); /* Kill the semicolon */
    1798         YY_BREAK
    1799 case 43:
    1800 YY_RULE_SETUP
    1801 #line 588 "parser.l"
    1802 line_number++; char_number = 1; pop_start();
    1803         YY_BREAK
    1804 case 44:
    1805 YY_RULE_SETUP
    1806 #line 589 "parser.l"
    1807 yyless(0); pop_start();
    1808         YY_BREAK
    1809 case 45:
    1810 YY_RULE_SETUP
    1811 #line 591 "parser.l"
    1812 ;       /* Ignore everything except #xxx during false #if state */
    1813         YY_BREAK
    1814 case 46:
    1815 YY_RULE_SETUP
    1816 #line 593 "parser.l"
    1817 pop_start();
    1818         YY_BREAK
    1819 /* These are special cases due to filename scanning */
    1820 case 47:
    1821 YY_RULE_SETUP
    1822 #line 596 "parser.l"
    1823 return DISCARDABLE;
    1824         YY_BREAK
    1825 case 48:
    1826 YY_RULE_SETUP
    1827 #line 597 "parser.l"
    1828 return tFIXED;
    1829         YY_BREAK
    1830 case 49:
    1831 YY_RULE_SETUP
    1832 #line 598 "parser.l"
    1833 return IMPURE;
    1834         YY_BREAK
    1835 case 50:
    1836 YY_RULE_SETUP
    1837 #line 599 "parser.l"
    1838 return MOVEABLE;
    1839         YY_BREAK
    1840 case 51:
    1841 YY_RULE_SETUP
    1842 #line 600 "parser.l"
    1843 return LOADONCALL;
    1844         YY_BREAK
    1845 case 52:
    1846 YY_RULE_SETUP
    1847 #line 601 "parser.l"
    1848 return PRELOAD;
    1849         YY_BREAK
    1850 case 53:
    1851 YY_RULE_SETUP
    1852 #line 602 "parser.l"
    1853 return tPURE;
    1854         YY_BREAK
    1855 case 54:
    1856 YY_RULE_SETUP
    1857 #line 604 "parser.l"
    1858 return tBEGIN;
    1859         YY_BREAK
    1860 case 55:
    1861 YY_RULE_SETUP
    1862 #line 605 "parser.l"
    1863 return tEND;
    1864         YY_BREAK
    1865 case 56:
    1866 YY_RULE_SETUP
    1867 #line 607 "parser.l"
    1868 { yylval.num = strtoul(yytext,  0, 10); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
    1869         YY_BREAK
    1870 case 57:
    1871 YY_RULE_SETUP
    1872 #line 608 "parser.l"
    1873 { yylval.num = strtoul(yytext,  0, 16); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
    1874         YY_BREAK
    1875 case 58:
    1876 YY_RULE_SETUP
    1877 #line 609 "parser.l"
    1878 { yylval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
    1879         YY_BREAK
    1880 case 59:
    1881 YY_RULE_SETUP
    1882 #line 610 "parser.l"
    1883 {
    1884                                 struct keyword *token;
    1885                                 struct pp_entry *ppp;
    1886 
    1887                                 want_rscname = 0;
    1888                                
    1889                                 if(want_ident)
    1890                                 {
    1891                                         /* Prevent preprocessor subst */
    1892                                         want_ident = 0;
    1893                                         yylval.str = make_string(yytext);
    1894                                 #ifdef LEX_DEBUG
    1895                                         printf("want IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
    1896                                 #endif
    1897                                         return IDENT;
    1898                                 }
    1899                                 else if((ppp = pp_lookup(yytext)) != NULL)
    1900                                 {
    1901                                         /* Do preprocessor substitution,
    1902                                          * but expand only if macro is not
    1903                                          * already expanding.
    1904                                          */
    1905                                         if(!ppp->expanding)
     1215                                        stripplevel--;
     1216                                        if(!stripplevel)
    19061217                                        {
    1907                                 #ifdef LEX_DEBUG
    1908                                                 printf("expand IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
    1909                                 #endif
    1910                                                 push_buffer(YY_CURRENT_BUFFER, ppp, NULL);
    1911                                                 yy_scan_string(ppp->subst);
     1218                                                yy_pop_state();
     1219                                                yy_push_state(pp_stripp_final);
    19121220                                        }
    19131221                                }
    1914                                 else if((token = iskeyword(yytext)) != NULL
    1915                                   && !(!token->alwayskeyword && want_rscname))
     1222        YY_BREAK
     1223case 11:
     1224YY_RULE_SETUP
     1225#line 355 "parser.l"
     1226; /* To catch comments */
     1227        YY_BREAK
     1228case 12:
     1229YY_RULE_SETUP
     1230#line 356 "parser.l"
     1231; /* Ignore rest */
     1232        YY_BREAK
     1233case 13:
     1234YY_RULE_SETUP
     1235#line 357 "parser.l"
     1236line_number++; char_number = 1;
     1237        YY_BREAK
     1238case 14:
     1239YY_RULE_SETUP
     1240#line 359 "parser.l"
     1241; /* Ignore */
     1242        YY_BREAK
     1243case 15:
     1244YY_RULE_SETUP
     1245#line 360 "parser.l"
     1246yy_pop_state(); /* Kill the semicolon */
     1247        YY_BREAK
     1248case 16:
     1249YY_RULE_SETUP
     1250#line 361 "parser.l"
     1251line_number++; char_number = 1; yy_pop_state();
     1252        YY_BREAK
     1253case 17:
     1254YY_RULE_SETUP
     1255#line 362 "parser.l"
     1256yyless(0); yy_pop_state();
     1257        YY_BREAK
     1258case 18:
     1259YY_RULE_SETUP
     1260#line 364 "parser.l"
     1261return tBEGIN;
     1262        YY_BREAK
     1263case 19:
     1264YY_RULE_SETUP
     1265#line 365 "parser.l"
     1266return tEND;
     1267        YY_BREAK
     1268case 20:
     1269YY_RULE_SETUP
     1270#line 367 "parser.l"
     1271{ yylval.num = strtoul(yytext,  0, 10); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     1272        YY_BREAK
     1273case 21:
     1274YY_RULE_SETUP
     1275#line 368 "parser.l"
     1276{ yylval.num = strtoul(yytext,  0, 16); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     1277        YY_BREAK
     1278case 22:
     1279YY_RULE_SETUP
     1280#line 369 "parser.l"
     1281{ yylval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     1282        YY_BREAK
     1283/*
     1284         * The next two rules scan identifiers and filenames.
     1285         * This is achieved by using the priority ruling
     1286         * of the scanner where a '.' is valid in a filename
     1287         * and *only* in a filename. In this case, the second
     1288         * rule will be reduced because it is longer.
     1289         */
     1290case 23:
     1291YY_RULE_SETUP
     1292#line 378 "parser.l"
     1293{
     1294                                struct keyword *tok = iskeyword(yytext);
     1295
     1296                                if(tok)
    19161297                                {
    1917                                         switch(token->token)
     1298                                        if(tok->token == tCLASS && !strcmp(yytext, "class"))
     1299                                                return tCPPCLASS;
     1300                                        else if(wanted_id && !tok->alwayskw)
    19181301                                        {
    1919                                         case tDEFINED:
    1920                                                 want_ident = 1;
    1921                                                 break;
    1922                                         /*case RCDATA:*/
    1923                                         case CURSOR:
    1924                                         case tBITMAP:
    1925                                         case MESSAGETABLE:
    1926                                         case DLGINIT:
    1927                                                 push_to(yywf);
    1928                                                 break;
    1929                                         case FONT:
    1930                                         case ICON:
    1931                                                 if(!indialog)
    1932                                                         push_to(yywf);
    1933                                                 break;
    1934                                         case DIALOG:
    1935                                         case DIALOGEX:
    1936                                                 indialog = 1;
    1937                                                 break;
     1302                                                yylval.str = make_string(yytext);
     1303                                                return tIDENT;
    19381304                                        }
    1939                                         return token->token;
     1305                                        else
     1306                                                return tok->token;
    19401307                                }
    19411308                                else
    19421309                                {
    19431310                                        yylval.str = make_string(yytext);
    1944                                 #ifdef LEX_DEBUG
    1945                                         printf("%s IDENT (%s, %d, %d): <%s>\n",
    1946                                                 want_rscname ? "rscname" : "just",
    1947                                                 input_name,
    1948                                                 line_number,
    1949                                                 char_number,
    1950                                                 yytext);
    1951                                 #endif
    1952                                         return IDENT;
     1311                                        return tIDENT;
    19531312                                }
    19541313                        }
    19551314        YY_BREAK
    1956 case 60:
    1957 YY_RULE_SETUP
    1958 #line 682 "parser.l"
    1959 return LOGOR;
    1960         YY_BREAK
    1961 case 61:
    1962 YY_RULE_SETUP
    1963 #line 683 "parser.l"
    1964 return LOGAND;
    1965         YY_BREAK
    1966 case 62:
    1967 YY_RULE_SETUP
    1968 #line 684 "parser.l"
    1969 return EQ;
    1970         YY_BREAK
    1971 case 63:
    1972 YY_RULE_SETUP
    1973 #line 685 "parser.l"
    1974 return NE;
    1975         YY_BREAK
    1976 case 64:
    1977 YY_RULE_SETUP
    1978 #line 686 "parser.l"
    1979 return LTE;
    1980         YY_BREAK
    1981 case 65:
    1982 YY_RULE_SETUP
    1983 #line 687 "parser.l"
    1984 return GTE;
    1985         YY_BREAK
    1986 case 66:
    1987 YY_RULE_SETUP
    1988 #line 689 "parser.l"
    1989 { pop_start(); yylval.str = make_filename(yytext, yyleng); return FILENAME; }
    1990         YY_BREAK
    1991 case 67:
    1992 YY_RULE_SETUP
    1993 #line 690 "parser.l"
    1994 push_to(yywf_s);
    1995         YY_BREAK
    1996 case 68:
    1997 YY_RULE_SETUP
    1998 #line 691 "parser.l"
    1999 { pop_start(); pop_start(); yylval.str = make_filename(yytext, yyleng-1); return FILENAME; }
    2000         YY_BREAK
    2001 case 69:
    2002 YY_RULE_SETUP
    2003 #line 692 "parser.l"
    2004 yyerror("Newline in filename");
    2005         YY_BREAK
    2006 case 70:
    2007 YY_RULE_SETUP
    2008 #line 694 "parser.l"
     1315case 24:
     1316YY_RULE_SETUP
     1317#line 399 "parser.l"
     1318yylval.str = make_string(yytext); return tFILENAME;
     1319        YY_BREAK
     1320/*
     1321         * Wide string scanning
     1322         */
     1323case 25:
     1324YY_RULE_SETUP
     1325#line 404 "parser.l"
    20091326{
    2010                                 push_to(yylstr);
     1327                                yy_push_state(yylstr);
    20111328                                wbufidx = 0;
    20121329                                if(!win32)
     
    20141331                        }
    20151332        YY_BREAK
    2016 case 71:
    2017 YY_RULE_SETUP
    2018 #line 700 "parser.l"
     1333case 26:
     1334#line 411 "parser.l"
     1335case 27:
     1336YY_RULE_SETUP
     1337#line 411 "parser.l"
    20191338{
    2020                                 pop_start();
     1339                                yy_pop_state();
    20211340                                yylval.str = get_buffered_wstring();
    20221341                                return tSTRING;
    20231342                        }
    20241343        YY_BREAK
    2025 case 72:
    2026 YY_RULE_SETUP
    2027 #line 705 "parser.l"
    2028 yyerror("Unterminated string");
    2029         YY_BREAK
    2030 case 73:
    2031 YY_RULE_SETUP
    2032 #line 706 "parser.l"
     1344case 28:
     1345YY_RULE_SETUP
     1346#line 416 "parser.l"
    20331347{ /* octal escape sequence */
    20341348                                int result;
     
    20391353                        }
    20401354        YY_BREAK
    2041 case 74:
    2042 YY_RULE_SETUP
    2043 #line 713 "parser.l"
     1355case 29:
     1356YY_RULE_SETUP
     1357#line 423 "parser.l"
    20441358{  /* hex escape sequence */
    20451359                                int result;
     
    20481362                        }
    20491363        YY_BREAK
    2050 case 75:
    2051 YY_RULE_SETUP
    2052 #line 718 "parser.l"
     1364case 30:
     1365YY_RULE_SETUP
     1366#line 428 "parser.l"
     1367{  yyerror("Invalid hex escape sequence '%s'", yytext); }
     1368        YY_BREAK
     1369case 31:
     1370YY_RULE_SETUP
     1371#line 430 "parser.l"
    20531372yyerror("Bad escape secuence");
    20541373        YY_BREAK
    2055 case 76:
    2056 YY_RULE_SETUP
    2057 #line 719 "parser.l"
     1374case 32:
     1375YY_RULE_SETUP
     1376#line 431 "parser.l"
    20581377addwchar('\a');
    20591378        YY_BREAK
    2060 case 77:
    2061 YY_RULE_SETUP
    2062 #line 720 "parser.l"
     1379case 33:
     1380YY_RULE_SETUP
     1381#line 432 "parser.l"
    20631382addwchar('\b');
    20641383        YY_BREAK
    2065 case 78:
    2066 YY_RULE_SETUP
    2067 #line 721 "parser.l"
     1384case 34:
     1385YY_RULE_SETUP
     1386#line 433 "parser.l"
    20681387addwchar('\f');
    20691388        YY_BREAK
    2070 case 79:
    2071 YY_RULE_SETUP
    2072 #line 722 "parser.l"
     1389case 35:
     1390YY_RULE_SETUP
     1391#line 434 "parser.l"
    20731392addwchar('\n');
    20741393        YY_BREAK
    2075 case 80:
    2076 YY_RULE_SETUP
    2077 #line 723 "parser.l"
     1394case 36:
     1395YY_RULE_SETUP
     1396#line 435 "parser.l"
    20781397addwchar('\r');
    20791398        YY_BREAK
    2080 case 81:
    2081 YY_RULE_SETUP
    2082 #line 724 "parser.l"
     1399case 37:
     1400YY_RULE_SETUP
     1401#line 436 "parser.l"
    20831402addwchar('\t');
    20841403        YY_BREAK
    2085 case 82:
    2086 YY_RULE_SETUP
    2087 #line 725 "parser.l"
     1404case 38:
     1405YY_RULE_SETUP
     1406#line 437 "parser.l"
    20881407addwchar('\v');
    20891408        YY_BREAK
    2090 case 83:
    2091 YY_RULE_SETUP
    2092 #line 726 "parser.l"
     1409case 39:
     1410YY_RULE_SETUP
     1411#line 438 "parser.l"
    20931412addwchar(yytext[1]);
    20941413        YY_BREAK
    2095 case 84:
    2096 YY_RULE_SETUP
    2097 #line 727 "parser.l"
     1414case 40:
     1415YY_RULE_SETUP
     1416#line 439 "parser.l"
     1417addwchar(yytext[2]);
     1418        YY_BREAK
     1419case 41:
     1420YY_RULE_SETUP
     1421#line 440 "parser.l"
    20981422addcchar('\"');         /* "bla""bla"  -> "bla\"bla" */
    20991423        YY_BREAK
    2100 case 85:
    2101 YY_RULE_SETUP
    2102 #line 728 "parser.l"
     1424case 42:
     1425YY_RULE_SETUP
     1426#line 441 "parser.l"
    21031427addcchar('\"');         /* "bla\""bla" -> "bla\"bla" */
    21041428        YY_BREAK
    2105 case 86:
    2106 YY_RULE_SETUP
    2107 #line 729 "parser.l"
     1429case 43:
     1430YY_RULE_SETUP
     1431#line 442 "parser.l"
    21081432;                       /* "bla" "bla" -> "blabla" */
    21091433        YY_BREAK
    2110 case 87:
    2111 YY_RULE_SETUP
    2112 #line 730 "parser.l"
     1434case 44:
     1435YY_RULE_SETUP
     1436#line 443 "parser.l"
    21131437{
    21141438                                char *yptr = yytext;
     
    21171441                        }
    21181442        YY_BREAK
    2119 case 88:
    2120 YY_RULE_SETUP
    2121 #line 736 "parser.l"
     1443case 45:
     1444YY_RULE_SETUP
     1445#line 448 "parser.l"
     1446yyerror("Unterminated string");
     1447        YY_BREAK
     1448/*
     1449         * Normal string scanning
     1450         */
     1451case 46:
     1452YY_RULE_SETUP
     1453#line 453 "parser.l"
     1454yy_push_state(yystr); cbufidx = 0;
     1455        YY_BREAK
     1456case 47:
     1457#line 455 "parser.l"
     1458case 48:
     1459YY_RULE_SETUP
     1460#line 455 "parser.l"
    21221461{
    2123                                 push_to(yystr);
    2124                                 cbufidx = 0;
    2125                         }
    2126         YY_BREAK
    2127 case 89:
    2128 YY_RULE_SETUP
    2129 #line 740 "parser.l"
    2130 {
    2131                                 pop_start();
     1462                                yy_pop_state();
    21321463                                yylval.str = get_buffered_cstring();
    21331464                                return tSTRING;
    21341465                        }
    21351466        YY_BREAK
    2136 case 90:
    2137 YY_RULE_SETUP
    2138 #line 745 "parser.l"
    2139 yyerror("Unterminated string");
    2140         YY_BREAK
    2141 case 91:
    2142 YY_RULE_SETUP
    2143 #line 746 "parser.l"
     1467case 49:
     1468YY_RULE_SETUP
     1469#line 460 "parser.l"
    21441470{ /* octal escape sequence */
    21451471                                int result;
     
    21501476                        }
    21511477        YY_BREAK
    2152 case 92:
    2153 YY_RULE_SETUP
    2154 #line 753 "parser.l"
     1478case 50:
     1479YY_RULE_SETUP
     1480#line 467 "parser.l"
    21551481{  /* hex escape sequence */
    21561482                                int result;
     
    21591485                        }
    21601486        YY_BREAK
    2161 case 93:
    2162 YY_RULE_SETUP
    2163 #line 758 "parser.l"
     1487case 51:
     1488YY_RULE_SETUP
     1489#line 472 "parser.l"
     1490{  yyerror("Invalid hex escape sequence '%s'", yytext); }
     1491        YY_BREAK
     1492case 52:
     1493YY_RULE_SETUP
     1494#line 474 "parser.l"
    21641495yyerror("Bad escape secuence");
    21651496        YY_BREAK
    2166 case 94:
    2167 YY_RULE_SETUP
    2168 #line 759 "parser.l"
     1497case 53:
     1498YY_RULE_SETUP
     1499#line 475 "parser.l"
    21691500addcchar('\a');
    21701501        YY_BREAK
    2171 case 95:
    2172 YY_RULE_SETUP
    2173 #line 760 "parser.l"
     1502case 54:
     1503YY_RULE_SETUP
     1504#line 476 "parser.l"
    21741505addcchar('\b');
    21751506        YY_BREAK
    2176 case 96:
    2177 YY_RULE_SETUP
    2178 #line 761 "parser.l"
     1507case 55:
     1508YY_RULE_SETUP
     1509#line 477 "parser.l"
    21791510addcchar('\f');
    21801511        YY_BREAK
    2181 case 97:
    2182 YY_RULE_SETUP
    2183 #line 762 "parser.l"
     1512case 56:
     1513YY_RULE_SETUP
     1514#line 478 "parser.l"
    21841515addcchar('\n');
    21851516        YY_BREAK
    2186 case 98:
    2187 YY_RULE_SETUP
    2188 #line 763 "parser.l"
     1517case 57:
     1518YY_RULE_SETUP
     1519#line 479 "parser.l"
    21891520addcchar('\r');
    21901521        YY_BREAK
    2191 case 99:
    2192 YY_RULE_SETUP
    2193 #line 764 "parser.l"
     1522case 58:
     1523YY_RULE_SETUP
     1524#line 480 "parser.l"
    21941525addcchar('\t');
    21951526        YY_BREAK
    2196 case 100:
    2197 YY_RULE_SETUP
    2198 #line 765 "parser.l"
     1527case 59:
     1528YY_RULE_SETUP
     1529#line 481 "parser.l"
    21991530addcchar('\v');
    22001531        YY_BREAK
    2201 case 101:
    2202 YY_RULE_SETUP
    2203 #line 766 "parser.l"
     1532case 60:
     1533YY_RULE_SETUP
     1534#line 482 "parser.l"
    22041535addcchar(yytext[1]);
    22051536        YY_BREAK
    2206 case 102:
    2207 YY_RULE_SETUP
    2208 #line 767 "parser.l"
     1537case 61:
     1538YY_RULE_SETUP
     1539#line 483 "parser.l"
     1540addcchar(yytext[2]);
     1541        YY_BREAK
     1542case 62:
     1543YY_RULE_SETUP
     1544#line 484 "parser.l"
    22091545{
    22101546                                char *yptr = yytext;
     
    22131549                        }
    22141550        YY_BREAK
    2215 case 103:
    2216 YY_RULE_SETUP
    2217 #line 772 "parser.l"
     1551case 63:
     1552YY_RULE_SETUP
     1553#line 489 "parser.l"
    22181554addcchar('\"');         /* "bla""bla"   -> "bla\"bla" */
    22191555        YY_BREAK
    2220 case 104:
    2221 YY_RULE_SETUP
    2222 #line 773 "parser.l"
     1556case 64:
     1557YY_RULE_SETUP
     1558#line 490 "parser.l"
    22231559addcchar('\"');         /* "bla\""bla"  -> "bla\"bla" */
    22241560        YY_BREAK
    2225 case 105:
    2226 YY_RULE_SETUP
    2227 #line 774 "parser.l"
     1561case 65:
     1562YY_RULE_SETUP
     1563#line 491 "parser.l"
    22281564;                       /* "bla" "bla"  -> "blabla" */
    22291565        YY_BREAK
    2230 case 106:
    2231 YY_RULE_SETUP
    2232 #line 775 "parser.l"
    2233 yywarning("Matched %c", *yytext);
    2234         YY_BREAK
    2235 case 107:
    2236 YY_RULE_SETUP
    2237 #line 778 "parser.l"
     1566case 66:
     1567YY_RULE_SETUP
     1568#line 492 "parser.l"
     1569yyerror("Unterminated string");
     1570        YY_BREAK
     1571/*
     1572         * Raw data scanning
     1573         */
     1574case 67:
     1575YY_RULE_SETUP
     1576#line 497 "parser.l"
     1577yy_push_state(yyrcd); cbufidx = 0;
     1578        YY_BREAK
     1579case 68:
     1580YY_RULE_SETUP
     1581#line 498 "parser.l"
    22381582{
    2239                                 push_to(yyrcd);
    2240                                 cbufidx = 0;
    2241                         }
    2242         YY_BREAK
    2243 case 108:
    2244 YY_RULE_SETUP
    2245 #line 782 "parser.l"
    2246 {
    2247                                 pop_start();
     1583                                yy_pop_state();
    22481584                                yylval.raw = new_raw_data();
    22491585                                yylval.raw->size = cbufidx;
    22501586                                yylval.raw->data = xmalloc(yylval.raw->size);
    22511587                                memcpy(yylval.raw->data, cbuffer, yylval.raw->size);
    2252                                 return RAWDATA;
    2253                         }
    2254         YY_BREAK
    2255 case 109:
    2256 YY_RULE_SETUP
    2257 #line 790 "parser.l"
     1588                                return tRAWDATA;
     1589                        }
     1590        YY_BREAK
     1591case 69:
     1592YY_RULE_SETUP
     1593#line 506 "parser.l"
    22581594{
    22591595                                int result;
     
    22621598                        }
    22631599        YY_BREAK
    2264 case 110:
    2265 YY_RULE_SETUP
    2266 #line 795 "parser.l"
     1600case 70:
     1601YY_RULE_SETUP
     1602#line 511 "parser.l"
    22671603;       /* Ignore space */
    22681604        YY_BREAK
    2269 case 111:
    2270 YY_RULE_SETUP
    2271 #line 796 "parser.l"
     1605case 71:
     1606YY_RULE_SETUP
     1607#line 512 "parser.l"
    22721608line_number++; char_number = 1;
    22731609        YY_BREAK
    2274 case 112:
    2275 YY_RULE_SETUP
    2276 #line 797 "parser.l"
     1610case 72:
     1611YY_RULE_SETUP
     1612#line 513 "parser.l"
    22771613yyerror("Malformed data-line");
    22781614        YY_BREAK
    2279 case 113:
    2280 YY_RULE_SETUP
    2281 #line 799 "parser.l"
    2282 push_to(comment);       /* Eat comment */
    2283         YY_BREAK
    2284 case 114:
    2285 YY_RULE_SETUP
    2286 #line 800 "parser.l"
     1615/*
     1616         * Comment stripping
     1617         * Should never occur after preprocessing
     1618         */
     1619case 73:
     1620YY_RULE_SETUP
     1621#line 519 "parser.l"
     1622{
     1623                                yy_push_state(comment);
     1624                                save_wanted_id = wanted_id;
     1625                                if(!no_preprocess)
     1626                                        yywarning("Found comments after preprocessing, please report");
     1627                        }
     1628        YY_BREAK
     1629case 74:
     1630YY_RULE_SETUP
     1631#line 525 "parser.l"
    22871632;
    22881633        YY_BREAK
    2289 case 115:
    2290 YY_RULE_SETUP
    2291 #line 801 "parser.l"
     1634case 75:
     1635YY_RULE_SETUP
     1636#line 526 "parser.l"
    22921637;
    22931638        YY_BREAK
    2294 case 116:
    2295 YY_RULE_SETUP
    2296 #line 802 "parser.l"
     1639case 76:
     1640YY_RULE_SETUP
     1641#line 527 "parser.l"
    22971642line_number++; char_number = 1;
    22981643        YY_BREAK
    2299 case 117:
    2300 YY_RULE_SETUP
    2301 #line 803 "parser.l"
    2302 pop_start();
    2303         YY_BREAK
    2304 case 118:
    2305 YY_RULE_SETUP
    2306 #line 805 "parser.l"
    2307 ; /* Eat comment */
    2308         YY_BREAK
    2309 case 119:
    2310 YY_RULE_SETUP
    2311 #line 806 "parser.l"
    2312 ; /* Eat comment */
    2313         YY_BREAK
    2314 case 120:
    2315 YY_RULE_SETUP
    2316 #line 808 "parser.l"
     1644case 77:
     1645YY_RULE_SETUP
     1646#line 528 "parser.l"
     1647yy_pop_state(); want_id = save_wanted_id;
     1648        YY_BREAK
     1649case 78:
     1650YY_RULE_SETUP
     1651#line 530 "parser.l"
     1652want_id = wanted_id; /* not really comment, but left-over c-junk */
     1653        YY_BREAK
     1654case 79:
     1655YY_RULE_SETUP
     1656#line 531 "parser.l"
     1657want_id = wanted_id; if(!no_preprocess) yywarning("Found comments after preprocessing, please report");
     1658        YY_BREAK
     1659case 80:
     1660YY_RULE_SETUP
     1661#line 533 "parser.l"
    23171662{
    2318                                 if(YY_START == yywf)
    2319                                         pop_start();
     1663                                want_id = wanted_id;
    23201664                                line_number++;
    23211665                                char_number = 1;
     
    23271671                        }
    23281672        YY_BREAK
    2329 case 121:
    2330 YY_RULE_SETUP
    2331 #line 819 "parser.l"
    2332 ;       /* Eat whitespace */
    2333         YY_BREAK
    2334 case 122:
    2335 YY_RULE_SETUP
    2336 #line 821 "parser.l"
     1673case 81:
     1674YY_RULE_SETUP
     1675#line 543 "parser.l"
     1676want_id = wanted_id;    /* Eat whitespace */
     1677        YY_BREAK
     1678case 82:
     1679YY_RULE_SETUP
     1680#line 545 "parser.l"
    23371681return yytext[0];
    23381682        YY_BREAK
    23391683case YY_STATE_EOF(INITIAL):
    2340 case YY_STATE_EOF(yywf):
    2341 case YY_STATE_EOF(yywf_s):
    23421684case YY_STATE_EOF(yystr):
    23431685case YY_STATE_EOF(yylstr):
    23441686case YY_STATE_EOF(yyrcd):
    23451687case YY_STATE_EOF(comment):
    2346 case YY_STATE_EOF(pp_incl):
    2347 case YY_STATE_EOF(pp_def):
    2348 case YY_STATE_EOF(pp_undef):
    2349 case YY_STATE_EOF(pp_if):
    2350 case YY_STATE_EOF(pp_ifdef):
    2351 case YY_STATE_EOF(pp_ifndef):
    2352 case YY_STATE_EOF(pp_elif):
    2353 case YY_STATE_EOF(pp_else):
    2354 case YY_STATE_EOF(pp_endif):
    2355 case YY_STATE_EOF(pp_error):
    2356 case YY_STATE_EOF(pp_def_s):
    2357 case YY_STATE_EOF(pp_ignore):
    2358 case YY_STATE_EOF(pp_ignore_eol):
    2359 case YY_STATE_EOF(pp_false):
    23601688case YY_STATE_EOF(pp_stripe):
    23611689case YY_STATE_EOF(pp_strips):
    23621690case YY_STATE_EOF(pp_stripp):
    23631691case YY_STATE_EOF(pp_stripp_final):
    2364 #line 822 "parser.l"
     1692case YY_STATE_EOF(pp_line):
     1693#line 547 "parser.l"
    23651694{
    2366                                 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
    2367                                 if(!pop_buffer())
    2368                                 {
    2369                                         if(YY_START == pp_strips || YY_START == pp_stripe || YY_START == pp_stripp || YY_START == pp_stripp_final)
    2370                                                 yyerror("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
    2371                                         else
    2372                                                 yyterminate();
    2373                                 }
    2374                                 yy_delete_buffer(b);
    2375                         }
    2376         YY_BREAK
    2377 case 123:
    2378 YY_RULE_SETUP
    2379 #line 834 "parser.l"
     1695                                if(YY_START == pp_strips || YY_START == pp_stripe || YY_START == pp_stripp || YY_START == pp_stripp_final)
     1696                                        yyerror("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
     1697                                else
     1698                                        yyterminate();
     1699                        }
     1700        YY_BREAK
     1701case 83:
     1702YY_RULE_SETUP
     1703#line 554 "parser.l"
    23801704{
    23811705                                /* Catch all rule to find any unmatched text */
     
    23861710                                }
    23871711                                yywarning("Unmatched text '%c' (0x%02x) YY_START=%d stripslevel=%d",
    2388                                         isprint(*yytext) ? *yytext : '.', *yytext, YY_START,stripslevel);
    2389                         }
    2390         YY_BREAK
    2391 case 124:
    2392 YY_RULE_SETUP
    2393 #line 845 "parser.l"
     1712                                        isprint(*yytext & 0xff) ? *yytext : '.', *yytext, YY_START,stripslevel);
     1713                        }
     1714        YY_BREAK
     1715case 84:
     1716YY_RULE_SETUP
     1717#line 565 "parser.l"
    23941718ECHO;
    23951719        YY_BREAK
    2396 #line 2397 "lexyy.c"
     1720#line 1721 "lexyy.c"
    23971721
    23981722        case YY_END_OF_BUFFER:
     
    26822006                        {
    26832007                        yy_current_state = (int) yy_def[yy_current_state];
    2684                         if ( yy_current_state >= 369 )
     2008                        if ( yy_current_state >= 162 )
    26852009                                yy_c = yy_meta[(unsigned int) yy_c];
    26862010                        }
     
    27172041                {
    27182042                yy_current_state = (int) yy_def[yy_current_state];
    2719                 if ( yy_current_state >= 369 )
     2043                if ( yy_current_state >= 162 )
    27202044                        yy_c = yy_meta[(unsigned int) yy_c];
    27212045                }
    27222046        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
    2723         yy_is_jam = (yy_current_state == 368);
     2047        yy_is_jam = (yy_current_state == 161);
    27242048
    27252049        return yy_is_jam ? 0 : yy_current_state;
     
    32542578        }
    32552579#endif
    3256 #line 845 "parser.l"
     2580#line 565 "parser.l"
    32572581
    32582582
     
    32732597 * the resource string.
    32742598 */
    3275 void addcchar(char c)
     2599static void addcchar(char c)
    32762600{
    32772601        if(cbufidx >= cbufalloc)
     
    32852609}
    32862610
    3287 void addwchar(short s)
     2611static void addwchar(short s)
    32882612{
    32892613        if(wbufidx >= wbufalloc)
     
    33062630}
    33072631
    3308 string_t *get_buffered_cstring(void)
     2632static string_t *get_buffered_cstring(void)
    33092633{
    33102634        string_t *str = new_string();
     
    33142638        memcpy(str->str.cstr, cbuffer, cbufidx);
    33152639        str->str.cstr[cbufidx] = '\0';
    3316 /*      printf("got cstring \"%s\"\n", str->str.cstr); */
    33172640        return str;
    33182641}
    33192642
    3320 string_t *get_buffered_wstring(void)
     2643static string_t *get_buffered_wstring(void)
    33212644{
    33222645        string_t *str = new_string();
     
    33292652}
    33302653
    3331 string_t *make_string(char *s)
     2654static string_t *make_string(char *s)
    33322655{
    33332656        string_t *str = new_string();
     
    33392662}
    33402663
    3341 string_t *make_filename(char *s, int len)
    3342 {
    3343         char *cptr;
    3344         string_t *str = new_string();
    3345 
    3346         str->size = len;
    3347         str->type = str_char;
    3348         str->str.cstr = (char *)xmalloc(str->size+1);
    3349         memcpy(str->str.cstr, s, str->size);
    3350         str->str.cstr[str->size] = '\0';
    3351 
    3352         /* Remove escaped backslash and convert to forward */
    3353         cptr = str->str.cstr;
    3354         for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
    3355         {
    3356                 if(cptr[1] == '\\')
    3357                 {
    3358                         memmove(cptr, cptr+1, strlen(cptr));
    3359                         str->size--;
    3360                 }
    3361                 *cptr = '/';
    3362         }
    3363 
    3364         /* Convert to lower case. Seems to be reasonable to do */
    3365         for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
    3366         {
    3367                 *cptr = tolower(*cptr);
    3368         }
    3369         return str;
    3370 }
    3371 
    3372 /* Called from the parser to signal filename request */
    3373 void set_yywf(void)
    3374 {
    3375         push_to(yywf);
    3376 }
    3377 
    3378 /* Called from the parser to signal preprocessor if case */
    3379 void set_pp_ignore(int state)
    3380 {
    3381         if(state)
    3382                 push_to(pp_false);
    3383         else
    3384                 pop_start();
    3385 }
    3386 
    33872664/* Called from the parser to kill c-junk */
    33882665void strip_extern(void)
    33892666{
    33902667        cjunk_tagline = line_number;
    3391         push_to(pp_stripe);
     2668        yy_push_state(pp_stripe);
    33922669}
    33932670
     
    33952672{
    33962673        cjunk_tagline = line_number;
    3397         push_to(pp_strips);
     2674        yy_push_state(pp_strips);
    33982675}
    33992676
     
    34022679        cjunk_tagline = line_number;
    34032680        stripplevel = 1;        /* One scanned already */
    3404         push_to(pp_stripp);
     2681        yy_push_state(pp_stripp);
    34052682}
    34062683
  • trunk/tools/wrc/makefile.os2

    r4712 r5522  
    1 # $Id: makefile.os2,v 1.12 2000-12-02 23:27:03 bird Exp $
     1# $Id: makefile.os2,v 1.13 2001-04-16 17:10:52 sandervl Exp $
    22
    33
     
    88
    99#DEFS      = -D__WINE__ -D__WIN32OS2__ -idirafter ../../include/win -idirafter ../../include
    10 DEFS      = -D__WINE__ -D__SEMICOLON__  -I. -I../../include/win -I../../include
     10DEFS      = -D__WINE__ -D__EMX__ -DMASM -D__SEMICOLON__  -I. -I../../include/win -I../../include -g -DDEBUG
    1111
    1212PROGRAMS = wrc.exe
    1313MODULE   = none
     14
     15YACCOPT   = #-v
    1416
    1517OBJS = \
     
    2325        y.tab.o \
    2426        lexyy.o \
    25         writeres.o
     27        ppy.tab.o \
     28        lex.ppl.o \
     29        writeres.o \
     30        u/string.o \
     31        u/cptable.o \
     32        u/utf8.o \
     33        u/mbtowc.o \
     34        u/wctomb.o \
     35        u/c_869.o \
     36        u/c_775.o \
     37        u/c_865.o \
     38        u/c_857.o \
     39        u/c_10000.o \
     40        u/c_10006.o \
     41        u/c_861.o \
     42        u/c_737.o \
     43        u/c_860.o \
     44        u/c_1253.o \
     45        u/c_28597.o \
     46        u/c_10029.o \
     47        u/c_10081.o \
     48        u/c_1257.o \
     49        u/c_1252.o \
     50        u/c_1254.o \
     51        u/c_28591.o \
     52        u/c_437.o \
     53        u/c_10079.o \
     54        u/c_852.o \
     55        u/c_875.o \
     56        u/c_863.o \
     57        u/c_037.o \
     58        u/c_1258.o \
     59        u/c_1250.o \
     60        u/c_850.o \
     61        u/c_28605.o \
     62        u/c_500.o \
     63        u/c_28599.o \
     64        u/c_28600.o \
     65        u/c_28603.o \
     66        u/c_28604.o \
     67        u/c_28594.o \
     68        u/c_1026.o \
     69        u/c_28592.o \
     70        u/c_28593.o \
     71        u/c_856.o \
     72        u/c_1006.o \
     73        u/c_862.o \
     74        u/c_864.o \
     75        u/c_878.o \
     76        u/c_866.o \
     77        u/c_855.o \
     78        u/c_20866.o \
     79        u/c_874.o \
     80        u/c_424.o \
     81        u/c_1255.o \
     82        u/c_1256.o \
     83        u/c_28596.o \
     84        u/c_28598.o \
     85        u/c_10007.o \
     86        u/c_1251.o \
     87        u/c_28595.o \
     88        u/c_042.o \
     89        u/compose.o \
     90        u/c_932.o \
     91        u/c_950.o \
     92        u/c_936.o \
     93        u/c_949.o \
     94        u/casemap.o \
     95        u/wctype.o
    2696
    2797EXTRA_SRCS = parser.y parser.l
     
    43113
    44114wrc.exe: lexyy.c y.tab.c $(OBJS)
    45     $(CC) $(CFLAGS) -o $@ $(OBJS)
     115    $(CC) $(CFLAGS) -o $@ $(OBJS)  -L. -lm
    46116    copy $@ ..\bin
    47117
     
    50120
    51121lexyy.c: parser.l
    52     $(LEX) -8 parser.l
     122    $(LEX) -8 -d parser.l
    53123
     124ppy.tab.c ppy.tab.h: ppy.y
     125    $(YACC) $(YACCOPT) -bppy -ppp -d -t ppy.y -o ppy.tab.c
     126
     127lex.ppl.c: ppl.l
     128    $(LEX) $(LEXOPT) -d -Ppp -8 -olex.ppl.c ppl.l
    54129
    55130dep:
  • trunk/tools/wrc/newstruc.c

    r3426 r5522  
    1313#include <string.h>
    1414#include <assert.h>
     15#include <ctype.h>
    1516
    1617#include "wrc.h"
     
    1819#include "utils.h"
    1920#include "parser.h"
     21
     22#include "wingdi.h"     /* for BITMAPINFOHEADER */
    2023
    2124/* Generate new_* functions that have no parameters (NOTE: no ';') */
     
    4144__NEW_STRUCT_FUNC(string)
    4245__NEW_STRUCT_FUNC(toolbar_item)
     46__NEW_STRUCT_FUNC(ani_any)
    4347
    4448/* New instances for all types of structures */
     
    145149        }
    146150        else
    147                 fnt->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
     151                fnt->memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE;
    148152        return fnt;
    149153}
     154
     155fontdir_t *new_fontdir(raw_data_t *rd, int *memopt)
     156{
     157        fontdir_t *fnd = (fontdir_t *)xmalloc(sizeof(fontdir_t));
     158        fnd->data = rd;
     159        if(memopt)
     160        {
     161                fnd->memopt = *memopt;
     162                free(memopt);
     163        }
     164        else
     165                fnd->memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE;
     166        return fnd;
     167}
     168
     169
     170/*
     171 * Convert bitmaps to proper endian
     172 */
     173static void convert_bitmap_swap_v3(BITMAPINFOHEADER *bih)
     174{
     175        bih->biSize             = BYTESWAP_DWORD(bih->biSize);
     176        bih->biWidth            = BYTESWAP_DWORD(bih->biWidth);
     177        bih->biHeight           = BYTESWAP_DWORD(bih->biHeight);
     178        bih->biPlanes           = BYTESWAP_WORD(bih->biPlanes);
     179        bih->biBitCount         = BYTESWAP_WORD(bih->biBitCount);
     180        bih->biCompression      = BYTESWAP_DWORD(bih->biCompression);
     181        bih->biSizeImage        = BYTESWAP_DWORD(bih->biSizeImage);
     182        bih->biXPelsPerMeter    = BYTESWAP_DWORD(bih->biXPelsPerMeter);
     183        bih->biYPelsPerMeter    = BYTESWAP_DWORD(bih->biYPelsPerMeter);
     184        bih->biClrUsed          = BYTESWAP_DWORD(bih->biClrUsed);
     185        bih->biClrImportant     = BYTESWAP_DWORD(bih->biClrImportant);
     186}
     187
     188static void convert_bitmap_swap_v4(BITMAPV4HEADER *b4h)
     189{
     190        convert_bitmap_swap_v3((BITMAPINFOHEADER *)b4h);
     191        b4h->bV4RedMask         = BYTESWAP_DWORD(b4h->bV4RedMask);
     192        b4h->bV4GreenMask       = BYTESWAP_DWORD(b4h->bV4GreenMask);
     193        b4h->bV4BlueMask        = BYTESWAP_DWORD(b4h->bV4BlueMask);
     194        b4h->bV4AlphaMask       = BYTESWAP_DWORD(b4h->bV4AlphaMask);
     195        b4h->bV4CSType          = BYTESWAP_DWORD(b4h->bV4CSType);
     196        b4h->bV4Endpoints.ciexyzRed.ciexyzX     = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzRed.ciexyzX);
     197        b4h->bV4Endpoints.ciexyzRed.ciexyzY     = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzRed.ciexyzY);
     198        b4h->bV4Endpoints.ciexyzRed.ciexyzZ     = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzRed.ciexyzZ);
     199        b4h->bV4Endpoints.ciexyzGreen.ciexyzX   = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzGreen.ciexyzX);
     200        b4h->bV4Endpoints.ciexyzGreen.ciexyzY   = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzGreen.ciexyzY);
     201        b4h->bV4Endpoints.ciexyzGreen.ciexyzZ   = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzGreen.ciexyzZ);
     202        b4h->bV4Endpoints.ciexyzBlue.ciexyzX    = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzBlue.ciexyzX);
     203        b4h->bV4Endpoints.ciexyzBlue.ciexyzY    = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzBlue.ciexyzY);
     204        b4h->bV4Endpoints.ciexyzBlue.ciexyzZ    = BYTESWAP_DWORD(b4h->bV4Endpoints.ciexyzBlue.ciexyzZ);
     205        b4h->bV4GammaRed        = BYTESWAP_DWORD(b4h->bV4GammaRed);
     206        b4h->bV4GammaGreen      = BYTESWAP_DWORD(b4h->bV4GammaGreen);
     207        b4h->bV4GammaBlue       = BYTESWAP_DWORD(b4h->bV4GammaBlue);
     208}
     209
     210#define FL_SIGBE        0x01
     211#define FL_SIZEBE       0x02
     212#define FL_V4           0x04
     213static int convert_bitmap(char *data, int size)
     214{
     215        BITMAPINFOHEADER *bih = (BITMAPINFOHEADER *)data;
     216        BITMAPV4HEADER *b4h = (BITMAPV4HEADER *)data;
     217        int type = 0;
     218#ifdef WORDS_BIGENDIAN
     219        DWORD bisizel = BYTESWAP_DWORD(sizeof(BITMAPINFOHEADER));
     220        DWORD b4sizel = BYTESWAP_DWORD(sizeof(BITMAPV4HEADER));
     221        DWORD bisizeb = sizeof(BITMAPINFOHEADER);
     222        DWORD b4sizeb = sizeof(BITMAPV4HEADER);
     223#else
     224        DWORD bisizel = sizeof(BITMAPINFOHEADER);
     225        DWORD b4sizel = sizeof(BITMAPV4HEADER);
     226        DWORD bisizeb = BYTESWAP_DWORD(sizeof(BITMAPINFOHEADER));
     227        DWORD b4sizeb = BYTESWAP_DWORD(sizeof(BITMAPV4HEADER));
     228#endif
     229
     230        if(data[0] == 'B' && data[1] == 'M')
     231        {
     232                /* Little endian signature */
     233                bih = (BITMAPINFOHEADER *)(data + sizeof(BITMAPFILEHEADER));
     234                b4h = (BITMAPV4HEADER *)(data + sizeof(BITMAPFILEHEADER));
     235        }
     236        else if(data[0] == 'M' && data[1] == 'B')
     237        {
     238                type |= FL_SIGBE;       /* Big endian signature */
     239                bih = (BITMAPINFOHEADER *)(data + sizeof(BITMAPFILEHEADER));
     240                b4h = (BITMAPV4HEADER *)(data + sizeof(BITMAPFILEHEADER));
     241        }
     242
     243        if(bih->biSize == bisizel)
     244        {
     245                /* Little endian */
     246        }
     247        else if(bih->biSize == b4sizel)
     248        {
     249                type |= FL_V4;
     250        }
     251        else if(bih->biSize == bisizeb)
     252        {
     253                type |= FL_SIZEBE;
     254        }
     255        else if(bih->biSize == b4sizeb)
     256        {
     257                type |= FL_SIZEBE | FL_V4;
     258        }
     259#ifdef __EMX__
     260        else if(bih->biSize == sizeof(BITMAPCOREHEADER))
     261        {
     262                /* Little endian */
     263        }
     264#endif
     265        else
     266                type = -1;
     267
     268        switch(type)
     269        {
     270        default:
     271                break;
     272        case FL_SIZEBE:
     273        case FL_SIZEBE | FL_V4:
     274                yywarning("Bitmap v%c signature little-endian, but size big-endian", type & FL_V4 ? '4' : '3');
     275                break;
     276        case FL_SIGBE:
     277        case FL_SIGBE | FL_V4:
     278                yywarning("Bitmap v%c signature big-endian, but size little-endian", type & FL_V4 ? '4' : '3');
     279                break;
     280        case -1:
     281                yyerror("Invalid bitmap format");
     282                break;
     283        }
     284
     285        switch(byteorder)
     286        {
     287#ifdef WORDS_BIGENDIAN
     288        default:
     289#endif
     290        case WRC_BO_BIG:
     291                if(!(type & FL_SIZEBE))
     292                {
     293                        if(type & FL_V4)
     294                                convert_bitmap_swap_v4(b4h);
     295                        else
     296                                convert_bitmap_swap_v3(bih);
     297                }
     298                break;
     299#ifndef WORDS_BIGENDIAN
     300        default:
     301#endif
     302        case WRC_BO_LITTLE:
     303                if(type & FL_SIZEBE)
     304                {
     305                        if(type & FL_V4)
     306                                convert_bitmap_swap_v4(b4h);
     307                        else
     308                                convert_bitmap_swap_v3(bih);
     309                }
     310                break;
     311        }
     312
     313        if(size && (void *)data != (void *)bih)
     314        {
     315                /* We have the fileheader still attached, remove it */
     316                memmove(data, data+sizeof(BITMAPFILEHEADER), size - sizeof(BITMAPFILEHEADER));
     317                return sizeof(BITMAPFILEHEADER);
     318        }
     319        return 0;
     320}
     321#undef FL_SIGBE
     322#undef FL_SIZEBE
     323#undef FL_V4
     324
     325/*
     326 * Cursor and icon splitter functions used when allocating
     327 * cursor- and icon-groups.
     328 */
     329typedef struct {
     330        language_t      lan;
     331        int             id;
     332} id_alloc_t;
     333
     334static int get_new_id(id_alloc_t **list, int *n, language_t *lan)
     335{
     336        int i;
     337        assert(lan != NULL);
     338        assert(list != NULL);
     339        assert(n != NULL);
     340
     341        if(!*list)
     342        {
     343                *list = (id_alloc_t *)xmalloc(sizeof(id_alloc_t));
     344                *n = 1;
     345                (*list)[0].lan = *lan;
     346                (*list)[0].id = 1;
     347                return 1;
     348        }
     349
     350        for(i = 0; i < *n; i++)
     351        {
     352                if((*list)[i].lan.id == lan->id && (*list)[i].lan.sub == lan->sub)
     353                        return ++((*list)[i].id);
     354        }
     355
     356        *list = (id_alloc_t *)xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
     357        (*list)[*n].lan = *lan;
     358        (*list)[*n].id = 1;
     359        *n += 1;
     360        return 1;
     361}
     362
     363static int alloc_icon_id(language_t *lan)
     364{
     365        static id_alloc_t *idlist = NULL;
     366        static int nid = 0;
     367
     368        return get_new_id(&idlist, &nid, lan);
     369}
     370
     371static int alloc_cursor_id(language_t *lan)
     372{
     373        static id_alloc_t *idlist = NULL;
     374        static int nid = 0;
     375
     376        return get_new_id(&idlist, &nid, lan);
     377}
     378
     379static void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico)
     380{
     381        int cnt;
     382        int i;
     383        icon_t *ico;
     384        icon_t *list = NULL;
     385        icon_header_t *ih = (icon_header_t *)rd->data;
     386        int swap = 0;
     387
     388        if(ih->type == 1)
     389                swap = 0;
     390        else if(BYTESWAP_WORD(ih->type) == 1)
     391                swap = 1;
     392        else
     393                yyerror("Icon resource data has invalid type id %d", ih->type);
     394
     395        cnt = swap ? BYTESWAP_WORD(ih->count) : ih->count;
     396        for(i = 0; i < cnt; i++)
     397        {
     398                icon_dir_entry_t ide;
     399                BITMAPINFOHEADER info;
     400                memcpy(&ide, rd->data + sizeof(icon_header_t)
     401                                      + i*sizeof(icon_dir_entry_t), sizeof(ide));
     402
     403                ico = new_icon();
     404                ico->id = alloc_icon_id(icog->lvc.language);
     405                ico->lvc = icog->lvc;
     406                if(swap)
     407                {
     408                        ide.offset = BYTESWAP_DWORD(ide.offset);
     409                        ide.ressize= BYTESWAP_DWORD(ide.ressize);
     410                }
     411                if(ide.offset > rd->size
     412                || ide.offset + ide.ressize > rd->size)
     413                        yyerror("Icon resource data corrupt");
     414                ico->width = ide.width;
     415                ico->height = ide.height;
     416                ico->nclr = ide.nclr;
     417                ico->planes = swap ? BYTESWAP_WORD(ide.planes) : ide.planes;
     418                ico->bits = swap ? BYTESWAP_WORD(ide.bits) : ide.bits;
     419                convert_bitmap((char *)rd->data + ide.offset, 0);
     420                memcpy(&info, rd->data + ide.offset, sizeof(info));
     421                if(!ico->planes)
     422                {
     423                        /* Argh! They did not fill out the resdir structure */
     424                        /* The bitmap is in destination byteorder. We want native for our structures */
     425                        switch(byteorder)
     426                        {
     427#ifdef WORDS_BIGENDIAN
     428                        case WRC_BO_LITTLE:
     429#else
     430                        case WRC_BO_BIG:
     431#endif
     432                                ico->planes = BYTESWAP_WORD(info.biPlanes);
     433                                break;
     434                        default:
     435                                ico->planes = info.biPlanes;
     436                        }
     437                }
     438                if(!ico->bits)
     439                {
     440                        /* Argh! They did not fill out the resdir structure */
     441                        /* The bitmap is in destination byteorder. We want native for our structures */
     442                        switch(byteorder)
     443                        {
     444#ifdef WORDS_BIGENDIAN
     445                        case WRC_BO_LITTLE:
     446#else
     447                        case WRC_BO_BIG:
     448#endif
     449                                ico->bits = BYTESWAP_WORD(info.biBitCount);
     450                                break;
     451                        default:
     452                                ico->bits = info.biBitCount;
     453                        }
     454                }
     455                ico->data = new_raw_data();
     456                copy_raw_data(ico->data, rd, ide.offset, ide.ressize);
     457                if(!list)
     458                {
     459                        list = ico;
     460                }
     461                else
     462                {
     463                        ico->next = list;
     464                        list->prev = ico;
     465                        list = ico;
     466                }
     467        }
     468        icog->iconlist = list;
     469        *nico = cnt;
     470}
     471
     472static void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur)
     473{
     474        int cnt;
     475        int i;
     476        cursor_t *cur;
     477        cursor_t *list = NULL;
     478        cursor_header_t *ch = (cursor_header_t *)rd->data;
     479        int swap = 0;
     480
     481        if(ch->type == 2)
     482                swap = 0;
     483        else if(BYTESWAP_WORD(ch->type) == 2)
     484                swap = 1;
     485        else
     486                yyerror("Cursor resource data has invalid type id %d", ch->type);
     487        cnt = swap ? BYTESWAP_WORD(ch->count) : ch->count;
     488        for(i = 0; i < cnt; i++)
     489        {
     490                cursor_dir_entry_t cde;
     491                BITMAPINFOHEADER info;
     492                memcpy(&cde, rd->data + sizeof(cursor_header_t)
     493                                      + i*sizeof(cursor_dir_entry_t), sizeof(cde));
     494
     495                cur = new_cursor();
     496                cur->id = alloc_cursor_id(curg->lvc.language);
     497                cur->lvc = curg->lvc;
     498                if(swap)
     499                {
     500                        cde.offset = BYTESWAP_DWORD(cde.offset);
     501                        cde.ressize= BYTESWAP_DWORD(cde.ressize);
     502                }
     503                if(cde.offset > rd->size
     504                || cde.offset + cde.ressize > rd->size)
     505                        yyerror("Cursor resource data corrupt");
     506                cur->width = cde.width;
     507                cur->height = cde.height;
     508                cur->nclr = cde.nclr;
     509                convert_bitmap((char *)rd->data + cde.offset, 0);
     510                memcpy(&info, rd->data + cde.offset, sizeof(info));
     511                /* The bitmap is in destination byteorder. We want native for our structures */
     512                switch(byteorder)
     513                {
     514#ifdef WORDS_BIGENDIAN
     515                case WRC_BO_LITTLE:
     516#else
     517                case WRC_BO_BIG:
     518#endif
     519                        cur->planes = BYTESWAP_WORD(info.biPlanes);
     520                        cur->bits = BYTESWAP_WORD(info.biBitCount);
     521                        break;
     522                default:
     523                        cur->planes = info.biPlanes;
     524                        cur->bits = info.biBitCount;
     525                }
     526                if(!win32 && (cur->planes != 1 || cur->bits != 1))
     527                        yywarning("Win16 cursor contains colors");
     528                cur->xhot = swap ? BYTESWAP_WORD(cde.xhot) : cde.xhot;
     529                cur->yhot = swap ? BYTESWAP_WORD(cde.yhot) : cde.yhot;
     530                cur->data = new_raw_data();
     531                copy_raw_data(cur->data, rd, cde.offset, cde.ressize);
     532                if(!list)
     533                {
     534                        list = cur;
     535                }
     536                else
     537                {
     538                        cur->next = list;
     539                        list->prev = cur;
     540                        list = cur;
     541                }
     542        }
     543        curg->cursorlist = list;
     544        *ncur = cnt;
     545}
     546
    150547
    151548icon_group_t *new_icon_group(raw_data_t *rd, int *memopt)
     
    159556        else
    160557                icog->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
    161         icog->lvc.language = dup_language(currentlanguage);
     558        icog->lvc = rd->lvc;
    162559        split_icons(rd, icog, &(icog->nicon));
    163560        free(rd->data);
     
    176573        else
    177574                curg->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
    178         curg->lvc.language = dup_language(currentlanguage);
     575        curg->lvc = rd->lvc;
    179576        split_cursors(rd, curg, &(curg->ncursor));
    180577        free(rd->data);
     
    183580}
    184581
     582/*
     583 * Animated cursors and icons
     584 *
     585 * The format of animated cursors and icons is yet another example
     586 * of bad design by "The Company". The entire RIFF structure is
     587 * flawed by design because it is inconsistent and single minded:
     588 * - some tags have lengths attached, others don't. The use of these
     589 *   non-length tags is absolutely unclear;
     590 * - the content of "icon" tags can be both icons and cursors;
     591 * - tags lack proper alignment constraints. It seems that everything
     592 *   is 16bit aligned, but I could not find that in any docu. Just be
     593 *   prepared to eat anything;
     594 * - there are no strict constraints on tag-nesting and the organization
     595 *   is highly illogical;
     596 *
     597 * Anyhow, here is the basic structure:
     598 * "RIFF" { dword taglength }
     599 *      "ACON"                                  // What does it do?
     600 *      "LIST" { dword taglength }
     601 *              "INFO"                          // And what does this do?
     602 *              "INAM" { dword taglength }      // Icon/cursor name
     603 *                      {inam data}
     604 *              "IART" { dword taglength }      // The artist
     605 *                      {iart data}
     606 *              "fram"                          // Is followed by "icon"s
     607 *              "icon" { dword taglength }      // First frame
     608 *                      { icon/cursor data }
     609 *              "icon" { dword taglength }      // Second frame
     610 *                      { icon/cursor data }
     611 *                      ...                     // ...
     612 *      "anih" { dword taglength }              // Header structure
     613 *              { aniheader_t structure }
     614 *      "rate" { dword taglength }              // The rate for each frame
     615 *              { `steps' dwords }
     616 *      "seq " { dword taglength }              // The frame blit-order
     617 *              { `steps' dwords }
     618 *
     619 * Tag length are bytelength without the header and length field (i.e. -8).
     620 * The "LIST" tag may occur several times and may encapsulate different
     621 * tags. The `steps' is the number of "icon" tags found (actually the
     622 * number of steps specified in the aniheader_t structure). The "seq "uence
     623 * tag can be ommitted, in which case the sequence is equal to the sequence
     624 * of "icon"s found in the file. Also "rate" may be ommitted, in which case
     625 * the default from the aniheader_t structure is used.
     626 *
     627 * An animated cursor puts `.cur' formatted files into each "icon" tag,
     628 * whereas animated icons contain `.ico' formatted files.
     629 *
     630 * Note about the code: Yes, it can be shorter/compressed. Some tags can be
     631 * dealt with in the same code. However, this version shows what is going on
     632 * and is better debug-able.
     633 */
     634static const char riff[4] = "RIFF";
     635static const char acon[4] = "ACON";
     636static const char list[4] = "LIST";
     637static const char info[4] = "INFO";
     638static const char inam[4] = "INAM";
     639static const char iart[4] = "IART";
     640static const char fram[4] = "fram";
     641static const char icon[4] = "icon";
     642static const char anih[4] = "anih";
     643static const char rate[4] = "rate";
     644static const char seq[4]  = "seq ";
     645
     646#define NEXT_TAG(p)     ((riff_tag_t *)(((char *)p) + (isswapped ? BYTESWAP_DWORD(p->size) : p->size) + sizeof(*p)))
     647
     648static void handle_ani_icon(riff_tag_t *rtp, enum res_e type, int isswapped)
     649{
     650        cursor_dir_entry_t *cdp;
     651        cursor_header_t *chp;
     652        int count;
     653        int ctype;
     654        int i;
     655        static int once = 0;    /* This will trigger only once per file! */
     656        const char *anistr = type == res_aniico ? "icon" : "cursor";
     657        /* Notes:
     658         * Both cursor and icon directories are similar
     659         * Both cursor and icon headers are similar
     660         */
     661
     662        chp = (cursor_header_t *)(rtp+1);
     663        cdp = (cursor_dir_entry_t *)(chp+1);
     664        count = isswapped ? BYTESWAP_WORD(chp->count) : chp->count;
     665        ctype = isswapped ? BYTESWAP_WORD(chp->type) : chp->type;
     666        chp->reserved   = BYTESWAP_WORD(chp->reserved);
     667        chp->type       = BYTESWAP_WORD(chp->type);
     668        chp->count      = BYTESWAP_WORD(chp->count);
     669
     670        if(type == res_anicur && ctype != 2 && !once)
     671        {
     672                yywarning("Animated cursor contains invalid \"icon\" tag cursor-file (%d->%s)",
     673                                ctype,
     674                                ctype == 1 ? "icontype" : "?");
     675                once++;
     676        }
     677        else if(type == res_aniico && ctype != 1 && !once)
     678        {
     679                yywarning("Animated icon contains invalid \"icon\" tag icon-file (%d->%s)",
     680                                ctype,
     681                                ctype == 2 ? "cursortype" : "?");
     682                once++;
     683        }
     684        else if(ctype != 1 && ctype != 2 && !once)
     685        {
     686                yywarning("Animated %s contains invalid \"icon\" tag file-type (%d; neither icon nor cursor)", anistr, ctype);
     687                once++;
     688        }
     689
     690        for(i = 0; i < count; i++)
     691        {
     692                DWORD ofs = isswapped ? BYTESWAP_DWORD(cdp[i].offset) : cdp[i].offset;
     693                DWORD sze = isswapped ? BYTESWAP_DWORD(cdp[i].ressize) : cdp[i].ressize;
     694                if(ofs > rtp->size || ofs+sze > rtp->size)
     695                        yyerror("Animated %s's data corrupt", anistr);
     696                convert_bitmap((char *)chp + ofs, 0);
     697                cdp[i].xhot     = BYTESWAP_WORD(cdp->xhot);
     698                cdp[i].yhot     = BYTESWAP_WORD(cdp->yhot);
     699                cdp[i].ressize  = BYTESWAP_DWORD(cdp->ressize);
     700                cdp[i].offset   = BYTESWAP_DWORD(cdp->offset);
     701        }
     702}
     703
     704static void handle_ani_list(riff_tag_t *lst, enum res_e type, int isswapped)
     705{
     706        riff_tag_t *rtp = lst+1;        /* Skip the "LIST" tag */
     707       
     708        while((char *)rtp < (char *)lst + lst->size + sizeof(*lst))
     709        {
     710                if(!memcmp(rtp->tag, info, sizeof(info)))
     711                {
     712                        rtp = (riff_tag_t *)(((char *)rtp) + 4);
     713                }
     714                else if(!memcmp(rtp->tag, inam, sizeof(inam)))
     715                {
     716                        /* Ignore the icon/cursor name; its a string */
     717                        rtp = NEXT_TAG(rtp);
     718                }
     719                else if(!memcmp(rtp->tag, iart, sizeof(iart)))
     720                {
     721                        /* Ignore the author's name; its a string */
     722                        rtp = NEXT_TAG(rtp);
     723                }
     724                else if(!memcmp(rtp->tag, fram, sizeof(fram)))
     725                {
     726                        /* This should be followed by "icon"s, but we
     727                         * simply ignore this because it is pure
     728                         * non-information.
     729                         */
     730                        rtp = (riff_tag_t *)(((char *)rtp) + 4);
     731                }
     732                else if(!memcmp(rtp->tag, icon, sizeof(icon)))
     733                {
     734                        handle_ani_icon(rtp, type, isswapped);
     735                        rtp = NEXT_TAG(rtp);
     736                }
     737                else
     738                        internal_error(__FILE__, __LINE__, "Unknown tag \"%c%c%c%c\" in RIFF file",
     739                                       isprint(rtp->tag[0]) ? rtp->tag[0] : '.',
     740                                       isprint(rtp->tag[1]) ? rtp->tag[1] : '.',
     741                                       isprint(rtp->tag[2]) ? rtp->tag[2] : '.',
     742                                       isprint(rtp->tag[3]) ? rtp->tag[3] : '.');
     743
     744                /* FIXME: This relies in sizeof(DWORD) == sizeof(pointer_type) */
     745                if((DWORD)rtp & 1)
     746                        ((char *)rtp)++;
     747        }
     748}
     749
     750ani_curico_t *new_ani_curico(enum res_e type, raw_data_t *rd, int *memopt)
     751{
     752        ani_curico_t *ani = (ani_curico_t *)xmalloc(sizeof(ani_curico_t));
     753        riff_tag_t *rtp;
     754        int isswapped = 0;
     755        int doswap;
     756        const char *anistr = type == res_aniico ? "icon" : "cursor";
     757
     758        assert(!memcmp(rd->data, riff, sizeof(riff)));
     759        assert(type == res_anicur || type == res_aniico);
     760
     761        rtp = (riff_tag_t *)rd->data;
     762
     763        if(BYTESWAP_DWORD(rtp->size) + 2*sizeof(DWORD) == rd->size)
     764                isswapped = 1;
     765        else if(rtp->size + 2*sizeof(DWORD) == rd->size)
     766                isswapped = 0;
     767        else
     768                yyerror("Animated %s has an invalid RIFF length", anistr);
     769
     770        switch(byteorder)
     771        {
     772#ifdef WORDS_BIGENDIAN
     773        case WRC_BO_LITTLE:
     774#else
     775        case WRC_BO_BIG:
     776#endif
     777                doswap = !isswapped;
     778                break;
     779        default:
     780                doswap = isswapped;
     781        }
     782
     783        /*
     784         * When to swap what:
     785         * isswapped | doswap |
     786         * ----------+--------+---------------------------------
     787         *     0     |    0   | read native; don't convert
     788         *     1     |    0   | read swapped size; don't convert
     789         *     0     |    1   | read native; convert
     790         *     1     |    1   | read swapped size; convert
     791         * Reading swapped size if necessary to calculate in native
     792         * format. E.g. a little-endian source on a big-endian
     793         * processor.
     794         */
     795        if(doswap)
     796        {
     797                /* We only go through the RIFF file if we need to swap
     798                 * bytes in words/dwords. Else we couldn't care less
     799                 * what the file contains. This is consistent with
     800                 * MS' rc.exe, which doesn't complain at all, eventhough
     801                 * the fileformat might not be entirely correct.
     802                 */
     803                rtp++;  /* Skip the "RIFF" tag */
     804
     805                while((char *)rtp < (char *)rd->data + rd->size)
     806                {
     807                        if(!memcmp(rtp->tag, acon, sizeof(acon)))
     808                        {
     809                                rtp = (riff_tag_t *)(((char *)rtp) + 4);
     810                        }
     811                        else if(!memcmp(rtp->tag, list, sizeof(list)))
     812                        {
     813                                handle_ani_list(rtp, type, isswapped);
     814                                rtp = NEXT_TAG(rtp);
     815                        }
     816                        else if(!memcmp(rtp->tag, anih, sizeof(anih)))
     817                        {
     818                                aniheader_t *ahp = (aniheader_t *)((char *)(rtp+1));
     819                                ahp->structsize = BYTESWAP_DWORD(ahp->structsize);
     820                                ahp->frames     = BYTESWAP_DWORD(ahp->frames);
     821                                ahp->steps      = BYTESWAP_DWORD(ahp->steps);
     822                                ahp->cx         = BYTESWAP_DWORD(ahp->cx);
     823                                ahp->cy         = BYTESWAP_DWORD(ahp->cy);
     824                                ahp->bitcount   = BYTESWAP_DWORD(ahp->bitcount);
     825                                ahp->planes     = BYTESWAP_DWORD(ahp->planes);
     826                                ahp->rate       = BYTESWAP_DWORD(ahp->rate);
     827                                ahp->flags      = BYTESWAP_DWORD(ahp->flags);
     828                                rtp = NEXT_TAG(rtp);
     829                        }
     830                        else if(!memcmp(rtp->tag, rate, sizeof(rate)))
     831                        {
     832                                int cnt = rtp->size / sizeof(DWORD);
     833                                DWORD *dwp = (DWORD *)(rtp+1);
     834                                int i;
     835                                for(i = 0; i < cnt; i++)
     836                                        dwp[i] = BYTESWAP_DWORD(dwp[i]);
     837                                rtp = NEXT_TAG(rtp);
     838                        }
     839                        else if(!memcmp(rtp->tag, seq, sizeof(seq)))
     840                        {
     841                                int cnt = rtp->size / sizeof(DWORD);
     842                                DWORD *dwp = (DWORD *)(rtp+1);
     843                                int i;
     844                                for(i = 0; i < cnt; i++)
     845                                        dwp[i] = BYTESWAP_DWORD(dwp[i]);
     846                                rtp = NEXT_TAG(rtp);
     847                        }
     848                        else
     849                                internal_error(__FILE__, __LINE__, "Unknown tag \"%c%c%c%c\" in RIFF file",
     850                                       isprint(rtp->tag[0]) ? rtp->tag[0] : '.',
     851                                       isprint(rtp->tag[1]) ? rtp->tag[1] : '.',
     852                                       isprint(rtp->tag[2]) ? rtp->tag[2] : '.',
     853                                       isprint(rtp->tag[3]) ? rtp->tag[3] : '.');
     854
     855                        /* FIXME: This relies in sizeof(DWORD) == sizeof(pointer_type) */
     856                        if((DWORD)rtp & 1)
     857                                ((char *)rtp)++;
     858                }
     859
     860                /* We must end correctly here */
     861                if((char *)rtp != (char *)rd->data + rd->size)
     862                        yyerror("Animated %s contains invalid field size(s)", anistr);
     863        }
     864
     865        ani->data = rd;
     866        if(memopt)
     867        {
     868                ani->memopt = *memopt;
     869                free(memopt);
     870        }
     871        else
     872                ani->memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE;
     873        return ani;
     874}
     875#undef NEXT_TAG
     876
     877/* Bitmaps */
    185878bitmap_t *new_bitmap(raw_data_t *rd, int *memopt)
    186879{
    187880        bitmap_t *bmp = (bitmap_t *)xmalloc(sizeof(bitmap_t));
     881
    188882        bmp->data = rd;
    189883        if(memopt)
     
    194888        else
    195889                bmp->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
     890        rd->size -= convert_bitmap(rd->data, rd->size);
    196891        return bmp;
    197892}
     
    214909}
    215910
    216 messagetable_t *new_messagetable(raw_data_t *rd)
     911#define MSGTAB_BAD_PTR(p, b, l, r)      (((l) - ((char *)(p) - (char *)(b))) > (r))
     912messagetable_t *new_messagetable(raw_data_t *rd, int *memopt)
    217913{
    218914        messagetable_t *msg = (messagetable_t *)xmalloc(sizeof(messagetable_t));
     915        msgtab_block_t *mbp;
     916        DWORD nblk;
     917        DWORD i;
     918        WORD lo;
     919        WORD hi;
     920
    219921        msg->data = rd;
     922        if(memopt)
     923        {
     924                msg->memopt = *memopt;
     925                free(memopt);
     926        }
     927        else
     928                msg->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
     929
     930        if(rd->size < sizeof(DWORD))
     931                yyerror("Invalid messagetable, size too small");
     932
     933        nblk = *(DWORD *)rd->data;
     934        lo = WRC_LOWORD(nblk);
     935        hi = WRC_HIWORD(nblk);
     936
     937        /* FIXME:
     938         * This test will fail for all n*2^16 blocks in the messagetable.
     939         * However, no sane person would want to have so many blocks
     940         * and have a table of megabytes attached.
     941         * So, I will assume that we have less than 2^16 blocks in the table
     942         * and all will just work out fine. Otherwise, we would need to test
     943         * the ID, offset and length (and flag) fields to be very sure.
     944         */
     945        if(hi && lo)
     946                internal_error(__FILE__, __LINE__, "Messagetable contains more than 65535 blocks; cannot determine endian");
     947        if(!hi && !lo)
     948                yyerror("Invalid messagetable block count 0");
     949
     950        if(!hi && lo)  /* Messagetable byteorder == native byteorder */
     951        {
     952#ifdef WORDS_BIGENDIAN
     953                if(byteorder != WRC_BO_LITTLE) goto out;
     954#else
     955                if(byteorder != WRC_BO_BIG) goto out;
     956#endif
     957                /* Resource byteorder != native byteorder */
     958
     959                mbp = (msgtab_block_t *)&(((DWORD *)rd->data)[1]);
     960                if(MSGTAB_BAD_PTR(mbp, rd->data, rd->size, nblk * sizeof(*mbp)))
     961                        yyerror("Messagetable's blocks are outside of defined data");
     962                for(i = 0; i < nblk; i++)
     963                {
     964                        msgtab_entry_t *mep, *next_mep;
     965                        DWORD id;
     966
     967                        mep = (msgtab_entry_t *)(((char *)rd->data) + mbp[i].offset);
     968
     969                        for(id = mbp[i].idlo; id <= mbp[i].idhi; id++)
     970                        {
     971                                if(MSGTAB_BAD_PTR(mep, rd->data, rd->size, mep->length))
     972                                        yyerror("Messagetable's data for block %d, ID 0x%08lx is outside of defined data", (int)i, id);
     973                                if(mep->flags == 1)     /* Docu says 'flags == 0x0001' for unicode */
     974                                {
     975                                        WORD *wp = (WORD *)&mep[1];
     976                                        int l = mep->length/2 - 2; /* Length included header */
     977                                        int n;
     978
     979                                        if(mep->length & 1)
     980                                                yyerror("Message 0x%08lx is unicode (block %d), but has odd length (%d)", id, (int)i, mep->length);
     981                                        for(n = 0; n < l; n++)
     982                                                wp[n] = BYTESWAP_WORD(wp[n]);
     983                                               
     984                                }
     985                                next_mep = (msgtab_entry_t *)(((char *)mep) + mep->length);
     986                                mep->length = BYTESWAP_WORD(mep->length);
     987                                mep->flags  = BYTESWAP_WORD(mep->flags);
     988                                mep = next_mep;
     989                        }
     990
     991                        mbp[i].idlo   = BYTESWAP_DWORD(mbp[i].idlo);
     992                        mbp[i].idhi   = BYTESWAP_DWORD(mbp[i].idhi);
     993                        mbp[i].offset = BYTESWAP_DWORD(mbp[i].offset);
     994                }
     995        }
     996        if(hi && !lo)  /* Messagetable byteorder != native byteorder */
     997        {
     998#ifdef WORDS_BIGENDIAN
     999                if(byteorder == WRC_BO_LITTLE) goto out;
     1000#else
     1001                if(byteorder == WRC_BO_BIG) goto out;
     1002#endif
     1003                /* Resource byteorder == native byteorder */
     1004
     1005                mbp = (msgtab_block_t *)&(((DWORD *)rd->data)[1]);
     1006                nblk = BYTESWAP_DWORD(nblk);
     1007                if(MSGTAB_BAD_PTR(mbp, rd->data, rd->size, nblk * sizeof(*mbp)))
     1008                        yyerror("Messagetable's blocks are outside of defined data");
     1009                for(i = 0; i < nblk; i++)
     1010                {
     1011                        msgtab_entry_t *mep;
     1012                        DWORD id;
     1013
     1014                        mbp[i].idlo   = BYTESWAP_DWORD(mbp[i].idlo);
     1015                        mbp[i].idhi   = BYTESWAP_DWORD(mbp[i].idhi);
     1016                        mbp[i].offset = BYTESWAP_DWORD(mbp[i].offset);
     1017                        mep = (msgtab_entry_t *)(((char *)rd->data) + mbp[i].offset);
     1018
     1019                        for(id = mbp[i].idlo; id <= mbp[i].idhi; id++)
     1020                        {
     1021                                mep->length = BYTESWAP_WORD(mep->length);
     1022                                mep->flags  = BYTESWAP_WORD(mep->flags);
     1023
     1024                                if(MSGTAB_BAD_PTR(mep, rd->data, rd->size, mep->length))
     1025                                        yyerror("Messagetable's data for block %d, ID 0x%08lx is outside of defined data", (int)i, id);
     1026                                if(mep->flags == 1)     /* Docu says 'flags == 0x0001' for unicode */
     1027                                {
     1028                                        WORD *wp = (WORD *)&mep[1];
     1029                                        int l = mep->length/2 - 2; /* Length included header */
     1030                                        int n;
     1031
     1032                                        if(mep->length & 1)
     1033                                                yyerror("Message 0x%08lx is unicode (block %d), but has odd length (%d)", id, (int)i, mep->length);
     1034                                        for(n = 0; n < l; n++)
     1035                                                wp[n] = BYTESWAP_WORD(wp[n]);
     1036                                               
     1037                                }
     1038                                mep = (msgtab_entry_t *)(((char *)mep) + mep->length);
     1039                        }
     1040                }
     1041        }
     1042
     1043 out:
    2201044        return msg;
    2211045}
    222 
    223 void copy_raw_data(raw_data_t *dst, raw_data_t *src, int offs, int len)
     1046#undef MSGTAB_BAD_PTR
     1047
     1048void copy_raw_data(raw_data_t *dst, raw_data_t *src, unsigned int offs, int len)
    2241049{
    2251050        assert(offs <= src->size);
     
    2941119        return st;
    2951120}
     1121
  • trunk/tools/wrc/newstruc.h

    r3426 r5522  
    4242__NEW_STRUCT_PROTO(string);
    4343__NEW_STRUCT_PROTO(toolbar_item);
     44__NEW_STRUCT_PROTO(ani_any);
    4445
    4546resource_t *new_resource(enum res_e t, void *res, int memopt, language_t *lan);
     
    5455user_t *new_user(name_id_t *type, raw_data_t *rd, int *memopt);
    5556font_t *new_font(raw_data_t *rd, int *memopt);
     57fontdir_t *new_fontdir(raw_data_t *rd, int *memopt);
    5658icon_group_t *new_icon_group(raw_data_t *rd, int *memopt);
    5759cursor_group_t *new_cursor_group(raw_data_t *rd, int *memopt);
     60ani_curico_t *new_ani_curico(enum res_e type, raw_data_t *rd, int *memopt);
    5861bitmap_t *new_bitmap(raw_data_t *rd, int *memopt);
    5962ver_words_t *new_ver_words(int i);
    6063ver_words_t *add_ver_words(ver_words_t *w, int i);
    61 messagetable_t *new_messagetable(raw_data_t *rd);
     64messagetable_t *new_messagetable(raw_data_t *rd, int *memopt);
    6265dlginit_t *new_dlginit(raw_data_t *rd, int *memopt);
    63 void copy_raw_data(raw_data_t *dst, raw_data_t *src, int offs, int len);
     66void copy_raw_data(raw_data_t *dst, raw_data_t *src, unsigned int offs, int len);
    6467int *new_int(int i);
    6568stringtable_t *new_stringtable(lvc_t *lvc);
  • trunk/tools/wrc/parser.h

    r3426 r5522  
    1010/* From parser.y */
    1111extern int yydebug;
    12 extern int indialog;            /* Set when parsing dialogs */
    13 extern int want_rscname;        /* Set when a resource's name is required */
     12extern int want_nl;             /* Set when getting line-numers */
     13extern int want_id;             /* Set when getting the resource name */
    1414
    1515int yyparse(void);
    16 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico);
    17 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur);
    1816
    1917/* From parser.l */
    2018extern FILE *yyin;
    2119extern char *yytext;
    22 extern int line_number;
    23 extern int char_number;
     20extern int yy_flex_debug;
    2421
    2522int yylex(void);
    26 void set_yywf(void);
    2723void set_pp_ignore(int state);
    28 void push_to(int start);
    29 void pop_start(void);
    30 void strip_extern(void);
    3124void strip_til_semicolon(void);
    3225void strip_til_parenthesis(void);
  • trunk/tools/wrc/parser.l

    r3426 r5522  
    11/* -*-C-*-
    22 *
    3  * Copyright 1994 Martin von Loewis
    4  * Copyright 1998 Bertho A. Stultiens (BS)
     3 * Copyright 1998-2000  Bertho A. Stultiens (BS)
    54 *
     5 * 21-May-2000 BS       - Fixed the ident requirement of resource names
     6 *                        which can be keywords.
     7 * 30-Apr-2000 BS       - Reintegration into the wine-tree
     8 * 11-Jan-2000 BS       - Very drastic cleanup because we don't have a
     9 *                        preprocessor in here anymore.
     10 * 02-Jan-2000 BS       - Removed the preprocessor code
     11 * 23-Dec-1999 BS       - Removed the copyright for Martin von Loewis.
     12 *                        There is really nothing left of his code in
     13 *                        this parser.
    614 * 20-Jun-1998 BS       - Changed the filename conversion. Filenames are
    715 *                        case-sensitive inder *nix, but not under dos.
     
    4553 */
    4654
    47 /* Exclusive rules when looking for a filename */
    48 %x yywf
    49 %x yywf_s
    5055/* Exclusive string handling */
    5156%x yystr
     
    5661/* Exclusive comment eating... */
    5762%x comment
    58 /* Preprocessor exclusives */
    59 %x pp_incl
    60 %x pp_def
    61 %x pp_undef
    62 %x pp_if
    63 %x pp_ifdef
    64 %x pp_ifndef
    65 %x pp_elif
    66 %x pp_else
    67 %x pp_endif
    68 %x pp_error
    69 /* Set when accumulating #define's expansion text */
    70 %x pp_def_s
    71 /* Set when processing function type defines */
    72 %x pp_ignore
    73 /* Set when need to strip to eol */
    74 %x pp_ignore_eol
    75 /* Set when handling a false #if case */
    76 %x pp_false
    7763/* Set when stripping c-junk */
    7864%x pp_stripe
     
    8066%x pp_stripp
    8167%x pp_stripp_final
    82 
    83 /*%option stack*/
     68/* Set when scanning #line style directives */
     69%x pp_line
     70
     71%option stack
    8472%option never-interactive
    85 /*%option noyywrap */
     73
    8674/* Some shortcut definitions */
    8775ws      [ \f\t\r]
     
    8977
    9078%{
    91 
    92 #if !defined(YY_FLEX_MAJOR_VERSION) || (1000 * YY_FLEX_MAJOR_VERSION + YY_FLEX_MINOR_VERSION < 2005)
    93 #error Must use flex version 2.5.1 or higher (yy_scan_* routines are required).
    94 #endif
    9579
    9680/*#define LEX_DEBUG*/
     
    10286#include <string.h>
    10387#include <ctype.h>
     88#include <assert.h>
    10489
    10590#include "wrc.h"
     
    11398#define YY_USE_PROTOS
    11499#define YY_NO_UNPUT
     100#define YY_NO_TOP_STATE
    115101
    116102/* Always update the current character position within a line */
    117 #define YY_USER_ACTION  char_number+=yyleng;
    118 
    119 raw_data_t *new_raw_data(void);
    120 
    121 void addcchar(char c);
    122 void addwchar(short s);
    123 string_t *get_buffered_cstring(void);
    124 string_t *get_buffered_wstring(void);
    125 string_t *make_string(char *s);
    126 string_t *make_filename(char *s, int len);
    127 
    128 int line_number = 1;            /* The current line */
    129 int char_number = 1;            /* The current char pos within the line */
     103#define YY_USER_ACTION  char_number+=yyleng; wanted_id = want_id; want_id = 0;
     104
     105static void addcchar(char c);
     106static void addwchar(short s);
     107static string_t *get_buffered_cstring(void);
     108static string_t *get_buffered_wstring(void);
     109static string_t *make_string(char *s);
     110
    130111static char *cbuffer;           /* Buffers for string collection */
    131112static int cbufidx;
     
    134115static int wbufidx;
    135116static int wbufalloc = 0;
    136 static int want_nl = 0;         /* Set when newline needs to go to parser */
    137 static int want_ident = 0;      /* Set is #ifdef, #ifndef or defined is seen */
    138117static int stripslevel = 0;     /* Count {} during pp_strips/pp_stripe mode */
    139118static int stripplevel = 0;     /* Count () during pp_strips mode */
    140 static char *substtext = NULL;  /* Holds the substition text while getting a define */
    141119static int cjunk_tagline;       /* Where did we start stripping (helps error tracking) */
    142120
    143 #ifdef YY_USE_STACK
    144 void push_to(int start) { yy_push_state(start); }
    145 void pop_start(void)    { yy_pop_state(start); }
    146 #else
    147 #define MAXSTARTSTACK   32
    148 static int startstack[MAXSTARTSTACK];
    149 static int startstackidx = 0;
    150 
    151 void push_to(int start)
    152 {
    153         if(yydebug)
    154                 printf("push_to(%d): %d -> %d\n", line_number, YY_START, start);
    155         if(startstackidx >= MAXSTARTSTACK-1)
    156                 internal_error(__FILE__, __LINE__, "Start condition stack overflow");
    157         startstack[startstackidx++] = YY_START;
    158         BEGIN(start);
    159 }
    160 
    161 void pop_start(void)
    162 {
    163         if(yydebug)
    164                 printf("pop_start(%d): %d <- %d\n", line_number, startstack[startstackidx-1], YY_START);
    165         if(startstackidx <= 0)
    166                 internal_error(__FILE__, __LINE__, "Start condition stack underflow");
    167         --startstackidx;
    168         BEGIN(startstack[startstackidx]);
    169 }
    170 #endif
    171 
    172 
    173 struct bufferstackentry {
    174         YY_BUFFER_STATE bufferstate;    /* Buffer to switch back to */
    175         struct pp_entry *define;        /* Points to expanding define
    176                                            or NULL if handling includes
    177                                          */
    178         int line_number;                /* Line that we were handling */
    179         int char_number;                /* The current position */
    180         char *filename;                 /* Filename that we were handling */
    181 };
    182 
    183 #define MAXBUFFERSTACK 128
    184 static struct bufferstackentry bufferstack[MAXBUFFERSTACK];
    185 static int bufferstackidx = 0;
    186 
    187 void push_buffer(YY_BUFFER_STATE buf, struct pp_entry *ppp, char *filename)
    188 {
    189         if(yydebug)
    190                 printf("push_buffer: %p %p %p\n", buf, ppp, filename);
    191         if(bufferstackidx >= MAXBUFFERSTACK-1)
    192                 internal_error(__FILE__, __LINE__, "Buffer stack overflow");
    193         memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
    194         bufferstack[bufferstackidx].bufferstate = buf;
    195         bufferstack[bufferstackidx].define = ppp;
    196         if(ppp)
    197                 ppp->expanding = 1;
    198         else if(filename)
    199         {
    200                 /* These will track the yyerror to the correct file and line */
    201                 bufferstack[bufferstackidx].line_number = line_number;
    202                 bufferstack[bufferstackidx].char_number = char_number;
    203                 line_number = 1;
    204                 char_number = 1;
    205                 bufferstack[bufferstackidx].filename = input_name;
    206                 input_name = filename;
    207         }
    208         else
    209                 internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
    210         bufferstackidx++;
    211 }
    212 
    213 YY_BUFFER_STATE pop_buffer(void)
    214 {
    215         if(bufferstackidx <= 0)
    216                 return (YY_BUFFER_STATE)0;
    217         bufferstackidx--;
    218         if(bufferstack[bufferstackidx].define)
    219                 bufferstack[bufferstackidx].define->expanding = 0;
    220         else
    221         {
    222                 line_number = bufferstack[bufferstackidx].line_number;
    223                 char_number = bufferstack[bufferstackidx].char_number;
    224                 input_name = bufferstack[bufferstackidx].filename;
    225                 fclose(yyin);
    226         }
    227         if(yydebug)
    228                 printf("pop_buffer: %p %p (%d, %d) %p\n",
    229                         bufferstack[bufferstackidx].bufferstate,
    230                         bufferstack[bufferstackidx].define,
    231                         bufferstack[bufferstackidx].line_number,
    232                         bufferstack[bufferstackidx].char_number,
    233                         bufferstack[bufferstackidx].filename);
    234         yy_switch_to_buffer(bufferstack[bufferstackidx].bufferstate);
    235         return bufferstack[bufferstackidx].bufferstate;
    236 }
    237 
    238 void do_include(char *name, int namelen)
    239 {
    240         char *cpy = (char *)xmalloc(namelen);
    241         strcpy(cpy, name+1);    /* strip leading " or < */
    242         cpy[namelen-2] = '\0';  /* strip trailing " or > */
    243         if((yyin = open_include(cpy, name[0] == '"')) == NULL)
    244                 yyerror("Unable to open include file %s", cpy);
    245         push_buffer(YY_CURRENT_BUFFER, NULL, cpy);
    246         yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
    247 }
    248 
     121/*
     122 * This one is a bit tricky.
     123 * We set 'want_id' in the parser to get the first
     124 * identifier we get across in the scanner, but we
     125 * also want it to be reset at nearly any token we
     126 * see. Exceptions are:
     127 * - newlines
     128 * - comments
     129 * - whitespace
     130 *
     131 * The scanner will automatically reset 'want_id'
     132 * after *each* scanner reduction and puts is value
     133 * into the var below. In this way we can see the
     134 * state after the YY_RULE_SETUP (i.e. the user action;
     135 * see above) and don't have to worry too much when
     136 * it needs to be reset.
     137 */
     138static int wanted_id = 0;
     139static int save_wanted_id;      /* To save across comment reductions */
    249140
    250141struct keyword {
     
    253144        int     isextension;
    254145        int     needcase;
    255         int     alwayskeyword;
     146        int     alwayskw;
    256147};
    257148
    258149static struct keyword keywords[] = {
    259         { "ACCELERATORS", ACCELERATORS, 0, 0, 0},
    260         { "ALT", ALT, 0, 0, 0},
    261         { "ASCII", ASCII, 0, 0, 0},
    262         { "AUTO3STATE", AUTO3STATE, 1, 0, 0},
    263         { "AUTOCHECKBOX", AUTOCHECKBOX, 1, 0, 0},
    264         { "AUTORADIOBUTTON", AUTORADIOBUTTON, 1, 0, 0},
    265         { "BEGIN", tBEGIN, 0, 0, 1},
    266         { "BITMAP", tBITMAP, 0, 0, 0},
    267         { "BLOCK", BLOCK, 0, 0, 1},
    268         { "BUTTON", BUTTON, 1, 0, 0},
    269         { "CAPTION", CAPTION, 0, 0, 0},
    270         { "CHARACTERISTICS", CHARACTERISTICS, 1, 0, 0},
    271         { "CHECKBOX", CHECKBOX, 0, 0, 0},
    272         { "CHECKED", CHECKED, 0, 0, 0},
    273         { "CLASS", CLASS, 0, 0, 0},
    274         { "COMBOBOX", COMBOBOX, 0, 0, 0},
    275         { "CONTROL", CONTROL, 0, 0, 0},
    276         { "CTEXT", CTEXT, 0, 0, 0},
    277         { "CURSOR", CURSOR, 0, 0, 0},
    278         { "defined", tDEFINED, 0, 1, 1},
    279         { "DEFPUSHBUTTON", DEFPUSHBUTTON, 0, 0, 1},
    280         { "DIALOG", DIALOG, 0, 0, 0},
    281         { "DIALOGEX", DIALOGEX, 1, 0, 0},
    282         { "DISCARDABLE", DISCARDABLE, 0, 0, 0},
    283         { "DLGINIT", DLGINIT, 0, 0, 0},
    284         { "EDITTEXT", EDITTEXT, 0, 0, 0},
    285         { "END", tEND, 0, 0, 1},
    286         { "EXSTYLE", EXSTYLE, 0, 0, 0},
    287         { "extern", tEXTERN, 0, 1, 1},
    288         { "FILEFLAGS", FILEFLAGS, 0, 0, 0},
    289         { "FILEFLAGSMASK", FILEFLAGSMASK, 0, 0, 0},
    290         { "FILEOS", FILEOS, 0, 0, 0},
    291         { "FILESUBTYPE", FILESUBTYPE, 0, 0, 0},
    292         { "FILETYPE", FILETYPE, 0, 0, 0},
    293         { "FILEVERSION", FILEVERSION, 0, 0, 0},
    294         { "FIXED", tFIXED, 0, 0, 0},
    295         { "FONT", FONT, 0, 0, 0},
    296         { "GRAYED", GRAYED, 0, 0, 0},
    297         { "GROUPBOX", GROUPBOX, 0, 0, 0},
    298         { "HELP", HELP, 0, 0, 0},
    299         { "ICON", ICON, 0, 0, 0},
    300         { "IMPURE", IMPURE, 0, 0, 0},
    301         { "INACTIVE", INACTIVE, 0, 0, 0},
    302         { "LANGUAGE", LANGUAGE, 1, 0, 1},
    303         { "LISTBOX", LISTBOX, 0, 0, 0},
    304         { "LOADONCALL", LOADONCALL, 0, 0, 0},
    305         { "LTEXT", LTEXT, 0, 0, 0},
    306         { "MENU", MENU, 0, 0, 0},
    307         { "MENUBARBREAK", MENUBARBREAK, 0, 0, 0},
    308         { "MENUBREAK", MENUBREAK, 0, 0, 0},
    309         { "MENUEX", MENUEX, 1, 0, 0},
    310         { "MENUITEM", MENUITEM, 0, 0, 0},
    311         { "MESSAGETABLE", MESSAGETABLE, 1, 0, 0},
    312         { "MOVEABLE", MOVEABLE, 0, 0, 0},
    313         { "NOINVERT", NOINVERT, 0, 0, 0},
    314         { "NOT", NOT, 0, 0, 0},
    315         { "POPUP", POPUP, 0, 0, 0},
    316         { "PRELOAD", PRELOAD, 0, 0, 0},
    317         { "PRODUCTVERSION", PRODUCTVERSION, 0, 0, 0},
    318         { "PURE", tPURE, 0, 0, 0},
    319         { "PUSHBUTTON", PUSHBUTTON, 0, 0, 0},
    320         { "RADIOBUTTON", RADIOBUTTON, 0, 0, 0},
    321         { "RCDATA", RCDATA, 0, 0, 0},
    322         { "RTEXT", RTEXT, 0, 0, 0},
    323         { "SCROLLBAR", SCROLLBAR, 0, 0, 0},
    324         { "SEPARATOR", SEPARATOR, 0, 0, 0},
    325         { "SHIFT", SHIFT, 0, 0, 0},
    326         { "STATE3", STATE3, 1, 0, 0},
    327         { "STRING", tSTRING, 0, 0, 0},
    328         { "STRINGTABLE", STRINGTABLE, 0, 0, 1},
    329         { "STYLE", STYLE, 0, 0, 0},
    330         { "TOOLBAR", TOOLBAR, 1, 0, 0},
    331         { "typedef", tTYPEDEF, 0, 1, 1},
    332         { "VALUE", VALUE, 0, 0, 0},
    333         { "VERSION", VERSION, 1, 0, 0},
    334         { "VERSIONINFO", VERSIONINFO, 0, 0, 0},
    335         { "VIRTKEY", VIRTKEY, 0, 0, 0}
     150        { "ACCELERATORS",       tACCELERATORS,          0, 0, 0},
     151        { "ALT",                tALT,                   0, 0, 0},
     152        { "ASCII",              tASCII,                 0, 0, 0},
     153        { "AUTO3STATE",         tAUTO3STATE,            1, 0, 0},
     154        { "AUTOCHECKBOX",       tAUTOCHECKBOX,          1, 0, 0},
     155        { "AUTORADIOBUTTON",    tAUTORADIOBUTTON,       1, 0, 0},
     156        { "BEGIN",              tBEGIN,                 0, 0, 0},
     157        { "BITMAP",             tBITMAP,                0, 0, 0},
     158        { "BLOCK",              tBLOCK,                 0, 0, 0},
     159        { "BUTTON",             tBUTTON,                1, 0, 0},
     160        { "CAPTION",            tCAPTION,               0, 0, 0},
     161        { "CHARACTERISTICS",    tCHARACTERISTICS,       1, 0, 0},
     162        { "CHECKBOX",           tCHECKBOX,              0, 0, 0},
     163        { "CHECKED",            tCHECKED,               0, 0, 0},
     164        { "CLASS",              tCLASS,                 0, 0, 0},
     165        { "COMBOBOX",           tCOMBOBOX,              0, 0, 0},
     166        { "CONTROL",            tCONTROL,               0, 0, 0},
     167        { "CTEXT",              tCTEXT,                 0, 0, 0},
     168        { "CURSOR",             tCURSOR,                0, 0, 0},
     169        { "DEFPUSHBUTTON",      tDEFPUSHBUTTON,         0, 0, 0},
     170        { "DIALOG",             tDIALOG,                0, 0, 0},
     171        { "DIALOGEX",           tDIALOGEX,              1, 0, 0},
     172        { "DISCARDABLE",        tDISCARDABLE,           0, 0, 0},
     173        { "DLGINIT",            tDLGINIT,               0, 0, 0},
     174        { "EDITTEXT",           tEDITTEXT,              0, 0, 0},
     175        { "END",                tEND,                   0, 0, 0},
     176        { "enum",               tENUM,                  0, 1, 1},
     177        { "EXSTYLE",            tEXSTYLE,               0, 0, 0},
     178        { "extern",             tEXTERN,                0, 1, 1},
     179        { "FILEFLAGS",          tFILEFLAGS,             0, 0, 0},
     180        { "FILEFLAGSMASK",      tFILEFLAGSMASK,         0, 0, 0},
     181        { "FILEOS",             tFILEOS,                0, 0, 0},
     182        { "FILESUBTYPE",        tFILESUBTYPE,           0, 0, 0},
     183        { "FILETYPE",           tFILETYPE,              0, 0, 0},
     184        { "FILEVERSION",        tFILEVERSION,           0, 0, 0},
     185        { "FIXED",              tFIXED,                 0, 0, 0},
     186        { "FONT",               tFONT,                  0, 0, 0},
     187        { "FONTDIR",            tFONTDIR,               0, 0, 0},       /* This is a Borland BRC extension */
     188        { "GRAYED",             tGRAYED,                0, 0, 0},
     189        { "GROUPBOX",           tGROUPBOX,              0, 0, 0},
     190        { "HELP",               tHELP,                  0, 0, 0},
     191        { "ICON",               tICON,                  0, 0, 0},
     192        { "IMPURE",             tIMPURE,                0, 0, 0},
     193        { "INACTIVE",           tINACTIVE,              0, 0, 0},
     194        { "inline",             tINLINE,                0, 1, 1},
     195        { "LANGUAGE",           tLANGUAGE,              1, 0, 1},
     196        { "LISTBOX",            tLISTBOX,               0, 0, 0},
     197        { "LOADONCALL",         tLOADONCALL,            0, 0, 0},
     198        { "LTEXT",              tLTEXT,                 0, 0, 0},
     199        { "MENU",               tMENU,                  0, 0, 0},
     200        { "MENUBARBREAK",       tMENUBARBREAK,          0, 0, 0},
     201        { "MENUBREAK",          tMENUBREAK,             0, 0, 0},
     202        { "MENUEX",             tMENUEX,                1, 0, 0},
     203        { "MENUITEM",           tMENUITEM,              0, 0, 0},
     204        { "MESSAGETABLE",       tMESSAGETABLE,          1, 0, 0},
     205        { "MOVEABLE",           tMOVEABLE,              0, 0, 0},
     206        { "NOINVERT",           tNOINVERT,              0, 0, 0},
     207        { "NOT",                tNOT,                   0, 0, 0},
     208        { "POPUP",              tPOPUP,                 0, 0, 0},
     209        { "PRELOAD",            tPRELOAD,               0, 0, 0},
     210        { "PRODUCTVERSION",     tPRODUCTVERSION,        0, 0, 0},
     211        { "PURE",               tPURE,                  0, 0, 0},
     212        { "PUSHBUTTON",         tPUSHBUTTON,            0, 0, 0},
     213        { "RADIOBUTTON",        tRADIOBUTTON,           0, 0, 0},
     214        { "RCDATA",             tRCDATA,                0, 0, 0},
     215        { "RTEXT",              tRTEXT,                 0, 0, 0},
     216        { "SCROLLBAR",          tSCROLLBAR,             0, 0, 0},
     217        { "SEPARATOR",          tSEPARATOR,             0, 0, 0},
     218        { "SHIFT",              tSHIFT,                 0, 0, 0},
     219        { "STATE3",             tSTATE3,                1, 0, 0},
     220        { "static",             tSTATIC,                0, 1, 1},
     221        { "STRING",             tSTRING,                0, 0, 0},
     222        { "STRINGTABLE",        tSTRINGTABLE,           0, 0, 1},
     223        { "struct",             tSTRUCT,                0, 1, 1},
     224        { "STYLE",              tSTYLE,                 0, 0, 0},
     225        { "TOOLBAR",            tTOOLBAR,               1, 0, 0},
     226        { "typedef",            tTYPEDEF,               0, 1, 1},
     227        { "VALUE",              tVALUE,                 0, 0, 0},
     228        { "VERSION",            tVERSION,               1, 0, 0},
     229        { "VERSIONINFO",        tVERSIONINFO,           0, 0, 0},
     230        { "VIRTKEY",            tVIRTKEY,               0, 0, 0}
    336231};
    337232
    338233#define NKEYWORDS       (sizeof(keywords)/sizeof(keywords[0]))
    339234#define KWP(p)          ((struct keyword *)(p))
    340 int kw_cmp_func(const void *s1, const void *s2)
     235static int kw_cmp_func(const void *s1, const void *s2)
    341236{
    342237        int ret;
     
    350245#define KW_BSEARCH
    351246#define DO_SORT
    352 struct keyword *iskeyword(char *kw)
     247static struct keyword *iskeyword(char *kw)
    353248{
    354249        struct keyword *kwp;
     
    384279#endif
    385280
    386 #ifdef LEX_DEBUG
    387         if(kwp && !strcmp(kwp->keyword, "LANGUAGE"))
    388                 printf("Got Language\n");
    389 #endif
    390281        if(kwp == NULL || (kwp->isextension && !extensions))
    391282                return NULL;
     
    394285}
    395286
    396 void add_to_substtext(char *text, int len)
    397 {
    398         if(!substtext)
    399         {
    400                 substtext = xstrdup(text);
     287%}
     288
     289/*
     290 **************************************************************************
     291 * The flexer starts here
     292 **************************************************************************
     293 */
     294%%
     295        /*
     296         * Catch the GCC-style line statements here and parse them.
     297         * This has the advantage that you can #include at any
     298         * stage in the resource file.
     299         * The preprocessor generates line directives in the format:
     300         * # <linenum> "filename" <codes>
     301         *
     302         * Codes can be a sequence of:
     303         * - 1 start of new file
     304         * - 2 returning to previous
     305         * - 3 system header
     306         * - 4 interpret as C-code
     307         *
     308         * 4 is not used and 1 mutually excludes 2
     309         * Anyhow, we are not really interested in these at all
     310         * because we only want to know the linenumber and
     311         * filename.
     312         */
     313<INITIAL,pp_strips,pp_stripp>^{ws}*\#{ws}*      yy_push_state(pp_line);
     314<pp_line>[^\n]* {
     315                int lineno;
     316                char *cptr;
     317                char *fname;
     318                yy_pop_state();
     319                lineno = (int)strtol(yytext, &cptr, 10);
     320                if(!lineno)
     321                        yyerror("Malformed '#...' line-directive; invalid linenumber");
     322                fname = strchr(cptr, '"');
     323                if(!fname)
     324                        yyerror("Malformed '#...' line-directive; missing filename");
     325                fname++;
     326                cptr = strchr(fname, '"');
     327                if(!cptr)
     328                        yyerror("Malformed '#...' line-directive; missing terminating \"");
     329                *cptr = '\0';
     330                line_number = lineno - 1;       /* We didn't read the newline */
     331                input_name = xstrdup(fname);
    401332        }
    402         else
    403         {
    404                 substtext = (char *)xrealloc(substtext, strlen(substtext)+len+1);
    405                 strcat(substtext, text);
    406         }
    407 }
    408 
    409 %}
    410 
    411 %%
    412         /* #include handling */
    413 ^{ws}*#{ws}*include{ws}*        push_to(pp_incl);
    414 <pp_incl>\<[^\n\>]+\>           do_include(yytext, yyleng); pop_start();
    415 <pp_incl>\"[^\n\>]+\"           do_include(yytext, yyleng); pop_start();
    416 <pp_incl>.              yyerror("Malformed #include");
    417 
    418         /* #define handling */
    419 ^{ws}*#{ws}*define{ws}* push_to(pp_def);
    420 <pp_def>{cident}        {
    421                                 set_define(yytext);
    422                                 push_to(pp_def_s);
    423                         }
    424 <pp_def>{cident}\(      push_to(pp_ignore); /* Ignore function-like defines for now*/
    425 <pp_def>.               yyerror("Malformed #define");
    426 
    427 <pp_ignore,pp_def_s>[^\/\\\n]*  {
    428                         if(YY_START == pp_def_s)
    429                                 add_to_substtext(yytext, yyleng);
    430                 }
    431 <pp_ignore,pp_def_s>\/[^\/\*][^\/\\\n]* { /* Comment is handled in normal handling */
    432                         if(YY_START == pp_def_s)
    433                                 add_to_substtext(yytext, yyleng);
    434                 }
    435 <pp_ignore,pp_def_s>\\{ws}*\n   line_number++;  char_number = 1; /* Line continuation */
    436 <pp_ignore,pp_def_s>\n          {
    437                         if(YY_START == pp_def_s)
    438                         {
    439                                 add_define(substtext ? substtext : "");
    440                                 free(substtext);
    441                                 substtext = NULL;
    442                         }
    443                         line_number++;
    444                         char_number = 1;
    445                         pop_start();
    446                         pop_start();
    447                 }
    448 
    449         /* #undef handling */
    450 ^{ws}*#{ws}*undef{ws}*  push_to(pp_undef);
    451 <pp_undef>{cident}      {
    452                                 del_define(yytext);
    453                                 pop_start();
    454                                 /*push_to(pp_ignore);*/
    455                         }
    456 
    457         /* Conditional handling */
    458 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*if{ws}*     {
    459                         if(YY_START == pp_false)
    460                         {
    461                                 if(yydebug)
    462                                         printf("(%d)#if ignored\n", line_number);
    463                                 push_if(0, 0, 1);
    464                                 push_to(pp_ignore_eol);
    465                         }
    466                         else
    467                         {
    468                                 push_to(INITIAL);
    469                                 want_nl = 1;
    470                                 return tIF;
    471                         }
    472                 }
    473 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*ifdef{ws}*  {
    474                         if(YY_START == pp_false)
    475                         {
    476                                 if(yydebug)
    477                                         printf("(%d)#ifdef ignored\n", line_number);
    478                                 push_if(0, 0, 1);
    479                                 push_to(pp_ignore_eol);
    480                         }
    481                         else
    482                         {
    483                                 push_to(INITIAL);
    484                                 want_nl = 1;
    485                                 want_ident = 1;
    486                                 return tIFDEF;
    487                         }
    488                 }
    489 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*ifndef{ws}* {
    490                         if(YY_START == pp_false)
    491                         {
    492                                 if(yydebug)
    493                                         printf("(%d)#ifndef ignored\n", line_number);
    494                                 push_if(0, 0, 1);
    495                                 push_to(pp_ignore_eol);
    496                         }
    497                         else
    498                         {
    499                                 push_to(INITIAL);
    500                                 want_nl = 1;
    501                                 want_ident = 1;
    502                                 return tIFNDEF;
    503                         }
    504                 }
    505 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*elif{ws}*   {
    506                         if(!isnevertrue_if())
    507                         {
    508                                 push_to(INITIAL);
    509                                 want_nl = 1;
    510                                 return tELIF;
    511                         }
    512                         else if(YY_START == pp_false)
    513                                 push_to(pp_ignore_eol);
    514                         if(yydebug)
    515                                 printf("(%d)#elif ignored\n", line_number);
    516                 }
    517 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*else{ws}*   {
    518                         if(!isnevertrue_if())
    519                         {
    520                                 push_to(INITIAL);
    521                                 want_nl = 1;
    522                                 return tELSE;
    523                         }
    524                         if(yydebug)
    525                                 printf("(%d)#else ignored\n", line_number);
    526                 }
    527 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*endif{ws}*  {
    528                         if(!isnevertrue_if())
    529                         {
    530                                 want_nl = 1;
    531                                 return tENDIF;
    532                         }
    533                         else
    534                         {
    535                                 if(yydebug)
    536                                         printf("(%d)#endif ignored\n", line_number);
    537                                 pop_if();
    538                         }
    539                 }
    540 
    541         /* The error directive */
    542 <INITIAL,pp_strips,pp_stripe,pp_stripp>^{ws}*#{ws}*error{ws}*   push_to(pp_error);
    543 <pp_error>[^\n]*        yyerror("Error directive: %s", yytext);
    544 <pp_false>^{ws}*#{ws}*error[^\n]* {
    545                         if(yydebug)
    546                                 printf("(%d)#error ignored\n", line_number);
    547                 }
    548 
    549         /* preprocessor junk */
    550 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*pragma[^\n]*        ;       /* Ignore #pragma */
    551 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*ident[^\n]*         ;       /* Ignore #ident */
    552 <INITIAL,pp_strips,pp_stripe,pp_stripp,pp_false>^{ws}*#{ws}*line[^\n]*          ;       /* Ignore #line */
    553  /* We'll get an error on malformed #xxx statements
    554   * by not recognising '#' at all. This helps tracking
    555   * preprocessor errors.
    556   */
    557  /*^{ws}*#{ws}*                 ;        Ignore # */
    558 
    559 <pp_strips>\{           stripslevel++;
    560 <pp_strips>\}           stripslevel--;
    561 <pp_strips>;            if(!stripslevel) pop_start();
     333
     334        /*
     335         * Strip everything until a ';' taking
     336         * into account braces {} for structures,
     337         * classes and enums.
     338         */
     339<pp_strips>\{                   stripslevel++;
     340<pp_strips>\}                   stripslevel--;
     341<pp_strips>;                    if(!stripslevel) yy_pop_state();
    562342<pp_strips>\/[^*\n]             ; /* To catch comments */
    563343<pp_strips>[^\{\};\n#/]*        ; /* Ignore rest */
    564 
    565 <pp_stripe>\{           stripslevel++;
    566 <pp_stripe>\}   {
    567                         stripslevel--;
    568                         if(!stripslevel) pop_start();
    569                 }
    570 <pp_stripe>;            if(!stripslevel) pop_start();
    571 <pp_stripe>\/[^*\n]             ; /* To catch comments */
    572 <pp_stripe>[^\{\};\n#/]*        ; /* Ignore rest */
    573 
    574 <pp_stripp>\(           stripplevel++;
    575 <pp_stripp>\)           {
    576                                 stripplevel--;
    577                                 if(!stripplevel)
    578                                 {
    579                                         pop_start();
    580                                         push_to(pp_stripp_final);
     344<pp_strips>\n                   line_number++; char_number = 1;
     345
     346<pp_stripp>\(                   stripplevel++;
     347<pp_stripp>\)                   {
     348                                        stripplevel--;
     349                                        if(!stripplevel)
     350                                        {
     351                                                yy_pop_state();
     352                                                yy_push_state(pp_stripp_final);
     353                                        }
    581354                                }
    582                         }
    583355<pp_stripp>\/[^*\n]             ; /* To catch comments */
    584356<pp_stripp>[^\(\);\n#/]*        ; /* Ignore rest */
    585 
    586 <pp_stripp_final>{ws}*  ; /* Ignore */
    587 <pp_stripp_final>;      pop_start(); /* Kill the semicolon */
    588 <pp_stripp_final>\n     line_number++; char_number = 1; pop_start();
    589 <pp_stripp_final>.      yyless(0); pop_start();
    590 
    591 <pp_false>.             ;       /* Ignore everything except #xxx during false #if state */
    592 
    593 <pp_ignore_eol>[^\n]*   pop_start();
    594 
    595  /* These are special cases due to filename scanning */
    596 <yywf>[Dd][Ii][Ss][Cc][Aa][Rr][Dd][Aa][Bb][Ll][Ee]      return DISCARDABLE;
    597 <yywf>[Ff][Ii][Xx][Ee][Dd]                              return tFIXED;
    598 <yywf>[Ii][Mm][Pp][Uu][Rr][Ee]                          return IMPURE;
    599 <yywf>[Mm][Oo][Vv][Ee][Aa][Bb][Ll][Ee]                  return MOVEABLE;
    600 <yywf>[Ll][Oo][Aa][Dd][Oo][Nn][Cc][Aa][Ll][Ll]          return LOADONCALL;
    601 <yywf>[Pp][Rr][Ee][Ll][Oo][Aa][Dd]                      return PRELOAD;
    602 <yywf>[Pp][Uu][Rr][Ee]                                  return tPURE;
     357<pp_stripp>\n                   line_number++; char_number = 1;
     358
     359<pp_stripp_final>{ws}*          ; /* Ignore */
     360<pp_stripp_final>;              yy_pop_state(); /* Kill the semicolon */
     361<pp_stripp_final>\n             line_number++; char_number = 1; yy_pop_state();
     362<pp_stripp_final>.              yyless(0); yy_pop_state();
    603363
    604364\{                      return tBEGIN;
    605365\}                      return tEND;
    606366
    607 [0-9]+[lL]?             { yylval.num = strtoul(yytext,  0, 10); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
    608 0[xX][0-9A-Fa-f]+[lL]?  { yylval.num = strtoul(yytext,  0, 16); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
    609 0[oO][0-7]+[lL]?        { yylval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
     367[0-9]+[lL]?             { yylval.num = strtoul(yytext,  0, 10); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     3680[xX][0-9A-Fa-f]+[lL]?  { yylval.num = strtoul(yytext,  0, 16); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     3690[oO][0-7]+[lL]?        { yylval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
     370
     371        /*
     372         * The next two rules scan identifiers and filenames.
     373         * This is achieved by using the priority ruling
     374         * of the scanner where a '.' is valid in a filename
     375         * and *only* in a filename. In this case, the second
     376         * rule will be reduced because it is longer.
     377         */
    610378[A-Za-z_0-9]+           {
    611                                 struct keyword *token;
    612                                 struct pp_entry *ppp;
    613 
    614                                 want_rscname = 0;
    615                                
    616                                 if(want_ident)
     379                                struct keyword *tok = iskeyword(yytext);
     380
     381                                if(tok)
    617382                                {
    618                                         /* Prevent preprocessor subst */
    619                                         want_ident = 0;
    620                                         yylval.str = make_string(yytext);
    621                                 #ifdef LEX_DEBUG
    622                                         printf("want IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
    623                                 #endif
    624                                         return IDENT;
    625                                 }
    626                                 else if((ppp = pp_lookup(yytext)) != NULL)
    627                                 {
    628                                         /* Do preprocessor substitution,
    629                                          * but expand only if macro is not
    630                                          * already expanding.
    631                                          */
    632                                         if(!ppp->expanding)
     383                                        if(tok->token == tCLASS && !strcmp(yytext, "class"))
     384                                                return tCPPCLASS;
     385                                        else if(wanted_id && !tok->alwayskw)
    633386                                        {
    634                                 #ifdef LEX_DEBUG
    635                                                 printf("expand IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
    636                                 #endif
    637                                                 push_buffer(YY_CURRENT_BUFFER, ppp, NULL);
    638                                                 yy_scan_string(ppp->subst);
     387                                                yylval.str = make_string(yytext);
     388                                                return tIDENT;
    639389                                        }
    640                                 }
    641                                 else if((token = iskeyword(yytext)) != NULL
    642                                   && !(!token->alwayskeyword && want_rscname))
    643                                 {
    644                                         switch(token->token)
    645                                         {
    646                                         case tDEFINED:
    647                                                 want_ident = 1;
    648                                                 break;
    649                                         /*case RCDATA:*/
    650                                         case CURSOR:
    651                                         case tBITMAP:
    652                                         case MESSAGETABLE:
    653                                         case DLGINIT:
    654                                                 push_to(yywf);
    655                                                 break;
    656                                         case FONT:
    657                                         case ICON:
    658                                                 if(!indialog)
    659                                                         push_to(yywf);
    660                                                 break;
    661                                         case DIALOG:
    662                                         case DIALOGEX:
    663                                                 indialog = 1;
    664                                                 break;
    665                                         }
    666                                         return token->token;
     390                                        else
     391                                                return tok->token;
    667392                                }
    668393                                else
    669394                                {
    670395                                        yylval.str = make_string(yytext);
    671                                 #ifdef LEX_DEBUG
    672                                         printf("%s IDENT (%s, %d, %d): <%s>\n",
    673                                                 want_rscname ? "rscname" : "just",
    674                                                 input_name,
    675                                                 line_number,
    676                                                 char_number,
    677                                                 yytext);
    678                                 #endif
    679                                         return IDENT;
     396                                        return tIDENT;
    680397                                }
    681398                        }
    682 \|\|                    return LOGOR;
    683 \&\&                    return LOGAND;
    684 \=\=                    return EQ;
    685 \!\=                    return NE;
    686 \<\=                    return LTE;
    687 \>\=                    return GTE;
    688 
    689 <yywf>[^ \f\t\r\n\"]*   { pop_start(); yylval.str = make_filename(yytext, yyleng); return FILENAME; }
    690 <yywf>\"                push_to(yywf_s);
    691 <yywf_s>[^\"\n]*\"      { pop_start(); pop_start(); yylval.str = make_filename(yytext, yyleng-1); return FILENAME; }
    692 <yywf_s>\n              yyerror("Newline in filename");
    693 
     399[A-Za-z_0-9./\\]+               yylval.str = make_string(yytext); return tFILENAME;
     400
     401        /*
     402         * Wide string scanning
     403         */
    694404L\"                     {
    695                                 push_to(yylstr);
     405                                yy_push_state(yylstr);
    696406                                wbufidx = 0;
    697407                                if(!win32)
    698408                                        yywarning("16bit resource contains unicode strings\n");
    699409                        }
     410<yylstr>\"{ws}+ |
    700411<yylstr>\"              {
    701                                 pop_start();
     412                                yy_pop_state();
    702413                                yylval.str = get_buffered_wstring();
    703414                                return tSTRING;
    704415                        }
    705 <yylstr>\n              yyerror("Unterminated string");
    706416<yylstr>\\[0-7]{1,6}    { /* octal escape sequence */
    707417                                int result;
     
    716426                                addwchar((short)result);
    717427                        }
     428<yylstr>\\x[0-9a-fA-F]{1,3} {  yyerror("Invalid hex escape sequence '%s'", yytext); }
     429
    718430<yylstr>\\[0-9]+        yyerror("Bad escape secuence");
    719431<yylstr>\\a             addwchar('\a');
     
    724436<yylstr>\\t             addwchar('\t');
    725437<yylstr>\\v             addwchar('\v');
    726 <yylstr>\\(.|\n)        addwchar(yytext[1]);
     438<yylstr>\\(\n|.)        addwchar(yytext[1]);
     439<yylstr>\\\r\n          addwchar(yytext[2]);
    727440<yylstr>\"\"            addcchar('\"');         /* "bla""bla"  -> "bla\"bla" */
    728441<yylstr>\\\"\"          addcchar('\"');         /* "bla\""bla" -> "bla\"bla" */
     
    733446                                        addwchar(*yptr++ & 0xff);
    734447                        }
    735 
    736 \"                      {
    737                                 push_to(yystr);
    738                                 cbufidx = 0;
    739                         }
     448<yylstr>\n              yyerror("Unterminated string");
     449
     450        /*
     451         * Normal string scanning
     452         */
     453\"                      yy_push_state(yystr); cbufidx = 0;
     454<yystr>\"{ws}+  |
    740455<yystr>\"               {
    741                                 pop_start();
     456                                yy_pop_state();
    742457                                yylval.str = get_buffered_cstring();
    743458                                return tSTRING;
    744459                        }
    745 <yystr>\n               yyerror("Unterminated string");
    746460<yystr>\\[0-7]{1,3}     { /* octal escape sequence */
    747461                                int result;
     
    756470                                addcchar((char)result);
    757471                        }
     472<yystr>\\x[0-9a-fA-F]   {  yyerror("Invalid hex escape sequence '%s'", yytext); }
     473
    758474<yystr>\\[0-9]+         yyerror("Bad escape secuence");
    759475<yystr>\\a              addcchar('\a');
     
    764480<yystr>\\t              addcchar('\t');
    765481<yystr>\\v              addcchar('\v');
    766 <yystr>\\(.|\n)         addcchar(yytext[1]);
     482<yystr>\\(\n|.)         addcchar(yytext[1]);
     483<yystr>\\\r\n           addcchar(yytext[2]);
    767484<yystr>[^\\\n\"]+       {
    768485                                char *yptr = yytext;
     
    773490<yystr>\\\"\"           addcchar('\"');         /* "bla\""bla"  -> "bla\"bla" */
    774491<yystr>\"{ws}+\"        ;                       /* "bla" "bla"  -> "blabla" */
    775 <yystr>.                yywarning("Matched %c", *yytext);
    776 
    777 
    778 \'                      {
    779                                 push_to(yyrcd);
    780                                 cbufidx = 0;
    781                         }
     492<yystr>\n               yyerror("Unterminated string");
     493
     494        /*
     495         * Raw data scanning
     496         */
     497\'                      yy_push_state(yyrcd); cbufidx = 0;
    782498<yyrcd>\'               {
    783                                 pop_start();
     499                                yy_pop_state();
    784500                                yylval.raw = new_raw_data();
    785501                                yylval.raw->size = cbufidx;
    786502                                yylval.raw->data = xmalloc(yylval.raw->size);
    787503                                memcpy(yylval.raw->data, cbuffer, yylval.raw->size);
    788                                 return RAWDATA;
     504                                return tRAWDATA;
    789505                        }
    790506<yyrcd>[0-9a-fA-F]{2}   {
     
    797513<yyrcd>.                yyerror("Malformed data-line");
    798514
    799 <INITIAL,pp_ignore,pp_def_s,pp_strips,pp_stripe,pp_stripp>"/*"  push_to(comment);       /* Eat comment */
     515        /*
     516         * Comment stripping
     517         * Should never occur after preprocessing
     518         */
     519<INITIAL,pp_stripp,pp_strips>"/*"       {
     520                                yy_push_state(comment);
     521                                save_wanted_id = wanted_id;
     522                                if(!no_preprocess)
     523                                        yywarning("Found comments after preprocessing, please report");
     524                        }
    800525<comment>[^*\n]*        ;
    801526<comment>"*"+[^*/\n]*   ;
    802527<comment>\n             line_number++; char_number = 1;
    803 <comment>"*"+"/"        pop_start();
    804 
    805 ;[^\n]*                 ; /* Eat comment */
    806 <INITIAL,pp_ignore,pp_def_s>"//"[^\n]*          ; /* Eat comment */
    807 
    808 <INITIAL,yywf,pp_false,pp_strips,pp_stripe,pp_stripp>\n {
    809                                 if(YY_START == yywf)
    810                                         pop_start();
     528<comment>"*"+"/"        yy_pop_state(); want_id = save_wanted_id;
     529
     530;[^\n]*                 want_id = wanted_id; /* not really comment, but left-over c-junk */
     531"//"[^\n]*              want_id = wanted_id; if(!no_preprocess) yywarning("Found comments after preprocessing, please report");
     532
     533\n                      {
     534                                want_id = wanted_id;
    811535                                line_number++;
    812536                                char_number = 1;
     
    817541                                }
    818542                        }
    819 <INITIAL,yywf>{ws}+     ;       /* Eat whitespace */
     543{ws}+                   want_id = wanted_id;    /* Eat whitespace */
    820544
    821545<INITIAL>.              return yytext[0];
     546
    822547<<EOF>>                 {
    823                                 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
    824                                 if(!pop_buffer())
    825                                 {
    826                                         if(YY_START == pp_strips || YY_START == pp_stripe || YY_START == pp_stripp || YY_START == pp_stripp_final)
    827                                                 yyerror("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
    828                                         else
    829                                                 yyterminate();
    830                                 }
    831                                 yy_delete_buffer(b);
     548                                if(YY_START == pp_strips || YY_START == pp_stripe || YY_START == pp_stripp || YY_START == pp_stripp_final)
     549                                        yyerror("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
     550                                else
     551                                        yyterminate();
    832552                        }
    833553
     
    840560                                }
    841561                                yywarning("Unmatched text '%c' (0x%02x) YY_START=%d stripslevel=%d",
    842                                         isprint(*yytext) ? *yytext : '.', *yytext, YY_START,stripslevel);
     562                                        isprint(*yytext & 0xff) ? *yytext : '.', *yytext, YY_START,stripslevel);
    843563                        }
    844564
     
    861581 * the resource string.
    862582 */
    863 void addcchar(char c)
     583static void addcchar(char c)
    864584{
    865585        if(cbufidx >= cbufalloc)
     
    873593}
    874594
    875 void addwchar(short s)
     595static void addwchar(short s)
    876596{
    877597        if(wbufidx >= wbufalloc)
     
    894614}
    895615
    896 string_t *get_buffered_cstring(void)
     616static string_t *get_buffered_cstring(void)
    897617{
    898618        string_t *str = new_string();
     
    902622        memcpy(str->str.cstr, cbuffer, cbufidx);
    903623        str->str.cstr[cbufidx] = '\0';
    904 /*      printf("got cstring \"%s\"\n", str->str.cstr); */
    905624        return str;
    906625}
    907626
    908 string_t *get_buffered_wstring(void)
     627static string_t *get_buffered_wstring(void)
    909628{
    910629        string_t *str = new_string();
     
    917636}
    918637
    919 string_t *make_string(char *s)
     638static string_t *make_string(char *s)
    920639{
    921640        string_t *str = new_string();
     
    927646}
    928647
    929 string_t *make_filename(char *s, int len)
    930 {
    931         char *cptr;
    932         string_t *str = new_string();
    933 
    934         str->size = len;
    935         str->type = str_char;
    936         str->str.cstr = (char *)xmalloc(str->size+1);
    937         memcpy(str->str.cstr, s, str->size);
    938         str->str.cstr[str->size] = '\0';
    939 
    940         /* Remove escaped backslash and convert to forward */
    941         cptr = str->str.cstr;
    942         for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
    943         {
    944                 if(cptr[1] == '\\')
    945                 {
    946                         memmove(cptr, cptr+1, strlen(cptr));
    947                         str->size--;
    948                 }
    949                 *cptr = '/';
    950         }
    951 
    952         /* Convert to lower case. Seems to be reasonable to do */
    953         for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
    954         {
    955                 *cptr = tolower(*cptr);
    956         }
    957         return str;
    958 }
    959 
    960 /* Called from the parser to signal filename request */
    961 void set_yywf(void)
    962 {
    963         push_to(yywf);
    964 }
    965 
    966 /* Called from the parser to signal preprocessor if case */
    967 void set_pp_ignore(int state)
    968 {
    969         if(state)
    970                 push_to(pp_false);
    971         else
    972                 pop_start();
    973 }
    974 
    975648/* Called from the parser to kill c-junk */
    976649void strip_extern(void)
    977650{
    978651        cjunk_tagline = line_number;
    979         push_to(pp_stripe);
     652        yy_push_state(pp_stripe);
    980653}
    981654
     
    983656{
    984657        cjunk_tagline = line_number;
    985         push_to(pp_strips);
     658        yy_push_state(pp_strips);
    986659}
    987660
     
    990663        cjunk_tagline = line_number;
    991664        stripplevel = 1;        /* One scanned already */
    992         push_to(pp_stripp);
    993 }
    994 
     665        yy_push_state(pp_stripp);
     666}
     667
  • trunk/tools/wrc/parser.y

    r3426 r5522  
    11%{
    22/*
    3  * Copyright  Martin von Loewis, 1994
    4  * Copyright 1998 Bertho A. Stultiens (BS)
    5  *           1999 Juergen Schmied (JS)
     3 * Copyright 1994       Martin von Loewis
     4 * Copyright 1998-2000  Bertho A. Stultiens (BS)
     5 *           1999       Juergen Schmied (JS)
    66 *
    7  * 6-Nov-1999 JS        - see CHANGES
     7 * 24-Jul-2000 BS       - Made a fix for broken Berkeley yacc on
     8 *                        non-terminals (see cjunk rule).
     9 * 21-May-2000 BS       - Partial implementation of font resources.
     10 *                      - Corrected language propagation for binary
     11 *                        resources such as bitmaps, isons, cursors,
     12 *                        userres and rcdata. The language is now
     13 *                        correct in .res files.
     14 *                      - Fixed reading the resource name as ident,
     15 *                        so that it may overlap keywords.
     16 * 20-May-2000 BS       - Implemented animated cursors and icons
     17 *                        resource types.
     18 * 30-Apr-2000 BS       - Reintegration into the wine-tree
     19 * 14-Jan-2000 BS       - Redid the usertype resources so that they
     20 *                        are compatible.
     21 * 02-Jan-2000 BS       - Removed the preprocessor from the grammar
     22 *                        expect for the # command (line numbers).
     23 *
     24 * 06-Nov-1999 JS       - see CHANGES
    825 *
    926 * 29-Dec-1998 AdH      - Grammar and function extensions.
     
    108125#include "parser.h"
    109126#include "windef.h"
     127#include "winbase.h"
    110128#include "wingdi.h"
    111129#include "winuser.h"
    112130
    113 #ifdef __BORLANDC__
    114 #pragma warn -sig
     131#if defined(YYBYACC)
     132        /* Berkeley yacc (byacc) doesn't seem to know about these */
     133        /* Some *BSD supplied versions do define these though */
     134# ifndef YYEMPTY
     135#  define YYEMPTY       (-1)    /* Empty lookahead value of yychar */
     136# endif
     137# ifndef YYLEX
     138#  define YYLEX         yylex()
     139# endif
     140
     141#elif defined(YYBISON)
     142        /* Bison was used for original development */
     143        /* #define YYEMPTY -2 */
     144        /* #define YYLEX   yylex() */
     145
     146#else   
     147        /* No yacc we know yet */
     148# if !defined(YYEMPTY) || !defined(YYLEX)
     149#  error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
     150# elif defined(__GNUC__)        /* gcc defines the #warning directive */
     151#  warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
     152  /* #else we just take a chance that it works... */
     153# endif
    115154#endif
    116155
    117 int indialog = 0;       /* Signal flex that we're parsing a dialog */
    118 int want_rscname = 0;   /* Set when a resource's name is required */
     156int want_nl = 0;        /* Signal flex that we need the next newline */
     157int want_id = 0;        /* Signal flex that we need the next identifier */
    119158stringtable_t *tagstt;  /* Stringtable tag.
    120159                         * It is set while parsing a stringtable to one of
     
    125164                         * stringtables with different lanuages
    126165                         */
     166static int dont_want_id = 0;    /* See language parsing for details */
     167
    127168/* Set to the current options of the currently scanning stringtable */
    128169static int *tagstt_memopt;
     
    130171static version_t *tagstt_version;
    131172
     173static const char riff[4] = "RIFF";     /* RIFF file magic for animated cursor/icon */
     174
    132175/* Prototypes of here defined functions */
    133 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur);
    134 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico);
    135 int alloc_cursor_id(language_t *);
    136 int alloc_icon_id(language_t *);
    137 void ins_stt_entry(stt_entry_t *ste);
    138 int check_stt_entry(stringtable_t *tabs, stt_entry_t *ste);
    139 event_t *get_event_head(event_t *p);
    140 control_t *get_control_head(control_t *p);
    141 ver_value_t *get_ver_value_head(ver_value_t *p);
    142 ver_block_t *get_ver_block_head(ver_block_t *p);
    143 resource_t *get_resource_head(resource_t *p);
    144 menuex_item_t *get_itemex_head(menuex_item_t *p);
    145 menu_item_t *get_item_head(menu_item_t *p);
    146 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
    147 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
    148 raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
    149 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
    150 raw_data_t *str2raw_data(string_t *str);
    151 raw_data_t *int2raw_data(int i);
    152 raw_data_t *long2raw_data(int i);
    153 raw_data_t *load_file(string_t *name);
    154 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
    155 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
    156 event_t *add_event(int key, int id, int flags, event_t *prev);
    157 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
    158 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
    159 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
    160 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
    161 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
    162 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
    163 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
    164 dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
    165 dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
    166 name_id_t *convert_ctlclass(name_id_t *cls);
    167 control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
    168 dialog_t *dialog_version(version_t *v, dialog_t *dlg);
    169 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
    170 dialog_t *dialog_language(language_t *l, dialog_t *dlg);
    171 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
    172 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
    173 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
    174 dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
    175 dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
    176 dialog_t *dialog_style(style_t * st, dialog_t *dlg);
    177 resource_t *build_stt_resources(stringtable_t *stthead);
    178 stringtable_t *find_stringtable(lvc_t *lvc);
    179 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
    180 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
     176static event_t *get_event_head(event_t *p);
     177static control_t *get_control_head(control_t *p);
     178static ver_value_t *get_ver_value_head(ver_value_t *p);
     179static ver_block_t *get_ver_block_head(ver_block_t *p);
     180static resource_t *get_resource_head(resource_t *p);
     181static menuex_item_t *get_itemex_head(menuex_item_t *p);
     182static menu_item_t *get_item_head(menu_item_t *p);
     183static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
     184static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
     185static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
     186static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
     187static raw_data_t *str2raw_data(string_t *str);
     188static raw_data_t *int2raw_data(int i);
     189static raw_data_t *long2raw_data(int i);
     190static raw_data_t *load_file(string_t *name);
     191static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
     192static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
     193static event_t *add_event(int key, int id, int flags, event_t *prev);
     194static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
     195static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
     196static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
     197static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
     198static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
     199static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
     200static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
     201static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
     202static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
     203static name_id_t *convert_ctlclass(name_id_t *cls);
     204static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
     205static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
     206static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
     207static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
     208static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
     209static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
     210static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
     211static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
     212static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
     213static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
     214static resource_t *build_stt_resources(stringtable_t *stthead);
     215static stringtable_t *find_stringtable(lvc_t *lvc);
     216static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
     217static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
     218static string_t *make_filename(string_t *s);
     219static resource_t *build_fontdirs(resource_t *tail);
     220static resource_t *build_fontdir(resource_t **fnt, int nfnt);
     221static int rsrcid_to_token(int lookahead);
    181222
    182223%}
     
    185226        int             num;
    186227        int             *iptr;
     228        char            *cptr;
    187229        resource_t      *res;
    188230        accelerator_t   *acc;
    189231        bitmap_t        *bmp;
    190         cursor_t        *cur;
    191         cursor_group_t  *curg;
    192232        dialog_t        *dlg;
    193233        dialogex_t      *dlgex;
    194234        font_t          *fnt;
    195         icon_t          *ico;
    196         icon_group_t    *icog;
     235        fontdir_t       *fnd;
    197236        menu_t          *men;
    198237        menuex_t        *menex;
     
    223262        style_pair_t    *styles;
    224263        style_t         *style;
    225 }
    226 
    227 %token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
    228 %token tTYPEDEF tEXTERN
    229 %token <num> NUMBER LNUMBER
    230 %token <str> tSTRING IDENT FILENAME
    231 %token <raw> RAWDATA
    232 %token ACCELERATORS tBITMAP CURSOR DIALOG DIALOGEX MENU MENUEX MESSAGETABLE
    233 %token RCDATA VERSIONINFO STRINGTABLE FONT ICON
    234 %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX DEFPUSHBUTTON
    235 %token PUSHBUTTON RADIOBUTTON STATE3 /* PUSHBOX */
    236 %token GROUPBOX COMBOBOX LISTBOX SCROLLBAR
    237 %token CONTROL EDITTEXT
    238 %token RTEXT CTEXT LTEXT
    239 %token BLOCK VALUE
    240 %token SHIFT ALT ASCII VIRTKEY GRAYED CHECKED INACTIVE NOINVERT
    241 %token tPURE IMPURE DISCARDABLE LOADONCALL PRELOAD tFIXED MOVEABLE
    242 %token CLASS CAPTION CHARACTERISTICS EXSTYLE STYLE VERSION LANGUAGE
    243 %token FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEOS FILETYPE FILEFLAGS FILESUBTYPE
    244 %token MENUBARBREAK MENUBREAK MENUITEM POPUP SEPARATOR
    245 %token HELP
    246 %token tSTRING IDENT RAWDATA
    247 %token TOOLBAR BUTTON
     264        ani_any_t       *ani;
     265}
     266
     267%token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
     268%token <num> tNUMBER tLNUMBER
     269%token <str> tSTRING tIDENT tFILENAME
     270%token <raw> tRAWDATA
     271%token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
     272%token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
     273%token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
     274%token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
     275%token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
     276%token tCONTROL tEDITTEXT
     277%token tRTEXT tCTEXT tLTEXT
     278%token tBLOCK tVALUE
     279%token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
     280%token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
     281%token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
     282%token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
     283%token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
     284%token tHELP
     285%token tSTRING tIDENT tRAWDATA
     286%token tTOOLBAR tBUTTON
    248287%token tBEGIN tEND
    249 %token DLGINIT
    250 %left LOGOR
    251 %left LOGAND
     288%token tDLGINIT
    252289%left '|'
    253290%left '^'
    254291%left '&'
    255 %left EQ NE
    256 %left '<' LTE '>' GTE
    257292%left '+' '-'
    258293%left '*' '/'
    259 %right '~' '!' NOT
     294%right '~' tNOT
     295%left pUPM
    260296
    261297%type <res>     resource_file resource resources resource_definition
    262298%type <stt>     stringtable strings
    263299%type <fnt>     font
    264 %type <icog>    icon
     300%type <fnd>     fontdir
    265301%type <acc>     accelerators
    266302%type <event>   events
    267303%type <bmp>     bitmap
    268 %type <curg>    cursor
     304%type <ani>     cursor icon
    269305%type <dlg>     dialog dlg_attributes
    270306%type <ctl>     ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
     
    273309%type <ctl>     exctrls gen_exctrl lab_exctrl exctrl_desc
    274310%type <rdt>     rcdata
    275 %type <raw>     raw_data raw_elements opt_data
     311%type <raw>     raw_data raw_elements opt_data file_raw
    276312%type <veri>    versioninfo fix_version
    277313%type <verw>    ver_words
     
    287323%type <num>     item_options
    288324%type <nid>     nameid nameid_s ctlclass usertype
    289 %type <num>     acc_opt
     325%type <num>     acc_opt acc accs
    290326%type <iptr>    loadmemopts lamo lama
    291327%type <fntid>   opt_font opt_exfont opt_expr
     
    296332%type <num>     expr xpr
    297333%type <iptr>    e_expr
    298 %type <iptr>    pp_expr pp_constant
    299334%type <tlbar>   toolbar
    300335%type <tlbarItems>      toolbar_items
     
    304339%type <style>   optional_style
    305340%type <style>   style
     341%type <str>     filename
    306342
    307343%%
     
    321357                else
    322358                        $1 = rsc;
     359                /* Find the tail again */
     360                while($1 && $1->next)
     361                        $1 = $1->next;
     362                /* Now add any fontdirecory */
     363                rsc = build_fontdirs($1);
     364                /* 'build_fontdir' returns a head and $1 is a tail */
     365                if($1)
     366                {
     367                        $1->next = rsc;
     368                        if(rsc)
     369                                rsc->prev = $1;
     370                }
     371                else
     372                        $1 = rsc;
    323373                /* Final statement before were done */
    324374                resource_top = get_resource_head($1);
     
    328378/* Resources are put into a linked list */
    329379resources
    330         : /* Empty */           { $$ = NULL; want_rscname = 1; }
     380        : /* Empty */           { $$ = NULL; want_id = 1; }
    331381        | resources resource    {
    332382                if($2)
     
    342392                                $1->next = head;
    343393                        $$ = tail;
     394                        /* Check for duplicate identifiers */
     395                        while($1 && head)
     396                        {
     397                                resource_t *rsc = $1;
     398                                while(rsc)
     399                                {
     400                                        if(rsc->type == head->type
     401                                        && rsc->lan->id == head->lan->id
     402                                        && rsc->lan->sub == head->lan->sub
     403                                        && !compare_name_id(rsc->name, head->name))
     404                                        {
     405                                                yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
     406                                        }
     407                                        rsc = rsc->prev;
     408                                }
     409                                head = head->next;
     410                        }
    344411                }
    345412                else if($1)
     
    352419                else
    353420                        $$ = NULL;
    354                 want_rscname = 1;
    355                 }
    356         | resources preprocessor                { $$ = $1; want_rscname = 1; }
    357         | resources cjunk                       { $$ = $1; want_rscname = 1; }
    358         ;
    359 
    360 /* The buildin preprocessor */
    361 preprocessor
    362         : tIF pp_expr tNL       { pop_start(); push_if($2 ? *($2) : 0, 0, 0); if($2) free($2);}
    363         | tIFDEF IDENT tNL      { pop_start(); push_if(pp_lookup($2->str.cstr) != NULL, 0, 0); }
    364         | tIFNDEF IDENT tNL     { pop_start(); push_if(pp_lookup($2->str.cstr) == NULL, 0, 0); }
    365         | tELIF pp_expr tNL     { pop_start(); push_if($2 ? *($2) : 0, pop_if(), 0); if($2) free($2); }
    366         | tELSE tNL             { pop_start(); push_if(1, pop_if(), 0); }
    367         | tENDIF tNL            { pop_if(); }
    368         ;
    369 
    370 pp_expr : pp_constant                   { $$ = $1; }
    371         | pp_expr LOGOR pp_expr         { $$ = new_int($1 && $3 ? (*$1 || *$3) : 0); if($1) free($1); if($3) free($3); }
    372         | pp_expr LOGAND pp_expr        { $$ = new_int($1 && $3 ? (*$1 && *$3) : 0); if($1) free($1); if($3) free($3); }
    373         | pp_expr '+' pp_expr           { $$ = new_int($1 && $3 ? (*$1  + *$3) : 0); if($1) free($1); if($3) free($3); }
    374         | pp_expr '-' pp_expr           { $$ = new_int($1 && $3 ? (*$1  - *$3) : 0); if($1) free($1); if($3) free($3); }
    375         | pp_expr '^' pp_expr           { $$ = new_int($1 && $3 ? (*$1  ^ *$3) : 0); if($1) free($1); if($3) free($3); }
    376         | pp_expr EQ pp_expr            { $$ = new_int($1 && $3 ? (*$1 == *$3) : 0); if($1) free($1); if($3) free($3); }
    377         | pp_expr NE pp_expr            { $$ = new_int($1 && $3 ? (*$1 != *$3) : 0); if($1) free($1); if($3) free($3); }
    378         | pp_expr '<' pp_expr           { $$ = new_int($1 && $3 ? (*$1  < *$3) : 0); if($1) free($1); if($3) free($3); }
    379         | pp_expr '>' pp_expr           { $$ = new_int($1 && $3 ? (*$1  > *$3) : 0); if($1) free($1); if($3) free($3); }
    380         | pp_expr LTE pp_expr           { $$ = new_int($1 && $3 ? (*$1 <= *$3) : 0); if($1) free($1); if($3) free($3); }
    381         | pp_expr GTE pp_expr           { $$ = new_int($1 && $3 ? (*$1 >= *$3) : 0); if($1) free($1); if($3) free($3); }
    382         | '~' pp_expr                   { $$ = $2; if($2) *$2 = ~(*$2); }
    383         | '+' pp_expr                   { $$ = $2; }
    384         | '-' pp_expr                   { $$ = $2; if($2) *$2 = -(*$2); }
    385         | '!' pp_expr                   { $$ = $2; if($2) *$2 = !(*$2); }
    386         | '(' pp_expr ')'               { $$ = $2; }
    387         ;
    388 
    389 pp_constant
    390         : any_num                       { $$ = new_int($1); }
    391         | IDENT                         { $$ = NULL; }
    392         | tDEFINED IDENT                { $$ = new_int(pp_lookup($2->str.cstr) != NULL); }
    393         | tDEFINED '(' IDENT ')'        { $$ = new_int(pp_lookup($3->str.cstr) != NULL); }
    394         ;
     421
     422                if(!dont_want_id)       /* See comments in language parsing below */
     423                        want_id = 1;
     424                dont_want_id = 0;
     425                }
     426        | resources cjunk                       { $$ = $1; want_id = 1; }
     427        ;
     428
    395429
    396430/* C ignore stuff */
    397431cjunk   : tTYPEDEF                      { strip_til_semicolon(); }
    398         | tEXTERN                       { strip_extern(); }
    399         | IDENT IDENT                   { strip_til_semicolon(); }
    400         | IDENT '('                     { strip_til_parenthesis(); }
    401         | IDENT '*'                     { strip_til_semicolon(); }
     432        | tSTRUCT                       { strip_til_semicolon(); }
     433        | tEXTERN                       { strip_til_semicolon(); }
     434        | tENUM                         { strip_til_semicolon(); }
     435        | tCPPCLASS                     { strip_til_semicolon(); }
     436        | tSTATIC                       { strip_til_semicolon(); }
     437        | tINLINE                       { internal_error(__FILE__, __LINE__, "Don't yet know how to strip inline functions\n"); }
     438/*      | tIDENT tIDENT                 { strip_til_semicolon(); } */
     439/*      | tIDENT tIDENT '('             { strip_til_parenthesis(); } See comments in 'resource' below */
     440/*      | tIDENT '('                    { strip_til_parenthesis(); } */
     441        | tIDENT '*'                    { strip_til_semicolon(); }
     442        | tNL   /*
     443                 * This newline rule will never get reduced because we never
     444                 * get the tNL token, unless we explicitely set the 'want_nl'
     445                 * flag, which we don't.
     446                 * The *ONLY* reason for this to be here is because Berkeley
     447                 * yacc (byacc), at least version 1.9, has a bug.
     448                 * (identified in the generated parser on the second
     449                 *  line with:
     450                 *  static char yysccsid[] = "@(#)yaccpar   1.9 (Berkeley) 02/21/93";
     451                 * )
     452                 * This extra rule fixes it.
     453                 * The problem is that the expression handling rule "expr: xpr"
     454                 * is not reduced on non-terminal tokens, defined above in the
     455                 * %token declarations. Token tNL is the only non-terminal that
     456                 * can occur. The error becomes visible in the language parsing
     457                 * rule below, which looks at the look-ahead token and tests it
     458                 * for tNL. However, byacc already generates an error upon reading
     459                 * the token instead of keeping it as a lookahead. The reason
     460                 * lies in the lack of a $default transition in the "expr : xpr . "
     461                 * state (currently state 25). It is probably ommitted because tNL
     462                 * is a non-terminal and the state contains 2 s/r conflicts. The
     463                 * state enumerates all possible transitions instead of using a
     464                 * $default transition.
     465                 * All in all, it is a bug in byacc. (period)
     466                 */
    402467        ;
    403468
    404469/* Parse top level resource definitions etc. */
    405470resource
    406         : nameid resource_definition {
    407                 $$ = $2;
     471        : expr usrcvt resource_definition {
     472                $$ = $3;
    408473                if($$)
    409474                {
    410                         $$->name = $1;
    411                         if($1->type == name_ord)
    412                         {
    413                                 chat("Got %s (%d)",get_typename($2),$1->name.i_name);
     475                        if($1 > 65535 || $1 < -32768)
     476                                yyerror("Resource's ID out of range (%d)", $1);
     477                        $$->name = new_name_id();
     478                        $$->name->type = name_ord;
     479                        $$->name->name.i_name = $1;
     480                        chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
    414481                        }
    415                         else if($1->type == name_str)
    416                         {
    417                                 chat("Got %s (%s)",get_typename($2),$1->name.s_name->str.cstr);
    418482                        }
    419                 }
    420                 }
     483        | tIDENT usrcvt resource_definition {
     484                $$ = $3;
     485                if($$)
     486                {
     487                        $$->name = new_name_id();
     488                        $$->name->type = name_str;
     489                        $$->name->name.s_name = $1;
     490                        chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
     491                }
     492                }
     493        | tIDENT usrcvt tIDENT '('      { /* cjunk */ strip_til_parenthesis(); $$ = NULL; }
     494                /* The above rule is inserted here with explicit tIDENT
     495                 * references to avoid a nasty LALR(2) problem when
     496                 * considering the 'cjunk' rules with respect to the usertype
     497                 * resources.
     498                 * A usertype resource can have two leading identifiers before
     499                 * it qualifies as shift into usertype rules. However, the
     500                 * cjunk scanner also has a rule of two leading identifiers.
     501                 * The problem occurs because the second identifier is at the
     502                 * second lookahead (hence LALR(2)) seen from the recursion
     503                 * rule 'resources'.
     504                 * Thus, the scanner will pick *one* of the rules in preference
     505                 * of the other (in this case it was 'cjunk') and generates a
     506                 * syntax error if the trailing context wasn't seen. The
     507                 * correct action would have been to rollback the stack and
     508                 * decent into the 'userres' rule, but this cannot be done
     509                 * because yacc only parses LALR(1).
     510                 * The problem is prevented from happening by making the decent
     511                 * into the cjunk-scanning obsolete and explicitly force the
     512                 * scanner to require no more than 1 lookahead.
     513                 */
    421514        | stringtable {
    422515                /* Don't do anything, stringtables are converted to
     
    427520                chat("Got STRINGTABLE");
    428521                }
    429         | opt_language {
     522        | tLANGUAGE {want_nl = 1; } expr ',' expr {
     523                /* We *NEED* the newline to delimit the expression.
     524                 * Otherwise, we would not be able to set the next
     525                 * want_id anymore because of the token-lookahead.
     526                 *
     527                 * However, we can test the lookahead-token for
     528                 * being "non-expression" type, in which case we
     529                 * continue. Fortunately, tNL is the only token that
     530                 * will break expression parsing and is implicitely
     531                 * void, so we just remove it. This scheme makes it
     532                 * possible to do some (not all) fancy preprocessor
     533                 * stuff.
     534                 * BTW, we also need to make sure that the next
     535                 * reduction of 'resources' above will *not* set
     536                 * want_id because we already have a lookahead that
     537                 * cannot be undone.
     538                 */
     539                if(yychar != YYEMPTY && yychar != tNL)
     540                        dont_want_id = 1;
     541
     542                if(yychar == tNL)
     543                        yychar = YYEMPTY;       /* Could use 'yyclearin', but we already need the*/
     544                                                /* direct access to yychar in rule 'usrcvt' below. */
     545                else if(yychar == tIDENT)
     546                        yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
     547
     548                want_nl = 0;    /* We don't want it anymore if we didn't get it */
     549
    430550                if(!win32)
    431551                        yywarning("LANGUAGE not supported in 16-bit mode");
    432552                if(currentlanguage)
    433553                        free(currentlanguage);
    434                 currentlanguage = $1;
     554                currentlanguage = new_language($3, $5);
    435555                $$ = NULL;
    436                 }
     556                chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
     557                }
     558        ;
     559
     560/*
     561 * Remapping of numerical resource types
     562 * (see also comment of called function below)
     563 */
     564usrcvt  : /* Empty */   { yychar = rsrcid_to_token(yychar); }
    437565        ;
    438566
     
    446574                $$->type = name_ord;
    447575                $$->name.i_name = $1;
    448                 want_rscname = 0;
    449                 }
    450         | IDENT {
     576                }
     577        | tIDENT {
    451578                $$ = new_name_id();
    452579                $$->type = name_str;
    453580                $$->name.s_name = $1;
    454                 want_rscname = 0;
    455581                }
    456582        ;
     
    464590                $$->type = name_str;
    465591                $$->name.s_name = $1;
    466                 want_rscname = 0;
    467592                }
    468593        ;
     
    471596resource_definition
    472597        : accelerators  { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
    473         | bitmap        { $$ = new_resource(res_bmp, $1, $1->memopt, dup_language(currentlanguage)); }
     598        | bitmap        { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
    474599        | cursor {
    475600                resource_t *rsc;
    476                 cursor_t *cur;
    477                 $$ = rsc = new_resource(res_curg, $1, $1->memopt, dup_language(currentlanguage));
    478                 for(cur = $1->cursorlist; cur; cur = cur->next)
    479                 {
    480                         rsc->prev = new_resource(res_cur, cur, $1->memopt, dup_language(currentlanguage));
    481                         rsc->prev->next = rsc;
    482                         rsc = rsc->prev;
    483                         rsc->name = new_name_id();
    484                         rsc->name->type = name_ord;
    485                         rsc->name->name.i_name = cur->id;
    486                 }
     601                if($1->type == res_anicur)
     602                {
     603                        $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
     604                }
     605                else if($1->type == res_curg)
     606                {
     607                        cursor_t *cur;
     608                        $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
     609                        for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
     610                        {
     611                                rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
     612                                rsc->prev->next = rsc;
     613                                rsc = rsc->prev;
     614                                rsc->name = new_name_id();
     615                                rsc->name->type = name_ord;
     616                                rsc->name->name.i_name = cur->id;
     617                        }
     618                }
     619                else
     620                        internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
     621                free($1);
    487622                }
    488623        | dialog        { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
     
    493628                        $$ = NULL;
    494629                }
    495         | dlginit       { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->lvc.language); }
    496         | font          { $$ = new_resource(res_fnt, $1, $1->memopt, dup_language(currentlanguage)); }
     630        | dlginit       { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
     631        | font          { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
     632        | fontdir       { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
    497633        | icon {
    498634                resource_t *rsc;
    499                 icon_t *ico;
    500                 $$ = rsc = new_resource(res_icog, $1, $1->memopt, dup_language(currentlanguage));
    501                 for(ico = $1->iconlist; ico; ico = ico->next)
    502                 {
    503                         rsc->prev = new_resource(res_ico, ico, $1->memopt, dup_language(currentlanguage));
    504                         rsc->prev->next = rsc;
    505                         rsc = rsc->prev;
    506                         rsc->name = new_name_id();
    507                         rsc->name->type = name_ord;
    508                         rsc->name->name.i_name = ico->id;
    509                 }
     635                if($1->type == res_aniico)
     636                {
     637                        $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
     638                }
     639                else if($1->type == res_icog)
     640                {
     641                        icon_t *ico;
     642                        $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
     643                        for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
     644                        {
     645                                rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
     646                                rsc->prev->next = rsc;
     647                                rsc = rsc->prev;
     648                                rsc->name = new_name_id();
     649                                rsc->name->type = name_ord;
     650                                rsc->name->name.i_name = ico->id;
     651                        }
     652                }
     653                else
     654                        internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
     655                free($1);
    510656                }
    511657        | menu          { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
     
    517663                }
    518664        | messagetable  { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
    519         | rcdata        { $$ = new_resource(res_rdt, $1, $1->memopt, $1->lvc.language); }
     665        | rcdata        { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
    520666        | toolbar       { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
    521         | userres       { $$ = new_resource(res_usr, $1, $1->memopt, dup_language(currentlanguage)); }
    522         | versioninfo   { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
     667        | userres       { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
     668        | versioninfo   { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
     669        ;
     670
     671
     672filename: tFILENAME     { $$ = make_filename($1); }
     673        | tIDENT        { $$ = make_filename($1); }
     674        | tSTRING       { $$ = make_filename($1); }
    523675        ;
    524676
    525677/* ------------------------------ Bitmap ------------------------------ */
    526 bitmap  : tBITMAP loadmemopts FILENAME  { $$ = new_bitmap(load_file($3), $2); }
    527         | tBITMAP loadmemopts raw_data  { $$ = new_bitmap($3, $2); }
     678bitmap  : tBITMAP loadmemopts file_raw  { $$ = new_bitmap($3, $2); }
    528679        ;
    529680
    530681/* ------------------------------ Cursor ------------------------------ */
    531 cursor  : CURSOR loadmemopts FILENAME   { $$ = new_cursor_group(load_file($3), $2); }
    532         | CURSOR loadmemopts raw_data   { $$ = new_cursor_group($3, $2); }
     682cursor  : tCURSOR loadmemopts file_raw  {
     683                $$ = new_ani_any();
     684                if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
     685                {
     686                        $$->type = res_anicur;
     687                        $$->u.ani = new_ani_curico(res_anicur, $3, $2);
     688                }
     689                else
     690                {
     691                        $$->type = res_curg;
     692                        $$->u.curg = new_cursor_group($3, $2);
     693                }
     694        }
     695        ;
     696
     697/* ------------------------------ Icon ------------------------------ */
     698icon    : tICON loadmemopts file_raw    {
     699                $$ = new_ani_any();
     700                if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
     701                {
     702                        $$->type = res_aniico;
     703                        $$->u.ani = new_ani_curico(res_aniico, $3, $2);
     704                }
     705                else
     706                {
     707                        $$->type = res_icog;
     708                        $$->u.icog = new_icon_group($3, $2);
     709                }
     710        }
    533711        ;
    534712
    535713/* ------------------------------ Font ------------------------------ */
    536 /* FIXME: Should we allow raw_data here? */
    537 font    : FONT loadmemopts FILENAME     { $$ = new_font(load_file($3), $2); }
    538         ;
    539 
    540 /* ------------------------------ Icon ------------------------------ */
    541 icon    : ICON loadmemopts FILENAME     { $$ = new_icon_group(load_file($3), $2); }
    542         | ICON loadmemopts raw_data     { $$ = new_icon_group($3, $2); }
     714        /*
     715         * The reading of raw_data for fonts is a Borland BRC
     716         * extension. MS generates an error. However, it is
     717         * most logical to support this, considering how wine
     718         * enters things in CVS (ascii).
     719         */
     720font    : tFONT loadmemopts file_raw    { $$ = new_font($3, $2); }
     721        ;
     722
     723        /*
     724         * The fontdir is a Borland BRC extension which only
     725         * reads the data as 'raw_data' from the file.
     726         * I don't know whether it is interpreted.
     727         * The fontdir is generated if it was not present and
     728         * fonts are defined in the source.
     729         */
     730fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
    543731        ;
    544732
     
    548736 */
    549737messagetable
    550         : MESSAGETABLE FILENAME {
     738        : tMESSAGETABLE loadmemopts file_raw    {
    551739                if(!win32)
    552740                        yywarning("MESSAGETABLE not supported in 16-bit mode");
    553                 $$ = new_messagetable(load_file($2));
     741                $$ = new_messagetable($3, $2);
    554742                }
    555743        ;
    556744
    557745/* ------------------------------ RCData ------------------------------ */
    558 rcdata  : RCDATA loadmemopts opt_lvc raw_data {
    559                 $$ = new_rcdata($4, $2);
    560                 if($3)
    561                 {
    562                         $$->lvc = *($3);
    563                         free($3);
    564                 }
    565                 if(!$$->lvc.language)
    566                         $$->lvc.language = dup_language(currentlanguage);
    567                 }
     746rcdata  : tRCDATA loadmemopts file_raw  { $$ = new_rcdata($3, $2); }
    568747        ;
    569748
    570749/* ------------------------------ DLGINIT ------------------------------ */
    571 dlginit : DLGINIT loadmemopts opt_lvc raw_data {
    572                 $$ = new_dlginit($4, $2);
    573                 if($3)
    574                 {
    575                         $$->lvc = *($3);
    576                         free($3);
    577                 }
    578                 if(!$$->lvc.language)
    579                         $$->lvc.language = dup_language(currentlanguage);
    580                 }
     750dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
    581751        ;         
    582752
    583753/* ------------------------------ UserType ------------------------------ */
    584 userres : usertype loadmemopts FILENAME { $$ = new_user($1, load_file($3), $2); }
    585         | usertype loadmemopts raw_data { $$ = new_user($1, $3, $2); }
    586         ;
    587 
    588 /* NOTE: This here is an exception where I do not allow an expression.
    589  * Reason for this is that it is not possible to set the 'yywf' condition
    590  * for flex if loadmemopts is empty. Reading an expression requires a
    591  * lookahead to determine its end. In this case here, that would mean that
    592  * the filename has been read as IDENT or tSTRING, which is incorrect.
    593  * Note also that IDENT cannot be used as a file-name because it is lacking
    594  * the '.'.
    595  */
    596 
    597 /* I also allow string identifiers as classtypes. Not MS implemented, but
    598  * seems to be reasonable to implement.
    599  */
    600 /* Allowing anything else than NUMBER makes it very hard to get rid of
    601  * prototypes. So, I remove IDENT to be able to get prototypes out of the
    602  * world.
    603  */
    604 usertype: NUMBER {
     754userres : usertype loadmemopts file_raw         {
     755                #ifdef WORDS_BIGENDIAN
     756                        if(pedantic && byteorder != WRC_BO_LITTLE)
     757                #else
     758                        if(pedantic && byteorder == WRC_BO_BIG)
     759                #endif
     760                                yywarning("Byteordering is not little-endian and type cannot be interpreted");
     761                        $$ = new_user($1, $3, $2);
     762                }
     763        ;
     764
     765usertype: tNUMBER {
    605766                $$ = new_name_id();
    606767                $$->type = name_ord;
    607768                $$->name.i_name = $1;
    608                 set_yywf();
    609                 }
    610 /*      | IDENT {
     769                }
     770        | tIDENT {
    611771                $$ = new_name_id();
    612772                $$->type = name_str;
    613773                $$->name.s_name = $1;
    614                 set_yywf();
    615                 }
    616 */      | tSTRING {
    617                 $$ = new_name_id();
    618                 $$->type = name_str;
    619                 $$->name.s_name = $1;
    620                 set_yywf();
    621774                }
    622775        ;
     
    624777/* ------------------------------ Accelerator ------------------------------ */
    625778accelerators
    626         : ACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
     779        : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
    627780                $$ = new_accelerator();
    628781                if($2)
     
    653806        ;
    654807
    655 acc_opt : /* Empty */           { $$=0; }
    656         | acc_opt ',' NOINVERT  { $$=$1 | WRC_AF_NOINVERT; }
    657         | acc_opt ',' SHIFT     { $$=$1 | WRC_AF_SHIFT; }
    658         | acc_opt ',' CONTROL   { $$=$1 | WRC_AF_CONTROL; }
    659         | acc_opt ',' ALT       { $$=$1 | WRC_AF_ALT; }
    660         | acc_opt ',' ASCII     { $$=$1 | WRC_AF_ASCII; }
    661         | acc_opt ',' VIRTKEY   { $$=$1 | WRC_AF_VIRTKEY; }
     808/*
     809 * The empty rule generates a s/r conflict because of {bi,u}nary expr
     810 * on - and +. It cannot be solved in any way because it is the same as
     811 * the if/then/else problem (LALR(1) problem). The conflict is moved
     812 * away by forcing it to be in the expression handling below.
     813 */
     814acc_opt : /* Empty */   { $$ = 0; }
     815        | ',' accs      { $$ = $2; }
     816        ;
     817
     818accs    : acc           { $$ = $1; }
     819        | accs ',' acc  { $$ = $1 | $3; }
     820        ;
     821
     822acc     : tNOINVERT     { $$ = WRC_AF_NOINVERT; }
     823        | tSHIFT        { $$ = WRC_AF_SHIFT; }
     824        | tCONTROL      { $$ = WRC_AF_CONTROL; }
     825        | tALT          { $$ = WRC_AF_ALT; }
     826        | tASCII        { $$ = WRC_AF_ASCII; }
     827        | tVIRTKEY      { $$ = WRC_AF_VIRTKEY; }
    662828        ;
    663829
    664830/* ------------------------------ Dialog ------------------------------ */
    665831/* FIXME: Support EXSTYLE in the dialog line itself */
    666 dialog  : DIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
     832dialog  : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
    667833          tBEGIN  ctrls tEND {
    668834                if($2)
     
    692858                $$->style->and_mask = 0;
    693859
    694                 indialog = FALSE;
    695860                if(!$$->lvc.language)
    696861                        $$->lvc.language = dup_language(currentlanguage);
     
    699864
    700865dlg_attributes
    701         : /* Empty */                   { $$=new_dialog(); }
    702         | dlg_attributes STYLE style    { $$=dialog_style($3,$1); }
    703         | dlg_attributes EXSTYLE style  { $$=dialog_exstyle($3,$1); }
    704         | dlg_attributes CAPTION tSTRING { $$=dialog_caption($3,$1); }
    705         | dlg_attributes opt_font       { $$=dialog_font($2,$1); }
    706         | dlg_attributes CLASS nameid_s { $$=dialog_class($3,$1); }
    707         | dlg_attributes MENU nameid    { $$=dialog_menu($3,$1); }
    708         | dlg_attributes opt_language   { $$=dialog_language($2,$1); }
    709         | dlg_attributes opt_characts   { $$=dialog_characteristics($2,$1); }
    710         | dlg_attributes opt_version    { $$=dialog_version($2,$1); }
     866        : /* Empty */                           { $$=new_dialog(); }
     867        | dlg_attributes tSTYLE style           { $$=dialog_style($3,$1); }
     868        | dlg_attributes tEXSTYLE style         { $$=dialog_exstyle($3,$1); }
     869        | dlg_attributes tCAPTION tSTRING       { $$=dialog_caption($3,$1); }
     870        | dlg_attributes opt_font               { $$=dialog_font($2,$1); }
     871        | dlg_attributes tCLASS nameid_s        { $$=dialog_class($3,$1); }
     872        | dlg_attributes tCPPCLASS nameid_s     { $$=dialog_class($3,$1); }
     873        | dlg_attributes tMENU nameid           { $$=dialog_menu($3,$1); }
     874        | dlg_attributes opt_language           { $$=dialog_language($2,$1); }
     875        | dlg_attributes opt_characts           { $$=dialog_characteristics($2,$1); }
     876        | dlg_attributes opt_version            { $$=dialog_version($2,$1); }
    711877        ;
    712878
    713879ctrls   : /* Empty */                           { $$ = NULL; }
    714         | ctrls CONTROL         gen_ctrl        { $$=ins_ctrl(-1, 0, $3, $1); }
    715         | ctrls EDITTEXT        ctrl_desc       { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
    716         | ctrls LISTBOX         ctrl_desc       { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
    717         | ctrls COMBOBOX        ctrl_desc       { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
    718         | ctrls SCROLLBAR       ctrl_desc       { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
    719         | ctrls CHECKBOX        lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
    720         | ctrls DEFPUSHBUTTON   lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
    721         | ctrls GROUPBOX        lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
    722         | ctrls PUSHBUTTON      lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
    723 /*      | ctrls PUSHBOX         lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
    724         | ctrls RADIOBUTTON     lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
    725         | ctrls AUTO3STATE      lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
    726         | ctrls STATE3          lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
    727         | ctrls AUTOCHECKBOX    lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
    728         | ctrls AUTORADIOBUTTON lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
    729         | ctrls LTEXT           lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
    730         | ctrls CTEXT           lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
    731         | ctrls RTEXT           lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
     880        | ctrls tCONTROL        gen_ctrl        { $$=ins_ctrl(-1, 0, $3, $1); }
     881        | ctrls tEDITTEXT       ctrl_desc       { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
     882        | ctrls tLISTBOX        ctrl_desc       { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
     883        | ctrls tCOMBOBOX       ctrl_desc       { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
     884        | ctrls tSCROLLBAR      ctrl_desc       { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
     885        | ctrls tCHECKBOX       lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
     886        | ctrls tDEFPUSHBUTTON  lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
     887        | ctrls tGROUPBOX       lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
     888        | ctrls tPUSHBUTTON     lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
     889/*      | ctrls tPUSHBOX        lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
     890        | ctrls tRADIOBUTTON    lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
     891        | ctrls tAUTO3STATE     lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
     892        | ctrls tSTATE3         lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
     893        | ctrls tAUTOCHECKBOX   lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
     894        | ctrls tAUTORADIOBUTTON lab_ctrl       { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
     895        | ctrls tLTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
     896        | ctrls tCTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
     897        | ctrls tRTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
    732898        /* special treatment for icons, as the extent is optional */
    733         | ctrls ICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
     899        | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
    734900                $10->title = $3;
    735901                $10->id = $5;
     
    830996
    831997opt_font
    832         : FONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
     998        : tFONT expr ',' tSTRING        { $$ = new_font_id($2, $4, 0, 0); }
    833999        ;
    8341000
     
    8491015        | '(' style ')'         { $$ = $2; }
    8501016        | any_num               { $$ = new_style($1, 0); }
    851         | NOT any_num           { $$ = new_style(0, $2); }
     1017        | tNOT any_num          { $$ = new_style(0, $2); }
    8521018        ;   
    8531019
     
    8661032
    8671033/* ------------------------------ DialogEx ------------------------------ */
    868 dialogex: DIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
     1034dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
    8691035          tBEGIN  exctrls tEND {
    8701036                if(!win32)
     
    9041070                $$->style->and_mask = 0;
    9051071
    906                 indialog = FALSE;
    9071072                if(!$$->lvc.language)
    9081073                        $$->lvc.language = dup_language(currentlanguage);
     
    9111076
    9121077dlgex_attribs
    913         : /* Empty */                   { $$=new_dialogex(); }
    914         | dlgex_attribs STYLE style     { $$=dialogex_style($3,$1); }
    915         | dlgex_attribs EXSTYLE style   { $$=dialogex_exstyle($3,$1); }
    916         | dlgex_attribs CAPTION tSTRING { $$=dialogex_caption($3,$1); }
    917         | dlgex_attribs opt_font        { $$=dialogex_font($2,$1); }
    918         | dlgex_attribs opt_exfont      { $$=dialogex_font($2,$1); }
    919         | dlgex_attribs CLASS nameid_s  { $$=dialogex_class($3,$1); }
    920         | dlgex_attribs MENU nameid     { $$=dialogex_menu($3,$1); }
    921         | dlgex_attribs opt_language    { $$=dialogex_language($2,$1); }
    922         | dlgex_attribs opt_characts    { $$=dialogex_characteristics($2,$1); }
    923         | dlgex_attribs opt_version     { $$=dialogex_version($2,$1); }
     1078        : /* Empty */                           { $$=new_dialogex(); }
     1079        | dlgex_attribs tSTYLE style            { $$=dialogex_style($3,$1); }
     1080        | dlgex_attribs tEXSTYLE style          { $$=dialogex_exstyle($3,$1); }
     1081        | dlgex_attribs tCAPTION tSTRING        { $$=dialogex_caption($3,$1); }
     1082        | dlgex_attribs opt_font                { $$=dialogex_font($2,$1); }
     1083        | dlgex_attribs opt_exfont              { $$=dialogex_font($2,$1); }
     1084        | dlgex_attribs tCLASS nameid_s         { $$=dialogex_class($3,$1); }
     1085        | dlgex_attribs tCPPCLASS nameid_s      { $$=dialogex_class($3,$1); }
     1086        | dlgex_attribs tMENU nameid            { $$=dialogex_menu($3,$1); }
     1087        | dlgex_attribs opt_language            { $$=dialogex_language($2,$1); }
     1088        | dlgex_attribs opt_characts            { $$=dialogex_characteristics($2,$1); }
     1089        | dlgex_attribs opt_version             { $$=dialogex_version($2,$1); }
    9241090        ;
    9251091
    9261092exctrls : /* Empty */                           { $$ = NULL; }
    927         | exctrls CONTROL       gen_exctrl      { $$=ins_ctrl(-1, 0, $3, $1); }
    928         | exctrls EDITTEXT      exctrl_desc     { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
    929         | exctrls LISTBOX       exctrl_desc     { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
    930         | exctrls COMBOBOX      exctrl_desc     { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
    931         | exctrls SCROLLBAR     exctrl_desc     { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
    932         | exctrls CHECKBOX      lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
    933         | exctrls DEFPUSHBUTTON lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
    934         | exctrls GROUPBOX      lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
    935         | exctrls PUSHBUTTON    lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
    936 /*      | exctrls PUSHBOX       lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
    937         | exctrls RADIOBUTTON   lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
    938         | exctrls AUTO3STATE    lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
    939         | exctrls STATE3        lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
    940         | exctrls AUTOCHECKBOX  lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
    941         | exctrls AUTORADIOBUTTON lab_exctrl    { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
    942         | exctrls LTEXT         lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
    943         | exctrls CTEXT         lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
    944         | exctrls RTEXT         lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
     1093        | exctrls tCONTROL      gen_exctrl      { $$=ins_ctrl(-1, 0, $3, $1); }
     1094        | exctrls tEDITTEXT     exctrl_desc     { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
     1095        | exctrls tLISTBOX      exctrl_desc     { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
     1096        | exctrls tCOMBOBOX     exctrl_desc     { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
     1097        | exctrls tSCROLLBAR    exctrl_desc     { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
     1098        | exctrls tCHECKBOX     lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
     1099        | exctrls tDEFPUSHBUTTON lab_exctrl     { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
     1100        | exctrls tGROUPBOX     lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
     1101        | exctrls tPUSHBUTTON   lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
     1102/*      | exctrls tPUSHBOX      lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
     1103        | exctrls tRADIOBUTTON  lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
     1104        | exctrls tAUTO3STATE   lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
     1105        | exctrls tSTATE3       lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
     1106        | exctrls tAUTOCHECKBOX lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
     1107        | exctrls tAUTORADIOBUTTON lab_exctrl   { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
     1108        | exctrls tLTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
     1109        | exctrls tCTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
     1110        | exctrls tRTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
    9451111        /* special treatment for icons, as the extent is optional */
    946         | exctrls ICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
     1112        | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
    9471113                $10->title = $3;
    9481114                $10->id = $5;
     
    10551221
    10561222opt_exfont
    1057         : FONT expr ',' tSTRING ',' expr ',' expr  opt_expr { $$ = new_font_id($2, $4, $6, $8); }
     1223        : tFONT expr ',' tSTRING ',' expr ',' expr  opt_expr { $$ = new_font_id($2, $4, $6, $8); }
    10581224        ;
    10591225
     
    10671233
    10681234/* ------------------------------ Menu ------------------------------ */
    1069 menu    : MENU loadmemopts opt_lvc menu_body {
     1235menu    : tMENU loadmemopts opt_lvc menu_body {
    10701236                if(!$4)
    10711237                        yyerror("Menu must contain items");
     
    10951261item_definitions
    10961262        : /* Empty */   {$$ = NULL;}
    1097         | item_definitions MENUITEM tSTRING opt_comma expr item_options {
     1263        | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
    10981264                $$=new_menu_item();
    10991265                $$->prev = $1;
     
    11041270                $$->name = $3;
    11051271                }
    1106         | item_definitions MENUITEM SEPARATOR {
     1272        | item_definitions tMENUITEM tSEPARATOR {
    11071273                $$=new_menu_item();
    11081274                $$->prev = $1;
     
    11101276                        $1->next = $$;
    11111277                }
    1112         | item_definitions POPUP tSTRING item_options menu_body {
     1278        | item_definitions tPOPUP tSTRING item_options menu_body {
    11131279                $$ = new_menu_item();
    11141280                $$->prev = $1;
     
    11291295 */
    11301296item_options
    1131         : /* Empty */                   { $$ = 0; }
    1132         | ',' CHECKED   item_options    { $$ = $3 | MF_CHECKED; }
    1133         | ',' GRAYED    item_options    { $$ = $3 | MF_GRAYED; }
    1134         | ',' HELP      item_options    { $$ = $3 | MF_HELP; }
    1135         | ',' INACTIVE  item_options    { $$ = $3 | MF_DISABLED; }
    1136         | ',' MENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
    1137         | ',' MENUBREAK item_options    { $$ = $3 | MF_MENUBREAK; }
     1297        : /* Empty */                           { $$ = 0; }
     1298        | ',' tCHECKED          item_options    { $$ = $3 | MF_CHECKED; }
     1299        | ',' tGRAYED           item_options    { $$ = $3 | MF_GRAYED; }
     1300        | ',' tHELP             item_options    { $$ = $3 | MF_HELP; }
     1301        | ',' tINACTIVE         item_options    { $$ = $3 | MF_DISABLED; }
     1302        | ',' tMENUBARBREAK     item_options    { $$ = $3 | MF_MENUBARBREAK; }
     1303        | ',' tMENUBREAK        item_options    { $$ = $3 | MF_MENUBREAK; }
    11381304        ;
    11391305
    11401306/* ------------------------------ MenuEx ------------------------------ */
    1141 menuex  : MENUEX loadmemopts opt_lvc menuex_body        {
     1307menuex  : tMENUEX loadmemopts opt_lvc menuex_body       {
    11421308                if(!win32)
    11431309                        yywarning("MENUEX not supported in 16-bit mode");
     
    11691335itemex_definitions
    11701336        : /* Empty */   {$$ = NULL; }
    1171         | itemex_definitions MENUITEM tSTRING itemex_options {
     1337        | itemex_definitions tMENUITEM tSTRING itemex_options {
    11721338                $$ = new_menuex_item();
    11731339                $$->prev = $1;
     
    11851351                free($4);
    11861352                }
    1187         | itemex_definitions MENUITEM SEPARATOR {
     1353        | itemex_definitions tMENUITEM tSEPARATOR {
    11881354                $$ = new_menuex_item();
    11891355                $$->prev = $1;
     
    11911357                        $1->next = $$;
    11921358                }
    1193         | itemex_definitions POPUP tSTRING itemex_p_options menuex_body {
     1359        | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
    11941360                $$ = new_menuex_item();
    11951361                $$->prev = $1;
     
    13151481
    13161482/* This is to get the language of the currently parsed stringtable */
    1317 stt_head: STRINGTABLE loadmemopts opt_lvc {
     1483stt_head: tSTRINGTABLE loadmemopts opt_lvc {
    13181484                if((tagstt = find_stringtable($3)) == NULL)
    13191485                        tagstt = new_stringtable($3);
     
    13501516                tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
    13511517
     1518                if(pedantic && !$4->size)
     1519                        yywarning("Zero length strings make no sense");
    13521520                if(!win32 && $4->size > 254)
    13531521                        yyerror("Stringtable entry more than 254 characters");
     
    13651533/* ------------------------------ VersionInfo ------------------------------ */
    13661534versioninfo
    1367         : VERSIONINFO fix_version tBEGIN ver_blocks tEND {
    1368                 $$ = $2;
    1369                 $2->blocks = get_ver_block_head($4);
     1535        : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
     1536                $$ = $3;
     1537                if($2)
     1538                {
     1539                        $$->memopt = *($2);
     1540                        free($2);
     1541                }
     1542                else
     1543                        $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
     1544                $$->blocks = get_ver_block_head($5);
     1545                /* Set language; there is no version or characteristics */
     1546                $$->lvc.language = dup_language(currentlanguage);
    13701547                }
    13711548        ;
     
    13731550fix_version
    13741551        : /* Empty */                   { $$ = new_versioninfo(); }
    1375         | fix_version FILEVERSION expr ',' expr ',' expr ',' expr {
     1552        | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
    13761553                if($1->gotit.fv)
    13771554                        yyerror("FILEVERSION already defined");
     
    13831560                $$->gotit.fv = 1;
    13841561                }
    1385         | fix_version PRODUCTVERSION expr ',' expr ',' expr ',' expr {
     1562        | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
    13861563                if($1->gotit.pv)
    13871564                        yyerror("PRODUCTVERSION already defined");
     
    13931570                $$->gotit.pv = 1;
    13941571                }
    1395         | fix_version FILEFLAGS expr {
     1572        | fix_version tFILEFLAGS expr {
    13961573                if($1->gotit.ff)
    13971574                        yyerror("FILEFLAGS already defined");
     
    14001577                $$->gotit.ff = 1;
    14011578                }
    1402         | fix_version FILEFLAGSMASK expr {
     1579        | fix_version tFILEFLAGSMASK expr {
    14031580                if($1->gotit.ffm)
    14041581                        yyerror("FILEFLAGSMASK already defined");
     
    14071584                $$->gotit.ffm = 1;
    14081585                }
    1409         | fix_version FILEOS expr {
     1586        | fix_version tFILEOS expr {
    14101587                if($1->gotit.fo)
    14111588                        yyerror("FILEOS already defined");
     
    14141591                $$->gotit.fo = 1;
    14151592                }
    1416         | fix_version FILETYPE expr {
     1593        | fix_version tFILETYPE expr {
    14171594                if($1->gotit.ft)
    14181595                        yyerror("FILETYPE already defined");
     
    14211598                $$->gotit.ft = 1;
    14221599                }
    1423         | fix_version FILESUBTYPE expr {
     1600        | fix_version tFILESUBTYPE expr {
    14241601                if($1->gotit.fst)
    14251602                        yyerror("FILESUBTYPE already defined");
     
    14411618
    14421619ver_block
    1443         : BLOCK tSTRING tBEGIN ver_values tEND {
     1620        : tBLOCK tSTRING tBEGIN ver_values tEND {
    14441621                $$ = new_ver_block();
    14451622                $$->name = $2;
     
    14641641                $$->value.block = $1;
    14651642                }
    1466         | VALUE tSTRING ',' tSTRING {
     1643        | tVALUE tSTRING ',' tSTRING {
    14671644                $$ = new_ver_value();
    14681645                $$->type = val_str;
     
    14701647                $$->value.str = $4;
    14711648                }
    1472         | VALUE tSTRING ',' ver_words {
     1649        | tVALUE tSTRING ',' ver_words {
    14731650                $$ = new_ver_value();
    14741651                $$->type = val_words;
     
    14841661
    14851662/* ------------------------------ Toolbar ------------------------------ */
    1486 toolbar: TOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
     1663toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
    14871664                int nitems;
    14881665                toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
     
    15111688toolbar_items
    15121689        :  /* Empty */                  { $$ = NULL; }
    1513         | toolbar_items BUTTON expr     {         
     1690        | toolbar_items tBUTTON expr    {         
    15141691                toolbar_item_t *idrec = new_toolbar_item();
    15151692                idrec->id = $3;
    15161693                $$ = ins_tlbr_button($1, idrec);
    15171694                }
    1518         | toolbar_items SEPARATOR       {         
     1695        | toolbar_items tSEPARATOR      {         
    15191696                toolbar_item_t *idrec = new_toolbar_item();
    15201697                idrec->id = 0;
     
    15511728        ;
    15521729
    1553 lamo    : PRELOAD       { $$ = new_int(WRC_MO_PRELOAD); }
    1554         | MOVEABLE      { $$ = new_int(WRC_MO_MOVEABLE); }
    1555         | DISCARDABLE   { $$ = new_int(WRC_MO_DISCARDABLE); }
     1730lamo    : tPRELOAD      { $$ = new_int(WRC_MO_PRELOAD); }
     1731        | tMOVEABLE     { $$ = new_int(WRC_MO_MOVEABLE); }
     1732        | tDISCARDABLE  { $$ = new_int(WRC_MO_DISCARDABLE); }
    15561733        | tPURE         { $$ = new_int(WRC_MO_PURE); }
    15571734        ;
    15581735
    1559 lama    : LOADONCALL    { $$ = new_int(~WRC_MO_PRELOAD); }
     1736lama    : tLOADONCALL   { $$ = new_int(~WRC_MO_PRELOAD); }
    15601737        | tFIXED        { $$ = new_int(~WRC_MO_MOVEABLE); }
    1561         | IMPURE        { $$ = new_int(~WRC_MO_PURE); }
     1738        | tIMPURE       { $$ = new_int(~WRC_MO_PURE); }
    15621739        ;
    15631740
     
    15901767        ;
    15911768
     1769        /*
     1770         * This here is another s/r conflict on {bi,u}nary + and -.
     1771         * It is due to the look-ahead which must determine when the
     1772         * rule opt_language ends. It could be solved with adding a
     1773         * tNL at the end, but that seems unreasonable to do.
     1774         * The conflict is now moved to the expression handling below.
     1775         */
    15921776opt_language
    1593         : LANGUAGE expr ',' expr        { $$ = new_language($2, $4); }
     1777        : tLANGUAGE expr ',' expr       { $$ = new_language($2, $4); }
    15941778        ;
    15951779
    15961780opt_characts
    1597         : CHARACTERISTICS expr          { $$ = new_characts($2); }
     1781        : tCHARACTERISTICS expr         { $$ = new_characts($2); }
    15981782        ;
    15991783
    16001784opt_version
    1601         : VERSION expr                  { $$ = new_version($2); }
    1602         ;
    1603 
    1604 /* ------------------------------ Raw data handking ------------------------------ */
    1605 raw_data: tBEGIN raw_elements tEND      { $$ = $2; }
     1785        : tVERSION expr                 { $$ = new_version($2); }
     1786        ;
     1787
     1788/* ------------------------------ Raw data handling ------------------------------ */
     1789raw_data: opt_lvc tBEGIN raw_elements tEND {
     1790                if($1)
     1791                {
     1792                        $3->lvc = *($1);
     1793                        free($1);
     1794                }
     1795
     1796                if(!$3->lvc.language)
     1797                        $3->lvc.language = dup_language(currentlanguage);
     1798
     1799                $$ = $3;
     1800                }
    16061801        ;
    16071802
    16081803raw_elements
    1609         : RAWDATA                       { $$ = $1; }
    1610         | NUMBER                        { $$ = int2raw_data($1); }
    1611         | LNUMBER                       { $$ = long2raw_data($1); }
     1804        : tRAWDATA                      { $$ = $1; }
     1805        | tNUMBER                       { $$ = int2raw_data($1); }
     1806        | tLNUMBER                      { $$ = long2raw_data($1); }
    16121807        | tSTRING                       { $$ = str2raw_data($1); }
    1613         | raw_elements opt_comma RAWDATA   { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
    1614         | raw_elements opt_comma NUMBER    { $$ = merge_raw_data_int($1, $3); }
    1615         | raw_elements opt_comma LNUMBER   { $$ = merge_raw_data_long($1, $3); }
    1616         | raw_elements opt_comma tSTRING   { $$ = merge_raw_data_str($1, $3); }
     1808        | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
     1809        | raw_elements opt_comma tNUMBER  { $$ = merge_raw_data_int($1, $3); }
     1810        | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
     1811        | raw_elements opt_comma tSTRING  { $$ = merge_raw_data_str($1, $3); }
     1812        ;
     1813
     1814/* File data or raw data */
     1815file_raw: filename      {
     1816                $$ = load_file($1);
     1817                $$->lvc.language = dup_language(currentlanguage);
     1818                }
     1819        | raw_data      { $$ = $1; }
    16171820        ;
    16181821
     
    16241827        | expr          { $$ = new_int($1); }
    16251828        ;
     1829
     1830/* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
    16261831expr    : xpr   { $$ = ($1); }
    16271832        ;
     
    16331838        | xpr '*' xpr   { $$ = ($1) * ($3); }
    16341839        | xpr '/' xpr   { $$ = ($1) / ($3); }
     1840        | xpr '^' xpr   { $$ = ($1) ^ ($3); }
    16351841        | '~' xpr       { $$ = ~($2); }
    1636         | '-' xpr       { $$ = -($2); }         /* FIXME: shift/reduce conflict */
    1637 /*      | '+' xpr       { $$ = $2; } */
     1842        | '-' xpr %prec pUPM    { $$ = -($2); }
     1843        | '+' xpr %prec pUPM    { $$ = $2; }
    16381844        | '(' xpr ')'   { $$ = $2; }
    1639         | any_num       { $$ = $1; want_rscname = 0; }
    1640         | NOT any_num   { $$ = ~($2); }
    1641         ;
    1642 
    1643 any_num : NUMBER        { $$ = $1; }
    1644         | LNUMBER       { $$ = $1; }
     1845        | any_num       { $$ = $1; }
     1846        | tNOT any_num  { $$ = ~($2); }
     1847        ;
     1848
     1849any_num : tNUMBER       { $$ = $1; }
     1850        | tLNUMBER      { $$ = $1; }
    16451851        ;
    16461852
    16471853%%
    16481854/* Dialog specific functions */
    1649 dialog_t *dialog_style(style_t * st, dialog_t *dlg)
     1855static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
    16501856{
    16511857        assert(dlg != NULL);
     
    16711877}
    16721878
    1673 dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
     1879static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
    16741880{
    16751881        assert(dlg != NULL);
     
    16951901}
    16961902
    1697 dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
     1903static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
    16981904{
    16991905        assert(dlg != NULL);
     
    17041910}
    17051911
    1706 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
     1912static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
    17071913{
    17081914        assert(dlg != NULL);
     
    17131919}
    17141920
    1715 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
     1921static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
    17161922{
    17171923        assert(dlg != NULL);
     
    17221928}
    17231929
    1724 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
     1930static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
    17251931{
    17261932        assert(dlg != NULL);
     
    17311937}
    17321938
    1733 dialog_t *dialog_language(language_t *l, dialog_t *dlg)
     1939static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
    17341940{
    17351941        assert(dlg != NULL);
     
    17401946}
    17411947
    1742 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
     1948static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
    17431949{
    17441950        assert(dlg != NULL);
     
    17491955}
    17501956
    1751 dialog_t *dialog_version(version_t *v, dialog_t *dlg)
     1957static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
    17521958{
    17531959        assert(dlg != NULL);
     
    17591965
    17601966/* Controls specific functions */
    1761 control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
     1967static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
    17621968{
    17631969        /* Hm... this seems to be jammed in at all time... */
     
    18832089}
    18842090
    1885 name_id_t *convert_ctlclass(name_id_t *cls)
    1886 {
    1887         char *cc;
     2091static name_id_t *convert_ctlclass(name_id_t *cls)
     2092{
     2093        char *cc = NULL;
    18882094        int iclass;
    18892095
     
    19212127
    19222128/* DialogEx specific functions */
    1923 dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
     2129static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
    19242130{
    19252131        assert(dlg != NULL);
     
    19452151}
    19462152
    1947 dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
     2153static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
    19482154{
    19492155        assert(dlg != NULL);
     
    19692175}
    19702176
    1971 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
     2177static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
    19722178{
    19732179        assert(dlg != NULL);
     
    19782184}
    19792185
    1980 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
     2186static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
    19812187{
    19822188        assert(dlg != NULL);
     
    19872193}
    19882194
    1989 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
     2195static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
    19902196{
    19912197        assert(dlg != NULL);
     
    19962202}
    19972203
    1998 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
     2204static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
    19992205{
    20002206        assert(dlg != NULL);
     
    20052211}
    20062212
    2007 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
     2213static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
    20082214{
    20092215        assert(dlg != NULL);
     
    20142220}
    20152221
    2016 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
     2222static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
    20172223{
    20182224        assert(dlg != NULL);
     
    20232229}
    20242230
    2025 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
     2231static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
    20262232{
    20272233        assert(dlg != NULL);
     
    20332239
    20342240/* Accelerator specific functions */
    2035 event_t *add_event(int key, int id, int flags, event_t *prev)
     2241static event_t *add_event(int key, int id, int flags, event_t *prev)
    20362242{
    20372243        event_t *ev = new_event();
     
    20492255}
    20502256
    2051 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
     2257static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
    20522258{
    20532259        int keycode = 0;
     
    20572263                yyerror("Key code must be an ascii string");
    20582264
    2059         if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0]) && !isdigit(key->str.cstr[0])))
     2265        if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
    20602266                yyerror("VIRTKEY code is not equal to ascii value");
    20612267
     
    20822288
    20832289/* MenuEx specific functions */
    2084 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
     2290static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
    20852291{
    20862292        itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
     
    20932299
    20942300/* Raw data functions */
    2095 raw_data_t *load_file(string_t *name)
     2301static raw_data_t *load_file(string_t *name)
    20962302{
    20972303        FILE *fp;
     
    21002306                yyerror("Filename must be ASCII string");
    21012307               
    2102         fp = open_include(name->str.cstr, 1);
     2308        fp = open_include(name->str.cstr, 1, NULL);
    21032309        if(!fp)
    21042310                yyerror("Cannot open file %s", name->str.cstr);
     
    21102316        fread(rd->data, rd->size, 1, fp);
    21112317        fclose(fp);
    2112         HEAPCHECK();
    21132318        return rd;
    21142319}
    21152320
    2116 raw_data_t *int2raw_data(int i)
     2321static raw_data_t *int2raw_data(int i)
    21172322{
    21182323        raw_data_t *rd;
     
    21242329        rd->size = sizeof(short);
    21252330        rd->data = (char *)xmalloc(rd->size);
    2126         *(short *)(rd->data) = (short)i;
     2331        switch(byteorder)
     2332        {
     2333#ifdef WORDS_BIGENDIAN
     2334        default:
     2335#endif
     2336        case WRC_BO_BIG:
     2337                rd->data[0] = HIBYTE(i);
     2338                rd->data[1] = LOBYTE(i);
     2339                break;
     2340
     2341#ifndef WORDS_BIGENDIAN
     2342        default:
     2343#endif
     2344        case WRC_BO_LITTLE:
     2345                rd->data[1] = HIBYTE(i);
     2346                rd->data[0] = LOBYTE(i);
     2347                break;
     2348        }
    21272349        return rd;
    21282350}
    21292351
    2130 raw_data_t *long2raw_data(int i)
     2352static raw_data_t *long2raw_data(int i)
    21312353{
    21322354        raw_data_t *rd;
     
    21342356        rd->size = sizeof(int);
    21352357        rd->data = (char *)xmalloc(rd->size);
    2136         *(int *)(rd->data) = i;
     2358        switch(byteorder)
     2359        {
     2360#ifdef WORDS_BIGENDIAN
     2361        default:
     2362#endif
     2363        case WRC_BO_BIG:
     2364                rd->data[0] = HIBYTE(HIWORD(i));
     2365                rd->data[1] = LOBYTE(HIWORD(i));
     2366                rd->data[2] = HIBYTE(LOWORD(i));
     2367                rd->data[3] = LOBYTE(LOWORD(i));
     2368                break;
     2369
     2370#ifndef WORDS_BIGENDIAN
     2371        default:
     2372#endif
     2373        case WRC_BO_LITTLE:
     2374                rd->data[3] = HIBYTE(HIWORD(i));
     2375                rd->data[2] = LOBYTE(HIWORD(i));
     2376                rd->data[1] = HIBYTE(LOWORD(i));
     2377                rd->data[0] = LOBYTE(LOWORD(i));
     2378                break;
     2379        }
    21372380        return rd;
    21382381}
    21392382
    2140 raw_data_t *str2raw_data(string_t *str)
     2383static raw_data_t *str2raw_data(string_t *str)
    21412384{
    21422385        raw_data_t *rd;
     
    21442387        rd->size = str->size * (str->type == str_char ? 1 : 2);
    21452388        rd->data = (char *)xmalloc(rd->size);
    2146         memcpy(rd->data, str->str.cstr, rd->size);
     2389        if(str->type == str_char)
     2390                memcpy(rd->data, str->str.cstr, rd->size);
     2391        else if(str->type == str_unicode)
     2392        {
     2393                int i;
     2394                switch(byteorder)
     2395                {
     2396#ifdef WORDS_BIGENDIAN
     2397                default:
     2398#endif
     2399                case WRC_BO_BIG:
     2400                        for(i = 0; i < str->size; i++)
     2401                        {
     2402                                rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
     2403                                rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
     2404                        }
     2405                        break;
     2406#ifndef WORDS_BIGENDIAN
     2407                default:
     2408#endif
     2409                case WRC_BO_LITTLE:
     2410                        for(i = 0; i < str->size; i++)
     2411                        {
     2412                                rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
     2413                                rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
     2414                        }
     2415                        break;
     2416                }
     2417        }
     2418        else
     2419                internal_error(__FILE__, __LINE__, "Invalid stringtype");
    21472420        return rd;
    21482421}
    21492422
    2150 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
     2423static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
    21512424{
    21522425        r1->data = xrealloc(r1->data, r1->size + r2->size);
     
    21562429}
    21572430
    2158 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
     2431static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
    21592432{
    21602433        raw_data_t *t = int2raw_data(i);
     
    21652438}
    21662439
    2167 raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
     2440static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
    21682441{
    21692442        raw_data_t *t = long2raw_data(i);
     
    21742447}
    21752448
    2176 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
     2449static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
    21772450{
    21782451        raw_data_t *t = str2raw_data(str);
     
    21842457
    21852458/* Function the go back in a list to get the head */
    2186 menu_item_t *get_item_head(menu_item_t *p)
     2459static menu_item_t *get_item_head(menu_item_t *p)
    21872460{
    21882461        if(!p)
     
    21932466}
    21942467
    2195 menuex_item_t *get_itemex_head(menuex_item_t *p)
     2468static menuex_item_t *get_itemex_head(menuex_item_t *p)
    21962469{
    21972470        if(!p)
     
    22022475}
    22032476
    2204 resource_t *get_resource_head(resource_t *p)
     2477static resource_t *get_resource_head(resource_t *p)
    22052478{
    22062479        if(!p)
     
    22112484}
    22122485
    2213 ver_block_t *get_ver_block_head(ver_block_t *p)
     2486static ver_block_t *get_ver_block_head(ver_block_t *p)
    22142487{
    22152488        if(!p)
     
    22202493}
    22212494
    2222 ver_value_t *get_ver_value_head(ver_value_t *p)
     2495static ver_value_t *get_ver_value_head(ver_value_t *p)
    22232496{
    22242497        if(!p)
     
    22292502}
    22302503
    2231 control_t *get_control_head(control_t *p)
     2504static control_t *get_control_head(control_t *p)
    22322505{
    22332506        if(!p)
     
    22382511}
    22392512
    2240 event_t *get_event_head(event_t *p)
     2513static event_t *get_event_head(event_t *p)
    22412514{
    22422515        if(!p)
     
    22482521
    22492522/* Find a stringtable with given language */
    2250 stringtable_t *find_stringtable(lvc_t *lvc)
     2523static stringtable_t *find_stringtable(lvc_t *lvc)
    22512524{
    22522525        stringtable_t *stt;
     
    22602533        {
    22612534                if(stt->lvc.language->id == lvc->language->id
    2262                 && stt->lvc.language->id == lvc->language->id)
     2535                && stt->lvc.language->sub == lvc->language->sub)
    22632536                {
    22642537                        /* Found a table with the same language */
     
    22842557/* qsort sorting function for string table entries */
    22852558#define STE(p)  ((stt_entry_t *)(p))
    2286 int sort_stt_entry(const void *e1, const void *e2)
     2559static int sort_stt_entry(const void *e1, const void *e2)
    22872560{
    22882561        return STE(e1)->id - STE(e2)->id;
     
    22902563#undef STE
    22912564
    2292 resource_t *build_stt_resources(stringtable_t *stthead)
     2565static resource_t *build_stt_resources(stringtable_t *stthead)
    22932566{
    22942567        stringtable_t *stt;
     
    23882661}
    23892662
    2390 /* Cursor and icon splitter functions */
    2391 typedef struct {
    2392         language_t      lan;
    2393         int             id;
    2394 } id_alloc_t;
    2395 
    2396 static int get_new_id(id_alloc_t **list, int *n, language_t *lan)
    2397 {
    2398         int i;
    2399         assert(lan != NULL);
    2400         assert(list != NULL);
    2401         assert(n != NULL);
    2402 
    2403         if(!*list)
    2404         {
    2405                 *list = (id_alloc_t *)xmalloc(sizeof(id_alloc_t));
    2406                 *n = 1;
    2407                 (*list)[0].lan = *lan;
    2408                 (*list)[0].id = 1;
    2409                 return 1;
    2410         }
    2411 
    2412         for(i = 0; i < *n; i++)
    2413         {
    2414                 if((*list)[i].lan.id == lan->id && (*list)[i].lan.sub == lan->sub)
    2415                         return ++((*list)[i].id);
    2416         }
    2417 
    2418         *list = (id_alloc_t *)xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
    2419         (*list)[*n].lan = *lan;
    2420         (*list)[*n].id = 1;
    2421         *n += 1;
    2422         return 1;
    2423 }
    2424 
    2425 int alloc_icon_id(language_t *lan)
    2426 {
    2427         static id_alloc_t *idlist = NULL;
    2428         static int nid = 0;
    2429 
    2430         return get_new_id(&idlist, &nid, lan);
    2431 }
    2432 
    2433 int alloc_cursor_id(language_t *lan)
    2434 {
    2435         static id_alloc_t *idlist = NULL;
    2436         static int nid = 0;
    2437 
    2438         return get_new_id(&idlist, &nid, lan);
    2439 }
    2440 
    2441 #define BPTR(base)      ((char *)(rd->data + (base)))
    2442 #define WPTR(base)      ((WORD *)(rd->data + (base)))
    2443 #define DPTR(base)      ((DWORD *)(rd->data + (base)))
    2444 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico)
    2445 {
    2446         int cnt;
    2447         int i;
    2448         icon_dir_entry_t *ide;
    2449         icon_t *ico;
    2450         icon_t *list = NULL;
    2451 
    2452         /* FIXME: Distinguish between normal and animated icons (RIFF format) */
    2453         if(WPTR(0)[1] != 1)
    2454                 yyerror("Icon resource data has invalid type id %d", WPTR(0)[1]);
    2455         cnt = WPTR(0)[2];
    2456         ide = (icon_dir_entry_t *)&(WPTR(0)[3]);
    2457         for(i = 0; i < cnt; i++)
    2458         {
    2459                 ico = new_icon();
    2460                 ico->id = alloc_icon_id(icog->lvc.language);
    2461                 ico->lvc.language = dup_language(icog->lvc.language);
    2462                 if(ide[i].offset > rd->size
    2463                 || ide[i].offset + ide[i].ressize > rd->size)
    2464                         yyerror("Icon resource data corrupt");
    2465                 ico->width = ide[i].width;
    2466                 ico->height = ide[i].height;
    2467                 ico->nclr = ide[i].nclr;
    2468                 ico->planes = ide[i].planes;
    2469                 ico->bits = ide[i].bits;
    2470                 if(!ico->planes)
    2471                 {
    2472                         /* Argh! They did not fill out the resdir structure */
    2473                         ico->planes = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biPlanes;
    2474                 }
    2475                 if(!ico->bits)
    2476                 {
    2477                         /* Argh! They did not fill out the resdir structure */
    2478                         ico->bits = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biBitCount;
    2479                 }
    2480                 ico->data = new_raw_data();
    2481                 copy_raw_data(ico->data, rd, ide[i].offset, ide[i].ressize);
    2482                 if(!list)
    2483                 {
    2484                         list = ico;
    2485                 }
    2486                 else
    2487                 {
    2488                         ico->next = list;
    2489                         list->prev = ico;
    2490                         list = ico;
    2491                 }
    2492         }
    2493         icog->iconlist = list;
    2494         *nico = cnt;
    2495 }
    2496 
    2497 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur)
    2498 {
    2499         int cnt;
    2500         int i;
    2501         cursor_dir_entry_t *cde;
    2502         cursor_t *cur;
    2503         cursor_t *list = NULL;
    2504 
    2505         /* FIXME: Distinguish between normal and animated cursors (RIFF format)*/
    2506         if(WPTR(0)[1] != 2)
    2507                 yyerror("Cursor resource data has invalid type id %d", WPTR(0)[1]);
    2508         cnt = WPTR(0)[2];
    2509         cde = (cursor_dir_entry_t *)&(WPTR(0)[3]);
    2510         for(i = 0; i < cnt; i++)
    2511         {
    2512                 cur = new_cursor();
    2513                 cur->id = alloc_cursor_id(curg->lvc.language);
    2514                 cur->lvc.language = dup_language(curg->lvc.language);
    2515                 if(cde[i].offset > rd->size
    2516                 || cde[i].offset + cde[i].ressize > rd->size)
    2517                         yyerror("Cursor resource data corrupt");
    2518                 cur->width = cde[i].width;
    2519                 cur->height = cde[i].height;
    2520                 cur->nclr = cde[i].nclr;
    2521                 /* The next two are to support color cursors */
    2522                 cur->planes = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biPlanes;
    2523                 cur->bits = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biBitCount;
    2524                 if(!win32 && (cur->planes != 1 || cur->bits != 1))
    2525                         yywarning("Win16 cursor contains colors");
    2526                 cur->xhot = cde[i].xhot;
    2527                 cur->yhot = cde[i].yhot;
    2528                 cur->data = new_raw_data();
    2529                 copy_raw_data(cur->data, rd, cde[i].offset, cde[i].ressize);
    2530                 if(!list)
    2531                 {
    2532                         list = cur;
    2533                 }
    2534                 else
    2535                 {
    2536                         cur->next = list;
    2537                         list->prev = cur;
    2538                         list = cur;
    2539                 }
    2540         }
    2541         curg->cursorlist = list;
    2542         *ncur = cnt;
    2543 }
    2544 
    2545 #undef  BPTR
    2546 #undef  WPTR
    2547 #undef  DPTR
    2548 
    2549 
    2550 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
     2663
     2664static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
    25512665{
    25522666        idrec->prev = prev;
     
    25572671}
    25582672
    2559 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
     2673static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
    25602674{
    25612675        if(!p)
     
    25762690}
    25772691
     2692static string_t *make_filename(string_t *str)
     2693{
     2694        char *cptr;
     2695
     2696        if(str->type != str_char)
     2697                yyerror("Cannot handle UNICODE filenames");
     2698
     2699        /* Remove escaped backslash and convert to forward */
     2700        cptr = str->str.cstr;
     2701        for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
     2702        {
     2703                if(cptr[1] == '\\')
     2704                {
     2705                        memmove(cptr, cptr+1, strlen(cptr));
     2706                        str->size--;
     2707                }
     2708                *cptr = '/';
     2709        }
     2710
     2711        /* Convert to lower case. Seems to be reasonable to do */
     2712        for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
     2713        {
     2714                *cptr = tolower(*cptr);
     2715        }
     2716        return str;
     2717}
     2718
     2719/*
     2720 * Process all resources to extract fonts and build
     2721 * a fontdir resource.
     2722 *
     2723 * Note: MS' resource compiler (build 1472) does not
     2724 * handle font resources with different languages.
     2725 * The fontdir is generated in the last active language
     2726 * and font identifiers must be unique across the entire
     2727 * source.
     2728 * This is not logical considering the localization
     2729 * constraints of all other resource types. MS has,
     2730 * most probably, never testet localized fonts. However,
     2731 * using fontresources is rare, so it might not occur
     2732 * in normal applications.
     2733 * Wine does require better localization because a lot
     2734 * of languages are coded into the same executable.
     2735 * Therefore, I will generate fontdirs for *each*
     2736 * localized set of fonts.
     2737 */
     2738static resource_t *build_fontdir(resource_t **fnt, int nfnt)
     2739{
     2740        static int once = 0;
     2741        if(!once)
     2742        {
     2743                warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
     2744                once++;
     2745        }
     2746        return NULL;
     2747}
     2748
     2749static resource_t *build_fontdirs(resource_t *tail)
     2750{
     2751        resource_t *rsc;
     2752        resource_t *lst = NULL;
     2753        resource_t **fnt = NULL;        /* List of all fonts */
     2754        int nfnt = 0;
     2755        resource_t **fnd = NULL;        /* List of all fontdirs */
     2756        int nfnd = 0;
     2757        resource_t **lanfnt = NULL;
     2758        int nlanfnt = 0;
     2759        int i;
     2760        name_id_t nid;
     2761        string_t str;
     2762        int fntleft;
     2763
     2764        nid.type = name_str;
     2765        nid.name.s_name = &str;
     2766        str.type = str_char;
     2767        str.str.cstr = "FONTDIR";
     2768        str.size = 7;
     2769
     2770        /* Extract all fonts and fontdirs */
     2771        for(rsc = tail; rsc; rsc = rsc->prev)
     2772        {
     2773                if(rsc->type == res_fnt)
     2774                {
     2775                        nfnt++;
     2776                        fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
     2777                        fnt[nfnt-1] = rsc;
     2778                }
     2779                else if(rsc->type == res_fntdir)
     2780                {
     2781                        nfnd++;
     2782                        fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
     2783                        fnd[nfnd-1] = rsc;
     2784                }
     2785        }
     2786
     2787        /* Verify the name of the present fontdirs */
     2788        for(i = 0; i < nfnd; i++)
     2789        {
     2790                if(compare_name_id(&nid, fnd[i]->name))
     2791                {
     2792                        warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
     2793                                get_nameid_str(fnd[i]->name));
     2794                        fnd[i] = NULL;
     2795                }
     2796        }
     2797
     2798        /* Sanity check */
     2799        if(nfnt == 0)
     2800        {
     2801                if(nfnd != 0)
     2802                        warning("Found %d FONTDIR entries without any fonts present", nfnd);
     2803                goto clean;
     2804        }
     2805
     2806        /* Copy space */
     2807        lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
     2808
     2809        /* Get all fonts covered by fontdirs */
     2810        for(i = 0; i < nfnd; i++)
     2811        {
     2812                int j;
     2813                WORD cnt;
     2814                int isswapped = 0;
     2815
     2816                if(!fnd[i])
     2817                        continue;
     2818                for(j = 0; j < nfnt; j++)
     2819                {
     2820                        if(!fnt[j])
     2821                                continue;
     2822                        if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
     2823                        {
     2824                                lanfnt[nlanfnt] = fnt[j];
     2825                                nlanfnt++;
     2826                                fnt[j] = NULL;
     2827                        }
     2828                }
     2829
     2830                cnt = *(WORD *)fnd[i]->res.fnd->data->data;
     2831                if(nlanfnt == cnt)
     2832                        isswapped = 0;
     2833                else if(nlanfnt == BYTESWAP_WORD(cnt))
     2834                        isswapped = 1;
     2835                else
     2836                        error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
     2837                                fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
     2838#ifdef WORDS_BIGENDIAN
     2839                if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
     2840#else
     2841                if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
     2842#endif
     2843                {
     2844                        internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
     2845                }
     2846        }
     2847
     2848        /* We now have fonts left where we need to make a fontdir resource */
     2849        for(i = fntleft = 0; i < nfnt; i++)
     2850        {
     2851                if(fnt[i])
     2852                        fntleft++;
     2853        }
     2854        while(fntleft)
     2855        {
     2856                /* Get fonts of same language in lanfnt[] */
     2857                for(i = nlanfnt = 0; i < nfnt; i++)
     2858                {
     2859                        if(fnt[i])
     2860                        {
     2861                                if(!nlanfnt)
     2862                                {
     2863                        addlanfnt:
     2864                                        lanfnt[nlanfnt] = fnt[i];
     2865                                        nlanfnt++;
     2866                                        fnt[i] = NULL;
     2867                                        fntleft--;
     2868                                }
     2869                                else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
     2870                                        goto addlanfnt;
     2871                        }
     2872                }
     2873                /* and build a fontdir */
     2874                rsc = build_fontdir(lanfnt, nlanfnt);
     2875                if(rsc)
     2876                {
     2877                        if(lst)
     2878                        {
     2879                                lst->next = rsc;
     2880                                rsc->prev = lst;
     2881                        }
     2882                        lst = rsc;
     2883                }
     2884        }
     2885
     2886        free(lanfnt);
     2887clean:
     2888        if(fnt)
     2889                free(fnt);
     2890        if(fnd)
     2891                free(fnd);
     2892        return lst;
     2893}
     2894
     2895/*
     2896 * This gets invoked to determine whether the next resource
     2897 * is to be of a standard-type (e.g. bitmaps etc.), or should
     2898 * be a user-type resource. This function is required because
     2899 * there is the _possibility_ of a lookahead token in the
     2900 * parser, which is generated from the "expr" state in the
     2901 * "nameid" parsing.
     2902 *
     2903 * The general resource format is:
     2904 * <identifier> <type> <flags> <resourcebody>
     2905 *
     2906 * The <identifier> can either be tIDENT or "expr". The latter
     2907 * will always generate a lookahead, which is the <type> of the
     2908 * resource to parse. Otherwise, we need to get a new token from
     2909 * the scanner to determine the next step.
     2910 *
     2911 * The problem arrises when <type> is numerical. This case should
     2912 * map onto default resource-types and be parsed as such instead
     2913 * of being mapped onto user-type resources.
     2914 *
     2915 * The trick lies in the fact that yacc (bison) doesn't care about
     2916 * intermediate changes of the lookahead while reducing a rule. We
     2917 * simply replace the lookahead with a token that will result in
     2918 * a shift to the appropriate rule for the specific resource-type.
     2919 */
     2920static int rsrcid_to_token(int lookahead)
     2921{
     2922        int token;
     2923        char *type = "?";
     2924
     2925        /* Get a token if we don't have one yet */
     2926        if(lookahead == YYEMPTY)
     2927                lookahead = YYLEX;
     2928
     2929        /* Only numbers are possibly interesting */
     2930        switch(lookahead)
     2931        {
     2932        case tNUMBER:
     2933        case tLNUMBER:
     2934                break;
     2935        default:
     2936                return lookahead;
     2937        }
     2938
     2939        token = lookahead;
     2940
     2941        switch(yylval.num)
     2942        {
     2943        case WRC_RT_CURSOR:
     2944                type = "CURSOR";
     2945                token = tCURSOR;
     2946                break;
     2947        case WRC_RT_ICON:
     2948                type = "ICON";
     2949                token = tICON;
     2950                break;
     2951        case WRC_RT_BITMAP:
     2952                type = "BITMAP";
     2953                token = tBITMAP;
     2954                break;
     2955        case WRC_RT_FONT:
     2956                type = "FONT";
     2957                token = tFONT;
     2958                break;
     2959        case WRC_RT_FONTDIR:
     2960                type = "FONTDIR";
     2961                token = tFONTDIR;
     2962                break;
     2963        case WRC_RT_RCDATA:
     2964                type = "RCDATA";
     2965                token = tRCDATA;
     2966                break;
     2967        case WRC_RT_MESSAGETABLE:
     2968                type = "MESSAGETABLE";
     2969                token = tMESSAGETABLE;
     2970                break;
     2971        case WRC_RT_DLGINIT:
     2972                type = "DLGINIT";
     2973                token = tDLGINIT;
     2974                break;
     2975        case WRC_RT_ACCELERATOR:
     2976                type = "ACCELERATOR";
     2977                token = tACCELERATORS;
     2978                break;
     2979        case WRC_RT_MENU:
     2980                type = "MENU";
     2981                token = tMENU;
     2982                break;
     2983        case WRC_RT_DIALOG:
     2984                type = "DIALOG";
     2985                token = tDIALOG;
     2986                break;
     2987        case WRC_RT_VERSION:
     2988                type = "VERSION";
     2989                token = tVERSIONINFO;
     2990                break;
     2991        case WRC_RT_TOOLBAR:
     2992                type = "TOOLBAR";
     2993                token = tTOOLBAR;
     2994                break;
     2995
     2996        case WRC_RT_STRING:
     2997                type = "STRINGTABLE";
     2998                break;
     2999
     3000        case WRC_RT_ANICURSOR:
     3001        case WRC_RT_ANIICON:
     3002        case WRC_RT_GROUP_CURSOR:
     3003        case WRC_RT_GROUP_ICON:
     3004                yywarning("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num);
     3005                return lookahead;
     3006
     3007        case WRC_RT_DLGINCLUDE:
     3008        case WRC_RT_PLUGPLAY:
     3009        case WRC_RT_VXD:
     3010        case WRC_RT_HTML:
     3011                yywarning("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num);
     3012        default:
     3013                return lookahead;
     3014        }
     3015
     3016        if(remap)
     3017                return token;
     3018        else
     3019                yywarning("Usertype uses reserved type-ID %d, which is used by %s", yylval.num, type);
     3020        return lookahead;
     3021}
     3022
  • trunk/tools/wrc/preproc.c

    r3476 r5522  
    99#include <stdlib.h>
    1010#include <string.h>
     11#include <assert.h>
    1112
    1213#include "wrc.h"
    1314#include "utils.h"
    1415#include "preproc.h"
    15 #include "parser.h"
    1616
    1717
    1818extern void set_pp_ignore(int); /* From parser.l */
    1919
    20 static char *current_define;
    21 
    2220#define HASHKEY         2039
    23 static struct pp_entry *pp_defines[HASHKEY];
     21static pp_entry_t *pp_defines[HASHKEY];
    2422
    2523#define MAXIFSTACK      64
    26 static struct if_state ifstack[MAXIFSTACK];
    27 static int ifstackidx = 0;
     24static if_state_t if_stack[MAXIFSTACK];
     25static int if_stack_idx = 0;
    2826
    2927#if 0
     28void pp_status(void) __attribute__((destructor));
    3029void pp_status(void)
    3130{
     
    3332        int sum;
    3433        int total = 0;
    35         struct pp_entry *ppp;
    36 
    37         printf("Defines statistics:\n");
     34        pp_entry_t *ppp;
     35
     36        fprintf(stderr, "Defines statistics:\n");
    3837        for(i = 0; i < HASHKEY; i++)
    3938        {
     
    4241                        sum++;
    4342                total += sum;
    44                 printf("%4d, %3d\n", i, sum);
    45         }
    46         printf("Total defines: %d\n", total);
    47 }
    48 #pragma exit pp_status
     43                fprintf(stderr, "%4d, %3d\n", i, sum);
     44        }
     45        fprintf(stderr, "Total defines: %d\n", total);
     46}
    4947#endif
    5048
    5149/* Don't comment on the hash, its primitive but functional... */
    52 int pp_hash(char *str)
     50int pphash(char *str)
    5351{
    5452        int sum = 0;
     
    5856}
    5957
    60 struct pp_entry *pp_lookup(char *ident)
    61 {
    62         int index = pp_hash(ident);
    63         struct pp_entry *ppp;
    64         for(ppp = pp_defines[index]; ppp; ppp = ppp->next)
     58pp_entry_t *pplookup(char *ident)
     59{
     60        int idx = pphash(ident);
     61        pp_entry_t *ppp;
     62
     63        for(ppp = pp_defines[idx]; ppp; ppp = ppp->next)
    6564        {
    6665                if(!strcmp(ident, ppp->ident))
     
    7069}
    7170
    72 void set_define(char *name)
    73 {
    74         current_define = xstrdup(name);
    75 }
    76 
    7771void del_define(char *name)
    7872{
    79         int index;
    80         struct pp_entry *ppp;
    81 
    82         if((ppp = pp_lookup(name)) == NULL)
     73        int idx;
     74        pp_entry_t *ppp;
     75
     76        if((ppp = pplookup(name)) == NULL)
    8377        {
    8478                if(pedantic)
     
    8781        }
    8882
    89         index = pp_hash(name);
    90         if(pp_defines[index] == ppp)
    91         {
    92                 pp_defines[index] = ppp->next;
    93                 if(pp_defines[index])
    94                         pp_defines[index]->prev = NULL;
     83        if(ppp->iep)
     84        {
     85                if(debuglevel & DEBUGLEVEL_PPMSG)
     86                        fprintf(stderr, "del_define: %s:%d: includelogic removed, include_ppp='%s', file=%s\n", input_name, line_number, name, ppp->iep->filename);
     87                if(ppp->iep == includelogiclist)
     88                {
     89                        includelogiclist = ppp->iep->next;
     90                        if(includelogiclist)
     91                                includelogiclist->prev = NULL;
     92                }
     93                else
     94                {
     95                        ppp->iep->prev->next = ppp->iep->next;
     96                        if(ppp->iep->next)
     97                                ppp->iep->next->prev = ppp->iep->prev;
     98                }
     99                free(ppp->iep->filename);
     100                free(ppp->iep);
     101        }
     102
     103        idx = pphash(name);
     104        if(pp_defines[idx] == ppp)
     105        {
     106                pp_defines[idx] = ppp->next;
     107                if(pp_defines[idx])
     108                        pp_defines[idx]->prev = NULL;
    95109        }
    96110        else
     
    100114                        ppp->next->prev = ppp->prev;
    101115        }
     116
    102117        free(ppp);
    103 }
    104 
    105 void add_define(char *text)
     118
     119        if(debuglevel & DEBUGLEVEL_PPMSG)
     120                printf("Deleted (%s, %d) <%s>\n", input_name, line_number, name);
     121}
     122
     123pp_entry_t *add_define(char *def, char *text)
    106124{
    107125        int len;
    108126        char *cptr;
    109         int index = pp_hash(current_define);
    110         struct pp_entry *ppp;
    111         if(pp_lookup(current_define) != NULL)
     127        int idx = pphash(def);
     128        pp_entry_t *ppp;
     129
     130        if((ppp = pplookup(def)) != NULL)
    112131        {
    113132                if(pedantic)
    114                         yywarning("Redefinition of %s", current_define);
    115                 del_define(current_define);
    116         }
    117         ppp = (struct pp_entry *)xmalloc(sizeof(struct pp_entry));
    118         ppp->ident = current_define;
    119         ppp->subst = xstrdup(text);
    120         ppp->next = pp_defines[index];
    121         pp_defines[index] = ppp;
     133                        yywarning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
     134                del_define(def);
     135        }
     136        ppp = (pp_entry_t *)xmalloc(sizeof(pp_entry_t));
     137        ppp->ident = def;
     138        ppp->type = def_define;
     139        ppp->subst.text = text;
     140        ppp->filename = input_name ? xstrdup(input_name) : "<internal or cmdline>";
     141        ppp->linenumber = input_name ? line_number : 0;
     142        ppp->next = pp_defines[idx];
     143        pp_defines[idx] = ppp;
    122144        if(ppp->next)
    123145                ppp->next->prev = ppp;
    124         /* Strip trailing white space from subst text */
    125         len = strlen(ppp->subst);
    126         while(len && strchr(" \t\r\n", ppp->subst[len-1]))
    127         {
    128                 ppp->subst[--len] = '\0';
    129         }
    130         /* Strip leading white space from subst text */
    131         for(cptr = ppp->subst; *cptr && strchr(" \t\r", *cptr); cptr++)
     146        if(text)
     147        {
     148                /* Strip trailing white space from subst text */
     149                len = strlen(text);
     150                while(len && strchr(" \t\r\n", text[len-1]))
     151                {
     152                        text[--len] = '\0';
     153                }
     154                /* Strip leading white space from subst text */
     155                for(cptr = text; *cptr && strchr(" \t\r", *cptr); cptr++)
    132156                ;
    133         if(ppp->subst != cptr)
    134                 memmove(ppp->subst, cptr, strlen(cptr)+1);
    135         if(yydebug)
    136                 printf("Added (%s, %d) <%s> to <%s>\n", input_name, line_number, ppp->ident, ppp->subst);
    137 }
    138 
    139 void add_cmdline_define(char *set)
     157                if(text != cptr)
     158                        memmove(text, cptr, strlen(cptr)+1);
     159        }
     160        if(debuglevel & DEBUGLEVEL_PPMSG)
     161                printf("Added define (%s, %d) <%s> to <%s>\n", input_name, line_number, ppp->ident, text ? text : "(null)");
     162
     163        return ppp;
     164}
     165
     166pp_entry_t *add_cmdline_define(char *set)
    140167{
    141168        char *cpy = xstrdup(set);       /* Because gcc passes a R/O string */
     
    143170        if(cptr)
    144171                *cptr = '\0';
    145         set_define(cpy);
    146         add_define(cptr ? cptr+1 : "");
    147         free(cpy);
    148 }
    149 
    150 /*kso added test for __SEMICOLON__ since __WIN32OS2__ isn't defined! */
    151 #if defined(__SEMICOLON__) || defined(_Windows) || defined(__MSDOS__) || defined(__WIN32OS2__)
     172        return add_define(cpy, xstrdup(cptr ? cptr+1 : ""));
     173}
     174
     175pp_entry_t *add_special_define(char *id)
     176{
     177        pp_entry_t *ppp = add_define(xstrdup(id), xstrdup(""));
     178        ppp->type = def_special;
     179        return ppp;
     180}
     181
     182pp_entry_t *add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
     183{
     184        int idx = pphash(id);
     185        pp_entry_t *ppp;
     186
     187        if((ppp = pplookup(id)) != NULL)
     188        {
     189                if(pedantic)
     190                        yywarning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
     191                del_define(id);
     192        }
     193        ppp = (pp_entry_t *)xmalloc(sizeof(pp_entry_t));
     194        ppp->ident      = id;
     195        ppp->type       = def_macro;
     196        ppp->margs      = args;
     197        ppp->nargs      = nargs;
     198        ppp->subst.mtext= exp;
     199        ppp->filename = input_name ? xstrdup(input_name) : "<internal or cmdline>";
     200        ppp->linenumber = input_name ? line_number : 0;
     201        ppp->next       = pp_defines[idx];
     202        pp_defines[idx] = ppp;
     203        if(ppp->next)
     204                ppp->next->prev = ppp;
     205
     206        if(debuglevel & DEBUGLEVEL_PPMSG)
     207        {
     208                fprintf(stderr, "Added macro (%s, %d) <%s(%d)> to <", input_name, line_number, ppp->ident, nargs);
     209                for(; exp; exp = exp->next)
     210                {
     211                        switch(exp->type)
     212                        {
     213                        case exp_text:
     214                                fprintf(stderr, " \"%s\" ", exp->subst.text);
     215                                break;
     216                        case exp_stringize:
     217                                fprintf(stderr, " #(%d) ", exp->subst.argidx);
     218                                break;
     219                        case exp_concat:
     220                                fprintf(stderr, "##");
     221                                break;
     222                        case exp_subst:
     223                                fprintf(stderr, " <%d> ", exp->subst.argidx);
     224                                break;
     225                        }
     226                }
     227                fprintf(stderr, ">\n");
     228        }
     229        return ppp;
     230}
     231
     232
     233/*
     234 *-------------------------------------------------------------------------
     235 * Include management
     236 *-------------------------------------------------------------------------
     237 */
     238#if defined(_Windows) || defined(__MSDOS__)
    152239#define INCLUDESEPARATOR        ";"
    153 #warning "Using ; as include separator"
    154240#else
    155 #warning "Using : as include separator"
    156241#define INCLUDESEPARATOR        ":"
    157242#endif
     
    192277}
    193278
    194 FILE *open_include(const char *name, int search)
     279FILE *open_include(const char *name, int search, char **newpath)
    195280{
    196281        char *cpy = xstrdup(name);
     
    212297        {
    213298                /* Search current dir and then -I path */
    214                 fp = fopen(name, "rt");
     299                fp = fopen(cpy, "rb");
    215300                if(fp)
    216301                {
    217                         if(yydebug)
     302                        if(debuglevel & DEBUGLEVEL_PPMSG)
    218303                                printf("Going to include <%s>\n", name);
    219                         free(cpy);
     304                        if(newpath)
     305                                *newpath = cpy;
     306                        else
     307                                free(cpy);
    220308                        return fp;
    221309                }
     
    229317                strcat(path, "/");
    230318                strcat(path, cpy);
    231                 fp = fopen(path, "rt");
    232                 if(fp && yydebug)
     319                fp = fopen(path, "rb");
     320                if(fp && (debuglevel & DEBUGLEVEL_PPMSG))
    233321                        printf("Going to include <%s>\n", path);
    234                 free(path);
    235322                if(fp)
    236323                {
     324                        if(newpath)
     325                                *newpath = path;
     326                        else
     327                                free(path);
    237328                        free(cpy);
    238329                        return fp;
    239330                }
    240 
     331                free(path);
    241332        }
    242333        free(cpy);
     334        if(newpath)
     335                *newpath = NULL;
    243336        return NULL;
    244337}
    245338
    246 void push_if(int truecase, int wastrue, int nevertrue)
    247 {
    248         if(ifstackidx >= MAXIFSTACK-1)
    249                 internal_error(__FILE__, __LINE__, "#if stack overflow");
    250         ifstack[ifstackidx].current = truecase && !wastrue;
    251         ifstack[ifstackidx].hasbeentrue = wastrue;
    252         ifstack[ifstackidx].nevertrue = nevertrue;
    253         if(nevertrue || !(truecase && !wastrue))
    254                 set_pp_ignore(1);
    255         if(yydebug)
    256                 printf("push_if: %d %d %d (%d %d %d)\n",
    257                         truecase,
    258                         wastrue,
    259                         nevertrue,
    260                         ifstack[ifstackidx].current,
    261                         ifstack[ifstackidx].hasbeentrue,
    262                         ifstack[ifstackidx].nevertrue);
    263         ifstackidx++;
    264 }
    265 
    266 int pop_if(void)
    267 {
    268         if(ifstackidx <= 0)
    269                 yyerror("#endif without #if|#ifdef|#ifndef (#if stack underflow)");
    270         ifstackidx--;
    271         if(yydebug)
    272                 printf("pop_if: %d %d %d\n",
    273                         ifstack[ifstackidx].current,
    274                         ifstack[ifstackidx].hasbeentrue,
    275                         ifstack[ifstackidx].nevertrue);
    276         if(ifstack[ifstackidx].nevertrue || !ifstack[ifstackidx].current)
    277                 set_pp_ignore(0);
    278         return ifstack[ifstackidx].hasbeentrue || ifstack[ifstackidx].current;
    279 }
    280 
    281 int isnevertrue_if(void)
    282 {
    283         return ifstackidx > 0 && ifstack[ifstackidx-1].nevertrue;
    284 }
    285 
     339/*
     340 *-------------------------------------------------------------------------
     341 * #if, #ifdef, #ifndef, #else, #elif and #endif state management
     342 *
     343 * #if state transitions are made on basis of the current TOS and the next
     344 * required state. The state transitions are required to housekeep because
     345 * #if:s can be nested. The ignore case is activated to prevent output from
     346 * within a false clause.
     347 * Some special cases come from the fact that the #elif cases are not
     348 * binary, but three-state. The problem is that all other elif-cases must
     349 * be false when one true one has been found. A second problem is that the
     350 * #else clause is a final clause. No extra #else:s may follow.
     351 *
     352 * The states mean:
     353 * if_true      Process input to output
     354 * if_false     Process input but no output
     355 * if_ignore    Process input but no output
     356 * if_elif      Process input but no output
     357 * if_elsefalse Process input but no output
     358 * if_elsettrue Process input to output
     359 *
     360 * The possible state-sequences are [state(stack depth)] (rest can be deduced):
     361 *      TOS             #if 1           #else                   #endif
     362 *      if_true(n)      if_true(n+1)    if_elsefalse(n+1)
     363 *      if_false(n)     if_ignore(n+1)  if_ignore(n+1)
     364 *      if_elsetrue(n)  if_true(n+1)    if_elsefalse(n+1)
     365 *      if_elsefalse(n) if_ignore(n+1)  if_ignore(n+1)
     366 *      if_elif(n)      if_ignore(n+1)  if_ignore(n+1)
     367 *      if_ignore(n)    if_ignore(n+1)  if_ignore(n+1)
     368 *
     369 *      TOS             #if 1           #elif 0         #else           #endif
     370 *      if_true(n)      if_true(n+1)    if_elif(n+1)    if_elif(n+1)
     371 *      if_false(n)     if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     372 *      if_elsetrue(n)  if_true(n+1)    if_elif(n+1)    if_elif(n+1)
     373 *      if_elsefalse(n) if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     374 *      if_elif(n)      if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     375 *      if_ignore(n)    if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     376 *
     377 *      TOS             #if 0           #elif 1         #else           #endif
     378 *      if_true(n)      if_false(n+1)   if_true(n+1)    if_elsefalse(n+1)
     379 *      if_false(n)     if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     380 *      if_elsetrue(n)  if_false(n+1)   if_true(n+1)    if_elsefalse(n+1)
     381 *      if_elsefalse(n) if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     382 *      if_elif(n)      if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     383 *      if_ignore(n)    if_ignore(n+1)  if_ignore(n+1)  if_ignore(n+1)
     384 *
     385 *-------------------------------------------------------------------------
     386 */
     387static char *if_state_str[] = {
     388        "if_false",
     389        "if_true",
     390        "if_elif",
     391        "if_elsefalse",
     392        "if_elsetrue",
     393        "if_ignore"
     394};
     395
     396void push_if(if_state_t s)
     397{
     398        if(if_stack_idx >= MAXIFSTACK)
     399                internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
     400
     401        if(debuglevel & DEBUGLEVEL_PPLEX)
     402                fprintf(stderr, "Push if %s:%d: %s(%d) -> %s(%d)\n", input_name, line_number, if_state_str[if_state()], if_stack_idx, if_state_str[s], if_stack_idx+1);
     403
     404        if_stack[if_stack_idx++] = s;
     405
     406        switch(s)
     407        {
     408        case if_true:
     409        case if_elsetrue:
     410                break;
     411        case if_false:
     412        case if_elsefalse:
     413        case if_elif:
     414        case if_ignore:
     415                push_ignore_state();
     416                break;
     417        }
     418}
     419
     420if_state_t pop_if(void)
     421{
     422        if(if_stack_idx <= 0)
     423                yyerror("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
     424
     425        switch(if_state())
     426        {
     427        case if_true:
     428        case if_elsetrue:
     429                break;
     430        case if_false:
     431        case if_elsefalse:
     432        case if_elif:
     433        case if_ignore:
     434                pop_ignore_state();
     435                break;
     436        }
     437
     438        if(debuglevel & DEBUGLEVEL_PPLEX)
     439                fprintf(stderr, "Pop if %s:%d: %s(%d) -> %s(%d)\n",
     440                                input_name,
     441                                line_number,
     442                                if_state_str[if_state()],
     443                                if_stack_idx,
     444                                if_state_str[if_stack[if_stack_idx <= 1 ? if_true : if_stack_idx-2]],
     445                                if_stack_idx-1);
     446
     447        return if_stack[--if_stack_idx];
     448}
     449
     450if_state_t if_state(void)
     451{
     452        if(!if_stack_idx)
     453                return if_true;
     454        else
     455                return if_stack[if_stack_idx-1];
     456}
     457
     458
     459void next_if_state(int i)
     460{
     461        switch(if_state())
     462        {
     463        case if_true:
     464        case if_elsetrue:
     465                push_if(i ? if_true : if_false);
     466                break;
     467        case if_false:
     468        case if_elsefalse:
     469        case if_elif:
     470        case if_ignore:
     471                push_if(if_ignore);
     472                break;
     473        default:
     474                internal_error(__FILE__, __LINE__, "Invalid if_state (%d) in #{if,ifdef,ifndef} directive", (int)if_state());
     475        }
     476}
     477
     478int get_if_depth(void)
     479{
     480        return if_stack_idx;
     481}
     482
  • trunk/tools/wrc/preproc.h

    r882 r5522  
    77#define __WRC_PREPROC_H
    88
    9 struct pp_entry {
     9struct pp_entry;        /* forward */
     10/*
     11 * Include logic
     12 * A stack of files which are already included and
     13 * are protected in the #ifndef/#endif way.
     14 */
     15typedef struct includelogicentry {
     16        struct includelogicentry *next;
     17        struct includelogicentry *prev;
     18        struct pp_entry *ppp;           /* The define which protects the file */
     19        char            *filename;      /* The filename of the include */
     20} includelogicentry_t;
     21
     22/*
     23 * The arguments of a macrodefinition
     24 */
     25typedef enum {
     26        arg_single,
     27        arg_list
     28} def_arg_t;
     29
     30typedef struct marg {
     31        def_arg_t       type;   /* Normal or ... argument */
     32        char            *arg;   /* The textual argument */
     33        int             nnl;    /* Number of newlines in the text to subst */
     34} marg_t;
     35
     36/*
     37 * The expansiontext of a macro
     38 */
     39typedef enum {
     40        exp_text,       /* Simple text substitution */
     41        exp_concat,     /* Concat (##) operator requested */
     42        exp_stringize,  /* Stringize (#) operator requested */
     43        exp_subst       /* Substitute argument */
     44} def_exp_t;
     45
     46typedef struct mtext {
     47        struct mtext    *next;
     48        struct mtext    *prev;
     49        def_exp_t       type;
     50        union {
     51                char    *text;
     52                int     argidx;         /* For exp_subst and exp_stringize reference */
     53        } subst;
     54} mtext_t;
     55
     56/*
     57 * The define descriptor
     58 */
     59typedef enum {
     60        def_none,       /* Not-a-define; used as return value */
     61        def_define,     /* Simple defines */
     62        def_macro,      /* Macro defines */
     63        def_special     /* Special expansions like __LINE__ and __FILE__ */
     64} def_type_t;
     65
     66typedef struct pp_entry {
    1067        struct pp_entry *next;
    1168        struct pp_entry *prev;
    12         char    *ident;
    13         char    *subst;
    14         int     expanding;
    15 };
     69        def_type_t      type;           /* Define or macro */
     70        char            *ident;         /* The key */
     71        marg_t          **margs;        /* Macro arguments array or NULL if none */
     72        int             nargs;
     73        union {
     74                mtext_t *mtext;         /* The substitution sequence or NULL if none */
     75                char    *text;
     76        } subst;
     77        int             expanding;      /* Set when feeding substitution into the input */
     78        char            *filename;      /* Filename where it was defined */
     79        int             linenumber;     /* Linenumber where it was defined */
     80        includelogicentry_t *iep;       /* Points to the include it protects */
     81} pp_entry_t;
    1682
    17 struct if_state {
    18         int     current;
    19         int     hasbeentrue;
    20         int     nevertrue;
    21 };
    2283
    23 struct pp_entry *pp_lookup(char *ident);
    24 void set_define(char *name);
     84/*
     85 * If logic
     86 */
     87#define MAXIFSTACK      64      /* If this isn't enough you should alter the source... */
     88
     89typedef enum {
     90        if_false,
     91        if_true,
     92        if_elif,
     93        if_elsefalse,
     94        if_elsetrue,
     95        if_ignore
     96} if_state_t;
     97
     98/*
     99 * I assume that 'long long' exists in the compiler when it has a size
     100 * of 8 or bigger. If not, then we revert to a simple 'long' for now.
     101 * This should prevent most unexpected things with other compilers than
     102 * gcc and egcs for now.
     103 * In the future it should be possible to use another way, like a
     104 * structure, so that we can emulate the MS compiler.
     105 */
     106#if defined(SIZEOF_LONGLONG) && SIZEOF_LONGLONG >= 8
     107typedef long long wrc_sll_t;
     108typedef unsigned long long wrc_ull_t;
     109#else
     110typedef long wrc_sll_t;
     111typedef unsigned long wrc_ull_t;
     112#endif
     113
     114#define SIZE_CHAR       1
     115#define SIZE_SHORT      2
     116#define SIZE_INT        3
     117#define SIZE_LONG       4
     118#define SIZE_LONGLONG   5
     119#define SIZE_MASK       0x00ff
     120#define FLAG_SIGNED     0x0100
     121
     122typedef enum {
     123#if 0
     124        cv_schar  = SIZE_CHAR + FLAG_SIGNED,
     125        cv_uchar  = SIZE_CHAR,
     126        cv_sshort = SIZE_SHORT + FLAG_SIGNED,
     127        cv_ushort = SIZE_SHORT,
     128#endif
     129        cv_sint   = SIZE_INT + FLAG_SIGNED,
     130        cv_uint   = SIZE_INT,
     131        cv_slong  = SIZE_LONG + FLAG_SIGNED,
     132        cv_ulong  = SIZE_LONG,
     133        cv_sll    = SIZE_LONGLONG + FLAG_SIGNED,
     134        cv_ull    = SIZE_LONGLONG
     135} ctype_t;
     136
     137typedef struct cval {
     138        ctype_t type;
     139        union {
     140#if 0
     141                signed char     sc;     /* Explicitely signed because compilers are stupid */
     142                unsigned char   uc;
     143                short           ss;
     144                unsigned short  us;
     145#endif
     146                int             si;
     147                unsigned int    ui;
     148                long            sl;
     149                unsigned long   ul;
     150                wrc_sll_t       sll;
     151                wrc_ull_t       ull;
     152        } val;
     153} cval_t;
     154
     155
     156
     157pp_entry_t *pplookup(char *ident);
     158pp_entry_t *add_define(char *def, char *text);
     159pp_entry_t *add_cmdline_define(char *set);
     160pp_entry_t *add_special_define(char *id);
     161pp_entry_t *add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
    25162void del_define(char *name);
    26 void add_define(char *text);
    27 void add_cmdline_define(char *set);
    28 FILE *open_include(const char *name, int search);
     163FILE *open_include(const char *name, int search, char **newpath);
    29164void add_include_path(char *path);
    30 void push_if(int truecase, int wastrue, int nevertrue);
    31 int pop_if(void);
    32 int isnevertrue_if(void);
     165void push_if(if_state_t s);
     166void next_if_state(int);
     167if_state_t pop_if(void);
     168if_state_t if_state(void);
     169int get_if_depth(void);
     170
     171/*
     172 * From ppl.l
     173 */
     174extern FILE *ppin;
     175extern FILE *ppout;
     176extern char *pptext;
     177extern int pp_flex_debug;
     178int pplex(void);
     179
     180void do_include(char *fname, int type);
     181void push_ignore_state(void);
     182void pop_ignore_state(void);
     183
     184extern int include_state;
     185extern char *include_ppp;
     186extern char *include_filename;
     187extern int include_ifdepth;
     188extern int seen_junk;
     189extern includelogicentry_t *includelogiclist;
     190
     191/*
     192 * From ppy.y
     193 */
     194int ppparse(void);
     195extern int ppdebug;
    33196
    34197#endif
  • trunk/tools/wrc/readres.c

    r882 r5522  
    3131        DWORD   version;        /* 0 */
    3232        DWORD   characts;       /* 0 */
    33 } emptyheader = {0, 0x20, 0xffff, 0, 0xffff, 0, 0, 0, 0, 0, 0};
     33} emptyheader           = {0, 0x20, 0xffff, 0, 0xffff, 0, 0, 0, 0, 0, 0},
     34  emptyheaderSWAPPED    = {0, BYTESWAP_DWORD(0x20), 0xffff, 0, 0xffff, 0, 0, 0, 0, 0, 0};
    3435
    3536/*
     
    6566int read_data(FILE *fp, size_t size, void *buf)
    6667{
    67         int r;
     68        unsigned int r;
    6869        int pos = ftell(fp);
    6970        r = fread(buf, 1, size, fp);
     
    136137#define get_dword(idx)  (*((DWORD *)(&res->data[idx])))
    137138
    138 resource_t *read_res32(FILE *fp)
     139static resource_t *read_res32(FILE *fp)
    139140{
    140141        static char wrong_format[] = "Wrong resfile format (32bit)";
     
    312313 *****************************************************************************
    313314*/
    314 resource_t *read_res16(FILE *fp)
     315static resource_t *read_res16(FILE *fp)
    315316{
    316317        internal_error(__FILE__, __LINE__, "Can't yet read 16 bit .res files");
     
    332333        FILE *fp;
    333334        struct resheader32 rh;
    334         int is32bit;
     335        int is32bit = 1;
    335336        resource_t *top;
    336337
     
    346347                if(!memcmp(&emptyheader, &rh, sizeof(rh)))
    347348                        is32bit = 1;
     349                else if(!memcmp(&emptyheaderSWAPPED, &rh, sizeof(rh)))
     350                        error("Binary .res-file has its byteorder swapped");
    348351                else
    349352                        is32bit = 0;
Note: See TracChangeset for help on using the changeset viewer.