create.bat 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "FullScriptPath=%~dp0"
  4. set "FullExecPath=%cd%"
  5. set "Command=%1"
  6. if "%Command%" == "test" (
  7. call :write_test %2
  8. exit /b %errorlevel%
  9. ) else if "%Command%" == "header" (
  10. call :write_header %2
  11. exit /b %errorlevel%
  12. ) else if "%Command%" == "source" (
  13. call :write_source %2
  14. exit /b %errorlevel%
  15. ) else if "%Command%" == "" (
  16. echo This is an utility for fast blank module creation.
  17. echo Please provide module path.
  18. exit /b
  19. )
  20. call :write_module %Command%
  21. exit /b %errorlevel%
  22. :write_module
  23. (
  24. set "CommandPath=%1"
  25. set "CommandPathUnix=!CommandPath:\=/!"
  26. if "!CommandPathUnix!" == "" (
  27. echo Provide module path.
  28. exit /b 1
  29. )
  30. echo Generating module !CommandPathUnix!..
  31. call create.bat header !CommandPathUnix!
  32. call create.bat source !CommandPathUnix!
  33. exit /b
  34. )
  35. :write_header
  36. (
  37. set "CommandPath=%1"
  38. set "CommandPathUnix=!CommandPath:\=/!"
  39. set "CommandPathWin=!CommandPath:/=\!"
  40. if "!CommandPathUnix!" == "" (
  41. echo Provide header path.
  42. exit /b 1
  43. ) else if exist "SourceFiles\!CommandPathWin!.h" (
  44. echo This header already exists.
  45. exit /b 1
  46. )
  47. echo Generating header !CommandPathUnix!.h..
  48. mkdir "SourceFiles\!CommandPathWin!.h"
  49. rmdir "SourceFiles\!CommandPathWin!.h"
  50. call :write_comment !CommandPathWin!.h
  51. set "header1=#pragma once"
  52. (
  53. echo !header1!
  54. echo.
  55. )>> "SourceFiles\!CommandPathWin!.h"
  56. exit /b
  57. )
  58. :write_source
  59. (
  60. set "CommandPath=%1"
  61. set "CommandPathUnix=!CommandPath:\=/!"
  62. set "CommandPathWin=!CommandPath:/=\!"
  63. if "!CommandPathUnix:~-4!" == "_mac" (
  64. set "CommandExt=mm"
  65. ) else (
  66. set "CommandExt=cpp"
  67. )
  68. if "!CommandPathUnix!" == "" (
  69. echo Provide source path.
  70. exit /b 1
  71. ) else if exist "SourceFiles\!CommandPathWin!.!CommandExt!" (
  72. echo This source already exists.
  73. exit /b 1
  74. )
  75. echo Generating source !CommandPathUnix!.!CommandExt!..
  76. mkdir "SourceFiles\!CommandPathWin!.!CommandExt!"
  77. rmdir "SourceFiles\!CommandPathWin!.!CommandExt!"
  78. call :write_comment !CommandPathWin!.!CommandExt!
  79. set "quote="""
  80. set "quote=!quote:~0,1!"
  81. set "source1=#include !quote!!CommandPathUnix!.h!quote!"
  82. (
  83. echo !source1!
  84. echo.
  85. )>> "SourceFiles\!CommandPathWin!.!CommandExt!"
  86. exit /b
  87. )
  88. :write_test
  89. (
  90. set "CommandPath=%1"
  91. set "CommandPathUnix=!CommandPath:\=/!"
  92. set "CommandPathWin=!CommandPath:/=\!"
  93. if "!CommandPathUnix!" == "" (
  94. echo Provide source path.
  95. exit /b 1
  96. ) else if exist "SourceFiles\!CommandPathWin!.cpp" (
  97. echo This source already exists.
  98. exit /b 1
  99. )
  100. echo Generating test !CommandPathUnix!.cpp..
  101. mkdir "SourceFiles\!CommandPathWin!.cpp"
  102. rmdir "SourceFiles\!CommandPathWin!.cpp"
  103. call :write_comment !CommandPathWin!.cpp
  104. set "quote="""
  105. set "quote=!quote:~0,1!"
  106. set "source1=#include !quote!catch.hpp!quote!"
  107. (
  108. echo !source1!
  109. echo.
  110. )>> "SourceFiles\!CommandPathWin!.cpp"
  111. exit /b
  112. )
  113. :write_comment
  114. (
  115. set "Path=%1"
  116. (
  117. echo /*
  118. echo This file is part of Telegram Desktop,
  119. echo the official desktop application for the Telegram messaging service.
  120. echo.
  121. echo For license and copyright information please follow this link:
  122. echo https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  123. echo */
  124. )> "SourceFiles\!Path!"
  125. exit /b
  126. )