コード例 #1
0
ファイル: callbacks.cpp プロジェクト: chasercat/libsf
	bool iiDefaultCallback_processMouseVariables(	SVariable* varX, SVariable* varY, SVariable* varCtrl, SVariable* varAlt, SVariable* varShift, SVariable* varClick,
													s32* lnX, s32* lnY, bool* tlCtrl, bool* tlAlt, bool* tlShift, u32* lnClick)
	{
		//////////
		// Validate the variables are appropriate
		//////
			if (!iVariable_isValid(varX) || !iVariable_isValid(varY) || !iVariable_isValid(varCtrl) || !iVariable_isValid(varAlt) || !iVariable_isValid(varShift) || !iVariable_isValid(varClick))
			{
				// Something is invalid, ignore it
				return(false);
			}
			if (!iVariable_isTypeNumeric(varX) || !iVariable_isTypeNumeric(varY) || !iVariable_isTypeLogical(varCtrl) || !iVariable_isTypeLogical(varAlt) || !iVariable_isTypeLogical(varShift) || !iVariable_isTypeNumeric(varClick))
			{
				// Something is not a proper variable, ignore it
				return(false);
			}
			*lnX		= (s16)iiVariable_getAs_s32(varX,	false, NULL, NULL);
			*lnY		= (u16)iiVariable_getAs_s32(varY,	false, NULL, NULL);
			*tlCtrl		= iiVariable_getAs_bool(varCtrl,	false, NULL, NULL);
			*tlAlt		= iiVariable_getAs_bool(varAlt,		false, NULL, NULL);
			*tlShift	= iiVariable_getAs_bool(varShift,	false, NULL, NULL);
			*lnClick	= iiVariable_getAs_u32(varClick,	false, NULL, NULL);


		//////////
		// Indicate we successfully parsed the variables
		//////
			return(true);
	}
コード例 #2
0
ファイル: i.cpp プロジェクト: RickCHodgin/libsf
//////////
//
// Function: INT()
// Takes a value and returns the INT(n) of that value.
//
//////
// Version 0.58
// Last update:
//     Apr.02.2015
//////
// Change log:
//     Apr.02.2015 - Refactoring
//     Jul.13.2014 - Initial creation
//////
// Parameters:
//     p1			-- Numeric or floating point
//
//////
// Returns:
//    INT(n) of the value in p1
//////
    void function_int(SReturnsParams* rpar)
    {
		SVariable*	varNumber = rpar->ip[0];
		f64			fValue;
		u32			errorNum;
        bool		error;
        SVariable*	result;


		//////////
		// Parameter 1 must be numeric
		//////
			rpar->rp[0] = NULL;
			if (!iVariable_isValid(varNumber) || !iVariable_isTypeNumeric(varNumber))
			{
				iError_report_byNumber(_ERROR_PARAMETER_IS_INCORRECT, iVariable_get_relatedComp(varNumber), false);
				return;
			}


		//////////
        // Based on its type, process it accordingly
		//////
			if (iVariable_isTypeFloatingPoint(varNumber))
			{
				fValue = iiVariable_getAs_f64(varNumber, false, &error, &errorNum);
				if (error)
				{
					iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber), false);
					return;
				}

				// Convert to S64
				result = iVariable_create(_VAR_TYPE_S64, NULL, true);
				if (result)
					*(s64*)result->value.data_s8 = (s64)fValue;

			} else {
				// Copy whatever it already is
				result = iVariable_copy(varNumber, false);
			}


		//////////
		// Are we good?
		//////
			if (!result)
			{
				iError_report(cgcInternalError, false);
				return;
			}


		//////////
        // Return our converted result
		//////
			rpar->rp[0] = result;

    }
