#include "swis.h"

#include "Desk.KernelSWIs.h"
#include "Desk.SWI.h"
#include "Desk.Debug.h"
#include "Desk.Error2.h"


int	Desk_OS_ReadVarVal_GetLength( const char *varname)
{
int	r2;

Desk_Debug4_Printf( Desk_error_PLACE "Desk_OS_ReadVarVal_GetLength called for '%s'\n", varname);
/*
Desk_SWI(	5, 3, 
  	|*Desk_SWI_XOS_Bit+*|Desk_SWI_OS_ReadVarVal, 
  	varname, 0, -1, 0, 0,
  	NULL, NULL, &r2
  	);
*/
/*
_swix( OS_ReadVarVal, _INR(0,4)|_OUT(2),
	varname, 0, -1, 0, 0,
	&r2
	);
Doesn't work - _swix doesn't fill in return values after an error...
*/
	/* This may return with an error - this can be ignored (see PRMs 1-309,310).	*/

r2 = Desk_OS_ReadVarVal_GetLength_Raw( varname);

Desk_Debug_Printf( Desk_error_PLACE "OS_ReadVarVal returned r2=%i\n", r2);

if (r2>=0)	{
	Desk_Debug_Printf( Desk_error_PLACE "GetVarLen - '%s' doesn't exist\n", varname);
	Desk_Error2_HandleTextf( "Variable '%s' doesn't exist", varname);
	return -1;
	}

else	{
	Desk_Debug_Printf( Desk_error_PLACE "GetVarLen - returning %i\n", ~r2);
	return ~r2;
	}
}
