@echo off

set merge=1
set preprep=1
set blox=1
set program=XNFMERGE
set log=MRG
set noblox=0
set design=
set parttype=

if "%1" == "" goto help 

echo.  
echo ********************************************** 
echo XBLOX2M1 Version 1.0PC 
echo ********************************************** 
echo.  
echo.      > xblox2m1.log
echo **********************************************  >> xblox2m1.log
echo XBLOX2M1 Version 1.0PC                          >> xblox2m1.log
echo **********************************************  >> xblox2m1.log
echo.                                                >> xblox2m1.log

if not "%XACT%" == "" goto xactset
  echo.
  echo ERROR! XACT environment variable not set!
  echo. >> xblox2m1.log
  echo ERROR! XACT environment variable not set! >> xblox2m1.log
  goto unsetvar
:xactset




:arguments
If "%1" == "" goto endarguments
If "%1" == "-p" goto dashp
If "%1" == "-noblox" goto noblox
If "%1" == "-h" goto help
If "%1" == "-help" goto help
If "%1" == "-x" goto dashx
Set design=%1
shift
Goto arguments


:dashp
shift
set parttype=%1
shift
goto arguments 

:noblox
set noblox=1
shift
goto arguments

:dashx
shift
if "%1" == "xff" set merge=0
if "%1" == "xtg" set merge=0
if "%1" == "xtg" set preprep=0
if "%1" == "XFF" set merge=0
if "%1" == "XTG" set merge=0
if "%1" == "XTG" set preprep=0
shift
goto arguments
:endarguments

if "%design%" == "" goto designun
Echo Setting Design to : "%design%"
echo Setting Design to : "%design%" >> xblox2m1.log

if "%parttype%" == "" goto nopart
echo Setting Part to:   "%parttype%"
echo Setting Part to:   "%parttype%" >> xblox2m1.log
goto part

:nopart
echo WARNING: Part Type not specified on command line. 
echo          Assuming part type specified in source XNF file.
echo WARNING: Part Type not specified on command line. >> xblox2m1.log 
echo          Assuming part type specified in source XNF file. >> xblox2m1.log

:part

if "%noblox%" == "1" set blox=0
if "%noblox%" == "1" set preprep=0

if "%merge%" == "0" goto xpreprep
:xmerge
    echo. 
    echo ***********************************
    echo Invoking XNFMERGE......    
    echo ***********************************
    echo.  
    echo.
    echo. >> xblox2m1.log
    echo *********************************** >> xblox2m1.log
    echo Invoking XNFMERGE......             >> xblox2m1.log
    echo *********************************** >> xblox2m1.log
    echo.                                    >> xblox2m1.log
    echo.                                    >> xblox2m1.log

    If "%parttype%" == "" goto xmergepart
:mergepart
    xnfmerge %design% -p %parttype% 
    if errorlevel 1 goto error
    goto xpreprep
:xmergepart
    xnfmerge %design%               
    if errorlevel 1 goto error


:xpreprep
if "%preprep%" == "0" goto bloxx
    echo.  
    echo ***********************************  
    echo Invoking Pre-XBLOX XNFPREP......  
    echo ***********************************  
    echo.  
    echo.
    echo.                           >> xblox2m1.log
    echo ***********************************  >> xblox2m1.log
    echo Invoking Pre-XBLOX XNFPREP......     >> xblox2m1.log
    echo ***********************************  >> xblox2m1.log
    echo.                                     >> xblox2m1.log
    echo.                                     >> xblox2m1.log
    set program=XNFPREP
    set log=PRX
      xnfprep %design%                        
      if errorlevel 1 goto error
  

:bloxx
if "%blox%" == "0" goto xprep
    echo.  
    echo ***********************************  
    echo Invoking XBLOX...... 
    echo ***********************************  
    echo.  
    Echo.
    echo.                            >> xblox2m1.log
    echo ***********************************    >> xblox2m1.log
    echo Invoking XBLOX......                   >> xblox2m1.log
    echo ***********************************    >> xblox2m1.log
    echo.                                       >> xblox2m1.log
    Echo.                                       >> xblox2m1.log

    set program=XBLOX
    set log=BLX
      xblox %design%                           
      if errorlevel 1 goto error
  

