home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir03 / f014430.re_ / f014430.re
Text File  |  1996-04-02  |  7KB  |  188 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/parse.mcv  $
  18. |   $Workfile:   parse.mc  $
  19. |   $Revision:   5.2  $
  20. |       $Date:   20 Jun 1995 08:49:48  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   parse.mc - examples for the mdlParse_ 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. +----------------------------------------------------------------------*/
  33. /*----------------------------------------------------------------------+
  34. |                                    |
  35. |   Include Files                               |
  36. |                                    |
  37. +----------------------------------------------------------------------*/
  38. #include    <mdl.h>        /* system include files */
  39. #include    <userfnc.h>
  40. #include    <msinputq.h>
  41. #include    <cmdlist.h>
  42. #include    <cmdclass.h>
  43.  
  44. /*----------------------------------------------------------------------+
  45. |                                    |
  46. |   Function declarations                        |
  47. |                                    |
  48. +----------------------------------------------------------------------*/
  49.  
  50. /*----------------------------------------------------------------------+
  51. |                                    |
  52. | name        main                            |
  53. |                                    |
  54. | author    BSI                     12/90        |
  55. |                                    |
  56. +----------------------------------------------------------------------*/
  57. main (void)
  58.     {
  59.     int        userParseFunction ();
  60.     
  61.     mdlParse_setFunction (PARSE_HANDLE_STRING, userParseFunction);
  62.     }
  63.     
  64. /*----------------------------------------------------------------------+
  65. |                                    |
  66. |   Private Utility Routines                        |
  67. |                                    |
  68. +----------------------------------------------------------------------*/
  69. /*----------------------------------------------------------------------+
  70. |                                    |
  71. | name        handleCommands                          |
  72. |                                    |
  73. | author    BSI                     12/90        |
  74. |                                    |
  75. +----------------------------------------------------------------------*/
  76. void commandHandler
  77. (
  78. char     *unparsedP
  79. ) cmdNumber 1, 2
  80.     {
  81.     mdlOutput_printf (MSG_MESSAGE, "Command %d, unparsed %s",
  82.     mdlCommandNumber, unparsedP);
  83.     }
  84.  
  85. /*----------------------------------------------------------------------+
  86. |                                    |
  87. | name        createCommandIQel                       |
  88. |                                    |
  89. | author    BSI                     12/90        |
  90. |                                    |
  91. +----------------------------------------------------------------------*/
  92. Private void createCommandIQel
  93. (
  94. Inputq_element    *queueElementP,
  95. int         commandNumber,
  96. boolean         microStationCommand,
  97. int         commandClass,        /* PLACEMENT, VIEWING, etc. */
  98. char        *unparsedP
  99. )
  100.     {
  101.     memset (queueElementP, '\0', sizeof (Inputq_header) + 
  102.                         sizeof (Inputq_command));
  103.     queueElementP->hdr.cmdtype    = CMDNUM;
  104.  
  105.     
  106.     queueElementP->hdr.bytes    = sizeof (Inputq_header) + 
  107.             sizeof (Inputq_command);
  108.     
  109.     /* The size already includes the EOS. Add in the count of non-zero
  110.        bytes in the string.
  111.     */
  112.     if (unparsedP)
  113.     queueElementP->hdr.bytes += strlen (unparsedP);
  114.     
  115.     queueElementP->hdr.source    = FROM_MDL;
  116.  
  117.     /*  commandNumber should be a MicroStation command number taken 
  118.         from cmdlist.h or should be a number associated with an MDL 
  119.     application with a cmdNumber directive
  120.     */
  121.     queueElementP->u.cmd.command = commandNumber;
  122.  
  123.     /*  Identify type of functionality provided by the command. This
  124.     information may be used by command filters. */
  125.     queueElementP->u.cmd.class = commandClass;
  126.  
  127.     /*------------------------------------------------------------------+
  128.       Set the task ID in the command structure to tell MicroStation what 
  129.       task should execute the command. Note that nothing is stored in the 
  130.       task ID in the header of the queue element. The task ID in the 
  131.       header is used to address the queue element to a specific task. 
  132.     +-------------------------------------------------------------------*/
  133.     /* Set the task ID */
  134.     if (microStationCommand)
  135.     strcpy (queueElementP->u.cmd.taskId, ustnTaskId);
  136.     else
  137.     strcpy (queueElementP->u.cmd.taskId, mdlSystem_getCurrTaskID ());
  138.     
  139.     strcpy (queueElementP->u.cmd.unparsed, unparsedP);
  140.     }
  141.  
  142. /*----------------------------------------------------------------------+
  143. |                                    |
  144. | name        userParseFunction                    |
  145. |                                    |
  146. | author    BSI                     12/90        |
  147. |                                    |
  148. |    userParseFunction illustrates how MicroStation responds to      |
  149. |    different return values from the parse function.        |
  150. |                                    |
  151. |    AA - queues command number 1                    |
  152. |    A  - queue command number 2                      |
  153. |    DX - returns ambiguous command                  |
  154. |    ZZ - returns ambiguous command                  |
  155. |                                    |
  156. +----------------------------------------------------------------------*/
  157. Private int userParseFunction
  158. (
  159. Inputq_element    *queueElementP,        /* <= MicroStation will queue it */
  160. char        *stringP
  161. )
  162.     {
  163.     char    buffer [5];
  164.     
  165.     strncpy (buffer, stringP, 5);
  166.     buffer [4] = '\0';
  167.     strupr (buffer);
  168.     
  169.     if (!strncmp (buffer, "AA=", 3))
  170.     /*  Replaces a MicroStation command. Note that this can only be
  171.         done for the 2-character codes. */
  172.     createCommandIQel (queueElementP, 1, FALSE, PARAMETERS, stringP+3);
  173.     else if (!strncmp (buffer, "A=", 2))
  174.     /*  Overrides MicroStation's ambiguous error. */
  175.     createCommandIQel (queueElementP, 2, FALSE, PARAMETERS, stringP+2);
  176.     else if (!strncmp (buffer, "DX=", 3))
  177.     /*  MicroStation will override the parse functions ambiguous error */
  178.     return -2;
  179.     else if (!strncmp (buffer, "ZZ=", 3))
  180.     /*  MicroStation will display an "ambiguous command" */
  181.     return -2;
  182.     else
  183.     return -1;
  184.     
  185.     return SUCCESS;
  186.     }
  187.  
  188.