@ECHO OFF
SETLOCAL
SET BATDIR=%~dp0

REM//劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅
REM//仭愝掕椺
REM//仩扨弮側僥僗僩僾儘僌儔儉
REM//劆SET SIMPLIFY=1
REM//劆SET DEL_RESOURCE_DATA=1
REM//仩Bison/Flex傪巊梡偡傞僾儘僌儔儉
REM//劆SET USE_BISON_FLEX=1
REM//劆SET SIMPLIFY=1
REM//劆SET DEL_RESOURCE_DATA=1
REM//仩PDCurses傪巊梡偡傞僾儘僌儔儉
REM//劆SET USE_PDCURSES=1
REM//劆SET SIMPLIFY=1
REM//劆SET DEL_RESOURCE_DATA=1
REM//仩DxLib傪巊梡偡傞僾儘僌儔儉
REM//劆SET USE_DXLIB=1
REM//劆SET SIMPLIFY=1
REM//仩GDI+傪巊梡偡傞僾儘僌儔儉
REM//劆SET USE_GDIPLUS=1
REM//劆SET SIMPLIFY=1
REM//劆SET DEL_RESOURCE_DATA=1
REM//劆SET APP_AS_CPP=1		偙偺峴偼徣棯偟偰傕峔偄傑偣傫丅'SET USE_GDIPLUS=1'偺張棟偺拞偱'SET APP_AS_CPP=1'傕帺摦揑偵僙僢僩偝傟傞偐傜偱偡丅
REM//仩PDCurses,DxLib,GDI+傪巊梡偟丄clip僼僅儖僟偺椬偵抲偄偰價儖僪偡傞丄傾僾儕働乕僔儑儞
REM//劆SET USE_PDCURSES=1
REM//劆SET USE_DXLIB=1
REM//劆SET USE_GDIPLUS=1
REM//劆SET SIMPLIFY=1
REM//劆SET APP_AS_CPP=1		偙偺峴偼徣棯偟偰傕峔偄傑偣傫丅'SET USE_GDIPLUS=1'偺張棟偺拞偱'SET APP_AS_CPP=1'傕帺摦揑偵僙僢僩偝傟傞偐傜偱偡丅
REM//SET MOVE_DIR=1
REM//劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅

SET PROJECT=test
REM//SET USE_BISON_FLEX=1
REM//SET USE_SQLITE=1
REM//SET USE_PDCURSES=1
REM//SET USE_DXLIB=1
REM//SET USE_SOFDEC=1
REM//SET USE_ADX=1
REM//SET USE_AFTERFX=1
REM//SET USE_SSBPLIB=1
REM//SET USE_GDIPLUS=1
REM//SET USE_NUKLEAR=1
REM//SET USE_LUA=1
REM//SET USE_ACTIVETCL=1
SET SIMPLIFY=1
SET DEL_RESOURCE_DATA=1
REM//SET APP_AS_CPP=1
REM//SET MOVE_DIR=1

REM *** 僾儘僕僃僋僩柤傪曄峏偡傞 ***
IF "%PROJECT%" NEQ "test" (
  ECHO 僾儘僕僃僋僩柤傪曄峏偟傑偡丅
  onigsed.exe -e "s/test/%PROJECT%/g" ^
              -i~ test.dsw test.dsp test.rc && (DEL *~) && (REN test.* %PROJECT%.*)
)

REM *** Bison/Flex ***
IF "%USE_BISON_FLEX%" EQU "" (
  ECHO Bison/Flex傪嶍彍偟傑偡丅
  DEL lex.yy.l
  DEL y.tab.y
  DEL prog1.txt
  DEL prog2.txt
  onigsed.exe -e "s/^#define USE_BISON_FLEX/\/\/&/" ^
              -i~ app.h && (DEL *~)
  onigsed.exe -e "/^# Begin Group \"Bison\/Flex Files\"/,/^# End Group/d" ^
              -i~ %PROJECT%.dsp && (DEL *~)
)