コード例 #3
0
ファイル: v.cpp プロジェクト: chasercat/libsf
//////////
//
// Function: _VJRSYS()
// Internal function.  Not published.  Used to access VJr system variables.
//
//////
// Version 0.58
// Last update:
//     Oct.28.2015
//////
// Change log:
//     Oct.28.2015 - Initial creation by Rick C. Hodgin
//////
// Parameters:
//     varIndex			-- Index function to access the variable
//
//////
// Returns:
//     Varies			-- Based on index, returns the VJr system variable
//////
	void function__vjrsys(SReturnsParams* rpar)
	{
		SVariable* varIndex		= rpar->ip[0];

		s32			lnIndex;
		u32			errorNum;
		bool		error;


		//////////
		// Parameter 1 must be valid and numeric
		//////
			rpar->rp[0] = NULL;
			if (!iVariable_isValid(varIndex) || !iVariable_isTypeNumeric(varIndex))
			{
				iError_report_byNumber(_ERROR_P1_IS_INCORRECT, iVariable_get_relatedComp(varIndex), false);
				return;
			}

			// Grab the index value
			lnIndex = iiVariable_getAs_s32(varIndex, false, &error, &errorNum);
			if (error)
			{
				iError_report_byNumber(errorNum, iVariable_get_relatedComp(varIndex), false);
				return;
			}


		//////////
		// Dispatch based on operation
		//////
			switch (lnIndex)
			{
				case 1:
					rpar->rp[0] = iVariable_createAndPopulate_byText(_VAR_TYPE_LOGICAL, iVariable_populate_byBool(glShuttingDown), 1, false);
					break;

				default:
					iError_report_byNumber(_ERROR_FEATURE_NOT_AVAILABLE, iVariable_get_relatedComp(varIndex), false);
					break;
			}

	}
コード例 #4
0
ファイル: v.cpp プロジェクト: chasercat/libsf
//////////
//
// Function: VERSION()
// Based on input, retrieves various version information.
//
//////
// Version 0.58
// Last update:
//     Jul.13.2014
//////
// Change log:
//     Jul.13.2014 - Initial creation
//////
// Parameters:
//     pIndex		-- (Optional) If present, Numeric, in the range 1..5
//
//////
// Returns:
//    Numeric or Character	-- Depending on index, various values are returned
//////
    void function_version(SReturnsParams* rpar)
    {
		SVariable*	varIndex = rpar->ip[0];
        s32			index;
		u32			errorNum;
        bool		error;
		u8*			lptr;
        SVariable*	result;


		//////////
		// Parameter 1 must be numeric
		//////
			rpar->rp[0]	= NULL;
			lptr				= NULL;
			if (!iVariable_isValid(varIndex))
			{
				// They are requesting the default information
				lptr = (u8*)cgcVersionText;

			} else if (!iVariable_isTypeNumeric(varIndex)) {
				// The parameter is not numeric
				iError_report_byNumber(_ERROR_P1_IS_INCORRECT, iVariable_get_relatedComp(varIndex), false);
				return;

			} else {
				// It must be in the range 1..5
				index = iiVariable_getAs_s32(varIndex, false, &error, &errorNum);
				if (error)
				{
					iError_report_byNumber(errorNum, iVariable_get_relatedComp(varIndex), false);
					return;

				} else if (index < 1 || index > 5) {
					// We report our own error
					iError_report((cu8*)"Parameter must be in the range 1..5", false);
					return;
				}
			}


		//////////
        // Create our return result
		//////
			if (lptr || index == 1 || index == 4)
			{
				// Character return
				result = iVariable_create(_VAR_TYPE_CHARACTER, NULL, true);
				if (lptr)
				{
					// Copy the version info
					iDatum_duplicate(&result->value, lptr, -1);

				} else if (index == 1) {
					// Copy the version1 info
					iDatum_duplicate(&result->value, cgcVersion1Text, -1);

				} else {
					// Copy the version4 info
					iDatum_duplicate(&result->value, cgcVersion4Text, -1);
				}

			} else {
				result = iVariable_create(_VAR_TYPE_S32, NULL, true);
				if (index == 2)
				{
					// 0=runtime, 1=standard, 2=professional
					*(s32*)result->value.data = gnVersion2;	// Oh yeah!

				} else if (index == 3) {
					// Localized version
					*(s32*)result->value.data = gnVersion3;	// English

				} else {
					// Version in a form like Major.Minor as M.mm, or 123 for version 1.23
					*(s32*)result->value.data = gnVersion5;
				}
			}
			if (!result)
			{
				iError_report(cgcInternalError, false);
				return;
			}


		//////////
        // Return our converted result
		//////
			rpar->rp[0] = result;

    }
