home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir03
/
f014430.re_
/
f014430.re
Wrap
Text File
|
1996-04-02
|
7KB
|
188 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. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Logfile: J:/mdl/examples/doc/parse.mcv $
| $Workfile: parse.mc $
| $Revision: 5.2 $
| $Date: 20 Jun 1995 08:49:48 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| parse.mc - examples for the mdlParse_ functions. |
| |
| This file is intended as an adjunct to the MDL manual to |
| illustrate MDL built-in function calling conventions and parameter |
| values. While it can be compiled, it does NOT, on its own, |
| constitute a workable MDL example. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h> /* system include files */
#include <userfnc.h>
#include <msinputq.h>
#include <cmdlist.h>
#include <cmdclass.h>
/*----------------------------------------------------------------------+
| |
| Function declarations |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name main |
| |
| author BSI 12/90 |
| |
+----------------------------------------------------------------------*/
main (void)
{
int userParseFunction ();
mdlParse_setFunction (PARSE_HANDLE_STRING, userParseFunction);
}
/*----------------------------------------------------------------------+
| |
| Private Utility Routines |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name handleCommands |
| |
| author BSI 12/90 |
| |
+----------------------------------------------------------------------*/
void commandHandler
(
char *unparsedP
) cmdNumber 1, 2
{
mdlOutput_printf (MSG_MESSAGE, "Command %d, unparsed %s",
mdlCommandNumber, unparsedP);
}
/*----------------------------------------------------------------------+
| |
| name createCommandIQel |
| |
| author BSI 12/90 |
| |
+----------------------------------------------------------------------*/
Private void createCommandIQel
(
Inputq_element *queueElementP,
int commandNumber,
boolean microStationCommand,
int commandClass, /* PLACEMENT, VIEWING, etc. */
char *unparsedP
)
{
memset (queueElementP, '\0', sizeof (Inputq_header) +
sizeof (Inputq_command));
queueElementP->hdr.cmdtype = CMDNUM;
queueElementP->hdr.bytes = sizeof (Inputq_header) +
sizeof (Inputq_command);
/* The size already includes the EOS. Add in the count of non-zero
bytes in the string.
*/
if (unparsedP)
queueElementP->hdr.bytes += strlen (unparsedP);
queueElementP->hdr.source = FROM_MDL;
/* commandNumber should be a MicroStation command number taken
from cmdlist.h or should be a number associated with an MDL
application with a cmdNumber directive
*/
queueElementP->u.cmd.command = commandNumber;
/* Identify type of functionality provided by the command. This
information may be used by command filters. */
queueElementP->u.cmd.class = commandClass;
/*------------------------------------------------------------------+
Set the task ID in the command structure to tell MicroStation what
task should execute the command. Note that nothing is stored in the
task ID in the header of the queue element. The task ID in the
header is used to address the queue element to a specific task.
+-------------------------------------------------------------------*/
/* Set the task ID */
if (microStationCommand)
strcpy (queueElementP->u.cmd.taskId, ustnTaskId);
else
strcpy (queueElementP->u.cmd.taskId, mdlSystem_getCurrTaskID ());
strcpy (queueElementP->u.cmd.unparsed, unparsedP);
}
/*----------------------------------------------------------------------+
| |
| name userParseFunction |
| |
| author BSI 12/90 |
| |
| userParseFunction illustrates how MicroStation responds to |
| different return values from the parse function. |
| |
| AA - queues command number 1 |
| A - queue command number 2 |
| DX - returns ambiguous command |
| ZZ - returns ambiguous command |
| |
+----------------------------------------------------------------------*/
Private int userParseFunction
(
Inputq_element *queueElementP, /* <= MicroStation will queue it */
char *stringP
)
{
char buffer [5];
strncpy (buffer, stringP, 5);
buffer [4] = '\0';
strupr (buffer);
if (!strncmp (buffer, "AA=", 3))
/* Replaces a MicroStation command. Note that this can only be
done for the 2-character codes. */
createCommandIQel (queueElementP, 1, FALSE, PARAMETERS, stringP+3);
else if (!strncmp (buffer, "A=", 2))
/* Overrides MicroStation's ambiguous error. */
createCommandIQel (queueElementP, 2, FALSE, PARAMETERS, stringP+2);
else if (!strncmp (buffer, "DX=", 3))
/* MicroStation will override the parse functions ambiguous error */
return -2;
else if (!strncmp (buffer, "ZZ=", 3))
/* MicroStation will display an "ambiguous command" */
return -2;
else
return -1;
return SUCCESS;
}