/*===============================
|	BlugsMHExtensions.c
|
|	Blugs 1.1 auxiliary routines
|	www.blugs.com
|
|	Copyright © 1998-2001 Brian Hall
|	You may use these routines in your software without restriction.
|
|===============================*/
#include "BlugsMHExtensions.h"

//===============================
void BLSetNRows( UInt16 inNRows, BlugsRef inList )
{
	UInt16	nRows;
	
	nRows = BLCountRows( inList );
	if (inNRows < nRows) BLDeleteRows( nRows - inNRows, inNRows + 1, inList );
	else if (inNRows > nRows) BLAddRowsCompat( inNRows - nRows, nRows + 1, inList );
}

//===============================
void BLSetNColumns( UInt16 inNColumns, BlugsRef inList )
{
	UInt16	nCols, count;
	
	nCols = BLCountColumns( inList );
	if (inNColumns < nCols)
	{
		count = nCols - inNColumns;
		BLDeleteColumns( count, inNColumns + 1, inList );
	}
	else if (inNColumns > nCols)
	{
		count = inNColumns - nCols;
		BLAddColumns( count, nCols + 1, inList );
	}
}

//===============================
UInt16 BLFindRowByID( OSType inID, BlugsRef inList )
{
	UInt16	nRows, row;
	Boolean	gotIt = false;
	
	nRows = BLCountRows( inList );
	for (row = 1; row <= nRows; row++)
	{
		OSErr	err;
		OSType	id;
		
		err = BLGetRowIdentifier( row, &id, inList );
		if (!err && id == inID)
		{
			gotIt = true;
			break;
		}
	}
	if (!gotIt) row = 0;
	return row;
}

//===============================
UInt16 BLFindColumnByID( OSType inID, BlugsRef inList )
{
	UInt16	nCols, col;
	Boolean	gotIt = false;
	
	nCols = BLCountColumns( inList );
	for (col = 1; col <= nCols; col++)
	{
		OSErr	err;
		OSType	id;
		
		err = BLGetColumnIdentifier( col, &id, inList );
		if (!err && id == inID)
		{
			gotIt = true;
			break;
		}
	}
	if (!gotIt) col = 0;
	return col;
}