init.bat 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. @echo off
  2. rem #########################################################################
  3. rem
  4. rem MODULE: GRASS Initialization
  5. rem AUTHOR(S): Paul Kelly
  6. rem
  7. rem PURPOSE: The source file for this batch script is lib/init/init.bat.
  8. rem It sets up some environment variables, default GISRC file
  9. rem if necessary, etc. prior to starting GRASS proper.
  10. rem It is intended to be a native Windows replacement for Init.bat,
  11. rem but does not (yet) contain all the same functionality.
  12. rem
  13. rem In particular also, GUI mode prints nothing to the terminal
  14. rem and does not expect or provide an interactive terminal
  15. rem running in addition to the GUI display.
  16. rem
  17. rem COPYRIGHT: (C) 2006, 2008 by the GRASS Development Team
  18. rem
  19. rem This program is free software under the GNU General Public
  20. rem License (>=v2). Read the file COPYING that comes with GRASS
  21. rem for details.
  22. rem
  23. rem #########################################################################
  24. set SAVEPATH=%PATH%
  25. rem DON'T include scripts directory in PATH - .bat files in bin directory
  26. rem are used to run scripts on Windows
  27. if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\bin;%WINGISBASE%\lib;%PATH%
  28. if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\bin;%WINGISBASE%\lib;%GRASS_ADDON_PATH%;%PATH%
  29. set GRASS_VERSION=GRASS_VERSION_NUMBER
  30. if "%HOME%"=="" set HOME=%USERPROFILE%
  31. set WINGISRC=%HOME%\.grassrc7
  32. rem Make sure %GISRC% is set so g.dirseps will work
  33. rem (not actually used)
  34. set GISRC=junk
  35. rem Generate GISBASE by converting dirsep characters from \ to /
  36. FOR /F "usebackq delims==" %%i IN (`g.dirseps -g "%WINGISBASE%"`) DO @set GISBASE=%%i
  37. set GRASS_PAGER=more
  38. if "%GRASS_WISH%"=="" set GRASS_WISH=wish.exe
  39. if "%GRASS_SH%"=="" set GRASS_SH=c:\msys\1.0\bin\sh.exe
  40. rem Should do something with "assoc .html" and ftype here but would require
  41. rem a new g.manual.bat too so leaving it like this for now...
  42. if "%GRASS_HTML_BROWSER%"=="" set GRASS_HTML_BROWSER=%SYSTEMDRIVE%/PROGRA~1/INTERN~1/IEXPLORE.EXE
  43. if "%GRASS_PROJSHARE%"=="" set GRASS_PROJSHARE=CONFIG_PROJSHARE
  44. if "%1" == "-version" goto displaylicence
  45. if "%1" == "-v" goto displaylicence
  46. if "%1" == "-text" goto settextmode
  47. :aftertextcheck
  48. if "%1" == "-tcltk" goto setguimode
  49. if "%1" == "-gui" goto setguimode
  50. :afterguicheck
  51. if exist "%WINGISRC%" goto aftercreategisrc
  52. rem Create an initial GISRC file based on current directory
  53. "%WINGISBASE%\etc\echo" "GISDBASE: %CD%" | g.dirseps -g > "%WINGISRC%"
  54. "%WINGISBASE%\etc\echo" "LOCATION_NAME: <UNKNOWN>" >> "%WINGISRC%"
  55. "%WINGISBASE%\etc\echo" "MAPSET: <UNKNOWN>" >> "%WINGISRC%"
  56. :aftercreategisrc
  57. rem Now set the real GISRC
  58. FOR /F "usebackq delims==" %%i IN (`g.dirseps -g "%WINGISRC%"`) DO @set GISRC=%%i
  59. rem Set GRASS_GUI
  60. if "%GRASS_GUI%" == "" (
  61. FOR /F "usebackq delims==" %%i IN (`g.gisenv "get=GRASS_GUI"`) DO @set GRASS_GUI=%%i
  62. ) else (
  63. g.gisenv "set=GRASS_GUI=%GRASS_GUI%"
  64. )
  65. rem Set tcltk as default if not specified elsewhere
  66. if "%GRASS_GUI%"=="" set GRASS_GUI=tcltk
  67. "%WINGISBASE%\etc\clean_temp" > NUL:
  68. if "%GRASS_GUI%"=="text" goto text
  69. if not "%GRASS_WISH%"=="" (
  70. "%GRASS_WISH%" "%WINGISBASE%\etc\gis_set.tcl"
  71. ) else (
  72. "%WINGISBASE%\etc\gis_set.tcl"
  73. )
  74. rem This doesn't seem to work; don't understand return codes from gis_set.tcl PK
  75. rem if return ok, gis.m start:
  76. if %errorlevel% == 2 goto exitinit
  77. if not "%GRASS_WISH%"=="" (
  78. "%GRASS_WISH%" "%WINGISBASE%\etc\gm\gm.tcl"
  79. ) else (
  80. "%WINGISBASE%\etc\gm\gm.tcl"
  81. )
  82. "%WINGISBASE%\etc\clean_temp" > NUL:
  83. goto exitinit
  84. :text
  85. "%WINGISBASE%\etc\set_data"
  86. if %errorlevel% == 1 goto exitinit
  87. rem Get LOCATION_NAME to use in prompt
  88. FOR /F "usebackq delims==" %%i IN (`g.gisenv "get=LOCATION_NAME"`) DO @set LOCATION_NAME=%%i
  89. type "%WINGISBASE%\etc\welcome"
  90. "%WINGISBASE%\etc\echo" ""
  91. "%WINGISBASE%\etc\echo" "GRASS homepage: http://grass.osgeo.org/"
  92. "%WINGISBASE%\etc\echo" "This version running thru: Windows Command Shell (cmd.exe)"
  93. "%WINGISBASE%\etc\echo" "When ready to quit enter: exit"
  94. "%WINGISBASE%\etc\echo" "Help is available with the command: g.manual -i"
  95. "%WINGISBASE%\etc\echo" "See the licence terms with: g.version -c"
  96. "%WINGISBASE%\etc\echo" ""
  97. prompt GRASS %GRASS_VERSION% $C%LOCATION_NAME%$F:$P $G
  98. cmd.exe
  99. prompt
  100. goto exitinit
  101. :displaylicence
  102. type "%WINGISBASE%\etc\license"
  103. goto exitinit
  104. :settextmode
  105. set GRASS_GUI=text
  106. shift
  107. goto aftertextcheck
  108. :setguimode
  109. set GRASS_GUI=tcltk
  110. shift
  111. goto afterguicheck
  112. :exitinit
  113. set PATH=%SAVEPATH%
  114. set SAVEPATH=
  115. exit /b