/****************************************************************************
Desc:
****************************************************************************/
void F_IniFile::init( void)
{
	m_pool.poolFree();	
	m_pool.poolInit( 512);
	m_pFirstLine = NULL;
	m_pLastLine = NULL;
	m_bReady = TRUE;
}
/****************************************************************************
Desc:	All of the toAscii() functions convert values from their native
		formats to a string representation
****************************************************************************/
RCODE F_IniFile::toAscii( 
	char **		ppszParamValue,
	FLMBOOL 		bVal)
{
	RCODE		rc = NE_FLM_OK;
	
	if( RC_BAD( rc = m_pool.poolAlloc( 6, (void **)ppszParamValue)))
	{
		goto Exit;
	}
	
	if( bVal)
	{
		f_memcpy( *ppszParamValue, "TRUE ", 6);
	}
	else
	{
		f_memcpy( *ppszParamValue, "FALSE", 6);
	}
	
	m_bModified = TRUE;
	
Exit:

	return( rc);
}
/****************************************************************************
Desc:	This code is common to all of the SetParam() functions
****************************************************************************/
RCODE F_IniFile::setParamCommon( 
	INI_LINE **		ppLine,
	const char *	pszParamName)
{
	RCODE				rc = NE_FLM_OK;
	INI_LINE *		pLine;

	if( RC_BAD( rc = m_pool.poolCalloc( 
		sizeof( INI_LINE), (void **)&pLine)))
	{
		goto Exit;
	}
	
	if( m_pLastLine)
	{
		m_pLastLine->pNext = pLine;
	}
	
	pLine->pPrev = m_pLastLine;
	m_pLastLine = pLine;
	
	if( !m_pFirstLine)
	{
		m_pFirstLine = pLine;
	}

	if( RC_BAD( rc = m_pool.poolAlloc( f_strlen(pszParamName)+1,
								(void **)&pLine->pszParamName)))
	{
		goto Exit;
	}

	f_strcpy( pLine->pszParamName, pszParamName);

Exit:

	if( RC_OK( rc))
	{
		*ppLine = pLine;
	}

	return( rc);
}
/****************************************************************************
Desc:	All of the toAscii() functions convert values from their native
		formats to a string representation
****************************************************************************/
RCODE F_IniFile::toAscii( 
	char **			ppszParamValue,
	const char * 	pszVal)
{
	RCODE		rc = NE_FLM_OK;
	
	if( RC_BAD( rc = m_pool.poolAlloc( f_strlen( pszVal),
							(void **)ppszParamValue)))
	{
		goto Exit;
	}
	
	f_strcpy( *ppszParamValue, pszVal);
	m_bModified = TRUE;
	
Exit:

	return( rc);
}
/****************************************************************************
Desc:	All of the toAscii() functions convert values from their native
		formats to a string representation
****************************************************************************/
RCODE F_IniFile::toAscii( 
	char **		ppszParamValue,
	FLMUINT 		puiVal)
{
	RCODE			rc = NE_FLM_OK;
	char 			szTemp[ 50];

	f_sprintf( szTemp, "%*.*lu", sizeof(szTemp), sizeof(szTemp), puiVal);

	if( RC_BAD( rc = m_pool.poolAlloc( f_strlen( szTemp),
		(void **)ppszParamValue)))
	{
		goto Exit;
	}
	
	f_strcpy( *ppszParamValue, szTemp);
	m_bModified = TRUE;
	
Exit:

	return( rc);
}
/****************************************************************************
Desc:	Parse a single line from the ini file into its name, value and comment
	   parts.
****************************************************************************/
RCODE F_IniFile::parseBuffer(
	char *		pszBuf,
	FLMUINT		uiNumBytes)
{
	RCODE			rc = NE_FLM_OK;
	FLMUINT		uiCurrentChar = 0;
	char *		pszNameStart = NULL;
	char *		pszNameEnd = NULL;
	char *		pszValStart = NULL;
	char *		pszValEnd = NULL;
	char *		pszCommentStart = NULL;
	INI_LINE *	pLine = NULL;
	FLMUINT		uiStrLen = 0;

	f_assert( pszBuf);
	f_assert( uiNumBytes);

	// Start looking for the parameter name...
	
	while (uiCurrentChar < uiNumBytes)
	{
		if( !isWhiteSpace( pszBuf[uiCurrentChar]))
		{
			if (pszBuf[uiCurrentChar] == '#') 
			{
				goto Comment;
			}
			else
			{
				pszNameStart = &pszBuf[uiCurrentChar];
				break;
			}
		}
		uiCurrentChar++;
	}

	// We've found a param name, now mark the end of it
	// We determine the end by looking for whitespace or '='
	// or '#'
	
	while (uiCurrentChar < uiNumBytes)
	{
		if( isWhiteSpace( pszBuf[uiCurrentChar]) ||
			  (pszBuf[uiCurrentChar] == '=') || 
			  (pszBuf[uiCurrentChar] == '#'))
		{
			pszNameEnd = &pszBuf[uiCurrentChar-1];
			break;
		}

		uiCurrentChar++;
	}

	if( (uiCurrentChar == uiNumBytes) && 
		  (pszNameEnd == NULL) )
	{
		pszNameEnd = &pszBuf[uiCurrentChar - 1];
	}

	// Now, there may be a value part or a comment part next.  If there's a
	// value, it had better be preceeded by an '='
	
	while( (uiCurrentChar < uiNumBytes) && 
			  isWhiteSpace( pszBuf[uiCurrentChar]) )
	{
		uiCurrentChar++;
	}
	
	if( uiCurrentChar < uiNumBytes && pszBuf[ uiCurrentChar] == '#')
	{
		goto Comment;
	}

	if( uiCurrentChar < uiNumBytes && pszBuf[uiCurrentChar] != '=' )
	{
		rc = RC_SET( NE_FLM_SYNTAX);
		goto Exit;
	}

	// Ok - at this point pszBuf[uiCurrentChar] contains an =.  Skip over
	// the = and any whitespace that follows.
	
	while( uiCurrentChar < uiNumBytes)
	{
		uiCurrentChar++;
		if( !isWhiteSpace( pszBuf[uiCurrentChar]))
		{
			pszValStart = &pszBuf[uiCurrentChar];
			break;
		}
	}

	// Now mark the end of the value.
	// We determine the end by looking for whitespace or '#'
	
	while( uiCurrentChar < uiNumBytes) 
	{
		if( isWhiteSpace( pszBuf[uiCurrentChar]) || 
			  (pszBuf[uiCurrentChar] == '#'))
		{
			pszValEnd = &pszBuf[uiCurrentChar-1];
			break;
		}		
		uiCurrentChar++;
	}

	if( uiCurrentChar == uiNumBytes && !pszValEnd)
	{
		pszValEnd = &pszBuf[uiCurrentChar-1];
	}

Comment:

	// Check out the rest of the line to see if there's a comment
	
	while( uiCurrentChar < uiNumBytes)
	{
		if( !isWhiteSpace( pszBuf[ uiCurrentChar]) &&
			 pszBuf[ uiCurrentChar] != '#')
		{
			rc = RC_SET( NE_FLM_SYNTAX);
			goto Exit;
		}
		else if( pszBuf[ uiCurrentChar] == '#')
		{
			// Comment found.  Set pszCommentStart to the next char
			
			pszCommentStart = &pszBuf[uiCurrentChar+1];
			break;
		}
		uiCurrentChar++;
	}

	// Done parsing.  Now, assuming the line had any info in it,
	// store all the strings...
	
	if( pszNameStart || pszCommentStart)
	{
		if( RC_BAD( rc = m_pool.poolCalloc( sizeof( INI_LINE),
										(void **)&pLine)))
		{
			goto Exit;
		}
		
		if( pszNameStart)
		{
			uiStrLen = pszNameEnd - pszNameStart + 1;
			if( RC_BAD( rc = m_pool.poolAlloc( uiStrLen + 1,
								(void **)&pLine->pszParamName)))
			{
				goto Exit;
			}
			
			f_memcpy( pLine->pszParamName, pszNameStart, uiStrLen);
			pLine->pszParamName[uiStrLen] = '\0';
		}

		if( pszValStart)
		{
			uiStrLen = pszValEnd - pszValStart + 1;
			if( RC_BAD( rc = m_pool.poolAlloc( uiStrLen + 1,
						(void **)&pLine->pszParamValue)))
			{
				goto Exit;
			}
			
			f_memcpy(pLine->pszParamValue, pszValStart, uiStrLen);
			pLine->pszParamValue[uiStrLen] = '\0';
		}
		
		if (pszCommentStart)
		{
			uiStrLen = uiNumBytes-(pszCommentStart-pszBuf);
			if (RC_BAD( rc = m_pool.poolAlloc( uiStrLen + 1,
										(void **)&pLine->pszComment)))
			{
				goto Exit;
			}
			
			f_memcpy(pLine->pszComment, pszCommentStart, uiStrLen);
			pLine->pszComment[uiStrLen] = '\0';
		}
		
		// Insert this struct into the linked list
		
		if( m_pLastLine)
		{
			m_pLastLine->pNext = pLine;
		}
		
		pLine->pPrev = m_pLastLine;
		pLine->pNext = NULL;
		m_pLastLine = pLine;
		
		if( !m_pFirstLine)
		{
			m_pFirstLine = pLine;
		}
	}
	
Exit:

	return( rc);
}
Exemple #7
0
/****************************************************************************
Desc : Adds a value to the selection criteria of a given cursor.
****************************************************************************/
FLMEXP RCODE FLMAPI FlmCursorAddValue(
	HFCURSOR		hCursor,
	QTYPES		eValType,
	void *		pVal,
	FLMUINT		uiValLen
	)
{
	RCODE			rc = FERR_OK;
	FLMUINT		uiVal;
	void *		pTmpVal = pVal;
	CURSOR *		pCursor = (CURSOR *)hCursor;
	F_Pool		pool;
	FLMBOOL		bPoolInitialized = FALSE;

	if (!pCursor)
	{
		flmAssert( 0);
		rc = RC_SET( FERR_INVALID_PARM);
		goto Exit;
	}
	
	if (RC_BAD( rc = pCursor->rc))
	{
		goto Exit;
	}

	// If a read operation has already been performed on this query, no
	// selection criteria may be added.
	
	if (pCursor->bOptimized)
	{
		rc = RC_SET( FERR_ILLEGAL_OP);
		goto Exit;
	}
	
	if (!( pCursor->QTInfo.uiExpecting & FLM_Q_OPERAND))
	{
		rc = RC_SET( FERR_CURSOR_SYNTAX);
		goto Exit;
	}

	switch (eValType)
	{

		// Convert all string types to FLM_TEXT_VALUE 
		//	in order to handle pure unicode coming in.

		case FLM_UNICODE_VAL:
		case FLM_STRING_VAL:
		{
			NODE	node;

			f_memset( &node, 0, sizeof(NODE));

			pool.poolInit( 512);
			bPoolInitialized = TRUE;

			rc = (eValType == FLM_UNICODE_VAL) 
					? GedPutUNICODE( &pool, &node, (FLMUNICODE *) pVal)
					: GedPutNATIVE( &pool, &node, (const char *)pVal);
			if (RC_BAD( rc))
			{
				goto Exit;
			}

			pTmpVal = GedValPtr( &node);
			uiValLen = GedValLen( &node);
			eValType = FLM_TEXT_VAL;
			break;
		}

		case FLM_BOOL_VAL:
			if (!pVal)
			{
				uiVal = FLM_UNK;
			}
			else
			{
				FLMBOOL bTrueFalse = (FLMBOOL)*(FLMBOOL *)pVal;
				uiVal = (bTrueFalse) ? FLM_TRUE : FLM_FALSE;
			}
			pTmpVal = &uiVal;
			eValType = FLM_BOOL_VAL;
			break;

		case FLM_INT32_VAL:
		case FLM_UINT32_VAL:
		case FLM_REC_PTR_VAL:
		case FLM_UINT64_VAL:
		case FLM_INT64_VAL:
		case FLM_TEXT_VAL:
		case FLM_BINARY_VAL:
		
			// pTmpVal is already pointing to pVal, and
			// eValType does not need to be changed.
			
			break;

		default:
			flmAssert( 0);
			rc = RC_SET( FERR_CURSOR_SYNTAX);
			break;
	}

	if (RC_OK( rc = flmCurMakeQNode( &pCursor->QueryPool, eValType, pTmpVal,
									uiValLen, pCursor->QTInfo.uiFlags,
									&(pCursor->QTInfo.pCurAtomNode))))
	{
		if (pCursor->QTInfo.pCurOpNode)
		{
			flmCurLinkLastChild( pCursor->QTInfo.pCurOpNode,
					pCursor->QTInfo.pCurAtomNode);
		}
		pCursor->QTInfo.uiExpecting &= ~FLM_Q_OPERAND;
		pCursor->QTInfo.uiExpecting |= FLM_Q_OPERATOR;
	}

Exit:

	if (pCursor)
	{
		pCursor->rc = rc;
	}

	if (bPoolInitialized)
	{
		pool.poolFree();
	}
	
	return( rc);
}
Exemple #8
0
int main(
#endif
	int			iArgC,
	char **		ppszArgV)
{
	int		iRetCode = 0;
	F_Pool	LogPool;

	gv_bBatchMode = FALSE;
	gv_bRunning = TRUE;

	if( RC_BAD( FlmStartup()))
	{
		iRetCode = -1;
		goto Exit;
	}

	f_conInit( 0xFFFF, 0xFFFF, "FLAIM Database Rebuild");

	if( RC_BAD( FlmGetFileSystem( &gv_pFileSystem)))
	{
		f_conStrOut( "\nCould not allocate a file system object.\n");
		goto Exit;
	}

	LogPool.poolInit( 1024);
	
	if( RC_BAD( LogPool.poolAlloc( MAX_LOG_BUFF, (void **)&gv_pucLogBuffer)))
	{
		goto Exit;
	}
	
	if( bldGetParams( iArgC, (const char **)ppszArgV))
	{
		if (!bldDoRebuild())
		{
			iRetCode = 1;
		}
	}
	
Exit:

	if (gv_bPauseBeforeExiting && !gv_bShutdown)
	{
		f_conStrOut( "\nPress any character to exit REBUILD: ");
		for (;;)
		{
			if (gv_bShutdown)
			{
				break;
			}
			
			if (f_conHaveKey())
			{
				f_conGetKey();
				break;
			}
			
			f_yieldCPU();
		}
	}

	if (gv_pFileSystem)
	{
		gv_pFileSystem->Release();
		gv_pFileSystem = NULL;
	}
	
	f_conExit();
	FlmShutdown();

	gv_bRunning = FALSE;
	return( iRetCode);
}