home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // config.c
- #include "snipit.h"
-
- static void DisplayCfgFile(pCHAR CfgPath, INT16 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;
- }
-
- // Turn on trace information if the debug layer is anabled (DLLSWAP.EXE).
- DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
-
- // Specify where temporary files are placed.
- rslt = DbiSetPrivateDir(szPrivDirectory);
- ChkRslt(rslt, "SetPrivateDir");
-
- // 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) ;
-
- // Turn off trace information.
- DbiDebugLayerOptions(0, NULL);
-
- // Close IDAPI.
- Screen("\r\n Exiting IDAPI...");
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
-
- Screen("\r\n*** End of Example ***");
- }
-
- //=====================================================================
- // Function:
- // DisplayCfgFile(CfgPath, Level);
- //
- // 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, INT16 Level)
- {
- DBIResult rslt; // Value to return
- hDBICur hCur; // Handle to the cursor
- pCHAR szNode; // String which contains the name of the node
- pCFGDesc CfgDesc; // Configuration descriptor
- INT16 iLoop; // Loop variable - used for indenting
- INT16 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, (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 = 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");
- }
- }
- }
-