Advertisement
Guest User

mprep empty template

a guest
May 7th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.71 KB | None | 0 0
  1. /*
  2.  * This file automatically produced by /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions/mprep from:
  3.  *  main.tm
  4.  * mprep Revision 16 Copyright (c) Wolfram Research, Inc. 1990-2009
  5.  */
  6.  
  7. #define MPREP_REVISION 16
  8.  
  9. #if CARBON_MPREP
  10. #include <Carbon/Carbon.h>
  11. #include <mathlink/mathlink.h>
  12. #else
  13. #include "mathlink.h"
  14. #endif
  15.  
  16. int MLAbort = 0;
  17. int MLDone  = 0;
  18. long MLSpecialCharacter = '\0';
  19.  
  20. MLINK stdlink = 0;
  21. MLEnvironment stdenv = 0;
  22. #if MLINTERFACE >= 3
  23. MLYieldFunctionObject stdyielder = (MLYieldFunctionObject)0;
  24. MLMessageHandlerObject stdhandler = (MLMessageHandlerObject)0;
  25. #else
  26. MLYieldFunctionObject stdyielder = 0;
  27. MLMessageHandlerObject stdhandler = 0;
  28. #endif /* MLINTERFACE >= 3 */
  29.  
  30. #if DARWIN_MATHLINK && CARBON_MPREP
  31. #define rMenuBar    1128
  32. #define rAboutBox   1128
  33. #define rBadSIZE    1127
  34. #define mApple      1128
  35. #define iAbout      1
  36. #define mFile       1129
  37. #define mEdit       1130
  38.  
  39. AEEventHandlerUPP handle_core_ae_upp;
  40. ModalFilterUPP about_filter_upp;
  41. UserItemUPP outline_hook_upp;
  42.  
  43. extern pascal OSErr handle_core_ae( const AppleEvent* event, AppleEvent* reply, long refcon);
  44. extern int init_macintosh( void);
  45. extern void do_about_box( void);
  46. extern int _handle_user_event( unsigned long ticks);
  47.  
  48. pascal OSErr handle_core_ae( const AppleEvent* event, AppleEvent* reply, long refcon)
  49. {
  50.     DescType eventid, gottype;
  51.     Size got;
  52.     reply = (AppleEvent*)0; /* suppress unused warning */
  53.     refcon = 0; /* suppress unused warning */
  54.     if( noErr == AEGetAttributePtr(event, keyEventIDAttr, typeType, &gottype, (Ptr)&eventid, sizeof(eventid), &got)
  55.     && errAEDescNotFound == AEGetAttributePtr(event, keyMissedKeywordAttr, typeWildCard, &gottype, nil, 0, &got)
  56.     ){
  57.         switch(eventid){
  58.         case kAEQuitApplication:
  59.             MLDone = MLAbort = 1;
  60.         case kAEOpenApplication:
  61.             return noErr;
  62.         }
  63.     }
  64.     return errAEEventNotHandled;
  65. }
  66.  
  67.  
  68. static void set_about_item(void){
  69.     Str255 aboutitem;
  70.     StringHandle abouthandle;
  71.  
  72.     GetMenuItemText( GetMenuHandle(mApple), iAbout, aboutitem);
  73.     abouthandle = NewString( aboutitem);
  74.     if( abouthandle){
  75.         StringPtr curApName = LMGetCurApName();
  76.         long len = Munger( (Handle)abouthandle, 1, "MathLink\252", 9, curApName + 1, *curApName);
  77.         if( len > 0){
  78.             **abouthandle = (unsigned char)len;
  79.             HLock( (Handle)abouthandle);
  80.             SetMenuItemText( GetMenuHandle(mApple), iAbout, *abouthandle);
  81.         }
  82.         DisposeHandle( (Handle)abouthandle);
  83.     }
  84. }
  85.  
  86.  
  87. static pascal Boolean about_filter(DialogPtr dptr, EventRecord *theEvent, short *theItem){
  88.     if( theEvent->what == keyDown || theEvent->what == autoKey){
  89.         unsigned char theKey = (unsigned char)(theEvent->message & charCodeMask);
  90.         if( theKey == 0x0D || (theKey == 0x03 && !(theEvent->modifiers & controlKey))){
  91.             short itemType;
  92.             ControlHandle okHdl;
  93.             Rect itemRect;
  94. #if UNIVERSAL_INTERFACES_VERSION >= 0x0301
  95.             unsigned long Ticks;
  96. #else
  97.             long Ticks;
  98. #endif
  99.             GetDialogItem( dptr, ok, &itemType, (Handle*) &okHdl, &itemRect);
  100.             HiliteControl( okHdl, kControlButtonPart);
  101. #ifdef __cplusplus
  102.             Delay( 3, &Ticks);
  103. #else
  104.             Delay( 3, (void *)&Ticks);
  105. #endif
  106.             HiliteControl( okHdl, 0);
  107.             *theItem = ok;
  108.             return true;
  109.         }
  110.     }
  111.     return false;
  112. }
  113.  
  114. static pascal void outline_hook(DialogRef dptr, short theItem){
  115.     short  itemType;
  116.     Handle itemHdl;
  117.     Rect itemRect;
  118.     PenState oldpen;
  119.     GetDialogItem( dptr, theItem, &itemType, &itemHdl, &itemRect);
  120.     GetPenState( &oldpen);
  121.     PenSize( 3, 3);
  122.     FrameRoundRect( &itemRect, 16, 16);
  123.     SetPenState( &oldpen);
  124. }
  125.  
  126.  
  127.  
  128. /* edit here and in mathlink.r */
  129. static unsigned short missing_DITL[] = { 5,
  130.     0, 0, 76, 120, 96, 200, 0x5C, 0x30, 0x30, 0x34, 0x5C, 0x30, 0x30, 0x32, 0x4F, 0x4B, /* '\004\002', 'OK', */
  131.     0, 0, 12, 13, 30, 28, 0x5C, 0x32, 0x31, 0x30, 0x5C, 0x30, 0x30, 0x31, 0x41, 0x5C, 0x30, /*'\210\001', 'A\0', */
  132.     0, 0, 12, 27, 30, 96, 0x5C, 0x32, 0x31, 0x30, 0x5C, 0x30, 0x31, 0x30, 0x20, 0x4D, 0x61, 0x74, 0x68, 0x4C, 0x69, 0x6E, 0x6B, /*'\210\010', 'Ma','th','Li','nk', */
  133.     0, 0, 12, 95, 30, 308, 0x5C, 0x32, 0x31, 0x30, 0x5C, 0x30, 0x33, 0x34, 0x5C, 0x32, 0x35, 0x32, 0x20, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x20, 0x67, 0x65, 0x6E, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x6D, 0x70, 0x72, 0x65, 0x70, /*'\210\034', '\252','pr','og','ra','m ','ge','ne','ra','te','d ','by',' m','pr','ep', */
  134.     0, 0, 42, 49, 56, 271, 0x5C, 0x32, 0x31, 0x30, 0x5C, 0x30, 0x35, 0x30, 0x6D, 0x70, 0x72, 0x65, 0x70, 0x5C, 0x32, 0x35, 0x31, 0x20, 0x57, 0x6F, 0x6C, 0x66, 0x72, 0x61, 0x6D, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2C, 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x20, 0x31, 0x39, 0x39, 0x30, 0x2D, 0x32, 0x30, 0x30, 0x32, /*'\210\050', 'mp','re','p ','\251 ','Wo','lf','ra','m','Re','se','ar','ch',', ','In','c.',' 1','99','0-','20','02', */ /* 1990-2002 */
  135.     0, 0, 170, 10, 190, 30, 0x5C, 0x32, 0x30, 0x30, 0x5C, 0x30, 0x30, 0x30 /*'\200\000' */
  136. };
  137.  
  138.  
  139. int init_macintosh( void)
  140. {
  141.     static int initdone = 0;
  142.     Handle menuBar;
  143.     long attributes;
  144.  
  145.     /* semaphore required for preemptive threads */
  146.     if( initdone) return initdone == 1;
  147.     initdone = -1;
  148.  
  149.     /* should I check for MLNK resource too as launch-filtering is done based on it? */
  150.     /* too late--since I'm running there likely wasn't a problem (this time anyway). */
  151.    
  152.     menuBar = GetNewMBar(rMenuBar);
  153.     if( menuBar){
  154.         SetMenuBar(menuBar);
  155.         DisposeHandle(menuBar);
  156.     }else{
  157.         MenuHandle am, fm, em;
  158.         am = NewMenu( mApple, (unsigned char*)"\001\024");
  159.         fm = NewMenu( mFile, (unsigned char*)"\004File");
  160.         em = NewMenu( mEdit, (unsigned char*)"\004Edit");
  161.         if( !am || !fm || !em) return 0;
  162.         AppendMenu( am, (unsigned char*)"\022About MathLink\252\311;-");
  163.                 DisableMenuItem(am, 0);
  164.         InsertMenu( am, 0);
  165.         AppendMenu( fm, (unsigned char*)"\006Quit/Q");
  166.         InsertMenu( fm, 0);
  167.         AppendMenu( em, (unsigned char*)"\043Undo/Z;-;Cut/X;Copy/C;Paste/V;Clear");
  168.                 DisableMenuItem(em, 0);
  169.         InsertMenu( em, 0);
  170.     }
  171.  
  172.     AppendResMenu( GetMenuHandle(mApple), 'DRVR');
  173.     set_about_item();
  174.     DrawMenuBar();
  175.     about_filter_upp =  NewModalFilterUPP( about_filter);
  176.     outline_hook_upp = NewUserItemUPP( outline_hook);
  177.     if( Gestalt( gestaltAppleEventsAttr, &attributes) == noErr
  178.     && ((1 << gestaltAppleEventsPresent) & attributes)){
  179.         handle_core_ae_upp = NewAEEventHandlerUPP( handle_core_ae);
  180.         (void) AEInstallEventHandler( kCoreEventClass, typeWildCard, handle_core_ae_upp, 0, false);
  181.     }else{
  182.         return 0; /* this may be too strong since I am, after all, running. */
  183.     }
  184.  
  185.     initdone = 1;
  186.     return initdone == 1;
  187. }
  188.  
  189. void do_about_box( void)
  190. {
  191.     GrafPtr oldPort;
  192.     DialogPtr dptr;
  193.     short item, itemType;
  194.     Handle itemHdl;
  195.     Rect itemRect;
  196.  
  197.     dptr = GetNewDialog( rAboutBox, nil, (WindowPtr)-1L);
  198.    
  199.     if( dptr == (DialogPtr)0){
  200.         Handle items = NewHandle( sizeof(missing_DITL));
  201.         static Rect bounds = {40, 20, 150, 340};
  202.  
  203.         if( ! items) return;
  204.         BlockMove( missing_DITL, *items, sizeof(missing_DITL));
  205.  
  206.         dptr = NewColorDialog( nil, &bounds, (unsigned char*)"\005About",
  207.                     false, dBoxProc, (WindowPtr)-1L, false, 0, items);
  208.                 }
  209.    
  210.     if( dptr == (DialogPtr)0) return;
  211.     GetPort (&oldPort);
  212.     SetPort (GetDialogPort(dptr));
  213.     GetDialogItem( dptr, ok, &itemType, &itemHdl, &itemRect);
  214.     InsetRect( &itemRect, -4, -4);
  215.     SetDialogItem( dptr, 6, userItem + itemDisable, (Handle)outline_hook_upp, &itemRect);
  216.  
  217.     FlushEvents( everyEvent, 0);
  218.         ShowWindow( GetDialogWindow(dptr));
  219.  
  220.     do {
  221.         ModalDialog( about_filter_upp, &item);
  222.     } while( item != ok);
  223.  
  224.     DisposeDialog( dptr);
  225.     SetPort( oldPort);
  226. }
  227.  
  228. int _handle_user_event( unsigned long ticks)
  229. {
  230.     EventRecord event;
  231.  
  232.     if( WaitNextEvent(everyEvent, &event, ticks, nil)){
  233.         long      menuResult = 0;
  234.         short     menuID, menuItem;
  235.         WindowPtr window;
  236.         Str255    daName;
  237.  
  238.         switch ( event.what ) {
  239.         case mouseDown:
  240.             if( FindWindow(event.where, &window) == inMenuBar)
  241.                 menuResult = MenuSelect(event.where);
  242.             break;
  243.         case keyDown:
  244.             if( event.modifiers & cmdKey )
  245.                 menuResult = MenuKey((short)event.message & charCodeMask);
  246.             break;
  247.         case kHighLevelEvent:
  248.             AEProcessAppleEvent(&event);
  249.             break;
  250.         }
  251.  
  252.         menuID = HiWord(menuResult);
  253.         menuItem = LoWord(menuResult);
  254.         switch ( menuID ) {
  255.         case mFile:
  256.             MLDone = MLAbort = 1;
  257.             break;
  258.         case mApple:
  259.             switch ( menuItem ) {
  260.             case iAbout:
  261.                 do_about_box();
  262.                 break;
  263.             default:
  264.                 GetMenuItemText(GetMenuHandle(mApple), menuItem, daName);
  265.                 break;
  266.             }
  267.             HiliteMenu(0);
  268.         }
  269.     }
  270.     return MLDone;
  271. }
  272.  
  273. #if MLINTERFACE >= 3
  274. MLYDEFN( int, MLDefaultYielder, ( MLINK mlp, MLYieldParameters yp))
  275. #else
  276. MLYDEFN( devyield_result, MLDefaultYielder, ( MLINK mlp, MLYieldParameters yp))
  277. #endif /* MLINTERFACE >= 3 */
  278. {
  279.     mlp = mlp; /* suppress unused warning */
  280. #if MLINTERFACE >= 3
  281.     return (int)_handle_user_event( MLSleepYP(yp));
  282. #else
  283.     return _handle_user_event( MLSleepYP(yp));
  284. #endif /* MLINTERFACE >= 3 */
  285. }
  286.  
  287. #endif /* (DARWIN_MATHLINK && CARBON_MPREP */
  288.  
  289. /********************************* end header *********************************/
  290.  
  291.  
  292. static struct func {
  293.     int   f_nargs;
  294.     int   manual;
  295.     int   (*f_func)P((MLINK));
  296.     const char  *f_name;
  297.     } *_tramps;
  298.  
  299. #define CARDOF_EVALSTRS 0
  300.  
  301. static int _definepattern P(( MLINK, char*, char*, int));
  302.  
  303. int  _MLDoCallPacket P(( MLINK, struct func[], int));
  304.  
  305.  
  306. #if MLPROTOTYPES
  307. int MLInstall( MLINK mlp)
  308. #else
  309. int MLInstall(mlp) MLINK mlp;
  310. #endif
  311. {
  312.     int _res;
  313.     _res = MLConnect(mlp);
  314.     if (_res) _res = MLPutSymbol( mlp, "End");
  315.     if (_res) _res = MLFlush( mlp);
  316.     return _res;
  317. } /* MLInstall */
  318.  
  319.  
  320. #if MLPROTOTYPES
  321. int MLDoCallPacket( MLINK mlp)
  322. #else
  323. int MLDoCallPacket( mlp) MLINK mlp;
  324. #endif
  325. {
  326.     return _MLDoCallPacket( mlp, _tramps, 0);
  327. } /* MLDoCallPacket */
  328.  
  329. /******************************* begin trailer ********************************/
  330.  
  331. #ifndef EVALSTRS_AS_BYTESTRINGS
  332. #   define EVALSTRS_AS_BYTESTRINGS 1
  333. #endif
  334.  
  335. #if CARDOF_EVALSTRS
  336. static int  _doevalstr( MLINK mlp, int n)
  337. {
  338.     long bytesleft, charsleft, bytesnow;
  339. #if !EVALSTRS_AS_BYTESTRINGS
  340.     long charsnow;
  341. #endif
  342.     char **s, **p;
  343.     char *t;
  344.  
  345.     s = (char **)evalstrs;
  346.     while( n-- > 0){
  347.         if( *s == 0) break;
  348.         while( *s++ != 0){}
  349.     }
  350.     if( *s == 0) return 0;
  351.     bytesleft = 0;
  352.     charsleft = 0;
  353.     p = s;
  354.     while( *p){
  355.         t = *p; while( *t) ++t;
  356.         bytesnow = t - *p;
  357.         bytesleft += bytesnow;
  358.         charsleft += bytesnow;
  359. #if !EVALSTRS_AS_BYTESTRINGS
  360.         t = *p;
  361.         charsleft -= MLCharacterOffset( &t, t + bytesnow, bytesnow);
  362.         /* assert( t == *p + bytesnow); */
  363. #endif
  364.         ++p;
  365.     }
  366.  
  367.  
  368.     MLPutNext( mlp, MLTKSTR);
  369. #if EVALSTRS_AS_BYTESTRINGS
  370.     p = s;
  371.     while( *p){
  372.         t = *p; while( *t) ++t;
  373.         bytesnow = t - *p;
  374.         bytesleft -= bytesnow;
  375.         MLPut8BitCharacters( mlp, bytesleft, (unsigned char*)*p, bytesnow);
  376.         ++p;
  377.     }
  378. #else
  379.     MLPut7BitCount( mlp, charsleft, bytesleft);
  380.     p = s;
  381.     while( *p){
  382.         t = *p; while( *t) ++t;
  383.         bytesnow = t - *p;
  384.         bytesleft -= bytesnow;
  385.         t = *p;
  386.         charsnow = bytesnow - MLCharacterOffset( &t, t + bytesnow, bytesnow);
  387.         /* assert( t == *p + bytesnow); */
  388.         charsleft -= charsnow;
  389.         MLPut7BitCharacters(  mlp, charsleft, *p, bytesnow, charsnow);
  390.         ++p;
  391.     }
  392. #endif
  393.     return MLError( mlp) == MLEOK;
  394. }
  395. #endif /* CARDOF_EVALSTRS */
  396.  
  397.  
  398. static int  _definepattern( MLINK mlp, char* patt, char* args, int func_n)
  399. {
  400.     MLPutFunction( mlp, "DefineExternal", (long)3);
  401.       MLPutString( mlp, patt);
  402.       MLPutString( mlp, args);
  403.       MLPutInteger( mlp, func_n);
  404.     return !MLError(mlp);
  405. } /* _definepattern */
  406.  
  407.  
  408. int _MLDoCallPacket( MLINK mlp, struct func functable[], int nfuncs)
  409. {
  410.     long len;
  411.     int n, res = 0;
  412.     struct func* funcp;
  413.  
  414.     if( ! MLGetInteger( mlp, &n) ||  n < 0 ||  n >= nfuncs) goto L0;
  415.     funcp = &functable[n];
  416.  
  417.     if( funcp->f_nargs >= 0
  418.     && ( ! MLCheckFunction(mlp, "List", &len)
  419.          || ( !funcp->manual && (len != funcp->f_nargs))
  420.          || (  funcp->manual && (len <  funcp->f_nargs))
  421.        )
  422.     ) goto L0;
  423.  
  424.     stdlink = mlp;
  425.     res = (*funcp->f_func)( mlp);
  426.  
  427. L0: if( res == 0)
  428.         res = MLClearError( mlp) && MLPutSymbol( mlp, "$Failed");
  429.     return res && MLEndPacket( mlp) && MLNewPacket( mlp);
  430. } /* _MLDoCallPacket */
  431.  
  432.  
  433. mlapi_packet MLAnswer( MLINK mlp)
  434. {
  435.     mlapi_packet pkt = 0;
  436.  
  437.     while( !MLDone && !MLError(mlp) && (pkt = MLNextPacket(mlp), pkt) && pkt == CALLPKT){
  438.         MLAbort = 0;
  439.         if( !MLDoCallPacket(mlp)) pkt = 0;
  440.     }
  441.     MLAbort = 0;
  442.     return pkt;
  443. } /* MLAnswer */
  444.  
  445.  
  446.  
  447. /*
  448.     Module[ { me = $ParentLink},
  449.         $ParentLink = contents of RESUMEPKT;
  450.         Message[ MessageName[$ParentLink, "notfe"], me];
  451.         me]
  452. */
  453.  
  454. static int refuse_to_be_a_frontend( MLINK mlp)
  455. {
  456.     int pkt;
  457.  
  458.     MLPutFunction( mlp, "EvaluatePacket", 1);
  459.       MLPutFunction( mlp, "Module", 2);
  460.         MLPutFunction( mlp, "List", 1);
  461.           MLPutFunction( mlp, "Set", 2);
  462.             MLPutSymbol( mlp, "me");
  463.             MLPutSymbol( mlp, "$ParentLink");
  464.       MLPutFunction( mlp, "CompoundExpression", 3);
  465.         MLPutFunction( mlp, "Set", 2);
  466.           MLPutSymbol( mlp, "$ParentLink");
  467.           MLTransferExpression( mlp, mlp);
  468.         MLPutFunction( mlp, "Message", 2);
  469.           MLPutFunction( mlp, "MessageName", 2);
  470.             MLPutSymbol( mlp, "$ParentLink");
  471.             MLPutString( mlp, "notfe");
  472.           MLPutSymbol( mlp, "me");
  473.         MLPutSymbol( mlp, "me");
  474.     MLEndPacket( mlp);
  475.  
  476.     while( (pkt = MLNextPacket( mlp), pkt) && pkt != SUSPENDPKT)
  477.         MLNewPacket( mlp);
  478.     MLNewPacket( mlp);
  479.     return MLError( mlp) == MLEOK;
  480. }
  481.  
  482.  
  483. int MLEvaluate( MLINK mlp, char* s)
  484. {
  485.     if( MLAbort) return 0;
  486.     return MLPutFunction( mlp, "EvaluatePacket", 1L)
  487.         && MLPutFunction( mlp, "ToExpression", 1L)
  488.         && MLPutString( mlp, s)
  489.         && MLEndPacket( mlp);
  490. } /* MLEvaluate */
  491.  
  492.  
  493. int MLEvaluateString( MLINK mlp, char* s)
  494. {
  495.     int pkt;
  496.     if( MLAbort) return 0;
  497.     if( MLEvaluate( mlp, s)){
  498.         while( (pkt = MLAnswer( mlp), pkt) && pkt != RETURNPKT)
  499.             MLNewPacket( mlp);
  500.         MLNewPacket( mlp);
  501.     }
  502.     return MLError( mlp) == MLEOK;
  503. } /* MLEvaluateString */
  504.  
  505.  
  506. #if MLINTERFACE >= 3
  507. MLMDEFN( void, MLDefaultHandler, ( MLINK mlp, int message, int n))
  508. #else
  509. MLMDEFN( void, MLDefaultHandler, ( MLINK mlp, unsigned long message, unsigned long n))
  510. #endif /* MLINTERFACE >= 3 */
  511. {
  512.     mlp = (MLINK)0; /* suppress unused warning */
  513.     n = 0; /* suppress unused warning */
  514.  
  515.     switch (message){
  516.     case MLTerminateMessage:
  517.         MLDone = 1;
  518.     case MLInterruptMessage:
  519.     case MLAbortMessage:
  520.         MLAbort = 1;
  521.     default:
  522.         return;
  523.     }
  524. }
  525.  
  526. #if MLINTERFACE >= 3
  527. static int _MLMain( char **argv, char **argv_end, char *commandline)
  528. #else
  529. static int _MLMain( charpp_ct argv, charpp_ct argv_end, charp_ct commandline)
  530. #endif /* MLINTERFACE >= 3 */
  531. {
  532.     MLINK mlp;
  533. #if MLINTERFACE >= 3
  534.     int err;
  535. #else
  536.     long err;
  537. #endif /* MLINTERFACE >= 3 */
  538.  
  539. #if (DARWIN_MATHLINK && CARBON_MPREP)
  540.     if( !init_macintosh()) goto R0;
  541. #endif /* (DARWIN_MATHLINK && CARBON_MPREP) */
  542.  
  543.     if( !stdenv)
  544.         stdenv = MLInitialize( (MLParametersPointer)0);
  545.     if( stdenv == (MLEnvironment)0) goto R0;
  546.  
  547. #if (DARWIN_MATHLINK && CARBON_MPREP)
  548. #if MLINTERFACE >= 3
  549.     if( !stdyielder)
  550.         stdyielder = (MLYieldFunctionObject)MLDefaultYielder;
  551. #else
  552.     if( !stdyielder)
  553.         stdyielder = MLCreateYieldFunction( stdenv, NewMLYielderProc( MLDefaultYielder), 0);
  554. #endif /* MLINTERFACE >= 3 */
  555. #endif /* (DARWIN_MATHLINK && CARBON_MPREP)*/
  556.  
  557. #if MLINTERFACE >= 3
  558.     if( !stdhandler)
  559.         stdhandler = (MLMessageHandlerObject)MLDefaultHandler;
  560. #else
  561.     if( !stdhandler)
  562.         stdhandler = MLCreateMessageHandler( stdenv, NewMLHandlerProc( MLDefaultHandler), 0);
  563. #endif /* MLINTERFACE >= 3 */
  564.  
  565. #if (DARWIN_MATHLINK && CARBON_MPREP)
  566.         MLSetDialogFunction(stdenv, MLRequestToInteractFunction, NewMLRequestToInteractProc(MLDontPermit_darwin));
  567.  
  568.     mlp = commandline
  569.         ? MLOpenString( stdenv, commandline, &err)
  570. #if MLINTERFACE >= 3
  571.             : MLOpenArgcArgv( stdenv, (int)(argv_end - argv), argv, &err);
  572. #else
  573.             : MLOpenArgv( stdenv, argv, argv_end, &err);
  574. #endif
  575.  
  576.         MLSetDialogFunction(stdenv, MLRequestToInteractFunction, NewMLRequestToInteractProc(MLPermit_darwin));
  577.  
  578.     if( mlp == (MLINK)0){
  579.                         mlp = commandline
  580.                                 ? MLOpenString( stdenv, commandline, &err)
  581. #if MLINTERFACE < 3
  582.                                 : MLOpenArgv( stdenv, argv, argv_end, &err);
  583. #else
  584.                                 : MLOpenArgcArgv( stdenv, (int)(argv_end - argv), argv, &err);
  585. #endif
  586.         }
  587. #else /* !(DARWIN_MATHLINK && CARBON_MPREP)*/
  588.     mlp = commandline
  589.         ? MLOpenString( stdenv, commandline, &err)
  590. #if MLINTERFACE < 3
  591.         : MLOpenArgv( stdenv, argv, argv_end, &err);
  592. #else
  593.         : MLOpenArgcArgv( stdenv, (int)(argv_end - argv), argv, &err);
  594. #endif
  595. #endif /* (DARWIN_MATHLINK && CARBON_MPREP)*/
  596.  
  597.     if( mlp == (MLINK)0){
  598.         MLAlert( stdenv, MLErrorString( stdenv, err));
  599.         goto R1;
  600.     }
  601.  
  602.     if( stdyielder) MLSetYieldFunction( mlp, stdyielder);
  603.     if( stdhandler) MLSetMessageHandler( mlp, stdhandler);
  604.  
  605.     if( MLInstall( mlp))
  606.         while( MLAnswer( mlp) == RESUMEPKT){
  607.             if( ! refuse_to_be_a_frontend( mlp)) break;
  608.         }
  609.  
  610.     MLClose( mlp);
  611. R1: MLDeinitialize( stdenv);
  612.     stdenv = (MLEnvironment)0;
  613. R0: return !MLDone;
  614. } /* _MLMain */
  615.  
  616.  
  617. #if MLINTERFACE >= 3
  618. int MLMainString( char *commandline)
  619. #else
  620. int MLMainString( charp_ct commandline)
  621. #endif /* MLINTERFACE >= 3 */
  622. {
  623. #if MLINTERFACE >= 3
  624.     return _MLMain( (char **)0, (char **)0, commandline);
  625. #else
  626.     return _MLMain( (charpp_ct)0, (charpp_ct)0, commandline);
  627. #endif /* MLINTERFACE >= 3 */
  628. }
  629.  
  630. int MLMainArgv( char** argv, char** argv_end) /* note not FAR pointers */
  631. {  
  632.     static char FAR * far_argv[128];
  633.     int count = 0;
  634.    
  635.     while(argv < argv_end)
  636.         far_argv[count++] = *argv++;
  637.          
  638.     return _MLMain( far_argv, far_argv + count, (charp_ct)0);
  639.  
  640. }
  641.  
  642. #if MLINTERFACE >= 3
  643. int MLMain( int argc, char ** argv)
  644. #else
  645. int MLMain( int argc, charpp_ct argv)
  646. #endif /* MLINTERFACE >= 3 */
  647. {
  648. #if MLINTERFACE >= 3
  649.     return _MLMain( argv, argv + argc, (char *)0);
  650. #else
  651.     return _MLMain( argv, argv + argc, (charp_ct)0);
  652. #endif /* MLINTERFACE >= 3 */
  653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement