@echo off

REM !---------------------------------------------------------
REM ! @(#)Z 1.10.1.2 com/src/tools/reg1part.bat, odinstall, od96nt, odnt9712d 97/03/21 17:27:03 (96/11/12 13:39:48)
REM ! reg1part.bat
REM ! OpenDoc tool to add a Part to the Part Registry
REM !---------------------------------------------------------

REM !-----------------------------------------------------------
REM ! Do we start with ODBASE set?
REM !-----------------------------------------------------------

if "%ODBASE%x" == "x" goto setODBASE
goto Step1

REM !-----------------------------------------------------------
REM ! handle case where ODBASE is not set
REM !-----------------------------------------------------------

:setODBASE

echo The environment variable ODBASE has not been set.
echo Please ensure that all OpenDoc environment variables are properly set
echo before attempting to run reg1part.
goto Done

REM !-----------------------------------------------------------
REM ! Initialize internal variables
REM !
REM ! BADCMD is used to force 'errorlevel' before we exit
REM ! GOODCMD is used to clear 'errorlevel' before we exit
REM !
REM !-----------------------------------------------------------

:Step1

REM !-----------------------------------------------------------
REM ! handle case where %1 is null
REM !-----------------------------------------------------------
if "%1x" == "x" goto badArgs

set BADCMD=cmd /c a_likely_non_existent_command ^>nul: 2^>^&1
set GOODCMD=cmd /c dir ^>nul: 2^>^&1
set BLANKLINE=echo.
set blank=
set ODREGPRT=odregprt
set SC=%SOMBASE%\bin\sc.exe
set CLASS=%1

echo %blank%    OpenDoc Part Registration Command


REM !-----------------------------------------------------------
REM ! Were we called with a named IDL as second parm?
REM ! If not, compute a default name
REM !-----------------------------------------------------------

if "%2x" == "x" goto defaultIDL
set IDLNAME=%2
goto Step2

:defaultIDL

set IDLNAME=%CLASS%.idl
echo %blank%    Assuming default IDL name %IDLNAME%.

REM !-----------------------------------------------------------
REM ! Invoke the SOM Compiler
REM !-----------------------------------------------------------

:Step2

echo %blank%    Class Name: %CLASS%
echo %blank%    Invoking SOM Compiler to update OpenDoc.ir
:Step2A
echo %blank%    IDL Name:   %IDLNAME%

set reg1partSMINCLUDE=%SMINCLUDE%
set SMINCLUDE=
%SC% -sir -u -mnolock -ESMINCLUDE="" -ESOMIR="%ODCFG%\opendoc.ir" -p -c -I. -I%SOMBASE%\include -D_PLATFORM_WIN32_ -D_PLATFORM_NT_ -I%ODBASE%\include -I%ODSRC%\include %IDLNAME%
set SMINCLUDE=%reg1partSMINCLUDE%

%if errorlevel 1 goto Error1
if "%3" == "" goto Step3
set IDLNAME=%3
shift
goto Step2A

REM !-----------------------------------------------------------
REM ! Register the Part
REM !-----------------------------------------------------------

:Step3

echo %blank%    Using %ODREGPRT% to register the part.

%ODREGPRT% %CLASS% > nul: 2>&1

%if errorlevel 1 goto Error2

:Step4
goto Done

REM !-----------------------------------------------------------
REM ! Error Handler for Bad SOM Compiler invocation
REM ! Print a message, and force an exit with an errorlevel set
REM !-----------------------------------------------------------

:Error1

echo %blank%    SOM Compiler returned an error.
%BADCMD%
goto Done


REM !-----------------------------------------------------------
REM ! Error Handler for Bad SOM Compiler invocation
REM ! Print a message, and force an exit with an errorlevel set
REM !-----------------------------------------------------------

:Error2

echo %blank%    %ODREGPRT% returned an error.
%BADCMD%
goto Done

:badArgs

echo Usage: reg1part Classname [IDLname, IDLname,...]
goto Done

REM !-----------------------------------------------------------
REM ! End of Program
REM !-----------------------------------------------------------

:Done

