@echo off

:start
echo ---DEBUG MODE START---
cd ..

rem 初期化
set USER_INPUT_FNAME=
set USER_INPUT_STATE=
set USER_INPUT_FUNC=

set str1=senni_
set str2=-
set str3=.txt
set OUT_FILENAME=%date%%str2%%time%
set OUT_FILENAME=%OUT_FILENAME::=%
set OUT_FILENAME=%OUT_FILENAME:.=%
set OUT_FILENAME=%OUT_FILENAME:/=%
set OUT_FILENAME=%OUT_FILENAME: =%
set OUT_FILENAME=%str1%%OUT_FILENAME%%str3%

rem TargetPrograms内のファイル名一覧を取得する
cd TargetPrograms\
echo TARGET:
for %%F in  (*.c) do (
echo %%F
set FILE_NAME=%%F
)
cd ..

rem 解析対象のファイル名を入力する
set /a counter=0
for %%A in (TargetPrograms\*) do (if exist %%A (set /a counter=counter+1))

if %counter% equ 0 (
echo Please Put the files in [TargetPrograms]
echo ---DEBUG MODE END---
pause
exit
) else if %counter% == 1 (
set USER_INPUT_FNAME=%FILE_NAME%
) else (
set /P USER_INPUT_FNAME="Please Input C_FILE_NAME(ex.fcal_mode3.c)"
)

rem 入力要求(状態変数名）
echo;
set /P USER_INPUT_STATE="Please Input STATE_NAME (ex.g_PushStatus)"

rem 入力要求
echo;
set /P USER_INPUT_FUNC="Please Input FUNC_NAME (ex.GLOBAL)"

echo;
echo CURRENT_PATH: %CD% > debug\%OUT_FILENAME%
echo FILE_NAME: %USER_INPUT_FNAME% >> debug\%OUT_FILENAME%
echo STATE_NAME: %USER_INPUT_STATE% >> debug\%OUT_FILENAME%
echo ; >> debug\%OUT_FILENAME%

rem tempへのコピー
set REPLACE_FNAME=%USER_INPUT_FNAME:.c=___o%
echo %REPLACE_FNAME%
xcopy /e /y temp\%REPLACE_FNAME% temp >nul 2>&1


echo;
echo Your LOG FILE is %OUT_FILENAME% 
echo;

rem 状態遷移表作成処理の実行
echo Now Processing... (Please Wait for 5 seconds)
start /min debug\tmp\timer_senni.bat
programs\senni.exe --jotai_value %USER_INPUT_STATE% --func %USER_INPUT_FUNC% --source_file %REPLACE_FNAME% >> debug\%OUT_FILENAME% 2>&1

echo ---DEBUG MODE END---

pause>nul