ftp.nice.ch/pub/next/science/mathematics/workbench/MathConnector.s.tar.gz#/MathConnector/mathlink.h

This is mathlink.h in view mode; [Download] [Up]

/*************************************************************************

        Copyright 1986 through 1992 by Wolfram Research Inc.
        All rights reserved

$Id: mathlink.h,v 1.19 1992/04/09 15:23:23 rory Exp $ 

*************************************************************************/

#ifndef _MATHLINK_H
#define _MATHLINK_H



#if defined(applec) || defined(THINK_C)
#define MACINTOSH
#endif


#ifndef P
#if defined( __STDC__) || defined(applec) || defined(THINK_C)
#define P(s) s
#else 
#define P(s) ()
#endif
#endif

#if defined( __STDC__) || defined(applec) || defined(THINK_C)
#define extended long double
#else 
#define extended double
#endif

#ifndef NULL
#define NULL ((void *) 0)
#endif


/*************** Storage allocation ***************/
/* MathLink allocates and deallocates space on the
 * free store using functions pointed to by MLalloc
 * and MLdealloc. If the default functions are not
 * satisfactory, set BOTH of these global variables
 * before you use ANY MathLink funtions.  These
 * functions should NEVER be used again within the
 * same program.
 */
extern void*	(*MLalloc) P((unsigned long));
extern void	(*MLdealloc) P((void*));

/*************** Connection interface ***************/

typedef struct MLink *MLINK;


enum {
	MLNetworkVisibleMask	= 0x00000003,
	MLBrowseMask		= 0x00000010,
	MLNonBlockingMask	= 0x00000020,
	MLInteractMask		= 0x00000100
};

#define MLDefaultOptions  ((unsigned long)0x00000000)

enum {
	MLNetworkVisible	= 0x00000000,
	MLLocallyVisible	= 0x00000001,
	MLInternetVisible	= 0x00000002,

	MLBrowse		= 0x00000000,
	MLDontBrowse		= 0x00000010,

	MLNonBlocking		= 0x00000000,
	MLBlocking		= 0x00000020,

	MLInteract		= 0x00000000,
	MLDontInteract		= 0x00000100
};

extern MLINK  MLOpen P(( int, char**));

extern MLINK  MLLaunch P(( char*, char*, unsigned long));
extern MLINK  MLParentConnect P(( char*, unsigned long ));
extern MLINK  MLTCPConnect P(( char*, char*, unsigned long));
extern MLINK  MLTCPListen P(( char*,  unsigned long ));
#ifdef MACINTOSH
extern MLINK  MLPPCConnect P(( char*, char*, unsigned long));
extern MLINK  MLPPCListen P(( char*,  unsigned long ));
#endif

/* The following functions are obsolete or for internal use */
#ifndef MACINTOSH
extern MLINK  MLStart P((char *));
extern MLINK  MLPipeStart P((char*,int,int,int,int));
extern MLINK  MLPipeConnect P((char*, int,int,int,int));
extern MLINK  MLServerSocket P((char *));
extern MLINK  MLClientSocket P((char *));
#endif




/* MLName returns a pointer to the the link's name.
 * Links are generally named when they are created
 * and are based on information that is potentially
 * useful and is available at that time.
 * Do not attempt to deallocate the name's storage
 * through this pointer.  The storage should be
 * considered in read-only memory.
 */
extern char* MLName P((MLINK));

extern char* MLRename P(( MLINK, char* ));

extern int   MLFlush P((MLINK));		
extern int   MLReady P((MLINK));
extern void  MLClose P((MLINK));

extern void MLSetUserData P(( MLINK, void* ));
extern void* MLGetUserData P(( MLINK ));



/* The following functions and enumerations are for internal use only */

#ifndef _MLMAKE
#define _MLMAKE
extern void    *(*_MLalloc) P((unsigned long));
extern void    (*_MLdealloc) P((void*));

enum {  _MLYinYangMask = 0x00000003,
        _MLFlowControlMask = 0x00000010,
        _MLBufferingMask = 0x00000300
 };

enum {  _MLNeuter = 0x00000000, _MLYin = 0x00000001, _MLYang = 0x00000002,
        _MLFlowControlOn = 0x00000000, _MLFlowControlOff = 0x00000010,
        _MLFullyBuffered = 0x00000000, _MLNotBuffered   = 0x00000300,
        _MLNotReadBuffered = 0x00000100, _MLNotWriteBuffered  = 0x00000200
 };

extern struct _MLink* _MLmake();

#endif

extern MLINK MLmake();
extern int   MLConnect P((MLINK));
extern int   MLFill P((MLINK));
extern int   MLNumber P((MLINK));
extern MLINK MLQueue();



