' *********************************************************************
'                Example 1.0 by Troels Walsted Hansen
'
'               C -> HBasic conversion  (24.6.02) done
'               by Dámaso D. Estévez <ast_dde@yahoo.es>
'
'                        All Rights Reserved
' *********************************************************************

OPTION BASE 1

REM $include dos.bh
REM $include exec.bh
REM $include openurl.bh

LIBRARY OPEN "dos.library",36&
LIBRARY OPEN "exec.library",NULL&

' Version string / Cadena de versión
' ----------------------------------
strver$ = "$VER: Example 1.2 (26.6.02)"+CHR$(0)

' Template string / Cadena de sintaxis
' ------------------------------------
strtpt$ = "URL,SHOW/S,TOFRONT/S,NEWWIN/S,LAUNCH/S,LAUNCHPREFS/S"+CHR$(0)

' Simulating "enum" (C language)/ Simulando "enum" del lenguaje C
' ---------------------------------------------------------------
DIM args&(7)

A_URL%         = 1%
A_SHOW%        = 2%
A_TOFRONT%     = 3%
A_NEWWIN%      = 4%
A_LAUNCH%      = 5%
A_LAUNCHPREFS% = 6%
A_MAX%         = 7% ' The last-the end / El último-el final

' Others vars / Otras variables
' -----------------------------
DIM tags&(7)   

OpenURLBase& = NULL&
rda&         = NULL&

' ---------------------------------------------------------------------

' Initial hypothesys / Hipótesis inicial
' --------------------------------------
retval& = RETURN_FAIL&

' Opening the library / Abriendo la biblioteca
' --------------------------------------------
OpenURLBase& = OpenLibrary&(SADD("openurl.library"+CHR$(0)),1&)

IF OpenURLBase& THEN

	LIBRARY VARPTR "openurl.library",OpenURLBase&

    ' Marking the end / Señalando el final
    ' ------------------------------------
	args&(7) = 0&
	
	rda& = ReadArgs&(SADD(strtpt$),VARPTR(args&(1)),NULL&)

	IF rda& THEN

		IF args&(A_LAUNCHPREFS%) THEN

			IF PEEKW(OpenURLBase&+lib_Version%) < 3% THEN

				PRINT "LAUNCHPREFS requires openurl.library V3+"

			ELSE

				dummy&  = NULL&
				dummy&  = URL_LaunchPrefsApp&
				retval& = RETURN_OK&

			END IF
		
		ELSE

			IF args&(A_URL%) THEN

				TAGLIST VARPTR(tags&(1)), _
				  URL_Show&,         PEEKL(VARPTR(args&(A_SHOW%))), _
				  URL_BringToFront&, PEEKL(VARPTR(args&(A_TOFRONT%))),_
				  URL_NewWindow&,    PEEKL(VARPTR(args&(A_NEWWIN%))), _
				  URL_Launch&,       PEEKL(VARPTR(args&(A_LAUNCH%))), _
				  TAG_DONE&

				dummy& = NULL&
				dummy& = URL_OpenA&(PEEKL(VARPTR(args&(A_URL%))),VARPTR(tags&(1)))
				IF dummy& THEN retval& = RETURN_OK&

			ELSE

				PRINT "Either URL or LAUNCHPREFS must be specified"
				FreeArgs rda&

			END IF

		END IF

	ELSE

		dummy& = PrintFault&(IoErr&,SADD("Failed to parse arguments"+CHR$(0)))
	
	END IF

	LIBRARY VARPTR "openurl.library",0&
	CloseLibrary OpenURLBase&

ELSE

	PRINT "Requires openurl.library V1+"

END IF

PRINT PrintFault&(IoErr&,SADD("Failed to parse arguments"+CHR$(0)))

LIBRARY CLOSE

STOP retval&

' ---------------------------------------------------------------------
