Exemplo n.º 1
0
/*
 * 	error_id(+Number, ?Message)
 *
 *		Returns the appropriate error message. Fails if the
 *		message string is empty or out of range, so that it
 *		can be used to check whether the given error exists.
 */
static int
p_error_id(value valn, type tagn, value vale, type tage)
{
    Error_If_Ref(tagn);
    Check_Output_String(tage);
    if (IsInteger(tagn))
    {
	if
	(
		valn.nint < 1
		||
		valn.nint >= MAX_ERRORS
		||
		!ErrorMessage[valn.nint]
	)
	{
		Fail_;
	}
	{
	    value v;
	    Cstring_To_Prolog(ErrorMessage[valn.nint], v);
	    Return_Unify_String(vale, tage, v.ptr);
	}
    }
    else if (IsAtom(tagn))
    {
	Return_Unify_String(vale, tage, DidString(valn.did));
    }
    else
    {
	Bip_Error(TYPE_ERROR);
    }
}
Exemplo n.º 2
0
static int
p_errno_id1(value sval, type stag)
{
    pword	pw;
    char	buf[1024];

    Check_Output_String(stag);

    Make_String(&pw, ec_os_err_string(ec_os_errno_, ec_os_errgrp_, buf, 1024));
    Return_Unify_Pw(sval, stag, pw.val, pw.tag);
}
Exemplo n.º 3
0
int
p_session_error_value(
		/* + */ value v_session, type t_session,
		/* + */ value v_code, type t_code,
		/* + */ value v_message, type t_message
		)
{
	int code;
	char * message;
	pword p;
	session_t * session;
	Prepare_Requests;

	Check_Output_Integer(t_code);
	Check_Output_String(t_message);
	Get_Typed_Object(v_session,t_session,&session_handle_tid,session);

	session_error_value(session, &code, &message);

	Make_String(&p,message);
	Request_Unify_Integer(v_code, t_code, code);
	Request_Unify_Pw(v_message, t_message, p.val, p.tag);
	Succeed;
}
Exemplo n.º 4
0
static int
p_substring(value val1, type tag1, value val2, type tag2, value valp, type tagp)
{
	char	*p1, *p2;
	word	length1, length2;
	word	i, j;

        /* string1 and string2 must be strings; posn an integer/variable. */ 

	Check_Output_Integer(tagp);
        Check_Output_String(tag1);
        Check_String(tag2);
	Error_If_Ref(tag1);

	length1 = StringLength(val1);
	length2 = StringLength(val2);

	if (!IsRef(tagp))
	{
		if (valp.nint <= 0 || valp.nint > length1 + 1)
		{
		    Bip_Error(RANGE_ERROR);
		}
		if (valp.nint > length1 - length2 + 1)
		{
		    Fail_;	/* string 2 is too long to match */
		}

		p1 = StringStart(val1) + valp.nint - 1;
		p2 = StringStart(val2);
		for(j = 0; j < length2; ++j)
		{
		    if (p1[j] != p2[j])
		    {
			Fail_;
		    }
		}
		Succeed_;
	}
	else
	{
		p1 = StringStart(val1);
		p2 = StringStart(val2);
		for (i = 1; i <= length1 - length2 + 1; i++)
		{
			/*
	         	 * search through p (i.e. string1) 'length2' characters
		 	 * at a time for val2.str (i.e. string2), till the end
		 	 * of string1. 
			 */ 
			for(j = 0; j < length2; ++j)
			{
			    if (p1[j] != p2[j])
				break;
			}
			if (j == length2)
			{
			    Return_Unify_Integer(valp, tagp, i);
			}
			p1++;
		}
		/* if not found, fail. */	
		Fail_;
	}	
}