/*************** Textual interface ***************/

#define	MLTKSYM		'Y'		/* symbol leaf node */
#define	MLTKSTR		'S'		/* string leaf node */
#define	MLTKINT		'I'		/* integer leaf node */
#define	MLTKREAL	'R'		/* real leaf node */
#define	MLTKFUNC	'F'		/* non-leaf node */
#define	MLTKPCTEND	']'		/* at end of top level expression */
#define	MLTKERROR	(0)		/* bad token */

extern int   MLGetNext P((MLINK));
extern int   MLGetType P((MLINK));
extern int   MLGetData P((MLINK, char*, long, long* ));	
extern int   MLGetArgCount P((MLINK, long* ));
extern int   MLBytesToGet P((MLINK, long* ));

extern int   MLPutNext P((MLINK, int));
extern int   MLPutSize P((MLINK, long));	
extern int   MLPutData P((MLINK, char *, long));	
extern int   MLPutArgCount P((MLINK, long));	
extern int   MLBytesToPut P((MLINK, long*));

/* MLTKEND, MLTKAEND, and MLTKELEN are for internal use only */
#define	MLTKEND		'\n'
#define	MLTKAEND	'\r'
#define	MLTKELEN	' '

/*************** Native C types interface ***************/

/* The functions MLGetString, MLGetSymbol, MLGetString,
 * MLGetFunction, MLGetIntegerList, and
 * MLGetRealList return a pointer to a buffer inside
 * of MathLink.  This buffer should be considered read-
 * only and must be returned to MathLink when you are
 * through using it.  MathLink is only lending you 
 * access to its internal data.  You MUST not free
 * this buffer as it may not have been allocated on
 * the free store.  You should not change the contents
 * of the buffer as the data may be used elsewhere
 * within MathLink or elsewhere in your program.
 * For example:
 *	f(){
 *		char* s;
 *		...
 *		if( MLGetSymbol(stdlink, &s) ){
 *			deal_with_symbol(s);
 *			MLDisownSymbol(stdlink, s);
 *		}
 *		...
 * 	}
 */

extern int   MLGetShortInteger P(( MLINK, short* ));
extern int   MLGetInteger      P(( MLINK, int* ));
extern int   MLGetLongInteger  P(( MLINK, long* ));
extern int   MLGetFloat        P(( MLINK, float* ));
extern int   MLGetReal         P(( MLINK, double* ));
extern int   MLGetDouble       P(( MLINK, double* ));
#define      MLGetReal( mlp, xp) MLGetDouble(mlp, xp)

extern int   MLGetString     P(( MLINK, char** ));
extern void  MLDisownString  P(( MLINK, char* ));
extern int   MLGetSymbol     P(( MLINK, char** ));
extern int   MLGetFunction   P(( MLINK, char**, long* )); 
extern void  MLDisownSymbol  P(( MLINK, char* ));

extern int   MLCheckFunction   P(( MLINK, char*, long* )); 
extern int   MLCheckFunctionWithArgCount P(( MLINK, char*, long* ));


extern int   MLGetIntegerList    P(( MLINK, int**, long* ));
extern void  MLDisownIntegerList P(( MLINK, int*, long ));
extern int   MLGetRealList       P(( MLINK, double**, long* ));
extern void  MLDisownRealList    P(( MLINK, double*, long ));


extern int   MLPutShort       P(( MLINK, int ));  
extern int   MLPutInteger     P(( MLINK, int ));  
extern int   MLPutLongInteger P(( MLINK, long ));  

extern int   MLPutFloat       P(( MLINK, double ));
extern int   MLPutReal        P(( MLINK, double ));
extern int   MLPutDouble      P(( MLINK, double ));
#define      MLPutReal( mlp, x) MLPutDouble(mlp, x)

extern int   MLPutString  P(( MLINK, char* ));
extern int   MLPutSymbol  P(( MLINK, char* ));

#define	    MLPutExpression( mlp, argn) is obsolete, use \
		(MLPutNext( mlp, MLTKFUNC) \
		&& MLPutArgCount( mlp, argn))

extern int   MLPutFunction P(( MLINK, char*, long ));
#define	     MLPutFunction( mlp, s, argn) \
		(MLPutNext( mlp, MLTKFUNC) \
		&& MLPutArgCount( mlp, argn) \
		&& MLPutSymbol( mlp, s))

extern int   MLPutIntegerList P(( MLINK, int*, long));
extern int   MLPutRealList P(( MLINK, double*, long));


/*************** Mathematica packet interface ***************/

extern int  MLNextPacket P((MLINK));
			/* get the next packet, return one of... */

