1 | @echo off
|
---|
2 | setlocal ENABLEDELAYEDEXPANSION
|
---|
3 |
|
---|
4 | set DebugOutput=1
|
---|
5 | set ExampleComponent=ExampleComponent
|
---|
6 |
|
---|
7 | :argc
|
---|
8 | set argc=0
|
---|
9 | for %%x in (%*) do set /A argc+=1
|
---|
10 |
|
---|
11 | :usage
|
---|
12 | if %argC% lss 1 (
|
---|
13 | echo Usage:
|
---|
14 | echo %0 ^<componentName^>
|
---|
15 | goto:EOF
|
---|
16 | )
|
---|
17 |
|
---|
18 | :args
|
---|
19 | set _componentName=%1
|
---|
20 | set _componentDir=%_componentName%Component
|
---|
21 | call :UCase _componentDir _componentDirCaps
|
---|
22 | if %DebugOutput%==1 (
|
---|
23 | echo _componentName=%_componentName%
|
---|
24 | echo _componentDir=%_componentDir%
|
---|
25 | echo _componentDirCaps=%_componentDirCaps%
|
---|
26 | )
|
---|
27 |
|
---|
28 | :cmake
|
---|
29 | ::cmake %ExampleComponent% -DCOMPONENT_NAME:STRING=%_componentName%
|
---|
30 | ::if %ERRORLEVEL% GEQ 1 (
|
---|
31 | :: echo CMake must be installed and added to PATH
|
---|
32 | :: goto:EOF
|
---|
33 | ::)
|
---|
34 | ::goto:EOF
|
---|
35 |
|
---|
36 | :dir
|
---|
37 | if exist %_componentDir% (
|
---|
38 | echo Directory %_componentDir% exists already!
|
---|
39 | echo Please delete it first and retry.
|
---|
40 | goto:EOF
|
---|
41 | )
|
---|
42 | mkdir %_componentDir%
|
---|
43 | if not exist %_componentDir% (
|
---|
44 | echo Directory %_componentDir% could not be created!
|
---|
45 | goto:EOF
|
---|
46 | )
|
---|
47 |
|
---|
48 | :copy
|
---|
49 | ::xcopy /S %ExampleComponent% %_componentDir%
|
---|
50 | copy %ExampleComponent%\CMakeLists.txt %_componentDir%\CMakeLists.txt
|
---|
51 | copy %ExampleComponent%\%ExampleComponent%.cpp %_componentDir%\%_componentDir%.cpp
|
---|
52 | copy %ExampleComponent%\%ExampleComponent%.h %_componentDir%\%_componentDir%.h
|
---|
53 | copy %ExampleComponent%\%ExampleComponent%Config.h %_componentDir%\%_componentDir%Config.h
|
---|
54 |
|
---|
55 | :substitute
|
---|
56 | set SedFile=NewComponent.sed
|
---|
57 | set _currentDate=%DATE%
|
---|
58 | :: escape / character
|
---|
59 | set _currentDate=!_currentDate:/=\/!
|
---|
60 | :: take first 8 characters (without milliseconds)
|
---|
61 | set _currentTime=%TIME:~0,8%
|
---|
62 | set _userName=%USERNAME%
|
---|
63 |
|
---|
64 | echo s/${^<PROJECT_NAME^>}/%_componentDir%/g > %SedFile%
|
---|
65 | echo s/${^<PROJECT_NAME_CAPS^>}/%_componentDirCaps%/g >> %SedFile%
|
---|
66 | echo s/${^<CURRENT_DATE^>}/%_currentDate%/g >> %SedFile%
|
---|
67 | echo s/${^<CURRENT_TIME^>}/%_currentTime%/g >> %SedFile%
|
---|
68 | echo s/${^<CURRENT_DATETIME^>}/%_currentDate% %_currentTime%/g >> %SedFile%
|
---|
69 | echo s/${^<USERNAME^>}/%_userName%/g >> %SedFile%
|
---|
70 |
|
---|
71 | for /r . %%f in (%_componentDir%\*) do (
|
---|
72 | if %DebugOutput%==1 (
|
---|
73 | echo %%f
|
---|
74 | )
|
---|
75 | sed -f %SedFile% %%f > %%f.tmp
|
---|
76 | )
|
---|
77 |
|
---|
78 | for /r . %%f in (%_componentDir%\*.tmp) do (
|
---|
79 | if %DebugOutput%==1 (
|
---|
80 | echo %%f
|
---|
81 | )
|
---|
82 | mv %%f %%~pnf
|
---|
83 | )
|
---|
84 |
|
---|
85 | goto:EOF
|
---|
86 |
|
---|
87 | :LCase
|
---|
88 | :UCase
|
---|
89 | :: Converts to upper/lower case variable contents
|
---|
90 | :: Syntax: CALL :UCase _VAR1 _VAR2
|
---|
91 | :: Syntax: CALL :LCase _VAR1 _VAR2
|
---|
92 | :: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
|
---|
93 | :: _VAR2 = NAME of variable to hold the converted value
|
---|
94 | :: Note: Use variable NAMES in the CALL, not values (pass "by reference")
|
---|
95 |
|
---|
96 | SET _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
---|
97 | SET _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
|
---|
98 | SET _Lib_UCase_Tmp=!%1!
|
---|
99 | IF /I "%0"==":UCase" SET _Abet=%_UCase%
|
---|
100 | IF /I "%0"==":LCase" SET _Abet=%_LCase%
|
---|
101 | FOR %%Z IN (%_Abet%) DO (
|
---|
102 | SET _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
|
---|
103 | )
|
---|
104 | SET %2=%_Lib_UCase_Tmp%
|
---|
105 | GOTO:EOF
|
---|