@Echo Off
Cls

Set srcFolder=src
Set newSrcFolder=srcPerf
Set targetFile=%newSrcFolder%\sources.cpp
Echo ____________________________________________________________
Echo.
Echo             Unique C and CPP file generator...
Echo ____________________________________________________________
Echo.
REM Suppression 2 fichiers déjà existant
If Exist %newSrcFolder%         Rd /s /q %newSrcFolder%
If Not Exist %newSrcFolder%     MkDir %newSrcFolder%
If Exist %targetFile%           Del %targetFile%
Echo // Sources C++>%targetFile%
SetLocal EnableDelayedExpansion
Set cCount=0
Set cppCount=0
REM Tous les fichiers .c
Echo extern "C">>%targetFile%
Echo {>>%targetFile%
Echo/|Set /p=C   Files 
For /F %%i In ('Dir %srcFolder%\*.c /B /A-D /S') Do (
    Set /A cCount+=1
    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo //############################>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //######### FILE : %%j>>%targetFile%
    Echo.>>%targetFile%
    Echo.>>%targetFile%

    More %%i>>%targetFile%

    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo //######### FILE : %%j>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //############################>>%targetFile%
    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo/|Set /p=.
)
Echo }>>%targetFile%
Echo.
Echo/|Set /p=C++ Files 
REM Tous les fichiers .cpp
For /F %%i In ('Dir %srcFolder%\*.cpp /B /A-D /S') Do (
    Set /A cppCount+=1
    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo //############################>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //######### FILE : %%j>>%targetFile%
    Echo.>>%targetFile%
    Echo.>>%targetFile%

    More %%i>>%targetFile%

    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo //######### FILE : %%j>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //#########                 ##>>%targetFile%
    Echo //############################>>%targetFile%
    Echo.>>%targetFile%
    Echo.>>%targetFile%
    Echo/|Set /p=.
)

Echo.
Echo ____________________________________________________________
Echo.
Echo   - Report :
Echo       - !cCount! C files appended...
Echo       - !cppCount! C++ files appended...
EndLocal

REM Copie des fichiers d'entête
Echo ____________________________________________________________
Echo.
Echo   - Header files copy...
For /F %%i In ('Dir %srcFolder% /B /AD') Do (
    REM Retrait des ".svn"
    If "%%i"==".svn" (
        REM Rien !
    ) Else (
        If Not Exist %newSrcFolder%\%%i     Mkdir %newSrcFolder%\%%i
        REM Fichiers ".h" et ".hpp"
        If Exist %srcFolder%\%%i\*.hpp      Copy /Y %srcFolder%\%%i\*.hpp %newSrcFolder%\%%i>nul
        If Exist %srcFolder%\%%i\*.h        Copy /Y %srcFolder%\%%i\*.h %newSrcFolder%\%%i>nul
        If Exist %srcFolder%\%%i\*.hpp      Copy /Y %srcFolder%\%%i\*.hpp %newSrcFolder%>nul
        If Exist %srcFolder%\%%i\*.h        Copy /Y %srcFolder%\%%i\*.h %newSrcFolder%>nul
    )
)
If Exist %srcFolder%\*.hpp  Copy /Y %srcFolder%\*.hpp %newSrcFolder%>nul
If Exist %srcFolder%\*.h    Copy /Y %srcFolder%\*.h %newSrcFolder%>nul

Echo ____________________________________________________________
Echo.
Echo Unique files generation done !
Echo ____________________________________________________________
Echo.
