1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
12 #include "sjme/error.h"
14 sjme_errorCode
sjme_error_also(
15 sjme_errorCode error
, sjme_errorCode expression
)
17 /* Keep existing error. */
18 if (sjme_error_is(error
))
21 /* Return the error from the expression. */
25 sjme_errorCode
sjme_error_alsoV(
26 sjme_errorCode error
, ...)
29 sjme_errorCode result
, now
;
34 /* Read in until the end of sequence. */
39 now
= va_arg(va
, sjme_errorCode
);
42 if (now
== SJME_NUM_ERROR_CODES
)
45 /* Perform the normal also call. */
46 result
= sjme_error_also(result
, result
);
52 /* Return the given result. */
56 sjme_errorCode
sjme_error_alsoVEnd(void)
58 /* The number of error codes is considered the end. */
59 return SJME_NUM_ERROR_CODES
;
62 sjme_jboolean
sjme_error_is(
65 return error
< SJME_ERROR_NONE
;
68 sjme_errorCode
sjme_error_default(
71 return sjme_error_defaultOr((error
), SJME_ERROR_UNKNOWN
);
74 sjme_errorCode
sjme_error_defaultOr(
75 sjme_errorCode error
, sjme_errorCode otherwise
)
77 if (!sjme_error_is(error
) || error
== SJME_ERROR_UNKNOWN
)
79 if (!sjme_error_is(otherwise
))
80 return SJME_ERROR_UNKNOWN
;