home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir02
/
f014590.re_
/
f014590.re
Wrap
Text File
|
1996-04-02
|
10KB
|
297 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1995) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Workfile: excfgvar.mc $
| $Revision: 5.5 $
| $Date: 25 Jul 1995 12:50:14 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function - |
| |
| Example demonstrating mdlSystem_cfgVarXXXX calls. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h> /* MDL Library funcs structures & constants */
#include <dlogitem.h> /* Dialog Box Manager structures & constants */
#include <cexpr.h> /* C Expression structures & constants */
#include <cmdlist.h> /* MicroStation command numbers */
#include <msdefs.h> /* MicroStation common defines */
#include <stdarg.h> /* Variable argument defines */
#include <string.h> /* String function defines */
#include <stdio.h> /* Standard function defines */
#include <stdlib.h> /* Function prototype for free() */
#include <dlogman.fdf> /* dialog box manager function prototypes */
#include <msrsrc.fdf> /* mdlResource_xxx prototypes */
#include <mssystem.fdf> /* mdlSystem_xxx prototypes */
#include <msstrngl.fdf> /* mdlStringList_xxx prototypes */
#include "excfgvar.h"
/*----------------------------------------------------------------------+
| |
| Name excfgvar_rscSprintf |
| |
| Author BSI 3/93 |
| |
+----------------------------------------------------------------------*/
Private void excfgvar_rscSprintf
(
char *stringP, /* <= Result of sprintf from resource */
int messageNumber, /* => Index into msg list for format str */
... /* => Any other optional arguments */
)
{
va_list ap;
char tempStr[1024];
va_start (ap, messageNumber);
*stringP = tempStr[0] = '\0';
mdlResource_loadFromStringList (tempStr, NULL, MESSAGELISTID_Msgs,
messageNumber);
vsprintf (stringP, tempStr, ap);
va_end (ap);
}
/*----------------------------------------------------------------------+
| |
| name main |
| |
| author BSI 5/93 |
| |
+----------------------------------------------------------------------*/
Public int main
(
int argc, /* => number of args in next array */
char *argv[] /* => array of cmd line arguments */
)
{
int cfgLevel, i;
char cfgLevelName[128];
char cfgVarValue[128];
char tmpString[128];
char *cfgVarExpansion = NULL;
char *name;
RscFileHandle rscHandle;
mdlResource_openFile (&rscHandle, NULL, FALSE);
/* Get an already existing configuration variable */
mdlSystem_getCfgVar (cfgVarValue, "MS_DEF", sizeof(cfgVarValue));
sprintf (tmpString, "MS_DEF = %s", cfgVarValue);
mdlDialog_dmsgsPrint (tmpString);
/* Expands the configuration variable */
cfgVarExpansion = mdlSystem_expandCfgVar (cfgVarValue);
if (cfgVarExpansion != NULL)
{
excfgvar_rscSprintf (tmpString, MSGID_MSDEFEXPANDED, cfgVarExpansion);
mdlDialog_dmsgsPrint (tmpString);
/* free when done */
free (cfgVarExpansion);
}
/* Get an undefined configuration variable */
if (mdlSystem_getCfgVar
(cfgVarValue, "TMP_NEW", sizeof(cfgVarValue)) != SUCCESS)
{
mdlResource_loadFromStringList (tmpString, NULL, MESSAGELISTID_Msgs,
MSGID_TMPNEWNOTYET);
mdlDialog_dmsgsPrint (tmpString);
}
/* Define a new configuration variable */
mdlSystem_defineCfgVar ("TMP_NEW", "$(MSDIR)test.txt", CFGVAR_LEVEL_USER);
/* Clear the string & get the newly created configuration variable */
if (mdlSystem_getCfgVar
(cfgVarValue, "TMP_NEW", sizeof(cfgVarValue)) == SUCCESS)
{
sprintf (tmpString, "TMP_NEW = %s", cfgVarValue);
mdlDialog_dmsgsPrint (tmpString);
/* Expand the configuration variable to get current value */
cfgVarExpansion = mdlSystem_expandCfgVar (cfgVarValue);
excfgvar_rscSprintf (tmpString, MSGID_TMPNEWEXPANDED, cfgVarExpansion);
mdlDialog_dmsgsPrint (tmpString);
/* free when done */
free (cfgVarExpansion);
}
#if defined (MSVERSION) && (MSVERSION >= 0x551)
/* Starting with 5.5.1, it is possible to get expanded value in one step */
cfgVarExpansion = mdlSystem_getExpandedCfgVar ("MS_DEF");
if (cfgVarExpansion != NULL)
{
int count;
StringList *strListP;
/* in 5.5.1, it is possible to create a list from a cfg vars value */
count = mdlSystem_createListFromCfgVarValue (&strListP, cfgVarExpansion);
if (count > 0)
{
char *valueEntryP;
int j;
for (j=0; j<count; j++)
{
mdlStringList_getMember (&valueEntryP, NULL, strListP, j);
sprintf (tmpString, "(%d) MS_DEF = %s", j, valueEntryP);
mdlDialog_dmsgsPrint (tmpString);
}
/* free string list created by createListFromCfgVarValue */
mdlStringList_destroy (strListP);
}
/* free when done */
free (cfgVarExpansion);
}
#endif
/* Delete the newly created configuration variable */
mdlSystem_deleteCfgVar ("TMP_NEW");
mdlSystem_getCfgVar (cfgVarValue, "TMP_NEW", sizeof(cfgVarValue));
excfgvar_rscSprintf(tmpString, MSGID_TMPNEWDELETED, cfgVarValue);
mdlDialog_dmsgsPrint (tmpString);
/* Define another new configuration variable */
mdlSystem_defineCfgVar ("TMP_ANOTHERNEW", "$(MSDIR)new.txt", CFGVAR_LEVEL_USER);
/* Check to see if the configuration variable is locked */
if (mdlSystem_isCfgVarLocked ("TMP_ANOTHERNEW") == TRUE)
{
mdlResource_loadFromStringList (tmpString, NULL, MESSAGELISTID_Msgs,
MSGID_TMPANOTHERNEWLOCKED);
mdlDialog_dmsgsPrint (tmpString);
}
else
{
mdlResource_loadFromStringList (tmpString, NULL, MESSAGELISTID_Msgs,
MSGID_TMPANOTHERNEWNOTLOCKED);
mdlDialog_dmsgsPrint (tmpString);
}
/* Lock the new configuration variable then try to change it */
mdlSystem_lockCfgVar ("TMP_ANOTHERNEW");
if (mdlSystem_isCfgVarLocked("TMP_ANOTHERNEW") == TRUE)
{
mdlResource_loadFromStringList (tmpString, NULL, MESSAGELISTID_Msgs,
MSGID_TMPANOTHERNEWNOWLOCKED);
mdlDialog_dmsgsPrint (tmpString);
}
/* Clear the string & get the newly created configuration variable */
mdlSystem_getCfgVar (cfgVarValue, "TMP_ANOTHERNEW", sizeof(cfgVarValue));
sprintf (tmpString, "TMP_ANOTHERNEW = %s", cfgVarValue);
mdlDialog_dmsgsPrint (tmpString);
/* Unsuccessfully delete the newly created & locked config variable */
mdlSystem_deleteCfgVar ("TMP_NEW");
if (mdlSystem_getCfgVar
(cfgVarValue, "TMP_ANOTHERNEW", sizeof(cfgVarValue)) == SUCCESS)
{
excfgvar_rscSprintf (tmpString, MSGID_TMPANOTHERNEWCANTDELETE,
cfgVarValue);
mdlDialog_dmsgsPrint (tmpString);
}
/* prints out the level that _USTN_SYSTEM IS */
mdlSystem_getCfgVarLevel(&cfgLevel,"_USTN_SYSTEM");
/* convert level number to level name (msdefs.h) */
switch (cfgLevel)
{
case CFGVAR_LEVEL_SYSENV:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_SysEnv);
break;
case CFGVAR_LEVEL_SYSTEM:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_System);
break;
case CFGVAR_LEVEL_APPL:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs,
MSGID_Application);
break;
case CFGVAR_LEVEL_SITE:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_Site);
break;
case CFGVAR_LEVEL_PROJECT:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_Project);
break;
case CFGVAR_LEVEL_USER:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_User);
break;
default:
mdlResource_loadFromStringList (cfgLevelName, NULL,
MESSAGELISTID_Msgs, MSGID_Unknown);
}
excfgvar_rscSprintf (tmpString, MSGID_USTNSYSTEM, cfgLevelName);
mdlDialog_dmsgsPrint (tmpString);
/* prints out all of the config variables starting with MS_C */
mdlDialog_dmsgsPrint (" ");
mdlResource_loadFromStringList (tmpString, NULL, MESSAGELISTID_Msgs,
MSGID_MSC);
mdlDialog_dmsgsPrint (tmpString);
i=0;
while (TRUE)
{
if (mdlSystem_getCfgVarByIndex (&name, NULL, NULL, NULL, i++) != SUCCESS)
break;
/* Only print those beginning with MS_C */
if (strncmp (name, "MS_C", 4) == 0)
{
mdlDialog_dmsgsPrint (name);
}
}
return (SUCCESS);
}