@echo off
REM  Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.

if %1.==. goto Usage
if %2.==. goto Usage

set __erw=\epoc32\release\wins
set _rscdir=%4
set _whatvar_=%3
if "%_whatvar_%"=="" set _whatvar_=deb
if not "%_rscdir%"=="" goto TestRscDir
if "%_whatvar_%"=="" goto Default
set _rscdir=%__erw%\%_whatvar_%\z\system\apps\%1
if not exist %_rscdir%\NUL set _rscdir=%__erw%\%_whatvar_%\z\system\data
goto TestRscDir

:Default
set _rscdir=%__erw%\%_whatvar_%\z\system\apps\%1

:TestRscDir
if not exist %_rscdir%\NUL set _rscdir=%__erw%\%_whatvar_%\z\system\data
set __erw=

if "%3"=="udeb" set _isunicode=-u
if "%3"=="UDEB" set _isunicode=-u
if "%3"=="urel" set _isunicode=-u
if "%3"=="UREL" set _isunicode=-u

if "%_isunicode%"=="-u" set _unicode_macro=-D _UNICODE

if "%2"=="01" set _languk=-D LANGUAGE_UK
if "%2"=="10" set _langus=-D LANGUAGE_US

cpp -I..\inc -I..\..\epoc32\include -D LANGUAGE_%2 %_languk% %_langus% %_unicode_macro% < %1.RSS > %1.RPP
if "%_MSDEV_BLD_ENV_%"=="1" call \epoc32\tools\rcomp %_isunicode% -o%_rscdir%\%1.R%2 -h%1.rs~ -i%1.RSS -s%1.RPP
if "%_MSDEV_BLD_ENV_%"=="" rcomp %_isunicode% -o%_rscdir%\%1.R%2 -h%1.rs~ -i%1.RSS -s%1.RPP
if not errorlevel==1 goto DoFc

if exist %_rscdir%\%1.R%2 del %_rscdir%\%1.R%2 > nul
if exist \epoc32\include\%1.RSG del \epoc32\include\%1.RSG > nul
if exist %1.rs~ del %1.rs~ > nul
goto DelRPP

:DoFc
if "%_MSDEV_BLD_ENV_%"=="1" \epoc32\tools\fc4bat %1.rs~ \epoc32\include\%1.RSG
if "%_MSDEV_BLD_ENV_%"=="" fc4bat %1.rs~ \epoc32\include\%1.RSG
if errorlevel==1 goto WriteHeaderFile
echo %1.RSG unchanged - not rewritten
del %1.rs~

goto DelRPP

:Usage
echo Usage: EIKRS FILENAME (with no extension) LANGUAGE VARIANT
echo e.g.   EIKRS paint FR deb
echo Explicit output directory can be given as 4th parameter
echo e.g.	EIKRS eikon GE \epoc32\release\wins\deb\z\system\data
echo N.B.	LANGUAGE must be given in upper case ("FR" not "fr")
goto End

:WriteHeaderFile
if exist \epoc32\include\%1.RSG del \epoc32\include\%1.RSG
copy %1.rs~ \epoc32\include\%1.RSG > nul
del %1.rs~ > nul
echo %1.RSG changed

:DelRPP
if exist %1.RPP del %1.RPP > nul

:End
set _rscdir=
set _isunicode=
set _unicode_macro=
set _languk=
set _langus=
set errorlevel=
