Exemplo n.º 1
0
Arquivo: t-date.c Projeto: mbk/ren-c
*/	static REBDAT Normalize_Date(REBINT day, REBINT month, REBINT year, REBINT tz)
/*
**		Given a year, month and day, normalize and combine to give a new
**		date value.
**
***********************************************************************/
{
	REBINT d;
	REBDAT dr;

	// First we normalize the month to get the right year
	if (month<0) {
		year-=(-month+11)/12;
		month=11-((-month+11)%12);
	}
	if (month >= 12) {
		year += month / 12;
		month %= 12;
	}

	// Now adjust the days by stepping through each month
	while (day >= (d = (REBINT)Month_Length(month, year))) {
		day -= d;
		if (++month >= 12) {
			month = 0;
			year++;
		}
	}
	while (day < 0) {
		if (month == 0) {
			month = 11;
			year--;
		}
		else
			month--;
		day += (REBINT)Month_Length(month, year);
	}

	if (year < 0 || year > MAX_YEAR) {
		Trap1(RE_TYPE_LIMIT, Get_Type(REB_DATE));
		// Unreachable, but we want to make the compiler happy
		assert(FALSE);
		return dr;
	}

	dr.date.year = year;
	dr.date.month = month+1;
	dr.date.day = day+1;
	dr.date.zone = tz;

	return dr;
}
//---------------------------------------------------------
bool CWKSP_Base_Manager::Add_Item(CWKSP_Base_Item *pItem)
{
	if( pItem )
	{
		m_Items				= (CWKSP_Base_Item **)realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Base_Item *));
		m_Items[m_nItems++]	= pItem;
		pItem->m_pManager	= this;
		pItem->m_ID			= m_Item_ID++;

		//-------------------------------------------------
		switch( Get_Type() )
		{
		default:
			break;

		case WKSP_ITEM_Module_Manager:
			g_pModule_Ctrl->Add_Group((CWKSP_Module_Group *)pItem);
			break;

		case WKSP_ITEM_Module_Group:
			g_pModule_Ctrl->Add_Library(GetId(), (CWKSP_Module_Library *)pItem);
			break;

		case WKSP_ITEM_Data_Manager:
		case WKSP_ITEM_Table_Manager:
		case WKSP_ITEM_Shapes_Manager:
		case WKSP_ITEM_Shapes_Type:
		case WKSP_ITEM_TIN_Manager:
		case WKSP_ITEM_PointCloud_Manager:
		case WKSP_ITEM_Grid_Manager:
		case WKSP_ITEM_Grid_System:
			g_pData_Ctrl->Add_Item(this, pItem);
			g_pACTIVE->Update_DataObjects();
			break;

		case WKSP_ITEM_Map_Manager:
		case WKSP_ITEM_Map:
			g_pMap_Ctrl->Add_Item(this, pItem);
			break;
		}

		return( true );
	}

	return( false );
}
Exemplo n.º 3
0
Arquivo: t-gob.c Projeto: xqlab/r3
*/	static void Set_GOB_Vars(REBGOB *gob, REBVAL *blk)
/*
***********************************************************************/
{
    REBVAL *var;
    REBVAL *val;

    while (NOT_END(blk)) {
        var = blk++;
        val = blk++;
        if (!IS_SET_WORD(var)) Trap2(RE_EXPECT_VAL, Get_Type(REB_SET_WORD), Of_Type(var));
        if (IS_END(val) || IS_UNSET(val) || IS_SET_WORD(val))
            Trap1(RE_NEED_VALUE, var);
        val = Get_Simple_Value(val);
        if (!Set_GOB_Var(gob, var, val)) Trap2(RE_BAD_FIELD_SET, var, Of_Type(val));
    }
}
Exemplo n.º 4
0
//---------------------------------------------------------
bool CSG_Grid::_Save_Native(const CSG_String &File_Name, int xA, int yA, int xN, int yN, bool bBinary)
{
	bool		bResult		= false;
	CSG_File	Stream;

	if(	Stream.Open(File_Name, SG_FILE_W, false) )
	{
		//-------------------------------------------------
		// Header...

		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_NAME			], Get_Name() );
		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DESCRIPTION	], Get_Description() );
		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_UNITNAME		], Get_Unit() );
		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DATAFILE_OFFSET], 0 );
		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DATAFORMAT		], bBinary ? gSG_Data_Type_Identifier[Get_Type()] : SG_T("ASCII") );
		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_BYTEORDER_BIG	], GRID_FILE_KEY_FALSE );
		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_POSITION_XMIN	], Get_XMin() + Get_Cellsize() * xA );
		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_POSITION_YMIN	], Get_YMin() + Get_Cellsize() * yA );
		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLCOUNT_X	], xN );
		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLCOUNT_Y	], yN );
		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLSIZE		], Get_Cellsize() );
		Stream.Printf(SG_T("%s\t= %f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_Z_FACTOR		], m_zFactor );
		Stream.Printf(SG_T("%s\t= %f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_NODATA_VALUE	], Get_NoData_Value() );
		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_TOPTOBOTTOM	], GRID_FILE_KEY_FALSE );


		//-------------------------------------------------
		// Data...

		if( Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")), SG_FILE_W, true) )
		{
			if( bBinary )
			{
				bResult		= _Save_Binary	(Stream, xA, yA, xN, yN, Get_Type(), false, false);
			}
			else
			{
				bResult		= _Save_ASCII	(Stream, xA, yA, xN, yN);
			}
		}
	}

	return( bResult );
}
bool CWKSP_Base_Manager::Del_Item(CWKSP_Base_Item *pItem)
{
	int		iItem;

	if( pItem && (iItem = pItem->Get_Index()) >= 0 && iItem < m_nItems )
	{
		m_nItems--;

		for( ; iItem<m_nItems; iItem++)
		{
			m_Items[iItem]	= m_Items[iItem + 1];
		}

		m_Items	= (CWKSP_Base_Item **)realloc(m_Items, m_nItems * sizeof(CWKSP_Base_Item *));

		//-------------------------------------------------
		switch( Get_Type() )
		{
		default:
			break;

		case WKSP_ITEM_Data_Manager:
			g_pData->Del_Manager(pItem);
			break;

		case WKSP_ITEM_Table_Manager:
		case WKSP_ITEM_Shapes_Type:
		case WKSP_ITEM_TIN_Manager:
		case WKSP_ITEM_PointCloud_Manager:
		case WKSP_ITEM_Grid_Manager:
		case WKSP_ITEM_Grid_System:
			if( g_pACTIVE )
			{
				g_pACTIVE->Update_DataObjects();
			}
			break;
		}

		return( true );
	}

	return( false );
}
Exemplo n.º 6
0
//
//  Mul_Max: C
//
int Mul_Max(enum Reb_Kind type, i64 n, i64 m, i64 maxi)
{
    i64 r = n * m;
    if (r < -maxi || r > maxi) fail (Error(RE_TYPE_LIMIT, Get_Type(type)));
    return (int)r;
}
Exemplo n.º 7
0
*/	void Trap_Make(REBCNT type, REBVAL *spec)
/*
***********************************************************************/
{
	Trap2(RE_BAD_MAKE_ARG, Get_Type(type), spec);
}
Exemplo n.º 8
0
*/	void Trap_Math_Args(REBCNT type, REBCNT action)
/*
***********************************************************************/
{
	Trap2(RE_NOT_RELATED, Get_Action_Word(action), Get_Type(type));
}
Exemplo n.º 9
0
*/	void Trap_Action(REBCNT type, REBCNT action)
/*
***********************************************************************/
{
	Trap2(RE_CANNOT_USE, Get_Action_Word(action), Get_Type(type));
}