/****************************************************************************
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:	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:	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,
	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);
}
Beispiel #6
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);
}