@echo off
rem -------------------------------------------------------------------------
rem Nextmidas source tree directory changer
rem @author Jeff Schoen, Neon Ngo
rem @version $Id: nmd.bat,v 1.10 2009/09/11 21:24:39 ntn Exp $
rem -------------------------------------------------------------------------
if ["%2"] == [""] goto NO_OPT
  set NM_OPT=%2
  goto HAS_OPT
:NO_OPT
  set NM_OPT=sys
  goto HAS_OPT
:HAS_OPT
if ["%1"] == [""] goto NO_DIR
  set NM_DIR=%1
  if /I ["%NM_DIR%"] == ["aux"]  goto AUX
  if /I ["%NM_DIR%"] == ["home"] goto HOME
  if /I ["%NM_OPT%"] == ["os"]   goto OS
  call nmsfset opt.%NM_OPT% nmd_path
  if ["%nmd_path%"]==["NotFound"] set nmd_path=%NMROOT%
  cd "%nmd_path%\nxm\%NM_OPT%\%NM_DIR%"
  goto NO_DIR
:AUX
  rem Change to specified AUX directory
  rem Set AUX_NAME in the format of AUX.<aux_name>, eg. AUX.1
  set AUX_NAME=%NM_DIR%.%2
  call nmsfset %AUX_NAME% NMD_PATH
  if ["%NMD_PATH%"]==["NotFound"] ( 
    echo %0: %AUX_NAME% not defined.
  ) else (
    rem Replace "+" with username and set it in DEST_PATH
    rem SET has to be CALLed to allow a variable to be evaluated
    call set DEST_PATH=%%nmd_path:+=%USER%%%
    cd "%DEST_PATH%"
  )  
  goto NO_DIR
:HOME
  call nmsfset nmd_path env.home
  cd "%nmd_path%"
  goto NO_DIR  
:OS
  cd "%NMROOT%\os\%NM_DIR%"
  goto NO_DIR
:NO_DIR
set nmd_path=
@REM display current directory
cd