Merge 13511:13830 from trunk
authorCasper Hornstrup <chorns@users.sourceforge.net>
Sat, 5 Mar 2005 20:50:25 +0000 (20:50 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Sat, 5 Mar 2005 20:50:25 +0000 (20:50 +0000)
svn path=/branches/xmlbuildsystem/; revision=13833

62 files changed:
1  2 
reactos/Makefile
reactos/bootdata/packages/reactos.dff
reactos/drivers/fs/np/create.c
reactos/drivers/fs/np/fsctrl.c
reactos/drivers/fs/np/npfs.h
reactos/drivers/fs/np/rw.c
reactos/lib/crt/crt.xml
reactos/lib/crt/ctype/isalnum.c
reactos/lib/crt/ctype/isascii.c
reactos/lib/crt/ctype/iscntrl.c
reactos/lib/crt/ctype/isctype.c
reactos/lib/crt/ctype/isgraph.c
reactos/lib/crt/ctype/isprint.c
reactos/lib/crt/ctype/ispunct.c
reactos/lib/crt/ctype/isupper.c
reactos/lib/crt/stdio/sprintf.c
reactos/lib/crt/stdio/swprintf.c
reactos/lib/crt/stdio/vsprintf.c
reactos/lib/crt/stdio/vswprintf.c
reactos/lib/crt/wine/scanf.c
reactos/lib/crtdll/crtdll.def
reactos/lib/crtdll/crtdll.xml
reactos/lib/crtdll/stdio/vsprintf.c
reactos/lib/directory.xml
reactos/lib/expat/Makefile
reactos/lib/expat/conftools/ac_c_bigendian_cross.m4
reactos/lib/expat/conftools/mkinstalldirs
reactos/lib/expat/expat.xml
reactos/lib/msvcrt/dllmain.c
reactos/lib/msvcrt/msvcrt.def
reactos/lib/msvcrt/msvcrt.xml
reactos/lib/oleaut32/oleaut32.xml
reactos/lib/rpcrt4/rpc_message.c
reactos/lib/setupapi/setupapi.xml
reactos/lib/shlwapi/shlwapi.xml
reactos/ntoskrnl/include/internal/io.h
reactos/ntoskrnl/io/cancel.c
reactos/ntoskrnl/io/iomgr.c
reactos/ntoskrnl/io/irp.c
reactos/ntoskrnl/io/remlock.c
reactos/ntoskrnl/kd/gdbstub.c
reactos/ntoskrnl/ntoskrnl.xml
reactos/ntoskrnl/ob/handle.c
reactos/ntoskrnl/ps/kill.c
reactos/subsys/csrss/csrss.xml
reactos/subsys/smss/smss.xml
reactos/subsys/system/directory.xml
reactos/subsys/system/explorer/explorer.xml
reactos/subsys/system/ibrowser/Makefile
reactos/subsys/system/ibrowser/ibrowser.xml
reactos/subsys/win32k/main/dllmain.c
reactos/subsys/win32k/win32k.xml
reactos/tools/Makefile
reactos/tools/buildno/Makefile
reactos/tools/buildno/buildno.cpp
reactos/tools/rbuild/backend/mingw/mingw.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/unicode/Makefile
reactos/tools/wpp/Makefile
reactos/tools/wrc/Makefile
reactos/tools/wrc/parser.y
reactos/tools/wrc/y.tab.c

 -# $Id$
 -#
 -# Global makefile
 -#
 -
 -PATH_TO_TOP = .
 -
 -include $(PATH_TO_TOP)/rules.mak
 -include $(PATH_TO_TOP)/config
 -
 -#
 -# Define to build ReactOS external targets
 -#
 -ifeq ($(ROS_BUILD_EXT),)
 -ROS_BUILD_EXT = no
 -else
 -ROS_BUILD_EXT = yes
 -endif
 -
 -ifneq ($(MINIMALDEPENDENCIES),no)
 -IMPLIB =
 -else
 -IMPLIB = implib
 +host_gcc = gcc
 +host_gpp = g++
 +host_ld = ld
 +host_ar = ar
 +host_objcopy = objcopy
 +ifeq ($(HOST),mingw32-linux)
 +      EXEPREFIX = ./
 +      EXEPOSTFIX =
 +      SEP = /
 +      nmkdir = mkdir -p
 +      gcc = mingw32-gcc
 +      gpp = mingw32-g++
 +      ld = mingw32-ld
 +      ar = mingw32-ar
 +      objcopy = mingw32-objcopy
 +      dlltool = mingw32-dlltool
 +      windres = mingw32-windres
 +      rm = rm -f
 +      cp = cp
 +      NUL = /dev/null
 +else # mingw32-windows
 +      EXEPREFIX =
 +      EXEPOSTFIX = .exe
 +      SEP = \$(EMPTY_VAR)
 +      nmkdir = mkdir
 +      gcc = gcc
 +      gpp = g++
 +      ld = ld
 +      ar = ar
 +      objcopy = objcopy
 +      dlltool = dlltool
 +      windres = windres
 +      rm = del /f /q
 +      cp = copy /y
 +      NUL = NUL
  endif
  
 -# Boot loaders
 -BOOT_LOADERS = freeldr
 -
 -# Required to run the system
 -COMPONENTS = ntoskrnl
 -
 -# Hardware Abstraction Layers
 -# halx86
 -HALS = halx86/up halx86/mp
 -
 -# Bus drivers
 -# acpi isapnp pci
 -BUS = acpi isapnp pci
 -
 -# Filesystem libraries
 -# vfatlib
 -LIB_FSLIB = vfatlib
 -
 -# libunicode, must be empty!
 -LIBUNICODE = 
 -
 -# Static libraries
 -LIB_STATIC = string rosrtl epsapi uuid libwine zlib rtl tgetopt pseh adns dxguid strmiids crt rossym wdmguid
 -
 -# Keyboard layout libraries
 -DLLS_KBD = kbdda kbddv kbdes kbdfr kbdgr kbdse kbduk kbdus
 -
 -# Control Panels
 -DLLS_CPL = cpl
 -
 -# Shell extensions
 -DLLS_SHELLEXT = shellext
 -
 -# User mode libraries
 -# libpcap packet epsapi
 -DLLS = acledit aclui advapi32 advpack cabinet cards comctl32 crtdll comdlg32 d3d8thk dbghelp expat fmifs freetype \
 -      gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 lzexpand mesa32 midimap mmdrv mpr msacm msafd \
 -      msgina msi msimg32 msvcrt20 msvideo mswsock netapi32 ntdll ole32 oleaut32 oledlg olepro32 opengl32 \
 -      packet psapi riched20 richedit rpcrt4 samlib secur32 setupapi shell32 shlwapi smdll snmpapi syssetup \
 -      twain user32 userenv version wininet winmm winspool ws2help ws2_32 wsock32 wshirda dnsapi \
 -      urlmon shdocvw dinput dinput8 dxdiagn devenum dsound lsasrv $(DLLS_KBD) $(DLLS_CPL) $(DLLS_SHELLEXT)
 -
 -SUBSYS = smss win32k csrss ntvdm
 -
 -#
 -# Select the server(s) you want to build
 -#
 -#SERVERS = posix linux os2
 -SERVERS = win32
 -
 -# Driver support libraries
 -#bzip2 zlib oskittcp
 -DRIVERS_LIB = bzip2 oskittcp ip csq
 +.PHONY: all
 +.PHONY: clean
  
 -# Kernel mode device drivers
 -# Obsolete: ide
 -# beep blue floppy null parallel ramdrv serenum serial
 -DEVICE_DRIVERS = beep blue debugout null serial bootvid
 +all: Makefile.auto
  
 -# Kernel mode input drivers
 -INPUT_DRIVERS = keyboard mouclass psaux sermouse
 -
 -# Kernel mode file system drivers
 -# cdfs ext2 fs_rec ms np vfat
 -FS_DRIVERS = cdfs fs_rec ms np vfat mup ntfs
 -
 -# Kernel mode networking drivers
 -# afd ndis npf tcpip tdi wshtcpip
 -NET_DRIVERS = afd ndis npf tcpip tdi wshtcpip
 -
 -# Kernel mode networking device drivers
 -# ne2000 pcnet
 -NET_DEVICE_DRIVERS = ne2000 pcnet
 -
 -# Kernel mode storage drivers
 -# atapi cdrom class2 disk scsiport
 -STORAGE_DRIVERS = atapi cdrom class2 disk floppy scsiport diskdump
 -
 -# System applications
 -# autochk cmd format services setup usetup welcome winlogon msiexec 
 -SYS_APPS = autochk calc cmd explorer expand format ibrowser msiexec regsvr32 \
 -  reporterror services setup taskmgr userinit usetup welcome vmwinst rundll32 \
 -  winlogon regedit winefile notepad reactos lsass
 -
 -# System services
 -SYS_SVC = rpcss eventlog umpnpmgr
 -
 -APPS = testsets utils
 -
 -
 -# External modules and (sub)systems for ReactOS
 -# rosapps posix os2 (requires c++) java (non-existant)
 -EXTERNALS = rosapps
 -
 -ifeq ($(ROS_BUILD_EXT),yes)
 -EXT_MODULES = $(EXTERNALS)
 -else
 -EXT_MODULES =
 +ifneq ($(ROS_INTERMEDIATE),)
 +$(ROS_INTERMEDIATE)tools: $(ROS_INTERMEDIATE)
 +      ${nmkdir} $(ROS_INTERMEDIATE)tools
  endif
  
 -KERNEL_DRIVERS = $(DRIVERS_LIB) $(DEVICE_DRIVERS) $(INPUT_DRIVERS) $(FS_DRIVERS) \
 -      $(NET_DRIVERS) $(NET_DEVICE_DRIVERS) $(STORAGE_DRIVERS) VIDEO_DRIVERS USB_DRIVERS
 -
 -# Regression tests
 -REGTESTS = regtests
 -
 -all: bootstrap $(BOOT_LOADERS) $(COMPONENTS) $(REGTESTS) $(HALS) $(BUS) $(LIB_FSLIB) \
 -     $(DLLS) $(SUBSYS) $(KERNEL_DRIVERS) $(SYS_APPS) $(SYS_SVC) $(APPS) $(EXT_MODULES)
 -
 -bootstrap: dk implib iface_native
 -
 -depends: $(LIB_STATIC:%=%_depends) $(LIB_FSLIB:%=%_depends) msvcrt_depends $(DLLS:%=%_depends) \
 -         $(SUBSYS:%=%_depends) $(SYS_SVC:%=%_depends) \
 -         $(EXT_MODULES:%=%_depends) $(POSIX_LIBS:%=%_depends)
 -
 -implib: hallib $(LIB_STATIC) $(LIB_FSLIB) $(COMPONENTS:%=%_implib) $(HALS:%=%_implib) \
 -        $(BUS:%=%_implib) $(LIB_STATIC:%=%_implib) $(LIB_FSLIB:%=%_implib) \
 -        msvcrt_implib $(DLLS:%=%_implib) $(KERNEL_DRIVERS:%=%_implib) \
 -        $(SUBSYS:%=%_implib) $(SYS_APPS:%=%_implib) $(SYS_SVC:%=%_implib) \
 -        $(EXT_MODULES:%=%_implib) $(REGTESTS:%=%_implib)
 -
 -test: $(BOOT_LOADERS:%=%_test) $(COMPONENTS:%=%_test) $(HALS:%=%_test) $(BUS:%=%_test) \
 -          $(LIB_STATIC:%=%_test) $(LIB_FSLIB:%=%_test) msvcrt_test $(DLLS:%=%_test) \
 -          $(KERNEL_DRIVERS:%=%_test) $(SUBSYS:%=%_test) \
 -          $(SYS_SVC:%=%_test) $(EXT_MODULES:%=%_test)
 -
 -clean: tools dk_clean iface_native_clean hallib_clean \
 -       $(BOOT_LOADERS:%=%_clean) $(HALS:%=%_clean) $(COMPONENTS:%=%_clean) \
 -       $(BUS:%=%_clean) $(LIB_STATIC:%=%_clean) $(LIB_FSLIB:%=%_clean) \
 -       msvcrt_clean $(DLLS:%=%_clean) $(KERNEL_DRIVERS:%=%_clean) \
 -       $(SUBSYS:%=%_clean) $(SYS_APPS:%=%_clean) $(SYS_SVC:%=%_clean) \
 -       $(NET_APPS:%=%_clean) $(APPS:%=%_clean) $(EXT_MODULES:%=%_clean) \
 -       $(REGTESTS:%=%_clean) clean_after tools_clean
 -
 -clean_after:
 -      $(HALFVERBOSEECHO) [RM]      /include/roscfg.h
 -      $(RM) $(PATH_TO_TOP)/include/roscfg.h
 -
 -fastinstall: tools install_dirs install_before $(COMPONENTS:%=%_install) $(HALS:%=%_install) \
 -         $(BUS:%=%_install) $(LIB_STATIC:%=%_install) $(LIB_FSLIB:%=%_install) \
 -         msvcrt_install $(DLLS:%=%_install) $(KERNEL_DRIVERS:%=%_install) \
 -         $(SUBSYS:%=%_install) $(SYS_APPS:%=%_install) $(SYS_SVC:%=%_install) \
 -         $(APPS:%=%_install) $(EXT_MODULES:%=%_install) $(REGTESTS:%=%_install)
 -install: fastinstall registry
 -
 -FREELDR_DIR = boot/freeldr
 -
 -bootcd_directory_layout:
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(BOOTCD_DIR)
 -      $(RMKDIR) $(BOOTCD_DIR)
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(BOOTCD_DIR)/bootdisk
 -      $(RMKDIR) $(BOOTCD_DIR)/bootdisk
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(BOOTCD_DIR)/loader
 -      $(RMKDIR) $(BOOTCD_DIR)/loader
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(BOOTCD_DIR)/reactos
 -      $(RMKDIR) $(BOOTCD_DIR)/reactos
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(BOOTCD_DIR)/reactos/system32
 -      $(RMKDIR) $(BOOTCD_DIR)/reactos/system32
 -
 -bootcd_bootstrap_files: $(BOOT_LOADERS:%=%_bootcd) $(COMPONENTS:%=%_bootcd) \
 -      $(HALS:%=%_bootcd) $(BUS:%=%_bootcd) $(LIB_STATIC:%=%_bootcd) \
 -      $(LIB_FSLIB:%=%_bootcd) msvcrt_bootcd $(DLLS:%=%_bootcd) \
 -      $(KERNEL_DRIVERS:%=%_bootcd) $(SUBSYS:%=%_bootcd) $(SYS_APPS:%=%_bootcd)
 -
 -bootcd_install_before:
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/autorun.inf to $(BOOTCD_DIR)/autorun.inf
 -      $(RLINE) bootdata/autorun.inf $(BOOTCD_DIR)/autorun.inf
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/readme.txt to $(BOOTCD_DIR)/readme.txt
 -      $(RLINE) bootdata/readme.txt $(BOOTCD_DIR)/readme.txt
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/hivecls.inf to $(BOOTCD_DIR)/reactos/hivecls.inf
 -      $(RLINE) bootdata/hivecls.inf $(BOOTCD_DIR)/reactos/hivecls.inf
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/hivedef.inf to $(BOOTCD_DIR)/reactos/hivedef.inf
 -      $(RLINE) bootdata/hivedef.inf $(BOOTCD_DIR)/reactos/hivedef.inf
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/hivesft.inf to $(BOOTCD_DIR)/reactos/hivesft.inf
 -      $(RLINE) bootdata/hivesft.inf $(BOOTCD_DIR)/reactos/hivesft.inf
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/hivesys.inf to $(BOOTCD_DIR)/reactos/hivesys.inf
 -      $(RLINE) bootdata/hivesys.inf $(BOOTCD_DIR)/reactos/hivesys.inf
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/txtsetup.sif to $(BOOTCD_DIR)/reactos/txtsetup.sif
 -      $(RLINE) bootdata/txtsetup.sif $(BOOTCD_DIR)/reactos/txtsetup.sif
 -      $(HALFVERBOSEECHO) [COPY]    bootdata/icon.ico to $(BOOTCD_DIR)/icon.ico
 -      $(CP) bootdata/icon.ico $(BOOTCD_DIR)/icon.ico
 -      $(HALFVERBOSEECHO) [COPY]    subsys/system/welcome/welcome.exe  to $(BOOTCD_DIR)/reactos/welcome.exe
 -      $(CP) subsys/system/welcome/welcome.exe $(BOOTCD_DIR)/reactos/welcome.exe
 -      $(HALFVERBOSEECHO) [COPY]    subsys/system/reactos/reactos.exe  to $(BOOTCD_DIR)/reactos/reactos.exe
 -      $(CP) subsys/system/reactos/reactos.exe $(BOOTCD_DIR)/reactos/reactos.exe
 -      $(HALFVERBOSEECHO) [COPY]    media/nls/c_1252.nls to $(BOOTCD_DIR)/reactos/c_1252.nls
 -      $(CP) media/nls/c_1252.nls $(BOOTCD_DIR)/reactos/c_1252.nls
 -      $(HALFVERBOSEECHO) [COPY]    media/nls/c_437.nls to $(BOOTCD_DIR)/reactos/c_437.nls
 -      $(CP) media/nls/c_437.nls $(BOOTCD_DIR)/reactos/c_437.nls
 -      $(HALFVERBOSEECHO) [COPY]    media/nls/l_intl.nls to $(BOOTCD_DIR)/reactos/l_intl.nls
 -      $(CP) media/nls/l_intl.nls $(BOOTCD_DIR)/reactos/l_intl.nls
 -      $(HALFVERBOSEECHO) [COPY]    media/drivers/etc/services to $(BOOTCD_DIR)/reactos/services
 -      $(CP) media/drivers/etc/services $(BOOTCD_DIR)/reactos/services
 -
 -bootcd_basic: bootcd_directory_layout bootcd_bootstrap_files bootcd_install_before
 -
 -bootcd_makecd:
 -      $(CABMAN) /C bootdata/packages/reactos.dff /L $(BOOTCD_DIR)/reactos /I
 -      $(CABMAN) /C bootdata/packages/reactos.dff /RC $(BOOTCD_DIR)/reactos/reactos.inf /L $(BOOTCD_DIR)/reactos /N
 -      - $(RM) $(BOOTCD_DIR)/reactos/reactos.inf
 -      $(HALFVERBOSEECHO) [CDMAKE]  ReactOS.iso
 -      $(CDMAKE) -v -m -b $(BOOTCD_DIR)/../isoboot.bin $(BOOTCD_DIR) REACTOS ReactOS.iso
 -
 -ubootcd_unattend:
 -      $(HALFVERBOSEECHO) [COPY]    bootdata/unattend.inf to $(BOOTCD_DIR)/reactos/unattend.inf
 -      $(CP) bootdata/unattend.inf $(BOOTCD_DIR)/reactos/unattend.inf
 -
 -livecd_directory_layout:
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)
 -      $(RMKDIR) $(LIVECD_DIR)
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)/loader
 -      $(RMKDIR) $(LIVECD_DIR)/loader
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)/reactos
 -      $(RMKDIR) $(LIVECD_DIR)/reactos
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)/Profiles/All\ Users/Desktop
 -      $(RMKDIR) $(LIVECD_DIR)/Profiles/All\ Users/Desktop
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)/Profiles/Default\ User/Desktop
 -      $(RMKDIR) $(LIVECD_DIR)/Profiles/Default\ User/Desktop
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(LIVECD_DIR)/Profiles/Default\ User/My\ Documents
 -      $(RMKDIR) $(LIVECD_DIR)/Profiles/Default\ User/My\ Documents
 -      $(HALFVERBOSEECHO) [COPY]    ${FREELDR_DIR}/bootsect/isoboot.bin to ${LIVECD_DIR}/../isoboot.bin
 -      $(CP) ${FREELDR_DIR}/bootsect/isoboot.bin ${LIVECD_DIR}/../isoboot.bin
 -      $(HALFVERBOSEECHO) [COPY]    ${FREELDR_DIR}/freeldr/freeldr.sys to ${LIVECD_DIR}/loader/setupldr.sys
 -      $(CP) ${FREELDR_DIR}/freeldr/freeldr.sys ${LIVECD_DIR}/loader/setupldr.sys
 -      $(HALFVERBOSEECHO) [RLINE]   bootdata/livecd.ini to $(LIVECD_DIR)/freeldr.ini
 -      $(RLINE) bootdata/livecd.ini $(LIVECD_DIR)/freeldr.ini
 -
 -livecd_bootstrap_files:
 -      $(MAKE) LIVECD_INSTALL=yes fastinstall
 -
 -livecd_install_before:
 -      $(MKHIVE) bootdata $(LIVECD_DIR)/reactos/system32/config bootdata/livecd.inf bootdata/hiveinst.inf
 -
 -livecd_basic: livecd_directory_layout livecd_bootstrap_files livecd_install_before
 -
 -livecd_makecd:
 -      $(HALFVERBOSEECHO) [CDMAKE]  roslive.iso
 -      $(CDMAKE) -m -j -b $(LIVECD_DIR)/../isoboot.bin $(LIVECD_DIR) REACTOS roslive.iso
 -
 -bootcd: bootcd_basic bootcd_makecd
 -
 -ubootcd: bootcd_basic ubootcd_unattend bootcd_makecd
 -
 -livecd: livecd_basic livecd_makecd
 -
 -registry: tools
 -      $(MKHIVE) bootdata $(INSTALL_DIR)/system32/config bootdata/hiveinst.inf
 -
 -.PHONY: all bootstrap depends implib test clean clean_before install bootcd_directory_layout \
 -bootcd_bootstrap_files bootcd_install_before bootcd_basic bootcd_makecd ubootcd_unattend bootcd
 -
 -
 -#
 -# Boot Loaders
 -#
 -$(BOOT_LOADERS): %:
 -      $(MAKE) -C boot/$*
 -
 -$(BOOT_LOADERS:%=%_test): %_test:
 -      $(MAKE) -C boot/$* test
 -
 -$(BOOT_LOADERS:%=%_clean): %_clean:
 -      $(MAKE) -C boot/$* clean
 -
 -$(BOOT_LOADERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C boot/$* bootcd
 -
 -.PHONY: $(BOOT_LOADERS) $(BOOT_LOADERS:%=%_test) $(BOOT_LOADERS:%=%_clean) \
 -        $(BOOT_LOADERS:%=%_bootcd)
 -
 -$(COMPONENTS): dk
 -
 -#
 -# System Applications
 -#
 -$(SYS_APPS): %: $(IMPLIB)
 -      $(MAKE) -C subsys/system/$*
 -
 -$(SYS_APPS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C subsys/system/$* implib
 -
 -$(SYS_APPS:%=%_test): %_test:
 -      $(MAKE) -C subsys/system/$* test
 -
 -$(SYS_APPS:%=%_clean): %_clean:
 -      $(MAKE) -C subsys/system/$* clean
 -
 -$(SYS_APPS:%=%_install): %_install:
 -      $(MAKE) -C subsys/system/$* install
 -
 -$(SYS_APPS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C subsys/system/$* bootcd
 -
 -.PHONY: $(SYS_APPS) $(SYS_APPS:%=%_implib) $(SYS_APPS:%=%_test) \
 -  $(SYS_APPS:%=%_clean) $(SYS_APPS:%=%_install) $(SYS_APPS:%=%_bootcd)
 -
 -#
 -# System Services
 -#
 -$(SYS_SVC): %: $(IMPLIB)
 -      $(MAKE) -C services/$*
 -
 -$(SYS_SVC:%=%_depends): %_depends:
 -      $(MAKE) -C services/$* depends
 -
 -$(SYS_SVC:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C services/$* implib
 -
 -$(SYS_SVC:%=%_test): %_test:
 -      $(MAKE) -C services/$* test
 -
 -$(SYS_SVC:%=%_clean): %_clean:
 -      $(MAKE) -C services/$* clean
 -
 -$(SYS_SVC:%=%_install): %_install:
 -      $(MAKE) -C services/$* install
 -
 -.PHONY: $(SYS_SVC) $(SYS_SVC:%=%_depends) $(SYS_SVC:%=%_implib) \
 -  $(SYS_SVC:%=%_test) $(SYS_SVC:%=%_clean) $(SYS_SVC:%=%_install)
 -
 -
 -#
 -# Applications
 -#
 -#
 -# Extra (optional system) Applications
 -#
 -$(APPS): %: $(IMPLIB)
 -      $(MAKE) -C apps/$*
 -
 -# Not needed
 -# $(APPS:%=%_implib): %_implib: dk
 -#     $(MAKE) --silent -C apps/$* implib
 -
 -$(APPS:%=%_test): %_test:
 -      $(MAKE) -C apps/$* test
 -
 -$(APPS:%=%_clean): %_clean:
 -      $(MAKE) -C apps/$* clean
 -
 -$(APPS:%=%_install): %_install:
 -      $(MAKE) -C apps/$* install
 -
 -.PHONY: $(APPS) $(APPS:%=%_test) $(APPS:%=%_clean) $(APPS:%=%_install)
 -
 -
 -#
 -# External ports and subsystem personalities
 -#
 -$(EXTERNALS): %:
 -      $(MAKE) -C $(ROOT_PATH)/$*
 -
 -$(EXTERNALS:%=%_depends): %_depends:
 -      $(MAKE) -C $(ROOT_PATH)/$* depends
 -
 -$(EXTERNALS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C $(ROOT_PATH)/$* implib
 -
 -$(EXTERNALS:%=%_clean): %_clean:
 -      $(MAKE) -C $(ROOT_PATH)/$* clean
 -
 -$(EXTERNALS:%=%_install): %_install:
 -      $(MAKE) -C $(ROOT_PATH)/$* install
 -
 -.PHONY: $(EXTERNALS) $(EXTERNALS:%=%_depends) $(EXTERNALS:%=%_implib) $(EXTERNALS:%=%_clean) $(EXTERNALS:%=%_install)
 -
 -
 -#
 -# Tools
 -#
 -tools:
 -      $(MAKE) --silent -C tools
 -
 -tools_implib:
 -      
 -
 -tools_test:
 -      
 -
 -tools_clean:
 -      $(MAKE) -C tools clean
 -
 -tools_install:
 -
 -.PHONY: tools tools_implib tools_test tools_clean tools_install
 -
 -
 -#
 -# Developer Kits
 -#
 -dk: tools
 -      @$(RMKDIR) $(DK_PATH)
 -      @$(RMKDIR) $(DDK_PATH)
 -      @$(RMKDIR) $(DDK_PATH_LIB)
 -      @$(RMKDIR) $(DDK_PATH_INC)
 -      @$(RMKDIR) $(SDK_PATH)
 -      @$(RMKDIR) $(SDK_PATH_LIB)
 -      @$(RMKDIR) $(SDK_PATH_INC)
 -      @$(RMKDIR) $(XDK_PATH)
 -      @$(RMKDIR) $(XDK_PATH_LIB)
 -#     @$(RMKDIR) $(XDK_PATH_INC)
 -
 -dk_implib:
 -
 -# WARNING! Be very sure that there are no important files
 -#          in these directories before cleaning them!!!
 -dk_clean:
 -      $(HALFVERBOSEECHO) [RM]      $(DDK_PATH_LIB)/*.a
 -      $(RM) $(DDK_PATH_LIB)/*.a
 -#     $(HALFVERBOSEECHO) [RM]      $(DDK_PATH_INC)/*.h
 -#     $(RM) $(DDK_PATH_INC)/*.h
 -      $(HALFVERBOSEECHO) [RMDIR]   $(DDK_PATH_LIB)
 -      $(RMDIR) $(DDK_PATH_LIB)
 -#     $(HALFVERBOSEECHO) [RMDIR]   $(DDK_PATH_INC)
 -#     $(RMDIR) $(DDK_PATH_INC)
 -      $(HALFVERBOSEECHO) [RM]      $(SDK_PATH_LIB)/*.a
 -      $(RM) $(SDK_PATH_LIB)/*.a
 -#     $(HALFVERBOSEECHO) [RM]      $(SDK_PATH_INC)/*.h
 -#     $(RM) $(SDK_PATH_INC)/*.h
 -      $(HALFVERBOSEECHO) [RMDIR]   $(SDK_PATH_LIB)
 -      $(RMDIR) $(SDK_PATH_LIB)
 -#     $(HALFVERBOSEECHO) [RMDIR]   $(SDK_PATH_INC)
 -#     $(RMDIR) $(SDK_PATH_INC)
 -      $(HALFVERBOSEECHO) [RM]      $(XDK_PATH_LIB)/*.a
 -      $(RM) $(XDK_PATH_LIB)/*.a
 -#     $(HALFVERBOSEECHO) [RM]      $(XDK_PATH_INC)/*.h
 -#     $(RM) $(XDK_PATH_INC)/*.h
 -      $(HALFVERBOSEECHO) [RMDIR]   $(XDK_PATH_LIB)
 -      $(RMDIR) $(XDK_PATH_LIB)
 -#     $(HALFVERBOSEECHO) [RMDIR]   $(XDK_PATH_INC)
 -#     $(RMDIR) $(XDK_PATH_INC)
 -
 -dk_install:
 -
 -.PHONY: dk dk_implib dk_clean dk_install
 -
 -
 -#
 -# Interfaces
 -#
 -iface_native:
 -      $(MAKE) --silent -C tools/nci
 -
 -iface_native_implib:
 -      
 -iface_native_test:
 -      
 -iface_native_clean:
 -      $(MAKE) --silent -C tools/nci clean
 -
 -iface_native_install:
 -
 -iface_native_bootcd:
 -
 -.PHONY: iface_native iface_native_implib iface_native_test iface_native_clean \
 -        iface_native_install iface_native_bootcd
 -
 -
 -#
 -# Bus driver rules
 -#
 -$(BUS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/bus/$*
 -
 -$(BUS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/bus/$* implib
 -
 -$(BUS:%=%_test): %_test:
 -      $(MAKE) -C drivers/bus/$* test
 -
 -$(BUS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/bus/$* clean
 -
 -$(BUS:%=%_install): %_install:
 -      $(MAKE) -C drivers/bus/$* install
 -
 -$(BUS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/bus/$* bootcd
 -
 -.PHONY: $(BUS) $(BUS:%=%_implib) $(BUS:%=%_clean) \
 -        $(BUS:%=%_install) $(BUS:%=%_bootcd)
 -
 -
 -#
 -# Driver support libraries rules
 -#
 -$(DRIVERS_LIB): %: $(IMPLIB)
 -      $(MAKE) -C drivers/lib/$*
 -
 -$(DRIVERS_LIB:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/lib/$* implib
 -
 -$(DRIVERS_LIB:%=%_test): %_test:
 -      $(MAKE) -C drivers/lib/$* test
 -
 -$(DRIVERS_LIB:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/lib/$* clean
 -
 -$(DRIVERS_LIB:%=%_install): %_install:
 -      $(MAKE) -C drivers/lib/$* install
 -
 -$(DRIVERS_LIB:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/lib/$* bootcd
 -
 -.PHONY: $(DRIVERS_LIB) $(DRIVERS_LIB:%=%_implib) $(DRIVERS_LIB:%=%_test) \
 -        $(DRIVERS_LIB:%=%_clean) $(DRIVERS_LIB:%=%_install) $(DRIVERS_LIB:%=%_bootcd)
 -
 -
 -#
 -# Device driver rules
 -#
 -$(DEVICE_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/dd/$*
 -
 -$(DEVICE_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/dd/$* implib
 -
 -$(DEVICE_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/dd/$* test
 -
 -$(DEVICE_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/dd/$* clean
 -
 -$(DEVICE_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/dd/$* install
 -
 -$(DEVICE_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/dd/$* bootcd
 -
 -.PHONY: $(DEVICE_DRIVERS) $(DEVICE_DRIVERS:%=%_implib) $(DEVICE_DRIVERS:%=%_test) \
 -        $(DEVICE_DRIVERS:%=%_clean) $(DEVICE_DRIVERS:%=%_install) $(DEVICE_DRIVERS:%=%_bootcd)
 -
 -
 -#
 -# Video device driver rules
 -#
 -VIDEO_DRIVERS: $(IMPLIB)
 -      $(MAKE) -C drivers/video
 -
 -VIDEO_DRIVERS_implib: dk
 -      $(MAKE) --silent -C drivers/video implib
 -
 -VIDEO_DRIVERS_test:
 -      $(MAKE) -C drivers/video test
 -
 -VIDEO_DRIVERS_clean:
 -      $(MAKE) -C drivers/video clean
 -
 -VIDEO_DRIVERS_install:
 -      $(MAKE) -C drivers/video install
 -
 -VIDEO_DRIVERS_bootcd:
 -      $(MAKE) -C drivers/video bootcd
 -
 -.PHONY: VIDEO_DRIVERS VIDEO_DRIVERS_implib VIDEO_DRIVERS_test\
 -        VIDEO_DRIVERS_clean VIDEO_DRIVERS_install VIDEO_DRIVERS_bootcd
 -
 -#
 -# USB device driver rules
 -#
 -USB_DRIVERS: $(IMPLIB)
 -      $(MAKE) -C drivers/usb
 -
 -USB_DRIVERS_implib: dk
 -      $(MAKE) --silent -C drivers/usb implib
 -
 -USB_DRIVERS_test:
 -      $(MAKE) -C drivers/usb test
 -
 -USB_DRIVERS_clean:
 -      $(MAKE) -C drivers/usb clean
 -
 -USB_DRIVERS_install:
 -      $(MAKE) -C drivers/usb install
 -
 -USB_DRIVERS_bootcd:
 -      $(MAKE) -C drivers/usb bootcd
 -
 -.PHONY: USB_DRIVERS USB_DRIVERS_implib USB_DRIVERS_test\
 -        USB_DRIVERS_clean USB_DRIVERS_install USB_DRIVERS_bootcd
 -
 -
 -#
 -# Input driver rules
 -#
 -$(INPUT_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/input/$*
 -
 -$(INPUT_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/input/$* implib
 -
 -$(INPUT_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/input/$* test
 -
 -$(INPUT_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/input/$* clean
 -
 -$(INPUT_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/input/$* install
 -
 -$(INPUT_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/input/$* bootcd
 -
 -.PHONY: $(INPUT_DRIVERS) $(INPUT_DRIVERS:%=%_implib) $(INPUT_DRIVERS:%=%_test) \
 -        $(INPUT_DRIVERS:%=%_clean) $(INPUT_DRIVERS:%=%_install) $(INPUT_DRIVERS:%=%_bootcd)
 -
 -#
 -# Filesystem driver rules
 -#
 -$(FS_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/fs/$*
 -
 -$(FS_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/fs/$* implib
 -
 -$(FS_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/fs/$* test
 -
 -$(FS_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/fs/$* clean
 -
 -$(FS_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/fs/$* install
 -
 -$(FS_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/fs/$* bootcd
 -
 -.PHONY: $(FS_DRIVERS) $(FS_DRIVERS:%=%_implib) $(FS_DRIVERS:%=%_test) \
 -        $(FS_DRIVERS:%=%_clean) $(FS_DRIVERS:%=%_install) $(FS_DRIVERS:%=%_bootcd)
 -
 -
 -#
 -# Network driver rules
 -#
 -$(NET_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/net/$*
 -
 -$(NET_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/net/$* implib
 -
 -$(NET_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/net/$* test
 -
 -$(NET_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/net/$* clean
 -
 -$(NET_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/net/$* install
 -
 -$(NET_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/net/$* bootcd
 -
 -.PHONY: $(NET_DRIVERS) $(NET_DRIVERS:%=%_implib) $(NET_DRIVERS:%=%_test) \
 -        $(NET_DRIVERS:%=%_clean) $(NET_DRIVERS:%=%_install) $(NET_DRIVERS:%=%_bootcd)
 -
 -
 -#
 -# Network device driver rules
 -#
 -$(NET_DEVICE_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/net/dd/$*
 -
 -$(NET_DEVICE_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/net/dd/$* implib
 -
 -$(NET_DEVICE_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/net/dd/$* test
 -
 -$(NET_DEVICE_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/net/dd/$* clean
 -
 -$(NET_DEVICE_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/net/dd/$* install
 -
 -$(NET_DEVICE_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/net/dd/$* bootcd
 -
 -.PHONY: $(NET_DEVICE_DRIVERS) $(NET_DEVICE_DRIVERS:%=%_clean) \
 -        $(NET_DEVICE_DRIVERS:%=%_implib) $(NET_DEVICE_DRIVERS:%=%_test) \
 -        $(NET_DEVICE_DRIVERS:%=%_install) $(NET_DEVICE_DRIVERS:%=%_bootcd)
 -
 -
 -#
 -# storage driver rules
 -#
 -$(STORAGE_DRIVERS): %: $(IMPLIB)
 -      $(MAKE) -C drivers/storage/$*
 -
 -$(STORAGE_DRIVERS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C drivers/storage/$* implib
 -
 -$(STORAGE_DRIVERS:%=%_test): %_test:
 -      $(MAKE) -C drivers/storage/$* test
 -
 -$(STORAGE_DRIVERS:%=%_clean): %_clean:
 -      $(MAKE) -C drivers/storage/$* clean
 -
 -$(STORAGE_DRIVERS:%=%_install): %_install:
 -      $(MAKE) -C drivers/storage/$* install
 -
 -$(STORAGE_DRIVERS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C drivers/storage/$* bootcd
 -
 -.PHONY: $(STORAGE_DRIVERS) $(STORAGE_DRIVERS:%=%_clean) \
 -        $(STORAGE_DRIVERS:%=%_implib) $(STORAGE_DRIVERS:%=%_test) \
 -        $(STORAGE_DRIVERS:%=%_install) $(STORAGE_DRIVERS:%=%_bootcd)
 -
 -
 -#
 -# Required system components
 -#
 -ntoskrnl: bootstrap
 -      $(MAKE) -C ntoskrnl
 -
 -ntoskrnl_implib: dk
 -      $(MAKE) --silent -C ntoskrnl implib
 -
 -ntoskrnl_test:
 -      $(MAKE) -C ntoskrnl test
 -
 -ntoskrnl_clean:
 -      $(MAKE) -C ntoskrnl clean
 -
 -ntoskrnl_install:
 -      $(MAKE) -C ntoskrnl install
 -
 -ntoskrnl_bootcd:
 -      $(MAKE) -C ntoskrnl bootcd
 -
 -.PHONY: ntoskrnl ntoskrnl_implib ntoskrnl_test \
 -        ntoskrnl_clean ntoskrnl_install ntoskrnl_bootcd
 -
 -
 -#
 -# Hardware Abstraction Layer import library
 -#
 -hallib: $(PATH_TO_TOP)/include/roscfg.h ntoskrnl_implib
 -      $(MAKE) --silent -C hal/hal
 -
 -hallib_implib: dk ntoskrnl_implib
 -      $(MAKE) --silent -C hal/hal implib
 -
 -hallib_test:
 -      $(MAKE) -C hal/hal test
 -
 -hallib_clean:
 -      $(MAKE) -C hal/hal clean
 -
 -hallib_install:
 -      $(MAKE) -C hal/hal install
 -
 -hallib_bootcd:
 -      $(MAKE) -C hal/hal bootcd
 -
 -.PHONY: hallib hallib_implib hallib_test hallib_clean \
 -        hallib_install hallib_bootcd
 -
 -
 -#
 -# Hardware Abstraction Layers
 -#
 -ifeq ($(CONFIG_SMP),1)
 -halx86: halx86/mp
 -else
 -halx86: halx86/up
 +ifneq ($(ROS_INTERMEDIATE),)
 +$(ROS_INTERMEDIATE):
 +      ${nmkdir} $(ROS_INTERMEDIATE)
  endif
  
 -$(HALS): %: $(IMPLIB)
 -      $(MAKE) -C hal/$*
 -
 -$(HALS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C hal/$* implib
 -
 -$(HALS:%=%_test): %_test:
 -      $(MAKE) -C hal/$* test
 -
 -$(HALS:%=%_clean): %_clean:
 -      $(MAKE) -C hal/$* clean
 -
 -$(HALS:%=%_install): %_install:
 -      $(MAKE) -C hal/$* install
 -
 -$(HALS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C hal/$* bootcd
 -
 -.PHONY: $(HALS) $(HALS:%=%_implib) $(HALS:%=%_test) \
 -        $(HALS:%=%_clean) $(HALS:%=%_install) $(HALS:%=%_bootcd)
 -
 -
 -#
 -# File system libraries
 -#
 -$(LIB_FSLIB): %: dk
 -      $(MAKE) -C lib/fslib/$*
 -
 -$(LIB_FSLIB:%=%_depends): %_depends:
 -      $(MAKE) -C lib/fslib/$* depends
 -
 -$(LIB_FSLIB:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C lib/fslib/$* implib
 -
 -$(LIB_FSLIB:%=%_test): %_test:
 -      $(MAKE) -C lib/fslib/$* test
 -
 -$(LIB_FSLIB:%=%_clean): %_clean:
 -      $(MAKE) -C lib/fslib/$* clean
 -
 -$(LIB_FSLIB:%=%_install): %_install:
 -      $(MAKE) -C lib/fslib/$* install
 -
 -$(LIB_FSLIB:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C lib/fslib/$* bootcd
 -
 -.PHONY: $(LIB_FSLIB) $(LIB_FSLIB:%=%_depends) $(LIB_FSLIB:%=%_implib) \
 -        $(LIB_FSLIB:%=%_test) $(LIB_FSLIB:%=%_clean) \
 -        $(LIB_FSLIB:%=%_install) $(LIB_FSLIB:%=%_bootcd)
 -
 -
 -#
 -# Static libraries
 -#
 -$(LIB_STATIC): %: dk
 -      $(MAKE) --silent -C lib/$*
 -
 -$(LIB_STATIC:%=%_depends): %_depends:
 -      $(MAKE) -C lib/string depends
 -
 -$(LIB_STATIC:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C lib/$* implib
 -
 -$(LIB_STATIC:%=%_test): %_test:
 -      $(MAKE) -C lib/$* test
 -
 -$(LIB_STATIC:%=%_clean): %_clean:
 -      $(MAKE) -C lib/$* clean
 -
 -$(LIB_STATIC:%=%_install): %_install:
 -      $(MAKE) -C lib/$* install
 -
 -$(LIB_STATIC:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C lib/$* bootcd
 -
 -.PHONY: $(LIB_STATIC) $(LIB_STATIC:%=%_depends) $(LIB_STATIC:%=%_implib) \
 -        $(LIB_STATIC:%=%_test) $(LIB_STATIC:%=%_clean) \
 -        $(LIB_STATIC:%=%_install) $(LIB_STATIC:%=%_bootcd)
 -
 -
 -#
 -# MSVCRT is seperate since CRTDLL depend on this
 -#
 -msvcrt: $(IMPLIB)
 -      $(MAKE) -C lib/msvcrt
 -
 -msvcrt_depends:
 -      $(MAKE) -C lib/msvcrt depends
 -
 -msvcrt_implib: dk
 -      $(MAKE) --silent -C lib/msvcrt implib
 -
 -msvcrt_test:
 -      $(MAKE) -C lib/msvcrt test
 -
 -msvcrt_clean:
 -      $(MAKE) -C lib/msvcrt clean
 -
 -msvcrt_install:
 -      $(MAKE) -C lib/msvcrt install
 -
 -msvcrt_bootcd:
 -      $(MAKE) -C lib/msvcrt bootcd
 -
 -.PHONY: msvcrt msvcrt_depends msvcrt_implib msvcrt_test \
 -        msvcrt_clean msvcrt_install msvcrt_bootcd
 -
 -
 -#
 -# DLLs
 -#
 -$(DLLS): %: $(IMPLIB) msvcrt
 -      $(MAKE) -C lib/$*
 -
 -$(DLLS:%=%_depends): %_depends:
 -      $(MAKE) -C lib/$* depends
 -
 -$(DLLS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C lib/$* implib
 -
 -$(DLLS:%=%_test): %_test:
 -      $(MAKE) -C lib/$* test
 -
 -$(DLLS:%=%_clean): %_clean:
 -      $(MAKE) -C lib/$* clean
 -
 -$(DLLS:%=%_install): %_install:
 -      $(MAKE) -C lib/$* install
 -
 -$(DLLS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C lib/$* bootcd
 -
 -.PHONY: $(DLLS) $(DLLS:%=%_depends) $(DLLS:%=%_implib) $(DLLS:%=%_test) \
 -        $(DLLS:%=%_clean) $(DLLS:%=%_install) $(DLLS:%=%_bootcd)
 -
 -
 -#
 -# Subsystem support modules
 -#
 -$(SUBSYS): %: $(IMPLIB)
 -      $(MAKE) -C subsys/$*
 -
 -$(SUBSYS:%=%_depends): %_depends:
 -      $(MAKE) -C subsys/$* depends
 -
 -$(SUBSYS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C subsys/$* implib
 -
 -$(SUBSYS:%=%_test): %_test:
 -      $(MAKE) -C subsys/$* test
 -
 -$(SUBSYS:%=%_clean): %_clean:
 -      $(MAKE) -C subsys/$* clean
 -
 -$(SUBSYS:%=%_install): %_install:
 -      $(MAKE) -C subsys/$* install
 -
 -$(SUBSYS:%=%_bootcd): %_bootcd:
 -      $(MAKE) -C subsys/$* bootcd
 -
 -.PHONY: $(SUBSYS) $(SUBSYS:%=%_depends) $(SUBSYS:%=%_implib) $(SUBSYS:%=%_test) \
 -        $(SUBSYS:%=%_clean) $(SUBSYS:%=%_install) $(SUBSYS:%=%_bootcd)
 -
 -#
 -# Regression testsuite
 -#
 -
 -$(REGTESTS): %: $(IMPLIB)
 -      $(MAKE) --silent -C regtests
 -
 -$(REGTESTS:%=%_implib): %_implib: dk
 -      $(MAKE) --silent -C regtests implib
 -
 -$(REGTESTS:%=%_clean): %_clean:
 -      $(MAKE) -C regtests clean
 -
 -$(REGTESTS:%=%_install): %_install:
 -      $(MAKE) -C regtests install
 -
 -.PHONY: $(REGTESTS) $(REGTESTS:%=%_depends) $(SUBSYS:%=%_clean) $(REGTESTS:%=%_install)
 -
 -
 -#
 -# Create an installation
 -#
 -
 -install_clean:
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/system32/drivers/*.*
 -      $(RM) $(INSTALL_DIR)/system32/drivers/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/system32/config/*.*
 -      $(RM) $(INSTALL_DIR)/system32/config/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/system32/*.*
 -      $(RM) $(INSTALL_DIR)/system32/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/media/fonts/*.*
 -      $(RM) $(INSTALL_DIR)/media/fonts/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/media/*.*
 -      $(RM) $(INSTALL_DIR)/media/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/inf/*.*
 -      $(RM) $(INSTALL_DIR)/inf/*.*
 -      $(HALFVERBOSEECHO) [RM]      $(INSTALL_DIR)/bin/*.*
 -      $(RM) $(INSTALL_DIR)/bin/*.*
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/system32/drivers
 -      $(RMDIR) $(INSTALL_DIR)/system32/drivers
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/system32/config
 -      $(RMDIR) $(INSTALL_DIR)/system32/config
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/system32
 -      $(RMDIR) $(INSTALL_DIR)/system32
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/media/fonts
 -      $(RMDIR) $(INSTALL_DIR)/media/fonts
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/media
 -      $(RMDIR) $(INSTALL_DIR)/media
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/inf
 -      $(RMDIR) $(INSTALL_DIR)/inf
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)/bin
 -      $(RMDIR) $(INSTALL_DIR)/bin
 -      $(HALFVERBOSEECHO) [RMDIR]   $(INSTALL_DIR)
 -      $(RMDIR) $(INSTALL_DIR)
 -
 -install_dirs:
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)
 -      $(RMKDIR) $(INSTALL_DIR)
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/bin
 -      $(RMKDIR) $(INSTALL_DIR)/bin
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/inf
 -      $(RMKDIR) $(INSTALL_DIR)/inf
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/media
 -      $(RMKDIR) $(INSTALL_DIR)/media
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/media/fonts
 -      $(RMKDIR) $(INSTALL_DIR)/media/fonts
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/system32
 -      $(RMKDIR) $(INSTALL_DIR)/system32
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/system32/config
 -      $(RMKDIR) $(INSTALL_DIR)/system32/config
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/system32/drivers
 -      $(RMKDIR) $(INSTALL_DIR)/system32/drivers
 -      $(HALFVERBOSEECHO) [RMKDIR]  $(INSTALL_DIR)/system32/drivers/etc
 -      $(RMKDIR) $(INSTALL_DIR)/system32/drivers/etc
 -
 -install_before:
 -      $(HALFVERBOSEECHO) [INSTALL] media/inf to $(INSTALL_DIR)/inf
 -      $(CP) media/inf $(INSTALL_DIR)/inf
 -      $(HALFVERBOSEECHO) [INSTALL] media/fonts to $(INSTALL_DIR)/media/fonts
 -      $(CP) media/fonts $(INSTALL_DIR)/media/fonts
 -      $(HALFVERBOSEECHO) [INSTALL] media/nls to $(INSTALL_DIR)/system32
 -      $(CP) media/nls $(INSTALL_DIR)/system32
 -      $(HALFVERBOSEECHO) [INSTALL] media/nls/c_1252.nls to $(INSTALL_DIR)/system32/ansi.nls
 -      $(CP) media/nls/c_1252.nls $(INSTALL_DIR)/system32/ansi.nls
 -      $(HALFVERBOSEECHO) [INSTALL] media/nls/c_437.nls to $(INSTALL_DIR)/system32/oem.nls
 -      $(CP) media/nls/c_437.nls $(INSTALL_DIR)/system32/oem.nls
 -      $(HALFVERBOSEECHO) [INSTALL] media/nls/l_intl.nls to $(INSTALL_DIR)/system32/casemap.nls
 -      $(CP) media/nls/l_intl.nls $(INSTALL_DIR)/system32/casemap.nls
 -      $(HALFVERBOSEECHO) [INSTALL] media/drivers/etc/services to $(INSTALL_DIR)/system32/drivers/etc/services
 -      $(CP) media/drivers/etc/services $(INSTALL_DIR)/system32/drivers/etc/services
 -
 -.PHONY: install_clean install_dirs install_before
 -
 -
 -etags:
 -      find . -name "*.[ch]" -print | etags --language=c -
 -
 -
 -docu:
 -      echo generating ReactOS NTOSKRNL documentation ...
 -      $(MAKE) -C ntoskrnl docu
 -
 -      echo generating ReactOS drivers documentation ...
 -      $(MAKE) -C drivers docu
 -
 -      echo generating ReactOS NTDLL documentation ...
 -      $(MAKE) -C lib/ntdll docu
 -
 -      echo generating ReactOS Freetype documentation ...
 -      $(MAKE) -C lib/freetype docu
 -
 -      echo generating ReactOS libs documentation ...
 -      $(MAKE) -C lib docu
 +include tools/Makefile
 +-include Makefile.auto
  
 -      echo generating ReactOS WIN32K documentation ...
 -      $(MAKE) -C subsys/win32k docu
 +PREAUTO := \
 +      include$(SEP)reactos$(SEP)buildno.h \
 +      include$(SEP)reactos$(SEP)bugcodes.h \
 +      ntoskrnl$(SEP)bugcodes.rc \
 +      include$(SEP)reactos$(SEP)errcodes.h \
 +      lib$(SEP)kernel32$(SEP)errcodes.rc
  
- Makefile.auto: $(RMKDIR_TARGET) $(BUILDNO_TARGET) $(NCI_SERVICE_FILES) $(WMC_TARGET) $(CDMAKE_TARGET) $(RBUILD_TARGET) $(PREAUTO)
 -      echo generating ReactOS apps+tools documentation ...
 -      $(MAKE) -C apps docu
++Makefile.auto: $(RMKDIR_TARGET) $(BUILDNO_TARGET) $(NCI_SERVICE_FILES) $(WMC_TARGET) $(WRC_TARGET) \
++               $(CDMAKE_TARGET) $(RBUILD_TARGET) $(PREAUTO)
 +      tools$(SEP)rbuild$(SEP)rbuild$(EXEPOSTFIX) mingw
 +#     $(MAKE) $(MAKECMDGOALS)
  
 -      echo generating ReactOS explorer documentation ...
 -      $(MAKE) -C subsys/system/explorer full-docu
  
 -      echo generating remaining ReactOS documentation ...
 -      doxygen Doxyfile
 +include$(SEP)reactos$(SEP)bugcodes.h ntoskrnl$(SEP)bugcodes.rc: $(WMC_TARGET) ntoskrnl$(SEP)ntoskrnl.mc
 +      $(WMC_TARGET) -H include$(SEP)reactos$(SEP)bugcodes.h -o ntoskrnl$(SEP)bugcodes.rc ntoskrnl$(SEP)ntoskrnl.mc
  
 -.PHONY: docu
 +include$(SEP)reactos$(SEP)errcodes.h lib$(SEP)kernel32$(SEP)errcodes.rc: $(WMC_TARGET) lib$(SEP)kernel32$(SEP)kernel32.mc
 +      $(WMC_TARGET) -H include$(SEP)reactos$(SEP)errcodes.h -o lib$(SEP)kernel32$(SEP)errcodes.rc lib$(SEP)kernel32$(SEP)kernel32.mc
  
 -include $(TOOLS_PATH)/config.mk
 +.PHONY: makefile_auto_clean
 +makefile_auto_clean:
 +      -@$(rm) Makefile.auto $(PREAUTO) 2>$(NUL)
 +clean: makefile_auto_clean
Simple merge
@@@ -48,17 -48,17 +48,18 @@@ static PNPFS_FC
  NpfsFindListeningServerInstance(PNPFS_PIPE Pipe)
  {
    PLIST_ENTRY CurrentEntry;
--  PNPFS_FCB ServerFcb;
++  PNPFS_WAITER_ENTRY Waiter;
  
--  CurrentEntry = Pipe->ServerFcbListHead.Flink;
--  while (CurrentEntry != &Pipe->ServerFcbListHead)
++  CurrentEntry = Pipe->WaiterListHead.Flink;
++  while (CurrentEntry != &Pipe->WaiterListHead)
      {
--      ServerFcb = CONTAINING_RECORD(CurrentEntry, NPFS_FCB, FcbListEntry);
--      if (ServerFcb->PipeState == FILE_PIPE_LISTENING_STATE)
++      Waiter = CONTAINING_RECORD(CurrentEntry, NPFS_WAITER_ENTRY, Entry);
++      if (Waiter->Fcb->PipeState == FILE_PIPE_LISTENING_STATE)
        {
--        DPRINT("Server found! Fcb %p\n", ServerFcb);
--        return ServerFcb;
++        DPRINT("Server found! Fcb %p\n", Waiter->Fcb);
++        return Waiter->Fcb;
        }
++
        CurrentEntry = CurrentEntry->Flink;
      }
  
  }
  
  
++static VOID
++NpfsSignalAndRemoveListeningServerInstance(PNPFS_PIPE Pipe,
++                                         PNPFS_FCB Fcb)
++{
++  PLIST_ENTRY CurrentEntry;
++  PNPFS_WAITER_ENTRY Waiter;
++
++  CurrentEntry = Pipe->WaiterListHead.Flink;
++  while (CurrentEntry != &Pipe->WaiterListHead)
++    {
++      Waiter = CONTAINING_RECORD(CurrentEntry, NPFS_WAITER_ENTRY, Entry);
++      if (Waiter->Fcb == Fcb)
++      {
++        DPRINT("Server found! Fcb %p\n", Waiter->Fcb);
++
++        KeSetEvent(Waiter->Irp->UserEvent, 0, FALSE);
++        Waiter->Irp->UserIosb->Status = FILE_PIPE_CONNECTED_STATE;
++        Waiter->Irp->UserIosb->Information = 0;
++        IoCompleteRequest(Waiter->Irp, IO_NO_INCREMENT);
++
++        RemoveEntryList(&Waiter->Entry);
++        ExFreePool(Waiter);
++        return;
++      }
++      CurrentEntry = CurrentEntry->Flink;
++    }
++}
++
++
  NTSTATUS STDCALL
  NpfsCreate(PDEVICE_OBJECT DeviceObject,
           PIRP Irp)
        ClientFcb->PipeState = FILE_PIPE_CONNECTED_STATE;
        ServerFcb->PipeState = FILE_PIPE_CONNECTED_STATE;
  
--      /* Wake server thread */
--      DPRINT("Setting the ConnectEvent for %x\n", ServerFcb);
--      KeSetEvent(&ServerFcb->ConnectEvent, 0, FALSE);
++      /* Signal the server thread and remove it from the waiter list */
++      NpfsSignalAndRemoveListeningServerInstance(Pipe, ServerFcb);
      }
  
    KeUnlockMutex(&Pipe->FcbListLock);
@@@ -318,6 -318,6 +347,7 @@@ NpfsCreateNamedPipe(PDEVICE_OBJECT Devi
  
         InitializeListHead(&Pipe->ServerFcbListHead);
         InitializeListHead(&Pipe->ClientFcbListHead);
++       InitializeListHead(&Pipe->WaiterListHead);
         KeInitializeMutex(&Pipe->FcbListLock, 0);
  
         Pipe->PipeType = Buffer->NamedPipeType;
  
  /* FUNCTIONS *****************************************************************/
  
++static VOID
++NpfsListeningCancelRoutine(IN PDEVICE_OBJECT DeviceObject,
++                           IN PIRP Irp)
++{
++  PNPFS_WAITER_ENTRY Waiter;
++
++  DPRINT1("NpfsListeningCancelRoutine() called\n");
++  /* FIXME: Not tested. */
++
++  Waiter = Irp->Tail.Overlay.DriverContext[0];
++
++  RemoveEntryList(&Waiter->Entry);
++  ExFreePool(Waiter);
++
++  IoReleaseCancelSpinLock(Irp->CancelIrql);
++
++  Irp->IoStatus.Status = STATUS_CANCELLED;
++  Irp->IoStatus.Information = 0;
++  IoCompleteRequest(Irp, IO_NO_INCREMENT);
++}
++
++
++static NTSTATUS
++NpfsAddListeningServerInstance(PIRP Irp,
++                             PNPFS_FCB Fcb)
++{
++  PNPFS_WAITER_ENTRY Entry;
++  KIRQL OldIrql;
++
++  Entry = ExAllocatePool(NonPagedPool, sizeof(NPFS_WAITER_ENTRY));
++  if (Entry == NULL)
++    return STATUS_INSUFFICIENT_RESOURCES;
++
++  Entry->Irp = Irp;
++  Entry->Fcb = Fcb;
++  InsertTailList(&Fcb->Pipe->WaiterListHead, &Entry->Entry);
++
++  IoAcquireCancelSpinLock(&OldIrql);
++  if (!Irp->Cancel)
++    {
++      Irp->Tail.Overlay.DriverContext[0] = Entry;
++      IoMarkIrpPending(Irp);
++      IoSetCancelRoutine(Irp, NpfsListeningCancelRoutine);
++      IoReleaseCancelSpinLock(OldIrql);
++      return STATUS_PENDING;
++    }
++  /* IRP has already been cancelled */
++  IoReleaseCancelSpinLock(OldIrql);
++
++  DPRINT1("FIXME: Remove waiter entry!\n");
++  RemoveEntryList(&Entry->Entry);
++  ExFreePool(Entry);
++
++  return STATUS_CANCELLED;
++}
++
++
  static NTSTATUS
--NpfsConnectPipe(PNPFS_FCB Fcb)
++NpfsConnectPipe(PIRP Irp,
++                PNPFS_FCB Fcb)
  {
    PNPFS_PIPE Pipe;
    PLIST_ENTRY current_entry;
        current_entry = current_entry->Flink;
      }
  
--  KeUnlockMutex(&Pipe->FcbListLock);
--
    /* no listening client fcb found */
    DPRINT("No listening client fcb found -- waiting for client\n");
  
    Fcb->PipeState = FILE_PIPE_LISTENING_STATE;
  
--  Status = KeWaitForSingleObject(&Fcb->ConnectEvent,
--                               UserRequest,
--                               KernelMode,
--                               FALSE,
--                               NULL);
--  if (!NT_SUCCESS(Status))
--    {
--      DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status);
--      return Status;
--    }
++  Status = NpfsAddListeningServerInstance(Irp, Fcb);
  
--  Fcb->PipeState = FILE_PIPE_CONNECTED_STATE;
++  KeUnlockMutex(&Pipe->FcbListLock);
  
--  DPRINT("Client Fcb: %p\n", Fcb->OtherSide);
++  DPRINT("NpfsConnectPipe() done (Status %lx)\n", Status);
  
--  return STATUS_PIPE_CONNECTED;
++  return Status;
  }
  
  
@@@ -327,7 -327,7 +374,6 @@@ NpfsPeekPipe(PIRP Irp
  }
  
  
--
  NTSTATUS STDCALL
  NpfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
                      PIRP Irp)
  
        case FSCTL_PIPE_LISTEN:
        DPRINT("Connecting pipe %wZ\n", &Pipe->PipeName);
--      Status = NpfsConnectPipe(Fcb);
++      Status = NpfsConnectPipe(Irp, Fcb);
        break;
  
        case FSCTL_PIPE_PEEK:
        Status = STATUS_UNSUCCESSFUL;
      }
  
--  Irp->IoStatus.Status = Status;
--  Irp->IoStatus.Information = 0;
--
--  IoCompleteRequest(Irp, IO_NO_INCREMENT);
++  if (Status != STATUS_PENDING)
++    {
++      Irp->IoStatus.Status = Status;
++      Irp->IoStatus.Information = 0;
++ 
++      IoCompleteRequest(Irp, IO_NO_INCREMENT);
++    }
  
--  return(Status);
++  return Status;
  }
  
  
@@@ -25,6 -19,6 +19,7 @@@ typedef struct _NPFS_PIP
    KMUTEX FcbListLock;
    LIST_ENTRY ServerFcbListHead;
    LIST_ENTRY ClientFcbListHead;
++  LIST_ENTRY WaiterListHead;
    ULONG PipeType;
    ULONG ReadMode;
    ULONG WriteMode;
@@@ -58,6 -52,6 +53,14 @@@ typedef struct _NPFS_FC
    KSPIN_LOCK DataListLock;    /* Data queue lock */
  } NPFS_FCB, *PNPFS_FCB;
  
++typedef struct _NPFS_WAITER_ENTRY
++{
++  LIST_ENTRY Entry;
++  PIRP Irp;
++  PNPFS_PIPE Pipe;
++  PNPFS_FCB Fcb;
++} NPFS_WAITER_ENTRY, *PNPFS_WAITER_ENTRY;
++
  
  extern NPAGED_LOOKASIDE_LIST NpfsPipeDataLookasideList;
  
@@@ -126,11 -99,14 +99,13 @@@ NpfsRead(PDEVICE_OBJECT DeviceObject
    while (1)
      {
        /* FIXME: check if in blocking mode */
-       if (ReadFcb->ReadDataAvailable == 0)
+       if (Fcb->ReadDataAvailable == 0)
        {
--        KeResetEvent(&Fcb->Event);
-         KeSetEvent(&ReadFcb->Event, IO_NO_INCREMENT, FALSE);
-         KeReleaseSpinLock(&ReadFcb->DataListLock, OldIrql);
+         if (Fcb->PipeState == FILE_PIPE_CONNECTED_STATE)
+           {
+             KeSetEvent(&WriterFcb->Event, IO_NO_INCREMENT, FALSE);
+           }
+         KeReleaseSpinLock(&Fcb->DataListLock, OldIrql);
          if (Information > 0)
            {
              Status = STATUS_SUCCESS;
  
          if (Length == 0)
            {
-             KeSetEvent(&ReadFcb->Event, IO_NO_INCREMENT, FALSE);
+             KeSetEvent(&WriterFcb->Event, IO_NO_INCREMENT, FALSE);
++            KeResetEvent(&Fcb->Event);
              break;
            }
        }
  #endif
  
              Information = CopyLength;
-             ReadFcb->ReadDataAvailable = 0;
-             ReadFcb->WriteQuotaAvailable = ReadFcb->MaxDataLength;
 -            Fcb->ReadDataAvailable = 0;
 -            Fcb->WriteQuotaAvailable = Fcb->MaxDataLength;
++
++            if (Fcb->ReadDataAvailable > Length)
++              {
++                memmove(Fcb->Data, Fcb->Data + Length,
++                        Fcb->ReadDataAvailable - Length);
++                Fcb->ReadDataAvailable -= Length;
++                Status = STATUS_MORE_ENTRIES;
++              }
++            else
++              {
++                Fcb->ReadDataAvailable = 0;
++                Fcb->WriteQuotaAvailable = Fcb->MaxDataLength;
++              }
            }
  
          if (Information > 0)
            {
-             KeSetEvent(&ReadFcb->Event, IO_NO_INCREMENT, FALSE);
+             if (Fcb->PipeState == FILE_PIPE_CONNECTED_STATE)
+               {
+                 KeSetEvent(&WriterFcb->Event, IO_NO_INCREMENT, FALSE);
+               }
++            KeResetEvent(&Fcb->Event);
              break;
            }
        }
@@@ -329,11 -289,11 +301,10 @@@ NpfsWrite(PDEVICE_OBJECT DeviceObject
  
    while(1)
      {
-       if (Fcb->WriteQuotaAvailable == 0)
+       if (ReaderFcb->WriteQuotaAvailable == 0)
        {
--        KeResetEvent(&Fcb->Event);
-         KeSetEvent(&Fcb->OtherSide->Event, IO_NO_INCREMENT, FALSE);
-         KeReleaseSpinLock(&Fcb->DataListLock, OldIrql);
+         KeSetEvent(&ReaderFcb->Event, IO_NO_INCREMENT, FALSE);
+         KeReleaseSpinLock(&ReaderFcb->DataListLock, OldIrql);
          if (Fcb->PipeState != FILE_PIPE_CONNECTED_STATE)
            {
              Status = STATUS_PIPE_BROKEN;
  
          if (Length == 0)
            {
-             KeSetEvent(&Fcb->OtherSide->Event, IO_NO_INCREMENT, FALSE);
+             KeSetEvent(&ReaderFcb->Event, IO_NO_INCREMENT, FALSE);
++            KeResetEvent(&Fcb->Event);
              break;
            }
        }
  
          if (Information > 0)
            {
-             KeSetEvent(&Fcb->OtherSide->Event, IO_NO_INCREMENT, FALSE);
+             KeSetEvent(&ReaderFcb->Event, IO_NO_INCREMENT, FALSE);
++            KeResetEvent(&Fcb->Event);
              break;
            }
        }
index 672e3e8,0000000..bf81f99
mode 100644,000000..100644
--- /dev/null
@@@ -1,386 -1,0 +1,385 @@@
-               <file>cscanf.c</file>\r
 +<module name="crt" type="staticlibrary">\r
 +      <include base="crt">.</include>\r
++      <include base="crt">include</include>\r
 +      <define name="_DISABLE_TIDENTS" />\r
++      <define name="__MINGW_IMPORT">extern</define>\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="__REACTOS__" />\r
 +      <define name="USE_MSVCRT_PREFIX" />\r
 +      <define name="_MSVCRT_LIB_" />\r
++      <define name="_MSVCRT_" />\r
 +      <define name="_MT" />\r
 +      <directory name="conio">\r
 +              <file>cgets.c</file>\r
 +              <file>cprintf.c</file>\r
 +              <file>cputs.c</file>\r
-           <file>stubs.c</file>\r
 +              <file>getch.c</file>\r
 +              <file>getche.c</file>\r
 +              <file>kbhit.c</file>\r
 +              <file>putch.c</file>\r
 +              <file>ungetch.c</file>\r
 +      </directory>\r
 +      <directory name="ctype">\r
 +              <file>ctype.c</file>\r
 +              <file>isascii.c</file>\r
 +              <file>iscntrl.c</file>\r
 +              <file>isgraph.c</file>\r
 +              <file>isprint.c</file>\r
 +              <file>ispunct.c</file>\r
 +              <file>isupper.c</file>\r
 +              <file>isctype.c</file>\r
 +      </directory>\r
 +      <directory name="direct">\r
 +              <file>chdir.c</file>\r
 +              <file>chdrive.c</file>\r
 +              <file>getcwd.c</file>\r
 +              <file>getdcwd.c</file>\r
 +              <file>getdfree.c</file>\r
 +              <file>getdrive.c</file>\r
 +              <file>mkdir.c</file>\r
 +              <file>rmdir.c</file>\r
 +              <file>wchdir.c</file>\r
 +              <file>wgetcwd.c</file>\r
 +              <file>wgetdcwd.c</file>\r
 +              <file>wmkdir.c</file>\r
 +              <file>wrmdir.c</file>\r
 +      </directory>\r
 +      <directory name="except">\r
 +              <file>abnorter.c</file>\r
 +              <file>exhand2.c</file>\r
 +              <file>matherr.c</file>\r
 +              <file>unwind.c</file>\r
 +      </directory>\r
 +      <directory name="float">\r
 +              <file>chgsign.c</file>\r
 +              <file>clearfp.c</file>\r
 +              <file>cntrlfp.c</file>\r
 +              <file>copysign.c</file>\r
 +              <file>fpclass.c</file>\r
 +              <file>fpecode.c</file>\r
 +              <file>fpreset.c</file>\r
 +              <file>isnan.c</file>\r
 +              <file>logb.c</file>\r
 +              <file>nafter.c</file>\r
 +              <file>scalb.c</file>\r
 +              <file>statfp.c</file>\r
 +      </directory>\r
 +      <directory name="io">\r
 +              <file>access.c</file>\r
 +              <file>chmod.c</file>\r
 +              <file>chsize.c</file>\r
 +              <file>close.c</file>\r
 +              <file>commit.c</file>\r
 +              <file>create.c</file>\r
 +              <file>dup.c</file>\r
 +              <file>dup2.c</file>\r
 +              <file>eof.c</file>\r
 +              <file>filelen.c</file>\r
 +              <file>fileleni.c</file>\r
 +              <file>find.c</file>\r
 +              <file>fmode.c</file>\r
 +              <file>isatty.c</file>\r
 +              <file>locking.c</file>\r
 +              <file>lseek.c</file>\r
 +              <file>lseeki64.c</file>\r
 +              <file>mktemp.c</file>\r
 +              <file>open.c</file>\r
 +              <file>pipe.c</file>\r
 +              <file>read.c</file>\r
 +              <file>setmode.c</file>\r
 +              <file>sopen.c</file>\r
-               <file>fscanf.c</file>\r
++              <file>stubs.c</file>\r
 +              <file>tell.c</file>\r
 +              <file>telli64.c</file>\r
 +              <file>umask.c</file>\r
 +              <file>unlink.c</file>\r
 +              <file>utime.c</file>\r
 +              <file>waccess.c</file>\r
 +              <file>wchmod.c</file>\r
 +              <file>wcreate.c</file>\r
 +              <file>wfind.c</file>\r
 +              <file>wmktemp.c</file>\r
 +              <file>wopen.c</file>\r
 +              <file>write.c</file>\r
 +              <file>wunlink.c</file>\r
 +              <file>wutime.c</file>\r
 +      </directory>\r
 +      <directory name="locale">\r
 +              <file>locale.c</file>\r
 +      </directory>\r
 +      <directory name="math">\r
 +              <file>acos.c</file>\r
 +              <file>adjust.c</file>\r
 +              <file>asin.c</file>\r
 +              <file>atan2.c</file>\r
 +              <file>cabs.c</file>\r
 +              <file>cosh.c</file>\r
 +              <file>exp.c</file>\r
 +              <file>fmod.c</file>\r
 +              <file>frexp.c</file>\r
 +              <file>huge_val.c</file>\r
 +              <file>hypot.c</file>\r
 +              <file>j0_y0.c</file>\r
 +              <file>j1_y1.c</file>\r
 +              <file>jn_yn.c</file>\r
 +              <file>ldexp.c</file>\r
 +              <file>log10.c</file>\r
 +              <file>modf.c</file>\r
 +              <file>pow.c</file>\r
 +              <file>sinh.c</file>\r
 +              <file>stubs.c</file>\r
 +              <file>tanh.c</file>\r
 +      </directory>\r
 +      <directory name="mbstring">\r
 +              <file>hanzen.c</file>\r
 +              <file>ischira.c</file>\r
 +              <file>iskana.c</file>\r
 +              <file>iskmoji.c</file>\r
 +              <file>iskpun.c</file>\r
 +              <file>islead.c</file>\r
 +              <file>islwr.c</file>\r
 +              <file>ismbal.c</file>\r
 +              <file>ismbaln.c</file>\r
 +              <file>ismbc.c</file>\r
 +              <file>ismbgra.c</file>\r
 +              <file>ismbkaln.c</file>\r
 +              <file>ismblead.c</file>\r
 +              <file>ismbpri.c</file>\r
 +              <file>ismbpun.c</file>\r
 +              <file>ismbtrl.c</file>\r
 +              <file>isuppr.c</file>\r
 +              <file>jistojms.c</file>\r
 +              <file>jmstojis.c</file>\r
 +              <file>mbbtype.c</file>\r
 +              <file>mbccpy.c</file>\r
 +              <file>mbclen.c</file>\r
 +              <file>mbscat.c</file>\r
 +              <file>mbschr.c</file>\r
 +              <file>mbscmp.c</file>\r
 +              <file>mbscoll.c</file>\r
 +              <file>mbscpy.c</file>\r
 +              <file>mbscspn.c</file>\r
 +              <file>mbsdec.c</file>\r
 +              <file>mbsdup.c</file>\r
 +              <file>mbsicmp.c</file>\r
 +              <file>mbsicoll.c</file>\r
 +              <file>mbsinc.c</file>\r
 +              <file>mbslen.c</file>\r
 +              <file>mbslwr.c</file>\r
 +              <file>mbsncat.c</file>\r
 +              <file>mbsnccnt.c</file>\r
 +              <file>mbsncmp.c</file>\r
 +              <file>mbsncoll.c</file>\r
 +              <file>mbsncpy.c</file>\r
 +              <file>mbsnextc.c</file>\r
 +              <file>mbsnicmp.c</file>\r
 +              <file>mbsnicoll.c</file>\r
 +              <file>mbsninc.c</file>\r
 +              <file>mbsnset.c</file>\r
 +              <file>mbspbrk.c</file>\r
 +              <file>mbsrchr.c</file>\r
 +              <file>mbsrev.c</file>\r
 +              <file>mbsset.c</file>\r
 +              <file>mbsspn.c</file>\r
 +              <file>mbsspnp.c</file>\r
 +              <file>mbsstr.c</file>\r
 +              <file>mbstok.c</file>\r
 +              <file>mbstrlen.c</file>\r
 +              <file>mbsupr.c</file>\r
 +      </directory>\r
 +      <directory name="misc">\r
 +              <file>amsg.c</file>\r
 +              <file>assert.c</file>\r
 +              <file>crtmain.c</file>\r
 +              <file>environ.c</file>\r
 +              <file>getargs.c</file>\r
 +              <file>initterm.c</file>\r
 +              <file>lock.c</file>\r
 +              <file>purecall.c</file>\r
 +              <file>stubs.c</file>\r
 +              <file>tls.c</file>\r
 +      </directory>\r
 +      <directory name="process">\r
 +              <file>_cwait.c</file>\r
 +              <file>_system.c</file>\r
 +              <file>dll.c</file>\r
 +              <file>process.c</file>\r
 +              <file>procid.c</file>\r
 +              <file>thread.c</file>\r
 +              <file>threadid.c</file>\r
 +              <file>threadx.c</file>\r
 +      </directory>\r
 +      <directory name="search">\r
 +              <file>lfind.c</file>\r
 +              <file>lsearch.c</file>\r
 +      </directory>\r
 +      <directory name="setjmp">\r
 +              <directory name="i386">\r
 +                      <file>setjmp.s</file>\r
 +              </directory>\r
 +      </directory>\r
 +      <directory name="signal">\r
 +              <file>signal.c</file>\r
 +              <file>xcptinfo.c</file>\r
 +      </directory>\r
 +      <directory name="stdio">\r
 +              <file>allocfil.c</file>\r
 +              <file>clearerr.c</file>\r
 +              <file>fclose.c</file>\r
 +              <file>fdopen.c</file>\r
 +              <file>feof.c</file>\r
 +              <file>ferror.c</file>\r
 +              <file>fflush.c</file>\r
 +              <file>fgetc.c</file>\r
 +              <file>fgetchar.c</file>\r
 +              <file>fgetpos.c</file>\r
 +              <file>fgets.c</file>\r
 +              <file>fgetws.c</file>\r
 +              <file>filbuf.c</file>\r
 +              <file>fileno.c</file>\r
 +              <file>flsbuf.c</file>\r
 +              <file>fopen.c</file>\r
 +              <file>fprintf.c</file>\r
 +              <file>fputc.c</file>\r
 +              <file>fputchar.c</file>\r
 +              <file>fputs.c</file>\r
 +              <file>fread.c</file>\r
 +              <file>freopen.c</file>\r
-               <file>scanf.c</file>\r
 +              <file>fseek.c</file>\r
 +              <file>fsetpos.c</file>\r
 +              <file>fsopen.c</file>\r
 +              <file>ftell.c</file>\r
 +              <file>fwalk.c</file>\r
 +              <file>fwrite.c</file>\r
 +              <file>getc.c</file>\r
 +              <file>getchar.c</file>\r
 +              <file>gets.c</file>\r
 +              <file>getw.c</file>\r
 +              <file>perror.c</file>\r
 +              <file>popen.c</file>\r
 +              <file>printf.c</file>\r
 +              <file>putc.c</file>\r
 +              <file>putchar.c</file>\r
 +              <file>puts.c</file>\r
 +              <file>putw.c</file>\r
 +              <file>remove.c</file>\r
 +              <file>rename.c</file>\r
 +              <file>rewind.c</file>\r
 +              <file>rmtmp.c</file>\r
-               <file>sscanf.c</file>\r
 +              <file>setbuf.c</file>\r
 +              <file>setvbuf.c</file>\r
 +              <file>sprintf.c</file>\r
-               <file>vfscanf.c</file>\r
++              <file>swprintf.c</file>\r
 +              <file>stdhnd.c</file>\r
 +              <file>tempnam.c</file>\r
 +              <file>tmpfile.c</file>\r
 +              <file>tmpnam.c</file>\r
 +              <file>ungetc.c</file>\r
 +              <file>vfprintf.c</file>\r
-               <file>vscanf.c</file>\r
 +              <file>vfwprint.c</file>\r
 +              <file>vprintf.c</file>\r
-               <file>vsscanf.c</file>\r
 +              <file>vsprintf.c</file>\r
++              <file>vswprintf.c</file>\r
 +              <file>wfdopen.c</file>\r
 +              <file>wrename.c</file>\r
 +              <file>wtempnam.c</file>\r
 +              <file>wtmpnam.c</file>\r
 +      </directory>\r
 +      <directory name="stdlib">\r
 +              <file>_exit.c</file>\r
 +              <file>abort.c</file>\r
 +              <file>atexit.c</file>\r
 +              <file>atof.c</file>\r
 +              <file>div.c</file>\r
 +              <file>ecvt.c</file>\r
 +              <file>ecvtbuf.c</file>\r
 +              <file>errno.c</file>\r
 +              <file>fcvt.c</file>\r
 +              <file>fcvtbuf.c</file>\r
 +              <file>fullpath.c</file>\r
 +              <file>gcvt.c</file>\r
 +              <file>getenv.c</file>\r
 +              <file>ldiv.c</file>\r
 +              <file>makepath.c</file>\r
 +              <file>malloc.c</file>\r
 +              <file>mbtowc.c</file>\r
 +              <file>obsol.c</file>\r
 +              <file>putenv.c</file>\r
 +              <file>rand.c</file>\r
 +              <file>rot.c</file>\r
 +              <file>senv.c</file>\r
 +              <file>strtod.c</file>\r
 +              <file>strtoul.c</file>\r
 +              <file>swab.c</file>\r
 +              <file>wcstod.c</file>\r
 +              <file>wcstombs.c</file>\r
 +              <file>wctomb.c</file>\r
 +              <file>wfulpath.c</file>\r
 +              <file>wputenv.c</file>\r
 +              <file>wsenv.c</file>\r
 +              <file>wsplitp.c</file>\r
 +              <file>wmakpath.c</file>\r
 +      </directory>\r
 +      <directory name="string">\r
 +              <file>lasttok.c</file>\r
 +              <file>strcoll.c</file>\r
 +              <file>strdup.c</file>\r
 +              <file>strerror.c</file>\r
 +              <file>strncoll.c</file>\r
 +              <file>strpbrk.c</file>\r
 +              <file>strrev.c</file>\r
 +              <file>strset.c</file>\r
 +              <file>strstr.c</file>\r
 +              <file>strtok.c</file>\r
 +              <file>strupr.c</file>\r
 +              <file>strxfrm.c</file>\r
 +      </directory>\r
 +      <directory name="sys_stat">\r
 +              <file>fstat.c</file>\r
 +              <file>fstati64.c</file>\r
 +              <file>futime.c</file>\r
 +              <file>stat.c</file>\r
 +              <file>wstat.c</file>\r
 +              <file>systime.c</file>\r
 +      </directory>\r
 +      <directory name="time">\r
 +              <file>clock.c</file>\r
 +              <file>ctime.c</file>\r
 +              <file>difftime.c</file>\r
 +              <file>ftime.c</file>\r
 +              <file>strdate.c</file>\r
 +              <file>strftime.c</file>\r
 +              <file>strtime.c</file>\r
 +              <file>time.c</file>\r
 +              <file>tz_vars.c</file>\r
 +              <file>wctime.c</file>\r
 +              <file>wstrdate.c</file>\r
 +              <file>wstrtime.c</file>\r
 +      </directory>\r
 +      <directory name="wstring">\r
 +              <file>wcscoll.c</file>\r
 +              <file>wcscspn.c</file>\r
 +              <file>wcsdup.c</file>\r
 +              <file>wcsicmp.c</file>\r
 +              <file>wcslwr.c</file>\r
 +              <file>wcsnicmp.c</file>\r
 +              <file>wcspbrk.c</file>\r
 +              <file>wcsrev.c</file>\r
 +              <file>wcsset.c</file>\r
 +              <file>wcsspn.c</file>\r
 +              <file>wcsstr.c</file>\r
 +              <file>wcstok.c</file>\r
 +              <file>wcsupr.c</file>\r
 +              <file>wcsxfrm.c</file>\r
 +              <file>wlasttok.c</file>\r
 +      </directory>\r
 +      <directory name="wine">\r
 +              <file>cpp.c</file>\r
 +              <file>cppexcept.c</file>\r
 +              <file>heap.c</file>\r
++              <file>scanf.c</file>\r
 +              <file>thread.c</file>\r
 +      </directory>\r
 +</module>\r
@@@ -7,9 -7,18 +7,9 @@@
   * UPDATE HISTORY:
   *              28/12/98: Created
   */
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
  
 -#undef isalnum
 -/*
 - * @implemented
 - */
 -int isalnum(int c)
 -{
 -    return _isctype(c, _ALPHA | _DIGIT);
 -}
 -
  #undef iswalnum
  /*
   * @implemented
@@@ -8,8 -8,16 +8,8 @@@
   *              28/12/98: Created
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -/*
 - * @implemented
 - */
 -int __isascii(int c)
 -{
 -    return (!((c)&(~0x7f)));
 -}
 -
  /*
   * @implemented
   */
@@@ -6,8 -6,16 +6,8 @@@
   * PROGRAMMER:       Copyright (C) 1995 DJ Delorie
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -#undef iscntrl
 -/*
 - * @implemented
 - */
 -int iscntrl(int c)
 -{
 -    return _isctype(c, _CONTROL);
 -}
  
  #undef iswcntrl
  /*
Simple merge
@@@ -6,8 -6,17 +6,8 @@@
   * PROGRAMMER:       Copyright (C) 1995 DJ Delorie
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -#undef isgraph
 -/*
 - * @implemented
 - */
 -int isgraph(int c)
 -{
 -  return _isctype(c,_PUNCT | _ALPHA | _DIGIT);
 -}
 -
  #undef iswgraph
  /*
   * @implemented
@@@ -6,8 -6,17 +6,8 @@@
   * PROGRAMMER:       Copyright (C) 1995 DJ Delorie
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -#undef isprint
 -/*
 - * @implemented
 - */
 -int isprint(int c)
 -{
 -  return _isctype(c,_BLANK | _PUNCT | _ALPHA | _DIGIT);
 -}
 -
  /*
   * @implemented
   */
@@@ -6,8 -6,17 +6,8 @@@
   * PROGRAMMER:       Copyright (C) 1995 DJ Delorie
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -#undef ispunct
 -/*
 - * @implemented
 - */
 -int ispunct(int c)
 -{
 -    return _isctype(c, _PUNCT);
 -}
 -
  #undef iswpunct
  /*
   * @implemented
@@@ -6,8 -6,17 +6,8 @@@
   * PROGRAMMER:       Copyright (C) 1995 DJ Delorie
   */
  
- #include <msvcrt/ctype.h>
+ #include <ctype.h>
  
 -#undef isupper
 -/*
 - * @implemented
 - */
 -int isupper(int c)
 -{
 -    return _isctype(c, _UPPER);
 -}
 -
  /*
   * @implemented
   */
@@@ -26,26 -27,12 +27,9 @@@ Cambridge, MA 02139, USA.  *
  
  #undef sprintf
  #undef wsprintf
- /*
-  * @implemented
-  */
- int
- crt_sprintf(char *str, const char *fmt, ...)
- {
-   va_list arg;
-   int done;
  
-   va_start (arg, fmt);
-   done = vsprintf (str, fmt, arg);
-   va_end (arg);
-   return done;
- }
--/*
-- * @implemented
-- */
  int
- crt_swprintf(wchar_t *str, const wchar_t *fmt, ...)
 -_stprintf(_TCHAR *str, const _TCHAR *fmt, ...)
++crt_sprintf(_TCHAR *str, const _TCHAR *fmt, ...)
  {
    va_list arg;
    int done;
  /* Write formatted output into S, according to the format
     string FORMAT, writing no more than MAXLEN characters.  */
  /* VARARGS3 */
- /*
-  * @implemented
-  */
- int
- crt__snprintf (char *s, size_t maxlen,const char *format, ...)
- {
-   va_list arg;
-   int done;
-   va_start (arg, format);
-   done = _vsnprintf (s, maxlen, format, arg);
-   va_end (arg);
-   return done;
- }
--/*
-- * @implemented
-- */
  int
- crt__snwprintf (wchar_t *s, size_t maxlen,const wchar_t *format, ...)
 -_sntprintf (_TCHAR *s, size_t maxlen,const _TCHAR *format, ...)
++crt__snprintf (_TCHAR *s, size_t maxlen,const _TCHAR *format, ...)
  {
    va_list arg;
    int done;
@@@ -1,65 -1,4 +1,62 @@@
- /* Copyright (C) 1991 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Library General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB.  If
- not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- Cambridge, MA 02139, USA.  */
- #include <msvcrt/stdarg.h>
- #include <msvcrt/stdio.h>
- #include <msvcrt/wchar.h>
- #include <msvcrt/alloc.h>
- #include <msvcrt/internal/stdio.h>
- /* Read formatted input from STREAM according to the format string FORMAT.  */
- /* VARARGS2 */
- /*
-  * @implemented
-  */
- int fscanf(FILE *stream,const char *format, ...)
- {
-   va_list arg;
-   int done;
-   va_start(arg, format);
-   done = __vfscanf(stream, format, arg);
-   va_end(arg);
-   return done;
- }
- /*
-  * @implemented
-  */
- int
- fwscanf(FILE *stream, const wchar_t *fmt, ...)
- {
-   va_list arg;
-   int done;
-   char *cf;
-   int i,len = wcslen(fmt);
-   cf = malloc(len+1);
-   for(i=0;i<len;i++)
-     cf[i] = fmt[i];
-   cf[i] = 0;
-   va_start(arg, fmt);
-   done = __vfscanf(stream, cf, arg);
-   va_end(arg);
-   free(cf);
-   return done;
- }
++/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */\r
++\r
++/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.\r
++This file is part of the GNU C Library.\r
++\r
++The GNU C Library is free software; you can redistribute it and/or\r
++modify it under the terms of the GNU Library General Public License as\r
++published by the Free Software Foundation; either version 2 of the\r
++License, or (at your option) any later version.\r
++\r
++The GNU C Library is distributed in the hope that it will be useful,\r
++but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++Library General Public License for more details.\r
++\r
++You should have received a copy of the GNU Library General Public\r
++License along with the GNU C Library; see the file COPYING.LIB.  If\r
++not, write to the Free Software Foundation, Inc., 675 Mass Ave,\r
++Cambridge, MA 02139, USA.  */\r
++\r
+ #define UNICODE\r
+ #define _UNICODE\r
++#include <stdarg.h>\r
++#include <stdio.h>\r
++#include <wchar.h>\r
++#include <limits.h>\r
++#include <internal/file.h>\r
++#include <tchar.h>\r
++\r
++#undef sprintf\r
++#undef wsprintf\r
++\r
++int\r
++crt_swprintf(_TCHAR *str, const _TCHAR *fmt, ...)\r
++{\r
++  va_list arg;\r
++  int done;\r
++\r
++  va_start (arg, fmt);\r
++  done = _vstprintf (str, fmt, arg);\r
++  va_end (arg);\r
++  return done;\r
++}\r
++\r
++\r
++/* Write formatted output into S, according to the format\r
++   string FORMAT, writing no more than MAXLEN characters.  */\r
++/* VARARGS3 */\r
++int\r
++crt__snwprintf (_TCHAR *s, size_t maxlen,const _TCHAR *format, ...)\r
++{\r
++  va_list arg;\r
++  int done;\r
++\r
++  va_start (arg, format);\r
++  done = _vsntprintf(s, maxlen, format, arg);\r
++  va_end (arg);\r
++\r
++  return done;\r
++}\r
++\r
\r
 -#include "sprintf.c"\r
@@@ -1,31 -1,17 +1,14 @@@
  /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
- #include <msvcrt/stdio.h>
- #include <msvcrt/stdarg.h>
+ #include <stdio.h>
+ #include <stdarg.h>
  #include <limits.h>
- #include <msvcrt/internal/file.h>
+ #include <internal/file.h>
+ #include <tchar.h>
  
 -/*
 - * @implemented
 - */
  int
- crt_vsprintf(char *str, const char *fmt, va_list ap)
 -_vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
++crt_vsprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
  {
-   FILE f;
-   int len;
-   f._flag = _IOWRT|_IOSTRG|_IOBINARY;
-   f._ptr = str;
-   f._cnt = INT_MAX;
-   f._file = -1;
-   len = vfprintf(&f,fmt, ap);
-   *f._ptr = 0;
-   return len;
- }
- /*
-  * @implemented
-  */
- int
- vswprintf(wchar_t *str, const wchar_t *fmt, va_list ap)
- {
-   FILE f;
+   FILE f = {0};
    int len;
  
    f._flag = _IOWRT|_IOSTRG|_IOBINARY;
  }
  
  
 -/*
 - * @implemented
 - */
  int
- crt__vsnprintf(char *str, size_t maxlen, const char *fmt, va_list ap)
- {
-   FILE f;
-   int len;
-   f._flag = _IOWRT|_IOSTRG|_IOBINARY;
-   f._ptr = str;
-   f._cnt = maxlen;
-   f._file = -1;
-   len = vfprintf(&f,fmt, ap);
-   // what if the buffer is full ??
-   *f._ptr = 0;
-   return len;
- }
- int
- crt__vsnwprintf(wchar_t *str, size_t maxlen, const wchar_t *fmt, va_list ap)
 -_vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)
++crt__vsnprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)
  {
-   FILE f;
+   FILE f = {0};
    int len;
+   
    f._flag = _IOWRT|_IOSTRG|_IOBINARY;
    f._ptr = (char*)str;
    f._cnt = maxlen;
index 0000000,646e937..9b3cbd8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,40 @@@
 -#include "vsprintf.c"\r
++/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */\r
+ #define UNICODE\r
+ #define _UNICODE\r
++#include <stdio.h>\r
++#include <stdarg.h>\r
++#include <limits.h>\r
++#include <internal/file.h>\r
++#include <tchar.h>\r
\r
++int\r
++crt__vswprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)\r
++{\r
++  FILE f = {0};\r
++  int len;\r
++\r
++  f._flag = _IOWRT|_IOSTRG|_IOBINARY;\r
++  f._ptr = (char*)str;\r
++  f._cnt = INT_MAX;\r
++  f._file = -1;\r
++  len = _vftprintf(&f,fmt, ap);\r
++  *(_TCHAR*)f._ptr = 0;\r
++  return len;\r
++}\r
++\r
++\r
++int\r
++crt__vsnwprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)\r
++{\r
++  FILE f = {0};\r
++  int len;\r
++  \r
++  f._flag = _IOWRT|_IOSTRG|_IOBINARY;\r
++  f._ptr = (char*)str;\r
++  f._cnt = maxlen;\r
++  f._file = -1;\r
++  len = _vftprintf(&f,fmt, ap);\r
++  // what if the buffer is full ??\r
++  *(_TCHAR *)f._ptr = 0;\r
++  return len;\r
++}\r
index 0000000,f7d9232..185e16d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,223 +1,223 @@@
 -int sscanf(const char *str, const char *format, ...)\r
+ /*\r
+  * general implementation of scanf used by scanf, sscanf, fscanf,\r
+  * _cscanf, wscanf, swscanf and fwscanf\r
+  *\r
+  * Copyright 1996,1998 Marcus Meissner\r
+  * Copyright 1996 Jukka Iivonen\r
+  * Copyright 1997,2000 Uwe Bonnes\r
+  * Copyright 2000 Jon Griffiths\r
+  * Copyright 2002 Daniel Gudbjartsson\r
+  *\r
+  * This library is free software; you can redistribute it and/or\r
+  * modify it under the terms of the GNU Lesser General Public\r
+  * License as published by the Free Software Foundation; either\r
+  * version 2.1 of the License, or (at your option) any later version.\r
+  *\r
+  * This library is distributed in the hope that it will be useful,\r
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+  * Lesser General Public License for more details.\r
+  *\r
+  * You should have received a copy of the GNU Lesser General Public\r
+  * License along with this library; if not, write to the Free Software\r
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+  */\r
+  \r
+  \r
+ /*\r
+ #include <stdarg.h>\r
\r
+ #include "windef.h"\r
+ #include "winbase.h"\r
+ #include "winreg.h"\r
+ #include "winternl.h"\r
+ #include "msvcrt.h"\r
+ */\r
\r
+ //#include <ntdll/ntdll.h>\r
+ #include <ntdll/rtl.h>\r
+ //#include <ddk/ntddk.h>\r
+ //#include <ntos/heap.h>\r
+ #include <stdarg.h>\r
+ #include <wchar.h>\r
+ #include <stdio.h>\r
+ #include <conio.h>\r
+ #include <ctype.h>\r
+ #include <internal/file.h>\r
\r
+ //#include <ntos/heap.h>\r
\r
+ #define NDEBUG\r
+ #include <internal/debug.h>\r
\r
\r
+ /*\r
+ This is so ugly. I tried including anything/everything, but no matter\r
+ what i did i got complaints about RtlGetProcessHeap etc. being undefined.\r
+ -Gunnar (i hate headers)\r
+ */\r
+ #define RtlFreeHeap HeapFree\r
+ #define RtlAllocateHeap HeapAlloc\r
+ #define RtlGetProcessHeap GetProcessHeap\r
+ //#include "wine/debug.h"\r
\r
+ #define WARN DPRINT1\r
\r
+ //WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);\r
\r
+ extern FILE _iob[];\r
\r
+ /* helper function for *scanf.  Returns the value of character c in the\r
+  * given base, or -1 if the given character is not a digit of the base.\r
+  */\r
+ static int char2digit(char c, int base) {\r
+     if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');\r
+     if (base<=10) return -1;\r
+     if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);\r
+     if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);\r
+     return -1;\r
+ }\r
\r
+ /* helper function for *wscanf.  Returns the value of character c in the\r
+  * given base, or -1 if the given character is not a digit of the base.\r
+  */\r
+ static int wchar2digit(wchar_t c, int base) {\r
+     if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');\r
+     if (base<=10) return -1;\r
+     if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);\r
+     if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);\r
+     return -1;\r
+ }\r
\r
+ /* vfscanf */\r
+ #undef WIDE_SCANF\r
+ #undef CONSOLE\r
+ #undef STRING\r
+ #include "scanf.h"\r
\r
+ /* vfwscanf */\r
+ #define WIDE_SCANF 1\r
+ #undef CONSOLE\r
+ #undef STRING\r
+ #include "scanf.h"\r
\r
+ /* vsscanf */\r
+ #undef WIDE_SCANF\r
+ #undef CONSOLE\r
+ #define STRING 1\r
+ #include "scanf.h"\r
\r
+ /* vswscanf */\r
+ #define WIDE_SCANF 1\r
+ #undef CONSOLE\r
+ #define STRING 1\r
+ #include "scanf.h"\r
\r
+ /* vcscanf */\r
+ #undef WIDE_SCANF\r
+ #define CONSOLE 1\r
+ #undef STRING\r
+ #include "scanf.h"\r
\r
\r
+ /*********************************************************************\r
+  *            fscanf (MSVCRT.@)\r
+  */\r
+ int fscanf(FILE *file, const char *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vfscanf(file, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
+ /*********************************************************************\r
+  *            scanf (MSVCRT.@)\r
+  */\r
+ int scanf(const char *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vfscanf(stdin, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
+ /*********************************************************************\r
+  *            fwscanf (MSVCRT.@)\r
+  */\r
+ int fwscanf(FILE *file, const wchar_t *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vfwscanf(file, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
\r
+ /*********************************************************************\r
+  *            wscanf (MSVCRT.@)\r
+  */\r
+ int wscanf(const wchar_t *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vfwscanf(stdin, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
\r
+ /*********************************************************************\r
+  *            sscanf (MSVCRT.@)\r
+  */\r
++int crt_sscanf(const char *str, const char *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vsscanf(str, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
\r
+ /*********************************************************************\r
+  *            swscanf (MSVCRT.@)\r
+  */\r
+ int swscanf(const wchar_t *str, const wchar_t *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vswscanf(str, format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
\r
\r
+ /*********************************************************************\r
+  *            _cscanf (MSVCRT.@)\r
+  */\r
+ int _cscanf(/*const*/ char *format, ...)\r
+ {\r
+     va_list valist;\r
+     int res;\r
\r
+     va_start(valist, format);\r
+     res = vcscanf(format, valist);\r
+     va_end(valist);\r
+     return res;\r
+ }\r
Simple merge
index a3609d1,0000000..8484282
mode 100644,000000..100644
--- /dev/null
@@@ -1,19 -1,0 +1,20 @@@
-       <library>crt</library>\r
 +<module name="crtdll" type="win32dll" baseaddress="${BASEADDRESS_CRTDLL}" mangledsymbols="true">\r
 +      <linkerflag>-nostartfiles</linkerflag>\r
 +      <linkerflag>-lgcc</linkerflag>\r
 +      <importlibrary definition="crtdll.def" />\r
 +      <include base="crtdll">.</include>\r
++      <include base="crt">include</include>\r
 +      <define name="_DISABLE_TIDENTS" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="__REACTOS__" />\r
 +      <define name="USE_MSVCRT_PREFIX" />\r
 +      <define name="_MSVCRT_LIB_" />\r
++      <library>crt</library>\r
 +      <library>string</library>\r
 +      <library>kernel32</library>\r
 +      <library>ntdll</library>\r
 +      <file>dllmain.c</file>\r
 +      <file>crtdll.rc</file>\r
 +</module>\r
@@@ -8,7 -8,7 +8,7 @@@
   * @implemented
   */
  int
--vsprintf(char *str, const char *fmt, va_list ap)
++crt_vsprintf(char *str, const char *fmt, va_list ap)
  {
    FILE f;
    int len;
@@@ -63,7 -63,7 +63,7 @@@ _vsnprintf(char *str, size_t maxlen, co
   * @implemented
   */
  int
--_vsnwprintf(wchar_t *str, size_t maxlen, const wchar_t *fmt, va_list ap)
++crt__vsnwprintf(wchar_t *str, size_t maxlen, const wchar_t *fmt, va_list ap)
  {
    FILE f;
    int len;
index c082b12,0000000..967de96
mode 100644,000000..100644
--- /dev/null
@@@ -1,273 -1,0 +1,270 @@@
- <directory name="unicode">\r
-       <xi:include href="unicode/unicode.xml" />\r
- </directory>\r
 +<directory name="acledit">\r
 +      <xi:include href="acledit/acledit.xml" />\r
 +</directory>\r
 +<directory name="aclui">\r
 +      <xi:include href="aclui/aclui.xml" />\r
 +</directory>\r
 +<directory name="adns">\r
 +      <xi:include href="adns/adns.xml" />\r
 +</directory>\r
 +<directory name="advapi32">\r
 +      <xi:include href="advapi32/advapi32.xml" />\r
 +</directory>\r
 +<directory name="advpack">\r
 +      <xi:include href="advpack/advpack.xml" />\r
 +</directory>\r
 +<directory name="cabinet">\r
 +      <xi:include href="cabinet/cabinet.xml" />\r
 +</directory>\r
 +<directory name="cards">\r
 +      <xi:include href="cards/cards.xml" />\r
 +</directory>\r
 +<directory name="comctl32">\r
 +      <xi:include href="comctl32/comctl32.xml" />\r
 +</directory>\r
 +<directory name="comdlg32">\r
 +      <xi:include href="comdlg32/comdlg32.xml" />\r
 +</directory>\r
 +<directory name="cpl">\r
 +      <xi:include href="cpl/directory.xml" />\r
 +</directory>\r
 +<directory name="crt">\r
 +      <xi:include href="crt/crt.xml" />\r
 +</directory>\r
 +<directory name="crtdll">\r
 +      <xi:include href="crtdll/crtdll.xml" />\r
 +</directory>\r
 +<directory name="dbghelp">\r
 +      <xi:include href="dbghelp/dbghelp.xml" />\r
 +</directory>\r
 +<directory name="devenum">\r
 +      <xi:include href="devenum/devenum.xml" />\r
 +</directory>\r
 +<directory name="dinput">\r
 +      <xi:include href="dinput/dinput.xml" />\r
 +</directory>\r
 +<directory name="dinput8">\r
 +      <xi:include href="dinput8/dinput8.xml" />\r
 +</directory>\r
 +<directory name="dnsapi">\r
 +      <xi:include href="dnsapi/dnsapi.xml" />\r
 +</directory>\r
 +<directory name="dsound">\r
 +      <xi:include href="dsound/dsound.xml" />\r
 +</directory>\r
 +<directory name="dxdiagn">\r
 +      <xi:include href="dxdiagn/dxdiagn.xml" />\r
 +</directory>\r
 +<directory name="dxguid">\r
 +      <xi:include href="dxguid/dxguid.xml" />\r
 +</directory>\r
 +<directory name="epsapi">\r
 +      <xi:include href="epsapi/epsapi.xml" />\r
 +</directory>\r
 +<directory name="expat">\r
 +      <xi:include href="expat/expat.xml" />\r
 +</directory>\r
 +<directory name="fmifs">\r
 +      <xi:include href="fmifs/fmifs.xml" />\r
 +</directory>\r
 +<directory name="freetype">\r
 +      <xi:include href="freetype/freetype.xml" />\r
 +</directory>\r
 +<directory name="fslib">\r
 +      <xi:include href="fslib/directory.xml" />\r
 +</directory>\r
 +<directory name="gdi32">\r
 +      <xi:include href="gdi32/gdi32.xml" />\r
 +</directory>\r
 +<directory name="gdiplus">\r
 +      <xi:include href="gdiplus/gdiplus.xml" />\r
 +</directory>\r
 +<directory name="glu32">\r
 +      <xi:include href="glu32/glu32.xml" />\r
 +</directory>\r
 +<directory name="imagehlp">\r
 +      <xi:include href="imagehlp/imagehlp.xml" />\r
 +</directory>\r
 +<directory name="imm32">\r
 +      <xi:include href="imm32/imm32.xml" />\r
 +</directory>\r
 +<directory name="iphlpapi">\r
 +      <xi:include href="iphlpapi/iphlpapi.xml" />\r
 +</directory>\r
 +<directory name="kbdda">\r
 +      <xi:include href="kbdda/kbdda.xml" />\r
 +</directory>\r
 +<directory name="kbddv">\r
 +      <xi:include href="kbddv/kbddv.xml" />\r
 +</directory>\r
 +<directory name="kbdes">\r
 +      <xi:include href="kbdes/kbdes.xml" />\r
 +</directory>\r
 +<directory name="kbdfr">\r
 +      <xi:include href="kbdfr/kbdfr.xml" />\r
 +</directory>\r
 +<directory name="kbdgr">\r
 +      <xi:include href="kbdgr/kbdgr.xml" />\r
 +</directory>\r
 +<directory name="kbdse">\r
 +      <xi:include href="kbdse/kbdse.xml" />\r
 +</directory>\r
 +<directory name="kbduk">\r
 +      <xi:include href="kbduk/kbduk.xml" />\r
 +</directory>\r
 +<directory name="kbdus">\r
 +      <xi:include href="kbdus/kbdus.xml" />\r
 +</directory>\r
 +<directory name="kernel32">\r
 +      <xi:include href="kernel32/kernel32.xml" />\r
 +</directory>\r
 +<directory name="kjs">\r
 +      <xi:include href="kjs/kjs.xml" />\r
 +</directory>\r
 +<directory name="libwine">\r
 +      <xi:include href="libwine/libwine.xml" />\r
 +</directory>\r
 +<directory name="lzexpand">\r
 +      <xi:include href="lzexpand/lz32.xml" />\r
 +</directory>\r
 +<directory name="mesa32">\r
 +      <xi:include href="mesa32/mesa32.xml" />\r
 +</directory>\r
 +<directory name="midimap">\r
 +      <xi:include href="midimap/midimap.xml" />\r
 +</directory>\r
 +<directory name="mmdrv">\r
 +      <xi:include href="mmdrv/mmdrv.xml" />\r
 +</directory>\r
 +<directory name="mpr">\r
 +      <xi:include href="mpr/mpr.xml" />\r
 +</directory>\r
 +<directory name="msafd">\r
 +      <xi:include href="msafd/msafd.xml" />\r
 +</directory>\r
 +<directory name="msgina">\r
 +      <xi:include href="msgina/msgina.xml" />\r
 +</directory>\r
 +<directory name="msimg32">\r
 +      <xi:include href="msimg32/msimg32.xml" />\r
 +</directory>\r
 +<directory name="msvcrt">\r
 +      <xi:include href="msvcrt/msvcrt.xml" />\r
 +</directory>\r
 +<directory name="msvcrt20">\r
 +      <xi:include href="msvcrt20/msvcrt20.xml" />\r
 +</directory>\r
 +<directory name="netapi32">\r
 +      <xi:include href="netapi32/netapi32.xml" />\r
 +</directory>\r
 +<directory name="ntdll">\r
 +      <xi:include href="ntdll/ntdll.xml" />\r
 +</directory>\r
 +<directory name="ole32">\r
 +      <xi:include href="ole32/ole32.xml" />\r
 +</directory>\r
 +<directory name="oleaut32">\r
 +      <xi:include href="oleaut32/oleaut32.xml" />\r
 +</directory>\r
 +<directory name="olepro32">\r
 +      <xi:include href="olepro32/olepro32.xml" />\r
 +</directory>\r
 +<directory name="opengl32">\r
 +      <xi:include href="opengl32/opengl32.xml" />\r
 +</directory>\r
 +<directory name="psapi">\r
 +      <xi:include href="psapi/psapi.xml" />\r
 +</directory>\r
 +<directory name="pseh">\r
 +      <xi:include href="pseh/pseh.xml" />\r
 +</directory>\r
 +<directory name="richedit">\r
 +      <xi:include href="richedit/riched32.xml" />\r
 +</directory>\r
 +<directory name="rosrtl">\r
 +      <xi:include href="rosrtl/rosrtl.xml" />\r
 +</directory>\r
 +<directory name="rossym">\r
 +      <xi:include href="rossym/rossym.xml" />\r
 +</directory>\r
 +<directory name="rpcrt4">\r
 +      <xi:include href="rpcrt4/rpcrt4.xml" />\r
 +</directory>\r
 +<directory name="rtl">\r
 +      <xi:include href="rtl/rtl.xml" />\r
 +</directory>\r
 +<directory name="samlib">\r
 +      <xi:include href="samlib/samlib.xml" />\r
 +</directory>\r
 +<directory name="secur32">\r
 +      <xi:include href="secur32/secur32.xml" />\r
 +</directory>\r
 +<directory name="setupapi">\r
 +      <xi:include href="setupapi/setupapi.xml" />\r
 +</directory>\r
 +<directory name="shdocvw">\r
 +      <xi:include href="shdocvw/shdocvw.xml" />\r
 +</directory>\r
 +<directory name="shell32">\r
 +      <xi:include href="shell32/shell32.xml" />\r
 +</directory>\r
 +<directory name="shlwapi">\r
 +      <xi:include href="shlwapi/shlwapi.xml" />\r
 +</directory>\r
 +<directory name="snmpapi">\r
 +      <xi:include href="snmpapi/snmpapi.xml" />\r
 +</directory>\r
 +<directory name="smdll">\r
 +      <xi:include href="smdll/smdll.xml" />\r
 +</directory>\r
 +<directory name="string">\r
 +      <xi:include href="string/string.xml" />\r
 +</directory>\r
 +<directory name="strmiids">\r
 +      <xi:include href="strmiids/strmiids.xml" />\r
 +</directory>\r
 +<directory name="syssetup">\r
 +      <xi:include href="syssetup/syssetup.xml" />\r
 +</directory>\r
 +<directory name="twain">\r
 +      <xi:include href="twain/twain_32.xml" />\r
 +</directory>\r
 +<directory name="urlmon">\r
 +      <xi:include href="urlmon/urlmon.xml" />\r
 +</directory>\r
 +<directory name="user32">\r
 +      <xi:include href="user32/user32.xml" />\r
 +</directory>\r
 +<directory name="userenv">\r
 +      <xi:include href="userenv/userenv.xml" />\r
 +</directory>\r
 +<directory name="uuid">\r
 +      <xi:include href="uuid/uuid.xml" />\r
 +</directory>\r
 +<directory name="version">\r
 +      <xi:include href="version/version.xml" />\r
 +</directory>\r
 +<directory name="wininet">\r
 +      <xi:include href="wininet/wininet.xml" />\r
 +</directory>\r
 +<directory name="winmm">\r
 +      <xi:include href="winmm/winmm.xml" />\r
 +</directory>\r
 +<directory name="winspool">\r
 +      <xi:include href="winspool/winspool.xml" />\r
 +</directory>\r
 +<directory name="ws2_32">\r
 +      <xi:include href="ws2_32/ws2_32.xml" />\r
 +</directory>\r
 +<directory name="ws2help">\r
 +      <xi:include href="ws2help/ws2help.xml" />\r
 +</directory>\r
 +<directory name="wshirda">\r
 +      <xi:include href="wshirda/wshirda.xml" />\r
 +</directory>\r
 +<directory name="wsock32">\r
 +      <xi:include href="wsock32/wsock32.xml" />\r
 +</directory>\r
 +<directory name="zlib">\r
 +      <xi:include href="zlib/zlib.xml" />\r
 +</directory>\r
@@@ -1,4 -1,4 +1,4 @@@
- # $Id$
 -# $Id: Makefile 13593 2005-02-16 14:01:34Z weiden $
++# $Id: Makefile 12851 2005-01-06 13:34:15Z mf $
  
  PATH_TO_TOP = ../..
  
@@@ -7,7 -7,7 +7,7 @@@ dnl The implementation will create a bi
  dnl the binary it will be grep'ed for some symbols that will look
  dnl different for different endianess of the binary.
  dnl
- dnl @version $Id$
 -dnl @version $Id: ac_c_bigendian_cross.m4,v 1.2 2001/10/01 20:03:13 fdrake Exp $
++dnl @version $Id: ac_c_bigendian_cross.m4 12851 2005-01-06 13:34:15Z mf $
  dnl @author Guido Draheim <guidod@gmx.de>
  dnl
  AC_DEFUN([AC_C_BIGENDIAN_CROSS],
@@@ -4,7 -4,7 +4,7 @@@
  # Created: 1993-05-16
  # Public domain
  
- # $Id$
 -# $Id: mkinstalldirs,v 1.1 2000/09/18 16:26:21 coopercc Exp $
++# $Id: mkinstalldirs 12851 2005-01-06 13:34:15Z mf $
  
  errstatus=0
  
index 1ce519f,0000000..1fc36fa
mode 100644,000000..100644
--- /dev/null
@@@ -1,12 -1,0 +1,13 @@@
 +<module name="expat" type="win32dll">\r
 +      <importlibrary definition="lib/libexpat.def" />\r
 +      <include base="expat">.</include>\r
++      <include base="expat">lib</include>\r
 +      <define name="HAVE_EXPAT_CONFIG_H" />\r
 +      <define name="__USE_W32API" />\r
 +      <library>kernel32</library>\r
 +      <directory name="lib">\r
 +              <file>xmlparse.c</file>\r
 +              <file>xmlrole.c</file>\r
 +              <file>xmltok.c</file>\r
 +      </directory>\r
 +</module>\r
Simple merge
@@@ -160,9 -160,9 +160,9 @@@ __setlc_active DAT
  __setusermatherr
  __threadhandle
  __threadid
 -__toascii
 +__toascii=NTDLL.__toascii
- ;__unDName
- ;__unDNameEx
+ __unDName=stub
+ __unDNameEx=stub
  __unguarded_readlc_active DATA
  __wargv
  __wgetmainargs
@@@ -192,21 -192,21 +192,21 @@@ _adj_fdivr_m32 = _adj_fdivr_m32@
  _adj_fdivr_m32i = _adj_fdivr_m32i@4
  _adj_fdivr_m64 = _adj_fdivr_m64@8
  _adj_fpatan
- ;_adj_fprem
- ;_adj_fprem1
- ;_adj_fptan
+ _adj_fprem=stub
+ _adj_fprem1=stub
+ _adj_fptan=stub
  _adjust_fdiv DATA
  _aexit_rtn
- ;_aligned_free
- ;_aligned_malloc
- ;_aligned_offset_malloc
- ;_aligned_offset_realloc
- ;_aligned_realloc
+ _aligned_free=stub
+ _aligned_malloc=stub
+ _aligned_offset_malloc=stub
+ _aligned_offset_realloc=stub
+ _aligned_realloc=stub
  _amsg_exit
  _assert
- ;_atodbl
+ _atodbl=stub
 -_atoi64
 +_atoi64=NTDLL._atoi64
- ;_atoldbl
+ _atoldbl=stub
  _beep
  _beginthread
  _beginthreadex
@@@ -322,15 -323,15 +323,15 @@@ _heapad
  _heapchk
  _heapmin
  _heapset
- ;_heapused
+ _heapused=stub
  _heapwalk
  _hypot
 -_i64toa
 -_i64tow
 +_i64toa=NTDLL._i64toa
 +_i64tow=NTDLL._i64tow
  _initterm
- ;_inp
- ;_inpd
- ;_inpw
+ _inp=stub
+ _inpd=stub
+ _inpw=stub
  _iob
  _isatty
  _isctype
@@@ -441,10 -443,10 +443,10 @@@ _mbsto
  _mbstrlen
  _mbsupr
  _memccpy
 -_memicmp
 +_memicmp=NTDLL._memicmp
  _mkdir
  _mktemp
- ;_mktime64
+ _mktime64=stub
  _msize
  _nextafter
  _onexit
@@@ -493,10 -495,10 +495,10 @@@ _setmbc
  _setmode
  _setsystime
  _sleep
 -_snprintf
 +_snprintf=crt__snprintf
- ;_snscanf
- ;_snwscanf
+ _snscanf=stub
+ _snwscanf=stub
 -_snwprintf
 +_snwprintf=crt__snwprintf
  _sopen
  _spawnl
  _spawnle
@@@ -506,9 -508,9 +508,9 @@@ _spawn
  _spawnve
  _spawnvp
  _spawnvpe
 -_splitpath
 +_splitpath=NTDLL._splitpath
  _stat
- ;_stat64
+ _stat64=stub
  _stati64
  _statusfp
  _strcmpi
@@@ -534,28 -536,27 +536,27 @@@ _sys_nerr DAT
  _tell
  _telli64
  _tempnam
- ;_time64
+ _time64=stub
  _timezone DATA
 -_tolower
 -_toupper
 +_tolower=NTDLL._tolower
 +_toupper=NTDLL._toupper
  _tzname DATA
  _tzset
 -_ui64toa
 -_ui64tow
 -_ultoa
 -_ultow
 +_ui64toa=NTDLL._i64toa
 +_ui64tow=NTDLL._i64tow
 +_ultoa=NTDLL._ultoa
 +_ultow=NTDLL._ultow
  _umask
  _ungetch
- ;_ungetwch
  _unlink
  _unloaddll
  _unlock
  _utime
- ;_utime64
- ;_vscprintf
- ;_vscwprintf
+ _utime64=stub
+ _vscprintf=stub
+ _vscwprintf=stub
 -_vsnprintf
 -_vsnwprintf
 +_vsnprintf=crt__vsnprintf
 +_vsnwprintf=crt__vsnwprintf
  _waccess
  _wasctime
  _wchdir
@@@ -633,12 -634,12 +634,12 @@@ _wstat64=stu
  _wstati64
  _wstrdate
  _wstrtime
- ;_wsystem
+ _wsystem=stub
  _wtempnam
  _wtmpnam
- ;_wtof
+ _wtof=stub
 -_wtoi
 -_wtoi64
 +_wtoi=NTDLL._wtoi
 +_wtoi64=NTDLL._wtoi64
  _wtol
  _wunlink
  _wutime
index 4e23941,0000000..feafc28
mode 100644,000000..100644
--- /dev/null
@@@ -1,22 -1,0 +1,23 @@@
-       <library>crt</library>\r
 +<module name="msvcrt" type="win32dll" baseaddress="${BASEADDRESS_MSVCRT}" mangledsymbols="true">\r
 +      <linkerflag>-nostartfiles</linkerflag>\r
 +      <linkerflag>--enable-stdcall-fixup</linkerflag>\r
 +      <linkerflag>-lgcc</linkerflag>\r
 +      <importlibrary definition="msvcrt.def" />\r
 +      <include base="msvcrt">.</include>\r
++      <include base="crt">include</include>\r
 +      <define name="_DISABLE_TIDENTS" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="__REACTOS__" />\r
 +      <define name="USE_MSVCRT_PREFIX" />\r
 +      <define name="_MSVCRT_LIB_" />\r
 +      <define name="_MT" />\r
++      <library>crt</library>\r
 +      <library>wine</library>\r
 +      <library>string</library>\r
 +      <library>kernel32</library>\r
 +      <library>ntdll</library>\r
 +      <file>dllmain.c</file>\r
 +      <file>msvcrt.rc</file>\r
 +</module>\r
index 32720af,0000000..a3cfd44
mode 100644,000000..100644
--- /dev/null
@@@ -1,45 -1,0 +1,44 @@@
-       <library>wine_unicode</library>\r
 +<module name="oleaut32" type="win32dll" baseaddress="${BASEADDRESS_OLEAUT32}">\r
 +      <dependency>winebuild</dependency>\r
 +      <importlibrary definition="oleaut32.spec.def" />\r
 +      <include base="oleaut32">.</include>\r
 +      <include base="ReactOS">include/wine</include>\r
 +      <define name="UNICODE" />\r
 +      <define name="_UNICODE" />\r
 +      <define name="__REACTOS__" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="WINVER">0x501</define>\r
 +      <define name="_STDDEF_H" />\r
 +      <define name="_OLEAUT32_" />\r
 +      <define name="COM_NO_WINDOWS_H" />\r
 +      <library>wine</library>\r
 +      <library>uuid</library>\r
 +      <library>ntdll</library>\r
 +      <library>kernel32</library>\r
 +      <library>advapi32</library>\r
 +      <library>gdi32</library>\r
 +      <library>user32</library>\r
 +      <library>rpcrt4</library>\r
 +      <library>ole32</library>\r
 +      <library>comctl32</library>\r
 +      <file>connpt.c</file>\r
 +      <file>dispatch.c</file>\r
 +      <file>hash.c</file>\r
 +      <file>oaidl_p.c</file>\r
 +      <file>oleaut.c</file>\r
 +      <file>olefont.c</file>\r
 +      <file>olepicture.c</file>\r
 +      <file>regsvr.c</file>\r
 +      <file>safearray.c</file>\r
 +      <file>stubs.c</file>\r
 +      <file>tmarshal.c</file>\r
 +      <file>typelib.c</file>\r
 +      <file>typelib2.c</file>\r
 +      <file>usrmarshal.c</file>\r
 +      <file>varformat.c</file>\r
 +      <file>variant.c</file>\r
 +      <file>vartype.c</file>\r
 +      <file>oleaut32.spec</file>\r
 +</module>\r
@@@ -265,10 -265,10 +265,15 @@@ RPC_STATUS RPCRT4_Send(RpcConnection *C
      }\r
  \r
      /* transmit packet header */\r
--    if (!WriteFile(Connection->conn, Header, hdr_size, &count, NULL)) {\r
++    ResetEvent(Connection->ovl.hEvent);\r
++    if (!WriteFile(Connection->conn, Header, hdr_size, &count, &Connection->ovl)) {\r
        WARN("WriteFile failed with error %ld\n", GetLastError());\r
        return GetLastError();\r
      }\r
++    if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count, TRUE)) {\r
++      WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
++      return GetLastError();\r
++    }\r
  \r
      /* fragment consisted of header only and is the last one */\r
      if (hdr_size == Header->common.frag_len &&\r
      }\r
  \r
      /* send the fragment data */\r
--    if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len - hdr_size, &count, NULL)) {\r
++    ResetEvent(Connection->ovl.hEvent);\r
++    if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len - hdr_size, &count, &Connection->ovl)) {\r
        WARN("WriteFile failed with error %ld\n", GetLastError());\r
        return GetLastError();\r
      }\r
++    if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count, TRUE)) {\r
++      WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
++      return GetLastError();\r
++    }\r
  \r
      Header->common.flags &= ~RPC_FLG_FIRST;\r
    }\r
@@@ -309,9 -309,9 +319,15 @@@ RPC_STATUS RPCRT4_Receive(RpcConnectio
    TRACE("(%p, %p, %p)\n", Connection, Header, pMsg);\r
  \r
    /* read packet common header */\r
--  if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead, NULL)) {\r
++  ResetEvent(Connection->ovl.hEvent);\r
++  if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead, &Connection->ovl)) {\r
++    WARN("ReadFile failed with error %ld\n", GetLastError());\r
++    status = RPC_S_PROTOCOL_ERROR;\r
++    goto fail;\r
++  }\r
++  if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead, TRUE)) {\r
      if (GetLastError() != ERROR_MORE_DATA) {\r
--      WARN("ReadFile failed with error %ld\n", GetLastError());\r
++      WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
        status = RPC_S_PROTOCOL_ERROR;\r
        goto fail;\r
      }\r
    memcpy(*Header, &common_hdr, sizeof(common_hdr));\r
  \r
    /* read the rest of packet header */\r
++  ResetEvent(Connection->ovl.hEvent);\r
    if (!ReadFile(Connection->conn, &(*Header)->common + 1,\r
--                hdr_length - sizeof(common_hdr), &dwRead, NULL)) {\r
++                hdr_length - sizeof(common_hdr), &dwRead, &Connection->ovl)) {\r
++    WARN("ReadFile failed with error %ld\n", GetLastError());\r
++    status = RPC_S_PROTOCOL_ERROR;\r
++    goto fail;\r
++  }\r
++  if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead, TRUE)) {\r
      if (GetLastError() != ERROR_MORE_DATA) {\r
--      WARN("ReadFile failed with error %ld\n", GetLastError());\r
++      WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
        status = RPC_S_PROTOCOL_ERROR;\r
        goto fail;\r
      }\r
      goto fail;\r
    }\r
  \r
++\r
    /* read packet body */\r
    switch (common_hdr.ptype) {\r
    case PKT_RESPONSE:\r
        goto fail;\r
      }\r
  \r
--    if (data_length == 0) dwRead = 0; else\r
--    if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, NULL)) {\r
--      if (GetLastError() != ERROR_MORE_DATA) {\r
++    if (data_length == 0) dwRead = 0; else {\r
++      ResetEvent(Connection->ovl.hEvent);\r
++      if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, &Connection->ovl)) {\r
          WARN("ReadFile failed with error %ld\n", GetLastError());\r
          status = RPC_S_PROTOCOL_ERROR;\r
          goto fail;\r
        }\r
++      if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead, TRUE)) {\r
++        if (GetLastError() != ERROR_MORE_DATA) {\r
++          WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
++          status = RPC_S_PROTOCOL_ERROR;\r
++          goto fail;\r
++        }\r
++      }\r
      }\r
      if (dwRead != data_length) {\r
        status = RPC_S_PROTOCOL_ERROR;\r
        TRACE("next header\n");\r
  \r
        /* read the header of next packet */\r
--      if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, NULL)) {\r
++      ResetEvent(Connection->ovl.hEvent);\r
++      if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, &Connection->ovl)) {\r
++        WARN("ReadFile failed with error %ld\n", GetLastError());\r
++        status = GetLastError();\r
++        goto fail;\r
++      }\r
++      if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead, TRUE)) {\r
          if (GetLastError() != ERROR_MORE_DATA) {\r
--          WARN("ReadFile failed with error %ld\n", GetLastError());\r
--          status = GetLastError();\r
++          WARN("GetOverlappedResult failed with error %ld\n", GetLastError());\r
++          status = RPC_S_PROTOCOL_ERROR;\r
            goto fail;\r
          }\r
        }\r
index 697ccb3,0000000..b96e022
mode 100644,000000..100644
--- /dev/null
@@@ -1,34 -1,0 +1,34 @@@
-       <library>wine_unicode</library>\r
 +<module name="setupapi" type="win32dll" baseaddress="${BASEADDRESS_SETUPAPI}">\r
 +      <dependency>winebuild</dependency>\r
 +      <importlibrary definition="setupapi.spec.def" />\r
 +      <include base="setupapi">.</include>\r
 +      <include base="ReactOS">include/wine</include>\r
 +      <define name="UNICODE" />\r
 +      <define name="_UNICODE" />\r
 +      <define name="__REACTOS__" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="WINVER">0x501</define>\r
 +      <define name="__WINESRC__" />\r
 +      <define name="_SETUPAPI_" />\r
 +      <library>wine</library>\r
 +      <library>ntdll</library>\r
 +      <library>kernel32</library>\r
 +      <library>advapi32</library>\r
 +      <library>user32</library>\r
 +      <library>rpcrt4</library>\r
 +      <library>version</library>\r
++      <file>cfgmgr.c</file>\r
 +      <file>devinst.c</file>\r
 +      <file>dirid.c</file>\r
 +      <file>diskspace.c</file>\r
 +      <file>install.c</file>\r
 +      <file>misc.c</file>\r
 +      <file>parser.c</file>\r
 +      <file>queue.c</file>\r
 +      <file>setupcab.c</file>\r
 +      <file>stubs.c</file>\r
 +      <file>setupapi.rc</file>\r
 +      <file>setupapi.spec</file>\r
 +</module>\r
index 357e683,0000000..ca01a3a
mode 100644,000000..100644
--- /dev/null
@@@ -1,43 -1,0 +1,42 @@@
-       <library>wine_unicode</library>\r
 +<module name="shlwapi" type="win32dll" baseaddress="${BASEADDRESS_SHLWAPI}">\r
 +      <dependency>winebuild</dependency>\r
 +      <importlibrary definition="shlwapi.spec.def" />\r
 +      <include base="shlwapi">.</include>\r
 +      <include base="ReactOS">include/wine</include>\r
 +      <define name="UNICODE" />\r
 +      <define name="_UNICODE" />\r
 +      <define name="__REACTOS__" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_IE">0x600</define>\r
 +      <define name="_WIN32_WINNT">0x501</define>\r
 +      <define name="WINVER">0x501</define>\r
 +      <define name="_SHLWAPI_"/>\r
 +      <define name="WINSHLWAPI">""</define>\r
 +      <linkerflag>-nostdlib</linkerflag>\r
 +      <linkerflag>-lgcc</linkerflag>\r
 +      <library>wine</library>\r
 +      <library>uuid</library>\r
 +      <library>msvcrt</library>\r
 +      <library>ntdll</library>\r
 +      <library>kernel32</library>\r
 +      <library>advapi32</library>\r
 +      <library>gdi32</library>\r
 +      <library>user32</library>\r
 +      <library>ole32</library>\r
 +      <library>oleaut32</library>\r
 +      <file>assoc.c</file>\r
 +      <file>clist.c</file>\r
 +      <file>istream.c</file>\r
 +      <file>msgbox.c</file>\r
 +      <file>ordinal.c</file>\r
 +      <file>path.c</file>\r
 +      <file>reg.c</file>\r
 +      <file>regstream.c</file>\r
 +      <file>shlwapi_main.c</file>\r
 +      <file>stopwatch.c</file>\r
 +      <file>string.c</file>\r
 +      <file>thread.c</file>\r
 +      <file>url.c</file>\r
 +      <file>wsprintf.c</file>\r
 +      <file>shlwapi.spec</file>\r
 +</module>\r
@@@ -426,6 -426,6 +426,11 @@@ IopBootLog(PUNICODE_STRING DriverName, 
  VOID
  IopSaveBootLogToFile(VOID);
  
++/* cancel.c */
++
++VOID STDCALL
++IoCancelThreadIo(PETHREAD Thread);
++
  /* errlog.c */
  
  NTSTATUS
@@@ -20,12 -20,12 +20,181 @@@ static KSPIN_LOCK CancelSpinLock
  
  /* FUNCTIONS *****************************************************************/
  
++/**
++ * @name NtCancelIoFile
++ *
++ * Cancel all pending I/O operations in the current thread for specified 
++ * file object.
++ *
++ * @param FileHandle
++ *        Handle to file object to cancel requests for. No specific
++ *        access rights are needed.
++ * @param IoStatusBlock
++ *        Pointer to status block which is filled with final completition
++ *        status on successful return.
++ *
++ * @return Status.
++ *
++ * @implemented
++ */
++
  NTSTATUS STDCALL
--NtCancelIoFile (IN    HANDLE                  FileHandle,
--              OUT     PIO_STATUS_BLOCK        IoStatusBlock)
++NtCancelIoFile(
++   IN HANDLE FileHandle,
++   OUT PIO_STATUS_BLOCK IoStatusBlock)
  {
--  UNIMPLEMENTED;
--  return(STATUS_NOT_IMPLEMENTED);
++   NTSTATUS Status;
++   PFILE_OBJECT FileObject;
++   PETHREAD Thread;
++   PLIST_ENTRY IrpEntry;
++   PIRP Irp;
++   KIRQL OldIrql;
++   BOOLEAN OurIrpsInList = FALSE;
++   LARGE_INTEGER Interval;
++
++   if ((ULONG_PTR)IoStatusBlock >= MmUserProbeAddress &&
++       KeGetPreviousMode() == UserMode)
++      return STATUS_ACCESS_VIOLATION;
++
++   Status = ObReferenceObjectByHandle(FileHandle, 0, IoFileObjectType,
++                                      KeGetPreviousMode(), (PVOID*)&FileObject,
++                                      NULL);
++   if (!NT_SUCCESS(Status))
++      return Status;
++
++   /* IRP cancellations are synchronized at APC_LEVEL. */
++   OldIrql = KfRaiseIrql(APC_LEVEL);
++
++   /*
++    * Walk the list of active IRPs and cancel the ones that belong to
++    * our file object.
++    */
++
++   Thread = PsGetCurrentThread();
++   for (IrpEntry = Thread->IrpList.Flink;
++        IrpEntry != &Thread->IrpList;
++        IrpEntry = IrpEntry->Flink)
++   {
++      Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
++      if (Irp->Tail.Overlay.OriginalFileObject == FileObject)
++      {
++         IoCancelIrp(Irp);
++         /* Don't break here, we want to cancel all IRPs for the file object. */
++         OurIrpsInList = TRUE;
++      }
++   }   
++
++   KfLowerIrql(OldIrql);
++
++   while (OurIrpsInList)
++   {
++      OurIrpsInList = FALSE;
++
++      /* Wait a short while and then look if all our IRPs were completed. */
++      Interval.QuadPart = -1000000; /* 100 milliseconds */
++      KeDelayExecutionThread(KernelMode, FALSE, &Interval);
++
++      OldIrql = KfRaiseIrql(APC_LEVEL);
++
++      /*
++       * Look in the list if all IRPs for the specified file object
++       * are completed (or cancelled). If someone sends a new IRP
++       * for our file object while we're here we can happily loop
++       * forever.
++       */
++
++      for (IrpEntry = Thread->IrpList.Flink;
++           IrpEntry != &Thread->IrpList;
++           IrpEntry = IrpEntry->Flink)
++      {
++         Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
++         if (Irp->Tail.Overlay.OriginalFileObject == FileObject)
++         {
++            OurIrpsInList = TRUE;
++            break;
++         }
++      }
++
++      KfLowerIrql(OldIrql);
++   }
++
++   _SEH_TRY
++   {
++      IoStatusBlock->Status = STATUS_SUCCESS;
++      IoStatusBlock->Information = 0;
++      Status = STATUS_SUCCESS;
++   }
++   _SEH_HANDLE
++   {
++      Status = STATUS_UNSUCCESSFUL;
++   }
++   _SEH_END;
++
++   ObDereferenceObject(FileObject);
++
++   return Status;
++}
++
++/**
++ * @name IoCancelThreadIo
++ *
++ * Cancel all pending I/O request associated with specified thread.
++ *
++ * @param Thread
++ *        Thread to cancel requests for.
++ */
++
++VOID STDCALL
++IoCancelThreadIo(PETHREAD Thread)
++{
++   PLIST_ENTRY IrpEntry;
++   PIRP Irp;
++   KIRQL OldIrql;
++   ULONG Retries = 3000;
++   LARGE_INTEGER Interval;
++
++   OldIrql = KfRaiseIrql(APC_LEVEL);
++
++   /*
++    * Start by cancelling all the IRPs in the current thread queue.
++    */
++
++   for (IrpEntry = Thread->IrpList.Flink;
++        IrpEntry != &Thread->IrpList;
++        IrpEntry = IrpEntry->Flink)
++   {
++      Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
++      IoCancelIrp(Irp);
++   }
++
++   /*
++    * Wait till all the IRPs are completed or cancelled.
++    */
++
++   while (!IsListEmpty(&Thread->IrpList))
++   {
++      KfLowerIrql(OldIrql);
++
++      /* Wait a short while and then look if all our IRPs were completed. */
++      Interval.QuadPart = -1000000; /* 100 milliseconds */
++      KeDelayExecutionThread(KernelMode, FALSE, &Interval);
++
++      /*
++       * Don't stay here forever if some broken driver doesn't complete
++       * the IRP.
++       */
++
++      if (Retries-- == 0)
++      {
++         /* FIXME: Handle this gracefully. */
++         DPRINT1("Thread with dead IRPs!");
++         ASSERT(FALSE);
++      }
++      
++      OldIrql = KfRaiseIrql(APC_LEVEL);
++   }
++
++   KfLowerIrql(OldIrql);
  }
  
  /*
@@@ -105,15 -105,15 +105,24 @@@ IopDeleteFile(PVOID ObjectBody
                                UserMode);
  #endif   
       KeResetEvent( &FileObject->Event );
--     Irp = IoBuildSynchronousFsdRequest(IRP_MJ_CLOSE,
--                                      FileObject->DeviceObject,
--                                      NULL,
--                                      0,
--                                      NULL,
--                                      &FileObject->Event,
--                                      NULL);
++
++     Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize, TRUE);
++     if (Irp == NULL)
++     {
++        /*
++         * FIXME: This case should eventually be handled. We should wait
++         * until enough memory is available to allocate the IRP.
++         */
++        ASSERT(FALSE);
++     }
++   
++     Irp->UserEvent = &FileObject->Event;
++     Irp->Tail.Overlay.Thread = PsGetCurrentThread();
       Irp->Flags |= IRP_CLOSE_OPERATION;
++   
       StackPtr = IoGetNextIrpStackLocation(Irp);
++     StackPtr->MajorFunction = IRP_MJ_CLOSE;
++     StackPtr->DeviceObject = FileObject->DeviceObject;
       StackPtr->FileObject = FileObject;
     
       Status = IoCallDriver(FileObject->DeviceObject, Irp);
@@@ -268,7 -268,7 +268,6 @@@ IoAllocateIrp(CCHAR StackSize
        return(NULL);
      }
  
--  RtlZeroMemory(Irp, IoSizeOfIrp(StackSize));
    IoInitializeIrp(Irp,
                  IoSizeOfIrp(StackSize),
                  StackSize);
@@@ -364,6 -364,6 +363,9 @@@ IofCompleteRequest(PIRP Irp
        ULONG MasterIrpCount;
        PIRP MasterIrp = Irp->AssociatedIrp.MasterIrp;
  
++      /* This should never happen! */
++      ASSERT(IsListEmpty(&Irp->ThreadListEntry));
++
        MasterIrpCount = InterlockedDecrement(&MasterIrp->AssociatedIrp.IrpCount);
        while ((Mdl = Irp->MdlAddress))
        {
     /* Windows NT File System Internals, page 165 */
     if (Irp->Flags & (IRP_PAGING_IO|IRP_CLOSE_OPERATION))
     {
++      /* This should never happen! */
++      ASSERT(IsListEmpty(&Irp->ThreadListEntry));
++
        /* 
         * If MDL_IO_PAGE_READ is set, then the caller is responsible 
         * for deallocating of the mdl. 
@@@ -582,19 -582,19 +587,19 @@@ IoGetTopLevelIrp(VOID
  VOID STDCALL
  IoQueueThreadIrp(IN PIRP Irp)
  {
--/* undefine this when (if ever) implementing irp cancellation */
--#if 0
--  KIRQL oldIrql;
++   KIRQL OldIrql;
    
--  oldIrql = KfRaiseIrql(APC_LEVEL);
++   OldIrql = KfRaiseIrql(APC_LEVEL);
    
--  /* Synchronous irp's are queued to requestor thread. If they are not completed
--  when the thread exits, they are canceled (cleaned up).
--  -Gunnar */
--  InsertTailList(&PsGetCurrentThread()->IrpList, &Irp->ThreadListEntry);
++   /*
++    * Synchronous irp's are queued to requestor thread. If they are not
++    * completed when the thread exits, they are canceled (cleaned up).
++    * - Gunnar
++    */
++
++   InsertTailList(&Irp->Tail.Overlay.Thread->IrpList, &Irp->ThreadListEntry);
      
--  KfLowerIrql(oldIrql);    
--#endif
++   KfLowerIrql(OldIrql);
  }
  
  
Simple merge
Simple merge
index 4794940,0000000..9aa63b2
mode 100644,000000..100644
--- /dev/null
@@@ -1,366 -1,0 +1,367 @@@
 +<module name="ntoskrnl" type="kernel">\r
 +      <bootstrap base="reactos" />\r
 +      <importlibrary definition="ntoskrnl.def" />\r
 +      <define name="_SEH_NO_NATIVE_NLG" />\r
 +      <define name="_DISABLE_TIDENTS" />\r
 +      <define name="__NTOSKRNL__" />\r
 +      <define name="__3GB__" />\r
 +      <include base="kjs">include</include>\r
 +      <include base="ntoskrnl">include</include>\r
 +      <library>csq</library>\r
 +      <library>hal</library>\r
 +      <library>kjs</library>\r
 +      <library>pseh</library>\r
 +      <library>rosrtl</library>\r
 +      <library>rtl</library>\r
 +      <library>string</library>\r
 +      <directory name="ke">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <file first="true">main.S</file>\r
 +                              <file>bios.c</file>\r
 +                              <file>brkpoint.c</file>\r
 +                              <file>bthread.S</file>\r
 +                              <file>exp.c</file>\r
 +                              <file>fpu.c</file>\r
 +                              <file>gdt.c</file>\r
 +                              <file>i386-mcount.S</file>\r
 +                              <file>idt.c</file>\r
 +                              <file>irq.c</file>\r
 +                              <file>irqhand.s</file>\r
 +                              <file>kernel.c</file>\r
 +                              <file>ldt.c</file>\r
 +                              <file>stkswitch.S</file>\r
 +                              <file>syscall.S</file>\r
 +                              <file>thread.c</file>\r
 +                              <file>tlbflush.S</file>\r
 +                              <file>trap.s</file>\r
 +                              <file>tskswitch.S</file>\r
 +                              <file>tss.c</file>\r
 +                              <file>usercall.c</file>\r
 +                              <file>usertrap.c</file>\r
 +                              <file>v86m.c</file>\r
 +                              <file>v86m_sup.S</file>\r
 +                              <file>vdm.c</file>\r
 +                      </directory>\r
 +              </if>\r
 +              <file>alert.c</file>\r
 +              <file>apc.c</file>\r
 +              <file>bug.c</file>\r
 +              <file>catch.c</file>\r
++              <file>clock.c</file>\r
 +              <file>critical.c</file>\r
 +              <file>device.c</file>\r
 +              <file>dpc.c</file>\r
 +              <file>error.c</file>\r
 +              <file>event.c</file>\r
 +              <file>gmutex.c</file>\r
 +              <file>ipi.c</file>\r
 +              <file>kqueue.c</file>\r
 +              <file>kthread.c</file>\r
 +              <file>main.c</file>\r
 +              <file>mutex.c</file>\r
 +              <file>process.c</file>\r
 +              <file>profile.c</file>\r
 +              <file>queue.c</file>\r
 +              <file>sem.c</file>\r
 +              <file>spinlock.c</file>\r
 +              <file>timer.c</file>\r
 +              <file>wait.c</file>\r
 +      </directory>\r
 +      <directory name="cc">\r
 +              <file>cacheman.c</file>\r
 +              <file>copy.c</file>\r
 +              <file>fs.c</file>\r
 +              <file>mdl.c</file>\r
 +              <file>pin.c</file>\r
 +              <file>view.c</file>\r
 +      </directory>\r
 +      <directory name="cm">\r
 +              <file>import.c</file>\r
 +              <file>ntfunc.c</file>\r
 +              <file>regfile.c</file>\r
 +              <file>registry.c</file>\r
 +              <file>regobj.c</file>\r
 +      </directory>\r
 +      <directory name="dbg">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <if property="KDBG" value="1">\r
 +                                      <group>\r
 +                                              <file>i386-dis.c</file>\r
 +                                              <file>kdb_help.S</file>\r
 +                                      </group>\r
 +                              </if>\r
 +                      </directory>\r
 +              </if>\r
 +              <if property="KDBG" value="1">\r
 +                      <file>kdb.c</file>\r
 +                      <file>kdb_keyboard.c</file>\r
 +                      <file>kdb_serial.c</file>\r
 +                      <file>rdebug.c</file>\r
 +                      <file>profile.c</file>\r
 +              </if>\r
 +              <if property="DBG_OR_KDBG" value="true">\r
 +                      <file>kdb_stabs.c</file>\r
 +                      <file>kdb_symbols.c</file>\r
 +              </if>\r
 +              <file>dbgctrl.c</file>\r
 +              <file>errinfo.c</file>\r
 +              <file>print.c</file>\r
 +              <file>user.c</file>\r
 +      </directory>\r
 +      <directory name="ex">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <file>interlck.c</file>\r
 +                      </directory>\r
 +              </if>\r
 +              <file>btree.c</file>\r
 +              <file>callback.c</file>\r
 +              <file>event.c</file>\r
 +              <file>evtpair.c</file>\r
 +              <file>fmutex.c</file>\r
 +              <file>hashtab.c</file>\r
 +              <file>init.c</file>\r
 +              <file>interlck.c</file>\r
 +              <file>list.c</file>\r
 +              <file>lookas.c</file>\r
 +              <file>mutant.c</file>\r
 +              <file>napi.c</file>\r
 +              <file>power.c</file>\r
 +              <file>profile.c</file>\r
 +              <file>resource.c</file>\r
 +              <file>rundown.c</file>\r
 +              <file>sem.c</file>\r
 +              <file>stree.c</file>\r
 +              <file>synch.c</file>\r
 +              <file>sysinfo.c</file>\r
 +              <file>time.c</file>\r
 +              <file>timer.c</file>\r
 +              <file>util.c</file>\r
 +              <file>uuid.c</file>\r
 +              <file>win32k.c</file>\r
 +              <file>work.c</file>\r
 +              <file>zone.c</file>\r
 +              <file>zw.S</file>\r
 +      </directory>\r
 +      <directory name="fs">\r
 +              <file>dbcsname.c</file>\r
 +              <file>filelock.c</file>\r
 +              <file>mcb.c</file>\r
 +              <file>mdl.c</file>\r
 +              <file>name.c</file>\r
 +              <file>notify.c</file>\r
 +              <file>oplock.c</file>\r
 +              <file>pool.c</file>\r
 +              <file>tunnel.c</file>\r
 +              <file>unc.c</file>\r
 +              <file>util.c</file>\r
 +      </directory>\r
 +      <directory name="inbv">\r
 +              <file>inbv.c</file>\r
 +      </directory>\r
 +      <directory name="io">\r
 +              <file>adapter.c</file>\r
 +              <file>arcname.c</file>\r
 +              <file>bootlog.c</file>\r
 +              <file>buildirp.c</file>\r
 +              <file>cancel.c</file>\r
 +              <file>cleanup.c</file>\r
 +              <file>cntrller.c</file>\r
 +              <file>create.c</file>\r
 +              <file>device.c</file>\r
 +              <file>deviface.c</file>\r
 +              <file>dir.c</file>\r
 +              <file>driver.c</file>\r
 +              <file>efi.c</file>\r
 +              <file>errlog.c</file>\r
 +              <file>error.c</file>\r
 +              <file>event.c</file>\r
 +              <file>file.c</file>\r
 +              <file>flush.c</file>\r
 +              <file>fs.c</file>\r
 +              <file>iocomp.c</file>\r
 +              <file>ioctrl.c</file>\r
 +              <file>iomgr.c</file>\r
 +              <file>iowork.c</file>\r
 +              <file>irp.c</file>\r
 +              <file>irq.c</file>\r
 +              <file>lock.c</file>\r
 +              <file>mailslot.c</file>\r
 +              <file>mdl.c</file>\r
 +              <file>npipe.c</file>\r
 +              <file>page.c</file>\r
 +              <file>parttab.c</file>\r
 +              <file>plugplay.c</file>\r
 +              <file>pnpdma.c</file>\r
 +              <file>pnpmgr.c</file>\r
 +              <file>pnpnotify.c</file>\r
 +              <file>pnpreport.c</file>\r
 +              <file>pnproot.c</file>\r
 +              <file>process.c</file>\r
 +              <file>queue.c</file>\r
 +              <file>rawfs.c</file>\r
 +              <file>remlock.c</file>\r
 +              <file>resource.c</file>\r
 +              <file>rw.c</file>\r
 +              <file>share.c</file>\r
 +              <file>shutdown.c</file>\r
 +              <file>symlink.c</file>\r
 +              <file>timer.c</file>\r
 +              <file>vpb.c</file>\r
 +              <file>wdm.c</file>\r
 +              <file>wmi.c</file>\r
 +              <file>xhaldisp.c</file>\r
 +              <file>xhaldrv.c</file>\r
 +      </directory>\r
 +      <directory name="kd">\r
 +              <file>dlog.c</file>\r
 +              <file>gdbstub.c</file>\r
 +              <file>kdebug.c</file>\r
 +              <file>mda.c</file>\r
 +              <file>service.c</file>\r
 +      </directory>\r
 +      <directory name="ldr">\r
 +              <file>init.c</file>\r
 +              <file>loader.c</file>\r
 +              <file>resource.c</file>\r
 +              <file>rtl.c</file>\r
 +              <file>sysdll.c</file>\r
 +              <file>userldr.c</file>\r
 +      </directory>\r
 +      <directory name="lpc">\r
 +              <file>close.c</file>\r
 +              <file>complete.c</file>\r
 +              <file>connect.c</file>\r
 +              <file>create.c</file>\r
 +              <file>listen.c</file>\r
 +              <file>port.c</file>\r
 +              <file>query.c</file>\r
 +              <file>queue.c</file>\r
 +              <file>receive.c</file>\r
 +              <file>reply.c</file>\r
 +              <file>send.c</file>\r
 +      </directory>\r
 +      <directory name="mm">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <file>memsafe.s</file>\r
 +                              <file>page.c</file>\r
 +                              <file>pfault.c</file>\r
 +                      </directory>\r
 +              </if>\r
 +              <file>anonmem.c</file>\r
 +              <file>aspace.c</file>\r
 +              <file>balance.c</file>\r
 +              <file>cont.c</file>\r
 +              <file>drvlck.c</file>\r
 +              <file>elf32.c</file>\r
 +              <file>elf64.c</file>\r
 +              <file>freelist.c</file>\r
 +              <file>iospace.c</file>\r
 +              <file>kmap.c</file>\r
 +              <file>marea.c</file>\r
 +              <file>mdl.c</file>\r
 +              <file>mm.c</file>\r
 +              <file>mminit.c</file>\r
 +              <file>mpw.c</file>\r
 +              <file>ncache.c</file>\r
 +              <file>npool.c</file>\r
 +              <file>pagefile.c</file>\r
 +              <file>pageop.c</file>\r
 +              <file>pager.c</file>\r
 +              <file>pagfault.c</file>\r
 +              <file>paging.c</file>\r
 +              <file>pe.c</file>\r
 +              <file>physical.c</file>\r
 +              <file>pool.c</file>\r
 +              <file>ppool.c</file>\r
 +              <file>region.c</file>\r
 +              <file>rmap.c</file>\r
 +              <file>section.c</file>\r
 +              <file>verifier.c</file>\r
 +              <file>virtual.c</file>\r
 +              <file>wset.c</file>\r
 +      </directory>\r
 +      <directory name="ob">\r
 +              <file>dirobj.c</file>\r
 +              <file>handle.c</file>\r
 +              <file>namespc.c</file>\r
 +              <file>ntobj.c</file>\r
 +              <file>object.c</file>\r
 +              <file>sdcache.c</file>\r
 +              <file>security.c</file>\r
 +              <file>symlink.c</file>\r
 +      </directory>\r
 +      <directory name="po">\r
 +              <file>power.c</file>\r
 +      </directory>\r
 +      <directory name="ps">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <file>continue.c</file>\r
 +                      </directory>\r
 +              </if>\r
 +              <file>cid.c</file>\r
 +              <file>create.c</file>\r
 +              <file>debug.c</file>\r
 +              <file>idle.c</file>\r
 +              <file>job.c</file>\r
 +              <file>kill.c</file>\r
 +              <file>locale.c</file>\r
 +              <file>process.c</file>\r
 +              <file>psmgr.c</file>\r
 +              <file>suspend.c</file>\r
 +              <file>thread.c</file>\r
 +              <file>tinfo.c</file>\r
 +              <file>w32call.c</file>\r
 +              <file>win32.c</file>\r
 +      </directory>\r
 +      <directory name="rtl">\r
 +              <if property="ARCH" value="i386">\r
 +                      <directory name="i386">\r
 +                              <file>alldiv.s</file>\r
 +                              <file>allmul.s</file>\r
 +                              <file>allrem.s</file>\r
 +                              <file>allshl.s</file>\r
 +                              <file>allshr.s</file>\r
 +                              <file>aulldiv.s</file>\r
 +                              <file>aullrem.s</file>\r
 +                              <file>aullshr.s</file>\r
 +                              <file>exception.c</file>\r
 +                              <file>seh.s</file>\r
 +                      </directory>\r
 +              </if>\r
 +              <file>atom.c</file>\r
 +              <file>capture.c</file>\r
 +              <file>ctype.c</file>\r
 +              <file>handle.c</file>\r
 +              <file>libsupp.c</file>\r
 +              <file>message.c</file>\r
 +              <file>misc.c</file>\r
 +              <file>nls.c</file>\r
 +              <file>purecall.c</file>\r
 +              <file>rangelist.c</file>\r
 +              <file>regio.c</file>\r
 +              <file>sprintf.c</file>\r
 +              <file>stdlib.c</file>\r
 +              <file>string.c</file>\r
 +              <file>strtok.c</file>\r
 +              <file>swprintf.c</file>\r
 +              <file>wstring.c</file>\r
 +      </directory>\r
 +      <directory name="se">\r
 +              <file>access.c</file>\r
 +              <file>acl.c</file>\r
 +              <file>audit.c</file>\r
 +              <file>lsa.c</file>\r
 +              <file>luid.c</file>\r
 +              <file>priv.c</file>\r
 +              <file>sd.c</file>\r
 +              <file>semgr.c</file>\r
 +              <file>sid.c</file>\r
 +              <file>token.c</file>\r
 +      </directory>\r
 +      <file>ntoskrnl.rc</file>\r
 +</module>\r
@@@ -1070,4 -1079,31 +1079,36 @@@ ObFindHandleForObject(IN PEPROCESS Proc
    return STATUS_UNSUCCESSFUL;
  }
  
+ VOID
+ ObpGetNextHandleByProcessCount(PSYSTEM_HANDLE_TABLE_ENTRY_INFO pshi,
+                                PEPROCESS Process,
+                                int Count)
+ {
+       ULONG P;
+       KIRQL oldIrql;
+ //      pshi->HandleValue;
++/* 
++   This will never work with ROS! M$, I guess uses 0 -> 65535.
++   Ros uses 0 -> 4294967295!
++ */
++
+       P = (ULONG) Process->UniqueProcessId;
+       pshi->UniqueProcessId = (USHORT) P;
+       KeAcquireSpinLock( &Process->HandleTable.ListLock, &oldIrql );
+ //      pshi->GrantedAccess;
+ //      pshi->Object;
+ //      pshi->ObjectTypeIndex;
+ //      pshi->HandleAttributes;
+       KeReleaseSpinLock( &Process->HandleTable.ListLock, oldIrql );
+       return;
+ }
  /* EOF */
@@@ -144,6 -158,6 +158,9 @@@ PsTerminateCurrentThread(NTSTATUS ExitS
   
     PsLockProcess(CurrentProcess, FALSE);
  
++   /* Cancel I/O for the thread. */
++   IoCancelThreadIo(CurrentThread);
++
     /* Remove the thread from the thread list of its process */
     RemoveEntryList(&CurrentThread->ThreadListEntry);
     Last = IsListEmpty(&CurrentProcess->ThreadListHead);
index b308c47,0000000..a7cdac0
mode 100644,000000..100644
--- /dev/null
@@@ -1,23 -1,0 +1,24 @@@
 +<module name="csrss" type="nativecui">\r
 +      <include base="csrss">.</include>\r
 +      <include base="csrss">include</include>\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_WINNT">0x0600</define>\r
 +      <define name="WINVER">0x0501</define>\r
 +      <library>rosrtl</library>\r
 +      <library>ntdll</library>\r
++      <library>smdll</library>\r
 +      <directory name="api">\r
 +              <file>handle.c</file>\r
 +              <file>process.c</file>\r
 +              <file>user.c</file>\r
 +              <file>wapi.c</file>\r
 +      </directory>\r
 +      <file>csrss.c</file>\r
 +      <file>init.c</file>\r
 +      <file>print.c</file>\r
 +      <file>video.c</file>\r
 +      <file>csrss.rc</file>\r
 +</module>\r
 +<directory name="win32csr">\r
 +      <xi:include href="win32csr/win32csr.xml" />\r
 +</directory>\r
index c71a071,0000000..930edeb
mode 100644,000000..100644
--- /dev/null
@@@ -1,21 -1,0 +1,26 @@@
-       <file>Debug.c</file>\r
 +<module name="smss" type="nativecui">\r
 +      <include base="smss">.</include>\r
 +      <define name="_DISABLE_TIDENTS" />\r
 +      <library>ntdll</library>\r
++      <library>smdll</library>\r
++      <linkerflag>-lgcc</linkerflag>\r
 +      <file>client.c</file>\r
++      <file>debug.c</file>\r
 +      <file>init.c</file>\r
 +      <file>initdosdev.c</file>\r
 +      <file>initenv.c</file>\r
 +      <file>initheap.c</file>\r
 +      <file>initmv.c</file>\r
 +      <file>initobdir.c</file>\r
 +      <file>initpage.c</file>\r
 +      <file>initreg.c</file>\r
 +      <file>initrun.c</file>\r
 +      <file>initss.c</file>\r
 +      <file>initwkdll.c</file>\r
++      <file>print.c</file>\r
 +      <file>smapi.c</file>\r
++      <file>smapicomp.c</file>\r
++      <file>smapiexec.c</file>\r
 +      <file>smss.c</file>\r
 +      <file>smss.rc</file>\r
 +</module>\r
index 499454c,0000000..b54bc33
mode 100644,000000..100644
--- /dev/null
@@@ -1,60 -1,0 +1,57 @@@
- <directory name="regedt32">\r
-       <xi:include href="regedt32/regedt32.xml" />\r
- </directory>\r
 +<directory name="autochk">\r
 +      <xi:include href="autochk/autochk.xml" />\r
 +</directory>\r
 +<directory name="calc">\r
 +      <xi:include href="calc/calc.xml" />\r
 +</directory>\r
 +<directory name="cmd">\r
 +      <xi:include href="cmd/cmd.xml" />\r
 +</directory>\r
 +<directory name="explorer">\r
 +      <xi:include href="explorer/explorer.xml" />\r
 +</directory>\r
 +<directory name="ibrowser">\r
 +      <xi:include href="ibrowser/ibrowser.xml" />\r
 +</directory>\r
 +<directory name="format">\r
 +      <xi:include href="format/format.xml" />\r
 +</directory>\r
 +<directory name="notepad">\r
 +      <xi:include href="notepad/notepad.xml" />\r
 +</directory>\r
 +<directory name="regedit">\r
 +      <xi:include href="regedit/regedit.xml" />\r
 +</directory>\r
 +<directory name="regsvr32">\r
 +      <xi:include href="regsvr32/regsvr32.xml" />\r
 +</directory>\r
 +<directory name="reporterror">\r
 +      <xi:include href="reporterror/reporterror.xml" />\r
 +</directory>\r
 +<directory name="services">\r
 +      <xi:include href="services/services.xml" />\r
 +</directory>\r
 +<directory name="setup">\r
 +      <xi:include href="setup/setup.xml" />\r
 +</directory>\r
 +<directory name="taskmgr">\r
 +      <xi:include href="taskmgr/taskmgr.xml" />\r
 +</directory>\r
 +<directory name="userinit">\r
 +      <xi:include href="userinit/userinit.xml" />\r
 +</directory>\r
 +<directory name="usetup">\r
 +      <xi:include href="usetup/usetup.xml" />\r
 +</directory>\r
 +<directory name="vmwinst">\r
 +      <xi:include href="vmwinst/vmwinst.xml" />\r
 +</directory>\r
 +<directory name="winefile">\r
 +      <xi:include href="winefile/winefile.xml" />\r
 +</directory>\r
 +<directory name="winlogon">\r
 +      <xi:include href="winlogon/winlogon.xml" />\r
 +</directory>\r
 +<directory name="welcome">\r
 +      <xi:include href="welcome/welcome.xml" />\r
 +</directory>\r
index 468625f,0000000..7994c7d
mode 100644,000000..100644
--- /dev/null
@@@ -1,66 -1,0 +1,68 @@@
 +<module name="explorer" type="win32gui">\r
 +      <linkerflag>-fexceptions</linkerflag>\r
 +      <include base="explorer">.</include>\r
++      <include base="ReactOS">include/expat</include>\r
 +      <define name="__USE_W32API" />\r
 +      <define name="UNICODE" />\r
 +      <define name="WIN32" />\r
 +      <define name="_ROS_" />\r
 +      <define name="_WIN32_IE">0x0600</define>\r
 +      <define name="_WIN32_WINNT">0x0501</define>\r
 +      <define name="WINVER">0x0500</define>\r
++      <define name="__WINDRES__" />\r
 +      <library>uuid</library>\r
 +      <library>kernel32</library>\r
 +      <library>gdi32</library>\r
 +      <library>ws2_32</library>\r
 +      <library>msimg32</library>\r
 +      <library>comctl32</library>\r
 +      <library>ole32</library>\r
 +      <library>oleaut32</library>\r
 +      <library>shell32</library>\r
 +      <library>expat</library>\r
 +      <library>notifyhook</library>\r
 +      <directory name="desktop">\r
 +              <file>desktop.cpp</file>\r
 +      </directory>\r
 +      <directory name="dialogs">\r
 +              <file>searchprogram.cpp</file>\r
 +              <file>settings.cpp</file>\r
 +      </directory>\r
 +      <directory name="shell">\r
 +              <file>entries.cpp</file>\r
 +              <file>fatfs.cpp</file>\r
 +              <file>filechild.cpp</file>\r
 +              <file>shellfs.cpp</file>\r
 +              <file>mainframe.cpp</file>\r
 +              <file>ntobjfs.cpp</file>\r
 +              <file>pane.cpp</file>\r
 +              <file>regfs.cpp</file>\r
 +              <file>shellbrowser.cpp</file>\r
 +              <file>startup.c</file>\r
 +              <file>unixfs.cpp</file>\r
 +              <file>webchild.cpp</file>\r
 +              <file>winfs.cpp</file>\r
 +      </directory>\r
 +      <directory name="taskbar">\r
 +              <file>desktopbar.cpp</file>\r
 +              <file>favorites.cpp</file>\r
 +              <file>taskbar.cpp</file>\r
 +              <file>startmenu.cpp</file>\r
 +              <file>traynotify.cpp</file>\r
 +              <file>quicklaunch.cpp</file>\r
 +      </directory>\r
 +      <directory name="utility">\r
 +              <file>shellclasses.cpp</file>\r
 +              <file>utility.cpp</file>\r
 +              <file>window.cpp</file>\r
 +              <file>dragdropimpl.cpp</file>\r
 +              <file>shellbrowserimpl.cpp</file>\r
 +              <file>xmlstorage.cpp</file>\r
 +      </directory>\r
 +      <file>explorer.cpp</file>\r
 +      <file>i386-stub-win32.c</file>\r
 +      <file>explorer.rc</file>\r
 +</module>\r
 +<directory name="notifyhook">\r
 +      <xi:include href="notifyhook/notifyhook.xml" />\r
 +</directory>\r
index a381bf7,0000000..2305957
mode 100644,000000..100644
--- /dev/null
@@@ -1,29 -1,0 +1,30 @@@
 +<module name="ibrowser" type="win32gui">\r
 +      <linkerflag>-fexceptions</linkerflag>\r
 +      <include base="ibrowser">.</include>\r
++      <include base="ReactOS">include/expat</include>\r
 +      <define name="__USE_W32API" />\r
 +      <define name="UNICODE" />\r
 +      <define name="WIN32" />\r
 +      <define name="_ROS_" />\r
 +      <define name="_WIN32_IE">0x0600</define>\r
 +      <define name="_WIN32_WINNT">0x0501</define>\r
 +      <define name="WINVER">0x0500</define>\r
 +      <library>uuid</library>\r
 +      <library>kernel32</library>\r
 +      <library>gdi32</library>\r
 +      <library>comctl32</library>\r
 +      <library>ole32</library>\r
 +      <library>oleaut32</library>\r
 +      <library>shell32</library>\r
 +      <library>expat</library>\r
 +      <directory name="utility">\r
 +              <file>utility.cpp</file>\r
 +              <file>window.cpp</file>\r
 +              <file>xmlstorage.cpp</file>\r
 +      </directory>\r
 +      <file>ibrowser.cpp</file>\r
 +      <file>favorites.cpp</file>\r
 +      <file>mainframe.cpp</file>\r
 +      <file>webchild.cpp</file>\r
 +      <file>ibrowser.rc</file>\r
 +</module>\r
Simple merge
index 3a8a6a1,0000000..f58aeb1
mode 100644,000000..100644
--- /dev/null
@@@ -1,134 -1,0 +1,135 @@@
 +<module name="win32k" type="kernelmodedriver">\r
 +      <importlibrary definition="win32k.def" />\r
 +      <include base="win32k">.</include>\r
 +      <include base="win32k">include</include>\r
 +      <include base="ntoskrnl">include</include>\r
 +      <include base="freetype">include</include>\r
 +      <define name="UNICODE" />\r
 +      <define name="__USE_W32API" />\r
 +      <define name="_WIN32_WINNT">0x0501</define>\r
 +      <define name="WINVER">0x600</define>\r
 +      <define name="_WIN32K_" />\r
 +      <library>rosrtl</library>\r
 +      <library>ntoskrnl</library>\r
 +      <library>hal</library>\r
 +      <library>pseh</library>\r
 +      <library>freetype</library>\r
 +      <directory name="dib">\r
 +              <file>dib1bpp.c</file>\r
 +              <file>dib4bpp.c</file>\r
 +              <file>dib8bpp.c</file>\r
 +              <file>dib16bpp.c</file>\r
 +              <file>dib24bpp.c</file>\r
 +              <file>dib32bpp.c</file>\r
 +              <file>dib.c</file>\r
 +      </directory>\r
 +      <directory name="eng">\r
 +              <file>bitblt.c</file>\r
 +              <file>brush.c</file>\r
 +              <file>clip.c</file>\r
 +              <file>copybits.c</file>\r
 +              <file>debug.c</file>\r
 +              <file>device.c</file>\r
 +              <file>driverobj.c</file>\r
 +              <file>error.c</file>\r
 +              <file>event.c</file>\r
 +              <file>float.c</file>\r
 +              <file>gradient.c</file>\r
 +              <file>lineto.c</file>\r
 +              <file>mem.c</file>\r
 +              <file>misc.c</file>\r
 +              <file>mouse.c</file>\r
 +              <file>paint.c</file>\r
 +              <file>palette.c</file>\r
 +              <file>perfcnt.c</file>\r
 +              <file>semaphor.c</file>\r
 +              <file>sort.c</file>\r
 +              <file>surface.c</file>\r
 +              <file>transblt.c</file>\r
 +              <file>window.c</file>\r
 +              <file>xlate.c</file>\r
 +      </directory>\r
 +      <directory name="ldr">\r
 +              <file>loader.c</file>\r
 +      </directory>\r
 +      <directory name="main">\r
 +              <file>dllmain.c</file>\r
 +              <file>svctabm.c</file>\r
 +      </directory>\r
 +      <directory name="misc">\r
 +              <file>driver.c</file>\r
 +              <file>error.c</file>\r
 +              <file>math.c</file>\r
 +              <file>object.c</file>\r
++              <file>ssec.c</file>\r
 +      </directory>\r
 +      <directory name="ntddraw">\r
 +              <file>ddraw.c</file>\r
 +              <file>stubs.c</file>\r
 +      </directory>\r
 +      <directory name="ntuser">\r
 +              <file>accelerator.c</file>\r
 +              <file>callback.c</file>\r
 +              <file>caret.c</file>\r
 +              <file>class.c</file>\r
 +              <file>clipboard.c</file>\r
 +              <file>csr.c</file>\r
 +              <file>cursoricon.c</file>\r
 +              <file>desktop.c</file>\r
 +              <file>focus.c</file>\r
 +              <file>guicheck.c</file>\r
 +              <file>hook.c</file>\r
 +              <file>hotkey.c</file>\r
 +              <file>input.c</file>\r
 +              <file>keyboard.c</file>\r
 +              <file>menu.c</file>\r
 +              <file>message.c</file>\r
 +              <file>metric.c</file>\r
 +              <file>misc.c</file>\r
 +              <file>monitor.c</file>\r
 +              <file>msgqueue.c</file>\r
 +              <file>painting.c</file>\r
 +              <file>prop.c</file>\r
 +              <file>scrollbar.c</file>\r
 +              <file>stubs.c</file>\r
 +              <file>timer.c</file>\r
 +              <file>useratom.c</file>\r
 +              <file>vis.c</file>\r
 +              <file>windc.c</file>\r
 +              <file>window.c</file>\r
 +              <file>winpos.c</file>\r
 +              <file>winsta.c</file>\r
 +      </directory>\r
 +      <directory name="objects">\r
 +              <file>bezier.c</file>\r
 +              <file>bitmaps.c</file>\r
 +              <file>brush.c</file>\r
 +              <file>cliprgn.c</file>\r
 +              <file>color.c</file>\r
 +              <file>coord.c</file>\r
 +              <file>dc.c</file>\r
 +              <file>dib.c</file>\r
 +              <file>fillshap.c</file>\r
 +              <file>font.c</file>\r
 +              <file>gdiobj.c</file>\r
 +              <file>icm.c</file>\r
 +              <file>line.c</file>\r
 +              <file>metafile.c</file>\r
 +              <file>paint.c</file>\r
 +              <file>palette.c</file>\r
 +              <file>path.c</file>\r
 +              <file>pen.c</file>\r
 +              <file>polyfill.c</file>\r
 +              <file>print.c</file>\r
 +              <file>rect.c</file>\r
 +              <file>region.c</file>\r
 +              <file>stockobj.c</file>\r
 +              <file>text.c</file>\r
 +              <file>wingl.c</file>\r
 +      </directory>\r
 +      <directory name="stubs">\r
 +              <file>stubs.c</file>\r
 +              <file>xpstubs.c</file>\r
 +      </directory>\r
 +      <file>win32k.rc</file>\r
 +</module>\r
 -PATH_TO_TOP = ..
 +RMKDIR_BASE = tools
  
 -include $(PATH_TO_TOP)/rules.mak
 +RMKDIR_TARGET = \
 +      $(ROS_INTERMEDIATE)$(RMKDIR_BASE)$(SEP)rmkdir$(EXEPOSTFIX)
  
 -CFLAGS += -Wall -Werror
 +RMKDIR_SOURCES = \
 +      $(RMKDIR_BASE)$(SEP)rmkdir.c
  
 -TOOLS = \
 -      regtests$(EXE_POSTFIX) \
 -      rcopy$(EXE_POSTFIX) \
 -      rdel$(EXE_POSTFIX) \
 -      rline$(EXE_POSTFIX) \
 -      rmkdir$(EXE_POSTFIX) \
 -      rrmdir$(EXE_POSTFIX) \
 -      rsym$(EXE_POSTFIX) \
 -      rtouch$(EXE_POSTFIX) \
 -      mkflpimg$(EXE_POSTFIX) \
 -      depends$(EXE_POSTFIX)
 +RMKDIR_OBJECTS = \
 +      $(RMKDIR_SOURCES:.c=.o)
  
 -LIBS = lib_unicode lib_wpp
 +RMKDIR_HOST_CFLAGS = -g -Werror -Wall
  
 -CLEAN_FILES = $(TOOLS)
 +RMKDIR_HOST_LFLAGS = -g
  
 -all: $(TOOLS) $(LIBS) zlib_target wmc_target cabman_target cdmake_target mkhive_target rgenstat_target \
 -      wine2ros_target pipetools_target winebuild_target bin2res_target wrc_target widl_target \
 -      buildno_target
 +$(RMKDIR_TARGET): $(RMKDIR_OBJECTS)
 +      ${host_gcc} $(RMKDIR_OBJECTS) $(RMKDIR_HOST_LFLAGS) -o $(RMKDIR_TARGET)
  
 -regtests$(EXE_POSTFIX): regtests.c
 -      @$(HOST_CC) $(CFLAGS) -o regtests$(EXE_POSTFIX) regtests.c
 +$(RMKDIR_OBJECTS): %.o : %.c
 +      ${host_gcc} $(RMKDIR_HOST_CFLAGS) -c $< -o $@
  
 -ifeq ($(HOST),mingw32-linux)
 -rcopy$(EXE_POSTFIX): rcopy.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rcopy.c -o rcopy$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rcopy$(EXE_POSTFIX): rcopy.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rcopy.c -o rcopy$(EXE_POSTFIX)
 -endif
 +.PHONY: rmkdir_clean
 +rmkdir_clean:
 +      -@$(rm) $(RMKDIR_TARGET) $(RMKDIR_OBJECTS) 2>$(NUL)
 +clean: rmkdir_clean
  
 -rdel$(EXE_POSTFIX): rdel.c
 -      @$(HOST_CC) $(CFLAGS) rdel.c -o rdel$(EXE_POSTFIX)
--
- BUILDNO_BASE = tools
 -ifeq ($(HOST),mingw32-linux)
 -rline$(EXE_POSTFIX): rline.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rline.c -o rline$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rline$(EXE_POSTFIX): rmkdir.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rline.c -o rline$(EXE_POSTFIX)
 -endif
--
- BUILDNO_TARGET = \
-       $(ROS_INTERMEDIATE)$(BUILDNO_BASE)$(SEP)buildno$(EXEPOSTFIX)
 -ifeq ($(HOST),mingw32-linux)
 -rmkdir$(EXE_POSTFIX): rmkdir.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rmkdir.c -o rmkdir$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rmkdir$(EXE_POSTFIX): rmkdir.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rmkdir.c -o rmkdir$(EXE_POSTFIX)
 -endif
--
- BUILDNO_SOURCES = \
-       $(BUILDNO_BASE)$(SEP)buildno.c
 -ifeq ($(HOST),mingw32-linux)
 -rrmdir$(EXE_POSTFIX): rrmdir.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rrmdir.c -o rrmdir$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rrmdir$(EXE_POSTFIX): rrmdir.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rrmdir.c -o rrmdir$(EXE_POSTFIX)
 -endif
--
- BUILDNO_OBJECTS = \
-       $(BUILDNO_SOURCES:.c=.o)
 -ifeq ($(HOST),mingw32-linux)
 -rsym$(EXE_POSTFIX): rsym.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rsym.c -o rsym$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rsym$(EXE_POSTFIX): rsym.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rsym.c -o rsym$(EXE_POSTFIX)
 -endif
--
- BUILDNO_HOST_CFLAGS = -g -Werror -Wall
 -ifeq ($(HOST),mingw32-linux)
 -rtouch$(EXE_POSTFIX): rtouch.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rtouch.c -o rtouch$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -rtouch$(EXE_POSTFIX): rtouch.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS rtouch.c -o rtouch$(EXE_POSTFIX)
 -endif
--
- BUILDNO_HOST_LFLAGS = -g
 -ifeq ($(HOST),mingw32-linux)
 -mkflpimg$(EXE_POSTFIX): mkflpimg.c
 -      @$(HOST_CC) $(CFLAGS) -DUNIX_PATHS mkflpimg.c -o mkflpimg$(EXE_POSTFIX)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -mkflpimg$(EXE_POSTFIX): mkflpimg.c
 -      @$(HOST_CC) $(CFLAGS) -DDOS_PATHS mkflpimg.c -o mkflpimg$(EXE_POSTFIX)
 -endif
--
- $(BUILDNO_TARGET): $(BUILDNO_OBJECTS)
-       ${host_gcc} $(BUILDNO_OBJECTS) $(BUILDNO_HOST_LFLAGS) -o $(BUILDNO_TARGET)
 -depends$(EXE_POSTFIX): depends.c
 -      @$(HOST_CC) $(CFLAGS) depends.c -o depends$(EXE_POSTFIX)
--
- $(BUILDNO_OBJECTS): %.o : %.c
-       ${host_gcc} $(BUILDNO_HOST_CFLAGS) -c $< -o $@
 -zlib_target:
 -      $(MAKE) --silent -C ../lib/zlib -f Makefile.host
--
- .PHONY: buildno_clean
- buildno_clean:
-       -@$(rm) $(BUILDNO_TARGET) $(BUILDNO_OBJECTS) 2>$(NUL)
- clean: buildno_clean
 -wmc_target:
 -      $(MAKE) --silent -C wmc wmc$(EXE_POSTFIX)
--
- include$(SEP)reactos$(SEP)buildno.h: $(BUILDNO_TARGET)
-       $(EXEPREFIX)$(BUILDNO_TARGET) include$(SEP)reactos$(SEP)buildno.h
 -cabman_target:
 -      $(MAKE) --silent -C cabman cabman$(EXE_POSTFIX)
 -
 -cdmake_target:
 -      $(MAKE) --silent -C cdmake cdmake$(EXE_POSTFIX)
 -
 -mkhive_target:
 -      $(MAKE) --silent -C mkhive mkhive$(EXE_POSTFIX)
 -
 -rgenstat_target:
 -      $(MAKE) --silent -C rgenstat rgenstat$(EXE_POSTFIX)
 -
 -wine2ros_target:
 -      $(MAKE) --silent -C wine2ros wine2ros$(EXE_POSTFIX)
 -
 -pipetools_target:
 -ifeq ($(HOST),mingw32-windows)
 -      $(MAKE) --silent -C pipetools
 -endif
 -
 -winebuild_target:
 -      $(MAKE) --silent -C winebuild winebuild$(EXE_POSTFIX)
 -
 -bin2res_target:
 -      $(MAKE) --silent -C bin2res bin2res$(EXE_POSTFIX)
 -
 -wrc_target: $(LIBS)
 -      $(MAKE) --silent -C wrc wrc$(EXE_POSTFIX)
 -
 -widl_target: lib_wpp
 -      $(MAKE) --silent -C widl widl$(EXE_POSTFIX)
 -
 -buildno_target:
 -      $(MAKE) --silent -C buildno buildno$(EXE_POSTFIX)
 -
 -lib_unicode:
 -      $(MAKE) -C unicode
 -
 -lib_wpp:
 -      $(MAKE) -C wpp
 -
 -.PHONY: wmc_target cdmake_target mkhive_target rgenstat_target pipetools_target wrc_target \
 -        widl_target buildno_target lib_unicode lib_wpp
 -
 -
 -ifeq ($(HOST),mingw32-linux)
 -clean:
 -      $(MAKE) --silent -C buildno clean
 -      $(MAKE) --silent -C widl clean
 -      $(MAKE) --silent -C wrc clean
 -      $(MAKE) --silent -C cabman clean
 -      $(MAKE) --silent -C cdmake clean
 -      $(MAKE) --silent -C mkhive clean
 -      $(MAKE) --silent -C wmc clean
 -      $(MAKE) --silent -C rgenstat clean
 -      $(MAKE) --silent -C wine2ros clean
 -      $(MAKE) --silent -C winebuild clean
 -      $(MAKE) --silent -C bin2res clean
 -      $(MAKE) --silent -C ../lib/zlib -f Makefile.host clean
 -      $(MAKE) -C wpp clean
 -      $(MAKE) -C unicode clean
 -      @rm mkconfig
 -      @rm $(TOOLS)
 -endif
 -ifeq ($(HOST),mingw32-windows)
 -clean:
 -      $(MAKE) --silent -C buildno clean
 -      $(MAKE) --silent -C widl clean
 -      $(MAKE) --silent -C wrc clean
 -      $(MAKE) --silent -C cabman clean
 -      $(MAKE) --silent -C cdmake clean
 -      $(MAKE) --silent -C mkhive clean
 -      $(MAKE) --silent -C wmc clean
 -      $(MAKE) --silent -C rgenstat clean
 -      $(MAKE) --silent -C pipetools clean
 -      $(MAKE) --silent -C wine2ros clean
 -      $(MAKE) --silent -C winebuild clean
 -      $(MAKE) --silent -C bin2res clean
 -      $(MAKE) --silent -C ../lib/zlib -f Makefile.host clean
 -      $(MAKE) -C wpp clean
 -      $(MAKE) -C unicode clean
 -      -@del *$(EXE_POSTFIX)
 -endif
--
 -.PHONY: all clean
++include tools/buildno/Makefile
 +include tools/cdmake/makefile
 +include tools/nci/makefile
 +include tools/rbuild/makefile
++include tools/unicode/Makefile
 +include tools/wmc/makefile
++include tools/wpp/Makefile
++include tools/wrc/makefile
index 0000000,a5e3cd7..a7136ac
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,42 +1,32 @@@
 -PATH_TO_TOP = ../..
++BUILDNO_BASE = tools$(SEP)buildno
 -TARGET = buildno$(EXE_POSTFIX)
++BUILDNO_TARGET = \
++      $(ROS_INTERMEDIATE)$(BUILDNO_BASE)$(SEP)buildno$(EXEPOSTFIX)
 -all: $(TARGET)
++BUILDNO_SOURCES = \
++      $(BUILDNO_BASE)$(SEP)buildno.cpp \
++      $(BUILDNO_BASE)$(SEP)exception.cpp \
++      $(BUILDNO_BASE)$(SEP)ssprintf.cpp \
++      $(BUILDNO_BASE)$(SEP)XML.cpp
 -OBJECTS = buildno.o XML.o exception.o ssprintf.o
++BUILDNO_OBJECTS = \
++      $(BUILDNO_SOURCES:.cpp=.o)
 -CLEAN_FILES = *.o buildno$(EXE_POSTFIX)
++BUILDNO_HOST_CFLAGS = -Iinclude/reactos -g -Werror -Wall
 -HOST_CXXFLAGS = -I$(PATH_TO_TOP)/include/reactos -g -Wall -Werror
++BUILDNO_HOST_LFLAGS = -g
 -buildno.o: buildno.cpp $(PATH_TO_TOP)/include/reactos/version.h
 -      $(HOST_CXX) $(HOST_CXXFLAGS) -o buildno.o -c buildno.cpp
++$(BUILDNO_TARGET): $(BUILDNO_OBJECTS)
++      ${host_gpp} $(BUILDNO_OBJECTS) $(BUILDNO_HOST_CFLAGS) -o $(BUILDNO_TARGET)
 -XML.o: XML.cpp
 -      $(HOST_CXX) $(HOST_CXXFLAGS) -o XML.o -c XML.cpp
++$(BUILDNO_OBJECTS): %.o : %.cpp include$(SEP)reactos$(SEP)version.h
++      ${host_gpp} $(BUILDNO_HOST_CFLAGS) -c $< -o $@
 -exception.o: exception.cpp
 -      $(HOST_CXX) $(HOST_CXXFLAGS) -o exception.o -c exception.cpp
++.PHONY: buildno_clean
++buildno_clean:
++      -@$(rm) $(BUILDNO_TARGET) $(BUILDNO_OBJECTS) 2>$(NUL)
 -ssprintf.o: ssprintf.cpp
 -      $(HOST_CXX) $(HOST_CXXFLAGS) -o ssprintf.o -c ssprintf.cpp
++BUILDNO_H = include$(SEP)reactos$(SEP)buildno.h
 -buildno$(EXE_POSTFIX): $(OBJECTS)
 -      $(HOST_CXX) -g $(OBJECTS) -o $(TARGET)
 -      @$(EXE_PREFIX)buildno$(EXE_POSTFIX)
 -
 -ifeq ($(HOST),mingw32-linux)
 -clean:
 -      -rm -f *.o $(TARGET)
 -      -rm $(PATH_TO_TOP)/include/reactos/buildno.h
 -endif
 -ifneq ($(HOST),mingw32-linux)
 -clean:
 -      -del *.o $(TARGET)
 -      -del ..\..\include\reactos\buildno.h
 -endif
 -
 -.PHONY: clean
 -
 -include $(PATH_TO_TOP)/rules.mak
++$(BUILDNO_H): $(BUILDNO_TARGET)
++      $(EXEPREFIX)$(BUILDNO_TARGET) $(BUILDNO_H)
Simple merge
index ea99758,0000000..fa848a5
mode 100644,000000..100644
--- /dev/null
@@@ -1,281 -1,0 +1,282 @@@
 +\r
 +#include "../../pch.h"\r
 +\r
 +#include "mingw.h"\r
 +#include <assert.h>\r
 +\r
 +using std::string;\r
 +using std::vector;\r
 +\r
 +static class MingwFactory : public Backend::Factory\r
 +{\r
 +public:\r
 +      MingwFactory() : Factory ( "mingw" ) {}\r
 +      Backend* operator() ( Project& project )\r
 +      {\r
 +              return new MingwBackend ( project );\r
 +      }\r
 +} factory;\r
 +\r
 +\r
 +MingwBackend::MingwBackend ( Project& project )\r
 +      : Backend ( project )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwBackend::Process ()\r
 +{\r
 +      CreateMakefile ();\r
 +      GenerateHeader ();\r
 +      GenerateGlobalVariables ();\r
 +      GenerateAllTarget ();\r
 +      GenerateInitTarget ();\r
 +      for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
 +      {\r
 +              Module& module = *ProjectNode.modules[i];\r
 +              ProcessModule ( module );\r
 +      }\r
 +      CheckAutomaticDependencies ();\r
 +      CloseMakefile ();\r
 +}\r
 +\r
 +void\r
 +MingwBackend::CreateMakefile ()\r
 +{\r
 +      fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" );\r
 +      if ( !fMakefile )\r
 +              throw AccessDeniedException ( ProjectNode.makefile );\r
 +      MingwModuleHandler::SetMakefile ( fMakefile );\r
 +}\r
 +\r
 +void\r
 +MingwBackend::CloseMakefile () const\r
 +{\r
 +      if (fMakefile)\r
 +              fclose ( fMakefile );\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateHeader () const\r
 +{\r
 +      fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation,\r
 +                                           const vector<Include*>& includes,\r
 +                                           const vector<Define*>& defines ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      fprintf (\r
 +              fMakefile,\r
 +              "PROJECT_CFLAGS %s",\r
 +              assignmentOperation );\r
 +      for ( i = 0; i < includes.size(); i++ )\r
 +      {\r
 +              fprintf (\r
 +                      fMakefile,\r
 +                      " -I%s",\r
 +                      includes[i]->directory.c_str() );\r
 +      }\r
 +\r
 +      for ( i = 0; i < defines.size(); i++ )\r
 +      {\r
 +              Define& d = *defines[i];\r
 +              fprintf (\r
 +                      fMakefile,\r
 +                      " -D%s",\r
 +                      d.name.c_str() );\r
 +              if ( d.value.size() )\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "=%s",\r
 +                              d.value.c_str() );\r
 +      }\r
 +      fprintf ( fMakefile, "\n" );\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateGlobalCFlagsAndProperties (\r
 +      const char* assignmentOperation,\r
 +      const vector<Property*>& properties,\r
 +      const vector<Include*>& includes,\r
 +      const vector<Define*>& defines,\r
 +      const vector<If*>& ifs ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      for ( i = 0; i < properties.size(); i++ )\r
 +      {\r
 +              Property& prop = *properties[i];\r
 +              fprintf ( fMakefile, "%s := %s\n",\r
 +                      prop.name.c_str(),\r
 +                      prop.value.c_str() );\r
 +      }\r
 +\r
 +      if ( includes.size() || defines.size() )\r
 +      {\r
 +              GenerateProjectCFlagsMacro ( assignmentOperation,\r
 +                                     includes,\r
 +                                     defines );\r
 +      }\r
 +\r
 +      for ( i = 0; i < ifs.size(); i++ )\r
 +      {\r
 +              If& rIf = *ifs[i];\r
 +              if ( rIf.defines.size() || rIf.includes.size() || rIf.ifs.size() )\r
 +              {\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "ifeq (\"$(%s)\",\"%s\")\n",\r
 +                              rIf.property.c_str(),\r
 +                              rIf.value.c_str() );\r
 +                      GenerateGlobalCFlagsAndProperties (\r
 +                              "+=",\r
 +                              rIf.properties,\r
 +                              rIf.includes,\r
 +                              rIf.defines,\r
 +                              rIf.ifs );\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "endif\n\n" );\r
 +              }\r
 +      }\r
 +}\r
 +\r
 +string\r
 +MingwBackend::GenerateProjectLFLAGS () const\r
 +{\r
 +      string lflags;\r
 +      for ( size_t i = 0; i < ProjectNode.linkerFlags.size (); i++ )\r
 +      {\r
 +              LinkerFlag& linkerFlag = *ProjectNode.linkerFlags[i];\r
 +              if ( lflags.length () > 0 )\r
 +                      lflags += " ";\r
 +              lflags += linkerFlag.flag;\r
 +      }\r
 +      return lflags;\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateGlobalVariables () const\r
 +{\r
 +      fprintf ( fMakefile, "mkdir = tools" SSEP "rmkdir" EXEPOSTFIX "\n" );\r
 +      fprintf ( fMakefile, "winebuild = tools" SSEP "winebuild" SSEP "winebuild" EXEPOSTFIX "\n" );\r
 +      fprintf ( fMakefile, "bin2res = tools" SSEP "bin2res" SSEP "bin2res" EXEPOSTFIX "\n" );\r
 +      fprintf ( fMakefile, "cabman = tools" SSEP "cabman" SSEP "cabman" EXEPOSTFIX "\n" );\r
 +      fprintf ( fMakefile, "cdmake = tools" SSEP "cdmake" SSEP "cdmake" EXEPOSTFIX "\n" );\r
++      fprintf ( fMakefile, "wrc = tools" SSEP "wrc" SSEP "wrc" EXEPOSTFIX "\n" );\r
 +      fprintf ( fMakefile, "\n" );\r
 +      GenerateGlobalCFlagsAndProperties (\r
 +              "=",\r
 +              ProjectNode.properties,\r
 +              ProjectNode.includes,\r
 +              ProjectNode.defines,\r
 +              ProjectNode.ifs );\r
 +      fprintf ( fMakefile, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );\r
 +      fprintf ( fMakefile, "PROJECT_LFLAGS = %s\n",\r
 +                GenerateProjectLFLAGS ().c_str () );\r
 +      fprintf ( fMakefile, "\n" );\r
 +}\r
 +\r
 +bool\r
 +MingwBackend::IncludeInAllTarget ( const Module& module ) const\r
 +{\r
 +      if ( module.type == ObjectLibrary )\r
 +              return false;\r
 +      if ( module.type == BootSector )\r
 +              return false;\r
 +      if ( module.type == Iso )\r
 +              return false;\r
 +      return true;\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateAllTarget () const\r
 +{\r
 +      fprintf ( fMakefile, "all:" );\r
 +      for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
 +      {\r
 +              Module& module = *ProjectNode.modules[i];\r
 +              if ( IncludeInAllTarget ( module ) )\r
 +              {\r
 +                      fprintf ( fMakefile,\r
 +                                " %s",\r
 +                                FixupTargetFilename ( module.GetPath () ).c_str () );\r
 +              }\r
 +      }\r
 +      fprintf ( fMakefile, "\n\t\n\n" );\r
 +}\r
 +\r
 +string\r
 +MingwBackend::GetBuildToolDependencies () const\r
 +{\r
 +      string dependencies;\r
 +      for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
 +      {\r
 +              Module& module = *ProjectNode.modules[i];\r
 +              if ( module.type == BuildTool )\r
 +              {\r
 +                      if ( dependencies.length () > 0 )\r
 +                              dependencies += " ";\r
 +                      dependencies += module.GetDependencyPath ();\r
 +              }\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +void\r
 +MingwBackend::GenerateInitTarget () const\r
 +{\r
 +      fprintf ( fMakefile,\r
 +                "init:");\r
 +      fprintf ( fMakefile,\r
 +                " $(ROS_INTERMEDIATE)." SSEP "tools" );\r
 +      fprintf ( fMakefile,\r
 +                " %s",\r
 +                GetBuildToolDependencies ().c_str () );\r
 +      fprintf ( fMakefile,\r
 +                " %s",\r
 +                "include" SSEP "reactos" SSEP "buildno.h" );\r
 +      fprintf ( fMakefile,\r
 +                "\n\t\n\n" );\r
 +\r
 +      fprintf ( fMakefile,\r
 +                "$(ROS_INTERMEDIATE)." SSEP "tools:\n" );\r
 +      fprintf ( fMakefile,\r
 +                "ifneq ($(ROS_INTERMEDIATE),)\n" );\r
 +      fprintf ( fMakefile,\r
 +                "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );\r
 +      fprintf ( fMakefile,\r
 +                "endif\n" );\r
 +      fprintf ( fMakefile,\r
 +                "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP "tools\n" );\r
 +      fprintf ( fMakefile,\r
 +                "\n" );\r
 +}\r
 +\r
 +void\r
 +MingwBackend::CheckAutomaticDependencies ()\r
 +{\r
 +      AutomaticDependency automaticDependency ( ProjectNode );\r
 +      automaticDependency.Process ();\r
 +      automaticDependency.CheckAutomaticDependencies ();\r
 +}\r
 +\r
 +void\r
 +MingwBackend::ProcessModule ( Module& module ) const\r
 +{\r
 +      MingwModuleHandler* h = MingwModuleHandler::LookupHandler (\r
 +              module.node.location,\r
 +              module.type );\r
 +      h->Process ( module );\r
 +      h->GenerateDirectoryTargets ();\r
 +}\r
 +\r
 +string\r
 +FixupTargetFilename ( const string& targetFilename )\r
 +{\r
 +      return string("$(ROS_INTERMEDIATE)") + NormalizeFilename ( targetFilename );\r
 +}\r
index 9a82bff,0000000..5098698
mode 100644,000000..100644
--- /dev/null
@@@ -1,2126 -1,0 +1,2144 @@@
-                      const string& newExtension )\r
 +#include "../../pch.h"\r
 +#include <assert.h>\r
 +\r
 +#include "../../rbuild.h"\r
 +#include "mingw.h"\r
 +#include "modulehandler.h"\r
 +\r
 +using std::string;\r
 +using std::vector;\r
 +using std::map;\r
 +using std::set;\r
 +\r
 +typedef set<string> set_string;\r
 +\r
 +map<ModuleType,MingwModuleHandler*>*\r
 +MingwModuleHandler::handler_map = NULL;\r
 +set_string\r
 +MingwModuleHandler::directory_set;\r
 +int\r
 +MingwModuleHandler::ref = 0;\r
 +\r
 +FILE*\r
 +MingwModuleHandler::fMakefile = NULL;\r
 +\r
 +string\r
 +ReplaceExtension ( const string& filename,\r
-                "\t%s %s -o %s ${%s}\n",\r
-                "${windres}",\r
++                   const string& newExtension )\r
 +{\r
 +      size_t index = filename.find_last_of ( '/' );\r
 +      if (index == string::npos) index = 0;\r
 +      string tmp = filename.substr( index, filename.size() - index );\r
 +      size_t ext_index = tmp.find_last_of( '.' );\r
 +      if (ext_index != string::npos) \r
 +              return filename.substr ( 0, index + ext_index ) + newExtension;\r
 +      return filename + newExtension;\r
 +}\r
 +\r
 +\r
 +MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype )\r
 +{\r
 +      if ( !ref++ )\r
 +              handler_map = new map<ModuleType,MingwModuleHandler*>;\r
 +      (*handler_map)[moduletype] = this;\r
 +}\r
 +\r
 +MingwModuleHandler::~MingwModuleHandler()\r
 +{\r
 +      if ( !--ref )\r
 +      {\r
 +              delete handler_map;\r
 +              handler_map = NULL;\r
 +      }\r
 +}\r
 +\r
 +const string &\r
 +MingwModuleHandler::PassThruCacheDirectory ( const string &file ) const \r
 +{\r
 +      directory_set.insert ( GetDirectory ( file ) );\r
 +      return file;\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::SetMakefile ( FILE* f )\r
 +{\r
 +      fMakefile = f;\r
 +}\r
 +\r
 +MingwModuleHandler*\r
 +MingwModuleHandler::LookupHandler ( const string& location,\r
 +                                    ModuleType moduletype )\r
 +{\r
 +      if ( !handler_map )\r
 +              throw Exception ( "internal tool error: no registered module handlers" );\r
 +      MingwModuleHandler* h = (*handler_map)[moduletype];\r
 +      if ( !h )\r
 +      {\r
 +              throw UnknownModuleTypeException ( location, moduletype );\r
 +              return NULL;\r
 +      }\r
 +      return h;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetWorkingDirectory () const\r
 +{\r
 +      return ".";\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetBasename ( const string& filename ) const\r
 +{\r
 +      size_t index = filename.find_last_of ( '.' );\r
 +      if ( index != string::npos )\r
 +              return filename.substr ( 0, index );\r
 +      return "";\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetActualSourceFilename ( const string& filename ) const\r
 +{\r
 +      string extension = GetExtension ( filename );\r
 +      if ( extension == ".spec" || extension == "SPEC" )\r
 +      {\r
 +              string basename = GetBasename ( filename );\r
 +              return basename + ".stubs.c";\r
 +      }\r
 +      else\r
 +              return filename;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetModuleArchiveFilename ( const Module& module ) const\r
 +{\r
 +      return ReplaceExtension ( FixupTargetFilename ( module.GetPath () ),\r
 +                                ".a" );\r
 +}\r
 +\r
 +bool\r
 +MingwModuleHandler::IsGeneratedFile ( const File& file ) const\r
 +{\r
 +      string extension = GetExtension ( file.name );\r
 +      if ( extension == ".spec" || extension == "SPEC" )\r
 +              return true;\r
 +      else\r
 +              return false;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetImportLibraryDependency ( const Module& importedModule ) const\r
 +{\r
 +      if ( importedModule.type == ObjectLibrary )\r
 +              return GetObjectsMacro ( importedModule );\r
 +      else\r
 +              return PassThruCacheDirectory ( FixupTargetFilename ( importedModule.GetDependencyPath () ) );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const\r
 +{\r
 +      string dependencies ( "" );\r
 +      for ( size_t i = 0; i < module.libraries.size (); i++ )\r
 +      {\r
 +              if ( dependencies.size () > 0 )\r
 +                      dependencies += " ";\r
 +              const Module* importedModule = module.project.LocateModule ( module.libraries[i]->name );\r
 +              assert ( importedModule != NULL );\r
 +              dependencies += GetImportLibraryDependency ( *importedModule );\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetModuleDependencies ( const Module& module ) const\r
 +{\r
 +      if ( module.dependencies.size () == 0 )\r
 +              return "";\r
 +      \r
 +      string dependencies ( "" );\r
 +      for ( size_t i = 0; i < module.dependencies.size (); i++ )\r
 +      {\r
 +              if ( dependencies.size () > 0 )\r
 +                      dependencies += " ";\r
 +              const Dependency* dependency = module.dependencies[i];\r
 +              const Module* dependencyModule = dependency->dependencyModule;\r
 +              dependencies += dependencyModule->GetTargets ();\r
 +      }\r
 +      string definitionDependencies = GetDefinitionDependencies ( module );\r
 +      if ( dependencies.length () > 0 && definitionDependencies.length () > 0 )\r
 +              dependencies += " " + definitionDependencies;\r
 +      else if ( definitionDependencies.length () > 0 )\r
 +              dependencies = definitionDependencies;\r
 +      return dependencies;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetAllDependencies ( const Module& module ) const\r
 +{\r
 +      string dependencies = GetImportLibraryDependencies ( module );\r
 +      string s = GetModuleDependencies ( module );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              dependencies += " ";\r
 +              dependencies += s;\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetSourceFilenames ( const Module& module,\r
 +                                           bool includeGeneratedFiles ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      string sourceFilenames ( "" );\r
 +      for ( i = 0; i < module.files.size (); i++ )\r
 +      {\r
 +              if ( includeGeneratedFiles || !IsGeneratedFile ( *module.files[i] ) )\r
 +                      sourceFilenames += " " + GetActualSourceFilename ( module.files[i]->name );\r
 +      }\r
 +      vector<If*> ifs = module.ifs;\r
 +      for ( i = 0; i < ifs.size (); i++ )\r
 +      {\r
 +              size_t j;\r
 +              If& rIf = *ifs[i];\r
 +              for ( j = 0; j < rIf.ifs.size (); j++ )\r
 +                      ifs.push_back ( rIf.ifs[j] );\r
 +              for ( j = 0; j < rIf.files.size (); j++ )\r
 +              {\r
 +                      if ( includeGeneratedFiles || !IsGeneratedFile ( *rIf.files[j] ) )\r
 +                              sourceFilenames += " " + GetActualSourceFilename ( rIf.files[j]->name );\r
 +              }\r
 +      }\r
 +      return sourceFilenames;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetSourceFilenames ( const Module& module ) const\r
 +{\r
 +      return GetSourceFilenames ( module,\r
 +                                  true );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module& module ) const\r
 +{\r
 +      return GetSourceFilenames ( module,\r
 +                                  false );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetObjectFilename ( const string& sourceFilename )\r
 +{\r
 +      string newExtension;\r
 +      string extension = GetExtension ( sourceFilename );\r
 +      if ( extension == ".rc" || extension == ".RC" )\r
 +              newExtension = ".coff";\r
 +      else if ( extension == ".spec" || extension == ".SPEC" )\r
 +              newExtension = ".stubs.o";\r
 +      else\r
 +              newExtension = ".o";\r
 +      return FixupTargetFilename ( ReplaceExtension ( sourceFilename, newExtension ) );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetObjectFilenames ( const Module& module ) const\r
 +{\r
 +      if ( module.files.size () == 0 )\r
 +              return "";\r
 +      \r
 +      string objectFilenames ( "" );\r
 +      for ( size_t i = 0; i < module.files.size (); i++ )\r
 +      {\r
 +              if ( objectFilenames.size () > 0 )\r
 +                      objectFilenames += " ";\r
 +              objectFilenames += PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( module.files[i]->name ) );\r
 +      }\r
 +      return objectFilenames;\r
 +}\r
 +\r
 +bool\r
 +MingwModuleHandler::IncludeDirectoryTarget ( const string& directory ) const\r
 +{\r
 +      if ( directory == "$(ROS_INTERMEDIATE)." SSEP "tools")\r
 +              return false;\r
 +      else\r
 +              return true;\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateDirectoryTargets () const\r
 +{\r
 +      if ( directory_set.size () == 0 )\r
 +              return;\r
 +      \r
 +      set_string::iterator i;\r
 +      fprintf ( fMakefile, "directories::" );\r
 +\r
 +      for ( i = directory_set.begin ();\r
 +            i != directory_set.end ();\r
 +            i++ )\r
 +      {\r
 +              if ( IncludeDirectoryTarget ( *i ) )\r
 +              {\r
 +                      fprintf ( fMakefile,\r
 +                                " %s",\r
 +                                i->c_str () );\r
 +              }\r
 +      }\r
 +\r
 +      fprintf ( fMakefile, "\n\n" );\r
 +\r
 +      for ( i = directory_set.begin ();\r
 +            i != directory_set.end ();\r
 +            i++ )\r
 +      {\r
 +              if ( IncludeDirectoryTarget ( *i ) )\r
 +              {\r
 +                      fprintf ( fMakefile,\r
 +                                "%s ",\r
 +                                i->c_str () );\r
 +              }\r
 +      }\r
 +\r
 +      fprintf ( fMakefile, \r
 +                "::\n\t${mkdir} $@\n\n" );\r
 +\r
 +      directory_set.clear ();\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector<Define*>& defines ) const\r
 +{\r
 +      string parameters;\r
 +      for ( size_t i = 0; i < defines.size (); i++ )\r
 +      {\r
 +              Define& define = *defines[i];\r
 +              if (parameters.length () > 0)\r
 +                      parameters += " ";\r
 +              parameters += "-D";\r
 +              parameters += define.name;\r
 +              if (define.value.length () > 0)\r
 +              {\r
 +                      parameters += "=";\r
 +                      parameters += define.value;\r
 +              }\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateGccDefineParameters ( const Module& module ) const\r
 +{\r
 +      string parameters = GenerateGccDefineParametersFromVector ( module.project.defines );\r
 +      string s = GenerateGccDefineParametersFromVector ( module.defines );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              parameters += " ";\r
 +              parameters += s;\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::ConcatenatePaths ( const string& path1,\r
 +                                         const string& path2 ) const\r
 +{\r
 +      if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )\r
 +              return path2;\r
 +      if ( path1[path1.length ()] == CSEP )\r
 +              return path1 + path2;\r
 +      else\r
 +              return path1 + CSEP + path2;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const\r
 +{\r
 +      string parameters;\r
 +      for ( size_t i = 0; i < includes.size (); i++ )\r
 +      {\r
 +              Include& include = *includes[i];\r
 +              if ( parameters.length () > 0 )\r
 +                      parameters += " ";\r
 +              parameters += "-I" + include.directory;\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const\r
 +{\r
 +      string parameters = GenerateGccIncludeParametersFromVector ( module.includes );\r
 +      string s = GenerateGccIncludeParametersFromVector ( module.project.includes );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              parameters += " ";\r
 +              parameters += s;\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const\r
 +{\r
 +      string parameters;\r
 +      for ( size_t i = 0; i < compilerFlags.size (); i++ )\r
 +      {\r
 +              CompilerFlag& compilerFlag = *compilerFlags[i];\r
 +              if ( parameters.length () > 0 )\r
 +                      parameters += " ";\r
 +              parameters += compilerFlag.flag;\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const\r
 +{\r
 +      string parameters;\r
 +      for ( size_t i = 0; i < linkerFlags.size (); i++ )\r
 +      {\r
 +              LinkerFlag& linkerFlag = *linkerFlags[i];\r
 +              if ( parameters.length () > 0 )\r
 +                      parameters += " ";\r
 +              parameters += linkerFlag.flag;\r
 +      }\r
 +      return parameters;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateLinkerParameters ( const Module& module ) const\r
 +{\r
 +      return GenerateLinkerParametersFromVector ( module.linkerFlags );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacro ( const char* assignmentOperation,\r
 +                                    const string& macro,\r
 +                                    const vector<Include*>& includes,\r
 +                                    const vector<Define*>& defines,\r
 +                                    const vector<CompilerFlag*>* compilerFlags ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      fprintf (\r
 +              fMakefile,\r
 +              "%s %s",\r
 +              macro.c_str(),\r
 +              assignmentOperation );\r
 +      \r
 +      if ( compilerFlags != NULL )\r
 +      {\r
 +              string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags );\r
 +              if ( compilerParameters.size () > 0 )\r
 +              {\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              " %s",\r
 +                              compilerParameters.c_str () );\r
 +              }\r
 +      }\r
 +\r
 +      for ( i = 0; i < includes.size(); i++ )\r
 +      {\r
 +              fprintf (\r
 +                      fMakefile,\r
 +                      " -I%s",\r
 +                      includes[i]->directory.c_str() );\r
 +      }\r
 +      for ( i = 0; i < defines.size(); i++ )\r
 +      {\r
 +              Define& d = *defines[i];\r
 +              fprintf (\r
 +                      fMakefile,\r
 +                      " -D%s",\r
 +                      d.name.c_str() );\r
 +              if ( d.value.size() )\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "=%s",\r
 +                              d.value.c_str() );\r
 +      }\r
 +      fprintf ( fMakefile, "\n" );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacros (\r
 +      const char* assignmentOperation,\r
 +      const vector<File*>& files,\r
 +      const vector<Include*>& includes,\r
 +      const vector<Define*>& defines,\r
 +      const vector<CompilerFlag*>* compilerFlags,\r
 +      const vector<LinkerFlag*>* linkerFlags,\r
 +      const vector<If*>& ifs,\r
 +      const string& cflags_macro,\r
 +      const string& nasmflags_macro,\r
 +      const string& windresflags_macro,\r
 +      const string& linkerflags_macro,\r
 +      const string& objs_macro) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      if ( includes.size() || defines.size() )\r
 +      {\r
 +              GenerateMacro ( assignmentOperation,\r
 +                              cflags_macro,\r
 +                              includes,\r
 +                              defines,\r
 +                              compilerFlags );\r
 +              GenerateMacro ( assignmentOperation,\r
 +                              windresflags_macro,\r
 +                              includes,\r
 +                              defines,\r
 +                              compilerFlags );\r
 +      }\r
 +      \r
 +      if ( linkerFlags != NULL )\r
 +      {\r
 +              string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );\r
 +              if ( linkerParameters.size () > 0 )\r
 +              {\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "%s %s %s\n",\r
 +                              linkerflags_macro.c_str (),\r
 +                              assignmentOperation,\r
 +                              linkerParameters.c_str() );\r
 +              }\r
 +      }\r
 +      \r
 +      if ( files.size() )\r
 +      {\r
 +              for ( i = 0; i < files.size(); i++ )\r
 +              {\r
 +                      if ( files[i]->first )\r
 +                      {\r
 +                              fprintf ( fMakefile,\r
 +                                      "%s := %s $(%s)\n",\r
 +                                      objs_macro.c_str(),\r
 +                                      PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ).c_str (),\r
 +                                      objs_macro.c_str() );\r
 +                      }\r
 +              }\r
 +              fprintf (\r
 +                      fMakefile,\r
 +                      "%s %s",\r
 +                      objs_macro.c_str(),\r
 +                      assignmentOperation );\r
 +              for ( i = 0; i < files.size(); i++ )\r
 +              {\r
 +                      string extension = GetExtension ( files[i]->name );\r
 +                      if ( extension != ".spec"\r
 +                        && extension != ".SPEC"\r
 +                        && !files[i]->first )\r
 +                      {\r
 +                              fprintf (\r
 +                                      fMakefile,\r
 +                                      "%s%s",\r
 +                                      ( i%10 == 9 ? "\\\n\t" : " " ),\r
 +                                      PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ).c_str () );\r
 +                      }\r
 +              }\r
 +              fprintf ( fMakefile, "\n" );\r
 +      }\r
 +\r
 +      for ( i = 0; i < ifs.size(); i++ )\r
 +      {\r
 +              If& rIf = *ifs[i];\r
 +              if ( rIf.defines.size() || rIf.includes.size() || rIf.files.size() || rIf.ifs.size() )\r
 +              {\r
 +                      fprintf (\r
 +                              fMakefile,\r
 +                              "ifeq (\"$(%s)\",\"%s\")\n",\r
 +                              rIf.property.c_str(),\r
 +                              rIf.value.c_str() );\r
 +                      GenerateMacros (\r
 +                              "+=",\r
 +                              rIf.files,\r
 +                              rIf.includes,\r
 +                              rIf.defines,\r
 +                              NULL,\r
 +                              NULL,\r
 +                              rIf.ifs,\r
 +                              cflags_macro,\r
 +                              nasmflags_macro,\r
 +                              windresflags_macro,\r
 +                              linkerflags_macro,\r
 +                              objs_macro );\r
 +                      fprintf ( \r
 +                              fMakefile,\r
 +                              "endif\n\n" );\r
 +              }\r
 +      }\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacros (\r
 +      const Module& module,\r
 +      const string& cflags_macro,\r
 +      const string& nasmflags_macro,\r
 +      const string& windresflags_macro,\r
 +      const string& linkerflags_macro,\r
 +      const string& objs_macro) const\r
 +{\r
 +      GenerateMacros (\r
 +              "=",\r
 +              module.files,\r
 +              module.includes,\r
 +              module.defines,\r
 +              &module.compilerFlags,\r
 +              &module.linkerFlags,\r
 +              module.ifs,\r
 +              cflags_macro,\r
 +              nasmflags_macro,\r
 +              windresflags_macro,\r
 +              linkerflags_macro,\r
 +              objs_macro );\r
 +      fprintf ( fMakefile, "\n" );\r
 +\r
 +      fprintf (\r
 +              fMakefile,\r
 +              "%s += $(PROJECT_CFLAGS)\n\n",\r
 +              cflags_macro.c_str () );\r
 +\r
 +      fprintf (\r
 +              fMakefile,\r
 +              "%s += $(PROJECT_RCFLAGS)\n\n",\r
 +              windresflags_macro.c_str () );\r
 +\r
 +      fprintf (\r
 +              fMakefile,\r
 +              "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",\r
 +              module.name.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateGccCommand ( const Module& module,\r
 +                                         const string& sourceFilename,\r
 +                                         const string& cc,\r
 +                                         const string& cflagsMacro ) const\r
 +{\r
 +      string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                objectFilename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
 +               "\t%s -c %s -o %s %s\n",\r
 +               cc.c_str (),\r
 +               sourceFilename.c_str (),\r
 +               objectFilename.c_str (),\r
 +               cflagsMacro.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateGccAssemblerCommand ( const Module& module,\r
 +                                                  const string& sourceFilename,\r
 +                                                  const string& cc,\r
 +                                                  const string& cflagsMacro ) const\r
 +{\r
 +      string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                objectFilename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",\r
 +                cc.c_str (),\r
 +                sourceFilename.c_str (),\r
 +                objectFilename.c_str (),\r
 +                cflagsMacro.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateNasmCommand ( const Module& module,\r
 +                                          const string& sourceFilename,\r
 +                                          const string& nasmflagsMacro ) const\r
 +{\r
 +      string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                objectFilename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t%s -f win32 %s -o %s %s\n",\r
 +                "nasm",\r
 +                sourceFilename.c_str (),\r
 +                objectFilename.c_str (),\r
 +                nasmflagsMacro.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateWindresCommand ( const Module& module,\r
 +                                             const string& sourceFilename,\r
 +                                             const string& windresflagsMacro ) const\r
 +{\r
 +      string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
++  string rciFilename = ReplaceExtension ( sourceFilename,\r
++                                          ".rci" );\r
++  string resFilename = ReplaceExtension ( sourceFilename,\r
++                                          ".res" );\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                objectFilename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
-                objectFilename.c_str (),\r
-                windresflagsMacro.c_str () );\r
++               "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",\r
++               windresflagsMacro.c_str (),\r
 +               sourceFilename.c_str (),\r
++               rciFilename.c_str () );\r
++      fprintf ( fMakefile,\r
++               "\t${wrc} ${%s} %s %s\n",\r
++           windresflagsMacro.c_str (),\r
++               rciFilename.c_str (),\r
++               resFilename.c_str () );\r
++      fprintf ( fMakefile,\r
++               "\t${rm} %s\n",\r
++               rciFilename.c_str () );\r
++      fprintf ( fMakefile,\r
++               "\t${windres} %s -o %s\n",\r
++               resFilename.c_str (),\r
++               objectFilename.c_str () );\r
++      fprintf ( fMakefile,\r
++               "\t${rm} %s\n",\r
++               resFilename.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateWinebuildCommands ( const Module& module,\r
 +                                                const string& sourceFilename ) const\r
 +{\r
 +      string basename = GetBasename ( sourceFilename );\r
 +      fprintf ( fMakefile,\r
 +                "%s.spec.def: %s\n",\r
 +                basename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t%s --def=%s -o %s.spec.def\n",\r
 +                "${winebuild}",\r
 +                sourceFilename.c_str (),\r
 +                basename.c_str () );\r
 +\r
 +      fprintf ( fMakefile,\r
 +                "%s.stubs.c: %s\n",\r
 +                basename.c_str (),\r
 +                sourceFilename.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t%s --pedll=%s -o %s.stubs.c\n",\r
 +                "${winebuild}",\r
 +                sourceFilename.c_str (),\r
 +                basename.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateCommands ( const Module& module,\r
 +                                       const string& sourceFilename,\r
 +                                       const string& cc,\r
 +                                       const string& cppc,\r
 +                                       const string& cflagsMacro,\r
 +                                       const string& nasmflagsMacro,\r
 +                                       const string& windresflagsMacro ) const\r
 +{\r
 +      string extension = GetExtension ( sourceFilename );\r
 +      if ( extension == ".c" || extension == ".C" )\r
 +      {\r
 +              GenerateGccCommand ( module,\r
 +                                   sourceFilename,\r
 +                                   cc,\r
 +                                   cflagsMacro );\r
 +              return;\r
 +      }\r
 +      else if ( extension == ".cc" || extension == ".CC" ||\r
 +                extension == ".cpp" || extension == ".CPP" ||\r
 +                extension == ".cxx" || extension == ".CXX" )\r
 +      {\r
 +              GenerateGccCommand ( module,\r
 +                                   sourceFilename,\r
 +                                   cppc,\r
 +                                   cflagsMacro );\r
 +              return;\r
 +      }\r
 +      else if ( extension == ".s" || extension == ".S" )\r
 +      {\r
 +              GenerateGccAssemblerCommand ( module,\r
 +                                            sourceFilename,\r
 +                                            cc,\r
 +                                            cflagsMacro );\r
 +              return;\r
 +      }\r
 +      else if ( extension == ".asm" || extension == ".ASM" )\r
 +      {\r
 +              GenerateNasmCommand ( module,\r
 +                                    sourceFilename,\r
 +                                    nasmflagsMacro );\r
 +              return;\r
 +      }\r
 +      else if ( extension == ".rc" || extension == ".RC" )\r
 +      {\r
 +              GenerateWindresCommand ( module,\r
 +                                       sourceFilename,\r
 +                                       windresflagsMacro );\r
 +              return;\r
 +      }\r
 +      else if ( extension == ".spec" || extension == ".SPEC" )\r
 +      {\r
 +              GenerateWinebuildCommands ( module,\r
 +                                          sourceFilename );\r
 +              GenerateGccCommand ( module,\r
 +                                   GetActualSourceFilename ( sourceFilename ),\r
 +                                   cc,\r
 +                                   cflagsMacro );\r
 +              return;\r
 +      }\r
 +\r
 +      throw InvalidOperationException ( __FILE__,\r
 +                                        __LINE__,\r
 +                                        "Unsupported filename extension '%s' in file '%s'",\r
 +                                        extension.c_str (),\r
 +                                        sourceFilename.c_str () );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateLinkerCommand ( const Module& module,\r
 +                                            const string& linker,\r
 +                                            const string& linkerParameters,\r
 +                                            const string& objectFilenames ) const\r
 +{\r
 +      string targetName ( module.GetTargetName () );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +      if ( module.importLibrary != NULL )\r
 +      {\r
 +              static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +              string base_tmp = ros_junk + module.name + ".base.tmp";\r
 +              string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
 +              string temp_exp = ros_junk + module.name + ".temp.exp";\r
 +\r
 +              fprintf ( fMakefile,\r
 +                        "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",\r
 +                        linker.c_str (),\r
 +                        linkerParameters.c_str (),\r
 +                        base_tmp.c_str (),\r
 +                        junk_tmp.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        importLibraryDependencies.c_str (),\r
 +                        GetLinkerMacro ( module ).c_str () );\r
 +\r
 +              fprintf ( fMakefile,\r
 +                        "\t${rm} %s\n",\r
 +                        junk_tmp.c_str () );\r
 +\r
 +              string killAt = module.mangledSymbols ? "" : "--kill-at";\r
 +              fprintf ( fMakefile,\r
 +                        "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",\r
 +                        targetName.c_str (),\r
 +                        base_tmp.c_str (),\r
 +                        ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),\r
 +                        temp_exp.c_str (),\r
 +                        killAt.c_str () );\r
 +\r
 +              fprintf ( fMakefile,\r
 +                        "\t${rm} %s\n",\r
 +                        base_tmp.c_str () );\r
 +\r
 +              fprintf ( fMakefile,\r
 +                        "\t%s %s %s -o %s %s %s %s\n\n",\r
 +                        linker.c_str (),\r
 +                        linkerParameters.c_str (),\r
 +                        temp_exp.c_str (),\r
 +                        target.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        importLibraryDependencies.c_str (),\r
 +                        GetLinkerMacro ( module ).c_str () );\r
 +\r
 +              fprintf ( fMakefile,\r
 +                        "\t${rm} %s\n\n",\r
 +                        temp_exp.c_str () );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile,\r
 +                        "\t%s %s -o %s %s %s %s\n\n",\r
 +                        linker.c_str (),\r
 +                        linkerParameters.c_str (),\r
 +                        target.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        importLibraryDependencies.c_str (),\r
 +                        GetLinkerMacro ( module ).c_str () );\r
 +      }\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,\r
 +                                                const vector<File*>& files,\r
 +                                                const vector<If*>& ifs,\r
 +                                                const string& cc,\r
 +                                                const string& cppc,\r
 +                                                const string& cflagsMacro,\r
 +                                                const string& nasmflagsMacro,\r
 +                                                const string& windresflagsMacro ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      for ( i = 0; i < files.size (); i++ )\r
 +      {\r
 +              string sourceFilename = files[i]->name;\r
 +              GenerateCommands ( module,\r
 +                                 sourceFilename,\r
 +                                 cc,\r
 +                                 cppc,\r
 +                                 cflagsMacro,\r
 +                                 nasmflagsMacro,\r
 +                                 windresflagsMacro );\r
 +              fprintf ( fMakefile,\r
 +                        "\n" );\r
 +      }\r
 +\r
 +      for ( i = 0; i < ifs.size(); i++ )\r
 +      {\r
 +              GenerateObjectFileTargets ( module,\r
 +                                          ifs[i]->files,\r
 +                                          ifs[i]->ifs,\r
 +                                          cc,\r
 +                                          cppc,\r
 +                                          cflagsMacro,\r
 +                                          nasmflagsMacro,\r
 +                                          windresflagsMacro );\r
 +      }\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,\r
 +                                                const string& cc,\r
 +                                                const string& cppc,\r
 +                                                const string& cflagsMacro,\r
 +                                                const string& nasmflagsMacro,\r
 +                                                const string& windresflagsMacro ) const\r
 +{\r
 +      GenerateObjectFileTargets ( module,\r
 +                                  module.files,\r
 +                                  module.ifs,\r
 +                                  cc,\r
 +                                  cppc,\r
 +                                  cflagsMacro,\r
 +                                  nasmflagsMacro,\r
 +                                  windresflagsMacro );\r
 +      fprintf ( fMakefile, "\n" );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GetCleanTargets ( vector<string>& out,\r
 +                                      const vector<File*>& files,\r
 +                                      const vector<If*>& ifs ) const\r
 +{\r
 +      size_t i;\r
 +\r
 +      for ( i = 0; i < files.size(); i++ )\r
 +              out.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ) );\r
 +\r
 +      for ( i = 0; i < ifs.size(); i++ )\r
 +              GetCleanTargets ( out, ifs[i]->files, ifs[i]->ifs );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GenerateArchiveTarget ( const Module& module,\r
 +                                            const string& ar,\r
 +                                            const string& objs_macro ) const\r
 +{\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      \r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                archiveFilename.c_str (),\r
 +                objs_macro.c_str ());\r
 +\r
 +      fprintf ( fMakefile,\r
 +                "\t%s -rc %s %s\n\n",\r
 +                ar.c_str (),\r
 +                archiveFilename.c_str (),\r
 +                objs_macro.c_str ());\r
 +\r
 +      return archiveFilename;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetCFlagsMacro ( const Module& module ) const\r
 +{\r
 +      return ssprintf ( "$(%s_CFLAGS)",\r
 +                        module.name.c_str () );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetObjectsMacro ( const Module& module ) const\r
 +{\r
 +      return ssprintf ( "$(%s_OBJS)",\r
 +                        module.name.c_str () );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetLinkerMacro ( const Module& module ) const\r
 +{\r
 +      return ssprintf ( "$(%s_LFLAGS)",\r
 +                        module.name.c_str () );\r
 +}\r
 +                                          \r
 +void\r
 +MingwModuleHandler::GenerateMacrosAndTargets (\r
 +      const Module& module,\r
 +      const string& cc,\r
 +      const string& cppc,\r
 +      const string& ar,\r
 +      const string* cflags,\r
 +      const string* nasmflags ) const\r
 +{\r
 +      string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());\r
 +      string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());\r
 +      string windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());\r
 +      string linkerFlagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());\r
 +      string objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());\r
 +\r
 +      GenerateMacros ( module,\r
 +                      cflagsMacro,\r
 +                      nasmflagsMacro,\r
 +                      windresflagsMacro,\r
 +                      linkerFlagsMacro,\r
 +                      objectsMacro );\r
 +\r
 +      if ( cflags != NULL )\r
 +      {\r
 +              fprintf ( fMakefile,\r
 +                        "%s += %s\n\n",\r
 +                        cflagsMacro.c_str (),\r
 +                        cflags->c_str () );\r
 +      }\r
 +\r
 +      if ( nasmflags != NULL )\r
 +      {\r
 +              fprintf ( fMakefile,\r
 +                        "%s += %s\n\n",\r
 +                        nasmflagsMacro.c_str (),\r
 +                        nasmflags->c_str () );\r
 +      }\r
 +\r
 +      // generate phony target for module name\r
 +      fprintf ( fMakefile, ".PHONY: %s\n",\r
 +              module.name.c_str () );\r
 +      fprintf ( fMakefile, "%s: %s\n\n",\r
 +              module.name.c_str (),\r
 +              FixupTargetFilename ( module.GetPath () ).c_str () );\r
 +\r
 +      // future references to the macros will be to get their values\r
 +      cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());\r
 +      nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());\r
 +      objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());\r
 +\r
 +      string ar_target = GenerateArchiveTarget ( module, ar, objectsMacro );\r
 +      GenerateObjectFileTargets ( module,\r
 +                                  cc,\r
 +                                  cppc,\r
 +                                  cflagsMacro,\r
 +                                  nasmflagsMacro,\r
 +                                  windresflagsMacro );\r
 +\r
 +      vector<string> clean_files;\r
 +      clean_files.push_back ( FixupTargetFilename(module.GetPath()) );\r
 +      clean_files.push_back ( ar_target );\r
 +      GetCleanTargets ( clean_files, module.files, module.ifs );\r
 +\r
 +      fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );\r
 +      fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );\r
 +      for ( size_t i = 0; i < clean_files.size(); i++ )\r
 +      {\r
 +              if ( 9==(i%10) )\r
 +                      fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );\r
 +              fprintf ( fMakefile, " %s", clean_files[i].c_str() );\r
 +      }\r
 +      fprintf ( fMakefile, " 2>$(NUL)\n" );\r
 +      fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const\r
 +{\r
 +      GenerateMacrosAndTargets ( module,\r
 +                                 "${host_gcc}",\r
 +                                 "${host_gpp}",\r
 +                                 "${host_ar}",\r
 +                                 NULL,\r
 +                                 NULL );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const\r
 +{\r
 +      GenerateMacrosAndTargetsTarget ( module,\r
 +                                       NULL,\r
 +                                       NULL );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,\r
 +                                                       const string* cflags,\r
 +                                                       const string* nasmflags ) const\r
 +{\r
 +      GenerateMacrosAndTargets ( module,\r
 +                                "${gcc}",\r
 +                                "${gpp}",\r
 +                                "${ar}",\r
 +                                cflags,\r
 +                                nasmflags );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const\r
 +{\r
 +      string dependencies;\r
 +      for ( size_t i = 0; i < module.invocations.size (); i++ )\r
 +      {\r
 +              Invoke& invoke = *module.invocations[i];\r
 +              if (invoke.invokeModule == &module)\r
 +                      /* Protect against circular dependencies */\r
 +                      continue;\r
 +              if ( dependencies.length () > 0 )\r
 +                      dependencies += " ";\r
 +              dependencies += invoke.GetTargets ();\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateInvocations ( const Module& module ) const\r
 +{\r
 +      if ( module.invocations.size () == 0 )\r
 +              return;\r
 +      \r
 +      for ( size_t i = 0; i < module.invocations.size (); i++ )\r
 +      {\r
 +              const Invoke& invoke = *module.invocations[i];\r
 +\r
 +              if ( invoke.invokeModule->type != BuildTool )\r
 +              {\r
 +                      throw InvalidBuildFileException ( module.node.location,\r
 +                                                        "Only modules of type buildtool can be invoked." );\r
 +              }\r
 +\r
 +              string invokeTarget = module.GetInvocationTarget ( i );\r
 +              fprintf ( fMakefile,\r
 +                        ".PHONY: %s\n\n",\r
 +                        invokeTarget.c_str () );\r
 +              fprintf ( fMakefile,\r
 +                        "%s: %s\n\n",\r
 +                        invokeTarget.c_str (),\r
 +                        invoke.GetTargets ().c_str () );\r
 +              fprintf ( fMakefile,\r
 +                        "%s: %s\n",\r
 +                        invoke.GetTargets ().c_str (),\r
 +                        FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );\r
 +              fprintf ( fMakefile,\r
 +                        "\t%s %s\n\n",\r
 +                        FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),\r
 +                        invoke.GetParameters ().c_str () );\r
 +      }\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) const\r
 +{\r
 +      return ssprintf ( "%s_precondition",\r
 +                        module.name.c_str () );\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const\r
 +{\r
 +      /* Avoid circular dependency */\r
 +      if ( module.type == BuildTool || module.name == "zlib" )\r
 +              return "$(ROS_INTERMEDIATE)." SSEP "tools $(ROS_INTERMEDIATE)." SSEP "lib" SSEP "zlib";\r
 +      else\r
 +              return "init";\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const\r
 +{\r
 +      string preconditionDependenciesName = GetPreconditionDependenciesName ( module );\r
 +      string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module );\r
 +      string dependencies = GetDefaultDependencies ( module );\r
 +      string s = GetModuleDependencies ( module );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              if ( dependencies.length () > 0 )\r
 +                      dependencies += " ";\r
 +              dependencies += s;\r
 +      }\r
 +\r
 +      s = GetInvocationDependencies ( module );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              if ( dependencies.length () > 0 )\r
 +                      dependencies += " ";\r
 +              dependencies += s;\r
 +      }\r
 +      \r
 +      fprintf ( fMakefile,\r
 +                ".PHONY: %s\n\n",\r
 +                preconditionDependenciesName.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n\n",\r
 +                preconditionDependenciesName.c_str (),\r
 +                dependencies.c_str () );\r
 +      const char* p = sourceFilenames.c_str();\r
 +      const char* end = p + strlen(p);\r
 +      while ( p < end )\r
 +      {\r
 +              const char* p2 = &p[512];\r
 +              if ( p2 > end )\r
 +                      p2 = end;\r
 +              while ( p2 > p && !isspace(*p2) )\r
 +                      --p2;\r
 +              if ( p == p2 )\r
 +              {\r
 +                      p2 = strpbrk ( p, " \t" );\r
 +                      if ( !p2 )\r
 +                              p2 = end;\r
 +              }\r
 +              fprintf ( fMakefile,\r
 +                        "%.*s: %s\n",\r
 +                        p2-p,\r
 +                        p,\r
 +                        preconditionDependenciesName.c_str ());\r
 +              p = p2;\r
 +              p += strspn ( p, " \t" );\r
 +      }\r
 +      fprintf ( fMakefile, "\n" );\r
 +}\r
 +\r
 +void\r
 +MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module& module ) const\r
 +{\r
 +      if ( module.importLibrary != NULL )\r
 +      {\r
 +              string definitionDependencies = GetDefinitionDependencies ( module );\r
 +              fprintf ( fMakefile, "%s: %s\n",\r
 +                        FixupTargetFilename( module.GetDependencyPath () ).c_str (),\r
 +                        definitionDependencies.c_str () );\r
 +\r
 +              string killAt = module.mangledSymbols ? "" : "--kill-at";\r
 +              fprintf ( fMakefile,\r
 +                        "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",\r
 +                        module.GetTargetName ().c_str (),\r
 +                        ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),\r
 +                        FixupTargetFilename ( module.GetDependencyPath () ).c_str (),\r
 +                        killAt.c_str () );\r
 +      }\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetSpecObjectDependencies ( const string& filename ) const\r
 +{\r
 +      string basename = GetBasename ( filename );\r
 +      return basename + ".spec.def" + " " + basename + ".stubs.c";\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const\r
 +{\r
 +      string dependencies;\r
 +      string dkNkmLibNoFixup = "dk/nkm/lib";\r
 +      dependencies += FixupTargetFilename ( dkNkmLibNoFixup );\r
 +      PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP );\r
 +      for ( size_t i = 0; i < module.files.size (); i++ )\r
 +      {\r
 +              File& file = *module.files[i];\r
 +              string extension = GetExtension ( file.name );\r
 +              if ( extension == ".spec" || extension == ".SPEC" )\r
 +              {\r
 +                      if ( dependencies.length () > 0 )\r
 +                              dependencies += " ";\r
 +                      dependencies += GetSpecObjectDependencies ( file.name );\r
 +              }\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +string\r
 +MingwModuleHandler::GetLinkingDependencies ( const Module& module ) const\r
 +{\r
 +      string dependencies = GetImportLibraryDependencies ( module );\r
 +      string s = GetDefinitionDependencies ( module );\r
 +      if ( s.length () > 0 )\r
 +      {\r
 +              dependencies += " ";\r
 +              dependencies += s;\r
 +      }\r
 +      return dependencies;\r
 +}\r
 +\r
 +bool\r
 +MingwModuleHandler::IsCPlusPlusModule ( const Module& module ) const\r
 +{\r
 +      if ( module.HasFileWithExtensions ( ".cc", ".CC" ) )\r
 +              return true;\r
 +      if ( module.HasFileWithExtensions ( ".cxx", ".CXX" ) )\r
 +              return true;\r
 +      if ( module.HasFileWithExtensions ( ".cpp", ".CPP" ) )\r
 +              return true;\r
 +      return false;\r
 +}\r
 +\r
 +\r
 +static MingwBuildToolModuleHandler buildtool_handler;\r
 +\r
 +MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()\r
 +      : MingwModuleHandler ( BuildTool )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwBuildToolModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateBuildToolModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& module )\r
 +{\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateMacrosAndTargetsHost ( module );\r
 +\r
 +      string linker;\r
 +      if ( IsCPlusPlusModule ( module ) )\r
 +              linker = "${host_gpp}";\r
 +      else\r
 +              linker = "${host_gcc}";\r
 +      \r
 +      fprintf ( fMakefile, "%s: %s %s\n",\r
 +                target.c_str (),\r
 +                archiveFilename.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t%s %s -o %s %s %s\n\n",\r
 +                linker.c_str (),\r
 +                GetLinkerMacro ( module ).c_str (),\r
 +                target.c_str (),\r
 +                archiveFilename.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +}\r
 +\r
 +\r
 +static MingwKernelModuleHandler kernelmodule_handler;\r
 +\r
 +MingwKernelModuleHandler::MingwKernelModuleHandler ()\r
 +      : MingwModuleHandler ( Kernel )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwKernelModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateKernelModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string targetName ( module.GetTargetName () );\r
 +      string target ( FixupTargetFilename (module.GetPath ()) );\r
 +      string workingDirectory = GetWorkingDirectory ();\r
 +      string objectsMacro = GetObjectsMacro ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +      string base_tmp = ros_junk + module.name + ".base.tmp";\r
 +      string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
 +      string temp_exp = ros_junk + module.name + ".temp.exp";\r
 +      string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
 +                                    module.GetBasePath ().c_str (),\r
 +                                    module.entrypoint.c_str (),\r
 +                                    module.baseaddress.c_str () );\r
 +\r
 +      GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      fprintf ( fMakefile, "%s: %s %s\n",\r
 +                target.c_str (),\r
 +                objectsMacro.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",\r
 +                GetLinkerMacro ( module ).c_str (),\r
 +                gccOptions.c_str (),\r
 +                base_tmp.c_str (),\r
 +                junk_tmp.c_str (),\r
 +                objectsMacro.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${rm} %s\n",\r
 +                junk_tmp.c_str () );\r
 +      string killAt = module.mangledSymbols ? "" : "--kill-at";\r
 +      fprintf ( fMakefile,\r
 +                "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",\r
 +                targetName.c_str (),\r
 +                base_tmp.c_str (),\r
 +                temp_exp.c_str (),\r
 +                killAt.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${rm} %s\n",\r
 +                base_tmp.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",\r
 +                GetLinkerMacro ( module ).c_str (),\r
 +                gccOptions.c_str (),\r
 +                temp_exp.c_str (),\r
 +                target.c_str (),\r
 +                objectsMacro.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${rm} %s\n\n",\r
 +                temp_exp.c_str () );\r
 +}\r
 +\r
 +\r
 +static MingwStaticLibraryModuleHandler staticlibrary_handler;\r
 +\r
 +MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()\r
 +      : MingwModuleHandler ( StaticLibrary )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwStaticLibraryModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateStaticLibraryModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module& module )\r
 +{\r
 +      GenerateMacrosAndTargetsTarget ( module );\r
 +}\r
 +\r
 +\r
 +static MingwObjectLibraryModuleHandler objectlibrary_handler;\r
 +\r
 +MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()\r
 +      : MingwModuleHandler ( ObjectLibrary )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwObjectLibraryModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateObjectLibraryModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module& module )\r
 +{\r
 +      GenerateMacrosAndTargetsTarget ( module );\r
 +}\r
 +\r
 +\r
 +static MingwKernelModeDLLModuleHandler kernelmodedll_handler;\r
 +\r
 +MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()\r
 +      : MingwModuleHandler ( KernelModeDLL )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwKernelModeDLLModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateKernelModeDLLModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        archiveFilename.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      "${gcc}",\r
 +                                      linkerParameters,\r
 +                                      archiveFilename );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n",\r
 +                        target.c_str ());\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwKernelModeDriverModuleHandler kernelmodedriver_handler;\r
 +\r
 +MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()\r
 +      : MingwModuleHandler ( KernelModeDriver )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwKernelModeDriverModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateKernelModeDriverModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +\r
 +void\r
 +MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( PassThruCacheDirectory( FixupTargetFilename ( module.GetPath () ) ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              string* cflags = new string ( "-D__NTDRIVER__" );\r
 +              GenerateMacrosAndTargetsTarget ( module,\r
 +                                               cflags,\r
 +                                               NULL );\r
 +              delete cflags;\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        archiveFilename.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      "${gcc}",\r
 +                                      linkerParameters,\r
 +                                      archiveFilename );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n",\r
 +                        target.c_str () );\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwNativeDLLModuleHandler nativedll_handler;\r
 +\r
 +MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()\r
 +      : MingwModuleHandler ( NativeDLL )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwNativeDLLModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateNativeDLLModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string objectFilenames = GetObjectFilenames ( module );\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +      \r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        archiveFilename.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      "${gcc}",\r
 +                                      linkerParameters,\r
 +                                      objectFilenames );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n\n",\r
 +                        target.c_str ());\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwNativeCUIModuleHandler nativecui_handler;\r
 +\r
 +MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()\r
 +      : MingwModuleHandler ( NativeCUI )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwNativeCUIModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateNativeCUIModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string objectFilenames = GetObjectFilenames ( module );\r
 +      string archiveFilename = GetModuleArchiveFilename ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +      \r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              string* cflags = new string ( "-D__NTAPP__" );\r
 +              GenerateMacrosAndTargetsTarget ( module,\r
 +                                               cflags,\r
 +                                               NULL );\r
 +              delete cflags;\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        archiveFilename.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      "${gcc}",\r
 +                                      linkerParameters,\r
 +                                      objectFilenames );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n\n",\r
 +                        target.c_str ());\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwWin32DLLModuleHandler win32dll_handler;\r
 +\r
 +MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()\r
 +      : MingwModuleHandler ( Win32DLL )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwWin32DLLModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GenerateExtractWineDLLResourcesTarget ( module );\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateWin32DLLModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module& module )\r
 +{\r
 +      fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",\r
 +                module.name.c_str () );\r
 +      fprintf ( fMakefile, "%s_extractresources: bin2res\n",\r
 +                module.name.c_str () );\r
 +      for ( size_t i = 0; i < module.files.size (); i++ )\r
 +      {\r
 +              File& file = *module.files[i];\r
 +              string extension = GetExtension ( file.name );\r
 +              if ( extension == ".rc" || extension == ".RC" )\r
 +              {\r
 +                      string resource = FixupTargetFilename ( file.name );\r
 +                      fprintf ( fMakefile, "\t@echo ${bin2res} -f -x %s\n",\r
 +                                resource.c_str () );\r
 +              }\r
 +      }\r
 +      fprintf ( fMakefile, "\n");\r
 +}\r
 +\r
 +void\r
 +MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string objectFilenames = GetObjectFilenames ( module );\r
 +      string linkingDependencies = GetLinkingDependencies ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              GenerateMacrosAndTargetsTarget ( module );\r
 +      \r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        linkingDependencies.c_str () );\r
 +\r
 +              string linker;\r
 +              if ( IsCPlusPlusModule ( module ) )\r
 +                      linker = "${gpp}";\r
 +              else\r
 +                      linker = "${gcc}";\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      linker,\r
 +                                      linkerParameters,\r
 +                                      objectFilenames );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str () );\r
 +              fprintf ( fMakefile, "%s:\n\n",\r
 +                        target.c_str () );\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwWin32CUIModuleHandler win32cui_handler;\r
 +\r
 +MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()\r
 +      : MingwModuleHandler ( Win32CUI )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwWin32CUIModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateWin32CUIModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string objectFilenames = GetObjectFilenames ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linker;\r
 +              if ( IsCPlusPlusModule ( module ) )\r
 +                      linker = "${gpp}";\r
 +              else\r
 +                      linker = "${gcc}";\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      linker,\r
 +                                      linkerParameters,\r
 +                                      objectFilenames );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n\n",\r
 +                        target.c_str ());\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwWin32GUIModuleHandler win32gui_handler;\r
 +\r
 +MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()\r
 +      : MingwModuleHandler ( Win32GUI )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwWin32GUIModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateWin32GUIModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ( );\r
 +      string objectFilenames = GetObjectFilenames ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateImportLibraryTargetIfNeeded ( module );\r
 +\r
 +      if ( module.files.size () > 0 )\r
 +      {\r
 +              GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +              fprintf ( fMakefile, "%s: %s %s\n",\r
 +                        target.c_str (),\r
 +                        objectFilenames.c_str (),\r
 +                        importLibraryDependencies.c_str () );\r
 +\r
 +              string linker;\r
 +              if ( IsCPlusPlusModule ( module ) )\r
 +                      linker = "${gpp}";\r
 +              else\r
 +                      linker = "${gcc}";\r
 +\r
 +              string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
 +                                                   module.entrypoint.c_str (),\r
 +                                                   module.baseaddress.c_str () );\r
 +              GenerateLinkerCommand ( module,\r
 +                                      linker,\r
 +                                      linkerParameters,\r
 +                                      objectFilenames );\r
 +      }\r
 +      else\r
 +      {\r
 +              fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                        target.c_str ());\r
 +              fprintf ( fMakefile, "%s:\n\n",\r
 +                        target.c_str ());\r
 +      }\r
 +}\r
 +\r
 +\r
 +static MingwBootLoaderModuleHandler bootloadermodule_handler;\r
 +\r
 +MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()\r
 +      : MingwModuleHandler ( BootLoader )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwBootLoaderModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateBootLoaderModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module& module )\r
 +{\r
 +      static string ros_junk ( "$(ROS_TEMPORARY)" );\r
 +      string targetName ( module.GetTargetName () );\r
 +      string target ( FixupTargetFilename ( module.GetPath () ) );\r
 +      string workingDirectory = GetWorkingDirectory ();\r
 +      string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
 +      string objectsMacro = GetObjectsMacro ( module );\r
 +      string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 +\r
 +      GenerateMacrosAndTargetsTarget ( module );\r
 +\r
 +      fprintf ( fMakefile, "%s: %s %s\n",\r
 +                target.c_str (),\r
 +                objectsMacro.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +\r
 +      fprintf ( fMakefile,\r
 +                "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",\r
 +                GetLinkerMacro ( module ).c_str (),\r
 +                junk_tmp.c_str (),\r
 +                objectsMacro.c_str (),\r
 +                importLibraryDependencies.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${objcopy} -O binary %s %s\n",\r
 +                junk_tmp.c_str (),\r
 +                target.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${rm} %s\n",\r
 +                junk_tmp.c_str () );\r
 +}\r
 +\r
 +\r
 +static MingwBootSectorModuleHandler bootsectormodule_handler;\r
 +\r
 +MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()\r
 +      : MingwModuleHandler ( BootSector )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwBootSectorModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateBootSectorModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module& module )\r
 +{\r
 +      string objectsMacro = GetObjectsMacro ( module );\r
 +\r
 +      string* nasmflags = new string ( "-f bin" );\r
 +      GenerateMacrosAndTargetsTarget ( module,\r
 +                                       NULL,\r
 +                                       nasmflags);\r
 +\r
 +      fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                    module.name.c_str ());\r
 +      fprintf ( fMakefile,\r
 +                "%s: %s\n",\r
 +                module.name.c_str (),\r
 +                objectsMacro.c_str () );\r
 +}\r
 +\r
 +\r
 +static MingwIsoModuleHandler isomodule_handler;\r
 +\r
 +MingwIsoModuleHandler::MingwIsoModuleHandler ()\r
 +      : MingwModuleHandler ( Iso )\r
 +{\r
 +}\r
 +\r
 +void\r
 +MingwIsoModuleHandler::Process ( const Module& module )\r
 +{\r
 +      GeneratePreconditionDependencies ( module );\r
 +      GenerateIsoModuleTarget ( module );\r
 +      GenerateInvocations ( module );\r
 +}\r
 +\r
 +void\r
 +MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory,\r
 +                                                           const Module& module ) const\r
 +{\r
 +      for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
 +      {\r
 +              const Module& m = *module.project.modules[i];\r
 +              if ( m.bootstrap != NULL )\r
 +              {\r
 +                      string targetFilenameNoFixup = bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd;\r
 +                      string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
 +                      fprintf ( fMakefile,\r
 +                                "\t${cp} %s %s\n",\r
 +                                m.GetPath ().c_str (),\r
 +                                targetFilename.c_str () );\r
 +              }\r
 +      }\r
 +}\r
 +\r
 +void\r
 +MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory,\r
 +                                                    const Module& module ) const\r
 +{\r
 +      for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
 +      {\r
 +              const CDFile& cdfile = *module.project.cdfiles[i];\r
 +              string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;\r
 +              string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
 +              fprintf ( fMakefile,\r
 +                        "\t${cp} %s %s\n",\r
 +                        cdfile.GetPath ().c_str (),\r
 +                        targetFilename.c_str () );\r
 +      }\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory,\r
 +                                                     const Module& module ) const\r
 +{\r
 +      string directories;\r
 +      for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
 +      {\r
 +              const Module& m = *module.project.modules[i];\r
 +              if ( m.bootstrap != NULL )\r
 +              {\r
 +                      string targetDirecctory = bootcdDirectory + SSEP + m.bootstrap->base;\r
 +                      if ( directories.size () > 0 )\r
 +                              directories += " ";\r
 +                      directories += FixupTargetFilename ( targetDirecctory );\r
 +              }\r
 +      }\r
 +      return directories;\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory,\r
 +                                                     const Module& module ) const\r
 +{\r
 +      string directories;\r
 +      for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
 +      {\r
 +              const CDFile& cdfile = *module.project.cdfiles[i];\r
 +              string targetDirecctory = bootcdDirectory + SSEP + cdfile.base;\r
 +              if ( directories.size () > 0 )\r
 +                      directories += " ";\r
 +              directories += FixupTargetFilename ( targetDirecctory );\r
 +      }\r
 +      return directories;\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory,\r
 +                                            const Module& module ) const\r
 +{\r
 +      string directories = GetBootstrapCdDirectories ( bootcdDirectory,\r
 +                                                       module );\r
 +      directories += " " + GetNonModuleCdDirectories ( bootcdDirectory,\r
 +                                                       module );\r
 +      return directories;\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory,\r
 +                                               const Module& module ) const\r
 +{\r
 +      string cdfiles;\r
 +      for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
 +      {\r
 +              const Module& m = *module.project.modules[i];\r
 +              if ( m.bootstrap != NULL )\r
 +              {\r
 +                      if ( cdfiles.size () > 0 )\r
 +                              cdfiles += " ";\r
 +                      cdfiles += FixupTargetFilename ( m.GetPath () );\r
 +              }\r
 +      }\r
 +      return cdfiles;\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory,\r
 +                                               const Module& module ) const\r
 +{\r
 +      string cdfiles;\r
 +      for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
 +      {\r
 +              const CDFile& cdfile = *module.project.cdfiles[i];\r
 +              if ( cdfiles.size () > 0 )\r
 +                      cdfiles += " ";\r
 +              cdfiles += NormalizeFilename ( cdfile.GetPath () );\r
 +      }\r
 +      return cdfiles;\r
 +}\r
 +\r
 +string\r
 +MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory,\r
 +                                      const Module& module ) const\r
 +{\r
 +      string cdfiles = GetBootstrapCdFiles ( bootcdDirectory,\r
 +                                             module );\r
 +      cdfiles += " " + GetNonModuleCdFiles ( bootcdDirectory,\r
 +                                             module );\r
 +      return cdfiles;\r
 +}\r
 +\r
 +void\r
 +MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module& module )\r
 +{\r
 +      string bootcdDirectory = "cd";\r
 +      string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );\r
 +      string bootcdReactosNoFixup = bootcdDirectory + "/reactos";\r
 +      string bootcdReactos = FixupTargetFilename ( bootcdReactosNoFixup );\r
 +      PassThruCacheDirectory ( bootcdReactos + SSEP );\r
 +      string reactosInf = FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );\r
 +      string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );\r
 +      string cdDirectories = bootcdReactos + " " + GetCdDirectories ( bootcdDirectory,\r
 +                                                                      module );\r
 +      string cdFiles = GetCdFiles ( bootcdDirectory,\r
 +                                    module );\r
 +\r
 +      fprintf ( fMakefile, ".PHONY: %s\n\n",\r
 +                    module.name.c_str ());\r
 +      fprintf ( fMakefile,\r
 +                "%s: all %s %s %s\n",\r
 +                module.name.c_str (),\r
 +                isoboot.c_str (),\r
 +                cdDirectories.c_str (),\r
 +                cdFiles.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${cabman} -C %s -L %s -I\n",\r
 +                reactosDff.c_str (),\r
 +                bootcdReactos.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t${cabman} -C %s -RC %s -L %s -N\n",\r
 +                reactosDff.c_str (),\r
 +                reactosInf.c_str (),\r
 +                bootcdReactos.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\t- ${rm} %s\n",\r
 +                reactosInf.c_str () );\r
 +      OutputBootstrapfileCopyCommands ( bootcdDirectory,\r
 +                                        module );\r
 +      OutputCdfileCopyCommands ( bootcdDirectory,\r
 +                                 module );\r
 +      fprintf ( fMakefile,\r
 +                "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",\r
 +                isoboot.c_str (),\r
 +                bootcdDirectory.c_str () );\r
 +      fprintf ( fMakefile,\r
 +                "\n" );\r
 +}\r
index 0000000,a5d9fd9..51977c4
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,87 +1,95 @@@
 -PATH_TO_TOP = ../..
++UNICODE_BASE = tools$(SEP)unicode
 -include $(PATH_TO_TOP)/config
++UNICODE_TARGET = \
++      $(ROS_INTERMEDIATE)$(UNICODE_BASE)$(SEP)libunicode.a
 -TARGET_TYPE = host_library
 -
 -TARGET_NAME = unicode
 -
 -TARGET_CFLAGS = -D__USE_W32API -DWINVER=0x501 -DWINE_UNICODE_API= \
 -                -Dwchar_t="unsigned short" -D_WCHAR_T_DEFINED \
 -                -I$(PATH_TO_TOP)/include/wine
 -
 -CODEPAGES = \
++UNICODE_CODEPAGES = \
+       037 \
+       424 \
+       437 \
+       500 \
+       737 \
+       775 \
+       850 \
+       852 \
+       855 \
+       856 \
+       857 \
+       860 \
+       861 \
+       862 \
+       863 \
+       864 \
+       865 \
+       866 \
+       869 \
+       874 \
+       875 \
+       878 \
+       932 \
+       936 \
+       949 \
+       950 \
+       1006 \
+       1026 \
+       1250 \
+       1251 \
+       1252 \
+       1253 \
+       1254 \
+       1255 \
+       1256 \
+       1257 \
+       1258 \
+       10000 \
+       10006 \
+       10007 \
+       10029 \
+       10079 \
+       10081 \
+       20866 \
+       20932 \
+       21866 \
+       28591 \
+       28592 \
+       28593 \
+       28594 \
+       28595 \
+       28596 \
+       28597 \
+       28598 \
+       28599 \
+       28600 \
+       28603 \
+       28604 \
+       28605 \
+       28606
 -TARGET_OBJECTS = \
 -      casemap.o \
 -      compose.o \
 -      cptable.o \
 -      mbtowc.o \
 -      string.o \
 -      wctomb.o \
 -      wctype.o \
 -      $(CODEPAGES:%=c_%.o)
++UNICODE_SOURCES = \
++      $(UNICODE_BASE)$(SEP)casemap.c \
++      $(UNICODE_BASE)$(SEP)compose.c \
++      $(UNICODE_BASE)$(SEP)cptable.c \
++      $(UNICODE_BASE)$(SEP)mbtowc.c \
++      $(UNICODE_BASE)$(SEP)string.c \
++      $(UNICODE_BASE)$(SEP)wctomb.c \
++      $(UNICODE_BASE)$(SEP)wctype.c \
++  $(addprefix $(UNICODE_BASE)$(SEP), $(UNICODE_CODEPAGES:%=c_%.o))
++
++UNICODE_OBJECTS = \
++      $(UNICODE_SOURCES:.c=.o)
++
++UNICODE_HOST_CFLAGS = \
++      -D__USE_W32API -DWINVER=0x501 -DWINE_UNICODE_API= \
++      -Dwchar_t="unsigned short" -D_WCHAR_T_DEFINED \
++      -I$(UNICODE_BASE) -Iinclude/wine
++
++$(UNICODE_TARGET): $(UNICODE_OBJECTS)
++      ${host_ar} -rc $(UNICODE_TARGET) $(UNICODE_OBJECTS)
 -include $(PATH_TO_TOP)/rules.mak
++$(UNICODE_OBJECTS): %.o : %.c
++      ${host_gcc} $(UNICODE_HOST_CFLAGS) -c $< -o $@
 -include $(TOOLS_PATH)/helper.mk
++.PHONY: unicode_clean
++unicode_clean:
++      -@$(rm) $(UNICODE_TARGET) $(UNICODE_OBJECTS) 2>$(NUL)
++clean: unicode_clean
index 0000000,3228817..60cdb59
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,33 +1,26 @@@
 -PATH_TO_TOP = ../..
++WPP_BASE = tools$(SEP)wpp
 -include $(PATH_TO_TOP)/config
++WPP_TARGET = \
++      $(ROS_INTERMEDIATE)$(WPP_BASE)$(SEP)libwpp.a
 -TARGET_TYPE = host_library
++WPP_SOURCES = \
++      $(WPP_BASE)$(SEP)lex.yy.c \
++      $(WPP_BASE)$(SEP)preproc.c \
++      $(WPP_BASE)$(SEP)wpp.c \
++      $(WPP_BASE)$(SEP)wpp.tab.c
 -TARGET_NAME = wpp
++WPP_OBJECTS = \
++      $(WPP_SOURCES:.c=.o)
 -TARGET_CFLAGS = -D__USE_W32API -I$(PATH_TO_TOP)/include/wine
++WPP_HOST_CFLAGS = -D__USE_W32API -I$(WPP_BASE) -Iinclude -Iinclude/wine -g
 -TARGET_OBJECTS = preproc.o wpp.o wpp.tab.o lex.yy.o
++$(WPP_TARGET): $(WPP_OBJECTS)
++      ${host_ar} -rc $(WPP_TARGET) $(WPP_OBJECTS)
 -#DEP_OBJECTS = $(TARGET_OBJECTS)
++$(WPP_OBJECTS): %.o : %.c
++      ${host_gcc} $(WPP_HOST_CFLAGS) -c $< -o $@
 -include $(PATH_TO_TOP)/rules.mak
 -
 -include $(TOOLS_PATH)/helper.mk
 -
 -#include $(TOOLS_PATH)/depend.mk
 -
 -LEXOPT    = -Cf #-w -b
 -YACCOPT   = #-v
 -#
 -#     Optional use of bison, this will allow independent building from
 -#     Wine.
 -#
 -#y.tab.c y.tab.h: ppl.l
 -#     bison $(YACCOPT) -ppp -d -t ppy.y -o wpp.tab.c
 -#
 -#lex.yy.c: ppl.l
 -#     flex $(LEXOPT) -d -8 -Ppp -olex.yy.c ppl.l
 -
 -# EOF
++.PHONY: wpp_clean
++wpp_clean:
++      -@$(rm) $(WPP_TARGET) $(WPP_OBJECTS) 2>$(NUL)
++clean: wpp_clean
index 0000000,db39b91..333bef9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,72 +1,39 @@@
 -#
 -# wrc
 -#
 -PATH_TO_TOP = ../..
 -
 -LIB_WPP_DIR = ../wpp
 -LIB_UNICODE_DIR = ../unicode
 -
 -include $(PATH_TO_TOP)/rules.mak
 -
 -TARGET = wrc$(EXE_POSTFIX)
 -
 -all: $(TARGET)
 -
 -BASE_OBJECTS = \
 -      dumpres.o \
 -      genres.o \
 -      newstruc.o \
 -      readres.o \
 -      translation.o \
 -      utils.o \
 -      wrc.o \
 -      writeres.o \
 -      y.tab.o \
 -      lex.yy.o
 -
 -PORT_OBJECTS = \
 -      port/mkstemps.o
 -
 -OBJECTS = $(BASE_OBJECTS) $(PORT_OBJECTS)
 -
 -LIBS = $(LIB_UNICODE_DIR)/libunicode.a $(LIB_WPP_DIR)/libwpp.a
 -
 -CLEAN_FILES = *.o $(TARGET)
 -
 -HOST_CFLAGS = -D__USE_W32API -DWINE_UNICODE_API= \
 -              -Dwchar_t="unsigned short" -D_WCHAR_T_DEFINED \
 -              -I$(LIB_UNICODE_DIR) -I$(LIB_WPP_DIR) -I$(PATH_TO_TOP)/include/wine \
 -              -I$(PATH_TO_TOP)/include -I$(PATH_TO_TOP)/w32api/include
 -
 -%.o: %.c
 -      $(HOST_CC) $(HOST_CFLAGS) -c $< -o $@
 -
 -$(TARGET): $(OBJECTS) $(LIBS)
 -      $(HOST_CC) -o $(TARGET) $(OBJECTS) $(LIBS)
 -
 -ifeq ($(HOST),mingw32-linux)
 -clean:
 -      -rm -f $(OBJECTS) $(TARGET)
 -endif
 -ifneq ($(HOST),mingw32-linux)
 -clean:
 -      -del $(TARGET)
 -      -del *.o
 -      -del port\*.o
 -endif
 -
 -.PHONY: clean
 -
 -LEXOPT    = -Cf #-w -b
 -YACCOPT   = #-v
 -#
 -#     Optional use of bison, this will allow independent building from
 -#     Wine.
 -#
 -#y.tab.c y.tab.h: parser.y
 -#     bison $(YACCOPT) -d -t parser.y -o y.tab.c
 -#
 -#lex.yy.c: parser.l
 -#     flex $(LEXOPT) -d -8 parser.l
 -
 -# EOF
++WRC_BASE = tools$(SEP)wrc
++
++WRC_TARGET = \
++      $(ROS_INTERMEDIATE)$(WRC_BASE)$(SEP)wrc$(EXEPOSTFIX)
++
++WRC_SOURCES = \
++      $(WRC_BASE)$(SEP)dumpres.c \
++      $(WRC_BASE)$(SEP)genres.c \
++      $(WRC_BASE)$(SEP)newstruc.c \
++      $(WRC_BASE)$(SEP)readres.c \
++      $(WRC_BASE)$(SEP)translation.c \
++      $(WRC_BASE)$(SEP)utils.c \
++      $(WRC_BASE)$(SEP)wrc.c \
++      $(WRC_BASE)$(SEP)writeres.c \
++      $(WRC_BASE)$(SEP)y.tab.c \
++      $(WRC_BASE)$(SEP)lex.yy.c \
++      $(WRC_BASE)$(SEP)port$(SEP)mkstemps.o
++
++WRC_OBJECTS = \
++      $(WRC_SOURCES:.c=.o)
++
++WRC_HOST_CFLAGS = -I$(WRC_BASE) -g -Werror -Wall \
++                  -D__USE_W32API -DWINE_UNICODE_API= \
++                  -Dwchar_t="unsigned short" -D_WCHAR_T_DEFINED \
++                  -I$(UNICODE_BASE) -I$(WPP_BASE) -I$(WRC_BASE) \
++                  -Iinclude/wine -Iinclude -Iw32api/include
++
++WRC_HOST_LFLAGS = -g
++
++$(WRC_TARGET): $(WRC_OBJECTS) $(UNICODE_TARGET) $(WPP_TARGET)
++      ${host_gcc} $(WRC_OBJECTS) $(UNICODE_TARGET) $(WPP_TARGET) $(WRC_HOST_LFLAGS) -o $(WRC_TARGET)
++
++$(WRC_OBJECTS): %.o : %.c
++      ${host_gcc} $(WRC_HOST_CFLAGS) -c $< -o $@
++
++.PHONY: wrc_clean
++wrc_clean:
++      -@$(rm) $(WRC_TARGET) $(WRC_OBJECTS) 2>$(NUL)
++clean: wrc_clean
index 0000000,ab11dcd..f9d3da8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,3027 +1,3032 @@@
 -        | any_num             { $$ = new_style($1, 0); }
 -        | tNOT any_num                { $$ = new_style(0, $2); }
+ %{
+ /*
+  * Copyright 1994     Martin von Loewis
+  * Copyright 1998-2000        Bertho A. Stultiens (BS)
+  *           1999     Juergen Schmied (JS)
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
+  * This library is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this library; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  *
+  * History:
+  * 24-Jul-2000 BS     - Made a fix for broken Berkeley yacc on
+  *                      non-terminals (see cjunk rule).
+  * 21-May-2000 BS     - Partial implementation of font resources.
+  *                    - Corrected language propagation for binary
+  *                      resources such as bitmaps, icons, cursors,
+  *                      userres and rcdata. The language is now
+  *                      correct in .res files.
+  *                    - Fixed reading the resource name as ident,
+  *                      so that it may overlap keywords.
+  * 20-May-2000 BS     - Implemented animated cursors and icons
+  *                      resource types.
+  * 30-Apr-2000 BS     - Reintegration into the wine-tree
+  * 14-Jan-2000 BS     - Redid the usertype resources so that they
+  *                      are compatible.
+  * 02-Jan-2000 BS     - Removed the preprocessor from the grammar
+  *                      except for the # command (line numbers).
+  *
+  * 06-Nov-1999 JS     - see CHANGES
+  *
+  * 29-Dec-1998 AdH    - Grammar and function extensions.
+  *                         grammar: TOOLBAR resources, Named ICONs in
+  *                            DIALOGS
+  *                         functions: semantic actions for the grammar
+  *                            changes, resource files can now be anywhere
+  *                            on the include path instead of just in the
+  *                            current directory
+  *
+  * 20-Jun-1998 BS     - Fixed a bug in load_file() where the name was not
+  *                      printed out correctly.
+  *
+  * 17-Jun-1998 BS     - Fixed a bug in CLASS statement parsing which should
+  *                      also accept a tSTRING as argument.
+  *
+  * 25-May-1998 BS     - Found out that I need to support language, version
+  *                      and characteristics in inline resources (bitmap,
+  *                      cursor, etc) but they can also be specified with
+  *                      a filename. This renders my filename-scanning scheme
+  *                      worthless. Need to build newline parsing to solve
+  *                      this one.
+  *                      It will come with version 1.1.0 (sigh).
+  *
+  * 19-May-1998 BS     - Started to build a builtin preprocessor
+  *
+  * 30-Apr-1998 BS     - Redid the stringtable parsing/handling. My previous
+  *                      ideas had some serious flaws.
+  *
+  * 27-Apr-1998 BS     - Removed a lot of dead comments and put it in a doc
+  *                      file.
+  *
+  * 21-Apr-1998 BS     - Added correct behavior for cursors and icons.
+  *                    - This file is growing too big. It is time to strip
+  *                      things and put it in a support file.
+  *
+  * 19-Apr-1998 BS     - Tagged the stringtable resource so that only one
+  *                      resource will be created. This because the table
+  *                      has a different layout than other resources. The
+  *                      table has to be sorted, and divided into smaller
+  *                      resource entries (see comment in source).
+  *
+  * 17-Apr-1998 BS     - Almost all strings, including identifiers, are parsed
+  *                      as string_t which include unicode strings upon
+  *                      input.
+  *                    - Parser now emits a warning when compiling win32
+  *                      extensions in win16 mode.
+  *
+  * 16-Apr-1998 BS     - Raw data elements are now *optionally* separated
+  *                      by commas. Read the comments in file sq2dq.l.
+  *                    - FIXME: there are instances in the source that rely
+  *                      on the fact that int==32bit and pointers are int size.
+  *                    - Fixed the conflict in menuex by changing a rule
+  *                      back into right recursion. See note in source.
+  *                    - UserType resources cannot have an expression as its
+  *                      typeclass. See note in source.
+  *
+  * 15-Apr-1998 BS     - Changed all right recursion into left recursion to
+  *                      get reduction of the parsestack.
+  *                      This also helps communication between bison and flex.
+  *                      Main advantage is that the Empty rule gets reduced
+  *                      first, which is used to allocate/link things.
+  *                      It also added a shift/reduce conflict in the menuex
+  *                      handling, due to expression/option possibility,
+  *                      although not serious.
+  *
+  * 14-Apr-1998 BS     - Redone almost the entire parser. We're not talking
+  *                      about making it more efficient, but readable (for me)
+  *                      and slightly easier to expand/change.
+  *                      This is done primarily by using more reduce states
+  *                      with many (intuitive) types for the various resource
+  *                      statements.
+  *                    - Added expression handling for all resources where a
+  *                      number is accepted (not only for win32). Also added
+  *                      multiply and division (not MS compatible, but handy).
+  *                      Unary minus introduced a shift/reduce conflict, but
+  *                      it is not serious.
+  *
+  * 13-Apr-1998 BS     - Reordered a lot of things
+  *                    - Made the source more readable
+  *                    - Added Win32 resource definitions
+  *                    - Corrected syntax problems with an old yacc (;)
+  *                    - Added extra comment about grammar
+  */
+ #include "config.h"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <assert.h>
+ #include <ctype.h>
+ #include <string.h>
+ #ifdef HAVE_ALLOCA_H
+ #include <alloca.h>
+ #endif
+ #include "wrc.h"
+ #include "utils.h"
+ #include "newstruc.h"
+ #include "dumpres.h"
+ #include "wine/wpp.h"
+ #include "wine/unicode.h"
+ #include "parser.h"
+ #include "windef.h"
+ #include "winbase.h"
+ #include "wingdi.h"
+ #include "winuser.h"
+ #if defined(YYBYACC)
+       /* Berkeley yacc (byacc) doesn't seem to know about these */
+       /* Some *BSD supplied versions do define these though */
+ # ifndef YYEMPTY
+ #  define YYEMPTY     (-1)    /* Empty lookahead value of yychar */
+ # endif
+ # ifndef YYLEX
+ #  define YYLEX               yylex()
+ # endif
+ #elif defined(YYBISON)
+       /* Bison was used for original development */
+       /* #define YYEMPTY -2 */
+       /* #define YYLEX   yylex() */
+ #else
+       /* No yacc we know yet */
+ # if !defined(YYEMPTY) || !defined(YYLEX)
+ #  error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
+ # elif defined(__GNUC__)      /* gcc defines the #warning directive */
+ #  warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
+   /* #else we just take a chance that it works... */
+ # endif
+ #endif
+ int want_nl = 0;      /* Signal flex that we need the next newline */
+ int want_id = 0;      /* Signal flex that we need the next identifier */
+ stringtable_t *tagstt;        /* Stringtable tag.
+                        * It is set while parsing a stringtable to one of
+                        * the stringtables in the sttres list or a new one
+                        * if the language was not parsed before.
+                        */
+ stringtable_t *sttres;        /* Stringtable resources. This holds the list of
+                        * stringtables with different lanuages
+                        */
+ static int dont_want_id = 0;  /* See language parsing for details */
+ /* Set to the current options of the currently scanning stringtable */
+ static int *tagstt_memopt;
+ static characts_t *tagstt_characts;
+ static version_t *tagstt_version;
+ static const char riff[4] = "RIFF";   /* RIFF file magic for animated cursor/icon */
+ /* Prototypes of here defined functions */
+ static event_t *get_event_head(event_t *p);
+ static control_t *get_control_head(control_t *p);
+ static ver_value_t *get_ver_value_head(ver_value_t *p);
+ static ver_block_t *get_ver_block_head(ver_block_t *p);
+ static resource_t *get_resource_head(resource_t *p);
+ static menuex_item_t *get_itemex_head(menuex_item_t *p);
+ static menu_item_t *get_item_head(menu_item_t *p);
+ static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
+ static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
+ static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
+ static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
+ static raw_data_t *str2raw_data(string_t *str);
+ static raw_data_t *int2raw_data(int i);
+ static raw_data_t *long2raw_data(int i);
+ static raw_data_t *load_file(string_t *name, language_t *lang);
+ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
+ static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
+ static event_t *add_event(int key, int id, int flags, event_t *prev);
+ static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
+ static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
+ static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
+ static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
+ static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
+ static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
+ static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
+ static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
+ static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
+ static name_id_t *convert_ctlclass(name_id_t *cls);
+ static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
+ static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
+ static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
+ static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
+ static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
+ static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
+ static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
+ static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
+ static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
+ static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
+ static resource_t *build_stt_resources(stringtable_t *stthead);
+ static stringtable_t *find_stringtable(lvc_t *lvc);
+ static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
+ static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
+ static string_t *make_filename(string_t *s);
+ static resource_t *build_fontdirs(resource_t *tail);
+ static resource_t *build_fontdir(resource_t **fnt, int nfnt);
+ static int rsrcid_to_token(int lookahead);
+ %}
+ %union{
+       string_t        *str;
+       int             num;
+       int             *iptr;
+       char            *cptr;
+       resource_t      *res;
+       accelerator_t   *acc;
+       bitmap_t        *bmp;
+       dialog_t        *dlg;
+       dialogex_t      *dlgex;
+       font_t          *fnt;
+       fontdir_t       *fnd;
+       menu_t          *men;
+       menuex_t        *menex;
+       rcdata_t        *rdt;
+       stringtable_t   *stt;
+       stt_entry_t     *stte;
+       user_t          *usr;
+       messagetable_t  *msg;
+       versioninfo_t   *veri;
+       control_t       *ctl;
+       name_id_t       *nid;
+       font_id_t       *fntid;
+       language_t      *lan;
+       version_t       *ver;
+       characts_t      *chars;
+       event_t         *event;
+       menu_item_t     *menitm;
+       menuex_item_t   *menexitm;
+       itemex_opt_t    *exopt;
+       raw_data_t      *raw;
+       lvc_t           *lvc;
+       ver_value_t     *val;
+       ver_block_t     *blk;
+       ver_words_t     *verw;
+       toolbar_t       *tlbar;
+       toolbar_item_t  *tlbarItems;
+       dlginit_t       *dginit;
+       style_pair_t    *styles;
+       style_t         *style;
+       ani_any_t       *ani;
+ }
+ %token tNL
+ %token <num> tNUMBER tLNUMBER
+ %token <str> tSTRING tIDENT tFILENAME
+ %token <raw> tRAWDATA
+ %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
+ %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
+ %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
+ %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
+ %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
+ %token tCONTROL tEDITTEXT
+ %token tRTEXT tCTEXT tLTEXT
+ %token tBLOCK tVALUE
+ %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
+ %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
+ %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
+ %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
+ %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
+ %token tHELP
+ %token tSTRING tIDENT tRAWDATA
+ %token tTOOLBAR tBUTTON
+ %token tBEGIN tEND
+ %token tDLGINIT
+ %left '|'
+ %left '^'
+ %left '&'
+ %left '+' '-'
+ %left '*' '/'
+ %right '~' tNOT
+ %left pUPM
+ %type <res>   resource_file resource resources resource_definition
+ %type <stt>   stringtable strings
+ %type <fnt>   font
+ %type <fnd>   fontdir
+ %type <acc>   accelerators
+ %type <event>         events
+ %type <bmp>   bitmap
+ %type <ani>   cursor icon
+ %type <dlg>   dialog dlg_attributes
+ %type <ctl>   ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
+ %type <iptr>  helpid
+ %type <dlgex>         dialogex dlgex_attribs
+ %type <ctl>   exctrls gen_exctrl lab_exctrl exctrl_desc
+ %type <rdt>   rcdata
+ %type <raw>   raw_data raw_elements opt_data file_raw
+ %type <veri>  versioninfo fix_version
+ %type <verw>  ver_words
+ %type <blk>   ver_blocks ver_block
+ %type <val>   ver_values ver_value
+ %type <men>   menu
+ %type <menitm>        item_definitions menu_body
+ %type <menex> menuex
+ %type <menexitm> itemex_definitions menuex_body
+ %type <exopt> itemex_p_options itemex_options
+ %type <msg>   messagetable
+ %type <usr>   userres
+ %type <num>   item_options
+ %type <nid>   nameid nameid_s ctlclass usertype
+ %type <num>   acc_opt acc accs
+ %type <iptr>  loadmemopts lamo lama
+ %type <fntid> opt_font opt_exfont opt_expr
+ %type <lvc>   opt_lvc
+ %type <lan>   opt_language
+ %type <chars> opt_characts
+ %type <ver>   opt_version
+ %type <num>   expr xpr
+ %type <iptr>  e_expr
+ %type <tlbar> toolbar
+ %type <tlbarItems>    toolbar_items
+ %type <dginit>  dlginit
+ %type <styles>  optional_style_pair
+ %type <num>   any_num
+ %type <style>   optional_style
+ %type <style>   style
+ %type <str>   filename
+ %%
+ resource_file
+       : resources {
+               resource_t *rsc;
+               /* First add stringtables to the resource-list */
+               rsc = build_stt_resources(sttres);
+               /* 'build_stt_resources' returns a head and $1 is a tail */
+               if($1)
+               {
+                       $1->next = rsc;
+                       if(rsc)
+                               rsc->prev = $1;
+               }
+               else
+                       $1 = rsc;
+               /* Find the tail again */
+               while($1 && $1->next)
+                       $1 = $1->next;
+               /* Now add any fontdirecory */
+               rsc = build_fontdirs($1);
+               /* 'build_fontdir' returns a head and $1 is a tail */
+               if($1)
+               {
+                       $1->next = rsc;
+                       if(rsc)
+                               rsc->prev = $1;
+               }
+               else
+                       $1 = rsc;
+               /* Final statement before were done */
+               resource_top = get_resource_head($1);
+               }
+       ;
+ /* Resources are put into a linked list */
+ resources
+       : /* Empty */           { $$ = NULL; want_id = 1; }
+       | resources resource    {
+               if($2)
+               {
+                       resource_t *tail = $2;
+                       resource_t *head = $2;
+                       while(tail->next)
+                               tail = tail->next;
+                       while(head->prev)
+                               head = head->prev;
+                       head->prev = $1;
+                       if($1)
+                               $1->next = head;
+                       $$ = tail;
+                       /* Check for duplicate identifiers */
+                       while($1 && head)
+                       {
+                               resource_t *rsc = $1;
+                               while(rsc)
+                               {
+                                       if(rsc->type == head->type
+                                       && rsc->lan->id == head->lan->id
+                                       && rsc->lan->sub == head->lan->sub
+                                       && !compare_name_id(rsc->name, head->name))
+                                       {
+                                               yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
+                                       }
+                                       rsc = rsc->prev;
+                               }
+                               head = head->next;
+                       }
+               }
+               else if($1)
+               {
+                       resource_t *tail = $1;
+                       while(tail->next)
+                               tail = tail->next;
+                       $$ = tail;
+               }
+               else
+                       $$ = NULL;
+               if(!dont_want_id)       /* See comments in language parsing below */
+                       want_id = 1;
+               dont_want_id = 0;
+               }
+       /*
+        * The following newline rule will never get reduced because we never
+        * get the tNL token, unless we explicitely set the 'want_nl'
+        * flag, which we don't.
+        * The *ONLY* reason for this to be here is because Berkeley
+        * yacc (byacc), at least version 1.9, has a bug.
+        * (identified in the generated parser on the second
+        *  line with:
+        *  static char yysccsid[] = "@(#)yaccpar   1.9 (Berkeley) 02/21/93";
+        * )
+        * This extra rule fixes it.
+        * The problem is that the expression handling rule "expr: xpr"
+        * is not reduced on non-terminal tokens, defined above in the
+        * %token declarations. Token tNL is the only non-terminal that
+        * can occur. The error becomes visible in the language parsing
+        * rule below, which looks at the look-ahead token and tests it
+        * for tNL. However, byacc already generates an error upon reading
+        * the token instead of keeping it as a lookahead. The reason
+        * lies in the lack of a $default transition in the "expr : xpr . "
+        * state (currently state 25). It is probably ommitted because tNL
+        * is a non-terminal and the state contains 2 s/r conflicts. The
+        * state enumerates all possible transitions instead of using a
+        * $default transition.
+        * All in all, it is a bug in byacc. (period)
+        */
+       | resources tNL
+       ;
+ /* Parse top level resource definitions etc. */
+ resource
+       : expr usrcvt resource_definition {
+               $$ = $3;
+               if($$)
+               {
+                       if($1 > 65535 || $1 < -32768)
+                               yyerror("Resource's ID out of range (%d)", $1);
+                       $$->name = new_name_id();
+                       $$->name->type = name_ord;
+                       $$->name->name.i_name = $1;
+                       chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
+                       }
+                       }
+       | tIDENT usrcvt resource_definition {
+               $$ = $3;
+               if($$)
+               {
+                       $$->name = new_name_id();
+                       $$->name->type = name_str;
+                       $$->name->name.s_name = $1;
+                       chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
+               }
+               }
+       | stringtable {
+               /* Don't do anything, stringtables are converted to
+                * resource_t structures when we are finished parsing and
+                * the final rule of the parser is reduced (see above)
+                */
+               $$ = NULL;
+               chat("Got STRINGTABLE");
+               }
+       | tLANGUAGE {want_nl = 1; } expr ',' expr {
+               /* We *NEED* the newline to delimit the expression.
+                * Otherwise, we would not be able to set the next
+                * want_id anymore because of the token-lookahead.
+                *
+                * However, we can test the lookahead-token for
+                * being "non-expression" type, in which case we
+                * continue. Fortunately, tNL is the only token that
+                * will break expression parsing and is implicitely
+                * void, so we just remove it. This scheme makes it
+                * possible to do some (not all) fancy preprocessor
+                * stuff.
+                * BTW, we also need to make sure that the next
+                * reduction of 'resources' above will *not* set
+                * want_id because we already have a lookahead that
+                * cannot be undone.
+                */
+               if(yychar != YYEMPTY && yychar != tNL)
+                       dont_want_id = 1;
+               if(yychar == tNL)
+                       yychar = YYEMPTY;       /* Could use 'yyclearin', but we already need the*/
+                                               /* direct access to yychar in rule 'usrcvt' below. */
+               else if(yychar == tIDENT)
+                       yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
+               want_nl = 0;    /* We don't want it anymore if we didn't get it */
+               if(!win32)
+                       yywarning("LANGUAGE not supported in 16-bit mode");
+               if(currentlanguage)
+                       free(currentlanguage);
+               if (get_language_codepage($3, $5) == -1)
+                       yyerror( "Language %04x is not supported", ($5<<10) + $3);
+               currentlanguage = new_language($3, $5);
+               $$ = NULL;
+               chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
+               }
+       ;
+ /*
+  * Remapping of numerical resource types
+  * (see also comment of called function below)
+  */
+ usrcvt        : /* Empty */   { yychar = rsrcid_to_token(yychar); }
+       ;
+ /*
+  * Get a valid name/id
+  */
+ nameid        : expr  {
+               if($1 > 65535 || $1 < -32768)
+                       yyerror("Resource's ID out of range (%d)", $1);
+               $$ = new_name_id();
+               $$->type = name_ord;
+               $$->name.i_name = $1;
+               }
+       | tIDENT {
+               $$ = new_name_id();
+               $$->type = name_str;
+               $$->name.s_name = $1;
+               }
+       ;
+ /*
+  * Extra string recognition for CLASS statement in dialogs
+  */
+ nameid_s: nameid      { $$ = $1; }
+       | tSTRING       {
+               $$ = new_name_id();
+               $$->type = name_str;
+               $$->name.s_name = $1;
+               }
+       ;
+ /* get the value for a single resource*/
+ resource_definition
+       : accelerators  { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
+       | bitmap        { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
+       | cursor {
+               resource_t *rsc;
+               if($1->type == res_anicur)
+               {
+                       $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
+               }
+               else if($1->type == res_curg)
+               {
+                       cursor_t *cur;
+                       $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
+                       for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
+                       {
+                               rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
+                               rsc->prev->next = rsc;
+                               rsc = rsc->prev;
+                               rsc->name = new_name_id();
+                               rsc->name->type = name_ord;
+                               rsc->name->name.i_name = cur->id;
+                       }
+               }
+               else
+                       internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
+               free($1);
+               }
+       | dialog        { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
+       | dialogex {
+               if(win32)
+                       $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
+               else
+                       $$ = NULL;
+               }
+       | dlginit       { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
+       | font          { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
+       | fontdir       { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
+       | icon {
+               resource_t *rsc;
+               if($1->type == res_aniico)
+               {
+                       $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
+               }
+               else if($1->type == res_icog)
+               {
+                       icon_t *ico;
+                       $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
+                       for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
+                       {
+                               rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
+                               rsc->prev->next = rsc;
+                               rsc = rsc->prev;
+                               rsc->name = new_name_id();
+                               rsc->name->type = name_ord;
+                               rsc->name->name.i_name = ico->id;
+                       }
+               }
+               else
+                       internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
+               free($1);
+               }
+       | menu          { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
+       | menuex {
+               if(win32)
+                       $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
+               else
+                       $$ = NULL;
+               }
+       | messagetable  { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
+       | rcdata        { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
+       | toolbar       { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
+       | userres       { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
+       | versioninfo   { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
+       ;
+ filename: tFILENAME   { $$ = make_filename($1); }
+       | tIDENT        { $$ = make_filename($1); }
+       | tSTRING       { $$ = make_filename($1); }
+       ;
+ /* ------------------------------ Bitmap ------------------------------ */
+ bitmap        : tBITMAP loadmemopts file_raw  { $$ = new_bitmap($3, $2); }
+       ;
+ /* ------------------------------ Cursor ------------------------------ */
+ cursor        : tCURSOR loadmemopts file_raw  {
+               $$ = new_ani_any();
+               if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
+               {
+                       $$->type = res_anicur;
+                       $$->u.ani = new_ani_curico(res_anicur, $3, $2);
+               }
+               else
+               {
+                       $$->type = res_curg;
+                       $$->u.curg = new_cursor_group($3, $2);
+               }
+       }
+       ;
+ /* ------------------------------ Icon ------------------------------ */
+ icon  : tICON loadmemopts file_raw    {
+               $$ = new_ani_any();
+               if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
+               {
+                       $$->type = res_aniico;
+                       $$->u.ani = new_ani_curico(res_aniico, $3, $2);
+               }
+               else
+               {
+                       $$->type = res_icog;
+                       $$->u.icog = new_icon_group($3, $2);
+               }
+       }
+       ;
+ /* ------------------------------ Font ------------------------------ */
+       /*
+        * The reading of raw_data for fonts is a Borland BRC
+        * extension. MS generates an error. However, it is
+        * most logical to support this, considering how wine
+        * enters things in CVS (ascii).
+        */
+ font  : tFONT loadmemopts file_raw    { $$ = new_font($3, $2); }
+       ;
+       /*
+        * The fontdir is a Borland BRC extension which only
+        * reads the data as 'raw_data' from the file.
+        * I don't know whether it is interpreted.
+        * The fontdir is generated if it was not present and
+        * fonts are defined in the source.
+        */
+ fontdir       : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
+       ;
+ /* ------------------------------ MessageTable ------------------------------ */
+ /* It might be interesting to implement the MS Message compiler here as well
+  * to get everything in one source. Might be a future project.
+  */
+ messagetable
+       : tMESSAGETABLE loadmemopts file_raw    {
+               if(!win32)
+                       yywarning("MESSAGETABLE not supported in 16-bit mode");
+               $$ = new_messagetable($3, $2);
+               }
+       ;
+ /* ------------------------------ RCData ------------------------------ */
+ rcdata        : tRCDATA loadmemopts file_raw  { $$ = new_rcdata($3, $2); }
+       ;
+ /* ------------------------------ DLGINIT ------------------------------ */
+ dlginit       : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
+       ;
+ /* ------------------------------ UserType ------------------------------ */
+ userres       : usertype loadmemopts file_raw         {
+               #ifdef WORDS_BIGENDIAN
+                       if(pedantic && byteorder != WRC_BO_LITTLE)
+               #else
+                       if(pedantic && byteorder == WRC_BO_BIG)
+               #endif
+                               yywarning("Byteordering is not little-endian and type cannot be interpreted");
+                       $$ = new_user($1, $3, $2);
+               }
+       ;
+ usertype: tNUMBER {
+               $$ = new_name_id();
+               $$->type = name_ord;
+               $$->name.i_name = $1;
+               }
+       | tIDENT {
+               $$ = new_name_id();
+               $$->type = name_str;
+               $$->name.s_name = $1;
+               }
+       ;
+ /* ------------------------------ Accelerator ------------------------------ */
+ accelerators
+       : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
+               $$ = new_accelerator();
+               if($2)
+               {
+                       $$->memopt = *($2);
+                       free($2);
+               }
+               else
+               {
+                       $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
+               }
+               if(!$5)
+                       yyerror("Accelerator table must have at least one entry");
+               $$->events = get_event_head($5);
+               if($3)
+               {
+                       $$->lvc = *($3);
+                       free($3);
+               }
+               if(!$$->lvc.language)
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ events        : /* Empty */                           { $$=NULL; }
+       | events tSTRING ',' expr acc_opt       { $$=add_string_event($2, $4, $5, $1); }
+       | events expr ',' expr acc_opt          { $$=add_event($2, $4, $5, $1); }
+       ;
+ /*
+  * The empty rule generates a s/r conflict because of {bi,u}nary expr
+  * on - and +. It cannot be solved in any way because it is the same as
+  * the if/then/else problem (LALR(1) problem). The conflict is moved
+  * away by forcing it to be in the expression handling below.
+  */
+ acc_opt       : /* Empty */   { $$ = 0; }
+       | ',' accs      { $$ = $2; }
+       ;
+ accs  : acc           { $$ = $1; }
+       | accs ',' acc  { $$ = $1 | $3; }
+       ;
+ acc   : tNOINVERT     { $$ = WRC_AF_NOINVERT; }
+       | tSHIFT        { $$ = WRC_AF_SHIFT; }
+       | tCONTROL      { $$ = WRC_AF_CONTROL; }
+       | tALT          { $$ = WRC_AF_ALT; }
+       | tASCII        { $$ = WRC_AF_ASCII; }
+       | tVIRTKEY      { $$ = WRC_AF_VIRTKEY; }
+       ;
+ /* ------------------------------ Dialog ------------------------------ */
+ /* FIXME: Support EXSTYLE in the dialog line itself */
+ dialog        : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
+         tBEGIN  ctrls tEND {
+               if($2)
+               {
+                       $10->memopt = *($2);
+                       free($2);
+               }
+               else
+                       $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               $10->x = $3;
+               $10->y = $5;
+               $10->width = $7;
+               $10->height = $9;
+               $10->controls = get_control_head($12);
+               $$ = $10;
+               if(!$$->gotstyle)
+               {
+                       $$->style = new_style(0,0);
+                       $$->style->or_mask = WS_POPUP;
+                       $$->gotstyle = TRUE;
+               }
+               if($$->title)
+                       $$->style->or_mask |= WS_CAPTION;
+               if($$->font)
+                       $$->style->or_mask |= DS_SETFONT;
+               $$->style->or_mask &= ~($$->style->and_mask);
+               $$->style->and_mask = 0;
+               if(!$$->lvc.language)
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ dlg_attributes
+       : /* Empty */                           { $$=new_dialog(); }
+       | dlg_attributes tSTYLE style           { $$=dialog_style($3,$1); }
+       | dlg_attributes tEXSTYLE style         { $$=dialog_exstyle($3,$1); }
+       | dlg_attributes tCAPTION tSTRING       { $$=dialog_caption($3,$1); }
+       | dlg_attributes opt_font               { $$=dialog_font($2,$1); }
+       | dlg_attributes tCLASS nameid_s        { $$=dialog_class($3,$1); }
+       | dlg_attributes tMENU nameid           { $$=dialog_menu($3,$1); }
+       | dlg_attributes opt_language           { $$=dialog_language($2,$1); }
+       | dlg_attributes opt_characts           { $$=dialog_characteristics($2,$1); }
+       | dlg_attributes opt_version            { $$=dialog_version($2,$1); }
+       ;
+ ctrls : /* Empty */                           { $$ = NULL; }
+       | ctrls tCONTROL        gen_ctrl        { $$=ins_ctrl(-1, 0, $3, $1); }
+       | ctrls tEDITTEXT       ctrl_desc       { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
+       | ctrls tLISTBOX        ctrl_desc       { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
+       | ctrls tCOMBOBOX       ctrl_desc       { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
+       | ctrls tSCROLLBAR      ctrl_desc       { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
+       | ctrls tCHECKBOX       lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
+       | ctrls tDEFPUSHBUTTON  lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
+       | ctrls tGROUPBOX       lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
+       | ctrls tPUSHBUTTON     lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
+ /*    | ctrls tPUSHBOX        lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
+       | ctrls tRADIOBUTTON    lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
+       | ctrls tAUTO3STATE     lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
+       | ctrls tSTATE3         lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
+       | ctrls tAUTOCHECKBOX   lab_ctrl        { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
+       | ctrls tAUTORADIOBUTTON lab_ctrl       { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
+       | ctrls tLTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
+       | ctrls tCTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
+       | ctrls tRTEXT          lab_ctrl        { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
+       /* special treatment for icons, as the extent is optional */
+       | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
+               $10->title = $3;
+               $10->id = $5;
+               $10->x = $7;
+               $10->y = $9;
+               $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
+               }
+       ;
+ lab_ctrl
+       : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
+               $$=new_control();
+               $$->title = new_name_id();
+               $$->title->type = name_str;
+               $$->title->name.s_name = $1;
+               $$->id = $3;
+               $$->x = $5;
+               $$->y = $7;
+               $$->width = $9;
+               $$->height = $11;
+               if($12)
+               {
+                       $$->style = $12;
+                       $$->gotstyle = TRUE;
+               }
+               }
+       ;
+ ctrl_desc
+       : expr ',' expr ',' expr ',' expr ',' expr optional_style {
+               $$ = new_control();
+               $$->id = $1;
+               $$->x = $3;
+               $$->y = $5;
+               $$->width = $7;
+               $$->height = $9;
+               if($10)
+               {
+                       $$->style = $10;
+                       $$->gotstyle = TRUE;
+               }
+               }
+       ;
+ iconinfo: /* Empty */
+               { $$ = new_control(); }
+       | ',' expr ',' expr {
+               $$ = new_control();
+               $$->width = $2;
+               $$->height = $4;
+               }
+       | ',' expr ',' expr ',' style {
+               $$ = new_control();
+               $$->width = $2;
+               $$->height = $4;
+               $$->style = $6;
+               $$->gotstyle = TRUE;
+               }
+       | ',' expr ',' expr ',' style ',' style {
+               $$ = new_control();
+               $$->width = $2;
+               $$->height = $4;
+               $$->style = $6;
+               $$->gotstyle = TRUE;
+               $$->exstyle = $8;
+               $$->gotexstyle = TRUE;
+               }
+       ;
+ gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
+               $$=new_control();
+               $$->title = $1;
+               $$->id = $3;
+               $$->ctlclass = convert_ctlclass($5);
+               $$->style = $7;
+               $$->gotstyle = TRUE;
+               $$->x = $9;
+               $$->y = $11;
+               $$->width = $13;
+               $$->height = $15;
+               $$->exstyle = $17;
+               $$->gotexstyle = TRUE;
+               }
+       | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
+               $$=new_control();
+               $$->title = $1;
+               $$->id = $3;
+               $$->ctlclass = convert_ctlclass($5);
+               $$->style = $7;
+               $$->gotstyle = TRUE;
+               $$->x = $9;
+               $$->y = $11;
+               $$->width = $13;
+               $$->height = $15;
+               }
+       ;
+ opt_font
+       : tFONT expr ',' tSTRING        { $$ = new_font_id($2, $4, 0, 0); }
+       ;
+ /* ------------------------------ style flags ------------------------------ */
+ optional_style                /* Abbused once to get optional ExStyle */
+       : /* Empty */   { $$ = NULL; }
+       | ',' style     { $$ = $2; }
+       ;
+ optional_style_pair
+       : /* Empty */           { $$ = NULL; }
+       | ',' style             { $$ = new_style_pair($2, 0); }
+       | ',' style ',' style   { $$ = new_style_pair($2, $4); }
+       ;
+ style
+       : style '|' style       { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
+       | '(' style ')'         { $$ = $2; }
 -      int keycode = 0;
++        | xpr                 { $$ = new_style($1, 0); }
++        | tNOT xpr            { $$ = new_style(0, $2); }
+         ;
+ ctlclass
+       : expr  {
+               $$ = new_name_id();
+               $$->type = name_ord;
+               $$->name.i_name = $1;
+               }
+       | tSTRING {
+               $$ = new_name_id();
+               $$->type = name_str;
+               $$->name.s_name = $1;
+               }
+       ;
+ /* ------------------------------ DialogEx ------------------------------ */
+ dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
+         tBEGIN  exctrls tEND {
+               if(!win32)
+                       yywarning("DIALOGEX not supported in 16-bit mode");
+               if($2)
+               {
+                       $11->memopt = *($2);
+                       free($2);
+               }
+               else
+                       $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               $11->x = $3;
+               $11->y = $5;
+               $11->width = $7;
+               $11->height = $9;
+               if($10)
+               {
+                       $11->helpid = *($10);
+                       $11->gothelpid = TRUE;
+                       free($10);
+               }
+               $11->controls = get_control_head($13);
+               $$ = $11;
+               assert($$->style != NULL);
+               if(!$$->gotstyle)
+               {
+                       $$->style->or_mask = WS_POPUP;
+                       $$->gotstyle = TRUE;
+               }
+               if($$->title)
+                       $$->style->or_mask |= WS_CAPTION;
+               if($$->font)
+                       $$->style->or_mask |= DS_SETFONT;
+               $$->style->or_mask &= ~($$->style->and_mask);
+               $$->style->and_mask = 0;
+               if(!$$->lvc.language)
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ dlgex_attribs
+       : /* Empty */                           { $$=new_dialogex(); }
+       | dlgex_attribs tSTYLE style            { $$=dialogex_style($3,$1); }
+       | dlgex_attribs tEXSTYLE style          { $$=dialogex_exstyle($3,$1); }
+       | dlgex_attribs tCAPTION tSTRING        { $$=dialogex_caption($3,$1); }
+       | dlgex_attribs opt_font                { $$=dialogex_font($2,$1); }
+       | dlgex_attribs opt_exfont              { $$=dialogex_font($2,$1); }
+       | dlgex_attribs tCLASS nameid_s         { $$=dialogex_class($3,$1); }
+       | dlgex_attribs tMENU nameid            { $$=dialogex_menu($3,$1); }
+       | dlgex_attribs opt_language            { $$=dialogex_language($2,$1); }
+       | dlgex_attribs opt_characts            { $$=dialogex_characteristics($2,$1); }
+       | dlgex_attribs opt_version             { $$=dialogex_version($2,$1); }
+       ;
+ exctrls       : /* Empty */                           { $$ = NULL; }
+       | exctrls tCONTROL      gen_exctrl      { $$=ins_ctrl(-1, 0, $3, $1); }
+       | exctrls tEDITTEXT     exctrl_desc     { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
+       | exctrls tLISTBOX      exctrl_desc     { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
+       | exctrls tCOMBOBOX     exctrl_desc     { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
+       | exctrls tSCROLLBAR    exctrl_desc     { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
+       | exctrls tCHECKBOX     lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
+       | exctrls tDEFPUSHBUTTON lab_exctrl     { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
+       | exctrls tGROUPBOX     lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
+       | exctrls tPUSHBUTTON   lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
+ /*    | exctrls tPUSHBOX      lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
+       | exctrls tRADIOBUTTON  lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
+       | exctrls tAUTO3STATE   lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
+       | exctrls tSTATE3       lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
+       | exctrls tAUTOCHECKBOX lab_exctrl      { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
+       | exctrls tAUTORADIOBUTTON lab_exctrl   { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
+       | exctrls tLTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
+       | exctrls tCTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
+       | exctrls tRTEXT        lab_exctrl      { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
+       /* special treatment for icons, as the extent is optional */
+       | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
+               $10->title = $3;
+               $10->id = $5;
+               $10->x = $7;
+               $10->y = $9;
+               $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
+               }
+       ;
+ gen_exctrl
+       : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
+         expr ',' style helpid opt_data {
+               $$=new_control();
+               $$->title = $1;
+               $$->id = $3;
+               $$->ctlclass = convert_ctlclass($5);
+               $$->style = $7;
+               $$->gotstyle = TRUE;
+               $$->x = $9;
+               $$->y = $11;
+               $$->width = $13;
+               $$->height = $15;
+               if($17)
+               {
+                       $$->exstyle = $17;
+                       $$->gotexstyle = TRUE;
+               }
+               if($18)
+               {
+                       $$->helpid = *($18);
+                       $$->gothelpid = TRUE;
+                       free($18);
+               }
+               $$->extra = $19;
+               }
+       | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
+               $$=new_control();
+               $$->title = $1;
+               $$->id = $3;
+               $$->style = $7;
+               $$->gotstyle = TRUE;
+               $$->ctlclass = convert_ctlclass($5);
+               $$->x = $9;
+               $$->y = $11;
+               $$->width = $13;
+               $$->height = $15;
+               $$->extra = $16;
+               }
+       ;
+ lab_exctrl
+       : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
+               $$=new_control();
+               $$->title = new_name_id();
+               $$->title->type = name_str;
+               $$->title->name.s_name = $1;
+               $$->id = $3;
+               $$->x = $5;
+               $$->y = $7;
+               $$->width = $9;
+               $$->height = $11;
+               if($12)
+               {
+                       $$->style = $12->style;
+                       $$->gotstyle = TRUE;
+                       if ($12->exstyle)
+                       {
+                           $$->exstyle = $12->exstyle;
+                           $$->gotexstyle = TRUE;
+                       }
+                       free($12);
+               }
+               $$->extra = $14;
+               }
+       ;
+ exctrl_desc
+       : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
+               $$ = new_control();
+               $$->id = $1;
+               $$->x = $3;
+               $$->y = $5;
+               $$->width = $7;
+               $$->height = $9;
+               if($10)
+               {
+                       $$->style = $10->style;
+                       $$->gotstyle = TRUE;
+                       if ($10->exstyle)
+                       {
+                           $$->exstyle = $10->exstyle;
+                           $$->gotexstyle = TRUE;
+                       }
+                       free($10);
+               }
+               $$->extra = $12;
+               }
+       ;
+ opt_data: /* Empty */ { $$ = NULL; }
+       | raw_data      { $$ = $1; }
+       ;
+ helpid        : /* Empty */   { $$ = NULL; }
+       | ',' expr      { $$ = new_int($2); }
+       ;
+ opt_exfont
+       : tFONT expr ',' tSTRING ',' expr ',' expr  opt_expr { $$ = new_font_id($2, $4, $6, $8); }
+       ;
+ /*
+  * FIXME: This odd expression is here to nullify an extra token found
+  * in some appstudio produced resources which appear to do nothing.
+  */
+ opt_expr: /* Empty */ { $$ = NULL; }
+       | ',' expr      { $$ = NULL; }
+       ;
+ /* ------------------------------ Menu ------------------------------ */
+ menu  : tMENU loadmemopts opt_lvc menu_body {
+               if(!$4)
+                       yyerror("Menu must contain items");
+               $$ = new_menu();
+               if($2)
+               {
+                       $$->memopt = *($2);
+                       free($2);
+               }
+               else
+                       $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               $$->items = get_item_head($4);
+               if($3)
+               {
+                       $$->lvc = *($3);
+                       free($3);
+               }
+               if(!$$->lvc.language)
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ menu_body
+       : tBEGIN item_definitions tEND  { $$ = $2; }
+       ;
+ item_definitions
+       : /* Empty */   {$$ = NULL;}
+       | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
+               $$=new_menu_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               $$->id =  $5;
+               $$->state = $6;
+               $$->name = $3;
+               }
+       | item_definitions tMENUITEM tSEPARATOR {
+               $$=new_menu_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               }
+       | item_definitions tPOPUP tSTRING item_options menu_body {
+               $$ = new_menu_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               $$->popup = get_item_head($5);
+               $$->name = $3;
+               }
+       ;
+ /* NOTE: item_options is right recursive because it would introduce
+  * a shift/reduce conflict on ',' in itemex_options due to the
+  * empty rule here. The parser is now forced to look beyond the ','
+  * before reducing (force shift).
+  * Right recursion here is not a problem because we cannot expect
+  * more than 7 parserstack places to be occupied while parsing this
+  * (who would want to specify a MF_x flag twice?).
+  */
+ item_options
+       : /* Empty */                           { $$ = 0; }
+       | ',' tCHECKED          item_options    { $$ = $3 | MF_CHECKED; }
+       | ',' tGRAYED           item_options    { $$ = $3 | MF_GRAYED; }
+       | ',' tHELP             item_options    { $$ = $3 | MF_HELP; }
+       | ',' tINACTIVE         item_options    { $$ = $3 | MF_DISABLED; }
+       | ',' tMENUBARBREAK     item_options    { $$ = $3 | MF_MENUBARBREAK; }
+       | ',' tMENUBREAK        item_options    { $$ = $3 | MF_MENUBREAK; }
+       ;
+ /* ------------------------------ MenuEx ------------------------------ */
+ menuex        : tMENUEX loadmemopts opt_lvc menuex_body       {
+               if(!win32)
+                       yywarning("MENUEX not supported in 16-bit mode");
+               if(!$4)
+                       yyerror("MenuEx must contain items");
+               $$ = new_menuex();
+               if($2)
+               {
+                       $$->memopt = *($2);
+                       free($2);
+               }
+               else
+                       $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               $$->items = get_itemex_head($4);
+               if($3)
+               {
+                       $$->lvc = *($3);
+                       free($3);
+               }
+               if(!$$->lvc.language)
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ menuex_body
+       : tBEGIN itemex_definitions tEND { $$ = $2; }
+       ;
+ itemex_definitions
+       : /* Empty */   {$$ = NULL; }
+       | itemex_definitions tMENUITEM tSTRING itemex_options {
+               $$ = new_menuex_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               $$->name = $3;
+               $$->id = $4->id;
+               $$->type = $4->type;
+               $$->state = $4->state;
+               $$->helpid = $4->helpid;
+               $$->gotid = $4->gotid;
+               $$->gottype = $4->gottype;
+               $$->gotstate = $4->gotstate;
+               $$->gothelpid = $4->gothelpid;
+               free($4);
+               }
+       | itemex_definitions tMENUITEM tSEPARATOR {
+               $$ = new_menuex_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               }
+       | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
+               $$ = new_menuex_item();
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               $$->popup = get_itemex_head($5);
+               $$->name = $3;
+               $$->id = $4->id;
+               $$->type = $4->type;
+               $$->state = $4->state;
+               $$->helpid = $4->helpid;
+               $$->gotid = $4->gotid;
+               $$->gottype = $4->gottype;
+               $$->gotstate = $4->gotstate;
+               $$->gothelpid = $4->gothelpid;
+               free($4);
+               }
+       ;
+ itemex_options
+       : /* Empty */                   { $$ = new_itemex_opt(0, 0, 0, 0); }
+       | ',' expr {
+               $$ = new_itemex_opt($2, 0, 0, 0);
+               $$->gotid = TRUE;
+               }
+       | ',' e_expr ',' e_expr item_options {
+               $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
+               $$->gotid = TRUE;
+               $$->gottype = TRUE;
+               $$->gotstate = TRUE;
+               if($2) free($2);
+               if($4) free($4);
+               }
+       | ',' e_expr ',' e_expr ',' expr {
+               $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
+               $$->gotid = TRUE;
+               $$->gottype = TRUE;
+               $$->gotstate = TRUE;
+               if($2) free($2);
+               if($4) free($4);
+               }
+       ;
+ itemex_p_options
+       : /* Empty */                   { $$ = new_itemex_opt(0, 0, 0, 0); }
+       | ',' expr {
+               $$ = new_itemex_opt($2, 0, 0, 0);
+               $$->gotid = TRUE;
+               }
+       | ',' e_expr ',' expr {
+               $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
+               if($2) free($2);
+               $$->gotid = TRUE;
+               $$->gottype = TRUE;
+               }
+       | ',' e_expr ',' e_expr ',' expr {
+               $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
+               if($2) free($2);
+               if($4) free($4);
+               $$->gotid = TRUE;
+               $$->gottype = TRUE;
+               $$->gotstate = TRUE;
+               }
+       | ',' e_expr ',' e_expr ',' e_expr ',' expr {
+               $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
+               if($2) free($2);
+               if($4) free($4);
+               if($6) free($6);
+               $$->gotid = TRUE;
+               $$->gottype = TRUE;
+               $$->gotstate = TRUE;
+               $$->gothelpid = TRUE;
+               }
+       ;
+ /* ------------------------------ StringTable ------------------------------ */
+ /* Stringtables are parsed differently than other resources because their
+  * layout is substantially different from other resources.
+  * The table is parsed through a _global_ variable 'tagstt' which holds the
+  * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
+  * list of stringtables of different languages.
+  */
+ stringtable
+       : stt_head tBEGIN strings tEND {
+               if(!$3)
+               {
+                       yyerror("Stringtable must have at least one entry");
+               }
+               else
+               {
+                       stringtable_t *stt;
+                       /* Check if we added to a language table or created
+                        * a new one.
+                        */
+                        for(stt = sttres; stt; stt = stt->next)
+                        {
+                               if(stt == tagstt)
+                                       break;
+                        }
+                        if(!stt)
+                        {
+                               /* It is a new one */
+                               if(sttres)
+                               {
+                                       sttres->prev = tagstt;
+                                       tagstt->next = sttres;
+                                       sttres = tagstt;
+                               }
+                               else
+                                       sttres = tagstt;
+                        }
+                        /* Else were done */
+               }
+               if(tagstt_memopt)
+               {
+                       free(tagstt_memopt);
+                       tagstt_memopt = NULL;
+               }
+               $$ = tagstt;
+               }
+       ;
+ /* This is to get the language of the currently parsed stringtable */
+ stt_head: tSTRINGTABLE loadmemopts opt_lvc {
+               if((tagstt = find_stringtable($3)) == NULL)
+                       tagstt = new_stringtable($3);
+               tagstt_memopt = $2;
+               tagstt_version = $3->version;
+               tagstt_characts = $3->characts;
+               if($3)
+                       free($3);
+               }
+       ;
+ strings       : /* Empty */   { $$ = NULL; }
+       | strings expr opt_comma tSTRING {
+               int i;
+               assert(tagstt != NULL);
+               if($2 > 65535 || $2 < -32768)
+                       yyerror("Stringtable entry's ID out of range (%d)", $2);
+               /* Search for the ID */
+               for(i = 0; i < tagstt->nentries; i++)
+               {
+                       if(tagstt->entries[i].id == $2)
+                               yyerror("Stringtable ID %d already in use", $2);
+               }
+               /* If we get here, then we have a new unique entry */
+               tagstt->nentries++;
+               tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
+               tagstt->entries[tagstt->nentries-1].id = $2;
+               tagstt->entries[tagstt->nentries-1].str = $4;
+               if(tagstt_memopt)
+                       tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
+               else
+                       tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
+               tagstt->entries[tagstt->nentries-1].version = tagstt_version;
+               tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
+               if(pedantic && !$4->size)
+                       yywarning("Zero length strings make no sense");
+               if(!win32 && $4->size > 254)
+                       yyerror("Stringtable entry more than 254 characters");
+               if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
+                       yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
+               $$ = tagstt;
+               }
+       ;
+ opt_comma     /* There seem to be two ways to specify a stringtable... */
+       : /* Empty */
+       | ','
+       ;
+ /* ------------------------------ VersionInfo ------------------------------ */
+ versioninfo
+       : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
+               $$ = $3;
+               if($2)
+               {
+                       $$->memopt = *($2);
+                       free($2);
+               }
+               else
+                       $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
+               $$->blocks = get_ver_block_head($5);
+               /* Set language; there is no version or characteristics */
+               $$->lvc.language = dup_language(currentlanguage);
+               }
+       ;
+ fix_version
+       : /* Empty */                   { $$ = new_versioninfo(); }
+       | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
+               if($1->gotit.fv)
+                       yyerror("FILEVERSION already defined");
+               $$ = $1;
+               $$->filever_maj1 = $3;
+               $$->filever_maj2 = $5;
+               $$->filever_min1 = $7;
+               $$->filever_min2 = $9;
+               $$->gotit.fv = 1;
+               }
+       | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
+               if($1->gotit.pv)
+                       yyerror("PRODUCTVERSION already defined");
+               $$ = $1;
+               $$->prodver_maj1 = $3;
+               $$->prodver_maj2 = $5;
+               $$->prodver_min1 = $7;
+               $$->prodver_min2 = $9;
+               $$->gotit.pv = 1;
+               }
+       | fix_version tFILEFLAGS expr {
+               if($1->gotit.ff)
+                       yyerror("FILEFLAGS already defined");
+               $$ = $1;
+               $$->fileflags = $3;
+               $$->gotit.ff = 1;
+               }
+       | fix_version tFILEFLAGSMASK expr {
+               if($1->gotit.ffm)
+                       yyerror("FILEFLAGSMASK already defined");
+               $$ = $1;
+               $$->fileflagsmask = $3;
+               $$->gotit.ffm = 1;
+               }
+       | fix_version tFILEOS expr {
+               if($1->gotit.fo)
+                       yyerror("FILEOS already defined");
+               $$ = $1;
+               $$->fileos = $3;
+               $$->gotit.fo = 1;
+               }
+       | fix_version tFILETYPE expr {
+               if($1->gotit.ft)
+                       yyerror("FILETYPE already defined");
+               $$ = $1;
+               $$->filetype = $3;
+               $$->gotit.ft = 1;
+               }
+       | fix_version tFILESUBTYPE expr {
+               if($1->gotit.fst)
+                       yyerror("FILESUBTYPE already defined");
+               $$ = $1;
+               $$->filesubtype = $3;
+               $$->gotit.fst = 1;
+               }
+       ;
+ ver_blocks
+       : /* Empty */                   { $$ = NULL; }
+       | ver_blocks ver_block {
+               $$ = $2;
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               }
+       ;
+ ver_block
+       : tBLOCK tSTRING tBEGIN ver_values tEND {
+               $$ = new_ver_block();
+               $$->name = $2;
+               $$->values = get_ver_value_head($4);
+               }
+       ;
+ ver_values
+       : /* Empty */                   { $$ = NULL; }
+       | ver_values ver_value {
+               $$ = $2;
+               $$->prev = $1;
+               if($1)
+                       $1->next = $$;
+               }
+       ;
+ ver_value
+       : ver_block {
+               $$ = new_ver_value();
+               $$->type = val_block;
+               $$->value.block = $1;
+               }
+       | tVALUE tSTRING ',' tSTRING {
+               $$ = new_ver_value();
+               $$->type = val_str;
+               $$->key = $2;
+               $$->value.str = $4;
+               }
+       | tVALUE tSTRING ',' ver_words {
+               $$ = new_ver_value();
+               $$->type = val_words;
+               $$->key = $2;
+               $$->value.words = $4;
+               }
+       ;
+ ver_words
+       : expr                  { $$ = new_ver_words($1); }
+       | ver_words ',' expr    { $$ = add_ver_words($1, $3); }
+       ;
+ /* ------------------------------ Toolbar ------------------------------ */
+ toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
+               int nitems;
+               toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
+               $$ = new_toolbar($3, $5, items, nitems);
+               if($2)
+               {
+                       $$->memopt = *($2);
+                       free($2);
+               }
+               else
+               {
+                       $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
+               }
+               if($6)
+               {
+                       $$->lvc = *($6);
+                       free($6);
+               }
+               if(!$$->lvc.language)
+               {
+                       $$->lvc.language = dup_language(currentlanguage);
+               }
+               }
+       ;
+ toolbar_items
+       :  /* Empty */                  { $$ = NULL; }
+       | toolbar_items tBUTTON expr    {
+               toolbar_item_t *idrec = new_toolbar_item();
+               idrec->id = $3;
+               $$ = ins_tlbr_button($1, idrec);
+               }
+       | toolbar_items tSEPARATOR      {
+               toolbar_item_t *idrec = new_toolbar_item();
+               idrec->id = 0;
+               $$ = ins_tlbr_button($1, idrec);
+       }
+       ;
+ /* ------------------------------ Memory options ------------------------------ */
+ loadmemopts
+       : /* Empty */           { $$ = NULL; }
+       | loadmemopts lamo {
+               if($1)
+               {
+                       *($1) |= *($2);
+                       $$ = $1;
+                       free($2);
+               }
+               else
+                       $$ = $2;
+               }
+       | loadmemopts lama {
+               if($1)
+               {
+                       *($1) &= *($2);
+                       $$ = $1;
+                       free($2);
+               }
+               else
+               {
+                       *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
+                       $$ = $2;
+               }
+               }
+       ;
+ lamo  : tPRELOAD      { $$ = new_int(WRC_MO_PRELOAD); }
+       | tMOVEABLE     { $$ = new_int(WRC_MO_MOVEABLE); }
+       | tDISCARDABLE  { $$ = new_int(WRC_MO_DISCARDABLE); }
+       | tPURE         { $$ = new_int(WRC_MO_PURE); }
+       ;
+ lama  : tLOADONCALL   { $$ = new_int(~WRC_MO_PRELOAD); }
+       | tFIXED        { $$ = new_int(~WRC_MO_MOVEABLE); }
+       | tIMPURE       { $$ = new_int(~WRC_MO_PURE); }
+       ;
+ /* ------------------------------ Win32 options ------------------------------ */
+ opt_lvc       : /* Empty */           { $$ = new_lvc(); }
+       | opt_lvc opt_language {
+               if(!win32)
+                       yywarning("LANGUAGE not supported in 16-bit mode");
+               if($1->language)
+                       yyerror("Language already defined");
+               $$ = $1;
+               $1->language = $2;
+               }
+       | opt_lvc opt_characts {
+               if(!win32)
+                       yywarning("CHARACTERISTICS not supported in 16-bit mode");
+               if($1->characts)
+                       yyerror("Characteristics already defined");
+               $$ = $1;
+               $1->characts = $2;
+               }
+       | opt_lvc opt_version {
+               if(!win32)
+                       yywarning("VERSION not supported in 16-bit mode");
+               if($1->version)
+                       yyerror("Version already defined");
+               $$ = $1;
+               $1->version = $2;
+               }
+       ;
+       /*
+        * This here is another s/r conflict on {bi,u}nary + and -.
+        * It is due to the look-ahead which must determine when the
+        * rule opt_language ends. It could be solved with adding a
+        * tNL at the end, but that seems unreasonable to do.
+        * The conflict is now moved to the expression handling below.
+        */
+ opt_language
+       : tLANGUAGE expr ',' expr       { $$ = new_language($2, $4);
+                                         if (get_language_codepage($2, $4) == -1)
+                                               yyerror( "Language %04x is not supported", ($4<<10) + $2);
+                                       }
+       ;
+ opt_characts
+       : tCHARACTERISTICS expr         { $$ = new_characts($2); }
+       ;
+ opt_version
+       : tVERSION expr                 { $$ = new_version($2); }
+       ;
+ /* ------------------------------ Raw data handling ------------------------------ */
+ raw_data: opt_lvc tBEGIN raw_elements tEND {
+               if($1)
+               {
+                       $3->lvc = *($1);
+                       free($1);
+               }
+               if(!$3->lvc.language)
+                       $3->lvc.language = dup_language(currentlanguage);
+               $$ = $3;
+               }
+       ;
+ raw_elements
+       : tRAWDATA                      { $$ = $1; }
+       | tNUMBER                       { $$ = int2raw_data($1); }
+       | '-' tNUMBER                   { $$ = int2raw_data(-($2)); }
+       | tLNUMBER                      { $$ = long2raw_data($1); }
+       | '-' tLNUMBER                  { $$ = long2raw_data(-($2)); }
+       | tSTRING                       { $$ = str2raw_data($1); }
+       | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
+       | raw_elements opt_comma tNUMBER  { $$ = merge_raw_data_int($1, $3); }
+       | raw_elements opt_comma '-' tNUMBER  { $$ = merge_raw_data_int($1, -($4)); }
+       | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
+       | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
+       | raw_elements opt_comma tSTRING  { $$ = merge_raw_data_str($1, $3); }
+       ;
+ /* File data or raw data */
+ file_raw: filename    { $$ = load_file($1,dup_language(currentlanguage)); }
+       | raw_data      { $$ = $1; }
+       ;
+ /* ------------------------------ Win32 expressions ------------------------------ */
+ /* All win16 numbers are also handled here. This is inconsistent with MS'
+  * resource compiler, but what the heck, its just handy to have.
+  */
+ e_expr        : /* Empty */   { $$ = 0; }
+       | expr          { $$ = new_int($1); }
+       ;
+ /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
+ expr  : xpr   { $$ = ($1); }
+       ;
+ xpr   : xpr '+' xpr   { $$ = ($1) + ($3); }
+       | xpr '-' xpr   { $$ = ($1) - ($3); }
+       | xpr '|' xpr   { $$ = ($1) | ($3); }
+       | xpr '&' xpr   { $$ = ($1) & ($3); }
+       | xpr '*' xpr   { $$ = ($1) * ($3); }
+       | xpr '/' xpr   { $$ = ($1) / ($3); }
+       | xpr '^' xpr   { $$ = ($1) ^ ($3); }
+       | '~' xpr       { $$ = ~($2); }
+       | '-' xpr %prec pUPM    { $$ = -($2); }
+       | '+' xpr %prec pUPM    { $$ = $2; }
+       | '(' xpr ')'   { $$ = $2; }
+       | any_num       { $$ = $1; }
+       | tNOT any_num  { $$ = ~($2); }
+       ;
+ any_num       : tNUMBER       { $$ = $1; }
+       | tLNUMBER      { $$ = $1; }
+       ;
+ %%
+ /* Dialog specific functions */
+ static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->style == NULL)
+       {
+               dlg->style = new_style(0,0);
+       }
+       if(dlg->gotstyle)
+       {
+               yywarning("Style already defined, or-ing together");
+       }
+       else
+       {
+               dlg->style->or_mask = 0;
+               dlg->style->and_mask = 0;
+       }
+       dlg->style->or_mask |= st->or_mask;
+       dlg->style->and_mask |= st->and_mask;
+       dlg->gotstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->exstyle == NULL)
+       {
+               dlg->exstyle = new_style(0,0);
+       }
+       if(dlg->gotexstyle)
+       {
+               yywarning("ExStyle already defined, or-ing together");
+       }
+       else
+       {
+               dlg->exstyle->or_mask = 0;
+               dlg->exstyle->and_mask = 0;
+       }
+       dlg->exstyle->or_mask |= st->or_mask;
+       dlg->exstyle->and_mask |= st->and_mask;
+       dlg->gotexstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->title)
+               yyerror("Caption already defined");
+       dlg->title = s;
+       return dlg;
+ }
+ static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->font)
+               yyerror("Font already defined");
+       dlg->font = f;
+       return dlg;
+ }
+ static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->dlgclass)
+               yyerror("Class already defined");
+       dlg->dlgclass = n;
+       return dlg;
+ }
+ static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->menu)
+               yyerror("Menu already defined");
+       dlg->menu = m;
+       return dlg;
+ }
+ static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.language)
+               yyerror("Language already defined");
+       dlg->lvc.language = l;
+       return dlg;
+ }
+ static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.characts)
+               yyerror("Characteristics already defined");
+       dlg->lvc.characts = c;
+       return dlg;
+ }
+ static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.version)
+               yyerror("Version already defined");
+       dlg->lvc.version = v;
+       return dlg;
+ }
+ /* Controls specific functions */
+ static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
+ {
+       /* Hm... this seems to be jammed in at all time... */
+       int defaultstyle = WS_CHILD | WS_VISIBLE;
+       assert(ctrl != NULL);
+       ctrl->prev = prev;
+       if(prev)
+               prev->next = ctrl;
+       if(type != -1)
+       {
+               ctrl->ctlclass = new_name_id();
+               ctrl->ctlclass->type = name_ord;
+               ctrl->ctlclass->name.i_name = type;
+       }
+       switch(type)
+       {
+       case CT_BUTTON:
+               if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
+                       defaultstyle |= WS_TABSTOP;
+               break;
+       case CT_EDIT:
+               defaultstyle |= WS_TABSTOP | WS_BORDER;
+               break;
+       case CT_LISTBOX:
+               defaultstyle |= LBS_NOTIFY | WS_BORDER;
+               break;
+       case CT_COMBOBOX:
+                 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
+                     defaultstyle |= CBS_SIMPLE;
+               break;
+       case CT_STATIC:
+               if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
+                       defaultstyle |= WS_GROUP;
+               break;
+       }
+       if(!ctrl->gotstyle)     /* Handle default style setting */
+       {
+               switch(type)
+               {
+               case CT_EDIT:
+                       defaultstyle |= ES_LEFT;
+                       break;
+               case CT_LISTBOX:
+                       defaultstyle |= LBS_NOTIFY;
+                       break;
+               case CT_COMBOBOX:
+                       defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
+                       break;
+               case CT_SCROLLBAR:
+                       defaultstyle |= SBS_HORZ;
+                       break;
+               case CT_BUTTON:
+                       switch(special_style)
+                       {
+                       case BS_CHECKBOX:
+                       case BS_DEFPUSHBUTTON:
+                       case BS_PUSHBUTTON:
+ /*                    case BS_PUSHBOX:        */
+                       case BS_AUTORADIOBUTTON:
+                       case BS_AUTO3STATE:
+                       case BS_3STATE:
+                       case BS_AUTOCHECKBOX:
+                               defaultstyle |= WS_TABSTOP;
+                               break;
+                       default:
+                               yywarning("Unknown default button control-style 0x%08x", special_style);
+                       case BS_GROUPBOX:
+                       case BS_RADIOBUTTON:
+                               break;
+                       }
+                       break;
+               case CT_STATIC:
+                       switch(special_style)
+                       {
+                       case SS_LEFT:
+                       case SS_RIGHT:
+                       case SS_CENTER:
+                               defaultstyle |= WS_GROUP;
+                               break;
+                       case SS_ICON:   /* Special case */
+                               break;
+                       default:
+                               yywarning("Unknown default static control-style 0x%08x", special_style);
+                               break;
+                       }
+                       break;
+               case -1:        /* Generic control */
+                       goto byebye;
+               default:
+                       yyerror("Internal error (report this): Got weird control type 0x%08x", type);
+               }
+       }
+       /* The SS_ICON flag is always forced in for icon controls */
+       if(type == CT_STATIC && special_style == SS_ICON)
+               defaultstyle |= SS_ICON;
+       if (!ctrl->gotstyle)
+               ctrl->style = new_style(0,0);
+       /* combine all styles */
+       ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
+       ctrl->gotstyle = TRUE;
+ byebye:
+       /* combine with NOT mask */
+       if (ctrl->gotstyle)
+       {
+               ctrl->style->or_mask &= ~(ctrl->style->and_mask);
+               ctrl->style->and_mask = 0;
+       }
+       if (ctrl->gotexstyle)
+       {
+               ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
+               ctrl->exstyle->and_mask = 0;
+       }
+       return ctrl;
+ }
+ static name_id_t *convert_ctlclass(name_id_t *cls)
+ {
+       char *cc = NULL;
+       int iclass;
+       if(cls->type == name_ord)
+               return cls;
+       assert(cls->type == name_str);
+       if(cls->type == str_unicode)
+       {
+               yyerror("Don't yet support unicode class comparison");
+       }
+       else
+               cc = cls->name.s_name->str.cstr;
+       if(!strcasecmp("BUTTON", cc))
+               iclass = CT_BUTTON;
+       else if(!strcasecmp("COMBOBOX", cc))
+               iclass = CT_COMBOBOX;
+       else if(!strcasecmp("LISTBOX", cc))
+               iclass = CT_LISTBOX;
+       else if(!strcasecmp("EDIT", cc))
+               iclass = CT_EDIT;
+       else if(!strcasecmp("STATIC", cc))
+               iclass = CT_STATIC;
+       else if(!strcasecmp("SCROLLBAR", cc))
+               iclass = CT_SCROLLBAR;
+       else
+               return cls;     /* No default, return user controlclass */
+       free(cls->name.s_name->str.cstr);
+       free(cls->name.s_name);
+       cls->type = name_ord;
+       cls->name.i_name = iclass;
+       return cls;
+ }
+ /* DialogEx specific functions */
+ static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->style == NULL)
+       {
+               dlg->style = new_style(0,0);
+       }
+       if(dlg->gotstyle)
+       {
+               yywarning("Style already defined, or-ing together");
+       }
+       else
+       {
+               dlg->style->or_mask = 0;
+               dlg->style->and_mask = 0;
+       }
+       dlg->style->or_mask |= st->or_mask;
+       dlg->style->and_mask |= st->and_mask;
+       dlg->gotstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->exstyle == NULL)
+       {
+               dlg->exstyle = new_style(0,0);
+       }
+       if(dlg->gotexstyle)
+       {
+               yywarning("ExStyle already defined, or-ing together");
+       }
+       else
+       {
+               dlg->exstyle->or_mask = 0;
+               dlg->exstyle->and_mask = 0;
+       }
+       dlg->exstyle->or_mask |= st->or_mask;
+       dlg->exstyle->and_mask |= st->and_mask;
+       dlg->gotexstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->title)
+               yyerror("Caption already defined");
+       dlg->title = s;
+       return dlg;
+ }
+ static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->font)
+               yyerror("Font already defined");
+       dlg->font = f;
+       return dlg;
+ }
+ static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->dlgclass)
+               yyerror("Class already defined");
+       dlg->dlgclass = n;
+       return dlg;
+ }
+ static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->menu)
+               yyerror("Menu already defined");
+       dlg->menu = m;
+       return dlg;
+ }
+ static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.language)
+               yyerror("Language already defined");
+       dlg->lvc.language = l;
+       return dlg;
+ }
+ static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.characts)
+               yyerror("Characteristics already defined");
+       dlg->lvc.characts = c;
+       return dlg;
+ }
+ static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.version)
+               yyerror("Version already defined");
+       dlg->lvc.version = v;
+       return dlg;
+ }
+ /* Accelerator specific functions */
+ static event_t *add_event(int key, int id, int flags, event_t *prev)
+ {
+       event_t *ev = new_event();
+       if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
+               yyerror("Cannot use both ASCII and VIRTKEY");
+       ev->key = key;
+       ev->id = id;
+       ev->flags = flags & ~WRC_AF_ASCII;
+       ev->prev = prev;
+       if(prev)
+               prev->next = ev;
+       return ev;
+ }
+ static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
+ {
 -      if(key->type != str_char)
 -              yyerror("Key code must be an ascii string");
++      int keycode = 0, keysym = 0;
+       event_t *ev = new_event();
 -      if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
++      if(key->type == str_char)
++              keysym = key->str.cstr[0];
++      else
++              keysym = key->str.wstr[0];
 -      if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
++      if((flags & WRC_AF_VIRTKEY) && (!isupper(keysym & 0xff) && !isdigit(keysym & 0xff)))
+               yyerror("VIRTKEY code is not equal to ascii value");
 -      else if(key->str.cstr[0] == '^')
++      if(keysym == '^' && (flags & WRC_AF_CONTROL) != 0)
+       {
+               yyerror("Cannot use both '^' and CONTROL modifier");
+       }
 -              keycode = toupper(key->str.cstr[1]) - '@';
++      else if(keysym == '^')
+       {
 -              keycode = key->str.cstr[0];
++              if(key->type == str_char)
++                      keycode = toupper(key->str.cstr[1]) - '@';
++              else
++                      keycode = toupper(key->str.wstr[1]) - '@';
+               if(keycode >= ' ')
+                       yyerror("Control-code out of range");
+       }
+       else
++              keycode = keysym;
+       ev->key = keycode;
+       ev->id = id;
+       ev->flags = flags & ~WRC_AF_ASCII;
+       ev->prev = prev;
+       if(prev)
+               prev->next = ev;
+       return ev;
+ }
+ /* MenuEx specific functions */
+ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
+ {
+       itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
+       opt->id = id;
+       opt->type = type;
+       opt->state = state;
+       opt->helpid = helpid;
+       return opt;
+ }
+ /* Raw data functions */
+ static raw_data_t *load_file(string_t *filename, language_t *lang)
+ {
+       FILE *fp = NULL;
+       char *path;
+       raw_data_t *rd;
+       string_t *name;
+       int codepage = get_language_codepage(lang->id, lang->sub);
+       /* FIXME: we may want to use utf-8 here */
+       if (codepage <= 0 && filename->type != str_char)
+               yyerror("Cannot convert filename to ASCII string");
+       name = convert_string( filename, str_char, codepage );
+       if (!(path = wpp_find_include(name->str.cstr, 1)))
+               yyerror("Cannot open file %s", name->str.cstr);
+       if (!(fp = fopen( path, "rb" )))
+               yyerror("Cannot open file %s", name->str.cstr);
+       free( path );
+       rd = new_raw_data();
+       fseek(fp, 0, SEEK_END);
+       rd->size = ftell(fp);
+       fseek(fp, 0, SEEK_SET);
+       if (rd->size)
+       {
+               rd->data = (char *)xmalloc(rd->size);
+               fread(rd->data, rd->size, 1, fp);
+       }
+       else rd->data = NULL;
+       fclose(fp);
+       rd->lvc.language = lang;
+       free_string(name);
+       return rd;
+ }
+ static raw_data_t *int2raw_data(int i)
+ {
+       raw_data_t *rd;
+       if( ( i >= 0 && (int)((unsigned short)i) != i) ||
+             ( i < 0  && (int)((short)i) != i) )
+               yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
+       rd = new_raw_data();
+       rd->size = sizeof(short);
+       rd->data = (char *)xmalloc(rd->size);
+       switch(byteorder)
+       {
+ #ifdef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_BIG:
+               rd->data[0] = HIBYTE(i);
+               rd->data[1] = LOBYTE(i);
+               break;
+ #ifndef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_LITTLE:
+               rd->data[1] = HIBYTE(i);
+               rd->data[0] = LOBYTE(i);
+               break;
+       }
+       return rd;
+ }
+ static raw_data_t *long2raw_data(int i)
+ {
+       raw_data_t *rd;
+       rd = new_raw_data();
+       rd->size = sizeof(int);
+       rd->data = (char *)xmalloc(rd->size);
+       switch(byteorder)
+       {
+ #ifdef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_BIG:
+               rd->data[0] = HIBYTE(HIWORD(i));
+               rd->data[1] = LOBYTE(HIWORD(i));
+               rd->data[2] = HIBYTE(LOWORD(i));
+               rd->data[3] = LOBYTE(LOWORD(i));
+               break;
+ #ifndef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_LITTLE:
+               rd->data[3] = HIBYTE(HIWORD(i));
+               rd->data[2] = LOBYTE(HIWORD(i));
+               rd->data[1] = HIBYTE(LOWORD(i));
+               rd->data[0] = LOBYTE(LOWORD(i));
+               break;
+       }
+       return rd;
+ }
+ static raw_data_t *str2raw_data(string_t *str)
+ {
+       raw_data_t *rd;
+       rd = new_raw_data();
+       rd->size = str->size * (str->type == str_char ? 1 : 2);
+       rd->data = (char *)xmalloc(rd->size);
+       if(str->type == str_char)
+               memcpy(rd->data, str->str.cstr, rd->size);
+       else if(str->type == str_unicode)
+       {
+               int i;
+               switch(byteorder)
+               {
+ #ifdef WORDS_BIGENDIAN
+               default:
+ #endif
+               case WRC_BO_BIG:
+                       for(i = 0; i < str->size; i++)
+                       {
+                               rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
+                               rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
+                       }
+                       break;
+ #ifndef WORDS_BIGENDIAN
+               default:
+ #endif
+               case WRC_BO_LITTLE:
+                       for(i = 0; i < str->size; i++)
+                       {
+                               rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
+                               rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
+                       }
+                       break;
+               }
+       }
+       else
+               internal_error(__FILE__, __LINE__, "Invalid stringtype");
+       return rd;
+ }
+ static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
+ {
+       r1->data = xrealloc(r1->data, r1->size + r2->size);
+       memcpy(r1->data + r1->size, r2->data, r2->size);
+       r1->size += r2->size;
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
+ {
+       raw_data_t *t = int2raw_data(i);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
+ {
+       raw_data_t *t = long2raw_data(i);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
+ {
+       raw_data_t *t = str2raw_data(str);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ /* Function the go back in a list to get the head */
+ static menu_item_t *get_item_head(menu_item_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static menuex_item_t *get_itemex_head(menuex_item_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static resource_t *get_resource_head(resource_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static ver_block_t *get_ver_block_head(ver_block_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static ver_value_t *get_ver_value_head(ver_value_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static control_t *get_control_head(control_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static event_t *get_event_head(event_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ /* Find a stringtable with given language */
+ static stringtable_t *find_stringtable(lvc_t *lvc)
+ {
+       stringtable_t *stt;
+       assert(lvc != NULL);
+       if(!lvc->language)
+               lvc->language = dup_language(currentlanguage);
+       for(stt = sttres; stt; stt = stt->next)
+       {
+               if(stt->lvc.language->id == lvc->language->id
+               && stt->lvc.language->sub == lvc->language->sub)
+               {
+                       /* Found a table with the same language */
+                       /* The version and characteristics are now handled
+                        * in the generation of the individual stringtables.
+                        * This enables localized analysis.
+                       if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
+                       || (!stt->lvc.version && lvc->version)
+                       || (stt->lvc.version && !lvc->version))
+                               yywarning("Stringtable's versions are not the same, using first definition");
+                       if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
+                       || (!stt->lvc.characts && lvc->characts)
+                       || (stt->lvc.characts && !lvc->characts))
+                               yywarning("Stringtable's characteristics are not the same, using first definition");
+                       */
+                       return stt;
+               }
+       }
+       return NULL;
+ }
+ /* qsort sorting function for string table entries */
+ #define STE(p)        ((stt_entry_t *)(p))
+ static int sort_stt_entry(const void *e1, const void *e2)
+ {
+       return STE(e1)->id - STE(e2)->id;
+ }
+ #undef STE
+ static resource_t *build_stt_resources(stringtable_t *stthead)
+ {
+       stringtable_t *stt;
+       stringtable_t *newstt;
+       resource_t *rsc;
+       resource_t *rsclist = NULL;
+       resource_t *rsctail = NULL;
+       int i;
+       int j;
+       DWORD andsum;
+       DWORD orsum;
+       characts_t *characts;
+       version_t *version;
+       if(!stthead)
+               return NULL;
+       /* For all languages defined */
+       for(stt = stthead; stt; stt = stt->next)
+       {
+               assert(stt->nentries > 0);
+               /* Sort the entries */
+               if(stt->nentries > 1)
+                       qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
+               for(i = 0; i < stt->nentries; )
+               {
+                       newstt = new_stringtable(&stt->lvc);
+                       newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
+                       newstt->nentries = 16;
+                       newstt->idbase = stt->entries[i].id & ~0xf;
+                       for(j = 0; j < 16 && i < stt->nentries; j++)
+                       {
+                               if(stt->entries[i].id - newstt->idbase == j)
+                               {
+                                       newstt->entries[j] = stt->entries[i];
+                                       i++;
+                               }
+                       }
+                       andsum = ~0;
+                       orsum = 0;
+                       characts = NULL;
+                       version = NULL;
+                       /* Check individual memory options and get
+                        * the first characteristics/version
+                        */
+                       for(j = 0; j < 16; j++)
+                       {
+                               if(!newstt->entries[j].str)
+                                       continue;
+                               andsum &= newstt->entries[j].memopt;
+                               orsum |= newstt->entries[j].memopt;
+                               if(!characts)
+                                       characts = newstt->entries[j].characts;
+                               if(!version)
+                                       version = newstt->entries[j].version;
+                       }
+                       if(andsum != orsum)
+                       {
+                               warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
+                       }
+                       /* Check version and characteristics */
+                       for(j = 0; j < 16; j++)
+                       {
+                               if(characts
+                               && newstt->entries[j].characts
+                               && *newstt->entries[j].characts != *characts)
+                                       warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
+                               if(version
+                               && newstt->entries[j].version
+                               && *newstt->entries[j].version != *version)
+                                       warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
+                       }
+                       rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
+                       rsc->name = new_name_id();
+                       rsc->name->type = name_ord;
+                       rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
+                       rsc->memopt = andsum; /* Set to least common denominator */
+                       newstt->memopt = andsum;
+                       newstt->lvc.characts = characts;
+                       newstt->lvc.version = version;
+                       if(!rsclist)
+                       {
+                               rsclist = rsc;
+                               rsctail = rsc;
+                       }
+                       else
+                       {
+                               rsctail->next = rsc;
+                               rsc->prev = rsctail;
+                               rsctail = rsc;
+                       }
+               }
+       }
+       return rsclist;
+ }
+ static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
+ {
+       idrec->prev = prev;
+       if(prev)
+               prev->next = idrec;
+       return idrec;
+ }
+ static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
+ {
+       if(!p)
+       {
+               *nitems = 0;
+               return NULL;
+       }
+       *nitems = 1;
+       while(p->prev)
+       {
+               (*nitems)++;
+               p = p->prev;
+       }
+       return p;
+ }
+ static string_t *make_filename(string_t *str)
+ {
+     if(str->type == str_char)
+     {
+       char *cptr;
+       /* Remove escaped backslash and convert to forward */
+       for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
+       {
+               if(cptr[1] == '\\')
+               {
+                       memmove(cptr, cptr+1, strlen(cptr));
+                       str->size--;
+               }
+               *cptr = '/';
+       }
+     }
+     else
+     {
+       WCHAR *wptr;
+       /* Remove escaped backslash and convert to forward */
+       for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
+       {
+               if(wptr[1] == '\\')
+               {
+                       memmove(wptr, wptr+1, strlenW(wptr));
+                       str->size--;
+               }
+               *wptr = '/';
+       }
+     }
+     return str;
+ }
+ /*
+  * Process all resources to extract fonts and build
+  * a fontdir resource.
+  *
+  * Note: MS' resource compiler (build 1472) does not
+  * handle font resources with different languages.
+  * The fontdir is generated in the last active language
+  * and font identifiers must be unique across the entire
+  * source.
+  * This is not logical considering the localization
+  * constraints of all other resource types. MS has,
+  * most probably, never testet localized fonts. However,
+  * using fontresources is rare, so it might not occur
+  * in normal applications.
+  * Wine does require better localization because a lot
+  * of languages are coded into the same executable.
+  * Therefore, I will generate fontdirs for *each*
+  * localized set of fonts.
+  */
+ static resource_t *build_fontdir(resource_t **fnt, int nfnt)
+ {
+       static int once = 0;
+       if(!once)
+       {
+               warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
+               once++;
+       }
+       return NULL;
+ }
+ static resource_t *build_fontdirs(resource_t *tail)
+ {
+       resource_t *rsc;
+       resource_t *lst = NULL;
+       resource_t **fnt = NULL;        /* List of all fonts */
+       int nfnt = 0;
+       resource_t **fnd = NULL;        /* List of all fontdirs */
+       int nfnd = 0;
+       resource_t **lanfnt = NULL;
+       int nlanfnt = 0;
+       int i;
+       name_id_t nid;
+       string_t str;
+       int fntleft;
+       nid.type = name_str;
+       nid.name.s_name = &str;
+       str.type = str_char;
+       str.str.cstr = xstrdup("FONTDIR");
+       str.size = 7;
+       /* Extract all fonts and fontdirs */
+       for(rsc = tail; rsc; rsc = rsc->prev)
+       {
+               if(rsc->type == res_fnt)
+               {
+                       nfnt++;
+                       fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
+                       fnt[nfnt-1] = rsc;
+               }
+               else if(rsc->type == res_fntdir)
+               {
+                       nfnd++;
+                       fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
+                       fnd[nfnd-1] = rsc;
+               }
+       }
+       /* Verify the name of the present fontdirs */
+       for(i = 0; i < nfnd; i++)
+       {
+               if(compare_name_id(&nid, fnd[i]->name))
+               {
+                       warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
+                               get_nameid_str(fnd[i]->name));
+                       fnd[i] = NULL;
+               }
+       }
+       /* Sanity check */
+       if(nfnt == 0)
+       {
+               if(nfnd != 0)
+                       warning("Found %d FONTDIR entries without any fonts present", nfnd);
+               goto clean;
+       }
+       /* Copy space */
+       lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
+       /* Get all fonts covered by fontdirs */
+       for(i = 0; i < nfnd; i++)
+       {
+               int j;
+               WORD cnt;
+               int isswapped = 0;
+               if(!fnd[i])
+                       continue;
+               for(j = 0; j < nfnt; j++)
+               {
+                       if(!fnt[j])
+                               continue;
+                       if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
+                       {
+                               lanfnt[nlanfnt] = fnt[j];
+                               nlanfnt++;
+                               fnt[j] = NULL;
+                       }
+               }
+               cnt = *(WORD *)fnd[i]->res.fnd->data->data;
+               if(nlanfnt == cnt)
+                       isswapped = 0;
+               else if(nlanfnt == BYTESWAP_WORD(cnt))
+                       isswapped = 1;
+               else
+                       error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
+                               fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
+ #ifdef WORDS_BIGENDIAN
+               if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
+ #else
+               if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
+ #endif
+               {
+                       internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
+               }
+       }
+       /* We now have fonts left where we need to make a fontdir resource */
+       for(i = fntleft = 0; i < nfnt; i++)
+       {
+               if(fnt[i])
+                       fntleft++;
+       }
+       while(fntleft)
+       {
+               /* Get fonts of same language in lanfnt[] */
+               for(i = nlanfnt = 0; i < nfnt; i++)
+               {
+                       if(fnt[i])
+                       {
+                               if(!nlanfnt)
+                               {
+                       addlanfnt:
+                                       lanfnt[nlanfnt] = fnt[i];
+                                       nlanfnt++;
+                                       fnt[i] = NULL;
+                                       fntleft--;
+                               }
+                               else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
+                                       goto addlanfnt;
+                       }
+               }
+               /* and build a fontdir */
+               rsc = build_fontdir(lanfnt, nlanfnt);
+               if(rsc)
+               {
+                       if(lst)
+                       {
+                               lst->next = rsc;
+                               rsc->prev = lst;
+                       }
+                       lst = rsc;
+               }
+       }
+       free(lanfnt);
+ clean:
+       if(fnt)
+               free(fnt);
+       if(fnd)
+               free(fnd);
+       free(str.str.cstr);
+       return lst;
+ }
+ /*
+  * This gets invoked to determine whether the next resource
+  * is to be of a standard-type (e.g. bitmaps etc.), or should
+  * be a user-type resource. This function is required because
+  * there is the _possibility_ of a lookahead token in the
+  * parser, which is generated from the "expr" state in the
+  * "nameid" parsing.
+  *
+  * The general resource format is:
+  * <identifier> <type> <flags> <resourcebody>
+  *
+  * The <identifier> can either be tIDENT or "expr". The latter
+  * will always generate a lookahead, which is the <type> of the
+  * resource to parse. Otherwise, we need to get a new token from
+  * the scanner to determine the next step.
+  *
+  * The problem arrises when <type> is numerical. This case should
+  * map onto default resource-types and be parsed as such instead
+  * of being mapped onto user-type resources.
+  *
+  * The trick lies in the fact that yacc (bison) doesn't care about
+  * intermediate changes of the lookahead while reducing a rule. We
+  * simply replace the lookahead with a token that will result in
+  * a shift to the appropriate rule for the specific resource-type.
+  */
+ static int rsrcid_to_token(int lookahead)
+ {
+       int token;
+       const char *type = "?";
+       /* Get a token if we don't have one yet */
+       if(lookahead == YYEMPTY)
+               lookahead = YYLEX;
+       /* Only numbers are possibly interesting */
+       switch(lookahead)
+       {
+       case tNUMBER:
+       case tLNUMBER:
+               break;
+       default:
+               return lookahead;
+       }
+       token = lookahead;
+       switch(yylval.num)
+       {
+       case WRC_RT_CURSOR:
+               type = "CURSOR";
+               token = tCURSOR;
+               break;
+       case WRC_RT_ICON:
+               type = "ICON";
+               token = tICON;
+               break;
+       case WRC_RT_BITMAP:
+               type = "BITMAP";
+               token = tBITMAP;
+               break;
+       case WRC_RT_FONT:
+               type = "FONT";
+               token = tFONT;
+               break;
+       case WRC_RT_FONTDIR:
+               type = "FONTDIR";
+               token = tFONTDIR;
+               break;
+       case WRC_RT_RCDATA:
+               type = "RCDATA";
+               token = tRCDATA;
+               break;
+       case WRC_RT_MESSAGETABLE:
+               type = "MESSAGETABLE";
+               token = tMESSAGETABLE;
+               break;
+       case WRC_RT_DLGINIT:
+               type = "DLGINIT";
+               token = tDLGINIT;
+               break;
+       case WRC_RT_ACCELERATOR:
+               type = "ACCELERATOR";
+               token = tACCELERATORS;
+               break;
+       case WRC_RT_MENU:
+               type = "MENU";
+               token = tMENU;
+               break;
+       case WRC_RT_DIALOG:
+               type = "DIALOG";
+               token = tDIALOG;
+               break;
+       case WRC_RT_VERSION:
+               type = "VERSION";
+               token = tVERSIONINFO;
+               break;
+       case WRC_RT_TOOLBAR:
+               type = "TOOLBAR";
+               token = tTOOLBAR;
+               break;
+       case WRC_RT_STRING:
+               type = "STRINGTABLE";
+               break;
+       case WRC_RT_ANICURSOR:
+       case WRC_RT_ANIICON:
+       case WRC_RT_GROUP_CURSOR:
+       case WRC_RT_GROUP_ICON:
+               yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
+               return lookahead;
+       case WRC_RT_DLGINCLUDE:
+       case WRC_RT_PLUGPLAY:
+       case WRC_RT_VXD:
+       case WRC_RT_HTML:
+               yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);
+       default:
+               return lookahead;
+       }
+       return token;
+ }
index 0000000,0d3a230..3246401
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,5524 +1,5536 @@@
 -#define YYLAST   674
+ /* A Bison parser, made by GNU Bison 1.875b.  */
+ /* Skeleton parser for Yacc-like parsing with Bison,
+    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2, or (at your option)
+    any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.  */
+ /* As a special exception, when this file is copied by Bison into a
+    Bison output file, you may use that output file without restriction.
+    This special exception was added by the Free Software Foundation
+    in version 1.24 of Bison.  */
+ /* Written by Richard Stallman by simplifying the original so called
+    ``semantic'' parser.  */
+ /* All symbols defined below should begin with yy or YY, to avoid
+    infringing on user name space.  This should be done even for local
+    variables, as they might otherwise be expanded by user macros.
+    There are some unavoidable exceptions within include files to
+    define necessary library symbols; they are noted "INFRINGES ON
+    USER NAME SPACE" below.  */
+ /* Identify Bison output.  */
+ #define YYBISON 1
+ /* Skeleton name.  */
+ #define YYSKELETON_NAME "yacc.c"
+ /* Pure parsers.  */
+ #define YYPURE 0
+ /* Using locations.  */
+ #define YYLSP_NEEDED 0
+ /* Tokens.  */
+ #ifndef YYTOKENTYPE
+ # define YYTOKENTYPE
+    /* Put the tokens into the symbol table, so that GDB and other debuggers
+       know about them.  */
+    enum yytokentype {
+      tNL = 258,
+      tNUMBER = 259,
+      tLNUMBER = 260,
+      tSTRING = 261,
+      tIDENT = 262,
+      tFILENAME = 263,
+      tRAWDATA = 264,
+      tACCELERATORS = 265,
+      tBITMAP = 266,
+      tCURSOR = 267,
+      tDIALOG = 268,
+      tDIALOGEX = 269,
+      tMENU = 270,
+      tMENUEX = 271,
+      tMESSAGETABLE = 272,
+      tRCDATA = 273,
+      tVERSIONINFO = 274,
+      tSTRINGTABLE = 275,
+      tFONT = 276,
+      tFONTDIR = 277,
+      tICON = 278,
+      tAUTO3STATE = 279,
+      tAUTOCHECKBOX = 280,
+      tAUTORADIOBUTTON = 281,
+      tCHECKBOX = 282,
+      tDEFPUSHBUTTON = 283,
+      tPUSHBUTTON = 284,
+      tRADIOBUTTON = 285,
+      tSTATE3 = 286,
+      tGROUPBOX = 287,
+      tCOMBOBOX = 288,
+      tLISTBOX = 289,
+      tSCROLLBAR = 290,
+      tCONTROL = 291,
+      tEDITTEXT = 292,
+      tRTEXT = 293,
+      tCTEXT = 294,
+      tLTEXT = 295,
+      tBLOCK = 296,
+      tVALUE = 297,
+      tSHIFT = 298,
+      tALT = 299,
+      tASCII = 300,
+      tVIRTKEY = 301,
+      tGRAYED = 302,
+      tCHECKED = 303,
+      tINACTIVE = 304,
+      tNOINVERT = 305,
+      tPURE = 306,
+      tIMPURE = 307,
+      tDISCARDABLE = 308,
+      tLOADONCALL = 309,
+      tPRELOAD = 310,
+      tFIXED = 311,
+      tMOVEABLE = 312,
+      tCLASS = 313,
+      tCAPTION = 314,
+      tCHARACTERISTICS = 315,
+      tEXSTYLE = 316,
+      tSTYLE = 317,
+      tVERSION = 318,
+      tLANGUAGE = 319,
+      tFILEVERSION = 320,
+      tPRODUCTVERSION = 321,
+      tFILEFLAGSMASK = 322,
+      tFILEOS = 323,
+      tFILETYPE = 324,
+      tFILEFLAGS = 325,
+      tFILESUBTYPE = 326,
+      tMENUBARBREAK = 327,
+      tMENUBREAK = 328,
+      tMENUITEM = 329,
+      tPOPUP = 330,
+      tSEPARATOR = 331,
+      tHELP = 332,
+      tTOOLBAR = 333,
+      tBUTTON = 334,
+      tBEGIN = 335,
+      tEND = 336,
+      tDLGINIT = 337,
+      tNOT = 338,
+      pUPM = 339
+    };
+ #endif
+ #define tNL 258
+ #define tNUMBER 259
+ #define tLNUMBER 260
+ #define tSTRING 261
+ #define tIDENT 262
+ #define tFILENAME 263
+ #define tRAWDATA 264
+ #define tACCELERATORS 265
+ #define tBITMAP 266
+ #define tCURSOR 267
+ #define tDIALOG 268
+ #define tDIALOGEX 269
+ #define tMENU 270
+ #define tMENUEX 271
+ #define tMESSAGETABLE 272
+ #define tRCDATA 273
+ #define tVERSIONINFO 274
+ #define tSTRINGTABLE 275
+ #define tFONT 276
+ #define tFONTDIR 277
+ #define tICON 278
+ #define tAUTO3STATE 279
+ #define tAUTOCHECKBOX 280
+ #define tAUTORADIOBUTTON 281
+ #define tCHECKBOX 282
+ #define tDEFPUSHBUTTON 283
+ #define tPUSHBUTTON 284
+ #define tRADIOBUTTON 285
+ #define tSTATE3 286
+ #define tGROUPBOX 287
+ #define tCOMBOBOX 288
+ #define tLISTBOX 289
+ #define tSCROLLBAR 290
+ #define tCONTROL 291
+ #define tEDITTEXT 292
+ #define tRTEXT 293
+ #define tCTEXT 294
+ #define tLTEXT 295
+ #define tBLOCK 296
+ #define tVALUE 297
+ #define tSHIFT 298
+ #define tALT 299
+ #define tASCII 300
+ #define tVIRTKEY 301
+ #define tGRAYED 302
+ #define tCHECKED 303
+ #define tINACTIVE 304
+ #define tNOINVERT 305
+ #define tPURE 306
+ #define tIMPURE 307
+ #define tDISCARDABLE 308
+ #define tLOADONCALL 309
+ #define tPRELOAD 310
+ #define tFIXED 311
+ #define tMOVEABLE 312
+ #define tCLASS 313
+ #define tCAPTION 314
+ #define tCHARACTERISTICS 315
+ #define tEXSTYLE 316
+ #define tSTYLE 317
+ #define tVERSION 318
+ #define tLANGUAGE 319
+ #define tFILEVERSION 320
+ #define tPRODUCTVERSION 321
+ #define tFILEFLAGSMASK 322
+ #define tFILEOS 323
+ #define tFILETYPE 324
+ #define tFILEFLAGS 325
+ #define tFILESUBTYPE 326
+ #define tMENUBARBREAK 327
+ #define tMENUBREAK 328
+ #define tMENUITEM 329
+ #define tPOPUP 330
+ #define tSEPARATOR 331
+ #define tHELP 332
+ #define tTOOLBAR 333
+ #define tBUTTON 334
+ #define tBEGIN 335
+ #define tEND 336
+ #define tDLGINIT 337
+ #define tNOT 338
+ #define pUPM 339
+ /* Copy the first part of user declarations.  */
+ #line 1 "parser.y"
+ /*
+  * Copyright 1994     Martin von Loewis
+  * Copyright 1998-2000        Bertho A. Stultiens (BS)
+  *           1999     Juergen Schmied (JS)
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
+  * This library is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this library; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  *
+  * History:
+  * 24-Jul-2000 BS     - Made a fix for broken Berkeley yacc on
+  *                      non-terminals (see cjunk rule).
+  * 21-May-2000 BS     - Partial implementation of font resources.
+  *                    - Corrected language propagation for binary
+  *                      resources such as bitmaps, icons, cursors,
+  *                      userres and rcdata. The language is now
+  *                      correct in .res files.
+  *                    - Fixed reading the resource name as ident,
+  *                      so that it may overlap keywords.
+  * 20-May-2000 BS     - Implemented animated cursors and icons
+  *                      resource types.
+  * 30-Apr-2000 BS     - Reintegration into the wine-tree
+  * 14-Jan-2000 BS     - Redid the usertype resources so that they
+  *                      are compatible.
+  * 02-Jan-2000 BS     - Removed the preprocessor from the grammar
+  *                      except for the # command (line numbers).
+  *
+  * 06-Nov-1999 JS     - see CHANGES
+  *
+  * 29-Dec-1998 AdH    - Grammar and function extensions.
+  *                         grammar: TOOLBAR resources, Named ICONs in
+  *                            DIALOGS
+  *                         functions: semantic actions for the grammar
+  *                            changes, resource files can now be anywhere
+  *                            on the include path instead of just in the
+  *                            current directory
+  *
+  * 20-Jun-1998 BS     - Fixed a bug in load_file() where the name was not
+  *                      printed out correctly.
+  *
+  * 17-Jun-1998 BS     - Fixed a bug in CLASS statement parsing which should
+  *                      also accept a tSTRING as argument.
+  *
+  * 25-May-1998 BS     - Found out that I need to support language, version
+  *                      and characteristics in inline resources (bitmap,
+  *                      cursor, etc) but they can also be specified with
+  *                      a filename. This renders my filename-scanning scheme
+  *                      worthless. Need to build newline parsing to solve
+  *                      this one.
+  *                      It will come with version 1.1.0 (sigh).
+  *
+  * 19-May-1998 BS     - Started to build a builtin preprocessor
+  *
+  * 30-Apr-1998 BS     - Redid the stringtable parsing/handling. My previous
+  *                      ideas had some serious flaws.
+  *
+  * 27-Apr-1998 BS     - Removed a lot of dead comments and put it in a doc
+  *                      file.
+  *
+  * 21-Apr-1998 BS     - Added correct behavior for cursors and icons.
+  *                    - This file is growing too big. It is time to strip
+  *                      things and put it in a support file.
+  *
+  * 19-Apr-1998 BS     - Tagged the stringtable resource so that only one
+  *                      resource will be created. This because the table
+  *                      has a different layout than other resources. The
+  *                      table has to be sorted, and divided into smaller
+  *                      resource entries (see comment in source).
+  *
+  * 17-Apr-1998 BS     - Almost all strings, including identifiers, are parsed
+  *                      as string_t which include unicode strings upon
+  *                      input.
+  *                    - Parser now emits a warning when compiling win32
+  *                      extensions in win16 mode.
+  *
+  * 16-Apr-1998 BS     - Raw data elements are now *optionally* separated
+  *                      by commas. Read the comments in file sq2dq.l.
+  *                    - FIXME: there are instances in the source that rely
+  *                      on the fact that int==32bit and pointers are int size.
+  *                    - Fixed the conflict in menuex by changing a rule
+  *                      back into right recursion. See note in source.
+  *                    - UserType resources cannot have an expression as its
+  *                      typeclass. See note in source.
+  *
+  * 15-Apr-1998 BS     - Changed all right recursion into left recursion to
+  *                      get reduction of the parsestack.
+  *                      This also helps communication between bison and flex.
+  *                      Main advantage is that the Empty rule gets reduced
+  *                      first, which is used to allocate/link things.
+  *                      It also added a shift/reduce conflict in the menuex
+  *                      handling, due to expression/option possibility,
+  *                      although not serious.
+  *
+  * 14-Apr-1998 BS     - Redone almost the entire parser. We're not talking
+  *                      about making it more efficient, but readable (for me)
+  *                      and slightly easier to expand/change.
+  *                      This is done primarily by using more reduce states
+  *                      with many (intuitive) types for the various resource
+  *                      statements.
+  *                    - Added expression handling for all resources where a
+  *                      number is accepted (not only for win32). Also added
+  *                      multiply and division (not MS compatible, but handy).
+  *                      Unary minus introduced a shift/reduce conflict, but
+  *                      it is not serious.
+  *
+  * 13-Apr-1998 BS     - Reordered a lot of things
+  *                    - Made the source more readable
+  *                    - Added Win32 resource definitions
+  *                    - Corrected syntax problems with an old yacc (;)
+  *                    - Added extra comment about grammar
+  */
+ #include "config.h"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <assert.h>
+ #include <ctype.h>
+ #include <string.h>
+ #ifdef HAVE_ALLOCA_H
+ #include <alloca.h>
+ #endif
+ #include "wrc.h"
+ #include "utils.h"
+ #include "newstruc.h"
+ #include "dumpres.h"
+ #include "wine/wpp.h"
+ #include "wine/unicode.h"
+ #include "parser.h"
+ #include "windef.h"
+ #include "winbase.h"
+ #include "wingdi.h"
+ #include "winuser.h"
+ #if defined(YYBYACC)
+       /* Berkeley yacc (byacc) doesn't seem to know about these */
+       /* Some *BSD supplied versions do define these though */
+ # ifndef YYEMPTY
+ #  define YYEMPTY     (-1)    /* Empty lookahead value of yychar */
+ # endif
+ # ifndef YYLEX
+ #  define YYLEX               yylex()
+ # endif
+ #elif defined(YYBISON)
+       /* Bison was used for original development */
+       /* #define YYEMPTY -2 */
+       /* #define YYLEX   yylex() */
+ #else
+       /* No yacc we know yet */
+ # if !defined(YYEMPTY) || !defined(YYLEX)
+ #  error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
+ # elif defined(__GNUC__)      /* gcc defines the #warning directive */
+ #  warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
+   /* #else we just take a chance that it works... */
+ # endif
+ #endif
+ int want_nl = 0;      /* Signal flex that we need the next newline */
+ int want_id = 0;      /* Signal flex that we need the next identifier */
+ stringtable_t *tagstt;        /* Stringtable tag.
+                        * It is set while parsing a stringtable to one of
+                        * the stringtables in the sttres list or a new one
+                        * if the language was not parsed before.
+                        */
+ stringtable_t *sttres;        /* Stringtable resources. This holds the list of
+                        * stringtables with different lanuages
+                        */
+ static int dont_want_id = 0;  /* See language parsing for details */
+ /* Set to the current options of the currently scanning stringtable */
+ static int *tagstt_memopt;
+ static characts_t *tagstt_characts;
+ static version_t *tagstt_version;
+ static const char riff[4] = "RIFF";   /* RIFF file magic for animated cursor/icon */
+ /* Prototypes of here defined functions */
+ static event_t *get_event_head(event_t *p);
+ static control_t *get_control_head(control_t *p);
+ static ver_value_t *get_ver_value_head(ver_value_t *p);
+ static ver_block_t *get_ver_block_head(ver_block_t *p);
+ static resource_t *get_resource_head(resource_t *p);
+ static menuex_item_t *get_itemex_head(menuex_item_t *p);
+ static menu_item_t *get_item_head(menu_item_t *p);
+ static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
+ static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
+ static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
+ static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
+ static raw_data_t *str2raw_data(string_t *str);
+ static raw_data_t *int2raw_data(int i);
+ static raw_data_t *long2raw_data(int i);
+ static raw_data_t *load_file(string_t *name, language_t *lang);
+ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
+ static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
+ static event_t *add_event(int key, int id, int flags, event_t *prev);
+ static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
+ static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
+ static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
+ static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
+ static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
+ static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
+ static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
+ static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
+ static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
+ static name_id_t *convert_ctlclass(name_id_t *cls);
+ static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
+ static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
+ static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
+ static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
+ static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
+ static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
+ static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
+ static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
+ static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
+ static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
+ static resource_t *build_stt_resources(stringtable_t *stthead);
+ static stringtable_t *find_stringtable(lvc_t *lvc);
+ static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
+ static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
+ static string_t *make_filename(string_t *s);
+ static resource_t *build_fontdirs(resource_t *tail);
+ static resource_t *build_fontdir(resource_t **fnt, int nfnt);
+ static int rsrcid_to_token(int lookahead);
+ /* Enabling traces.  */
+ #ifndef YYDEBUG
+ # define YYDEBUG 1
+ #endif
+ /* Enabling verbose error messages.  */
+ #ifdef YYERROR_VERBOSE
+ # undef YYERROR_VERBOSE
+ # define YYERROR_VERBOSE 1
+ #else
+ # define YYERROR_VERBOSE 0
+ #endif
+ #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+ #line 240 "parser.y"
+ typedef union YYSTYPE {
+       string_t        *str;
+       int             num;
+       int             *iptr;
+       char            *cptr;
+       resource_t      *res;
+       accelerator_t   *acc;
+       bitmap_t        *bmp;
+       dialog_t        *dlg;
+       dialogex_t      *dlgex;
+       font_t          *fnt;
+       fontdir_t       *fnd;
+       menu_t          *men;
+       menuex_t        *menex;
+       rcdata_t        *rdt;
+       stringtable_t   *stt;
+       stt_entry_t     *stte;
+       user_t          *usr;
+       messagetable_t  *msg;
+       versioninfo_t   *veri;
+       control_t       *ctl;
+       name_id_t       *nid;
+       font_id_t       *fntid;
+       language_t      *lan;
+       version_t       *ver;
+       characts_t      *chars;
+       event_t         *event;
+       menu_item_t     *menitm;
+       menuex_item_t   *menexitm;
+       itemex_opt_t    *exopt;
+       raw_data_t      *raw;
+       lvc_t           *lvc;
+       ver_value_t     *val;
+       ver_block_t     *blk;
+       ver_words_t     *verw;
+       toolbar_t       *tlbar;
+       toolbar_item_t  *tlbarItems;
+       dlginit_t       *dginit;
+       style_pair_t    *styles;
+       style_t         *style;
+       ani_any_t       *ani;
+ } YYSTYPE;
+ /* Line 191 of yacc.c.  */
+ #line 527 "y.tab.c"
+ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
+ # define YYSTYPE_IS_DECLARED 1
+ # define YYSTYPE_IS_TRIVIAL 1
+ #endif
+ /* Copy the second part of user declarations.  */
+ /* Line 214 of yacc.c.  */
+ #line 539 "y.tab.c"
+ #if ! defined (yyoverflow) || YYERROR_VERBOSE
+ /* The parser invokes alloca or malloc; define the necessary symbols.  */
+ # if YYSTACK_USE_ALLOCA
+ #  define YYSTACK_ALLOC alloca
+ # else
+ #  ifndef YYSTACK_USE_ALLOCA
+ #   if defined (alloca) || defined (_ALLOCA_H)
+ #    define YYSTACK_ALLOC alloca
+ #   else
+ #    ifdef __GNUC__
+ #     define YYSTACK_ALLOC __builtin_alloca
+ #    endif
+ #   endif
+ #  endif
+ # endif
+ # ifdef YYSTACK_ALLOC
+    /* Pacify GCC's `empty if-body' warning. */
+ #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+ # else
+ #  if defined (__STDC__) || defined (__cplusplus)
+ #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ #   define YYSIZE_T size_t
+ #  endif
+ #  define YYSTACK_ALLOC malloc
+ #  define YYSTACK_FREE free
+ # endif
+ #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+ #if (! defined (yyoverflow) \
+      && (! defined (__cplusplus) \
+        || (YYSTYPE_IS_TRIVIAL)))
+ /* A type that is properly aligned for any stack member.  */
+ union yyalloc
+ {
+   short yyss;
+   YYSTYPE yyvs;
+   };
+ /* The size of the maximum gap between one aligned stack and the next.  */
+ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+ /* The size of an array large to enough to hold all stacks, each with
+    N elements.  */
+ # define YYSTACK_BYTES(N) \
+      ((N) * (sizeof (short) + sizeof (YYSTYPE))                               \
+       + YYSTACK_GAP_MAXIMUM)
+ /* Copy COUNT objects from FROM to TO.  The source and destination do
+    not overlap.  */
+ # ifndef YYCOPY
+ #  if 1 < __GNUC__
+ #   define YYCOPY(To, From, Count) \
+       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+ #  else
+ #   define YYCOPY(To, From, Count)            \
+       do                                      \
+       {                                       \
+         register YYSIZE_T yyi;                \
+         for (yyi = 0; yyi < (Count); yyi++)   \
+           (To)[yyi] = (From)[yyi];            \
+       }                                       \
+       while (0)
+ #  endif
+ # endif
+ /* Relocate STACK from its old location to the new one.  The
+    local variables YYSIZE and YYSTACKSIZE give the old and new number of
+    elements in the stack, and YYPTR gives the new location of the
+    stack.  Advance YYPTR to a properly aligned location for the next
+    stack.  */
+ # define YYSTACK_RELOCATE(Stack)                                      \
+     do                                                                        \
+       {                                                                       \
+       YYSIZE_T yynewbytes;                                            \
+       YYCOPY (&yyptr->Stack, Stack, yysize);                          \
+       Stack = &yyptr->Stack;                                          \
+       yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+       yyptr += yynewbytes / sizeof (*yyptr);                          \
+       }                                                                       \
+     while (0)
+ #endif
+ #if defined (__STDC__) || defined (__cplusplus)
+    typedef signed char yysigned_char;
+ #else
+    typedef short yysigned_char;
+ #endif
+ /* YYFINAL -- State number of the termination state. */
+ #define YYFINAL  3
+ /* YYLAST -- Last index in YYTABLE.  */
 -#define YYNSTATES  570
++#define YYLAST   692
+ /* YYNTOKENS -- Number of terminals. */
+ #define YYNTOKENS  96
+ /* YYNNTS -- Number of nonterminals. */
+ #define YYNNTS  83
+ /* YYNRULES -- Number of rules. */
+ #define YYNRULES  258
+ /* YYNRULES -- Number of states. */
 -      -1,   178,    -1,    91,   178,    -1,   176,    -1,     6,    -1,
++#define YYNSTATES  572
+ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
+ #define YYUNDEFTOK  2
+ #define YYMAXUTOK   339
+ #define YYTRANSLATE(YYX)                                              \
+   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+ /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+ static const unsigned char yytranslate[] =
+ {
+        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,    85,     2,
+       94,    95,    88,    86,    93,    87,     2,    89,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,    84,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,    83,     2,    90,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
+        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
+       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
+       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
+       45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
+       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
+       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
+       75,    76,    77,    78,    79,    80,    81,    82,    91,    92
+ };
+ #if YYDEBUG
+ /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+    YYRHS.  */
+ static const unsigned short yyprhs[] =
+ {
+        0,     0,     3,     5,     6,     9,    12,    16,    20,    22,
+       23,    29,    30,    32,    34,    36,    38,    40,    42,    44,
+       46,    48,    50,    52,    54,    56,    58,    60,    62,    64,
+       66,    68,    70,    72,    74,    76,    80,    84,    88,    92,
+       96,   100,   104,   108,   112,   114,   116,   123,   124,   130,
+      136,   137,   140,   142,   146,   148,   150,   152,   154,   156,
+      158,   172,   173,   177,   181,   185,   188,   192,   196,   199,
+      202,   205,   206,   210,   214,   218,   222,   226,   230,   234,
+      238,   242,   246,   250,   254,   258,   262,   266,   270,   274,
+      285,   298,   309,   310,   315,   322,   331,   349,   365,   370,
+      371,   374,   375,   378,   383,   387,   391,   393,   396,   398,
+      400,   415,   416,   420,   424,   428,   431,   434,   438,   442,
+      445,   448,   451,   452,   456,   460,   464,   468,   472,   476,
+      480,   484,   488,   492,   496,   500,   504,   508,   512,   516,
+      520,   531,   551,   568,   583,   596,   597,   599,   600,   603,
+      613,   614,   617,   622,   626,   627,   634,   638,   644,   645,
+      649,   653,   657,   661,   665,   669,   674,   678,   679,   684,
+      688,   694,   695,   698,   704,   711,   712,   715,   720,   727,
+      736,   741,   745,   746,   751,   752,   754,   761,   762,   772,
+      782,   786,   790,   794,   798,   802,   803,   806,   812,   813,
+      816,   818,   823,   828,   830,   834,   844,   845,   849,   852,
+      853,   856,   859,   861,   863,   865,   867,   869,   871,   873,
+      874,   877,   880,   883,   888,   891,   894,   899,   901,   903,
+      906,   908,   911,   913,   917,   921,   926,   930,   935,   939,
+      941,   943,   944,   946,   948,   952,   956,   960,   964,   968,
+      972,   976,   979,   982,   985,   989,   991,   994,   996
+ };
+ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
+ static const short yyrhs[] =
+ {
+       97,     0,    -1,    98,    -1,    -1,    98,    99,    -1,    98,
+        3,    -1,   176,   101,   104,    -1,     7,   101,   104,    -1,
+      152,    -1,    -1,    64,   100,   176,    93,   176,    -1,    -1,
+      176,    -1,     7,    -1,   102,    -1,     6,    -1,   116,    -1,
+      106,    -1,   107,    -1,   121,    -1,   133,    -1,   113,    -1,
+      109,    -1,   110,    -1,   108,    -1,   143,    -1,   147,    -1,
+      111,    -1,   112,    -1,   163,    -1,   114,    -1,   156,    -1,
+        8,    -1,     7,    -1,     6,    -1,    11,   165,   174,    -1,
+       12,   165,   174,    -1,    23,   165,   174,    -1,    21,   165,
+      174,    -1,    22,   165,   174,    -1,    17,   165,   174,    -1,
+       18,   165,   174,    -1,    82,   165,   174,    -1,   115,   165,
+      174,    -1,     4,    -1,     7,    -1,    10,   165,   168,    80,
+      117,    81,    -1,    -1,   117,     6,    93,   176,   118,    -1,
+      117,   176,    93,   176,   118,    -1,    -1,    93,   119,    -1,
+      120,    -1,   119,    93,   120,    -1,    50,    -1,    43,    -1,
+       36,    -1,    44,    -1,    45,    -1,    46,    -1,    13,   165,
+      176,    93,   176,    93,   176,    93,   176,   122,    80,   123,
+       81,    -1,    -1,   122,    62,   131,    -1,   122,    61,   131,
+       -1,   122,    59,     6,    -1,   122,   128,    -1,   122,    58,
+      103,    -1,   122,    15,   102,    -1,   122,   169,    -1,   122,
+      170,    -1,   122,   171,    -1,    -1,   123,    36,   127,    -1,
+      123,    37,   125,    -1,   123,    34,   125,    -1,   123,    33,
+      125,    -1,   123,    35,   125,    -1,   123,    27,   124,    -1,
+      123,    28,   124,    -1,   123,    32,   124,    -1,   123,    29,
+      124,    -1,   123,    30,   124,    -1,   123,    24,   124,    -1,
+      123,    31,   124,    -1,   123,    25,   124,    -1,   123,    26,
+      124,    -1,   123,    40,   124,    -1,   123,    39,   124,    -1,
+      123,    38,   124,    -1,   123,    23,   103,   155,   176,    93,
+      176,    93,   176,   126,    -1,     6,   155,   176,    93,   176,
+       93,   176,    93,   176,    93,   176,   129,    -1,   176,    93,
+      176,    93,   176,    93,   176,    93,   176,   129,    -1,    -1,
+       93,   176,    93,   176,    -1,    93,   176,    93,   176,    93,
+      131,    -1,    93,   176,    93,   176,    93,   131,    93,   131,
+       -1,   103,   155,   176,    93,   132,    93,   131,    93,   176,
+       93,   176,    93,   176,    93,   176,    93,   131,    -1,   103,
+      155,   176,    93,   132,    93,   131,    93,   176,    93,   176,
+       93,   176,    93,   176,    -1,    21,   176,    93,     6,    -1,
+       -1,    93,   131,    -1,    -1,    93,   131,    -1,    93,   131,
+       93,   131,    -1,   131,    83,   131,    -1,    94,   131,    95,
 -     119,   120,   121,     0,   173,   241,     0,     0,   107,     0,
++      -1,   177,    -1,    91,   177,    -1,   176,    -1,     6,    -1,
+       14,   165,   176,    93,   176,    93,   176,    93,   176,   140,
+      134,    80,   135,    81,    -1,    -1,   134,    62,   131,    -1,
+      134,    61,   131,    -1,   134,    59,     6,    -1,   134,   128,
+       -1,   134,   141,    -1,   134,    58,   103,    -1,   134,    15,
+      102,    -1,   134,   169,    -1,   134,   170,    -1,   134,   171,
+       -1,    -1,   135,    36,   136,    -1,   135,    37,   138,    -1,
+      135,    34,   138,    -1,   135,    33,   138,    -1,   135,    35,
+      138,    -1,   135,    27,   137,    -1,   135,    28,   137,    -1,
+      135,    32,   137,    -1,   135,    29,   137,    -1,   135,    30,
+      137,    -1,   135,    24,   137,    -1,   135,    31,   137,    -1,
+      135,    25,   137,    -1,   135,    26,   137,    -1,   135,    40,
+      137,    -1,   135,    39,   137,    -1,   135,    38,   137,    -1,
+      135,    23,   103,   155,   176,    93,   176,    93,   176,   126,
+       -1,   103,   155,   176,    93,   132,    93,   131,    93,   176,
+       93,   176,    93,   176,    93,   176,    93,   131,   140,   139,
+       -1,   103,   155,   176,    93,   132,    93,   131,    93,   176,
+       93,   176,    93,   176,    93,   176,   139,    -1,     6,   155,
+      176,    93,   176,    93,   176,    93,   176,    93,   176,   130,
+      140,   139,    -1,   176,    93,   176,    93,   176,    93,   176,
+       93,   176,   130,   140,   139,    -1,    -1,   172,    -1,    -1,
+       93,   176,    -1,    21,   176,    93,     6,    93,   176,    93,
+      176,   142,    -1,    -1,    93,   176,    -1,    15,   165,   168,
+      144,    -1,    80,   145,    81,    -1,    -1,   145,    74,     6,
+      155,   176,   146,    -1,   145,    74,    76,    -1,   145,    75,
+        6,   146,   144,    -1,    -1,    93,    48,   146,    -1,    93,
+       47,   146,    -1,    93,    77,   146,    -1,    93,    49,   146,
+       -1,    93,    72,   146,    -1,    93,    73,   146,    -1,    16,
+      165,   168,   148,    -1,    80,   149,    81,    -1,    -1,   149,
+       74,     6,   150,    -1,   149,    74,    76,    -1,   149,    75,
+        6,   151,   148,    -1,    -1,    93,   176,    -1,    93,   175,
+       93,   175,   146,    -1,    93,   175,    93,   175,    93,   176,
+       -1,    -1,    93,   176,    -1,    93,   175,    93,   176,    -1,
+       93,   175,    93,   175,    93,   176,    -1,    93,   175,    93,
+      175,    93,   175,    93,   176,    -1,   153,    80,   154,    81,
+       -1,    20,   165,   168,    -1,    -1,   154,   176,   155,     6,
+       -1,    -1,    93,    -1,    19,   165,   157,    80,   158,    81,
+       -1,    -1,   157,    65,   176,    93,   176,    93,   176,    93,
+      176,    -1,   157,    66,   176,    93,   176,    93,   176,    93,
+      176,    -1,   157,    70,   176,    -1,   157,    67,   176,    -1,
+      157,    68,   176,    -1,   157,    69,   176,    -1,   157,    71,
+      176,    -1,    -1,   158,   159,    -1,    41,     6,    80,   160,
+       81,    -1,    -1,   160,   161,    -1,   159,    -1,    42,     6,
+       93,     6,    -1,    42,     6,    93,   162,    -1,   176,    -1,
+      162,    93,   176,    -1,    78,   165,   176,    93,   176,   168,
+       80,   164,    81,    -1,    -1,   164,    79,   176,    -1,   164,
+       76,    -1,    -1,   165,   166,    -1,   165,   167,    -1,    55,
+       -1,    57,    -1,    53,    -1,    51,    -1,    54,    -1,    56,
+       -1,    52,    -1,    -1,   168,   169,    -1,   168,   170,    -1,
+      168,   171,    -1,    64,   176,    93,   176,    -1,    60,   176,
+       -1,    63,   176,    -1,   168,    80,   173,    81,    -1,     9,
+       -1,     4,    -1,    87,     4,    -1,     5,    -1,    87,     5,
+       -1,     6,    -1,   173,   155,     9,    -1,   173,   155,     4,
+       -1,   173,   155,    87,     4,    -1,   173,   155,     5,    -1,
+      173,   155,    87,     5,    -1,   173,   155,     6,    -1,   105,
+       -1,   172,    -1,    -1,   176,    -1,   177,    -1,   177,    86,
+      177,    -1,   177,    87,   177,    -1,   177,    83,   177,    -1,
+      177,    85,   177,    -1,   177,    88,   177,    -1,   177,    89,
+      177,    -1,   177,    84,   177,    -1,    90,   177,    -1,    87,
+      177,    -1,    86,   177,    -1,    94,   177,    95,    -1,   178,
+       -1,    91,   178,    -1,     4,    -1,     5,    -1
+ };
+ /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+ static const unsigned short yyrline[] =
+ {
+        0,   362,   362,   396,   397,   467,   473,   485,   495,   503,
+      503,   547,   553,   560,   570,   571,   580,   581,   582,   606,
+      607,   613,   614,   615,   616,   640,   641,   647,   648,   649,
+      650,   651,   655,   656,   657,   661,   665,   681,   703,   713,
+      721,   729,   733,   737,   748,   753,   762,   786,   787,   788,
+      797,   798,   801,   802,   805,   806,   807,   808,   809,   810,
+      815,   850,   851,   852,   853,   854,   855,   856,   857,   858,
+      859,   862,   863,   864,   865,   866,   867,   868,   869,   870,
+      871,   873,   874,   875,   876,   877,   878,   879,   880,   882,
+      892,   911,   927,   929,   934,   941,   952,   966,   981,   986,
+      987,   991,   992,   993,   997,   998,   999,  1000,  1004,  1009,
+     1017,  1061,  1062,  1063,  1064,  1065,  1066,  1067,  1068,  1069,
+     1070,  1071,  1074,  1075,  1076,  1077,  1078,  1079,  1080,  1081,
+     1082,  1083,  1085,  1086,  1087,  1088,  1089,  1090,  1091,  1092,
+     1094,  1104,  1129,  1145,  1173,  1196,  1197,  1200,  1201,  1205,
+     1212,  1213,  1217,  1240,  1244,  1245,  1254,  1260,  1279,  1280,
+     1281,  1282,  1283,  1284,  1285,  1289,  1314,  1318,  1319,  1335,
+     1341,  1361,  1362,  1366,  1374,  1385,  1386,  1390,  1396,  1404,
+     1424,  1465,  1476,  1477,  1510,  1512,  1517,  1533,  1534,  1544,
+     1554,  1561,  1568,  1575,  1582,  1592,  1593,  1602,  1610,  1611,
+     1620,  1625,  1631,  1640,  1641,  1645,  1671,  1672,  1677,  1686,
+     1687,  1697,  1712,  1713,  1714,  1715,  1718,  1719,  1720,  1724,
+     1725,  1733,  1741,  1759,  1766,  1770,  1774,  1789,  1790,  1791,
+     1792,  1793,  1794,  1795,  1796,  1797,  1798,  1799,  1800,  1804,
+     1805,  1812,  1813,  1817,  1820,  1821,  1822,  1823,  1824,  1825,
+     1826,  1827,  1828,  1829,  1830,  1831,  1832,  1835,  1836
+ };
+ #endif
+ #if YYDEBUG || YYERROR_VERBOSE
+ /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+    First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+ static const char *const yytname[] =
+ {
+   "$end", "error", "$undefined", "tNL", "tNUMBER", "tLNUMBER", "tSTRING", 
+   "tIDENT", "tFILENAME", "tRAWDATA", "tACCELERATORS", "tBITMAP", 
+   "tCURSOR", "tDIALOG", "tDIALOGEX", "tMENU", "tMENUEX", "tMESSAGETABLE", 
+   "tRCDATA", "tVERSIONINFO", "tSTRINGTABLE", "tFONT", "tFONTDIR", "tICON", 
+   "tAUTO3STATE", "tAUTOCHECKBOX", "tAUTORADIOBUTTON", "tCHECKBOX", 
+   "tDEFPUSHBUTTON", "tPUSHBUTTON", "tRADIOBUTTON", "tSTATE3", "tGROUPBOX", 
+   "tCOMBOBOX", "tLISTBOX", "tSCROLLBAR", "tCONTROL", "tEDITTEXT", 
+   "tRTEXT", "tCTEXT", "tLTEXT", "tBLOCK", "tVALUE", "tSHIFT", "tALT", 
+   "tASCII", "tVIRTKEY", "tGRAYED", "tCHECKED", "tINACTIVE", "tNOINVERT", 
+   "tPURE", "tIMPURE", "tDISCARDABLE", "tLOADONCALL", "tPRELOAD", "tFIXED", 
+   "tMOVEABLE", "tCLASS", "tCAPTION", "tCHARACTERISTICS", "tEXSTYLE", 
+   "tSTYLE", "tVERSION", "tLANGUAGE", "tFILEVERSION", "tPRODUCTVERSION", 
+   "tFILEFLAGSMASK", "tFILEOS", "tFILETYPE", "tFILEFLAGS", "tFILESUBTYPE", 
+   "tMENUBARBREAK", "tMENUBREAK", "tMENUITEM", "tPOPUP", "tSEPARATOR", 
+   "tHELP", "tTOOLBAR", "tBUTTON", "tBEGIN", "tEND", "tDLGINIT", "'|'", 
+   "'^'", "'&'", "'+'", "'-'", "'*'", "'/'", "'~'", "tNOT", "pUPM", "','", 
+   "'('", "')'", "$accept", "resource_file", "resources", "resource", "@1", 
+   "usrcvt", "nameid", "nameid_s", "resource_definition", "filename", 
+   "bitmap", "cursor", "icon", "font", "fontdir", "messagetable", "rcdata", 
+   "dlginit", "userres", "usertype", "accelerators", "events", "acc_opt", 
+   "accs", "acc", "dialog", "dlg_attributes", "ctrls", "lab_ctrl", 
+   "ctrl_desc", "iconinfo", "gen_ctrl", "opt_font", "optional_style", 
+   "optional_style_pair", "style", "ctlclass", "dialogex", "dlgex_attribs", 
+   "exctrls", "gen_exctrl", "lab_exctrl", "exctrl_desc", "opt_data", 
+   "helpid", "opt_exfont", "opt_expr", "menu", "menu_body", 
+   "item_definitions", "item_options", "menuex", "menuex_body", 
+   "itemex_definitions", "itemex_options", "itemex_p_options", 
+   "stringtable", "stt_head", "strings", "opt_comma", "versioninfo", 
+   "fix_version", "ver_blocks", "ver_block", "ver_values", "ver_value", 
+   "ver_words", "toolbar", "toolbar_items", "loadmemopts", "lamo", "lama", 
+   "opt_lvc", "opt_language", "opt_characts", "opt_version", "raw_data", 
+   "raw_elements", "file_raw", "e_expr", "expr", "xpr", "any_num", 0
+ };
+ #endif
+ # ifdef YYPRINT
+ /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+    token YYLEX-NUM.  */
+ static const unsigned short yytoknum[] =
+ {
+        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
+      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
+      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
+      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
+      295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
+      305,   306,   307,   308,   309,   310,   311,   312,   313,   314,
+      315,   316,   317,   318,   319,   320,   321,   322,   323,   324,
+      325,   326,   327,   328,   329,   330,   331,   332,   333,   334,
+      335,   336,   337,   124,    94,    38,    43,    45,    42,    47,
+      126,   338,   339,    44,    40,    41
+ };
+ # endif
+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
+ static const unsigned char yyr1[] =
+ {
+        0,    96,    97,    98,    98,    98,    99,    99,    99,   100,
+       99,   101,   102,   102,   103,   103,   104,   104,   104,   104,
+      104,   104,   104,   104,   104,   104,   104,   104,   104,   104,
+      104,   104,   105,   105,   105,   106,   107,   108,   109,   110,
+      111,   112,   113,   114,   115,   115,   116,   117,   117,   117,
+      118,   118,   119,   119,   120,   120,   120,   120,   120,   120,
+      121,   122,   122,   122,   122,   122,   122,   122,   122,   122,
+      122,   123,   123,   123,   123,   123,   123,   123,   123,   123,
+      123,   123,   123,   123,   123,   123,   123,   123,   123,   123,
+      124,   125,   126,   126,   126,   126,   127,   127,   128,   129,
+      129,   130,   130,   130,   131,   131,   131,   131,   132,   132,
+      133,   134,   134,   134,   134,   134,   134,   134,   134,   134,
+      134,   134,   135,   135,   135,   135,   135,   135,   135,   135,
+      135,   135,   135,   135,   135,   135,   135,   135,   135,   135,
+      135,   136,   136,   137,   138,   139,   139,   140,   140,   141,
+      142,   142,   143,   144,   145,   145,   145,   145,   146,   146,
+      146,   146,   146,   146,   146,   147,   148,   149,   149,   149,
+      149,   150,   150,   150,   150,   151,   151,   151,   151,   151,
+      152,   153,   154,   154,   155,   155,   156,   157,   157,   157,
+      157,   157,   157,   157,   157,   158,   158,   159,   160,   160,
+      161,   161,   161,   162,   162,   163,   164,   164,   164,   165,
+      165,   165,   166,   166,   166,   166,   167,   167,   167,   168,
+      168,   168,   168,   169,   170,   171,   172,   173,   173,   173,
+      173,   173,   173,   173,   173,   173,   173,   173,   173,   174,
+      174,   175,   175,   176,   177,   177,   177,   177,   177,   177,
+      177,   177,   177,   177,   177,   177,   177,   178,   178
+ };
+ /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
+ static const unsigned char yyr2[] =
+ {
+        0,     2,     1,     0,     2,     2,     3,     3,     1,     0,
+        5,     0,     1,     1,     1,     1,     1,     1,     1,     1,
+        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
+        1,     1,     1,     1,     1,     3,     3,     3,     3,     3,
+        3,     3,     3,     3,     1,     1,     6,     0,     5,     5,
+        0,     2,     1,     3,     1,     1,     1,     1,     1,     1,
+       13,     0,     3,     3,     3,     2,     3,     3,     2,     2,
+        2,     0,     3,     3,     3,     3,     3,     3,     3,     3,
+        3,     3,     3,     3,     3,     3,     3,     3,     3,    10,
+       12,    10,     0,     4,     6,     8,    17,    15,     4,     0,
+        2,     0,     2,     4,     3,     3,     1,     2,     1,     1,
+       14,     0,     3,     3,     3,     2,     2,     3,     3,     2,
+        2,     2,     0,     3,     3,     3,     3,     3,     3,     3,
+        3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
+       10,    19,    16,    14,    12,     0,     1,     0,     2,     9,
+        0,     2,     4,     3,     0,     6,     3,     5,     0,     3,
+        3,     3,     3,     3,     3,     4,     3,     0,     4,     3,
+        5,     0,     2,     5,     6,     0,     2,     4,     6,     8,
+        4,     3,     0,     4,     0,     1,     6,     0,     9,     9,
+        3,     3,     3,     3,     3,     0,     2,     5,     0,     2,
+        1,     4,     4,     1,     3,     9,     0,     3,     2,     0,
+        2,     2,     1,     1,     1,     1,     1,     1,     1,     0,
+        2,     2,     2,     4,     2,     2,     4,     1,     1,     2,
+        1,     2,     1,     3,     3,     4,     3,     4,     3,     1,
+        1,     0,     1,     1,     3,     3,     3,     3,     3,     3,
+        3,     2,     2,     2,     3,     1,     2,     1,     1
+ };
+ /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+    means the default is an error.  */
+ static const unsigned short yydefact[] =
+ {
+        3,     0,     2,     1,     5,   257,   258,    11,   209,     9,
+        0,     0,     0,     0,     0,     4,     8,     0,    11,   243,
+      255,     0,   219,     0,   253,   252,   251,   256,     0,   182,
+        0,     0,     0,     0,     0,     0,     0,     0,    44,    45,
+      209,   209,   209,   209,   209,   209,   209,   209,   209,   209,
+      209,   209,   209,   209,   209,     7,    17,    18,    24,    22,
+       23,    27,    28,    21,    30,   209,    16,    19,    20,    25,
+       26,    31,    29,   215,   218,   214,   216,   212,   217,   213,
+      210,   211,   181,     0,   254,     0,     6,   246,   250,   247,
+      244,   245,   248,   249,   219,   219,   219,     0,     0,   219,
+      219,   219,   219,   187,   219,   219,   219,     0,   219,   219,
+        0,     0,     0,   220,   221,   222,     0,   180,   184,     0,
+       34,    33,    32,   239,     0,   240,    35,    36,     0,     0,
+        0,     0,    40,    41,     0,    38,    39,    37,     0,    42,
+       43,   224,   225,     0,    10,   185,     0,    47,     0,     0,
+        0,   154,   152,   167,   165,     0,     0,     0,     0,     0,
+        0,     0,   195,     0,     0,   183,     0,   228,   230,   232,
+      227,     0,   184,     0,     0,     0,     0,     0,     0,   191,
+      192,   193,   190,   194,     0,   219,   223,     0,    46,     0,
+      229,   231,   226,     0,     0,     0,     0,     0,   153,     0,
+        0,   166,     0,     0,     0,   186,   196,     0,     0,     0,
+      234,   236,   238,   233,     0,     0,     0,   184,   156,   158,
+      171,   169,   175,     0,     0,     0,   206,    50,    50,   235,
+      237,     0,     0,     0,     0,     0,   241,   168,   241,     0,
+        0,     0,   198,     0,     0,    48,    49,    61,   147,   158,
+      158,   158,   158,   158,   158,   158,   157,     0,   172,     0,
+      176,   170,     0,     0,     0,   208,     0,   205,    56,    55,
+       57,    58,    59,    54,    51,    52,     0,     0,   111,   155,
+      160,   159,   162,   163,   164,   161,   241,   241,     0,     0,
+        0,   197,   200,   199,   207,     0,     0,     0,     0,     0,
+        0,     0,    71,    65,    68,    69,    70,   148,     0,   158,
+      242,     0,   177,   188,   189,     0,    53,    13,    67,    12,
+        0,    15,    14,    66,    64,     0,     0,    63,   106,    62,
+        0,     0,     0,     0,     0,     0,     0,   122,   115,   116,
 -       0,     0,     0,     0,     0,     0,     0,     0,     0,    60,
 -     118,     0,   117,   114,   113,   112,     0,   174,     0,   178,
 -     201,   202,   203,    98,   105,   104,   184,   184,    82,    84,
 -      85,    77,    78,    80,    81,    83,    79,    75,     0,    74,
 -      76,   184,    72,    73,    88,    87,    86,     0,     0,     0,
++     119,   120,   121,     0,   173,   241,     0,     0,   107,   255,
+        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
 -       0,     0,     0,     0,     0,     0,   110,     0,     0,     0,
 -       0,     0,     0,    98,   184,   184,   133,   135,   136,   128,
 -     129,   131,   132,   134,   130,   126,     0,   125,   127,   184,
 -     123,   124,   139,   138,   137,   179,   204,     0,     0,     0,
+        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
 -       0,     0,     0,     0,     0,     0,     0,     0,   109,     0,
 -     108,     0,     0,     0,     0,     0,     0,     0,     0,     0,
 -     150,     0,     0,     0,     0,    92,     0,     0,     0,     0,
 -     149,     0,     0,     0,     0,     0,    89,     0,     0,     0,
 -     151,    92,     0,     0,     0,     0,     0,    99,     0,   140,
 -       0,     0,     0,     0,     0,     0,    91,     0,     0,   101,
 -       0,    93,    99,   100,     0,     0,     0,   147,     0,     0,
 -      90,     0,   101,   102,   145,     0,    94,     0,   147,     0,
 -     144,   146,     0,     0,     0,   145,   103,     0,    95,    97,
 -     143,     0,     0,   145,    96,     0,   142,   147,   145,   141
++       0,    60,   118,     0,   117,   114,   113,   112,     0,   174,
++       0,   178,   201,   202,   203,    98,   105,   104,   184,   184,
++      82,    84,    85,    77,    78,    80,    81,    83,    79,    75,
++       0,    74,    76,   184,    72,    73,    88,    87,    86,     0,
+        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
 -      66,   166,   245,   274,   275,    67,   276,   330,   388,   397,
 -     506,   402,   303,   526,   537,   327,   479,    68,   308,   376,
 -     450,   436,   445,   550,   278,   339,   500,    69,   152,   175,
++       0,     0,     0,     0,     0,     0,     0,     0,   110,     0,
++       0,     0,     0,     0,     0,    98,   184,   184,   133,   135,
++     136,   128,   129,   131,   132,   134,   130,   126,     0,   125,
++     127,   184,   123,   124,   139,   138,   137,   179,   204,     0,
++       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
++       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
++     109,     0,   108,     0,     0,     0,     0,     0,     0,     0,
++       0,     0,   150,     0,     0,     0,     0,    92,     0,     0,
++       0,     0,   149,     0,     0,     0,     0,     0,    89,     0,
++       0,     0,   151,    92,     0,     0,     0,     0,     0,    99,
++       0,   140,     0,     0,     0,     0,     0,     0,    91,     0,
++       0,   101,     0,    93,    99,   100,     0,     0,     0,   147,
++       0,     0,    90,     0,   101,   102,   145,     0,    94,     0,
++     147,     0,   144,   146,     0,     0,     0,   145,   103,     0,
++      95,    97,   143,     0,     0,   145,    96,     0,   142,   147,
++     145,   141
+ };
+ /* YYDEFGOTO[NTERM-NUM]. */
+ static const short yydefgoto[] =
+ {
+       -1,     1,     2,    15,    23,    21,   322,   323,    55,   123,
+       56,    57,    58,    59,    60,    61,    62,    63,    64,    65,
 -      71,   134,   184,   206,   264,   293,   381,    72,   243,    22,
++      66,   166,   245,   274,   275,    67,   276,   330,   390,   399,
++     508,   404,   303,   528,   539,   327,   481,    68,   308,   378,
++     452,   438,   447,   552,   278,   339,   502,    69,   152,   175,
+      235,    70,   154,   176,   237,   239,    16,    17,    85,   146,
 -#define YYPACT_NINF -492
++      71,   134,   184,   206,   264,   293,   383,    72,   243,    22,
+       80,    81,   124,   113,   114,   115,   125,   172,   126,   257,
+      319,    19,    20
+ };
+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+    STATE-NUM.  */
 -    -492,    13,     3,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -     238,   238,   238,    64,   238,  -492,  -492,   -56,  -492,   405,
 -    -492,   363,   617,   238,  -492,  -492,  -492,  -492,   556,  -492,
 -     363,   238,   238,   238,   238,   238,   238,   238,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -    -492,  -492,   -45,   -53,  -492,    82,  -492,   232,   368,   309,
 -     134,   134,  -492,  -492,   617,   282,   282,    80,    80,   617,
 -     617,   282,   282,   617,   282,   282,   282,    80,   282,   282,
 -     238,   238,   238,  -492,  -492,  -492,   238,  -492,   -44,   -38,
 -    -492,  -492,  -492,  -492,    18,  -492,  -492,  -492,   -23,    11,
 -     199,   289,  -492,  -492,   407,  -492,  -492,  -492,    34,  -492,
 -    -492,  -492,  -492,    95,  -492,  -492,    67,  -492,    41,   238,
 -     238,  -492,  -492,  -492,  -492,   238,   238,   238,   238,   238,
 -     238,   238,  -492,   238,   238,  -492,    26,  -492,  -492,  -492,
 -    -492,   241,   -52,    97,   103,   128,   175,   112,   115,  -492,
 -    -492,  -492,  -492,  -492,   -27,  -492,  -492,   121,  -492,   123,
 -    -492,  -492,  -492,    57,   238,   238,    -5,    86,  -492,    -1,
 -     109,  -492,   238,   238,   139,  -492,  -492,   359,   238,   238,
 -    -492,  -492,  -492,  -492,   278,   131,   144,   -44,  -492,   148,
 -     161,  -492,   174,   181,   185,   192,  -492,   198,   198,  -492,
 -    -492,   238,   238,   238,   204,   214,   238,  -492,   238,   218,
 -     238,   238,  -492,   179,   498,  -492,  -492,  -492,   211,   148,
 -     148,   148,   148,   148,   148,   148,  -492,   217,   220,   233,
 -     220,  -492,   234,   247,   -30,  -492,   238,  -492,  -492,  -492,
 -    -492,  -492,  -492,  -492,   253,  -492,   330,   238,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,   238,   238,   238,   238,
 -     169,  -492,  -492,  -492,  -492,   498,   206,   238,    32,   293,
 -      12,    12,  -492,  -492,  -492,  -492,  -492,  -492,   341,   261,
 -    -492,   271,   220,  -492,  -492,   272,  -492,  -492,  -492,  -492,
 -     273,  -492,  -492,  -492,  -492,    64,    12,   231,  -492,   231,
 -     565,   206,   238,    32,   297,    12,    12,  -492,  -492,  -492,
 -    -492,  -492,  -492,    52,  -492,   238,   215,   362,  -492,    -7,
 -      12,    32,   365,   365,   365,   365,   365,   365,   365,   365,
 -     365,   238,   238,   238,    32,   238,   365,   365,   365,  -492,
 -    -492,   290,  -492,  -492,   231,   231,   583,  -492,   294,   220,
 -    -492,   313,  -492,  -492,  -492,  -492,   -44,   -44,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,   314,  -492,
 -    -492,   -44,  -492,  -492,  -492,  -492,  -492,   402,    32,   403,
 -     403,   403,   403,   403,   403,   403,   403,   403,   238,   238,
 -     238,    32,   238,   403,   403,   403,  -492,   238,   238,   238,
 -     238,   238,   238,   321,   -44,   -44,  -492,  -492,  -492,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,   331,  -492,  -492,   -44,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,   338,   347,   349,
 -     350,   238,   238,   238,   238,   238,   238,   238,   238,   221,
 -     351,   353,   354,   356,   357,   376,   377,   378,  -492,   409,
 -    -492,   238,   238,   238,   238,   221,   238,   238,   238,    12,
 -     415,   422,   430,   431,   434,   435,   436,   437,    47,   238,
 -    -492,   238,   238,   238,    12,   238,  -492,   238,   238,   238,
 -    -492,   435,   438,   439,    58,   442,   444,   445,   447,  -492,
 -     238,   238,   238,   238,   238,    12,  -492,   238,   452,   453,
 -     456,   458,   445,   231,   460,   238,    12,   211,   238,    12,
 -    -492,   238,   453,    94,   388,   461,    96,   462,   211,    12,
 -    -492,  -492,   238,    12,   238,   388,   231,   463,   231,   464,
 -    -492,   238,    12,   135,   231,    12,  -492,   111,   388,  -492
++#define YYPACT_NINF -435
+ static const short yypact[] =
+ {
 -    -492,  -492,  -492,  -492,  -492,   440,  -276,  -173,   465,  -492,
 -    -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,  -492,
 -    -492,  -492,   268,  -492,   203,  -492,  -492,  -492,   210,   -94,
 -      49,  -492,   254,    40,    31,  -292,    89,  -492,  -492,  -492,
 -    -492,   242,  -270,  -491,  -446,  -492,  -492,  -492,   344,  -492,
 -     -69,  -492,   342,  -492,  -492,  -492,  -492,  -492,  -492,  -169,
 -    -492,  -492,  -492,   316,  -492,  -492,  -492,  -492,  -492,   584,
 -    -492,  -492,   -20,  -249,  -248,  -243,  -213,  -492,   408,  -234,
 -      -2,   401,    22
++    -435,     7,    81,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++      93,    93,    93,    39,    93,  -435,  -435,   -58,  -435,   596,
++    -435,   393,   635,    93,  -435,  -435,  -435,  -435,   558,  -435,
++     393,    93,    93,    93,    93,    93,    93,    93,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++    -435,  -435,   230,   -80,  -435,   108,  -435,   371,   391,   356,
++     -37,   -37,  -435,  -435,   635,   382,   382,    87,    87,   635,
++     635,   382,   382,   635,   382,   382,   382,    87,   382,   382,
++      93,    93,    93,  -435,  -435,  -435,    93,  -435,   -64,    70,
++    -435,  -435,  -435,  -435,   177,  -435,  -435,  -435,   -56,   -29,
++     251,   296,  -435,  -435,   477,  -435,  -435,  -435,   -27,  -435,
++    -435,  -435,  -435,   -25,  -435,  -435,    29,  -435,     0,    93,
++      93,  -435,  -435,  -435,  -435,    93,    93,    93,    93,    93,
++      93,    93,  -435,    93,    93,  -435,    13,  -435,  -435,  -435,
++    -435,   113,   -66,   -22,    44,   184,   188,    53,    56,  -435,
++    -435,  -435,  -435,  -435,   -33,  -435,  -435,    58,  -435,    72,
++    -435,  -435,  -435,    19,    93,    93,    14,    68,  -435,    40,
++     109,  -435,    93,    93,   126,  -435,  -435,   321,    93,    93,
++    -435,  -435,  -435,  -435,   266,    76,    83,   -64,  -435,    92,
++      95,  -435,   103,   110,   118,   144,  -435,   142,   142,  -435,
++    -435,    93,    93,    93,   173,   176,    93,  -435,    93,   180,
++      93,    93,  -435,   147,   404,  -435,  -435,  -435,   181,    92,
++      92,    92,    92,    92,    92,    92,  -435,   185,   190,   204,
++     190,  -435,   213,   214,   -31,  -435,    93,  -435,  -435,  -435,
++    -435,  -435,  -435,  -435,   219,  -435,   240,    93,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,    93,    93,    93,    93,
++     310,  -435,  -435,  -435,  -435,   404,   122,    93,    34,   311,
++     186,   186,  -435,  -435,  -435,  -435,  -435,  -435,   431,   225,
++    -435,   226,   190,  -435,  -435,   228,  -435,  -435,  -435,  -435,
++     233,  -435,  -435,  -435,  -435,    93,   186,   244,   596,   244,
++     567,   122,    93,    34,   327,   186,   186,  -435,  -435,  -435,
++    -435,  -435,  -435,   305,  -435,    93,   238,   330,   371,  -435,
++     -13,   558,   186,    34,   331,   331,   331,   331,   331,   331,
++     331,   331,   331,    93,    93,    93,    34,    93,   331,   331,
++     331,  -435,  -435,   247,  -435,  -435,   244,   244,   585,  -435,
++     252,   190,  -435,   253,  -435,  -435,  -435,  -435,   -64,   -64,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++     256,  -435,  -435,   -64,  -435,  -435,  -435,  -435,  -435,   344,
++      34,   345,   345,   345,   345,   345,   345,   345,   345,   345,
++      93,    93,    93,    34,    93,   345,   345,   345,  -435,    93,
++      93,    93,    93,    93,    93,   262,   -64,   -64,  -435,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,   271,  -435,
++    -435,   -64,  -435,  -435,  -435,  -435,  -435,  -435,  -435,   280,
++     282,   286,   287,    93,    93,    93,    93,    93,    93,    93,
++      93,   248,   290,   293,   294,   300,   301,   309,   320,   324,
++    -435,   358,  -435,    93,    93,    93,    93,   248,    93,    93,
++      93,   186,   360,   377,   379,   380,   381,   403,   405,   407,
++     -67,    93,  -435,    93,    93,    93,   186,    93,  -435,    93,
++      93,    93,  -435,   403,   411,   413,    77,   417,   419,   421,
++     422,  -435,    93,    93,    93,    93,    93,   186,  -435,    93,
++     423,   424,   425,   426,   421,   244,   432,    93,   186,   181,
++      93,   186,  -435,    93,   424,   121,   361,   433,   132,   436,
++     181,   186,  -435,  -435,    93,   186,    93,   361,   244,   437,
++     244,   438,  -435,    93,   186,     9,   244,   186,  -435,   134,
++     361,  -435
+ };
+ /* YYPGOTO[NTERM-NUM].  */
+ static const short yypgoto[] =
+ {
 -      18,   217,    82,   193,   259,   220,     4,     5,     6,   329,
 -       7,   204,   290,     3,   204,   110,     5,     6,   111,   112,
 -     318,    83,   110,     8,    29,   111,   112,   304,   305,   192,
 -       5,     6,   187,   306,   349,    27,     5,     6,   321,   317,
 -     116,   145,   147,   374,   375,   167,   168,   169,   233,   145,
 -     170,   291,   309,   311,   205,   370,     5,     6,   385,   340,
 -     341,   210,   211,   212,   560,   342,   213,     9,     5,     6,
 -     149,   218,   566,   165,   119,   221,   350,   569,   110,   130,
 -     131,   111,   112,   118,     5,     6,     5,     6,   384,    10,
 -      11,   544,   219,    12,    13,   128,   129,    14,   148,   250,
 -     251,   252,   555,   325,   150,   138,   326,   188,   141,   142,
 -     143,   378,    10,    11,   144,   222,    12,    13,    10,    11,
 -      14,   568,    12,    13,   253,   254,    14,   163,   171,   255,
 -     350,    73,    74,    75,    76,    77,    78,    79,    10,    11,
 -     509,   350,    12,    13,   214,   225,    14,   173,   174,   447,
 -     448,   522,   451,   177,   178,   179,   180,   181,   182,   183,
 -     372,   185,   186,   117,   189,   207,    10,    11,    10,    11,
 -      12,    13,    12,    13,    14,   315,    14,   350,   386,   350,
 -     279,   280,   281,   282,   283,   284,   285,   549,   164,   553,
 -     194,   401,   215,   216,   350,  -219,   195,   498,  -219,  -219,
 -     223,   224,   196,   197,   277,   202,   227,   228,   203,   198,
 -       5,     6,   514,   317,   208,  -219,   209,   429,   430,     5,
 -       6,   380,    36,    37,   231,     5,     6,   478,   565,   247,
 -     248,   249,   432,   533,   258,   434,   260,   232,   262,   263,
 -     344,   234,     5,     6,   543,   190,   191,   546,   449,   199,
 -     200,   250,   251,   252,   236,   265,   201,   556,   266,   110,
 -     267,   558,   111,   112,   294,   462,   463,   238,   399,   400,
 -     564,   403,   242,   567,   240,   307,   253,   254,   241,   151,
 -     465,   255,   229,   230,   310,   312,   313,   314,   120,   121,
 -     122,   244,    10,    11,   151,   320,    12,    13,   153,   324,
 -      14,    10,    11,   373,   277,    12,    13,    10,    11,    14,
 -     286,    12,    13,  -242,   350,    14,    32,    33,    34,    35,
 -      36,    37,   328,   328,    10,    11,   287,   288,    12,    13,
 -     371,   551,    14,    73,    74,    75,    76,    77,    78,    79,
 -     289,   377,   551,   379,   382,   296,   295,   348,   328,   110,
 -     551,   297,   111,   112,   343,   551,   331,   328,   328,   398,
 -     398,   398,   332,   398,   345,   346,   347,    38,   383,   153,
 -      39,   387,   328,    40,    41,    42,    43,    44,    45,    46,
 -      47,    48,    49,   407,    50,    51,    52,   427,   298,   299,
 -     110,   300,   301,   111,   112,    34,    35,    36,    37,   333,
 -     334,   110,   335,   336,   111,   112,   428,   431,   433,   435,
 -     302,    24,    25,    26,   461,    28,   446,   446,   446,   110,
 -     446,   337,   111,   112,   464,   455,   456,   457,   458,   459,
 -     460,   466,    87,    88,    89,    90,    91,    92,    93,   226,
 -     467,    53,   468,   469,   481,    54,   482,   483,  -219,   484,
 -     485,  -219,  -219,    33,    34,    35,    36,    37,    30,   470,
 -     471,   472,   473,   474,   475,   476,   477,   480,  -219,   486,
 -     487,   488,   155,   156,   157,   158,   159,   160,   161,   490,
 -     491,   492,   493,   480,   495,   496,   497,   162,    31,    32,
 -      33,    34,    35,    36,    37,    86,   246,   510,   316,   511,
 -     512,   513,   489,   515,   127,   516,   517,   518,   499,   132,
 -     133,   328,   135,   136,   137,   501,   139,   140,   528,   529,
 -     530,   531,   532,   502,   503,   534,   328,   504,   505,   507,
 -     508,   520,   521,   542,   268,   523,   545,   524,   525,   547,
 -     527,   269,   270,   271,   272,   535,   536,   328,   273,   538,
 -     557,   539,   559,   541,   552,   554,   561,   562,   328,   563,
 -     519,   328,   338,   389,   390,   391,   392,   393,   394,   395,
 -     396,   328,   540,   548,   494,   328,   404,   405,   406,   256,
 -     292,   261,     0,     0,   328,     0,     0,   328,   351,   352,
++    -435,  -435,  -435,  -435,  -435,   479,  -282,  -288,   368,  -435,
++    -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,  -435,
++    -435,  -435,   195,  -435,   237,  -435,  -435,  -435,   210,  -116,
++      20,  -435,   229,     2,   -10,  -259,    52,  -435,  -435,  -435,
++    -435,   242,  -133,  -434,  -387,  -435,  -435,  -435,   315,  -435,
++     117,  -435,   312,  -435,  -435,  -435,  -435,  -435,  -435,  -170,
++    -435,  -435,  -435,   276,  -435,  -435,  -435,  -435,  -435,   586,
++    -435,  -435,   -19,  -246,  -245,  -197,  -360,  -435,   569,  -226,
++      -2,    22,   -12
+ };
+ /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+    positive, shift that token.  If negative, reduce the rule which
+    number is the opposite.  If zero, do what YYDEFACT says.
+    If YYTABLE_NINF, syntax error.  */
+ #define YYTABLE_NINF -243
+ static const short yytable[] =
+ {
 -     363,   364,   365,   366,   367,   368,   408,   409,   410,   411,
++      18,    27,   193,    82,   167,   168,   169,     3,   204,   170,
++     204,   290,   259,   116,   318,   192,   352,     5,     6,   187,
++     217,    83,    29,   210,   211,   212,   511,   145,   213,   145,
++     304,   305,    24,    25,    26,   165,    28,   149,     5,     6,
++     321,   317,   329,     5,     6,   374,   220,   233,   205,   372,
++     291,    36,    37,    87,    88,    89,    90,    91,    92,    93,
++     309,   311,   340,   341,   150,   388,   163,   350,   164,  -219,
++     352,   194,  -219,  -219,   219,   119,   376,   377,   403,   306,
++     130,   131,   386,   118,     4,     5,     6,   171,     7,  -219,
++     218,     5,     6,   387,   188,   128,   129,     5,     6,    10,
++      11,     8,   567,    12,    13,   138,   214,    14,   141,   142,
++     143,   342,     5,     6,   144,   222,   221,   190,   191,   380,
++      10,    11,   436,   562,    12,    13,     5,     6,    14,   317,
++     110,   568,   225,   111,   112,   451,   571,   195,    73,    74,
++      75,    76,    77,    78,    79,     9,   202,   173,   174,   203,
++     147,   208,   546,   177,   178,   179,   180,   181,   182,   183,
++     352,   185,   186,   557,   189,   209,   207,    10,    11,   231,
++     524,    12,    13,    10,    11,    14,   232,    12,    13,    10,
++      11,    14,   570,    12,    13,   234,   553,    14,   236,   117,
++       5,     6,   215,   216,    10,    11,   238,   553,    12,    13,
++     223,   224,    14,   240,   352,   553,   227,   228,    10,    11,
++     553,   241,    12,    13,   551,   352,    14,   352,   431,   432,
++     250,   251,   252,   265,   242,   555,   266,   277,   267,   247,
++     248,   249,   500,   434,   258,   244,   260,   110,   262,   263,
++     111,   112,     5,     6,   382,   253,   254,   516,   401,   402,
++     255,   405,     5,     6,   480,   296,   151,   148,   196,   197,
++     153,   297,   199,   200,   294,   198,   464,   465,   535,   201,
++     229,   230,    10,    11,   277,   307,    12,   325,   286,   545,
++     326,   467,   548,  -242,   310,   312,   313,   314,   449,   450,
++     110,   453,   558,   111,   112,   320,   560,   287,   298,   299,
++     110,   300,   301,   111,   112,   566,   288,   289,   569,     5,
++       6,   110,   295,   349,   111,   112,   315,   324,   343,   345,
++     302,   346,   328,   328,    10,    11,   347,   352,    12,    13,
++     373,   151,    14,   375,    10,    11,   385,   389,    12,    13,
++     409,   379,    14,   381,   384,   429,   430,   348,   351,   433,
++     435,   437,   250,   251,   252,   463,   110,   328,   328,   111,
++     112,   400,   400,   400,   466,   400,   279,   280,   281,   282,
++     283,   284,   285,   468,   328,   469,   153,   253,   254,   470,
++     471,   110,   255,   483,   111,   112,   484,   485,   120,   121,
++     122,    10,    11,   486,   487,    12,    13,    38,    86,    14,
++      39,   226,   488,    40,    41,    42,    43,    44,    45,    46,
++      47,    48,    49,   489,    50,    51,    52,   490,   448,   448,
++     448,  -219,   448,   246,  -219,  -219,   344,   457,   458,   459,
++     460,   461,   462,    73,    74,    75,    76,    77,    78,    79,
++     268,  -219,    34,    35,    36,    37,   331,   269,   270,   271,
++     272,   491,   332,   501,   273,    32,    33,    34,    35,    36,
++      37,   472,   473,   474,   475,   476,   477,   478,   479,   482,
++     503,    53,   504,   505,   506,    54,    33,    34,    35,    36,
++      37,   492,   493,   494,   495,   482,   497,   498,   499,   333,
++     334,   110,   335,   336,   111,   112,   507,    30,   509,   512,
++     510,   513,   514,   515,   522,   517,   523,   518,   519,   520,
++     525,   337,   526,   328,   527,   529,   537,   538,   540,   541,
++     530,   531,   532,   533,   534,   543,   554,   536,   328,   556,
++     563,   564,   316,   521,   550,   544,   542,   338,   547,   496,
++     292,   549,   155,   156,   157,   158,   159,   160,   161,   328,
++     256,   261,   559,     0,   561,     0,     0,   162,     0,     0,
++     328,   565,     0,   328,     0,   391,   392,   393,   394,   395,
++     396,   397,   398,   328,     0,     0,     0,   328,   406,   407,
++     408,     0,     0,     0,     0,     0,   328,     0,     0,   328,
+      353,   354,   355,   356,   357,   358,   359,   360,   361,   362,
 -     422,   423,   424,   425,    94,    95,    96,    97,    98,    99,
 -     100,   101,   102,   103,   104,   105,   106,   107,   108,    31,
 -      32,    33,    34,    35,    36,    37,   369,     0,     0,   109,
 -       0,    84,   437,   438,   439,   440,   441,   442,   443,   444,
 -       0,     0,     0,     0,   426,   452,   453,   454,    73,    74,
 -      75,    76,    77,    78,    79
++     363,   364,   365,   366,   367,   368,   369,   370,   410,   411,
+      412,   413,   414,   415,   416,   417,   418,   419,   420,   421,
 -       2,     6,    22,   172,   238,     6,     3,     4,     5,   301,
 -       7,    41,    42,     0,    41,    60,     4,     5,    63,    64,
 -     296,    23,    60,    20,    80,    63,    64,   276,   276,    81,
 -       4,     5,     6,   276,   326,    13,     4,     5,     6,     7,
 -      93,    93,    80,   335,   336,     4,     5,     6,   217,    93,
 -       9,    81,   286,   287,    81,   331,     4,     5,   350,   308,
 -     308,     4,     5,     6,   555,   308,     9,    64,     4,     5,
 -      93,    76,   563,     6,    94,    76,    83,   568,    60,    99,
 -     100,    63,    64,    85,     4,     5,     4,     5,    95,    86,
 -      87,   537,     6,    90,    91,    97,    98,    94,    80,    47,
 -      48,    49,   548,    91,    93,   107,    94,    81,   110,   111,
 -     112,   345,    86,    87,   116,     6,    90,    91,    86,    87,
 -      94,   567,    90,    91,    72,    73,    94,    93,    87,    77,
 -      83,    51,    52,    53,    54,    55,    56,    57,    86,    87,
 -      93,    83,    90,    91,    87,     6,    94,   149,   150,   419,
 -     420,    93,   422,   155,   156,   157,   158,   159,   160,   161,
 -     333,   163,   164,    81,   166,   185,    86,    87,    86,    87,
 -      90,    91,    90,    91,    94,     6,    94,    83,   351,    83,
 -     249,   250,   251,   252,   253,   254,   255,    93,    93,    93,
 -      93,   364,   194,   195,    83,    60,    93,   489,    63,    64,
 -     202,   203,    74,    75,    93,    93,   208,   209,    93,    81,
 -       4,     5,   504,     7,    93,    80,    93,   386,   387,     4,
 -       5,     6,    88,    89,    93,     4,     5,     6,    93,   231,
 -     232,   233,   401,   525,   236,   408,   238,    93,   240,   241,
 -     309,    93,     4,     5,   536,     4,     5,   539,   421,    74,
 -      75,    47,    48,    49,    93,    76,    81,   549,    79,    60,
 -      81,   553,    63,    64,   266,   434,   435,    93,   362,   363,
 -     562,   365,    80,   565,    93,   277,    72,    73,    93,    80,
 -     449,    77,     4,     5,   286,   287,   288,   289,     6,     7,
 -       8,    93,    86,    87,    80,   297,    90,    91,    80,     6,
 -      94,    86,    87,     6,    93,    90,    91,    86,    87,    94,
 -      93,    90,    91,    93,    83,    94,    84,    85,    86,    87,
 -      88,    89,   300,   301,    86,    87,    93,    93,    90,    91,
 -     332,   544,    94,    51,    52,    53,    54,    55,    56,    57,
 -      93,   343,   555,   345,   346,    15,    93,   325,   326,    60,
 -     563,    21,    63,    64,    93,   568,    15,   335,   336,   361,
 -     362,   363,    21,   365,    93,    93,    93,     4,     6,    80,
 -       7,     6,   350,    10,    11,    12,    13,    14,    15,    16,
 -      17,    18,    19,    93,    21,    22,    23,    93,    58,    59,
 -      60,    61,    62,    63,    64,    86,    87,    88,    89,    58,
 -      59,    60,    61,    62,    63,    64,    93,    93,     6,     6,
 -      80,    10,    11,    12,    93,    14,   418,   419,   420,    60,
 -     422,    80,    63,    64,    93,   427,   428,   429,   430,   431,
 -     432,    93,    31,    32,    33,    34,    35,    36,    37,    80,
 -      93,    78,    93,    93,    93,    82,    93,    93,    60,    93,
 -      93,    63,    64,    85,    86,    87,    88,    89,    18,   461,
 -     462,   463,   464,   465,   466,   467,   468,   469,    80,    93,
 -      93,    93,    65,    66,    67,    68,    69,    70,    71,   481,
 -     482,   483,   484,   485,   486,   487,   488,    80,    83,    84,
 -      85,    86,    87,    88,    89,    30,   228,   499,   295,   501,
 -     502,   503,    93,   505,    96,   507,   508,   509,    93,   101,
 -     102,   489,   104,   105,   106,    93,   108,   109,   520,   521,
 -     522,   523,   524,    93,    93,   527,   504,    93,    93,    93,
 -      93,    93,    93,   535,    36,    93,   538,    93,    93,   541,
 -      93,    43,    44,    45,    46,    93,    93,   525,    50,    93,
 -     552,    93,   554,    93,    93,    93,    93,    93,   536,   561,
 -     511,   539,   308,   353,   354,   355,   356,   357,   358,   359,
 -     360,   549,   532,   542,   485,   553,   366,   367,   368,   235,
 -     264,   239,    -1,    -1,   562,    -1,    -1,   565,    23,    24,
++     422,   423,   424,   425,   426,   427,    94,    95,    96,    97,
++      98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
++     108,    31,    32,    33,    34,    35,    36,    37,   371,     0,
++       0,   109,     0,    84,   439,   440,   441,   442,   443,   444,
++     445,   446,     0,     0,     0,   127,   428,   454,   455,   456,
++     132,   133,     0,   135,   136,   137,     0,   139,   140,    31,
++      32,    33,    34,    35,    36,    37,    73,    74,    75,    76,
++      77,    78,    79
+ };
+ static const short yycheck[] =
+ {
 -      35,    36,    37,    38,    39,    40,    23,    24,    25,    26,
 -      27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
 -      37,    38,    39,    40,    40,    41,    42,    43,    44,    45,
 -      46,    47,    48,    49,    50,    51,    52,    53,    54,    83,
 -      84,    85,    86,    87,    88,    89,    81,    -1,    -1,    65,
 -      -1,    95,   410,   411,   412,   413,   414,   415,   416,   417,
 -      -1,    -1,    -1,    -1,    81,   423,   424,   425,    51,    52,
 -      53,    54,    55,    56,    57
++       2,    13,   172,    22,     4,     5,     6,     0,    41,     9,
++      41,    42,   238,    93,   296,    81,    83,     4,     5,     6,
++       6,    23,    80,     4,     5,     6,    93,    93,     9,    93,
++     276,   276,    10,    11,    12,     6,    14,    93,     4,     5,
++       6,     7,   301,     4,     5,   333,     6,   217,    81,   331,
++      81,    88,    89,    31,    32,    33,    34,    35,    36,    37,
++     286,   287,   308,   308,    93,   353,    93,   326,    93,    60,
++      83,    93,    63,    64,     6,    94,   335,   336,   366,   276,
++      99,   100,    95,    85,     3,     4,     5,    87,     7,    80,
++      76,     4,     5,   352,    81,    97,    98,     4,     5,    86,
++      87,    20,    93,    90,    91,   107,    87,    94,   110,   111,
++     112,   308,     4,     5,   116,     6,    76,     4,     5,   345,
++      86,    87,   410,   557,    90,    91,     4,     5,    94,     7,
++      60,   565,     6,    63,    64,   423,   570,    93,    51,    52,
++      53,    54,    55,    56,    57,    64,    93,   149,   150,    93,
++      80,    93,   539,   155,   156,   157,   158,   159,   160,   161,
++      83,   163,   164,   550,   166,    93,   185,    86,    87,    93,
++      93,    90,    91,    86,    87,    94,    93,    90,    91,    86,
++      87,    94,   569,    90,    91,    93,   546,    94,    93,    81,
++       4,     5,   194,   195,    86,    87,    93,   557,    90,    91,
++     202,   203,    94,    93,    83,   565,   208,   209,    86,    87,
++     570,    93,    90,    91,    93,    83,    94,    83,   388,   389,
++      47,    48,    49,    76,    80,    93,    79,    93,    81,   231,
++     232,   233,   491,   403,   236,    93,   238,    60,   240,   241,
++      63,    64,     4,     5,     6,    72,    73,   506,   364,   365,
++      77,   367,     4,     5,     6,    15,    80,    80,    74,    75,
++      80,    21,    74,    75,   266,    81,   436,   437,   527,    81,
++       4,     5,    86,    87,    93,   277,    90,    91,    93,   538,
++      94,   451,   541,    93,   286,   287,   288,   289,   421,   422,
++      60,   424,   551,    63,    64,   297,   555,    93,    58,    59,
++      60,    61,    62,    63,    64,   564,    93,    93,   567,     4,
++       5,    60,    93,   325,    63,    64,     6,     6,    93,    93,
++      80,    93,   300,   301,    86,    87,    93,    83,    90,    91,
++     332,    80,    94,     6,    86,    87,     6,     6,    90,    91,
++      93,   343,    94,   345,   346,    93,    93,   325,   326,    93,
++       6,     6,    47,    48,    49,    93,    60,   335,   336,    63,
++      64,   363,   364,   365,    93,   367,   249,   250,   251,   252,
++     253,   254,   255,    93,   352,    93,    80,    72,    73,    93,
++      93,    60,    77,    93,    63,    64,    93,    93,     6,     7,
++       8,    86,    87,    93,    93,    90,    91,     4,    30,    94,
++       7,    80,    93,    10,    11,    12,    13,    14,    15,    16,
++      17,    18,    19,    93,    21,    22,    23,    93,   420,   421,
++     422,    60,   424,   228,    63,    64,   309,   429,   430,   431,
++     432,   433,   434,    51,    52,    53,    54,    55,    56,    57,
++      36,    80,    86,    87,    88,    89,    15,    43,    44,    45,
++      46,    93,    21,    93,    50,    84,    85,    86,    87,    88,
++      89,   463,   464,   465,   466,   467,   468,   469,   470,   471,
++      93,    78,    93,    93,    93,    82,    85,    86,    87,    88,
++      89,   483,   484,   485,   486,   487,   488,   489,   490,    58,
++      59,    60,    61,    62,    63,    64,    93,    18,    93,   501,
++      93,   503,   504,   505,    93,   507,    93,   509,   510,   511,
++      93,    80,    93,   491,    93,    93,    93,    93,    93,    93,
++     522,   523,   524,   525,   526,    93,    93,   529,   506,    93,
++      93,    93,   295,   513,   544,   537,   534,   308,   540,   487,
++     264,   543,    65,    66,    67,    68,    69,    70,    71,   527,
++     235,   239,   554,    -1,   556,    -1,    -1,    80,    -1,    -1,
++     538,   563,    -1,   541,    -1,   355,   356,   357,   358,   359,
++     360,   361,   362,   551,    -1,    -1,    -1,   555,   368,   369,
++     370,    -1,    -1,    -1,    -1,    -1,   564,    -1,    -1,   567,
++      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
++      33,    34,    35,    36,    37,    38,    39,    40,    23,    24,
+       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
 -     176,     6,   102,   103,     6,    91,    94,   131,   178,   131,
++      35,    36,    37,    38,    39,    40,    40,    41,    42,    43,
++      44,    45,    46,    47,    48,    49,    50,    51,    52,    53,
++      54,    83,    84,    85,    86,    87,    88,    89,    81,    -1,
++      -1,    65,    -1,    95,   412,   413,   414,   415,   416,   417,
++     418,   419,    -1,    -1,    -1,    96,    81,   425,   426,   427,
++     101,   102,    -1,   104,   105,   106,    -1,   108,   109,    83,
++      84,    85,    86,    87,    88,    89,    51,    52,    53,    54,
++      55,    56,    57
+ };
+ /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+    symbol of state STATE-NUM.  */
+ static const unsigned char yystos[] =
+ {
+        0,    97,    98,     0,     3,     4,     5,     7,    20,    64,
+       86,    87,    90,    91,    94,    99,   152,   153,   176,   177,
+      178,   101,   165,   100,   177,   177,   177,   178,   177,    80,
+      101,    83,    84,    85,    86,    87,    88,    89,     4,     7,
+       10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
+       21,    22,    23,    78,    82,   104,   106,   107,   108,   109,
+      110,   111,   112,   113,   114,   115,   116,   121,   133,   143,
+      147,   156,   163,    51,    52,    53,    54,    55,    56,    57,
+      166,   167,   168,   176,    95,   154,   104,   177,   177,   177,
+      177,   177,   177,   177,   165,   165,   165,   165,   165,   165,
+      165,   165,   165,   165,   165,   165,   165,   165,   165,   165,
+       60,    63,    64,   169,   170,   171,    93,    81,   176,   168,
+        6,     7,     8,   105,   168,   172,   174,   174,   176,   176,
+      168,   168,   174,   174,   157,   174,   174,   174,   176,   174,
+      174,   176,   176,   176,   176,    93,   155,    80,    80,    93,
+       93,    80,   144,    80,   148,    65,    66,    67,    68,    69,
+       70,    71,    80,    93,    93,     6,   117,     4,     5,     6,
+        9,    87,   173,   176,   176,   145,   149,   176,   176,   176,
+      176,   176,   176,   176,   158,   176,   176,     6,    81,   176,
+        4,     5,    81,   155,    93,    93,    74,    75,    81,    74,
+       75,    81,    93,    93,    41,    81,   159,   168,    93,    93,
+        4,     5,     6,     9,    87,   176,   176,     6,    76,     6,
+        6,    76,     6,   176,   176,     6,    80,   176,   176,     4,
+        5,    93,    93,   155,    93,   146,    93,   150,    93,   151,
+       93,    93,    80,   164,    93,   118,   118,   176,   176,   176,
+       47,    48,    49,    72,    73,    77,   144,   175,   176,   175,
+      176,   148,   176,   176,   160,    76,    79,    81,    36,    43,
+       44,    45,    46,    50,   119,   120,   122,    93,   140,   146,
+      146,   146,   146,   146,   146,   146,    93,    93,    93,    93,
+       42,    81,   159,   161,   176,    93,    15,    21,    58,    59,
+       61,    62,    80,   128,   169,   170,   171,   176,   134,   175,
+      176,   175,   176,   176,   176,     6,   120,     7,   102,   176,
 -     169,   170,   171,    93,   146,    93,    93,    93,   178,   131,
 -      83,    23,    24,    25,    26,    27,    28,    29,    30,    31,
 -      32,    33,    34,    35,    36,    37,    38,    39,    40,    81,
 -     102,   176,   103,     6,   131,   131,   135,   176,   175,   176,
 -       6,   162,   176,     6,    95,   131,   103,     6,   124,   124,
 -     124,   124,   124,   124,   124,   124,   124,   125,   176,   125,
 -     125,   103,   127,   125,   124,   124,   124,    93,    23,    24,
 -      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
 -      35,    36,    37,    38,    39,    40,    81,    93,    93,   155,
 -     155,    93,   155,     6,   103,     6,   137,   137,   137,   137,
 -     137,   137,   137,   137,   137,   138,   176,   138,   138,   103,
 -     136,   138,   137,   137,   137,   176,   176,   176,   176,   176,
 -     176,    93,   155,   155,    93,   155,    93,    93,    93,    93,
 -     176,   176,   176,   176,   176,   176,   176,   176,     6,   132,
 -     176,    93,    93,    93,    93,    93,    93,    93,    93,    93,
 -     176,   176,   176,   176,   132,   176,   176,   176,   131,    93,
 -     142,    93,    93,    93,    93,    93,   126,    93,    93,    93,
 -     176,   176,   176,   176,   131,   176,   176,   176,   176,   126,
 -      93,    93,    93,    93,    93,    93,   129,    93,   176,   176,
 -     176,   176,   176,   131,   176,    93,    93,   130,    93,    93,
 -     129,    93,   176,   131,   140,   176,   131,   176,   130,    93,
 -     139,   172,    93,    93,    93,   140,   131,   176,   131,   176,
 -     139,    93,    93,   176,   131,    93,   139,   131,   140,   139
++     176,     6,   102,   103,     6,    91,    94,   131,   177,   131,
+      123,    15,    21,    58,    59,    61,    62,    80,   128,   141,
 -#line 4129 "y.tab.c"
++     169,   170,   171,    93,   146,    93,    93,    93,   177,   178,
++     131,   177,    83,    23,    24,    25,    26,    27,    28,    29,
++      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
++      40,    81,   102,   176,   103,     6,   131,   131,   135,   176,
++     175,   176,     6,   162,   176,     6,    95,   131,   103,     6,
++     124,   124,   124,   124,   124,   124,   124,   124,   124,   125,
++     176,   125,   125,   103,   127,   125,   124,   124,   124,    93,
++      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
++      33,    34,    35,    36,    37,    38,    39,    40,    81,    93,
++      93,   155,   155,    93,   155,     6,   103,     6,   137,   137,
++     137,   137,   137,   137,   137,   137,   137,   138,   176,   138,
++     138,   103,   136,   138,   137,   137,   137,   176,   176,   176,
++     176,   176,   176,    93,   155,   155,    93,   155,    93,    93,
++      93,    93,   176,   176,   176,   176,   176,   176,   176,   176,
++       6,   132,   176,    93,    93,    93,    93,    93,    93,    93,
++      93,    93,   176,   176,   176,   176,   132,   176,   176,   176,
++     131,    93,   142,    93,    93,    93,    93,    93,   126,    93,
++      93,    93,   176,   176,   176,   176,   131,   176,   176,   176,
++     176,   126,    93,    93,    93,    93,    93,    93,   129,    93,
++     176,   176,   176,   176,   176,   131,   176,    93,    93,   130,
++      93,    93,   129,    93,   176,   131,   140,   176,   131,   176,
++     130,    93,   139,   172,    93,    93,    93,   140,   131,   176,
++     131,   176,   139,    93,    93,   176,   131,    93,   139,   131,
++     140,   139
+ };
+ #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+ # define YYSIZE_T __SIZE_TYPE__
+ #endif
+ #if ! defined (YYSIZE_T) && defined (size_t)
+ # define YYSIZE_T size_t
+ #endif
+ #if ! defined (YYSIZE_T)
+ # if defined (__STDC__) || defined (__cplusplus)
+ #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+ #  define YYSIZE_T size_t
+ # endif
+ #endif
+ #if ! defined (YYSIZE_T)
+ # define YYSIZE_T unsigned int
+ #endif
+ #define yyerrok               (yyerrstatus = 0)
+ #define yyclearin     (yychar = YYEMPTY)
+ #define YYEMPTY               (-2)
+ #define YYEOF         0
+ #define YYACCEPT      goto yyacceptlab
+ #define YYABORT               goto yyabortlab
+ #define YYERROR               goto yyerrlab1
+ /* Like YYERROR except do call yyerror.  This remains here temporarily
+    to ease the transition to the new meaning of YYERROR, for GCC.
+    Once GCC version 2 has supplanted version 1, this can go.  */
+ #define YYFAIL                goto yyerrlab
+ #define YYRECOVERING()  (!!yyerrstatus)
+ #define YYBACKUP(Token, Value)                                        \
+ do                                                            \
+   if (yychar == YYEMPTY && yylen == 1)                                \
+     {                                                         \
+       yychar = (Token);                                               \
+       yylval = (Value);                                               \
+       yytoken = YYTRANSLATE (yychar);                         \
+       YYPOPSTACK;                                             \
+       goto yybackup;                                          \
+     }                                                         \
+   else                                                                \
+     {                                                                 \
+       yyerror ("syntax error: cannot back up");\
+       YYERROR;                                                        \
+     }                                                         \
+ while (0)
+ #define YYTERROR      1
+ #define YYERRCODE     256
+ /* YYLLOC_DEFAULT -- Compute the default location (before the actions
+    are run).  */
+ #ifndef YYLLOC_DEFAULT
+ # define YYLLOC_DEFAULT(Current, Rhs, N)         \
+   Current.first_line   = Rhs[1].first_line;      \
+   Current.first_column = Rhs[1].first_column;    \
+   Current.last_line    = Rhs[N].last_line;       \
+   Current.last_column  = Rhs[N].last_column;
+ #endif
+ /* YYLEX -- calling `yylex' with the right arguments.  */
+ #ifdef YYLEX_PARAM
+ # define YYLEX yylex (YYLEX_PARAM)
+ #else
+ # define YYLEX yylex ()
+ #endif
+ /* Enable debugging if requested.  */
+ #if YYDEBUG
+ # ifndef YYFPRINTF
+ #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+ #  define YYFPRINTF fprintf
+ # endif
+ # define YYDPRINTF(Args)                      \
+ do {                                          \
+   if (yydebug)                                        \
+     YYFPRINTF Args;                           \
+ } while (0)
+ # define YYDSYMPRINT(Args)                    \
+ do {                                          \
+   if (yydebug)                                        \
+     yysymprint Args;                          \
+ } while (0)
+ # define YYDSYMPRINTF(Title, Token, Value, Location)          \
+ do {                                                          \
+   if (yydebug)                                                        \
+     {                                                         \
+       YYFPRINTF (stderr, "%s ", Title);                               \
+       yysymprint (stderr,                                     \
+                   Token, Value);      \
+       YYFPRINTF (stderr, "\n");                                       \
+     }                                                         \
+ } while (0)
+ /*------------------------------------------------------------------.
+ | yy_stack_print -- Print the state stack from its BOTTOM up to its |
+ | TOP (cinluded).                                                   |
+ `------------------------------------------------------------------*/
+ #if defined (__STDC__) || defined (__cplusplus)
+ static void
+ yy_stack_print (short *bottom, short *top)
+ #else
+ static void
+ yy_stack_print (bottom, top)
+     short *bottom;
+     short *top;
+ #endif
+ {
+   YYFPRINTF (stderr, "Stack now");
+   for (/* Nothing. */; bottom <= top; ++bottom)
+     YYFPRINTF (stderr, " %d", *bottom);
+   YYFPRINTF (stderr, "\n");
+ }
+ # define YY_STACK_PRINT(Bottom, Top)                          \
+ do {                                                          \
+   if (yydebug)                                                        \
+     yy_stack_print ((Bottom), (Top));                         \
+ } while (0)
+ /*------------------------------------------------.
+ | Report that the YYRULE is going to be reduced.  |
+ `------------------------------------------------*/
+ #if defined (__STDC__) || defined (__cplusplus)
+ static void
+ yy_reduce_print (int yyrule)
+ #else
+ static void
+ yy_reduce_print (yyrule)
+     int yyrule;
+ #endif
+ {
+   int yyi;
+   unsigned int yylno = yyrline[yyrule];
+   YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
+              yyrule - 1, yylno);
+   /* Print the symbols being reduced, and their result.  */
+   for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+     YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
+   YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
+ }
+ # define YY_REDUCE_PRINT(Rule)                \
+ do {                                  \
+   if (yydebug)                                \
+     yy_reduce_print (Rule);           \
+ } while (0)
+ /* Nonzero means print parse trace.  It is left uninitialized so that
+    multiple parsers can coexist.  */
+ int yydebug;
+ #else /* !YYDEBUG */
+ # define YYDPRINTF(Args)
+ # define YYDSYMPRINT(Args)
+ # define YYDSYMPRINTF(Title, Token, Value, Location)
+ # define YY_STACK_PRINT(Bottom, Top)
+ # define YY_REDUCE_PRINT(Rule)
+ #endif /* !YYDEBUG */
+ /* YYINITDEPTH -- initial size of the parser's stacks.  */
+ #ifndef       YYINITDEPTH
+ # define YYINITDEPTH 200
+ #endif
+ /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+    if the built-in stack extension method is used).
+    Do not make this value too large; the results are undefined if
+    SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+    evaluated with infinite-precision integer arithmetic.  */
+ #if YYMAXDEPTH == 0
+ # undef YYMAXDEPTH
+ #endif
+ #ifndef YYMAXDEPTH
+ # define YYMAXDEPTH 10000
+ #endif
\f
+ #if YYERROR_VERBOSE
+ # ifndef yystrlen
+ #  if defined (__GLIBC__) && defined (_STRING_H)
+ #   define yystrlen strlen
+ #  else
+ /* Return the length of YYSTR.  */
+ static YYSIZE_T
+ #   if defined (__STDC__) || defined (__cplusplus)
+ yystrlen (const char *yystr)
+ #   else
+ yystrlen (yystr)
+      const char *yystr;
+ #   endif
+ {
+   register const char *yys = yystr;
+   while (*yys++ != '\0')
+     continue;
+   return yys - yystr - 1;
+ }
+ #  endif
+ # endif
+ # ifndef yystpcpy
+ #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+ #   define yystpcpy stpcpy
+ #  else
+ /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+    YYDEST.  */
+ static char *
+ #   if defined (__STDC__) || defined (__cplusplus)
+ yystpcpy (char *yydest, const char *yysrc)
+ #   else
+ yystpcpy (yydest, yysrc)
+      char *yydest;
+      const char *yysrc;
+ #   endif
+ {
+   register char *yyd = yydest;
+   register const char *yys = yysrc;
+   while ((*yyd++ = *yys++) != '\0')
+     continue;
+   return yyd - 1;
+ }
+ #  endif
+ # endif
+ #endif /* !YYERROR_VERBOSE */
\f
+ #if YYDEBUG
+ /*--------------------------------.
+ | Print this symbol on YYOUTPUT.  |
+ `--------------------------------*/
+ #if defined (__STDC__) || defined (__cplusplus)
+ static void
+ yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
+ #else
+ static void
+ yysymprint (yyoutput, yytype, yyvaluep)
+     FILE *yyoutput;
+     int yytype;
+     YYSTYPE *yyvaluep;
+ #endif
+ {
+   /* Pacify ``unused variable'' warnings.  */
+   (void) yyvaluep;
+   if (yytype < YYNTOKENS)
+     {
+       YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ # ifdef YYPRINT
+       YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+ # endif
+     }
+   else
+     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+   switch (yytype)
+     {
+       default:
+         break;
+     }
+   YYFPRINTF (yyoutput, ")");
+ }
+ #endif /* ! YYDEBUG */
+ /*-----------------------------------------------.
+ | Release the memory associated to this symbol.  |
+ `-----------------------------------------------*/
+ #if defined (__STDC__) || defined (__cplusplus)
+ static void
+ yydestruct (int yytype, YYSTYPE *yyvaluep)
+ #else
+ static void
+ yydestruct (yytype, yyvaluep)
+     int yytype;
+     YYSTYPE *yyvaluep;
+ #endif
+ {
+   /* Pacify ``unused variable'' warnings.  */
+   (void) yyvaluep;
+   switch (yytype)
+     {
+       default:
+         break;
+     }
+ }
\f
+ /* Prevent warnings from -Wmissing-prototypes.  */
+ #ifdef YYPARSE_PARAM
+ # if defined (__STDC__) || defined (__cplusplus)
+ int yyparse (void *YYPARSE_PARAM);
+ # else
+ int yyparse ();
+ # endif
+ #else /* ! YYPARSE_PARAM */
+ #if defined (__STDC__) || defined (__cplusplus)
+ int yyparse (void);
+ #else
+ int yyparse ();
+ #endif
+ #endif /* ! YYPARSE_PARAM */
+ /* The lookahead symbol.  */
+ int yychar;
+ /* The semantic value of the lookahead symbol.  */
+ YYSTYPE yylval;
+ /* Number of syntax errors so far.  */
+ int yynerrs;
+ /*----------.
+ | yyparse.  |
+ `----------*/
+ #ifdef YYPARSE_PARAM
+ # if defined (__STDC__) || defined (__cplusplus)
+ int yyparse (void *YYPARSE_PARAM)
+ # else
+ int yyparse (YYPARSE_PARAM)
+   void *YYPARSE_PARAM;
+ # endif
+ #else /* ! YYPARSE_PARAM */
+ #if defined (__STDC__) || defined (__cplusplus)
+ int
+ yyparse (void)
+ #else
+ int
+ yyparse ()
+ #endif
+ #endif
+ {
+   
+   register int yystate;
+   register int yyn;
+   int yyresult;
+   /* Number of tokens to shift before error messages enabled.  */
+   int yyerrstatus;
+   /* Lookahead token as an internal (translated) token number.  */
+   int yytoken = 0;
+   /* Three stacks and their tools:
+      `yyss': related to states,
+      `yyvs': related to semantic values,
+      `yyls': related to locations.
+      Refer to the stacks thru separate pointers, to allow yyoverflow
+      to reallocate them elsewhere.  */
+   /* The state stack.  */
+   short       yyssa[YYINITDEPTH];
+   short *yyss = yyssa;
+   register short *yyssp;
+   /* The semantic value stack.  */
+   YYSTYPE yyvsa[YYINITDEPTH];
+   YYSTYPE *yyvs = yyvsa;
+   register YYSTYPE *yyvsp;
+ #define YYPOPSTACK   (yyvsp--, yyssp--)
+   YYSIZE_T yystacksize = YYINITDEPTH;
+   /* The variables used to return semantic value and location from the
+      action routines.  */
+   YYSTYPE yyval;
+   /* When reducing, the number of symbols on the RHS of the reduced
+      rule.  */
+   int yylen;
+   YYDPRINTF ((stderr, "Starting parse\n"));
+   yystate = 0;
+   yyerrstatus = 0;
+   yynerrs = 0;
+   yychar = YYEMPTY;           /* Cause a token to be read.  */
+   /* Initialize stack pointers.
+      Waste one element of value and location stack
+      so that they stay on the same level as the state stack.
+      The wasted elements are never initialized.  */
+   yyssp = yyss;
+   yyvsp = yyvs;
+   goto yysetstate;
+ /*------------------------------------------------------------.
+ | yynewstate -- Push a new state, which is found in yystate.  |
+ `------------------------------------------------------------*/
+  yynewstate:
+   /* In all cases, when you get here, the value and location stacks
+      have just been pushed. so pushing a state here evens the stacks.
+      */
+   yyssp++;
+  yysetstate:
+   *yyssp = yystate;
+   if (yyss + yystacksize - 1 <= yyssp)
+     {
+       /* Get the current used size of the three stacks, in elements.  */
+       YYSIZE_T yysize = yyssp - yyss + 1;
+ #ifdef yyoverflow
+       {
+       /* Give user a chance to reallocate the stack. Use copies of
+          these so that the &'s don't force the real ones into
+          memory.  */
+       YYSTYPE *yyvs1 = yyvs;
+       short *yyss1 = yyss;
+       /* Each stack pointer address is followed by the size of the
+          data in use in that stack, in bytes.  This used to be a
+          conditional around just the two extra args, but that might
+          be undefined if yyoverflow is a macro.  */
+       yyoverflow ("parser stack overflow",
+                   &yyss1, yysize * sizeof (*yyssp),
+                   &yyvs1, yysize * sizeof (*yyvsp),
+                   &yystacksize);
+       yyss = yyss1;
+       yyvs = yyvs1;
+       }
+ #else /* no yyoverflow */
+ # ifndef YYSTACK_RELOCATE
+       goto yyoverflowlab;
+ # else
+       /* Extend the stack our own way.  */
+       if (YYMAXDEPTH <= yystacksize)
+       goto yyoverflowlab;
+       yystacksize *= 2;
+       if (YYMAXDEPTH < yystacksize)
+       yystacksize = YYMAXDEPTH;
+       {
+       short *yyss1 = yyss;
+       union yyalloc *yyptr =
+         (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+       if (! yyptr)
+         goto yyoverflowlab;
+       YYSTACK_RELOCATE (yyss);
+       YYSTACK_RELOCATE (yyvs);
+ #  undef YYSTACK_RELOCATE
+       if (yyss1 != yyssa)
+         YYSTACK_FREE (yyss1);
+       }
+ # endif
+ #endif /* no yyoverflow */
+       yyssp = yyss + yysize - 1;
+       yyvsp = yyvs + yysize - 1;
+       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+                 (unsigned long int) yystacksize));
+       if (yyss + yystacksize - 1 <= yyssp)
+       YYABORT;
+     }
+   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+   goto yybackup;
+ /*-----------.
+ | yybackup.  |
+ `-----------*/
+ yybackup:
+ /* Do appropriate processing given the current state.  */
+ /* Read a lookahead token if we need one and don't already have one.  */
+ /* yyresume: */
+   /* First try to decide what to do without reference to lookahead token.  */
+   yyn = yypact[yystate];
+   if (yyn == YYPACT_NINF)
+     goto yydefault;
+   /* Not known => get a lookahead token if don't already have one.  */
+   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
+   if (yychar == YYEMPTY)
+     {
+       YYDPRINTF ((stderr, "Reading a token: "));
+       yychar = YYLEX;
+     }
+   if (yychar <= YYEOF)
+     {
+       yychar = yytoken = YYEOF;
+       YYDPRINTF ((stderr, "Now at end of input.\n"));
+     }
+   else
+     {
+       yytoken = YYTRANSLATE (yychar);
+       YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
+     }
+   /* If the proper action on seeing token YYTOKEN is to reduce or to
+      detect an error, take that action.  */
+   yyn += yytoken;
+   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+     goto yydefault;
+   yyn = yytable[yyn];
+   if (yyn <= 0)
+     {
+       if (yyn == 0 || yyn == YYTABLE_NINF)
+       goto yyerrlab;
+       yyn = -yyn;
+       goto yyreduce;
+     }
+   if (yyn == YYFINAL)
+     YYACCEPT;
+   /* Shift the lookahead token.  */
+   YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
+   /* Discard the token being shifted unless it is eof.  */
+   if (yychar != YYEOF)
+     yychar = YYEMPTY;
+   *++yyvsp = yylval;
+   /* Count tokens shifted since error; after three, turn off error
+      status.  */
+   if (yyerrstatus)
+     yyerrstatus--;
+   yystate = yyn;
+   goto yynewstate;
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state.  |
+ `-----------------------------------------------------------*/
+ yydefault:
+   yyn = yydefact[yystate];
+   if (yyn == 0)
+     goto yyerrlab;
+   goto yyreduce;
+ /*-----------------------------.
+ | yyreduce -- Do a reduction.  |
+ `-----------------------------*/
+ yyreduce:
+   /* yyn is the number of a rule to reduce with.  */
+   yylen = yyr2[yyn];
+   /* If YYLEN is nonzero, implement the default value of the action:
+      `$$ = $1'.
+      Otherwise, the following line sets YYVAL to garbage.
+      This behavior is undocumented and Bison
+      users should not rely upon it.  Assigning to YYVAL
+      unconditionally makes the parser a bit smaller, and it avoids a
+      GCC warning that YYVAL may be used uninitialized.  */
+   yyval = yyvsp[1-yylen];
+   YY_REDUCE_PRINT (yyn);
+   switch (yyn)
+     {
+         case 2:
+ #line 362 "parser.y"
+     {
+               resource_t *rsc;
+               /* First add stringtables to the resource-list */
+               rsc = build_stt_resources(sttres);
+               /* 'build_stt_resources' returns a head and $1 is a tail */
+               if(yyvsp[0].res)
+               {
+                       yyvsp[0].res->next = rsc;
+                       if(rsc)
+                               rsc->prev = yyvsp[0].res;
+               }
+               else
+                       yyvsp[0].res = rsc;
+               /* Find the tail again */
+               while(yyvsp[0].res && yyvsp[0].res->next)
+                       yyvsp[0].res = yyvsp[0].res->next;
+               /* Now add any fontdirecory */
+               rsc = build_fontdirs(yyvsp[0].res);
+               /* 'build_fontdir' returns a head and $1 is a tail */
+               if(yyvsp[0].res)
+               {
+                       yyvsp[0].res->next = rsc;
+                       if(rsc)
+                               rsc->prev = yyvsp[0].res;
+               }
+               else
+                       yyvsp[0].res = rsc;
+               /* Final statement before were done */
+               resource_top = get_resource_head(yyvsp[0].res);
+               ;}
+     break;
+   case 3:
+ #line 396 "parser.y"
+     { yyval.res = NULL; want_id = 1; ;}
+     break;
+   case 4:
+ #line 397 "parser.y"
+     {
+               if(yyvsp[0].res)
+               {
+                       resource_t *tail = yyvsp[0].res;
+                       resource_t *head = yyvsp[0].res;
+                       while(tail->next)
+                               tail = tail->next;
+                       while(head->prev)
+                               head = head->prev;
+                       head->prev = yyvsp[-1].res;
+                       if(yyvsp[-1].res)
+                               yyvsp[-1].res->next = head;
+                       yyval.res = tail;
+                       /* Check for duplicate identifiers */
+                       while(yyvsp[-1].res && head)
+                       {
+                               resource_t *rsc = yyvsp[-1].res;
+                               while(rsc)
+                               {
+                                       if(rsc->type == head->type
+                                       && rsc->lan->id == head->lan->id
+                                       && rsc->lan->sub == head->lan->sub
+                                       && !compare_name_id(rsc->name, head->name))
+                                       {
+                                               yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
+                                       }
+                                       rsc = rsc->prev;
+                               }
+                               head = head->next;
+                       }
+               }
+               else if(yyvsp[-1].res)
+               {
+                       resource_t *tail = yyvsp[-1].res;
+                       while(tail->next)
+                               tail = tail->next;
+                       yyval.res = tail;
+               }
+               else
+                       yyval.res = NULL;
+               if(!dont_want_id)       /* See comments in language parsing below */
+                       want_id = 1;
+               dont_want_id = 0;
+               ;}
+     break;
+   case 6:
+ #line 473 "parser.y"
+     {
+               yyval.res = yyvsp[0].res;
+               if(yyval.res)
+               {
+                       if(yyvsp[-2].num > 65535 || yyvsp[-2].num < -32768)
+                               yyerror("Resource's ID out of range (%d)", yyvsp[-2].num);
+                       yyval.res->name = new_name_id();
+                       yyval.res->name->type = name_ord;
+                       yyval.res->name->name.i_name = yyvsp[-2].num;
+                       chat("Got %s (%d)", get_typename(yyvsp[0].res), yyval.res->name->name.i_name);
+                       }
+                       ;}
+     break;
+   case 7:
+ #line 485 "parser.y"
+     {
+               yyval.res = yyvsp[0].res;
+               if(yyval.res)
+               {
+                       yyval.res->name = new_name_id();
+                       yyval.res->name->type = name_str;
+                       yyval.res->name->name.s_name = yyvsp[-2].str;
+                       chat("Got %s (%s)", get_typename(yyvsp[0].res), yyval.res->name->name.s_name->str.cstr);
+               }
+               ;}
+     break;
+   case 8:
+ #line 495 "parser.y"
+     {
+               /* Don't do anything, stringtables are converted to
+                * resource_t structures when we are finished parsing and
+                * the final rule of the parser is reduced (see above)
+                */
+               yyval.res = NULL;
+               chat("Got STRINGTABLE");
+               ;}
+     break;
+   case 9:
+ #line 503 "parser.y"
+     {want_nl = 1; ;}
+     break;
+   case 10:
+ #line 503 "parser.y"
+     {
+               /* We *NEED* the newline to delimit the expression.
+                * Otherwise, we would not be able to set the next
+                * want_id anymore because of the token-lookahead.
+                *
+                * However, we can test the lookahead-token for
+                * being "non-expression" type, in which case we
+                * continue. Fortunately, tNL is the only token that
+                * will break expression parsing and is implicitely
+                * void, so we just remove it. This scheme makes it
+                * possible to do some (not all) fancy preprocessor
+                * stuff.
+                * BTW, we also need to make sure that the next
+                * reduction of 'resources' above will *not* set
+                * want_id because we already have a lookahead that
+                * cannot be undone.
+                */
+               if(yychar != YYEMPTY && yychar != tNL)
+                       dont_want_id = 1;
+               if(yychar == tNL)
+                       yychar = YYEMPTY;       /* Could use 'yyclearin', but we already need the*/
+                                               /* direct access to yychar in rule 'usrcvt' below. */
+               else if(yychar == tIDENT)
+                       yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
+               want_nl = 0;    /* We don't want it anymore if we didn't get it */
+               if(!win32)
+                       yywarning("LANGUAGE not supported in 16-bit mode");
+               if(currentlanguage)
+                       free(currentlanguage);
+               if (get_language_codepage(yyvsp[-2].num, yyvsp[0].num) == -1)
+                       yyerror( "Language %04x is not supported", (yyvsp[0].num<<10) + yyvsp[-2].num);
+               currentlanguage = new_language(yyvsp[-2].num, yyvsp[0].num);
+               yyval.res = NULL;
+               chat("Got LANGUAGE %d,%d (0x%04x)", yyvsp[-2].num, yyvsp[0].num, (yyvsp[0].num<<10) + yyvsp[-2].num);
+               ;}
+     break;
+   case 11:
+ #line 547 "parser.y"
+     { yychar = rsrcid_to_token(yychar); ;}
+     break;
+   case 12:
+ #line 553 "parser.y"
+     {
+               if(yyvsp[0].num > 65535 || yyvsp[0].num < -32768)
+                       yyerror("Resource's ID out of range (%d)", yyvsp[0].num);
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_ord;
+               yyval.nid->name.i_name = yyvsp[0].num;
+               ;}
+     break;
+   case 13:
+ #line 560 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_str;
+               yyval.nid->name.s_name = yyvsp[0].str;
+               ;}
+     break;
+   case 14:
+ #line 570 "parser.y"
+     { yyval.nid = yyvsp[0].nid; ;}
+     break;
+   case 15:
+ #line 571 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_str;
+               yyval.nid->name.s_name = yyvsp[0].str;
+               ;}
+     break;
+   case 16:
+ #line 580 "parser.y"
+     { yyval.res = new_resource(res_acc, yyvsp[0].acc, yyvsp[0].acc->memopt, yyvsp[0].acc->lvc.language); ;}
+     break;
+   case 17:
+ #line 581 "parser.y"
+     { yyval.res = new_resource(res_bmp, yyvsp[0].bmp, yyvsp[0].bmp->memopt, yyvsp[0].bmp->data->lvc.language); ;}
+     break;
+   case 18:
+ #line 582 "parser.y"
+     {
+               resource_t *rsc;
+               if(yyvsp[0].ani->type == res_anicur)
+               {
+                       yyval.res = rsc = new_resource(res_anicur, yyvsp[0].ani->u.ani, yyvsp[0].ani->u.ani->memopt, yyvsp[0].ani->u.ani->data->lvc.language);
+               }
+               else if(yyvsp[0].ani->type == res_curg)
+               {
+                       cursor_t *cur;
+                       yyval.res = rsc = new_resource(res_curg, yyvsp[0].ani->u.curg, yyvsp[0].ani->u.curg->memopt, yyvsp[0].ani->u.curg->lvc.language);
+                       for(cur = yyvsp[0].ani->u.curg->cursorlist; cur; cur = cur->next)
+                       {
+                               rsc->prev = new_resource(res_cur, cur, yyvsp[0].ani->u.curg->memopt, yyvsp[0].ani->u.curg->lvc.language);
+                               rsc->prev->next = rsc;
+                               rsc = rsc->prev;
+                               rsc->name = new_name_id();
+                               rsc->name->type = name_ord;
+                               rsc->name->name.i_name = cur->id;
+                       }
+               }
+               else
+                       internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", yyvsp[0].ani->type);
+               free(yyvsp[0].ani);
+               ;}
+     break;
+   case 19:
+ #line 606 "parser.y"
+     { yyval.res = new_resource(res_dlg, yyvsp[0].dlg, yyvsp[0].dlg->memopt, yyvsp[0].dlg->lvc.language); ;}
+     break;
+   case 20:
+ #line 607 "parser.y"
+     {
+               if(win32)
+                       yyval.res = new_resource(res_dlgex, yyvsp[0].dlgex, yyvsp[0].dlgex->memopt, yyvsp[0].dlgex->lvc.language);
+               else
+                       yyval.res = NULL;
+               ;}
+     break;
+   case 21:
+ #line 613 "parser.y"
+     { yyval.res = new_resource(res_dlginit, yyvsp[0].dginit, yyvsp[0].dginit->memopt, yyvsp[0].dginit->data->lvc.language); ;}
+     break;
+   case 22:
+ #line 614 "parser.y"
+     { yyval.res = new_resource(res_fnt, yyvsp[0].fnt, yyvsp[0].fnt->memopt, yyvsp[0].fnt->data->lvc.language); ;}
+     break;
+   case 23:
+ #line 615 "parser.y"
+     { yyval.res = new_resource(res_fntdir, yyvsp[0].fnd, yyvsp[0].fnd->memopt, yyvsp[0].fnd->data->lvc.language); ;}
+     break;
+   case 24:
+ #line 616 "parser.y"
+     {
+               resource_t *rsc;
+               if(yyvsp[0].ani->type == res_aniico)
+               {
+                       yyval.res = rsc = new_resource(res_aniico, yyvsp[0].ani->u.ani, yyvsp[0].ani->u.ani->memopt, yyvsp[0].ani->u.ani->data->lvc.language);
+               }
+               else if(yyvsp[0].ani->type == res_icog)
+               {
+                       icon_t *ico;
+                       yyval.res = rsc = new_resource(res_icog, yyvsp[0].ani->u.icog, yyvsp[0].ani->u.icog->memopt, yyvsp[0].ani->u.icog->lvc.language);
+                       for(ico = yyvsp[0].ani->u.icog->iconlist; ico; ico = ico->next)
+                       {
+                               rsc->prev = new_resource(res_ico, ico, yyvsp[0].ani->u.icog->memopt, yyvsp[0].ani->u.icog->lvc.language);
+                               rsc->prev->next = rsc;
+                               rsc = rsc->prev;
+                               rsc->name = new_name_id();
+                               rsc->name->type = name_ord;
+                               rsc->name->name.i_name = ico->id;
+                       }
+               }
+               else
+                       internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", yyvsp[0].ani->type);
+               free(yyvsp[0].ani);
+               ;}
+     break;
+   case 25:
+ #line 640 "parser.y"
+     { yyval.res = new_resource(res_men, yyvsp[0].men, yyvsp[0].men->memopt, yyvsp[0].men->lvc.language); ;}
+     break;
+   case 26:
+ #line 641 "parser.y"
+     {
+               if(win32)
+                       yyval.res = new_resource(res_menex, yyvsp[0].menex, yyvsp[0].menex->memopt, yyvsp[0].menex->lvc.language);
+               else
+                       yyval.res = NULL;
+               ;}
+     break;
+   case 27:
+ #line 647 "parser.y"
+     { yyval.res = new_resource(res_msg, yyvsp[0].msg, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, yyvsp[0].msg->data->lvc.language); ;}
+     break;
+   case 28:
+ #line 648 "parser.y"
+     { yyval.res = new_resource(res_rdt, yyvsp[0].rdt, yyvsp[0].rdt->memopt, yyvsp[0].rdt->data->lvc.language); ;}
+     break;
+   case 29:
+ #line 649 "parser.y"
+     { yyval.res = new_resource(res_toolbar, yyvsp[0].tlbar, yyvsp[0].tlbar->memopt, yyvsp[0].tlbar->lvc.language); ;}
+     break;
+   case 30:
+ #line 650 "parser.y"
+     { yyval.res = new_resource(res_usr, yyvsp[0].usr, yyvsp[0].usr->memopt, yyvsp[0].usr->data->lvc.language); ;}
+     break;
+   case 31:
+ #line 651 "parser.y"
+     { yyval.res = new_resource(res_ver, yyvsp[0].veri, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, yyvsp[0].veri->lvc.language); ;}
+     break;
+   case 32:
+ #line 655 "parser.y"
+     { yyval.str = make_filename(yyvsp[0].str); ;}
+     break;
+   case 33:
+ #line 656 "parser.y"
+     { yyval.str = make_filename(yyvsp[0].str); ;}
+     break;
+   case 34:
+ #line 657 "parser.y"
+     { yyval.str = make_filename(yyvsp[0].str); ;}
+     break;
+   case 35:
+ #line 661 "parser.y"
+     { yyval.bmp = new_bitmap(yyvsp[0].raw, yyvsp[-1].iptr); ;}
+     break;
+   case 36:
+ #line 665 "parser.y"
+     {
+               yyval.ani = new_ani_any();
+               if(yyvsp[0].raw->size > 4 && !memcmp(yyvsp[0].raw->data, riff, sizeof(riff)))
+               {
+                       yyval.ani->type = res_anicur;
+                       yyval.ani->u.ani = new_ani_curico(res_anicur, yyvsp[0].raw, yyvsp[-1].iptr);
+               }
+               else
+               {
+                       yyval.ani->type = res_curg;
+                       yyval.ani->u.curg = new_cursor_group(yyvsp[0].raw, yyvsp[-1].iptr);
+               }
+       ;}
+     break;
+   case 37:
+ #line 681 "parser.y"
+     {
+               yyval.ani = new_ani_any();
+               if(yyvsp[0].raw->size > 4 && !memcmp(yyvsp[0].raw->data, riff, sizeof(riff)))
+               {
+                       yyval.ani->type = res_aniico;
+                       yyval.ani->u.ani = new_ani_curico(res_aniico, yyvsp[0].raw, yyvsp[-1].iptr);
+               }
+               else
+               {
+                       yyval.ani->type = res_icog;
+                       yyval.ani->u.icog = new_icon_group(yyvsp[0].raw, yyvsp[-1].iptr);
+               }
+       ;}
+     break;
+   case 38:
+ #line 703 "parser.y"
+     { yyval.fnt = new_font(yyvsp[0].raw, yyvsp[-1].iptr); ;}
+     break;
+   case 39:
+ #line 713 "parser.y"
+     { yyval.fnd = new_fontdir(yyvsp[0].raw, yyvsp[-1].iptr); ;}
+     break;
+   case 40:
+ #line 721 "parser.y"
+     {
+               if(!win32)
+                       yywarning("MESSAGETABLE not supported in 16-bit mode");
+               yyval.msg = new_messagetable(yyvsp[0].raw, yyvsp[-1].iptr);
+               ;}
+     break;
+   case 41:
+ #line 729 "parser.y"
+     { yyval.rdt = new_rcdata(yyvsp[0].raw, yyvsp[-1].iptr); ;}
+     break;
+   case 42:
+ #line 733 "parser.y"
+     { yyval.dginit = new_dlginit(yyvsp[0].raw, yyvsp[-1].iptr); ;}
+     break;
+   case 43:
+ #line 737 "parser.y"
+     {
+               #ifdef WORDS_BIGENDIAN
+                       if(pedantic && byteorder != WRC_BO_LITTLE)
+               #else
+                       if(pedantic && byteorder == WRC_BO_BIG)
+               #endif
+                               yywarning("Byteordering is not little-endian and type cannot be interpreted");
+                       yyval.usr = new_user(yyvsp[-2].nid, yyvsp[0].raw, yyvsp[-1].iptr);
+               ;}
+     break;
+   case 44:
+ #line 748 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_ord;
+               yyval.nid->name.i_name = yyvsp[0].num;
+               ;}
+     break;
+   case 45:
+ #line 753 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_str;
+               yyval.nid->name.s_name = yyvsp[0].str;
+               ;}
+     break;
+   case 46:
+ #line 762 "parser.y"
+     {
+               yyval.acc = new_accelerator();
+               if(yyvsp[-4].iptr)
+               {
+                       yyval.acc->memopt = *(yyvsp[-4].iptr);
+                       free(yyvsp[-4].iptr);
+               }
+               else
+               {
+                       yyval.acc->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
+               }
+               if(!yyvsp[-1].event)
+                       yyerror("Accelerator table must have at least one entry");
+               yyval.acc->events = get_event_head(yyvsp[-1].event);
+               if(yyvsp[-3].lvc)
+               {
+                       yyval.acc->lvc = *(yyvsp[-3].lvc);
+                       free(yyvsp[-3].lvc);
+               }
+               if(!yyval.acc->lvc.language)
+                       yyval.acc->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 47:
+ #line 786 "parser.y"
+     { yyval.event=NULL; ;}
+     break;
+   case 48:
+ #line 787 "parser.y"
+     { yyval.event=add_string_event(yyvsp[-3].str, yyvsp[-1].num, yyvsp[0].num, yyvsp[-4].event); ;}
+     break;
+   case 49:
+ #line 788 "parser.y"
+     { yyval.event=add_event(yyvsp[-3].num, yyvsp[-1].num, yyvsp[0].num, yyvsp[-4].event); ;}
+     break;
+   case 50:
+ #line 797 "parser.y"
+     { yyval.num = 0; ;}
+     break;
+   case 51:
+ #line 798 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+   case 52:
+ #line 801 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+   case 53:
+ #line 802 "parser.y"
+     { yyval.num = yyvsp[-2].num | yyvsp[0].num; ;}
+     break;
+   case 54:
+ #line 805 "parser.y"
+     { yyval.num = WRC_AF_NOINVERT; ;}
+     break;
+   case 55:
+ #line 806 "parser.y"
+     { yyval.num = WRC_AF_SHIFT; ;}
+     break;
+   case 56:
+ #line 807 "parser.y"
+     { yyval.num = WRC_AF_CONTROL; ;}
+     break;
+   case 57:
+ #line 808 "parser.y"
+     { yyval.num = WRC_AF_ALT; ;}
+     break;
+   case 58:
+ #line 809 "parser.y"
+     { yyval.num = WRC_AF_ASCII; ;}
+     break;
+   case 59:
+ #line 810 "parser.y"
+     { yyval.num = WRC_AF_VIRTKEY; ;}
+     break;
+   case 60:
+ #line 816 "parser.y"
+     {
+               if(yyvsp[-11].iptr)
+               {
+                       yyvsp[-3].dlg->memopt = *(yyvsp[-11].iptr);
+                       free(yyvsp[-11].iptr);
+               }
+               else
+                       yyvsp[-3].dlg->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               yyvsp[-3].dlg->x = yyvsp[-10].num;
+               yyvsp[-3].dlg->y = yyvsp[-8].num;
+               yyvsp[-3].dlg->width = yyvsp[-6].num;
+               yyvsp[-3].dlg->height = yyvsp[-4].num;
+               yyvsp[-3].dlg->controls = get_control_head(yyvsp[-1].ctl);
+               yyval.dlg = yyvsp[-3].dlg;
+               if(!yyval.dlg->gotstyle)
+               {
+                       yyval.dlg->style = new_style(0,0);
+                       yyval.dlg->style->or_mask = WS_POPUP;
+                       yyval.dlg->gotstyle = TRUE;
+               }
+               if(yyval.dlg->title)
+                       yyval.dlg->style->or_mask |= WS_CAPTION;
+               if(yyval.dlg->font)
+                       yyval.dlg->style->or_mask |= DS_SETFONT;
+               yyval.dlg->style->or_mask &= ~(yyval.dlg->style->and_mask);
+               yyval.dlg->style->and_mask = 0;
+               if(!yyval.dlg->lvc.language)
+                       yyval.dlg->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 61:
+ #line 850 "parser.y"
+     { yyval.dlg=new_dialog(); ;}
+     break;
+   case 62:
+ #line 851 "parser.y"
+     { yyval.dlg=dialog_style(yyvsp[0].style,yyvsp[-2].dlg); ;}
+     break;
+   case 63:
+ #line 852 "parser.y"
+     { yyval.dlg=dialog_exstyle(yyvsp[0].style,yyvsp[-2].dlg); ;}
+     break;
+   case 64:
+ #line 853 "parser.y"
+     { yyval.dlg=dialog_caption(yyvsp[0].str,yyvsp[-2].dlg); ;}
+     break;
+   case 65:
+ #line 854 "parser.y"
+     { yyval.dlg=dialog_font(yyvsp[0].fntid,yyvsp[-1].dlg); ;}
+     break;
+   case 66:
+ #line 855 "parser.y"
+     { yyval.dlg=dialog_class(yyvsp[0].nid,yyvsp[-2].dlg); ;}
+     break;
+   case 67:
+ #line 856 "parser.y"
+     { yyval.dlg=dialog_menu(yyvsp[0].nid,yyvsp[-2].dlg); ;}
+     break;
+   case 68:
+ #line 857 "parser.y"
+     { yyval.dlg=dialog_language(yyvsp[0].lan,yyvsp[-1].dlg); ;}
+     break;
+   case 69:
+ #line 858 "parser.y"
+     { yyval.dlg=dialog_characteristics(yyvsp[0].chars,yyvsp[-1].dlg); ;}
+     break;
+   case 70:
+ #line 859 "parser.y"
+     { yyval.dlg=dialog_version(yyvsp[0].ver,yyvsp[-1].dlg); ;}
+     break;
+   case 71:
+ #line 862 "parser.y"
+     { yyval.ctl = NULL; ;}
+     break;
+   case 72:
+ #line 863 "parser.y"
+     { yyval.ctl=ins_ctrl(-1, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 73:
+ #line 864 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_EDIT, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 74:
+ #line 865 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_LISTBOX, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 75:
+ #line 866 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_COMBOBOX, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 76:
+ #line 867 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_SCROLLBAR, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 77:
+ #line 868 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_CHECKBOX, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 78:
+ #line 869 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 79:
+ #line 870 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_GROUPBOX, yyvsp[0].ctl, yyvsp[-2].ctl);;}
+     break;
+   case 80:
+ #line 871 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 81:
+ #line 873 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 82:
+ #line 874 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 83:
+ #line 875 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_3STATE, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 84:
+ #line 876 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 85:
+ #line 877 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 86:
+ #line 878 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_LEFT, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 87:
+ #line 879 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_CENTER, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 88:
+ #line 880 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_RIGHT, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 89:
+ #line 882 "parser.y"
+     {
+               yyvsp[0].ctl->title = yyvsp[-7].nid;
+               yyvsp[0].ctl->id = yyvsp[-5].num;
+               yyvsp[0].ctl->x = yyvsp[-3].num;
+               yyvsp[0].ctl->y = yyvsp[-1].num;
+               yyval.ctl = ins_ctrl(CT_STATIC, SS_ICON, yyvsp[0].ctl, yyvsp[-9].ctl);
+               ;}
+     break;
+   case 90:
+ #line 892 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = new_name_id();
+               yyval.ctl->title->type = name_str;
+               yyval.ctl->title->name.s_name = yyvsp[-11].str;
+               yyval.ctl->id = yyvsp[-9].num;
+               yyval.ctl->x = yyvsp[-7].num;
+               yyval.ctl->y = yyvsp[-5].num;
+               yyval.ctl->width = yyvsp[-3].num;
+               yyval.ctl->height = yyvsp[-1].num;
+               if(yyvsp[0].style)
+               {
+                       yyval.ctl->style = yyvsp[0].style;
+                       yyval.ctl->gotstyle = TRUE;
+               }
+               ;}
+     break;
+   case 91:
+ #line 911 "parser.y"
+     {
+               yyval.ctl = new_control();
+               yyval.ctl->id = yyvsp[-9].num;
+               yyval.ctl->x = yyvsp[-7].num;
+               yyval.ctl->y = yyvsp[-5].num;
+               yyval.ctl->width = yyvsp[-3].num;
+               yyval.ctl->height = yyvsp[-1].num;
+               if(yyvsp[0].style)
+               {
+                       yyval.ctl->style = yyvsp[0].style;
+                       yyval.ctl->gotstyle = TRUE;
+               }
+               ;}
+     break;
+   case 92:
+ #line 927 "parser.y"
+     { yyval.ctl = new_control(); ;}
+     break;
+   case 93:
+ #line 929 "parser.y"
+     {
+               yyval.ctl = new_control();
+               yyval.ctl->width = yyvsp[-2].num;
+               yyval.ctl->height = yyvsp[0].num;
+               ;}
+     break;
+   case 94:
+ #line 934 "parser.y"
+     {
+               yyval.ctl = new_control();
+               yyval.ctl->width = yyvsp[-4].num;
+               yyval.ctl->height = yyvsp[-2].num;
+               yyval.ctl->style = yyvsp[0].style;
+               yyval.ctl->gotstyle = TRUE;
+               ;}
+     break;
+   case 95:
+ #line 941 "parser.y"
+     {
+               yyval.ctl = new_control();
+               yyval.ctl->width = yyvsp[-6].num;
+               yyval.ctl->height = yyvsp[-4].num;
+               yyval.ctl->style = yyvsp[-2].style;
+               yyval.ctl->gotstyle = TRUE;
+               yyval.ctl->exstyle = yyvsp[0].style;
+               yyval.ctl->gotexstyle = TRUE;
+               ;}
+     break;
+   case 96:
+ #line 952 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = yyvsp[-16].nid;
+               yyval.ctl->id = yyvsp[-14].num;
+               yyval.ctl->ctlclass = convert_ctlclass(yyvsp[-12].nid);
+               yyval.ctl->style = yyvsp[-10].style;
+               yyval.ctl->gotstyle = TRUE;
+               yyval.ctl->x = yyvsp[-8].num;
+               yyval.ctl->y = yyvsp[-6].num;
+               yyval.ctl->width = yyvsp[-4].num;
+               yyval.ctl->height = yyvsp[-2].num;
+               yyval.ctl->exstyle = yyvsp[0].style;
+               yyval.ctl->gotexstyle = TRUE;
+               ;}
+     break;
+   case 97:
+ #line 966 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = yyvsp[-14].nid;
+               yyval.ctl->id = yyvsp[-12].num;
+               yyval.ctl->ctlclass = convert_ctlclass(yyvsp[-10].nid);
+               yyval.ctl->style = yyvsp[-8].style;
+               yyval.ctl->gotstyle = TRUE;
+               yyval.ctl->x = yyvsp[-6].num;
+               yyval.ctl->y = yyvsp[-4].num;
+               yyval.ctl->width = yyvsp[-2].num;
+               yyval.ctl->height = yyvsp[0].num;
+               ;}
+     break;
+   case 98:
+ #line 981 "parser.y"
+     { yyval.fntid = new_font_id(yyvsp[-2].num, yyvsp[0].str, 0, 0); ;}
+     break;
+   case 99:
+ #line 986 "parser.y"
+     { yyval.style = NULL; ;}
+     break;
+   case 100:
+ #line 987 "parser.y"
+     { yyval.style = yyvsp[0].style; ;}
+     break;
+   case 101:
+ #line 991 "parser.y"
+     { yyval.styles = NULL; ;}
+     break;
+   case 102:
+ #line 992 "parser.y"
+     { yyval.styles = new_style_pair(yyvsp[0].style, 0); ;}
+     break;
+   case 103:
+ #line 993 "parser.y"
+     { yyval.styles = new_style_pair(yyvsp[-2].style, yyvsp[0].style); ;}
+     break;
+   case 104:
+ #line 997 "parser.y"
+     { yyval.style = new_style(yyvsp[-2].style->or_mask | yyvsp[0].style->or_mask, yyvsp[-2].style->and_mask | yyvsp[0].style->and_mask); free(yyvsp[-2].style); free(yyvsp[0].style);;}
+     break;
+   case 105:
+ #line 998 "parser.y"
+     { yyval.style = yyvsp[-1].style; ;}
+     break;
+   case 106:
+ #line 999 "parser.y"
+     { yyval.style = new_style(yyvsp[0].num, 0); ;}
+     break;
+   case 107:
+ #line 1000 "parser.y"
+     { yyval.style = new_style(0, yyvsp[0].num); ;}
+     break;
+   case 108:
+ #line 1004 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_ord;
+               yyval.nid->name.i_name = yyvsp[0].num;
+               ;}
+     break;
+   case 109:
+ #line 1009 "parser.y"
+     {
+               yyval.nid = new_name_id();
+               yyval.nid->type = name_str;
+               yyval.nid->name.s_name = yyvsp[0].str;
+               ;}
+     break;
+   case 110:
+ #line 1018 "parser.y"
+     {
+               if(!win32)
+                       yywarning("DIALOGEX not supported in 16-bit mode");
+               if(yyvsp[-12].iptr)
+               {
+                       yyvsp[-3].dlgex->memopt = *(yyvsp[-12].iptr);
+                       free(yyvsp[-12].iptr);
+               }
+               else
+                       yyvsp[-3].dlgex->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               yyvsp[-3].dlgex->x = yyvsp[-11].num;
+               yyvsp[-3].dlgex->y = yyvsp[-9].num;
+               yyvsp[-3].dlgex->width = yyvsp[-7].num;
+               yyvsp[-3].dlgex->height = yyvsp[-5].num;
+               if(yyvsp[-4].iptr)
+               {
+                       yyvsp[-3].dlgex->helpid = *(yyvsp[-4].iptr);
+                       yyvsp[-3].dlgex->gothelpid = TRUE;
+                       free(yyvsp[-4].iptr);
+               }
+               yyvsp[-3].dlgex->controls = get_control_head(yyvsp[-1].ctl);
+               yyval.dlgex = yyvsp[-3].dlgex;
+               assert(yyval.dlgex->style != NULL);
+               if(!yyval.dlgex->gotstyle)
+               {
+                       yyval.dlgex->style->or_mask = WS_POPUP;
+                       yyval.dlgex->gotstyle = TRUE;
+               }
+               if(yyval.dlgex->title)
+                       yyval.dlgex->style->or_mask |= WS_CAPTION;
+               if(yyval.dlgex->font)
+                       yyval.dlgex->style->or_mask |= DS_SETFONT;
+               yyval.dlgex->style->or_mask &= ~(yyval.dlgex->style->and_mask);
+               yyval.dlgex->style->and_mask = 0;
+               if(!yyval.dlgex->lvc.language)
+                       yyval.dlgex->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 111:
+ #line 1061 "parser.y"
+     { yyval.dlgex=new_dialogex(); ;}
+     break;
+   case 112:
+ #line 1062 "parser.y"
+     { yyval.dlgex=dialogex_style(yyvsp[0].style,yyvsp[-2].dlgex); ;}
+     break;
+   case 113:
+ #line 1063 "parser.y"
+     { yyval.dlgex=dialogex_exstyle(yyvsp[0].style,yyvsp[-2].dlgex); ;}
+     break;
+   case 114:
+ #line 1064 "parser.y"
+     { yyval.dlgex=dialogex_caption(yyvsp[0].str,yyvsp[-2].dlgex); ;}
+     break;
+   case 115:
+ #line 1065 "parser.y"
+     { yyval.dlgex=dialogex_font(yyvsp[0].fntid,yyvsp[-1].dlgex); ;}
+     break;
+   case 116:
+ #line 1066 "parser.y"
+     { yyval.dlgex=dialogex_font(yyvsp[0].fntid,yyvsp[-1].dlgex); ;}
+     break;
+   case 117:
+ #line 1067 "parser.y"
+     { yyval.dlgex=dialogex_class(yyvsp[0].nid,yyvsp[-2].dlgex); ;}
+     break;
+   case 118:
+ #line 1068 "parser.y"
+     { yyval.dlgex=dialogex_menu(yyvsp[0].nid,yyvsp[-2].dlgex); ;}
+     break;
+   case 119:
+ #line 1069 "parser.y"
+     { yyval.dlgex=dialogex_language(yyvsp[0].lan,yyvsp[-1].dlgex); ;}
+     break;
+   case 120:
+ #line 1070 "parser.y"
+     { yyval.dlgex=dialogex_characteristics(yyvsp[0].chars,yyvsp[-1].dlgex); ;}
+     break;
+   case 121:
+ #line 1071 "parser.y"
+     { yyval.dlgex=dialogex_version(yyvsp[0].ver,yyvsp[-1].dlgex); ;}
+     break;
+   case 122:
+ #line 1074 "parser.y"
+     { yyval.ctl = NULL; ;}
+     break;
+   case 123:
+ #line 1075 "parser.y"
+     { yyval.ctl=ins_ctrl(-1, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 124:
+ #line 1076 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_EDIT, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 125:
+ #line 1077 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_LISTBOX, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 126:
+ #line 1078 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_COMBOBOX, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 127:
+ #line 1079 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_SCROLLBAR, 0, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 128:
+ #line 1080 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_CHECKBOX, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 129:
+ #line 1081 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 130:
+ #line 1082 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_GROUPBOX, yyvsp[0].ctl, yyvsp[-2].ctl);;}
+     break;
+   case 131:
+ #line 1083 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 132:
+ #line 1085 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 133:
+ #line 1086 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 134:
+ #line 1087 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_3STATE, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 135:
+ #line 1088 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 136:
+ #line 1089 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 137:
+ #line 1090 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_LEFT, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 138:
+ #line 1091 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_CENTER, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 139:
+ #line 1092 "parser.y"
+     { yyval.ctl=ins_ctrl(CT_STATIC, SS_RIGHT, yyvsp[0].ctl, yyvsp[-2].ctl); ;}
+     break;
+   case 140:
+ #line 1094 "parser.y"
+     {
+               yyvsp[0].ctl->title = yyvsp[-7].nid;
+               yyvsp[0].ctl->id = yyvsp[-5].num;
+               yyvsp[0].ctl->x = yyvsp[-3].num;
+               yyvsp[0].ctl->y = yyvsp[-1].num;
+               yyval.ctl = ins_ctrl(CT_STATIC, SS_ICON, yyvsp[0].ctl, yyvsp[-9].ctl);
+               ;}
+     break;
+   case 141:
+ #line 1105 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = yyvsp[-18].nid;
+               yyval.ctl->id = yyvsp[-16].num;
+               yyval.ctl->ctlclass = convert_ctlclass(yyvsp[-14].nid);
+               yyval.ctl->style = yyvsp[-12].style;
+               yyval.ctl->gotstyle = TRUE;
+               yyval.ctl->x = yyvsp[-10].num;
+               yyval.ctl->y = yyvsp[-8].num;
+               yyval.ctl->width = yyvsp[-6].num;
+               yyval.ctl->height = yyvsp[-4].num;
+               if(yyvsp[-2].style)
+               {
+                       yyval.ctl->exstyle = yyvsp[-2].style;
+                       yyval.ctl->gotexstyle = TRUE;
+               }
+               if(yyvsp[-1].iptr)
+               {
+                       yyval.ctl->helpid = *(yyvsp[-1].iptr);
+                       yyval.ctl->gothelpid = TRUE;
+                       free(yyvsp[-1].iptr);
+               }
+               yyval.ctl->extra = yyvsp[0].raw;
+               ;}
+     break;
+   case 142:
+ #line 1129 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = yyvsp[-15].nid;
+               yyval.ctl->id = yyvsp[-13].num;
+               yyval.ctl->style = yyvsp[-9].style;
+               yyval.ctl->gotstyle = TRUE;
+               yyval.ctl->ctlclass = convert_ctlclass(yyvsp[-11].nid);
+               yyval.ctl->x = yyvsp[-7].num;
+               yyval.ctl->y = yyvsp[-5].num;
+               yyval.ctl->width = yyvsp[-3].num;
+               yyval.ctl->height = yyvsp[-1].num;
+               yyval.ctl->extra = yyvsp[0].raw;
+               ;}
+     break;
+   case 143:
+ #line 1145 "parser.y"
+     {
+               yyval.ctl=new_control();
+               yyval.ctl->title = new_name_id();
+               yyval.ctl->title->type = name_str;
+               yyval.ctl->title->name.s_name = yyvsp[-13].str;
+               yyval.ctl->id = yyvsp[-11].num;
+               yyval.ctl->x = yyvsp[-9].num;
+               yyval.ctl->y = yyvsp[-7].num;
+               yyval.ctl->width = yyvsp[-5].num;
+               yyval.ctl->height = yyvsp[-3].num;
+               if(yyvsp[-2].styles)
+               {
+                       yyval.ctl->style = yyvsp[-2].styles->style;
+                       yyval.ctl->gotstyle = TRUE;
+                       if (yyvsp[-2].styles->exstyle)
+                       {
+                           yyval.ctl->exstyle = yyvsp[-2].styles->exstyle;
+                           yyval.ctl->gotexstyle = TRUE;
+                       }
+                       free(yyvsp[-2].styles);
+               }
+               yyval.ctl->extra = yyvsp[0].raw;
+               ;}
+     break;
+   case 144:
+ #line 1173 "parser.y"
+     {
+               yyval.ctl = new_control();
+               yyval.ctl->id = yyvsp[-11].num;
+               yyval.ctl->x = yyvsp[-9].num;
+               yyval.ctl->y = yyvsp[-7].num;
+               yyval.ctl->width = yyvsp[-5].num;
+               yyval.ctl->height = yyvsp[-3].num;
+               if(yyvsp[-2].styles)
+               {
+                       yyval.ctl->style = yyvsp[-2].styles->style;
+                       yyval.ctl->gotstyle = TRUE;
+                       if (yyvsp[-2].styles->exstyle)
+                       {
+                           yyval.ctl->exstyle = yyvsp[-2].styles->exstyle;
+                           yyval.ctl->gotexstyle = TRUE;
+                       }
+                       free(yyvsp[-2].styles);
+               }
+               yyval.ctl->extra = yyvsp[0].raw;
+               ;}
+     break;
+   case 145:
+ #line 1196 "parser.y"
+     { yyval.raw = NULL; ;}
+     break;
+   case 146:
+ #line 1197 "parser.y"
+     { yyval.raw = yyvsp[0].raw; ;}
+     break;
+   case 147:
+ #line 1200 "parser.y"
+     { yyval.iptr = NULL; ;}
+     break;
+   case 148:
+ #line 1201 "parser.y"
+     { yyval.iptr = new_int(yyvsp[0].num); ;}
+     break;
+   case 149:
+ #line 1205 "parser.y"
+     { yyval.fntid = new_font_id(yyvsp[-7].num, yyvsp[-5].str, yyvsp[-3].num, yyvsp[-1].num); ;}
+     break;
+   case 150:
+ #line 1212 "parser.y"
+     { yyval.fntid = NULL; ;}
+     break;
+   case 151:
+ #line 1213 "parser.y"
+     { yyval.fntid = NULL; ;}
+     break;
+   case 152:
+ #line 1217 "parser.y"
+     {
+               if(!yyvsp[0].menitm)
+                       yyerror("Menu must contain items");
+               yyval.men = new_menu();
+               if(yyvsp[-2].iptr)
+               {
+                       yyval.men->memopt = *(yyvsp[-2].iptr);
+                       free(yyvsp[-2].iptr);
+               }
+               else
+                       yyval.men->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               yyval.men->items = get_item_head(yyvsp[0].menitm);
+               if(yyvsp[-1].lvc)
+               {
+                       yyval.men->lvc = *(yyvsp[-1].lvc);
+                       free(yyvsp[-1].lvc);
+               }
+               if(!yyval.men->lvc.language)
+                       yyval.men->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 153:
+ #line 1240 "parser.y"
+     { yyval.menitm = yyvsp[-1].menitm; ;}
+     break;
+   case 154:
+ #line 1244 "parser.y"
+     {yyval.menitm = NULL;;}
+     break;
+   case 155:
+ #line 1245 "parser.y"
+     {
+               yyval.menitm=new_menu_item();
+               yyval.menitm->prev = yyvsp[-5].menitm;
+               if(yyvsp[-5].menitm)
+                       yyvsp[-5].menitm->next = yyval.menitm;
+               yyval.menitm->id =  yyvsp[-1].num;
+               yyval.menitm->state = yyvsp[0].num;
+               yyval.menitm->name = yyvsp[-3].str;
+               ;}
+     break;
+   case 156:
+ #line 1254 "parser.y"
+     {
+               yyval.menitm=new_menu_item();
+               yyval.menitm->prev = yyvsp[-2].menitm;
+               if(yyvsp[-2].menitm)
+                       yyvsp[-2].menitm->next = yyval.menitm;
+               ;}
+     break;
+   case 157:
+ #line 1260 "parser.y"
+     {
+               yyval.menitm = new_menu_item();
+               yyval.menitm->prev = yyvsp[-4].menitm;
+               if(yyvsp[-4].menitm)
+                       yyvsp[-4].menitm->next = yyval.menitm;
+               yyval.menitm->popup = get_item_head(yyvsp[0].menitm);
+               yyval.menitm->name = yyvsp[-2].str;
+               ;}
+     break;
+   case 158:
+ #line 1279 "parser.y"
+     { yyval.num = 0; ;}
+     break;
+   case 159:
+ #line 1280 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_CHECKED; ;}
+     break;
+   case 160:
+ #line 1281 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_GRAYED; ;}
+     break;
+   case 161:
+ #line 1282 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_HELP; ;}
+     break;
+   case 162:
+ #line 1283 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_DISABLED; ;}
+     break;
+   case 163:
+ #line 1284 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_MENUBARBREAK; ;}
+     break;
+   case 164:
+ #line 1285 "parser.y"
+     { yyval.num = yyvsp[0].num | MF_MENUBREAK; ;}
+     break;
+   case 165:
+ #line 1289 "parser.y"
+     {
+               if(!win32)
+                       yywarning("MENUEX not supported in 16-bit mode");
+               if(!yyvsp[0].menexitm)
+                       yyerror("MenuEx must contain items");
+               yyval.menex = new_menuex();
+               if(yyvsp[-2].iptr)
+               {
+                       yyval.menex->memopt = *(yyvsp[-2].iptr);
+                       free(yyvsp[-2].iptr);
+               }
+               else
+                       yyval.menex->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
+               yyval.menex->items = get_itemex_head(yyvsp[0].menexitm);
+               if(yyvsp[-1].lvc)
+               {
+                       yyval.menex->lvc = *(yyvsp[-1].lvc);
+                       free(yyvsp[-1].lvc);
+               }
+               if(!yyval.menex->lvc.language)
+                       yyval.menex->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 166:
+ #line 1314 "parser.y"
+     { yyval.menexitm = yyvsp[-1].menexitm; ;}
+     break;
+   case 167:
+ #line 1318 "parser.y"
+     {yyval.menexitm = NULL; ;}
+     break;
+   case 168:
+ #line 1319 "parser.y"
+     {
+               yyval.menexitm = new_menuex_item();
+               yyval.menexitm->prev = yyvsp[-3].menexitm;
+               if(yyvsp[-3].menexitm)
+                       yyvsp[-3].menexitm->next = yyval.menexitm;
+               yyval.menexitm->name = yyvsp[-1].str;
+               yyval.menexitm->id = yyvsp[0].exopt->id;
+               yyval.menexitm->type = yyvsp[0].exopt->type;
+               yyval.menexitm->state = yyvsp[0].exopt->state;
+               yyval.menexitm->helpid = yyvsp[0].exopt->helpid;
+               yyval.menexitm->gotid = yyvsp[0].exopt->gotid;
+               yyval.menexitm->gottype = yyvsp[0].exopt->gottype;
+               yyval.menexitm->gotstate = yyvsp[0].exopt->gotstate;
+               yyval.menexitm->gothelpid = yyvsp[0].exopt->gothelpid;
+               free(yyvsp[0].exopt);
+               ;}
+     break;
+   case 169:
+ #line 1335 "parser.y"
+     {
+               yyval.menexitm = new_menuex_item();
+               yyval.menexitm->prev = yyvsp[-2].menexitm;
+               if(yyvsp[-2].menexitm)
+                       yyvsp[-2].menexitm->next = yyval.menexitm;
+               ;}
+     break;
+   case 170:
+ #line 1341 "parser.y"
+     {
+               yyval.menexitm = new_menuex_item();
+               yyval.menexitm->prev = yyvsp[-4].menexitm;
+               if(yyvsp[-4].menexitm)
+                       yyvsp[-4].menexitm->next = yyval.menexitm;
+               yyval.menexitm->popup = get_itemex_head(yyvsp[0].menexitm);
+               yyval.menexitm->name = yyvsp[-2].str;
+               yyval.menexitm->id = yyvsp[-1].exopt->id;
+               yyval.menexitm->type = yyvsp[-1].exopt->type;
+               yyval.menexitm->state = yyvsp[-1].exopt->state;
+               yyval.menexitm->helpid = yyvsp[-1].exopt->helpid;
+               yyval.menexitm->gotid = yyvsp[-1].exopt->gotid;
+               yyval.menexitm->gottype = yyvsp[-1].exopt->gottype;
+               yyval.menexitm->gotstate = yyvsp[-1].exopt->gotstate;
+               yyval.menexitm->gothelpid = yyvsp[-1].exopt->gothelpid;
+               free(yyvsp[-1].exopt);
+               ;}
+     break;
+   case 171:
+ #line 1361 "parser.y"
+     { yyval.exopt = new_itemex_opt(0, 0, 0, 0); ;}
+     break;
+   case 172:
+ #line 1362 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[0].num, 0, 0, 0);
+               yyval.exopt->gotid = TRUE;
+               ;}
+     break;
+   case 173:
+ #line 1366 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[-3].iptr ? *(yyvsp[-3].iptr) : 0, yyvsp[-1].iptr ? *(yyvsp[-1].iptr) : 0, yyvsp[0].num, 0);
+               yyval.exopt->gotid = TRUE;
+               yyval.exopt->gottype = TRUE;
+               yyval.exopt->gotstate = TRUE;
+               if(yyvsp[-3].iptr) free(yyvsp[-3].iptr);
+               if(yyvsp[-1].iptr) free(yyvsp[-1].iptr);
+               ;}
+     break;
+   case 174:
+ #line 1374 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[-4].iptr ? *(yyvsp[-4].iptr) : 0, yyvsp[-2].iptr ? *(yyvsp[-2].iptr) : 0, yyvsp[0].num, 0);
+               yyval.exopt->gotid = TRUE;
+               yyval.exopt->gottype = TRUE;
+               yyval.exopt->gotstate = TRUE;
+               if(yyvsp[-4].iptr) free(yyvsp[-4].iptr);
+               if(yyvsp[-2].iptr) free(yyvsp[-2].iptr);
+               ;}
+     break;
+   case 175:
+ #line 1385 "parser.y"
+     { yyval.exopt = new_itemex_opt(0, 0, 0, 0); ;}
+     break;
+   case 176:
+ #line 1386 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[0].num, 0, 0, 0);
+               yyval.exopt->gotid = TRUE;
+               ;}
+     break;
+   case 177:
+ #line 1390 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[-2].iptr ? *(yyvsp[-2].iptr) : 0, yyvsp[0].num, 0, 0);
+               if(yyvsp[-2].iptr) free(yyvsp[-2].iptr);
+               yyval.exopt->gotid = TRUE;
+               yyval.exopt->gottype = TRUE;
+               ;}
+     break;
+   case 178:
+ #line 1396 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[-4].iptr ? *(yyvsp[-4].iptr) : 0, yyvsp[-2].iptr ? *(yyvsp[-2].iptr) : 0, yyvsp[0].num, 0);
+               if(yyvsp[-4].iptr) free(yyvsp[-4].iptr);
+               if(yyvsp[-2].iptr) free(yyvsp[-2].iptr);
+               yyval.exopt->gotid = TRUE;
+               yyval.exopt->gottype = TRUE;
+               yyval.exopt->gotstate = TRUE;
+               ;}
+     break;
+   case 179:
+ #line 1404 "parser.y"
+     {
+               yyval.exopt = new_itemex_opt(yyvsp[-6].iptr ? *(yyvsp[-6].iptr) : 0, yyvsp[-4].iptr ? *(yyvsp[-4].iptr) : 0, yyvsp[-2].iptr ? *(yyvsp[-2].iptr) : 0, yyvsp[0].num);
+               if(yyvsp[-6].iptr) free(yyvsp[-6].iptr);
+               if(yyvsp[-4].iptr) free(yyvsp[-4].iptr);
+               if(yyvsp[-2].iptr) free(yyvsp[-2].iptr);
+               yyval.exopt->gotid = TRUE;
+               yyval.exopt->gottype = TRUE;
+               yyval.exopt->gotstate = TRUE;
+               yyval.exopt->gothelpid = TRUE;
+               ;}
+     break;
+   case 180:
+ #line 1424 "parser.y"
+     {
+               if(!yyvsp[-1].stt)
+               {
+                       yyerror("Stringtable must have at least one entry");
+               }
+               else
+               {
+                       stringtable_t *stt;
+                       /* Check if we added to a language table or created
+                        * a new one.
+                        */
+                        for(stt = sttres; stt; stt = stt->next)
+                        {
+                               if(stt == tagstt)
+                                       break;
+                        }
+                        if(!stt)
+                        {
+                               /* It is a new one */
+                               if(sttres)
+                               {
+                                       sttres->prev = tagstt;
+                                       tagstt->next = sttres;
+                                       sttres = tagstt;
+                               }
+                               else
+                                       sttres = tagstt;
+                        }
+                        /* Else were done */
+               }
+               if(tagstt_memopt)
+               {
+                       free(tagstt_memopt);
+                       tagstt_memopt = NULL;
+               }
+               yyval.stt = tagstt;
+               ;}
+     break;
+   case 181:
+ #line 1465 "parser.y"
+     {
+               if((tagstt = find_stringtable(yyvsp[0].lvc)) == NULL)
+                       tagstt = new_stringtable(yyvsp[0].lvc);
+               tagstt_memopt = yyvsp[-1].iptr;
+               tagstt_version = yyvsp[0].lvc->version;
+               tagstt_characts = yyvsp[0].lvc->characts;
+               if(yyvsp[0].lvc)
+                       free(yyvsp[0].lvc);
+               ;}
+     break;
+   case 182:
+ #line 1476 "parser.y"
+     { yyval.stt = NULL; ;}
+     break;
+   case 183:
+ #line 1477 "parser.y"
+     {
+               int i;
+               assert(tagstt != NULL);
+               if(yyvsp[-2].num > 65535 || yyvsp[-2].num < -32768)
+                       yyerror("Stringtable entry's ID out of range (%d)", yyvsp[-2].num);
+               /* Search for the ID */
+               for(i = 0; i < tagstt->nentries; i++)
+               {
+                       if(tagstt->entries[i].id == yyvsp[-2].num)
+                               yyerror("Stringtable ID %d already in use", yyvsp[-2].num);
+               }
+               /* If we get here, then we have a new unique entry */
+               tagstt->nentries++;
+               tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
+               tagstt->entries[tagstt->nentries-1].id = yyvsp[-2].num;
+               tagstt->entries[tagstt->nentries-1].str = yyvsp[0].str;
+               if(tagstt_memopt)
+                       tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
+               else
+                       tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
+               tagstt->entries[tagstt->nentries-1].version = tagstt_version;
+               tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
+               if(pedantic && !yyvsp[0].str->size)
+                       yywarning("Zero length strings make no sense");
+               if(!win32 && yyvsp[0].str->size > 254)
+                       yyerror("Stringtable entry more than 254 characters");
+               if(win32 && yyvsp[0].str->size > 65534) /* Hmm..., does this happen? */
+                       yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
+               yyval.stt = tagstt;
+               ;}
+     break;
+   case 186:
+ #line 1517 "parser.y"
+     {
+               yyval.veri = yyvsp[-3].veri;
+               if(yyvsp[-4].iptr)
+               {
+                       yyval.veri->memopt = *(yyvsp[-4].iptr);
+                       free(yyvsp[-4].iptr);
+               }
+               else
+                       yyval.veri->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
+               yyval.veri->blocks = get_ver_block_head(yyvsp[-1].blk);
+               /* Set language; there is no version or characteristics */
+               yyval.veri->lvc.language = dup_language(currentlanguage);
+               ;}
+     break;
+   case 187:
+ #line 1533 "parser.y"
+     { yyval.veri = new_versioninfo(); ;}
+     break;
+   case 188:
+ #line 1534 "parser.y"
+     {
+               if(yyvsp[-8].veri->gotit.fv)
+                       yyerror("FILEVERSION already defined");
+               yyval.veri = yyvsp[-8].veri;
+               yyval.veri->filever_maj1 = yyvsp[-6].num;
+               yyval.veri->filever_maj2 = yyvsp[-4].num;
+               yyval.veri->filever_min1 = yyvsp[-2].num;
+               yyval.veri->filever_min2 = yyvsp[0].num;
+               yyval.veri->gotit.fv = 1;
+               ;}
+     break;
+   case 189:
+ #line 1544 "parser.y"
+     {
+               if(yyvsp[-8].veri->gotit.pv)
+                       yyerror("PRODUCTVERSION already defined");
+               yyval.veri = yyvsp[-8].veri;
+               yyval.veri->prodver_maj1 = yyvsp[-6].num;
+               yyval.veri->prodver_maj2 = yyvsp[-4].num;
+               yyval.veri->prodver_min1 = yyvsp[-2].num;
+               yyval.veri->prodver_min2 = yyvsp[0].num;
+               yyval.veri->gotit.pv = 1;
+               ;}
+     break;
+   case 190:
+ #line 1554 "parser.y"
+     {
+               if(yyvsp[-2].veri->gotit.ff)
+                       yyerror("FILEFLAGS already defined");
+               yyval.veri = yyvsp[-2].veri;
+               yyval.veri->fileflags = yyvsp[0].num;
+               yyval.veri->gotit.ff = 1;
+               ;}
+     break;
+   case 191:
+ #line 1561 "parser.y"
+     {
+               if(yyvsp[-2].veri->gotit.ffm)
+                       yyerror("FILEFLAGSMASK already defined");
+               yyval.veri = yyvsp[-2].veri;
+               yyval.veri->fileflagsmask = yyvsp[0].num;
+               yyval.veri->gotit.ffm = 1;
+               ;}
+     break;
+   case 192:
+ #line 1568 "parser.y"
+     {
+               if(yyvsp[-2].veri->gotit.fo)
+                       yyerror("FILEOS already defined");
+               yyval.veri = yyvsp[-2].veri;
+               yyval.veri->fileos = yyvsp[0].num;
+               yyval.veri->gotit.fo = 1;
+               ;}
+     break;
+   case 193:
+ #line 1575 "parser.y"
+     {
+               if(yyvsp[-2].veri->gotit.ft)
+                       yyerror("FILETYPE already defined");
+               yyval.veri = yyvsp[-2].veri;
+               yyval.veri->filetype = yyvsp[0].num;
+               yyval.veri->gotit.ft = 1;
+               ;}
+     break;
+   case 194:
+ #line 1582 "parser.y"
+     {
+               if(yyvsp[-2].veri->gotit.fst)
+                       yyerror("FILESUBTYPE already defined");
+               yyval.veri = yyvsp[-2].veri;
+               yyval.veri->filesubtype = yyvsp[0].num;
+               yyval.veri->gotit.fst = 1;
+               ;}
+     break;
+   case 195:
+ #line 1592 "parser.y"
+     { yyval.blk = NULL; ;}
+     break;
+   case 196:
+ #line 1593 "parser.y"
+     {
+               yyval.blk = yyvsp[0].blk;
+               yyval.blk->prev = yyvsp[-1].blk;
+               if(yyvsp[-1].blk)
+                       yyvsp[-1].blk->next = yyval.blk;
+               ;}
+     break;
+   case 197:
+ #line 1602 "parser.y"
+     {
+               yyval.blk = new_ver_block();
+               yyval.blk->name = yyvsp[-3].str;
+               yyval.blk->values = get_ver_value_head(yyvsp[-1].val);
+               ;}
+     break;
+   case 198:
+ #line 1610 "parser.y"
+     { yyval.val = NULL; ;}
+     break;
+   case 199:
+ #line 1611 "parser.y"
+     {
+               yyval.val = yyvsp[0].val;
+               yyval.val->prev = yyvsp[-1].val;
+               if(yyvsp[-1].val)
+                       yyvsp[-1].val->next = yyval.val;
+               ;}
+     break;
+   case 200:
+ #line 1620 "parser.y"
+     {
+               yyval.val = new_ver_value();
+               yyval.val->type = val_block;
+               yyval.val->value.block = yyvsp[0].blk;
+               ;}
+     break;
+   case 201:
+ #line 1625 "parser.y"
+     {
+               yyval.val = new_ver_value();
+               yyval.val->type = val_str;
+               yyval.val->key = yyvsp[-2].str;
+               yyval.val->value.str = yyvsp[0].str;
+               ;}
+     break;
+   case 202:
+ #line 1631 "parser.y"
+     {
+               yyval.val = new_ver_value();
+               yyval.val->type = val_words;
+               yyval.val->key = yyvsp[-2].str;
+               yyval.val->value.words = yyvsp[0].verw;
+               ;}
+     break;
+   case 203:
+ #line 1640 "parser.y"
+     { yyval.verw = new_ver_words(yyvsp[0].num); ;}
+     break;
+   case 204:
+ #line 1641 "parser.y"
+     { yyval.verw = add_ver_words(yyvsp[-2].verw, yyvsp[0].num); ;}
+     break;
+   case 205:
+ #line 1645 "parser.y"
+     {
+               int nitems;
+               toolbar_item_t *items = get_tlbr_buttons_head(yyvsp[-1].tlbarItems, &nitems);
+               yyval.tlbar = new_toolbar(yyvsp[-6].num, yyvsp[-4].num, items, nitems);
+               if(yyvsp[-7].iptr)
+               {
+                       yyval.tlbar->memopt = *(yyvsp[-7].iptr);
+                       free(yyvsp[-7].iptr);
+               }
+               else
+               {
+                       yyval.tlbar->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
+               }
+               if(yyvsp[-3].lvc)
+               {
+                       yyval.tlbar->lvc = *(yyvsp[-3].lvc);
+                       free(yyvsp[-3].lvc);
+               }
+               if(!yyval.tlbar->lvc.language)
+               {
+                       yyval.tlbar->lvc.language = dup_language(currentlanguage);
+               }
+               ;}
+     break;
+   case 206:
+ #line 1671 "parser.y"
+     { yyval.tlbarItems = NULL; ;}
+     break;
+   case 207:
+ #line 1672 "parser.y"
+     {
+               toolbar_item_t *idrec = new_toolbar_item();
+               idrec->id = yyvsp[0].num;
+               yyval.tlbarItems = ins_tlbr_button(yyvsp[-2].tlbarItems, idrec);
+               ;}
+     break;
+   case 208:
+ #line 1677 "parser.y"
+     {
+               toolbar_item_t *idrec = new_toolbar_item();
+               idrec->id = 0;
+               yyval.tlbarItems = ins_tlbr_button(yyvsp[-1].tlbarItems, idrec);
+       ;}
+     break;
+   case 209:
+ #line 1686 "parser.y"
+     { yyval.iptr = NULL; ;}
+     break;
+   case 210:
+ #line 1687 "parser.y"
+     {
+               if(yyvsp[-1].iptr)
+               {
+                       *(yyvsp[-1].iptr) |= *(yyvsp[0].iptr);
+                       yyval.iptr = yyvsp[-1].iptr;
+                       free(yyvsp[0].iptr);
+               }
+               else
+                       yyval.iptr = yyvsp[0].iptr;
+               ;}
+     break;
+   case 211:
+ #line 1697 "parser.y"
+     {
+               if(yyvsp[-1].iptr)
+               {
+                       *(yyvsp[-1].iptr) &= *(yyvsp[0].iptr);
+                       yyval.iptr = yyvsp[-1].iptr;
+                       free(yyvsp[0].iptr);
+               }
+               else
+               {
+                       *yyvsp[0].iptr &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
+                       yyval.iptr = yyvsp[0].iptr;
+               }
+               ;}
+     break;
+   case 212:
+ #line 1712 "parser.y"
+     { yyval.iptr = new_int(WRC_MO_PRELOAD); ;}
+     break;
+   case 213:
+ #line 1713 "parser.y"
+     { yyval.iptr = new_int(WRC_MO_MOVEABLE); ;}
+     break;
+   case 214:
+ #line 1714 "parser.y"
+     { yyval.iptr = new_int(WRC_MO_DISCARDABLE); ;}
+     break;
+   case 215:
+ #line 1715 "parser.y"
+     { yyval.iptr = new_int(WRC_MO_PURE); ;}
+     break;
+   case 216:
+ #line 1718 "parser.y"
+     { yyval.iptr = new_int(~WRC_MO_PRELOAD); ;}
+     break;
+   case 217:
+ #line 1719 "parser.y"
+     { yyval.iptr = new_int(~WRC_MO_MOVEABLE); ;}
+     break;
+   case 218:
+ #line 1720 "parser.y"
+     { yyval.iptr = new_int(~WRC_MO_PURE); ;}
+     break;
+   case 219:
+ #line 1724 "parser.y"
+     { yyval.lvc = new_lvc(); ;}
+     break;
+   case 220:
+ #line 1725 "parser.y"
+     {
+               if(!win32)
+                       yywarning("LANGUAGE not supported in 16-bit mode");
+               if(yyvsp[-1].lvc->language)
+                       yyerror("Language already defined");
+               yyval.lvc = yyvsp[-1].lvc;
+               yyvsp[-1].lvc->language = yyvsp[0].lan;
+               ;}
+     break;
+   case 221:
+ #line 1733 "parser.y"
+     {
+               if(!win32)
+                       yywarning("CHARACTERISTICS not supported in 16-bit mode");
+               if(yyvsp[-1].lvc->characts)
+                       yyerror("Characteristics already defined");
+               yyval.lvc = yyvsp[-1].lvc;
+               yyvsp[-1].lvc->characts = yyvsp[0].chars;
+               ;}
+     break;
+   case 222:
+ #line 1741 "parser.y"
+     {
+               if(!win32)
+                       yywarning("VERSION not supported in 16-bit mode");
+               if(yyvsp[-1].lvc->version)
+                       yyerror("Version already defined");
+               yyval.lvc = yyvsp[-1].lvc;
+               yyvsp[-1].lvc->version = yyvsp[0].ver;
+               ;}
+     break;
+   case 223:
+ #line 1759 "parser.y"
+     { yyval.lan = new_language(yyvsp[-2].num, yyvsp[0].num);
+                                         if (get_language_codepage(yyvsp[-2].num, yyvsp[0].num) == -1)
+                                               yyerror( "Language %04x is not supported", (yyvsp[0].num<<10) + yyvsp[-2].num);
+                                       ;}
+     break;
+   case 224:
+ #line 1766 "parser.y"
+     { yyval.chars = new_characts(yyvsp[0].num); ;}
+     break;
+   case 225:
+ #line 1770 "parser.y"
+     { yyval.ver = new_version(yyvsp[0].num); ;}
+     break;
+   case 226:
+ #line 1774 "parser.y"
+     {
+               if(yyvsp[-3].lvc)
+               {
+                       yyvsp[-1].raw->lvc = *(yyvsp[-3].lvc);
+                       free(yyvsp[-3].lvc);
+               }
+               if(!yyvsp[-1].raw->lvc.language)
+                       yyvsp[-1].raw->lvc.language = dup_language(currentlanguage);
+               yyval.raw = yyvsp[-1].raw;
+               ;}
+     break;
+   case 227:
+ #line 1789 "parser.y"
+     { yyval.raw = yyvsp[0].raw; ;}
+     break;
+   case 228:
+ #line 1790 "parser.y"
+     { yyval.raw = int2raw_data(yyvsp[0].num); ;}
+     break;
+   case 229:
+ #line 1791 "parser.y"
+     { yyval.raw = int2raw_data(-(yyvsp[0].num)); ;}
+     break;
+   case 230:
+ #line 1792 "parser.y"
+     { yyval.raw = long2raw_data(yyvsp[0].num); ;}
+     break;
+   case 231:
+ #line 1793 "parser.y"
+     { yyval.raw = long2raw_data(-(yyvsp[0].num)); ;}
+     break;
+   case 232:
+ #line 1794 "parser.y"
+     { yyval.raw = str2raw_data(yyvsp[0].str); ;}
+     break;
+   case 233:
+ #line 1795 "parser.y"
+     { yyval.raw = merge_raw_data(yyvsp[-2].raw, yyvsp[0].raw); free(yyvsp[0].raw->data); free(yyvsp[0].raw); ;}
+     break;
+   case 234:
+ #line 1796 "parser.y"
+     { yyval.raw = merge_raw_data_int(yyvsp[-2].raw, yyvsp[0].num); ;}
+     break;
+   case 235:
+ #line 1797 "parser.y"
+     { yyval.raw = merge_raw_data_int(yyvsp[-3].raw, -(yyvsp[0].num)); ;}
+     break;
+   case 236:
+ #line 1798 "parser.y"
+     { yyval.raw = merge_raw_data_long(yyvsp[-2].raw, yyvsp[0].num); ;}
+     break;
+   case 237:
+ #line 1799 "parser.y"
+     { yyval.raw = merge_raw_data_long(yyvsp[-3].raw, -(yyvsp[0].num)); ;}
+     break;
+   case 238:
+ #line 1800 "parser.y"
+     { yyval.raw = merge_raw_data_str(yyvsp[-2].raw, yyvsp[0].str); ;}
+     break;
+   case 239:
+ #line 1804 "parser.y"
+     { yyval.raw = load_file(yyvsp[0].str,dup_language(currentlanguage)); ;}
+     break;
+   case 240:
+ #line 1805 "parser.y"
+     { yyval.raw = yyvsp[0].raw; ;}
+     break;
+   case 241:
+ #line 1812 "parser.y"
+     { yyval.iptr = 0; ;}
+     break;
+   case 242:
+ #line 1813 "parser.y"
+     { yyval.iptr = new_int(yyvsp[0].num); ;}
+     break;
+   case 243:
+ #line 1817 "parser.y"
+     { yyval.num = (yyvsp[0].num); ;}
+     break;
+   case 244:
+ #line 1820 "parser.y"
+     { yyval.num = (yyvsp[-2].num) + (yyvsp[0].num); ;}
+     break;
+   case 245:
+ #line 1821 "parser.y"
+     { yyval.num = (yyvsp[-2].num) - (yyvsp[0].num); ;}
+     break;
+   case 246:
+ #line 1822 "parser.y"
+     { yyval.num = (yyvsp[-2].num) | (yyvsp[0].num); ;}
+     break;
+   case 247:
+ #line 1823 "parser.y"
+     { yyval.num = (yyvsp[-2].num) & (yyvsp[0].num); ;}
+     break;
+   case 248:
+ #line 1824 "parser.y"
+     { yyval.num = (yyvsp[-2].num) * (yyvsp[0].num); ;}
+     break;
+   case 249:
+ #line 1825 "parser.y"
+     { yyval.num = (yyvsp[-2].num) / (yyvsp[0].num); ;}
+     break;
+   case 250:
+ #line 1826 "parser.y"
+     { yyval.num = (yyvsp[-2].num) ^ (yyvsp[0].num); ;}
+     break;
+   case 251:
+ #line 1827 "parser.y"
+     { yyval.num = ~(yyvsp[0].num); ;}
+     break;
+   case 252:
+ #line 1828 "parser.y"
+     { yyval.num = -(yyvsp[0].num); ;}
+     break;
+   case 253:
+ #line 1829 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+   case 254:
+ #line 1830 "parser.y"
+     { yyval.num = yyvsp[-1].num; ;}
+     break;
+   case 255:
+ #line 1831 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+   case 256:
+ #line 1832 "parser.y"
+     { yyval.num = ~(yyvsp[0].num); ;}
+     break;
+   case 257:
+ #line 1835 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+   case 258:
+ #line 1836 "parser.y"
+     { yyval.num = yyvsp[0].num; ;}
+     break;
+     }
+ /* Line 999 of yacc.c.  */
 -      int keycode = 0;
++#line 4136 "y.tab.c"
\f
+   yyvsp -= yylen;
+   yyssp -= yylen;
+   YY_STACK_PRINT (yyss, yyssp);
+   *++yyvsp = yyval;
+   /* Now `shift' the result of the reduction.  Determine what state
+      that goes to, based on the state we popped back to and the rule
+      number reduced by.  */
+   yyn = yyr1[yyn];
+   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+     yystate = yytable[yystate];
+   else
+     yystate = yydefgoto[yyn - YYNTOKENS];
+   goto yynewstate;
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
+ yyerrlab:
+   /* If not already recovering from an error, report this error.  */
+   if (!yyerrstatus)
+     {
+       ++yynerrs;
+ #if YYERROR_VERBOSE
+       yyn = yypact[yystate];
+       if (YYPACT_NINF < yyn && yyn < YYLAST)
+       {
+         YYSIZE_T yysize = 0;
+         int yytype = YYTRANSLATE (yychar);
+         const char* yyprefix;
+         char *yymsg;
+         int yyx;
+         /* Start YYX at -YYN if negative to avoid negative indexes in
+            YYCHECK.  */
+         int yyxbegin = yyn < 0 ? -yyn : 0;
+         /* Stay within bounds of both yycheck and yytname.  */
+         int yychecklim = YYLAST - yyn;
+         int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+         int yycount = 0;
+         yyprefix = ", expecting ";
+         for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+           if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+             {
+               yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
+               yycount += 1;
+               if (yycount == 5)
+                 {
+                   yysize = 0;
+                   break;
+                 }
+             }
+         yysize += (sizeof ("syntax error, unexpected ")
+                    + yystrlen (yytname[yytype]));
+         yymsg = (char *) YYSTACK_ALLOC (yysize);
+         if (yymsg != 0)
+           {
+             char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
+             yyp = yystpcpy (yyp, yytname[yytype]);
+             if (yycount < 5)
+               {
+                 yyprefix = ", expecting ";
+                 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+                   if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+                     {
+                       yyp = yystpcpy (yyp, yyprefix);
+                       yyp = yystpcpy (yyp, yytname[yyx]);
+                       yyprefix = " or ";
+                     }
+               }
+             yyerror (yymsg);
+             YYSTACK_FREE (yymsg);
+           }
+         else
+           yyerror ("syntax error; also virtual memory exhausted");
+       }
+       else
+ #endif /* YYERROR_VERBOSE */
+       yyerror ("syntax error");
+     }
+   if (yyerrstatus == 3)
+     {
+       /* If just tried and failed to reuse lookahead token after an
+        error, discard it.  */
+       /* Return failure if at end of input.  */
+       if (yychar == YYEOF)
+         {
+         /* Pop the error token.  */
+           YYPOPSTACK;
+         /* Pop the rest of the stack.  */
+         while (yyss < yyssp)
+           {
+             YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+             yydestruct (yystos[*yyssp], yyvsp);
+             YYPOPSTACK;
+           }
+         YYABORT;
+         }
+       YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
+       yydestruct (yytoken, &yylval);
+       yychar = YYEMPTY;
+     }
+   /* Else will try to reuse lookahead token after shifting the error
+      token.  */
+   goto yyerrlab1;
+ /*----------------------------------------------------.
+ | yyerrlab1 -- error raised explicitly by an action.  |
+ `----------------------------------------------------*/
+ yyerrlab1:
+   yyerrstatus = 3;    /* Each real token shifted decrements this.  */
+   for (;;)
+     {
+       yyn = yypact[yystate];
+       if (yyn != YYPACT_NINF)
+       {
+         yyn += YYTERROR;
+         if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+           {
+             yyn = yytable[yyn];
+             if (0 < yyn)
+               break;
+           }
+       }
+       /* Pop the current state because it cannot handle the error token.  */
+       if (yyssp == yyss)
+       YYABORT;
+       YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+       yydestruct (yystos[yystate], yyvsp);
+       yyvsp--;
+       yystate = *--yyssp;
+       YY_STACK_PRINT (yyss, yyssp);
+     }
+   if (yyn == YYFINAL)
+     YYACCEPT;
+   YYDPRINTF ((stderr, "Shifting error token, "));
+   *++yyvsp = yylval;
+   yystate = yyn;
+   goto yynewstate;
+ /*-------------------------------------.
+ | yyacceptlab -- YYACCEPT comes here.  |
+ `-------------------------------------*/
+ yyacceptlab:
+   yyresult = 0;
+   goto yyreturn;
+ /*-----------------------------------.
+ | yyabortlab -- YYABORT comes here.  |
+ `-----------------------------------*/
+ yyabortlab:
+   yyresult = 1;
+   goto yyreturn;
+ #ifndef yyoverflow
+ /*----------------------------------------------.
+ | yyoverflowlab -- parser overflow comes here.  |
+ `----------------------------------------------*/
+ yyoverflowlab:
+   yyerror ("parser stack overflow");
+   yyresult = 2;
+   /* Fall through.  */
+ #endif
+ yyreturn:
+ #ifndef yyoverflow
+   if (yyss != yyssa)
+     YYSTACK_FREE (yyss);
+ #endif
+   return yyresult;
+ }
+ #line 1839 "parser.y"
+ /* Dialog specific functions */
+ static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->style == NULL)
+       {
+               dlg->style = new_style(0,0);
+       }
+       if(dlg->gotstyle)
+       {
+               yywarning("Style already defined, or-ing together");
+       }
+       else
+       {
+               dlg->style->or_mask = 0;
+               dlg->style->and_mask = 0;
+       }
+       dlg->style->or_mask |= st->or_mask;
+       dlg->style->and_mask |= st->and_mask;
+       dlg->gotstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->exstyle == NULL)
+       {
+               dlg->exstyle = new_style(0,0);
+       }
+       if(dlg->gotexstyle)
+       {
+               yywarning("ExStyle already defined, or-ing together");
+       }
+       else
+       {
+               dlg->exstyle->or_mask = 0;
+               dlg->exstyle->and_mask = 0;
+       }
+       dlg->exstyle->or_mask |= st->or_mask;
+       dlg->exstyle->and_mask |= st->and_mask;
+       dlg->gotexstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->title)
+               yyerror("Caption already defined");
+       dlg->title = s;
+       return dlg;
+ }
+ static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->font)
+               yyerror("Font already defined");
+       dlg->font = f;
+       return dlg;
+ }
+ static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->dlgclass)
+               yyerror("Class already defined");
+       dlg->dlgclass = n;
+       return dlg;
+ }
+ static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->menu)
+               yyerror("Menu already defined");
+       dlg->menu = m;
+       return dlg;
+ }
+ static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.language)
+               yyerror("Language already defined");
+       dlg->lvc.language = l;
+       return dlg;
+ }
+ static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.characts)
+               yyerror("Characteristics already defined");
+       dlg->lvc.characts = c;
+       return dlg;
+ }
+ static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.version)
+               yyerror("Version already defined");
+       dlg->lvc.version = v;
+       return dlg;
+ }
+ /* Controls specific functions */
+ static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
+ {
+       /* Hm... this seems to be jammed in at all time... */
+       int defaultstyle = WS_CHILD | WS_VISIBLE;
+       assert(ctrl != NULL);
+       ctrl->prev = prev;
+       if(prev)
+               prev->next = ctrl;
+       if(type != -1)
+       {
+               ctrl->ctlclass = new_name_id();
+               ctrl->ctlclass->type = name_ord;
+               ctrl->ctlclass->name.i_name = type;
+       }
+       switch(type)
+       {
+       case CT_BUTTON:
+               if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
+                       defaultstyle |= WS_TABSTOP;
+               break;
+       case CT_EDIT:
+               defaultstyle |= WS_TABSTOP | WS_BORDER;
+               break;
+       case CT_LISTBOX:
+               defaultstyle |= LBS_NOTIFY | WS_BORDER;
+               break;
+       case CT_COMBOBOX:
+                 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
+                     defaultstyle |= CBS_SIMPLE;
+               break;
+       case CT_STATIC:
+               if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
+                       defaultstyle |= WS_GROUP;
+               break;
+       }
+       if(!ctrl->gotstyle)     /* Handle default style setting */
+       {
+               switch(type)
+               {
+               case CT_EDIT:
+                       defaultstyle |= ES_LEFT;
+                       break;
+               case CT_LISTBOX:
+                       defaultstyle |= LBS_NOTIFY;
+                       break;
+               case CT_COMBOBOX:
+                       defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
+                       break;
+               case CT_SCROLLBAR:
+                       defaultstyle |= SBS_HORZ;
+                       break;
+               case CT_BUTTON:
+                       switch(special_style)
+                       {
+                       case BS_CHECKBOX:
+                       case BS_DEFPUSHBUTTON:
+                       case BS_PUSHBUTTON:
+ /*                    case BS_PUSHBOX:        */
+                       case BS_AUTORADIOBUTTON:
+                       case BS_AUTO3STATE:
+                       case BS_3STATE:
+                       case BS_AUTOCHECKBOX:
+                               defaultstyle |= WS_TABSTOP;
+                               break;
+                       default:
+                               yywarning("Unknown default button control-style 0x%08x", special_style);
+                       case BS_GROUPBOX:
+                       case BS_RADIOBUTTON:
+                               break;
+                       }
+                       break;
+               case CT_STATIC:
+                       switch(special_style)
+                       {
+                       case SS_LEFT:
+                       case SS_RIGHT:
+                       case SS_CENTER:
+                               defaultstyle |= WS_GROUP;
+                               break;
+                       case SS_ICON:   /* Special case */
+                               break;
+                       default:
+                               yywarning("Unknown default static control-style 0x%08x", special_style);
+                               break;
+                       }
+                       break;
+               case -1:        /* Generic control */
+                       goto byebye;
+               default:
+                       yyerror("Internal error (report this): Got weird control type 0x%08x", type);
+               }
+       }
+       /* The SS_ICON flag is always forced in for icon controls */
+       if(type == CT_STATIC && special_style == SS_ICON)
+               defaultstyle |= SS_ICON;
+       if (!ctrl->gotstyle)
+               ctrl->style = new_style(0,0);
+       /* combine all styles */
+       ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
+       ctrl->gotstyle = TRUE;
+ byebye:
+       /* combine with NOT mask */
+       if (ctrl->gotstyle)
+       {
+               ctrl->style->or_mask &= ~(ctrl->style->and_mask);
+               ctrl->style->and_mask = 0;
+       }
+       if (ctrl->gotexstyle)
+       {
+               ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
+               ctrl->exstyle->and_mask = 0;
+       }
+       return ctrl;
+ }
+ static name_id_t *convert_ctlclass(name_id_t *cls)
+ {
+       char *cc = NULL;
+       int iclass;
+       if(cls->type == name_ord)
+               return cls;
+       assert(cls->type == name_str);
+       if(cls->type == str_unicode)
+       {
+               yyerror("Don't yet support unicode class comparison");
+       }
+       else
+               cc = cls->name.s_name->str.cstr;
+       if(!strcasecmp("BUTTON", cc))
+               iclass = CT_BUTTON;
+       else if(!strcasecmp("COMBOBOX", cc))
+               iclass = CT_COMBOBOX;
+       else if(!strcasecmp("LISTBOX", cc))
+               iclass = CT_LISTBOX;
+       else if(!strcasecmp("EDIT", cc))
+               iclass = CT_EDIT;
+       else if(!strcasecmp("STATIC", cc))
+               iclass = CT_STATIC;
+       else if(!strcasecmp("SCROLLBAR", cc))
+               iclass = CT_SCROLLBAR;
+       else
+               return cls;     /* No default, return user controlclass */
+       free(cls->name.s_name->str.cstr);
+       free(cls->name.s_name);
+       cls->type = name_ord;
+       cls->name.i_name = iclass;
+       return cls;
+ }
+ /* DialogEx specific functions */
+ static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->style == NULL)
+       {
+               dlg->style = new_style(0,0);
+       }
+       if(dlg->gotstyle)
+       {
+               yywarning("Style already defined, or-ing together");
+       }
+       else
+       {
+               dlg->style->or_mask = 0;
+               dlg->style->and_mask = 0;
+       }
+       dlg->style->or_mask |= st->or_mask;
+       dlg->style->and_mask |= st->and_mask;
+       dlg->gotstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->exstyle == NULL)
+       {
+               dlg->exstyle = new_style(0,0);
+       }
+       if(dlg->gotexstyle)
+       {
+               yywarning("ExStyle already defined, or-ing together");
+       }
+       else
+       {
+               dlg->exstyle->or_mask = 0;
+               dlg->exstyle->and_mask = 0;
+       }
+       dlg->exstyle->or_mask |= st->or_mask;
+       dlg->exstyle->and_mask |= st->and_mask;
+       dlg->gotexstyle = TRUE;
+       free(st);
+       return dlg;
+ }
+ static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->title)
+               yyerror("Caption already defined");
+       dlg->title = s;
+       return dlg;
+ }
+ static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->font)
+               yyerror("Font already defined");
+       dlg->font = f;
+       return dlg;
+ }
+ static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->dlgclass)
+               yyerror("Class already defined");
+       dlg->dlgclass = n;
+       return dlg;
+ }
+ static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->menu)
+               yyerror("Menu already defined");
+       dlg->menu = m;
+       return dlg;
+ }
+ static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.language)
+               yyerror("Language already defined");
+       dlg->lvc.language = l;
+       return dlg;
+ }
+ static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.characts)
+               yyerror("Characteristics already defined");
+       dlg->lvc.characts = c;
+       return dlg;
+ }
+ static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
+ {
+       assert(dlg != NULL);
+       if(dlg->lvc.version)
+               yyerror("Version already defined");
+       dlg->lvc.version = v;
+       return dlg;
+ }
+ /* Accelerator specific functions */
+ static event_t *add_event(int key, int id, int flags, event_t *prev)
+ {
+       event_t *ev = new_event();
+       if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
+               yyerror("Cannot use both ASCII and VIRTKEY");
+       ev->key = key;
+       ev->id = id;
+       ev->flags = flags & ~WRC_AF_ASCII;
+       ev->prev = prev;
+       if(prev)
+               prev->next = ev;
+       return ev;
+ }
+ static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
+ {
 -      if(key->type != str_char)
 -              yyerror("Key code must be an ascii string");
++      int keycode = 0, keysym = 0;
+       event_t *ev = new_event();
 -      if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
++      if(key->type == str_char)
++              keysym = key->str.cstr[0];
++      else
++              keysym = key->str.wstr[0];
 -      if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
++      if((flags & WRC_AF_VIRTKEY) && (!isupper(keysym & 0xff) && !isdigit(keysym & 0xff)))
+               yyerror("VIRTKEY code is not equal to ascii value");
 -      else if(key->str.cstr[0] == '^')
++      if(keysym == '^' && (flags & WRC_AF_CONTROL) != 0)
+       {
+               yyerror("Cannot use both '^' and CONTROL modifier");
+       }
 -              keycode = toupper(key->str.cstr[1]) - '@';
++      else if(keysym == '^')
+       {
 -              keycode = key->str.cstr[0];
++              if(key->type == str_char)
++                      keycode = toupper(key->str.cstr[1]) - '@';
++              else
++                      keycode = toupper(key->str.wstr[1]) - '@';
+               if(keycode >= ' ')
+                       yyerror("Control-code out of range");
+       }
+       else
++              keycode = keysym;
+       ev->key = keycode;
+       ev->id = id;
+       ev->flags = flags & ~WRC_AF_ASCII;
+       ev->prev = prev;
+       if(prev)
+               prev->next = ev;
+       return ev;
+ }
+ /* MenuEx specific functions */
+ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
+ {
+       itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
+       opt->id = id;
+       opt->type = type;
+       opt->state = state;
+       opt->helpid = helpid;
+       return opt;
+ }
+ /* Raw data functions */
+ static raw_data_t *load_file(string_t *filename, language_t *lang)
+ {
+       FILE *fp = NULL;
+       char *path;
+       raw_data_t *rd;
+       string_t *name;
+       int codepage = get_language_codepage(lang->id, lang->sub);
+       /* FIXME: we may want to use utf-8 here */
+       if (codepage <= 0 && filename->type != str_char)
+               yyerror("Cannot convert filename to ASCII string");
+       name = convert_string( filename, str_char, codepage );
+       if (!(path = wpp_find_include(name->str.cstr, 1)))
+               yyerror("Cannot open file %s", name->str.cstr);
+       if (!(fp = fopen( path, "rb" )))
+               yyerror("Cannot open file %s", name->str.cstr);
+       free( path );
+       rd = new_raw_data();
+       fseek(fp, 0, SEEK_END);
+       rd->size = ftell(fp);
+       fseek(fp, 0, SEEK_SET);
+       if (rd->size)
+       {
+               rd->data = (char *)xmalloc(rd->size);
+               fread(rd->data, rd->size, 1, fp);
+       }
+       else rd->data = NULL;
+       fclose(fp);
+       rd->lvc.language = lang;
+       free_string(name);
+       return rd;
+ }
+ static raw_data_t *int2raw_data(int i)
+ {
+       raw_data_t *rd;
+       if( ( i >= 0 && (int)((unsigned short)i) != i) ||
+             ( i < 0  && (int)((short)i) != i) )
+               yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
+       rd = new_raw_data();
+       rd->size = sizeof(short);
+       rd->data = (char *)xmalloc(rd->size);
+       switch(byteorder)
+       {
+ #ifdef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_BIG:
+               rd->data[0] = HIBYTE(i);
+               rd->data[1] = LOBYTE(i);
+               break;
+ #ifndef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_LITTLE:
+               rd->data[1] = HIBYTE(i);
+               rd->data[0] = LOBYTE(i);
+               break;
+       }
+       return rd;
+ }
+ static raw_data_t *long2raw_data(int i)
+ {
+       raw_data_t *rd;
+       rd = new_raw_data();
+       rd->size = sizeof(int);
+       rd->data = (char *)xmalloc(rd->size);
+       switch(byteorder)
+       {
+ #ifdef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_BIG:
+               rd->data[0] = HIBYTE(HIWORD(i));
+               rd->data[1] = LOBYTE(HIWORD(i));
+               rd->data[2] = HIBYTE(LOWORD(i));
+               rd->data[3] = LOBYTE(LOWORD(i));
+               break;
+ #ifndef WORDS_BIGENDIAN
+       default:
+ #endif
+       case WRC_BO_LITTLE:
+               rd->data[3] = HIBYTE(HIWORD(i));
+               rd->data[2] = LOBYTE(HIWORD(i));
+               rd->data[1] = HIBYTE(LOWORD(i));
+               rd->data[0] = LOBYTE(LOWORD(i));
+               break;
+       }
+       return rd;
+ }
+ static raw_data_t *str2raw_data(string_t *str)
+ {
+       raw_data_t *rd;
+       rd = new_raw_data();
+       rd->size = str->size * (str->type == str_char ? 1 : 2);
+       rd->data = (char *)xmalloc(rd->size);
+       if(str->type == str_char)
+               memcpy(rd->data, str->str.cstr, rd->size);
+       else if(str->type == str_unicode)
+       {
+               int i;
+               switch(byteorder)
+               {
+ #ifdef WORDS_BIGENDIAN
+               default:
+ #endif
+               case WRC_BO_BIG:
+                       for(i = 0; i < str->size; i++)
+                       {
+                               rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
+                               rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
+                       }
+                       break;
+ #ifndef WORDS_BIGENDIAN
+               default:
+ #endif
+               case WRC_BO_LITTLE:
+                       for(i = 0; i < str->size; i++)
+                       {
+                               rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
+                               rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
+                       }
+                       break;
+               }
+       }
+       else
+               internal_error(__FILE__, __LINE__, "Invalid stringtype");
+       return rd;
+ }
+ static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
+ {
+       r1->data = xrealloc(r1->data, r1->size + r2->size);
+       memcpy(r1->data + r1->size, r2->data, r2->size);
+       r1->size += r2->size;
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
+ {
+       raw_data_t *t = int2raw_data(i);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
+ {
+       raw_data_t *t = long2raw_data(i);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
+ {
+       raw_data_t *t = str2raw_data(str);
+       merge_raw_data(r1, t);
+       free(t->data);
+       free(t);
+       return r1;
+ }
+ /* Function the go back in a list to get the head */
+ static menu_item_t *get_item_head(menu_item_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static menuex_item_t *get_itemex_head(menuex_item_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static resource_t *get_resource_head(resource_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static ver_block_t *get_ver_block_head(ver_block_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static ver_value_t *get_ver_value_head(ver_value_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static control_t *get_control_head(control_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ static event_t *get_event_head(event_t *p)
+ {
+       if(!p)
+               return NULL;
+       while(p->prev)
+               p = p->prev;
+       return p;
+ }
+ /* Find a stringtable with given language */
+ static stringtable_t *find_stringtable(lvc_t *lvc)
+ {
+       stringtable_t *stt;
+       assert(lvc != NULL);
+       if(!lvc->language)
+               lvc->language = dup_language(currentlanguage);
+       for(stt = sttres; stt; stt = stt->next)
+       {
+               if(stt->lvc.language->id == lvc->language->id
+               && stt->lvc.language->sub == lvc->language->sub)
+               {
+                       /* Found a table with the same language */
+                       /* The version and characteristics are now handled
+                        * in the generation of the individual stringtables.
+                        * This enables localized analysis.
+                       if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
+                       || (!stt->lvc.version && lvc->version)
+                       || (stt->lvc.version && !lvc->version))
+                               yywarning("Stringtable's versions are not the same, using first definition");
+                       if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
+                       || (!stt->lvc.characts && lvc->characts)
+                       || (stt->lvc.characts && !lvc->characts))
+                               yywarning("Stringtable's characteristics are not the same, using first definition");
+                       */
+                       return stt;
+               }
+       }
+       return NULL;
+ }
+ /* qsort sorting function for string table entries */
+ #define STE(p)        ((stt_entry_t *)(p))
+ static int sort_stt_entry(const void *e1, const void *e2)
+ {
+       return STE(e1)->id - STE(e2)->id;
+ }
+ #undef STE
+ static resource_t *build_stt_resources(stringtable_t *stthead)
+ {
+       stringtable_t *stt;
+       stringtable_t *newstt;
+       resource_t *rsc;
+       resource_t *rsclist = NULL;
+       resource_t *rsctail = NULL;
+       int i;
+       int j;
+       DWORD andsum;
+       DWORD orsum;
+       characts_t *characts;
+       version_t *version;
+       if(!stthead)
+               return NULL;
+       /* For all languages defined */
+       for(stt = stthead; stt; stt = stt->next)
+       {
+               assert(stt->nentries > 0);
+               /* Sort the entries */
+               if(stt->nentries > 1)
+                       qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
+               for(i = 0; i < stt->nentries; )
+               {
+                       newstt = new_stringtable(&stt->lvc);
+                       newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
+                       newstt->nentries = 16;
+                       newstt->idbase = stt->entries[i].id & ~0xf;
+                       for(j = 0; j < 16 && i < stt->nentries; j++)
+                       {
+                               if(stt->entries[i].id - newstt->idbase == j)
+                               {
+                                       newstt->entries[j] = stt->entries[i];
+                                       i++;
+                               }
+                       }
+                       andsum = ~0;
+                       orsum = 0;
+                       characts = NULL;
+                       version = NULL;
+                       /* Check individual memory options and get
+                        * the first characteristics/version
+                        */
+                       for(j = 0; j < 16; j++)
+                       {
+                               if(!newstt->entries[j].str)
+                                       continue;
+                               andsum &= newstt->entries[j].memopt;
+                               orsum |= newstt->entries[j].memopt;
+                               if(!characts)
+                                       characts = newstt->entries[j].characts;
+                               if(!version)
+                                       version = newstt->entries[j].version;
+                       }
+                       if(andsum != orsum)
+                       {
+                               warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
+                       }
+                       /* Check version and characteristics */
+                       for(j = 0; j < 16; j++)
+                       {
+                               if(characts
+                               && newstt->entries[j].characts
+                               && *newstt->entries[j].characts != *characts)
+                                       warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
+                               if(version
+                               && newstt->entries[j].version
+                               && *newstt->entries[j].version != *version)
+                                       warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
+                       }
+                       rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
+                       rsc->name = new_name_id();
+                       rsc->name->type = name_ord;
+                       rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
+                       rsc->memopt = andsum; /* Set to least common denominator */
+                       newstt->memopt = andsum;
+                       newstt->lvc.characts = characts;
+                       newstt->lvc.version = version;
+                       if(!rsclist)
+                       {
+                               rsclist = rsc;
+                               rsctail = rsc;
+                       }
+                       else
+                       {
+                               rsctail->next = rsc;
+                               rsc->prev = rsctail;
+                               rsctail = rsc;
+                       }
+               }
+       }
+       return rsclist;
+ }
+ static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
+ {
+       idrec->prev = prev;
+       if(prev)
+               prev->next = idrec;
+       return idrec;
+ }
+ static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
+ {
+       if(!p)
+       {
+               *nitems = 0;
+               return NULL;
+       }
+       *nitems = 1;
+       while(p->prev)
+       {
+               (*nitems)++;
+               p = p->prev;
+       }
+       return p;
+ }
+ static string_t *make_filename(string_t *str)
+ {
+     if(str->type == str_char)
+     {
+       char *cptr;
+       /* Remove escaped backslash and convert to forward */
+       for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
+       {
+               if(cptr[1] == '\\')
+               {
+                       memmove(cptr, cptr+1, strlen(cptr));
+                       str->size--;
+               }
+               *cptr = '/';
+       }
+     }
+     else
+     {
+       WCHAR *wptr;
+       /* Remove escaped backslash and convert to forward */
+       for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
+       {
+               if(wptr[1] == '\\')
+               {
+                       memmove(wptr, wptr+1, strlenW(wptr));
+                       str->size--;
+               }
+               *wptr = '/';
+       }
+     }
+     return str;
+ }
+ /*
+  * Process all resources to extract fonts and build
+  * a fontdir resource.
+  *
+  * Note: MS' resource compiler (build 1472) does not
+  * handle font resources with different languages.
+  * The fontdir is generated in the last active language
+  * and font identifiers must be unique across the entire
+  * source.
+  * This is not logical considering the localization
+  * constraints of all other resource types. MS has,
+  * most probably, never testet localized fonts. However,
+  * using fontresources is rare, so it might not occur
+  * in normal applications.
+  * Wine does require better localization because a lot
+  * of languages are coded into the same executable.
+  * Therefore, I will generate fontdirs for *each*
+  * localized set of fonts.
+  */
+ static resource_t *build_fontdir(resource_t **fnt, int nfnt)
+ {
+       static int once = 0;
+       if(!once)
+       {
+               warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
+               once++;
+       }
+       return NULL;
+ }
+ static resource_t *build_fontdirs(resource_t *tail)
+ {
+       resource_t *rsc;
+       resource_t *lst = NULL;
+       resource_t **fnt = NULL;        /* List of all fonts */
+       int nfnt = 0;
+       resource_t **fnd = NULL;        /* List of all fontdirs */
+       int nfnd = 0;
+       resource_t **lanfnt = NULL;
+       int nlanfnt = 0;
+       int i;
+       name_id_t nid;
+       string_t str;
+       int fntleft;
+       nid.type = name_str;
+       nid.name.s_name = &str;
+       str.type = str_char;
+       str.str.cstr = xstrdup("FONTDIR");
+       str.size = 7;
+       /* Extract all fonts and fontdirs */
+       for(rsc = tail; rsc; rsc = rsc->prev)
+       {
+               if(rsc->type == res_fnt)
+               {
+                       nfnt++;
+                       fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
+                       fnt[nfnt-1] = rsc;
+               }
+               else if(rsc->type == res_fntdir)
+               {
+                       nfnd++;
+                       fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
+                       fnd[nfnd-1] = rsc;
+               }
+       }
+       /* Verify the name of the present fontdirs */
+       for(i = 0; i < nfnd; i++)
+       {
+               if(compare_name_id(&nid, fnd[i]->name))
+               {
+                       warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
+                               get_nameid_str(fnd[i]->name));
+                       fnd[i] = NULL;
+               }
+       }
+       /* Sanity check */
+       if(nfnt == 0)
+       {
+               if(nfnd != 0)
+                       warning("Found %d FONTDIR entries without any fonts present", nfnd);
+               goto clean;
+       }
+       /* Copy space */
+       lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
+       /* Get all fonts covered by fontdirs */
+       for(i = 0; i < nfnd; i++)
+       {
+               int j;
+               WORD cnt;
+               int isswapped = 0;
+               if(!fnd[i])
+                       continue;
+               for(j = 0; j < nfnt; j++)
+               {
+                       if(!fnt[j])
+                               continue;
+                       if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
+                       {
+                               lanfnt[nlanfnt] = fnt[j];
+                               nlanfnt++;
+                               fnt[j] = NULL;
+                       }
+               }
+               cnt = *(WORD *)fnd[i]->res.fnd->data->data;
+               if(nlanfnt == cnt)
+                       isswapped = 0;
+               else if(nlanfnt == BYTESWAP_WORD(cnt))
+                       isswapped = 1;
+               else
+                       error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
+                               fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
+ #ifdef WORDS_BIGENDIAN
+               if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
+ #else
+               if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
+ #endif
+               {
+                       internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
+               }
+       }
+       /* We now have fonts left where we need to make a fontdir resource */
+       for(i = fntleft = 0; i < nfnt; i++)
+       {
+               if(fnt[i])
+                       fntleft++;
+       }
+       while(fntleft)
+       {
+               /* Get fonts of same language in lanfnt[] */
+               for(i = nlanfnt = 0; i < nfnt; i++)
+               {
+                       if(fnt[i])
+                       {
+                               if(!nlanfnt)
+                               {
+                       addlanfnt:
+                                       lanfnt[nlanfnt] = fnt[i];
+                                       nlanfnt++;
+                                       fnt[i] = NULL;
+                                       fntleft--;
+                               }
+                               else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
+                                       goto addlanfnt;
+                       }
+               }
+               /* and build a fontdir */
+               rsc = build_fontdir(lanfnt, nlanfnt);
+               if(rsc)
+               {
+                       if(lst)
+                       {
+                               lst->next = rsc;
+                               rsc->prev = lst;
+                       }
+                       lst = rsc;
+               }
+       }
+       free(lanfnt);
+ clean:
+       if(fnt)
+               free(fnt);
+       if(fnd)
+               free(fnd);
+       free(str.str.cstr);
+       return lst;
+ }
+ /*
+  * This gets invoked to determine whether the next resource
+  * is to be of a standard-type (e.g. bitmaps etc.), or should
+  * be a user-type resource. This function is required because
+  * there is the _possibility_ of a lookahead token in the
+  * parser, which is generated from the "expr" state in the
+  * "nameid" parsing.
+  *
+  * The general resource format is:
+  * <identifier> <type> <flags> <resourcebody>
+  *
+  * The <identifier> can either be tIDENT or "expr". The latter
+  * will always generate a lookahead, which is the <type> of the
+  * resource to parse. Otherwise, we need to get a new token from
+  * the scanner to determine the next step.
+  *
+  * The problem arrises when <type> is numerical. This case should
+  * map onto default resource-types and be parsed as such instead
+  * of being mapped onto user-type resources.
+  *
+  * The trick lies in the fact that yacc (bison) doesn't care about
+  * intermediate changes of the lookahead while reducing a rule. We
+  * simply replace the lookahead with a token that will result in
+  * a shift to the appropriate rule for the specific resource-type.
+  */
+ static int rsrcid_to_token(int lookahead)
+ {
+       int token;
+       const char *type = "?";
+       /* Get a token if we don't have one yet */
+       if(lookahead == YYEMPTY)
+               lookahead = YYLEX;
+       /* Only numbers are possibly interesting */
+       switch(lookahead)
+       {
+       case tNUMBER:
+       case tLNUMBER:
+               break;
+       default:
+               return lookahead;
+       }
+       token = lookahead;
+       switch(yylval.num)
+       {
+       case WRC_RT_CURSOR:
+               type = "CURSOR";
+               token = tCURSOR;
+               break;
+       case WRC_RT_ICON:
+               type = "ICON";
+               token = tICON;
+               break;
+       case WRC_RT_BITMAP:
+               type = "BITMAP";
+               token = tBITMAP;
+               break;
+       case WRC_RT_FONT:
+               type = "FONT";
+               token = tFONT;
+               break;
+       case WRC_RT_FONTDIR:
+               type = "FONTDIR";
+               token = tFONTDIR;
+               break;
+       case WRC_RT_RCDATA:
+               type = "RCDATA";
+               token = tRCDATA;
+               break;
+       case WRC_RT_MESSAGETABLE:
+               type = "MESSAGETABLE";
+               token = tMESSAGETABLE;
+               break;
+       case WRC_RT_DLGINIT:
+               type = "DLGINIT";
+               token = tDLGINIT;
+               break;
+       case WRC_RT_ACCELERATOR:
+               type = "ACCELERATOR";
+               token = tACCELERATORS;
+               break;
+       case WRC_RT_MENU:
+               type = "MENU";
+               token = tMENU;
+               break;
+       case WRC_RT_DIALOG:
+               type = "DIALOG";
+               token = tDIALOG;
+               break;
+       case WRC_RT_VERSION:
+               type = "VERSION";
+               token = tVERSIONINFO;
+               break;
+       case WRC_RT_TOOLBAR:
+               type = "TOOLBAR";
+               token = tTOOLBAR;
+               break;
+       case WRC_RT_STRING:
+               type = "STRINGTABLE";
+               break;
+       case WRC_RT_ANICURSOR:
+       case WRC_RT_ANIICON:
+       case WRC_RT_GROUP_CURSOR:
+       case WRC_RT_GROUP_ICON:
+               yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
+               return lookahead;
+       case WRC_RT_DLGINCLUDE:
+       case WRC_RT_PLUGPLAY:
+       case WRC_RT_VXD:
+       case WRC_RT_HTML:
+               yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);
+       default:
+               return lookahead;
+       }
+       return token;
+ }