REM *** SQLite ***
IF "%USE_SQLITE%" EQU "" (
  ECHO SQLite傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_SQLITE/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** PDCurses ***
IF "%USE_PDCURSES%" EQU "" (
  ECHO PDCurses傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_PDCURSES/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** DxLib ***
IF "%USE_DXLIB%" EQU "" (
  ECHO DxLib傪嶍彍偟傑偡丅
  DEL cpp.cpp
  onigsed.exe -e "s/^#define USE_DXLIB/\/\/&/" ^
              -i~ app.h && (DEL *~)
  onigsed.exe -e "/^#ifdef  USE_DXLIB/,/^#endif\/\/USE_DXLIB/d" ^
              -i~ app.h app.c work.h && (DEL *~)
  onigsed.exe -e "/^# Begin Group \"grp\"/,/^# End Group/d" ^
              -e "/^# Begin Group \"snd\"/,/^# End Group/d" ^
              -e "/^SOURCE=\.\\cpp\.cpp/,/^$/d" ^
              -e "/^USERDEP/{s/\"grp\\[[:alnum:]]*\.txt\"[[:blank:]]*//g}" ^
              -e "/^USERDEP/{s/\"snd\\[[:alnum:]]*\.txt\"[[:blank:]]*//g}" ^
              -e "/^USERDEP/{s/\"TapDef\.h\"[[:blank:]]*//g}" ^
              -i~ %PROJECT%.dsp && (DEL *~)
  onigsed.exe -e "s/^#include \"grp\\[[:alnum:]]*\.txt\"/\/\/&/" ^
              -e "s/^#include \"snd\\[[:alnum:]]*\.txt\"/\/\/&/" ^
              -i~ txt\EnmDef.txt txt\RegTbl.txt && (DEL txt\*~)
  onigsed.exe -e "s/^#include \"TapDef\.h\"/\/\/&/" ^
              -e "s/^#include \"dir\\Test\.txt\"/\/\/&/" ^
              -i~ txt\DirSeq.txt && (DEL txt\*~)
  onigsed.exe -e "d" ^
              -i~ txt\AnmSeq.txt txt\TapDef.txt && (DEL txt\*~)
  RMDIR /S /Q grp
  RMDIR /S /Q snd
  SET USE_SOFDEC=
  SET USE_ADX=
  SET USE_AFTERFX=
  SET USE_SSBPLIB=
)

REM *** Sofdec ***
IF "%USE_SOFDEC%" EQU "" (
  ECHO Sofdec傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_SOFDEC/\/\/&/" ^
              -i~ app.h && (DEL *~)
  SET USE_ADX=
)

REM *** ADX ***
IF "%USE_ADX%" EQU "" (
  ECHO ADX傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_ADX/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** AfterEffects ***
IF "%USE_AFTERFX%" EQU "" (
  ECHO AfterEffects傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_AFTERFX/\/\/&/" ^
              -i~ app.h && (DEL *~)
  onigsed.exe -e "/^SOURCE=\.\\grp\\AfxBin\.bin/,/^$/d" ^
              -e "/^USERDEP/{s/\"grp\\EnmAfxBin\.txt\"[[:blank:]]*//g}" ^
              -i~ %PROJECT%.dsp && (DEL *~)
  onigsed.exe -e "s/^#include \"grp\\EnmAfxBin\.txt\"/\/\/&/" ^
              -i~ txt\EnmDef.txt txt\RegTbl.txt && (DEL txt\*~)
  REM //AfxBin儕僜乕僗傪嶲徠偟偰偄傞晹暘傪僐儊儞僩傾僂僩偟傑偡丅
  onigsed.exe -e "s/^AFXBIN/\/\/&/" ^
              -i~ %PROJECT%.rc && (DEL *~)
  onigsed.exe -e "s/.*TBL_AfxSeqNo.*/\/\/&/" ^
              -i~ app.c work.h && (DEL *~)
)

REM *** ssbpLib ***
IF "%USE_SSBPLIB%" EQU "" (
  ECHO ssbpLib傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_SSBPLIB/\/\/&/" ^
              -i~ app.h && (DEL *~)
  RMDIR /S /Q ssbp
)

REM *** GDI+ ***
IF "%USE_GDIPLUS%" EQU "" (
  ECHO GDI+傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_GDIPLUS/\/\/&/" ^
              -i~ app.h && (DEL *~)
) ELSE (
  SET APP_AS_CPP=1
)

REM *** Nuklear ***
IF "%USE_NUKLEAR%" EQU "" (
  ECHO Nuklear傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_NUKLEAR/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** Lua ***
IF "%USE_LUA%" EQU "" (
  ECHO Lua傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_LUA/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** ActiveTcl ***
IF "%USE_ACTIVETCL%" EQU "" (
  ECHO ActiveTcl傪嶍彍偟傑偡丅
  onigsed.exe -e "s/^#define USE_ACTIVETCL/\/\/&/" ^
              -i~ app.h && (DEL *~)
)

REM *** 傾僾儕働乕僔儑儞傪扨弮偵偡傞 ***
IF "%SIMPLIFY%" NEQ "" (
  ECHO 傾僾儕働乕僔儑儞傪扨弮偵偟傑偡丅
  onigsed.exe -e "/^\/\/{{TEST/,/^\/\/}}TEST/d" ^
              -i~ app.c cpp.cpp && (DEL *~)
  onigsed.exe -e "s/^#define DUALSCREEN/\/\/&/" ^
              -i~ Define.h && (DEL *~)
)

REM *** 儕僜乕僗僼傽傿儖偲僨乕僞僼傽傿儖傪嶍彍偡傞 ***
IF "%DEL_RESOURCE_DATA%" NEQ "" (
  ECHO 儕僜乕僗僼傽傿儖偲僨乕僞僼傽傿儖傪嶍彍偟傑偡丅
  DEL resource.h
  DEL *.rc
  DEL *.ico
  DEL *.manifest
  DEL Layout.*
  DEL Define.*
  DEL Struct.*
  DEL Const.*
  DEL MkCpk.bat
  DEL MkDxa.bat
  RMDIR /S /Q txt
  onigsed.exe -e "s/^#include \"resource.h\"/\/\/&/" ^
              -i~ app.h && (DEL *~)
  onigsed.exe -e "/^\/\/{{DATA/,/^\/\/}}DATA/d" ^
              -i~ app.h app.c work.h && (DEL *~)
  REM "Data Files"偺Group傪嶍彍偡傞慜偵丄妋幚偵"grp"偲"snd"偺Group傪嶍彍偡傞昁梫偑桳傝傑偡丅
  REM '# Begin Group "Data Files"'乣'# End Group'偺拞偵丄'# Begin Group "grp"'乣'# End Group'偲'# Begin Group "snd"'乣'# End Group'偑僱僗僩偟偰偄傞偐傜偱偡丅
  REM 傕偟"grp"偲"snd"偺Group傪嶍彍偡傞慜偵"Data Files"偺Group傪嶍彍偡傞偲丄"grp"枖偼"snd"偺'End Group'傪岆偭偰"Data Files"偺'End Group'偲尒側偟偰偟傑偄傑偡丅
  REM 壓婰偺傛偆偵彂偄偰偍偗偽丄僱僗僩偟偨嬫娫撪偱偼1峴栚,枖偼,2峴栚偺'd'僐儅儞僪偵傛偭偰3峴栚埲崀偺張棟偼峴傢傟偢丄婜懸捠傝偺寢壥偵側傝傑偡丅
  onigsed.exe -e "/^# Begin Group \"grp\"/,/^# End Group/d" ^
              -e "/^# Begin Group \"snd\"/,/^# End Group/d" ^
              -e "/^# Begin Group \"Data Files\"/,/^# End Group/d" ^
              -e "/^# Begin Group \"Resource Files\"/,/^# End Group/d" ^
              -i~ %PROJECT%.dsp && (DEL *~)
)

REM *** app.c傪app.cpp偵曄峏偡傞 ***
IF "%APP_AS_CPP%" NEQ "" (
  ECHO app.c傪app.cpp偵曄峏偟傑偡丅
  REN  app.c  app.cpp
  onigsed.exe -e "s/app\.c/app\.cpp/g" ^
              -i~ app.h %PROJECT%.dsp && (DEL *~)
)

REM *** 僾儘僕僃僋僩僼僅儖僟傪clip僼僅儖僟偺椬偵抲偔傛偆偵憡懳僷僗傪曄峏偡傞 ***
IF "%MOVE_DIR%" NEQ "" (
  ECHO 憡懳僷僗傪曄峏偟傑偡丅
  onigsed.exe -e "s/\.\./\.\.\\clip/g" ^
              -i~ %PROJECT%.dsp && (DEL *~)
)

REM *** 偙偺僶僢僠僼傽僀儖傪嶍彍偡傞 ***
DEL %0
