home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Total C++ 2
/
TOTALCTWO.iso
/
borland
/
32snipit.pak
/
CONFIG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-06
|
6KB
|
186 lines
// BDE32 3.x - (C) Copyright 1996 by Borland International
// config.c
#include "snipit.h"
static void DisplayCfgFile(pCHAR CfgPath, UINT16 Level) ;
//=====================================================================
// Function:
// Configuration();
//
// Description:
// This example dumps the information contained in the
// IDAPI configuration file, as well as displaying which
// configuration file is being used.
//=====================================================================
void
Configuration (void)
{
SYSConfig sysConfig; // Used for storing the system configuration
// information - used to determine the
// location of the configuration file.
DBIResult rslt; // Return value from IDAPI functions.
Screen("*** Configuration Example ***\r\n");
BREAK_IN_DEBUGGER();
Screen(" Initializing IDAPI...");
rslt = DbiInit(NULL);
if (ChkRslt(rslt, "Init") != DBIERR_NONE)
{
Screen("\r\n*** End of Example ***");
return;
}
// Determine which configuration file is being used.
rslt = DbiGetSysConfig(&sysConfig);
ChkRslt(rslt, "GetSysConfig");
Screen("\r\n Display the information in the currently used"
" configuration file:\r\n\r\n\t\t %s\r\n", sysConfig.szIniFile);
// Call the recursive function which dumps information from the
// configuration file.
DisplayCfgFile ("\\", 0) ;
// Close IDAPI
Screen("\r\n Exiting IDAPI...");
rslt = DbiExit();
ChkRslt(rslt, "Exit");
Screen("\r\n*** End of Example ***");
}
//=====================================================================
// Function:
// DisplayCfgFile();
//
// Input: CfgPath - Path within the CFG file to the desired
// option within the configuration file. Starts
// at "\\" for the root of the configuration tree.
// Level - Depth of Recursion.
//
// Return: None.
//
// Desc: This recursive function is used to display all information
// within the configuration file.
//=====================================================================
void
DisplayCfgFile (pCHAR CfgPath, UINT16 Level)
{
hDBICur hCur = 0; // Handle to the cursor
DBIResult rslt; // Value to return
pCHAR szNode; // String which contains the name of the node
pCFGDesc CfgDesc; // Configuration descriptor
int iLoop; // Loop variable - used for indenting
UINT16 BaseSize; // Length of the current node
// Open the Configuration file - returns the configuration options
// for the current level in a schema table referenced by hCur.
rslt = DbiOpenCfgInfoList(NULL, dbiREADONLY, cfgPersistent, CfgPath,
&hCur);
if (ChkRslt(rslt, "OpenCfgInfoList") == DBIERR_NONE)
{
// Allocate resources - make block large enough to contain all
// information.
szNode = (pCHAR)malloc(512 * sizeof(CHAR));
if (! szNode)
{
Screen(" Error - Out of memory");
return;
}
CfgDesc = (pCFGDesc)malloc(sizeof(CFGDesc));
if (! CfgDesc)
{
Screen(" Error - Out of memory");
return;
}
// Initialize descriptor to 0
memset((void *)CfgDesc, 0, sizeof(CFGDesc));
// Process all nodes/paths
// Get the next record in the table - contains the next option
// of the given level in the tree.
while (DbiGetNextRecord(hCur, dbiNOLOCK, (pBYTE)CfgDesc, NULL)
== DBIERR_NONE)
{
// Clear the szNode variable
szNode[0] = 0;
// Indent according to the depth of the configuration option
for (iLoop = 0; iLoop < Level; iLoop++)
{
strcat(szNode, " ");
}
// Output this node, copying the name of the node to the
// szNode variable.
strcat(szNode, CfgDesc->szNodeName);
Screen(szNode);
// Process this node if it has sub-nodes
if (CfgDesc->bHasSubnodes)
{
// Determine if this is a base node
if (Level == 0)
{
sprintf(szNode, "%s%s", CfgPath, CfgDesc->szNodeName);
}
else // if not a base node
{
sprintf(szNode, "%s\\%s", CfgPath,
CfgDesc->szNodeName);
}
// Recursively call this function to get information about
// sub-nodes.
DisplayCfgFile(szNode, (UINT16)(Level + 1));
}
else // No sub-nodes...
{
// Clear the szNode variable
szNode[0] = 0;
// Indent according to the depth of the config option
for (iLoop = 0; iLoop <= Level; iLoop++)
{
strcat(szNode, " ");
}
// Determine the length of the string
BaseSize = (UINT16)strlen(szNode);
// Display the remaining information & description
sprintf(&szNode[BaseSize], "Desc: %s",
CfgDesc->szDescription);
Screen(szNode);
// Display the type of the node
sprintf(&szNode[BaseSize], "Type: %d",
CfgDesc->iDataType);
Screen(szNode);
// Display the value of the node
sprintf(&szNode[BaseSize], " Val: %s", CfgDesc->szValue);
Screen(szNode);
}
// Initialize descriptor to 0
memset((void *) CfgDesc, 0, sizeof(CFGDesc));
}
// Clean up
free(szNode);
free((pCHAR)CfgDesc);
if (hCur)
{
rslt = DbiCloseCursor(&hCur);
ChkRslt(rslt, "CloseCursor");
}
}
}