home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir04 / f014280.re_ / f014280.re
Text File  |  1996-04-02  |  6KB  |  178 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1995) Bentley Systems, Inc., All rights reserved.        |
  4. |                                    |
  5. |  "MicroStation" is a registered trademark and "MDL" and "MicroCSL"    |
  6. |  are trademarks of Bentley Systems, Inc.                    |
  7. |                                    |
  8. |  Limited permission is hereby granted to reproduce and modify this    |
  9. |  copyrighted material provided that the resulting code is used only     |
  10. |  in conjunction with Bentley Systems products under the terms of the    |
  11. |  license agreement provided therein, and that this notice is retained    |
  12. |  in its entirety in any such reproduction or modification.        |
  13. |                                    |
  14. +----------------------------------------------------------------------*/
  15. /*----------------------------------------------------------------------+
  16. |                                    |
  17. |    $Logfile:   J:/mdl/examples/doc/cexpr.mcv  $
  18. |   $Workfile:   cexpr.mc  $
  19. |   $Revision:   5.2  $
  20. |       $Date:   20 Jun 1995 08:49:58  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   cexpr.mc - examples for the mdlCExpression_ functions.          |
  26. |                                    |
  27. |   This file is intended as an adjunct to the MDL manual to        |
  28. |   illustrate MDL built-in function calling conventions and parameter    |
  29. |   values. While it can be compiled, it does NOT, on its own,        |
  30. |   constitute a workable MDL example.                      |
  31. |                                    |
  32. |   See the files in mdl\examples\calculat for a useful example of      |
  33. |   the mdlCExpression_ functions.                      |
  34. |                                    |
  35. +----------------------------------------------------------------------*/
  36. /*----------------------------------------------------------------------+
  37. |                                    |
  38. |   Include Files                               |
  39. |                                    |
  40. +----------------------------------------------------------------------*/
  41.  
  42. #include    <mdl.h>
  43. #include    <cexpr.h>
  44.  
  45. /*----------------------------------------------------------------------+
  46. |                                    |
  47. |   Private variables                            |
  48. |                                    |
  49. +----------------------------------------------------------------------*/
  50.  
  51. Private void    *setP;
  52. Private CType   *intPointerTypeP, *doubleArrayTypeP;
  53.  
  54.  
  55. /*----------------------------------------------------------------------+
  56. |                                    |
  57. |   Variables to be published                       |
  58. |                                    |
  59. +----------------------------------------------------------------------*/
  60.  
  61. int     intVariable;
  62. int    *intVariable1P, *intVariable2P;
  63. double    *doubleArrayP;
  64.  
  65. /*----------------------------------------------------------------------+
  66. |                                    |
  67. | name        displayError                        |
  68. |                                    |
  69. | author    BSI                     9/90        |
  70. |                                    |
  71. |    The MDL Debugger clobbers the information used by the system    |
  72. |    to generate the message. If you are stepping through this       |
  73. |    with the MDL debugger, the message that is generated will be    |
  74. |    incorrect.                              |
  75. |                                    |
  76. +----------------------------------------------------------------------*/
  77. displayError (void)
  78.     {
  79.     char    messageBuffer [128];    /* The message is guaranteed to be less
  80.                        than 128 characters */
  81.                     
  82.     mdlCExpression_generateMessage (messageBuffer, mdlErrno);
  83.     mdlOutput_error (messageBuffer);
  84.     }
  85.     
  86. /*----------------------------------------------------------------------+
  87. |                                    |
  88. | name        hideSymbols                         |
  89. |                                    |
  90. | author    BSI                     9/90        |
  91. |                                    |
  92. +----------------------------------------------------------------------*/
  93. cmdName hideSymbols
  94. (
  95. )
  96.     {
  97.     if (setP != NULL)
  98.     {
  99.     /*  The call to mdlCExpression_freeSet frees all memory 
  100.         associated with the symbol set. It frees all memory 
  101.         that had been allocated by calls to 
  102.         mdlCExpression_typeFromRsc, mdlCExpression_typePointer, etc */
  103.     mdlCExpression_freeSet (setP);
  104.     setP = NULL;
  105.     }
  106.     }
  107.  
  108. /*----------------------------------------------------------------------+
  109. |                                    |
  110. | name        publishSymbols                      |
  111. |                                    |
  112. | author    BSI                     9/90        |
  113. |                                    |
  114. +----------------------------------------------------------------------*/
  115. cmdName publishSymbols
  116. (
  117. )
  118.     {
  119.     /*  Initialize the symbol set. Set it up so that symbols that are
  120.     added to it can be recognized by the calculator. */
  121.     setP = mdlCExpression_initializeSet (VISIBILITY_CALCULATOR, 0, FALSE);
  122.  
  123.     /*  Create a simple variable */
  124.     mdlCExpression_symbolPublish (setP, "intVariable", SYMBOL_CLASS_VAR,
  125.         &intType, &intVariable);
  126.  
  127.     /*  Create a pointer variable. First define a type that can be used
  128.     for all subsequent definitions of varaibles with type pointer
  129.     to int.
  130.     */
  131.     intPointerTypeP = mdlCExpression_typePointer (setP, &intType);
  132.     mdlCExpression_symbolPublish (setP, "pointer1", SYMBOL_CLASS_VAR,
  133.         intPointerTypeP, &intVariable1P);
  134.     mdlCExpression_symbolPublish (setP, "pointer2", SYMBOL_CLASS_VAR,
  135.         intPointerTypeP, &intVariable2P);
  136.  
  137.     /*  Create an array variable. */
  138.     doubleArrayP = malloc (sizeof (double) * 10);
  139.     doubleArrayTypeP = mdlCExpression_typeArray (setP, &doubleType, 10);
  140.     mdlCExpression_symbolPublish (setP, "doubleArray", SYMBOL_CLASS_VAR,
  141.         doubleArrayTypeP, doubleArrayP);
  142.     }
  143.  
  144.  
  145. /*----------------------------------------------------------------------+
  146. |                                    |
  147. | name        evaluateExpressions                     |
  148. |                                    |
  149. | author    BSI                     9/90        |
  150. |                                    |
  151. +----------------------------------------------------------------------*/
  152. cmdName evaluateExpressions
  153. (
  154. )
  155.     {
  156.     CExprResult         result;        /*  Detailed result */
  157.     CExprValue         value;        /*  Similar to result, but easier to
  158.                     interpret. */
  159.     
  160.     if (mdlCExpression_getValue (&value, &result, "intVariable*20", 
  161.     VISIBILITY_CALCULATOR))
  162.     displayError ();
  163.     
  164.     if (mdlCExpression_getValue (&value, &result, "INTVariable-10",
  165.     VISIBILITY_CALCULATOR))
  166.     displayError ();
  167.     
  168.     /*  The following sequence sets doubleArray [2] to 5.2 */
  169.     value.type = CEXPR_TYPE_DOUBLE;
  170.     value.val.valDouble = 5.2;
  171.     mdlCExpression_setValue (&value, NULL, "doubleArray [2]",
  172.                  VISIBILITY_CALCULATOR);
  173.                 
  174.     /*  The following sequence sets doubleArray [2] to 7.5 */
  175.     mdlCExpression_getValue (&value, &result, "doubleArray [2] = 7.5",
  176.                  VISIBILITY_CALCULATOR);
  177.     }
  178.