コード例 #5
0
ファイル: callbacks.cpp プロジェクト: chasercat/libsf
	bool iiDefaultCallback_processKeyVariables(	SVariable* varCtrl, SVariable* varAlt, SVariable* varShift, SVariable* varCaps, SVariable* varAscii, SVariable* varVKey, SVariable* varIsCAS, SVariable* varIsAscii,
												bool* tlCtrl, bool* tlAlt, bool* tlShift, bool* tlCaps, bool* tlIsCAS, bool* tlIsAscii,
												s16* lcAscii, u16* lnVKey)
	{
		//////////
		// Validate the variables are appropriate
		//////
			if (!iVariable_isValid(varCtrl) || !iVariable_isValid(varAlt) || !iVariable_isValid(varShift) || !iVariable_isValid(varCaps) || !iVariable_isValid(varIsAscii) || !iVariable_isValid(varAscii)	|| !iVariable_isValid(varVKey))
			{
				// Something is invalid
				return(false);	// Do not continue consuming
			}
			if (!iVariable_isTypeLogical(varCtrl) || !iVariable_isTypeLogical(varAlt) || !iVariable_isTypeLogical(varShift) || !iVariable_isTypeLogical(varCaps) || !iVariable_isTypeLogical(varIsAscii) || !iVariable_isTypeNumeric(varAscii)	|| !iVariable_isTypeNumeric(varVKey))
			{
				// Something is not a proper variable
				return(false);	// Do not continue consuming
			}
			*tlCtrl		= iiVariable_getAs_bool(varCtrl,		false, NULL, NULL);
			*tlAlt		= iiVariable_getAs_bool(varAlt,		false, NULL, NULL);
			*tlShift	= iiVariable_getAs_bool(varShift,		false, NULL, NULL);
			*tlCaps		= iiVariable_getAs_bool(varCaps,		false, NULL, NULL);
			*tlIsCAS	= iiVariable_getAs_bool(varIsCAS,		false, NULL, NULL);
			*tlIsAscii	= iiVariable_getAs_bool(varIsAscii,	false, NULL, NULL);
			*lcAscii	= iiVariable_getAs_s16(varAscii,		false, NULL, NULL);
			*lnVKey		= iiVariable_getAs_u16(varVKey,		false, NULL, NULL);


		//////////
		// Indicate we successfully parsed the keyboard variables
		//////
			return(true);
	}
コード例 #6
0
ファイル: callbacks.cpp プロジェクト: chasercat/libsf
	bool iDefaultCallback_onMouseWheel(SWindow* win, SObject* obj, SVariable* varX, SVariable* varY, SVariable* varCtrl, SVariable* varAlt, SVariable* varShift, SVariable* varClick, SVariable* varUnits)
	{
		s32		lnX, lnY, lnUnits;
		u32		lnClick;
		bool	llCtrl, llAlt, llShift;
//		POINT	pt;


		// Make sure our environment is sane
		if (!iiDefaultCallback_processMouseVariables(varX, varY, varCtrl, varAlt, varShift, varClick, &lnX, &lnY, &llCtrl, &llAlt, &llShift, &lnClick) || !iVariable_isValid(varUnits) || !iVariable_isTypeNumeric(varUnits))
			return(false);	// Do not continue consuming

		// Grab the units
		lnUnits = iiVariable_getAs_s32(varUnits, false, NULL, NULL);


		// Assume we consumed the mouse wheel, and that the parent doesn't need to receive it
		if (obj->objType == _OBJ_TYPE_EDITBOX)
		{
			// Ctrl+MouseWheel is a normal navigate
			if (llCtrl)
			{
				// They are just moving the cursor line
				iSEM_navigate(obj->p.sem, obj, lnUnits * ((llShift) ? -1 : -3), 0);

			// MouseWheel is a scroll
			} else {
				// They want to scroll the entire window, including the cursor line
				iSEM_scroll(obj->p.sem, obj, lnUnits * ((llShift) ? -1 : -3), 0);
			}
			iObj_setDirtyRender_ascent(obj, true);
			iWindow_render(win, false);

		} else if (obj->objType == _OBJ_TYPE_CAROUSEL) {
			// Create a point
//			pt.x = lnX;
//			pt.y = lnY;

			// They are they outside of the client area?
			return(iEvents_carouselMouseWheel(win, obj, lnX, lnY, llCtrl, llAlt, llShift, lnClick));

		} else {
			// Continue propagating
			return(true);
		}

		// Do not continue to propagate this message to other objects
		return(false);
	}