#define INPUTPKT       1
#define TEXTPKT        INPUTPKT+1 
#define RETURNPKT      TEXTPKT+1
#define RETURNTEXTPKT  RETURNPKT+1
#define MESSAGEPKT     RETURNTEXTPKT+1 
#define MENUPKT        MESSAGEPKT+1 
#define CALLPKT        MENUPKT+1
#define INPUTNAMEPKT   CALLPKT+1
#define OUTPUTNAMEPKT  INPUTNAMEPKT+1
#define SYNTAXPKT      OUTPUTNAMEPKT+1
#define DISPLAYPKT     SYNTAXPKT+1
#define DISPLAYENDPKT  DISPLAYPKT+1

extern int  MLNewPacket P((MLINK));
			/* skip to the end of the current packet */

extern int  MLEndPacket P((MLINK));
			/* send an end-of-packet marker */

/*************** Template interface ***************/

/* The following are useful only when using template files.*/

extern MLINK	stdlink;
extern int	MLMain P((int, char**)); /* pass in argc and argv */

extern int	MLInstall P((MLINK));
extern int	MLMainStep P((MLINK));
extern int	MLEvaluate P(( MLINK, char* ));
extern int	MLAbort;


/*************** Experimental enhancements ***************/

extern int   MLPutIntegerArray
	P(( MLINK, int* data, long* dims, char** heads, long depth));

extern int   MLPutShortIntegerArray
	P(( MLINK, short* data, long* dims, char** heads, long depth));

extern int   MLPutLongIntegerArray
	P(( MLINK, long* data, long* dims, char** heads, long depth));

extern int   MLPutDoubleArray
	P(( MLINK, double* data, long* dims, char** heads, long depth));

extern int   MLPutFloatArray
	P(( MLINK, float* data, long* dims, char** heads, long depth));



extern int   MLGetIntegerArray
	 P(( MLINK mlp, int **data, long **dims, char ***heads, long *depth));
extern void  MLDisownIntegerArray P(( MLINK, int*, long*, char**, long));

extern int   MLGetShortIntegerArray
	 P(( MLINK mlp, short **data, long **dims, char ***heads, long *depth));
extern void  MLDisownShortIntegerArray P(( MLINK, short*, long*, char**, long));

extern int   MLGetLongIntegerArray
	 P(( MLINK mlp, long **data, long **dims, char ***heads, long *depth));
extern void  MLDisownLongIntegerArray P(( MLINK, long*, long*, char**, long));


extern int   MLGetDoubleArray
	P(( MLINK mlp, double** data, long** dims, char*** heads, long* depth));
extern void  MLDisownDoubleArray P(( MLINK, double*, long*, char**, long));

extern int   MLGetFloatArray
	P(( MLINK mlp, float** data, long** dims, char*** heads, long* depth));
extern void  MLDisownFloatArray P(( MLINK, float*, long*, char**, long));

/*NOPRE*/
extern int   MLGetLongDouble   P(( MLINK, extended* ));
extern int   MLPutLongDouble  P(( MLINK, extended ));
extern int   MLPutLongDoubleArray
	P(( MLINK, extended* data, long* dims, char** heads, long depth));
extern int   MLGetLongDoubleArray
	P(( MLINK mlp, extended** data, long** dims, char*** heads, long* depth));
extern void  MLDisownLongDoubleArray P(( MLINK, extended*, long*, char**, long));
/*ENDNOPRE*/




/*************** Message interface ***************/
enum {	MLTerminateMessage = 1, MLInterruptMessage, MLAbortMessage,
	MLEndPacketMessage, MLSynchronizeMessage, MLImDyingMessage,
	MLWaitingAcknowledgment,
	MLFirstUserMessage = 128, MLLastUserMessage = 255 };

extern int   MLPutMessage P(( MLINK, unsigned long msg ));
extern int   MLMessageReady P(( MLINK ));
extern int   MLGetMessage P(( MLINK, unsigned long *msgp, unsigned long *markp ));

extern int   MLGetMessageHandler ();
extern int   MLSetMessageHandler ();

/*************** Threads interface ***************/

extern int   MLGetYieldFunction ();
extern int   MLSetYieldFunction ();

/*************** MathLink errors ***************/
/*
 * When some problem is detected within MathLink, routines
 * will return a simple indication of failure and store
 * an error code internally. (For routines that have nothing
 * else useful to return, success is indicated by returning
 * non-zero and failure by returning 0.)  MLerror() returns
 * the current error code;  MLErrorMessage returns an English
 * language description of the error.
 * The error MLEDEAD is irrecoverable.  For the others, MLClearError()
 * will reset the error code to MLEOK.
 */

