home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir03
/
f014640.re_
/
f014640.re
Wrap
Text File
|
1996-04-02
|
9KB
|
306 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: K:/mdl/examples/externpg/externpg.c_v $
| $Workfile: externpg.c $
| $Revision: 5.19 $
| $Date: 22 Nov 1995 12:40:04 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| externpg.c -- Sample external program. This program is started |
| by the MDL application in externpg.mc. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
/* basedefs.h is first to make sure the environment constants such as
"unix" are defined. */
#include <basedefs.h>
#include <mdl.h>
#include <msextern.h>
#include "externpg.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <extprg.fdf>
/*----------------------------------------------------------------------+
| |
| Local defines |
| |
+----------------------------------------------------------------------*/
#define strcpyFromFar(dp, sp) \
{ \
char *d; \
SHMEM_SC char *s; \
d = dp, s = sp; \
while ((*d++ = *s++) != 0); \
}
#define strcpyToFar(dp, sp) \
{ \
char *s; \
SHMEM_SC char *d; \
d = dp, s = sp; \
while ((*d++ = *s++) != 0); \
}
/*----------------------------------------------------------------------+
| |
| Local type definitions |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Global variables |
| |
+----------------------------------------------------------------------*/
SHMEM_SC char *pSharedMem;
MSMsgqDescr *pQueueDescr;
#if defined (macintosh)
FILE *logFile;
#endif
/*----------------------------------------------------------------------+
| |
| External variables |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Function declarations |
| |
+----------------------------------------------------------------------*/
/*ff Major Public Code Section */
/*----------------------------------------------------------------------+
| |
| Major Public Code Section |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| name externpg_init |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void externpg_init
(
void
)
{
#if defined (macintosh)
/* Set the stack size */
extprg_initializePlatform (16000);
/* Open a file for printing progress and error messages */
logFile = fopen ("externpg.log", "w");
#endif
}
/*----------------------------------------------------------------------+
| |
| name externpg_output |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void externpg_output
(
char *string /* => string to output */
)
{
#if defined (macintosh)
if (logFile)
fprintf (logFile, "%s\n", string);
#else
printf ("%s\n", string);
#endif
}
/*----------------------------------------------------------------------+
| |
| name externpg_exit |
| |
| author BSI 10/92 |
| |
+----------------------------------------------------------------------*/
Private void externpg_exit
(
int exitStatus
)
{
#if defined (macintosh)
/* Close the message file */
fclose (logFile);
#endif
extprg_shutdownPlatform ();
exit(exitStatus);
}
#if defined (MWBUGFIXED)
/*----------------------------------------------------------------------+
| |
| name . |
| |
| author BSI 03/90 |
| |
+----------------------------------------------------------------------*/
Private void strcpyFromFar
(
char *destinationP,
SHMEM_SC char *sourceP
)
{
/* Stop as soon as the end of the string is copied. */
while ((*destinationP++ = *sourceP++) != 0)
;
}
/*----------------------------------------------------------------------+
| |
| name . |
| |
| author BSI 03/90 |
| |
+----------------------------------------------------------------------*/
Private void strcpyToFar
(
SHMEM_SC char *destinationP,
char *sourceP
)
{
/* Stop as soon as the end of the string is copied. */
while ((*destinationP++ = *sourceP++) != 0)
;
}
#endif
/*----------------------------------------------------------------------+
| |
| name . |
| |
| author BSI 03/90 |
| |
+----------------------------------------------------------------------*/
Public void main
(
int argc,
char *argv[]
)
{
ExternalMessage message;
char displayBuffer [200];
int i;
externpg_init ();
/* Fetch command line arguments if not passed directly (Macintosh) */
extprg_getCommandLineArguments (&argc, &argv);
for (i = 0; i < argc; i++)
externpg_output (argv[i]);
#if defined (pm386) && defined (debugMWPro)
_inline (0xcc);
#endif
/* First initialize the message queue and shared memory. */
if (argc != 3)
externpg_exit (1);
if ((pQueueDescr = extprg_queueAttach (*(argv+1))) == NULL)
externpg_exit (2);
externpg_output ("Got the queue descriptor.");
if ((pSharedMem = extprg_shmemAttach (*(argv+2))) == NULL)
{
sprintf (displayBuffer,
"Error attaching to the shared memory %s, errno = %d.",
*(argv+2), errno);
externpg_output (displayBuffer);
externpg_exit (3);
}
externpg_output ("Got the shared memory.");
for (;;)
{
if (extprg_messageReceive (&message, pQueueDescr, 0, 0) != 0)
{
sprintf (displayBuffer,
"messageReceive returned an error. errno = %d.",
errno);
externpg_output (displayBuffer);
externpg_exit (4);
}
externpg_output ("Received a message.");
switch (message.reqtype)
{
case EXTERNPG_UPDATE:
externpg_output ("received update request.");
message.reqtype = EXTERNPG_ACKNOWLEDGE;
message.msglength = 0;
/* Do all time critical work prior to responding to
MicroStation.
*/
if (extprg_messageSend (&message, pQueueDescr))
externpg_exit (5);
break;
case EXTERNPG_DISPLAY:
/* Display the contents of the shared memory buffer */
strcpyFromFar (displayBuffer, pSharedMem);
externpg_output (displayBuffer);
message.reqtype = EXTERNPG_ACKNOWLEDGE;
message.msglength = 0;
strcpyToFar (pSharedMem, "Here it is");
if (extprg_messageSend (&message, pQueueDescr))
externpg_exit (5);
break;
case EXTERNPG_TERMINATE:
/* The MDL application is being unloaded. Perform
any clean up required, such as closing and flushing
files. Then send an acknowledge to the
application. */
message.reqtype = EXTERNPG_ACKNOWLEDGE;
message.msglength = 0;
if (extprg_messageSend (&message, pQueueDescr))
externpg_exit (5);
/* Exit with no errors. */
externpg_exit (20);
default:
externpg_output ("in default case.");
externpg_exit (6);
}
}
}