コード例 #7
0
ファイル: e.cpp プロジェクト: chasercat/libsf
	// Common numeric functions used for EXP(), LOG(), LOG10(), PI(), SQRT(), CEILING(), FLOOR(), DTOR(), RTOD(), ...
    void ifunction_numbers_common(SReturnsParams* rpar, SVariable* varNumber1, SVariable* varNumber2, SVariable* varNumber3, u32 tnFunctionType, const u32 tnResultType, bool tlSameInputType, bool tlNoEmptyParam)
    {
		f64			lfResult, lfValue1, lfValue2, lfValue3;
		u32			errorNum;
        bool		error;
        SVariable*	result;


		//////////
		// If varNumber1 is provided, must also be numeric
		//////
			rpar->rp[0] = NULL;
			if (varNumber1)
			{
				//////////
				// Must be numeric
				//////
					if (!iVariable_isValid(varNumber1) || !iVariable_isTypeNumeric(varNumber1))
					{
						iError_report_byNumber(_ERROR_PARAMETER_IS_INCORRECT, iVariable_get_relatedComp(varNumber1), false);
						return;
					}


				//////////
				// Convert to f64
				//////
					lfValue1 = iiVariable_getAs_f64(varNumber1, false, &error, &errorNum);
					if (error)
					{
						iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber1), false);
						return;
					}

				//////////
				// Check empty param
				//////
					if (tlNoEmptyParam && lfValue1 == 0.0)
					{
						iError_report_byNumber(_ERROR_CANNOT_BE_ZERO, iVariable_get_relatedComp(varNumber1), false);
						return;
					}

			} else {
				lfValue1 = 0.0;
			}


		//////////
		// If varNumber2 is provided, must also be numeric
		//////
			if (varNumber2)
			{
				//////////
				// Must be numeric
				//////
					if (!iVariable_isValid(varNumber2) || !iVariable_isTypeNumeric(varNumber2))
					{
						iError_report_byNumber(_ERROR_PARAMETER_IS_INCORRECT, iVariable_get_relatedComp(varNumber2), false);
						return;
					}


				//////////
				// Convert to f64
				//////
					lfValue2 = iiVariable_getAs_f64(varNumber2, false, &error, &errorNum);
					if (error)
					{
						iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber2), false);
						return;
					}

				//////////
				// Check empty param
				//////
					if (tlNoEmptyParam && lfValue2 == 0.0)
					{
						iError_report_byNumber(_ERROR_CANNOT_BE_ZERO, iVariable_get_relatedComp(varNumber2), false);
						return;
					}

			} else {
				lfValue2 = 0.0;
			}


		//////////
		// If varNumber3 is provided, must also be numeric
		//////
			if (varNumber3)
			{
				//////////
				// Must be numeric
				//////
					if (!iVariable_isValid(varNumber3) || !iVariable_isTypeNumeric(varNumber3))
					{
						iError_report_byNumber(_ERROR_PARAMETER_IS_INCORRECT, iVariable_get_relatedComp(varNumber3), false);
						return;
					}


				//////////
				// Convert to f64
				//////
					lfValue3 = iiVariable_getAs_f64(varNumber3, false, &error, &errorNum);
					if (error)
					{
						iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber3), false);
						return;
					}

				//////////
				// Check empty param
				//////
					if (tlNoEmptyParam && lfValue3 == 0.0)
					{
						iError_report_byNumber(_ERROR_CANNOT_BE_ZERO, iVariable_get_relatedComp(varNumber3), false);
						return;
					}

			} else {
				lfValue3 = 0.0;
			}


		//////////
		// Compute numeric function
		//////
			switch (tnFunctionType)
			{

// SQRT()
				case _FP_COMMON_SQRT:

					//////////
					// Verify p1 >= 0
					//////
						if (lfValue1 < 0.0)
						{
							// Oops!
							iError_report_byNumber(_ERROR_CANNOT_BE_NEGATIVE, iVariable_get_relatedComp(varNumber1), false);
							return;
						}


					//////////
					// Compute sqrt
					//////
						lfResult = sqrt(lfValue1);
						break;

// EXP()
				case _FP_COMMON_EXP:
					lfResult = exp(lfValue1);
					break;

// PI()
				case _FP_COMMON_PI:
					lfResult = _MATH_PI;
					break;

// LOG()
// LOG10()
				case _FP_COMMON_LOG:
				case _FP_COMMON_LOG10:

					//////////
					// Verify p1 > 0
					//////
						if (lfValue1 <= 0.0)
						{
							// Oops!
							iError_report_byNumber(_ERROR_CANNOT_BE_ZERO_OR_NEGATIVE, iVariable_get_relatedComp(varNumber1), false);
							return;
						}


					//////////
					// Compute
					//////
						if (tnFunctionType == _FP_COMMON_LOG)		lfResult = log(lfValue1);
						else										lfResult = log10(lfValue1);
						break;

// CEILING()
				case _FP_COMMON_CEILING:
					lfResult = ceil(lfValue1);
					break;

// FLOOR()
				case _FP_COMMON_FLOOR:
					lfResult = floor(lfValue1);
					break;

// DTOR()
				case _FP_COMMON_DTOR:
					lfResult = lfValue1 * _MATH_PI180;
					break;

// RTOD()
				case _FP_COMMON_RTOD:
					lfResult = lfValue1 * _MATH_180PI;
					break;

// COS()
				case _FP_COMMON_COS:
					lfResult = cos(lfValue1);
					break;

// SIN()
				case _FP_COMMON_SIN:
					lfResult = sin(lfValue1);
					break;

// ABS()
				case _FP_COMMON_ABS:
					lfResult = abs(lfValue1);
					break;

// ACOS()
// ASIN()
				case _FP_COMMON_ACOS:
				case _FP_COMMON_ASIN:

					//////////
					// Verify p1 > 0
					//////
						if (lfValue1 < -1 || lfValue1 > 1)
						{
							// Oops!
							iError_report_byNumber(_ERROR_OUT_OF_RANGE, iVariable_get_relatedComp(varNumber1), false);
							return;
						}

					//////////
					// Compute
					//////
						if (tnFunctionType == _FP_COMMON_ACOS)		lfResult = acos(lfValue1);
						else										lfResult = asin(lfValue1);
						break;

// ATAN()
				case _FP_COMMON_ATAN:

					//////////
					// Verify p1 > 0
					//////
						if (lfValue1 < -_MATH_PI2 || lfValue1 > _MATH_PI2)
						{
							// Oops!
							iError_report_byNumber(_ERROR_OUT_OF_RANGE, iVariable_get_relatedComp(varNumber1), false);
							return;
						}

					//////////
					// Compute
					//////
						lfResult = atan(lfValue1);
						break;

// ATN2()
				case _FP_COMMON_ATN2:
					lfResult = atan2(lfValue1, lfValue2);
					break;
// TAN()
				case _FP_COMMON_TAN:
					lfResult = tan(lfValue1);
					break;
// MOD()
				case _FP_COMMON_MOD:

					//////////
					// Verify divisor not 0
					//////
						if (lfValue2 == 0.0)
						{
							// Oops!
							iError_report_byNumber(_ERROR_DIVISION_BY_ZERO, iVariable_get_relatedComp(varNumber2), false);
							return;
						}


					//////////
					// Compute
					//////
						lfResult = fmod(lfValue1, abs(lfValue2));
						if (lfValue2 < 0 && lfResult != 0.0)			// Mar.14.2015
							lfResult += lfValue2;

					break;

// FV()
				case _FP_COMMON_FV:

					//////////
					// Future value
					//////
						lfResult = (pow((1 + lfValue2), lfValue3) - 1) / lfValue2 * lfValue1;
						break;

// PV()
				case _FP_COMMON_PV:

					//////////
					// Present value
					//////
						lfResult = lfValue1 * ((1 - pow((1 + lfValue2), -lfValue3)) / lfValue2);
						break;

// PAYMENT()
				case _FP_COMMON_PAYMENT:

					//////////
					// Payment
					//////
						lfValue1 = (lfValue1 * pow(lfValue2 + 1, lfValue3) * lfValue2) / (pow(lfValue2 + 1, lfValue3) - 1);
						break;

				default:
					// Programmer error... this is an internal function and we should never get here
					iError_report_byNumber(_ERROR_INTERNAL_ERROR, iVariable_get_relatedComp(varNumber1), false);
					return;
			}


		//////////
		// Create output variable
		//////
			if (tlSameInputType)	result = iVariable_create(varNumber1->varType, NULL, true);
			else					result = iVariable_create(tnResultType, NULL, true);

			if (!result)
			{
				iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber1), false);
				return;
			}


		//////////
		// Set the value
		//////
			if (!iVariable_setNumeric_toNumericType(result, NULL, &lfResult, NULL, NULL, NULL, NULL))
				iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber1), false);


		//////////
        // return(result)
		//////
			rpar->rp[0] = result;
	}