extern int   MLError P((MLINK));
			 /* return link error code */
extern int   MLClearError P((MLINK));
			 /* reset errno to MLEOK, if possible */
extern int   MLSetError P((MLINK, int));
			 /* set errno if currently MLEOK */
extern char  *MLErrorMessage P((MLINK));
extern void  MLPrintErrorMessage P((MLINK));

#define	MLEOK		0	/* everything ok so far */
#define	MLEDEAD		1	/* link died -- unrecoverable error */
#define	MLEGBAD		2	/* inconsitent data was read */
#define	MLEGSEQ		3	/* MLGet? out of sequence */
#define	MLEPBTK		4	/* MLPutNext() was passed a bad token */
#define	MLEPSEQ		5	/* MLPut? out of sequence */
#define	MLEPBIG		6	/* MLPutData given too much data */
#define	MLEOVFL		7	/* machine integer overflow */
#define	MLEMEM		8	/* out of memory */
#define	MLEACCEPT	9	/* failure to accept socket connection */
#define	MLECONNECT	10	/* a deferred connection is
				 * still unconnected
				 */
#define	MLECLOSED	11	/* the other side closed the link, you may
				 * still get undelivered data
				 */

#define	MLEPUTENDPACKET	 21
		/* unexpected call of MLEndPacket; currently atoms aren't
		 * counted on the way out so this error is raised only when
		 * MLEndPacket is called in the midst of an atom
		 */
#define	MLENEXTPACKET	22
		/* MLNextPacket called while the current packet has
		 * unread data
		 */
#define	MLEUNKNOWNPACKET 23
		/* MLNextPacket read in an unknown packet head */
#define	MLEGETENDPACKET  24	 /* unexpected end-of-packet token */
#define MLEABORT         25	 /* a put or get was aborted before
				  * affecting the link
				  */

#define	MLEUSER        1000	 /* start of user defined errors */


/*************** User interaction--for internal use only ***************/

extern void	MLAlert P((const char* /*message*/ ));
extern char*	MLRequest P((const char* /*prompt*/, char* /*response and default*/,
			long /*sizeof(response)*/ )); 
extern int	MLConfirm P((const char* /*yes|no question*/,
			int /*default answer*/));

/*************** MathLink non-ASCII string interface ***************/

/*
 * To iterate over the character codes in a MathLink string,
 * use MLStringChar inside of an MLforString loop.
 *
 *	f()
 *	{
 *		MLStringPosition pos;
 *		int code;
 *		char *s;
 *		if( MLGetString(stdlink, &s)) {
 *			MLforString (s, pos) {
 *				ch = MLStringChar(pos);
 *				use_the_character_code(code);
 *			}
 *			MLDisownString(stdlink, s);
 *		}
 *	}
 *
 * To construct a MathLink string from a sequence of
 * character codes, use MLPutCharToString inside a for
 * loop. MLPutCharToString(code, NULL) returns the number of
 * bytes required to encode code.
 *
 *	g(codes, len)
 *		int codes[];
 *		int len;
 *	{
 *		int i, size;
 *		char *s, *p;
 *		for( i = 0; i<len; i++)
 *			size += MLPutCharToString(codes[i], NULL);
 *
 *		if( p = s = (char*)malloc(size + 1) ) {
 *			for( i = 0; i<len; i++)
 *				MLPutCharToString(codes[i], &p);
 *			*p = '\0';
 *			MLPutString(stdlink, s);
 *			free(s);
 *		}
 *	}
 */

typedef struct {
	unsigned char *cc;
	int  mode;
	int  more;
	unsigned char *head;
	} MLStringPosition;

extern int   MLPutCharToString P((int, char**));

#define MLforString( s, pos) \
  for ( MLStringFirstPos( s, pos); (pos).more; MLStringNextPos( pos))

#define MLStringChar(pos) \
  ( ((pos).mode <= 1) ? *(unsigned char*)((pos).cc) : MLStringCharFun( &pos) )

 
 	
/* The following names are for internal use only */

#define MLStringFirstPos(s,pos) MLStringFirstPosFun( s, &(pos))

#define MLStringNextPos(pos)  (                   \
	((pos).mode == 0)                           \
	? ((*(*(pos).cc ? ++(pos).cc : (pos).cc)     \
		? 0                                  \
		: ((pos).more = 0)),                     \
  	   (pos).cc)                                \
	: MLStringNextPosFun( &pos) )


extern unsigned char  *MLStringNextPosFun P((MLStringPosition *)); 		
extern unsigned char  *MLStringFirstPosFun P((char *, MLStringPosition *)); 
extern int MLStringCharFun P(( MLStringPosition *));


#endif /* _MATHLINK_H */

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.