:xprep
    echo.  
    echo ***********************************  
    echo Invoking XNFPREP......  
    echo *********************************** 
    echo.  
    echo.
    echo.                                      >> xblox2m1.log
    echo ***********************************   >> xblox2m1.log
    echo Invoking XNFPREP......                >> xblox2m1.log
    echo ***********************************   >> xblox2m1.log
    echo.                                      >> xblox2m1.log
    echo.                                      >> xblox2m1.log
    set program=XNFPREP
    set log=PRP
    if "%blox%" == "0" goto xprepnoblox
    xnfprep %design%.xg                        
    if errorlevel 1 goto error
    goto finished
:xprepnoblox
    xnfprep %design%.xff                       
    if errorlevel 1 goto error
    goto finished

    



:help
  echo XBLOX2M1 Version 1.0PC  
  echo.   
  echo "Usage: xblox2m1 [-noblox] [-p <partname>] [-x <xff|xtg>] <design_name> "  
  echo.   
  echo        -h               Print this help  
  echo        -p  partname     Use specified part type (Example: -p 4005epc84)  
  echo        -noblox          Do not invoke XBLOX. This is for non-XBLOX designs
  echo        -x               Extension of source. Default is XNF. Use this
  echo                         if XFF or XTG file is source.
  echo        design_name      Specify input XNF,XFF, or XTG file without
  echo                         extension. Use -x switch for XFF and XTG files.
  echo.         
  echo XBLOX2M1 will call XNFMERGE, XNFPREP, and XBLOX to translate a  
  echo XACT 5.x XBLOX-based XNF/XFF/XTG file to a XTF file, which can  
  echo be used by the M1 tool NGDBUILD. 
  echo.   
  echo. 
  goto unsetvar 

:designun

echo ERROR! Design name not specified
echo ERROR! Design name not specified  >> xblox2m1.log
goto end 

:error

  echo.   
  echo. 
  echo ERROR! "%program%" did not finish properly!
  echo        Check the PATH and XACT environment variables,
  echo        check the XBLOX2M1.LOG report file,
  echo        or look in the "%program%" ."%log%" report.
  echo.
  echo XBLOX2M1 has stopped with errors.
  echo.
  echo.                                                  >> xblox2m1.log
  echo.                                                  >> xblox2m1.log
  echo ERROR! "%program%" did not finish properly!       >> xblox2m1.log
  echo        Check the PATH and XACT environment variables,   >> xblox2m1.log
  echo        check the XBLOX2M1.LOG report file,              >> xblox2m1.log
  echo        or look in the "%program%" ."%log%" report.      >> xblox2m1.log
  echo.                                                        >> xblox2m1.log
  echo XBLOX2M1 has stopped with errors.                       >> xblox2m1.log
  echo.

Goto unsetvar

:finished
  echo. 
  echo. 
  echo XBLOX2M1 has completed. The XTF file may now be used by the M1
  echo tools. You may either:
  echo 1) Create a project in the Alliance/Foundation Series Design Manager,
  echo    using the XTF file as the source.
  echo 2) Run from command line as usual, using the XTF file as the source.
  echo    Example:
  echo        ngdbuild design.xtf -p 4020ehq240
  echo        .....continue on as normal (MAP->PAR->TRCE, etc) 
  echo. 
  echo.

  echo. >> xblox2m1.log
  echo. >> xblox2m1.log
  echo XBLOX2M1 has completed. The XTF file may now be used by the M1" >> xblox2m1.log
  echo tools. You may either:" >> xblox2m1.log
  echo 1) Create a project in the Alliance/Foundation Series Design Manager," >> xblox2m1.log 
  echo    using the XTF file as the source." >> xblox2m1.log
  echo 2) Run from command line as usual, using the XTF file as the source." >> xblox2m1.log
  echo    Example:" >> xblox2m1.log
  echo        ngdbuild design.xtf -p 4020ehq240" >> xblox2m1.log
  echo        .....continue on as normal (MAP->PAR->TRCE, etc) " >> xblox2m1.log
  echo.  >> xblox2m1.log
  echo.  >> xblox2m1.log


:unsetvar
set merge=
set preprep=
set blox=
set program=
set log=
set noblox=
set design=
set parttype=


 

:end