コード例 #8
0
ファイル: w.cpp プロジェクト: RickCHodgin/libsf
//////////
//
// Function: WEEK()
// Returns a number representing the week of the year from a Date or DateTime expression.
//
//////
// Version 0.58
// Last update:
//     May.01.2015
//////
// Change log:
//     May.01.2015 - Initial creation by Stefano D'Amico
//////
// Parameters:
//     p1			-- Date or DateTime
//     p2			-- Numeric [nMinDaysOfWeek] Minimum number of days in first week of year (1..7)
//     p3			-- Numeric [nFirstDayOfWeek] 
//
//////
// Returns:
//    WEEK() returns a number representing the week of the year.
//////
// Example:
//	  dt = datetime()	&& May.01.2015
//    ? WEEK(dt)		&& Displays 18
//////
	void function_week(SReturnsParams* rpar)
	{
		SVariable*	varParam			= rpar->ip[0];
		SVariable*	varFirstWeek		= rpar->ip[1];
		SVariable*	varFirstDayOfWeek	= rpar->ip[2];

		u32			lnYear, lnMonth, lnDay;
		s32			lnWeek, lnMinDaysInWeek, lnFirstDayOfWeek;
		SYSTEMTIME	lst;
		bool		error;
		u32			errorNum;
		SVariable*	result;


		//////////
		// If provided, parameter 1 must be date or datetime
		//////
			rpar->rp[0] = NULL;
			if (varParam)
			{
				if (!iVariable_isValid(varParam) || !(iVariable_isTypeDate(varParam) || iVariable_isTypeDatetime(varParam) || iVariable_isTypeDatetimeX(varParam)))
				{
					iError_report_byNumber(_ERROR_INVALID_ARGUMENT_TYPE_COUNT, iVariable_get_relatedComp(varParam), false);
					return;
				}

			//////////
			// Grab year, month, day from datetime or date
			//////
				     if (iVariable_isTypeDatetime(varParam))		iiDateMath_get_YyyyMmDd_from_julian					(varParam->value.data_dt->julian,			&lnYear, &lnMonth, &lnDay);
				else if (iVariable_isTypeDatetimeX(varParam))		iiDateMath_get_YyyyMmDdHhMmSsMssNss_from_jseconds	(varParam->value.data_dtx->jseconds, NULL,	&lnYear, &lnMonth, &lnDay, NULL, NULL, NULL, NULL, NULL);
				else /* date */										iiDateMath_get_YyyyMmDd_from_YYYYMMDD				(varParam->value.data_u8,					&lnYear, &lnMonth, &lnDay);

			} else {
				// Use the current date
				if (_settings)		iTime_getLocalOrSystem(&lst, propGet_settings_TimeLocal(_settings));
				else				GetLocalTime(&lst);

				lnYear	= lst.wYear;
				lnMonth	= lst.wMonth;
				lnDay	= lst.wDay;
			}


		//////////
		// Parameter 2 must be numeric
		//////
			if (varFirstWeek)
			{
				if (!iVariable_isValid(varFirstWeek) || !iVariable_isTypeNumeric(varFirstWeek))
				{
					iError_report_byNumber(_ERROR_P2_IS_INCORRECT, iVariable_get_relatedComp(varFirstWeek), false);
					return;
				}

				// Grab the minimum number of days in week
				lnMinDaysInWeek = iiVariable_getAs_s32(varFirstWeek, false, &error, &errorNum);
				if (error)
				{
					// An error extracting the value (should never happen)
					iError_report_byNumber(errorNum, iVariable_get_relatedComp(varFirstWeek), false);
					return;
				}

				if (lnMinDaysInWeek < 1 || 7 < lnMinDaysInWeek)
				{
					iError_report_byNumber(_ERROR_OUT_OF_RANGE, iVariable_get_relatedComp(varFirstWeek), false);
					return;				
				}

			} else {
				// First week contains January 1st.
				lnMinDaysInWeek = 1;
			}


		//////////
		// Parameter 3 must be numeric
		//////
			if (varFirstDayOfWeek)
			{
				if (!iVariable_isValid(varFirstDayOfWeek) || !iVariable_isTypeNumeric(varFirstDayOfWeek))
				{
					iError_report_byNumber(_ERROR_P3_IS_INCORRECT, iVariable_get_relatedComp(varFirstDayOfWeek), false);
					return;
				}

				// Grab the first day of week
				lnFirstDayOfWeek = iiVariable_getAs_s32(varFirstDayOfWeek, false, &error, &errorNum);
				if (error)
				{
					// An error extracting the value (should never happen)
					iError_report_byNumber(errorNum, iVariable_get_relatedComp(varFirstDayOfWeek), false);
					return;
				}

				if (lnFirstDayOfWeek < 0 || 6 < lnFirstDayOfWeek)
				{
					iError_report_byNumber(_ERROR_OUT_OF_RANGE, iVariable_get_relatedComp(varFirstWeek), false);
					return;				
				}

			} else {
				// Sunday
				lnFirstDayOfWeek = 0;
			}


		/////////
		// Grab week
		//////
			lnWeek = ifunction_week_common(rpar, lnYear, lnMonth, lnDay, lnMinDaysInWeek, lnFirstDayOfWeek);


		//////////
		// Create and populate our output variable
		//////
			result = iVariable_createAndPopulate_byText(_VAR_TYPE_S32, (cs8*)&lnWeek, 4, false);
			if (!result)
				iError_report_byNumber(_ERROR_INTERNAL_ERROR, iVariable_get_relatedComp(varParam), false);


		//////////
		// Indicate our result
		//////
			rpar->rp[0] = result;

	}
