create.bat 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "FullScriptPath=%~dp0"
  4. set "FullExecPath=%cd%"
  5. set "Command=%1"
  6. if "%Command%" == "header" (
  7. call :write_header %2
  8. exit /b %errorlevel%
  9. ) else if "%Command%" == "source" (
  10. call :write_source %2
  11. exit /b %errorlevel%
  12. ) else if "%Command%" == "" (
  13. echo This is an utility for fast blank module creation.
  14. echo Please provide module path.
  15. exit /b
  16. )
  17. call :write_module %Command%
  18. exit /b %errorlevel%
  19. :write_module
  20. (
  21. set "CommandPath=%1"
  22. set "CommandPathUnix=!CommandPath:\=/!"
  23. if "!CommandPathUnix!" == "" (
  24. echo Provide module path.
  25. exit /b 1
  26. )
  27. echo Generating module !CommandPathUnix!..
  28. call %FullScriptPath%\create.bat header !CommandPathUnix!
  29. call %FullScriptPath%\create.bat source !CommandPathUnix!
  30. exit /b
  31. )
  32. :write_header
  33. (
  34. set "CommandPath=%1"
  35. set "CommandPathUnix=!CommandPath:\=/!"
  36. set "CommandPathWin=!CommandPath:/=\!"
  37. if "!CommandPathUnix!" == "" (
  38. echo Provide header path.
  39. exit /b 1
  40. ) else if exist "!CommandPathWin!.h" (
  41. echo This header already exists.
  42. exit /b 1
  43. )
  44. echo Generating header !CommandPathUnix!.h..
  45. mkdir "!CommandPathWin!.h"
  46. rmdir "!CommandPathWin!.h"
  47. call :write_comment !CommandPathWin!.h
  48. set "header1=#pragma once"
  49. (
  50. echo !header1!
  51. echo.
  52. )>> "!CommandPathWin!.h"
  53. exit /b
  54. )
  55. :write_source
  56. (
  57. set "CommandPath=%1"
  58. set "CommandPathUnix=!CommandPath:\=/!"
  59. set "CommandPathWin=!CommandPath:/=\!"
  60. if "!CommandPathUnix:~-4!" == "_mac" (
  61. set "CommandExt=mm"
  62. ) else (
  63. set "CommandExt=cpp"
  64. )
  65. if "!CommandPathUnix!" == "" (
  66. echo Provide source path.
  67. exit /b 1
  68. ) else if exist "!CommandPathWin!.!CommandExt!" (
  69. echo This source already exists.
  70. exit /b 1
  71. )
  72. echo Generating source !CommandPathUnix!.!CommandExt!..
  73. mkdir "!CommandPathWin!.!CommandExt!"
  74. rmdir "!CommandPathWin!.!CommandExt!"
  75. call :write_comment !CommandPathWin!.!CommandExt!
  76. set "quote="""
  77. set "quote=!quote:~0,1!"
  78. set "source1=#include !quote!!CommandPathUnix!.h!quote!"
  79. (
  80. echo !source1!
  81. echo.
  82. )>> "!CommandPathWin!.!CommandExt!"
  83. exit /b
  84. )
  85. :write_comment
  86. (
  87. set "Path=%1"
  88. (
  89. echo // This file is part of Desktop App Toolkit,
  90. echo // a set of libraries for developing nice desktop applications.
  91. echo //
  92. echo // For license and copyright information please follow this link:
  93. echo // https://github.com/desktop-app/legal/blob/master/LEGAL
  94. echo //
  95. )> "!Path!"
  96. exit /b
  97. )