コード例 #9
0
ファイル: l.cpp プロジェクト: jhernancanom/libsf
//////////
//
// Function: LEFT()
// Returns the left N characters of a string.
//
//////
// Version 0.57
// Last update:
//     Jul.12.2014
//////
// Change log:
//     Jul.12.2014 - Initial creation
//////
// Parameters:
//     pString		-- Character, the string to trim
//     pCount		-- Numeric, the number of characters to copy
//
//////
// Returns:
//    Character		-- The string of the left N characters
//////
	void function_left(SThisCode* thisCode, SFunctionParms* rpar)
	{
		SVariable*	varString	= rpar->params[0];
		SVariable*	varCount	= rpar->params[1];
		s32			lnLength;
		u32			errorNum;
		bool		error;
        SVariable*	result;


		//////////
		// Parameter 1 must be character
		//////
			rpar->returns[0] = NULL;
			if (!iVariable_isValid(varString) || iVariable_getType(varString) != _VAR_TYPE_CHARACTER)
			{
				iError_reportByNumber(thisCode, _ERROR_P1_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varString), false);
				return;
			}


		//////////
		// Parameter 2 must be numeric
		//////
			if (!iVariable_isValid(varCount) || !iVariable_isTypeNumeric(varCount))
			{
				iError_reportByNumber(thisCode, _ERROR_P2_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varCount), false);
				return;
			}


		//////////
        // Find out how long they want our string to be
		//////
			lnLength = iiVariable_getAs_s32(thisCode, varCount, false, &error, &errorNum);
			if (error)
			{
				iError_reportByNumber(thisCode, errorNum, iVariable_getRelatedComp(thisCode, varCount), false);
				return;
			}


		//////////
        // Create our return result
		//////
	        result = iVariable_create(thisCode, _VAR_TYPE_CHARACTER, NULL, true);
			if (!result)
			{
				iError_report(thisCode, cgcInternalError, false);
				return;
			}


		//////////
        // Copy as much of the source string as will fit
		//////
			if (lnLength > 0)
				iDatum_duplicate(&result->value, varString->value.data_u8, min(varString->value.length, lnLength));


		//////////
        // Return our converted result
		//////
			rpar->returns[0] = result;

	}