[BACK]Return to mlo.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_math

Diff for /OpenXM/src/ox_math/mlo.c between version 1.1 and 1.9

version 1.1, 1999/11/29 12:09:58 version 1.9, 2000/12/03 21:46:52
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C -*- */
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/ox_math/mlo.c,v 1.8 2000/11/28 20:16:03 ohara Exp $ */
   
 /* Open Mathematica サーバ */  /*
 /* ファイルディスクリプタ 3, 4 は open されていると仮定して動作する. */     Copyright (C) Katsuyoshi OHARA, 2000.
      Portions copyright 1999 Wolfram Research, Inc.
   
 /* MathLink との通信部分 */     You must see OpenXM/Copyright/Copyright.generic.
      The MathLink Library is licensed from Wolfram Research Inc..
      See OpenXM/Copyright/Copyright.mathlink for detail.
   */
   
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
 #include <gmp.h>  
 #include <mathlink.h>  #include <mathlink.h>
 #include "ox.h"  #include <ox_toolkit.h>
 #include "parse.h"  #include "mlo.h"
 #include "serv2.h"  #include "sm.h"
   
   /* If this flag sets then we identify MLTKSYM to CMO_INDETERMINATE. */
 int flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE;  int flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE;
   
 /* MLINK はポインタ型. */  /* MLINK is a indentifier of MathLink connection. */
 MLINK stdlink;  MLINK stdlink;
   
 typedef cmo mlo;  
 typedef cmo_string mlo_string;  
 typedef cmo_zz mlo_zz;  
   
 mlo *receive_mlo_zz()  mlo *receive_mlo_zz()
 {  {
     char *s;      char *s;
Line 57  cmo *receive_mlo_function()
Line 57  cmo *receive_mlo_function()
     MLGetFunction(stdlink, &s, &n);      MLGetFunction(stdlink, &s, &n);
     fprintf(stderr, "--debug: MLO == MLTKFUNC (%s[#%d]).\n", s, n);      fprintf(stderr, "--debug: MLO == MLTKFUNC (%s[#%d]).\n", s, n);
     m = new_cmo_list();      m = new_cmo_list();
     append_cmo_list((cmo_list *)m, new_cmo_string(s));      list_append((cmo_list *)m, new_cmo_string(s));
   
     for (i=0; i<n; i++) {      for (i=0; i<n; i++) {
         fprintf(stderr, "  --debug: arg[%d]\n", i);          fprintf(stderr, "  --debug: arg[%d]\n", i);
         fflush(stderr);          fflush(stderr);
         ob = receive_mlo();          ob = receive_mlo();
         append_cmo_list((cmo_list *)m, ob);          list_append((cmo_list *)m, ob);
     }      }
   
     MLDisownString(stdlink, s);      MLDisownString(stdlink, s);
     return m;      return m;
 }  }
   
   #if 0
   cmo *convert_mlo_to_cmo(mlo *m)
   {
           if (m->tag == MLO_FUNCTION) {
                   if (strcmp(((mlo_function *)m)->function, "List") == 0) {
                           return convert_mlo_function_list_to_cmo_list(m);
                   }
           }
           return m;
   }
   #endif
   
   #define MLO_FUNCTION   (CMO_PRIVATE+1)
   
 mlo_function *new_mlo_function(char *function)  mlo_function *new_mlo_function(char *function)
 {  {
     mlo_function *c = malloc(sizeof(mlo_function));      mlo_function *c = malloc(sizeof(mlo_function));
Line 96  cmo *receive_mlo_function_newer()
Line 110  cmo *receive_mlo_function_newer()
         fprintf(stderr, "--debug: arg[%d]\n", i);          fprintf(stderr, "--debug: arg[%d]\n", i);
         fflush(stderr);          fflush(stderr);
         ob = receive_mlo();          ob = receive_mlo();
         append_cmo_list((cmo_list *)m, ob);          list_append((cmo_list *)m, ob);
     }      }
   
     MLDisownString(stdlink, s);      MLDisownString(stdlink, s);
Line 121  cmo *receive_mlo_symbol()
Line 135  cmo *receive_mlo_symbol()
     return ob;      return ob;
 }  }
   
 /* Mathematica を起動する. */  /* starting a MathLink connection. */
 int ml_init()  int ml_init()
 {  {
     int argc = 2;      int argc = 2;
Line 135  int ml_init()
Line 149  int ml_init()
     return 0;      return 0;
 }  }
   
   /* closing a MathLink connection. */
 int ml_exit()  int ml_exit()
 {  {
     /* quit Mathematica then close the link */      /* quit Mathematica then close the link */
Line 142  int ml_exit()
Line 157  int ml_exit()
     MLClose(stdlink);      MLClose(stdlink);
 }  }
   
 cmo *ml_get_object()  /* Never forget call ml_select() before calling receive_mlo(). */
   int ml_select()
 {  {
     /* skip any packets before the first ReturnPacket */      /* skip any packets before the first ReturnPacket */
     while (MLNextPacket(stdlink) != RETURNPKT) {      while (MLNextPacket(stdlink) != RETURNPKT) {
         usleep(10);          usleep(10);
         MLNewPacket(stdlink);          MLNewPacket(stdlink);
     }      }
     return receive_mlo();  
 }  }
   
   /* Never forget call ml_flush() after calling send_mlo(). */
   int ml_flush()
   {
       MLEndPacket(stdlink);
   }
   
 cmo *receive_mlo()  cmo *receive_mlo()
 {  {
     char *s;      char *s;
Line 163  cmo *receive_mlo()
Line 184  cmo *receive_mlo()
     case MLTKSTR:      case MLTKSTR:
         return receive_mlo_string();          return receive_mlo_string();
     case MLTKREAL:      case MLTKREAL:
         /* double はまだ... */          /* Yet we have no implementation of CMO_DOUBLE... */
         fprintf(stderr, "--debug: MLO == MLTKREAL.\n");          fprintf(stderr, "--debug: MLO == MLTKREAL.\n");
         MLGetString(stdlink, &s);          MLGetString(stdlink, &s);
         return (cmo *)new_cmo_string(s);          return (cmo *)new_cmo_string(s);
Line 197  int send_mlo_zz(cmo *m)
Line 218  int send_mlo_zz(cmo *m)
 {  {
     char *s;      char *s;
     MLPutFunction(stdlink, "ToExpression", 1);      MLPutFunction(stdlink, "ToExpression", 1);
     s = convert_cmo_to_string(m);      s = new_string_set_cmo(m);
     MLPutString(stdlink, s);      MLPutString(stdlink, s);
 }  }
   
 int send_mlo_list(cmo *c)  int send_mlo_list(cmo *c)
 {  {
     char *s;      char *s;
     cell *cp = ((cmo_list *)c)->head;      cell *cp = list_first((cmo_list *)c);
     int len = length_cmo_list((cmo_list *)c);      int len = list_length((cmo_list *)c);
   
     MLPutFunction(stdlink, "List", len);      MLPutFunction(stdlink, "List", len);
     while(cp->next != NULL) {      while(!list_endof(c, cp)) {
         send_mlo(cp->cmo);          send_mlo(cp->cmo);
         cp = cp->next;          cp = list_next(cp);
     }      }
 }  }
   
 int ml_sendObject(cmo *m)  
 {  
     send_mlo(m);  
     MLEndPacket(stdlink);  
 }  
   
 int send_mlo(cmo *m)  int send_mlo(cmo *m)
 {  {
     char *s;      char *s;
Line 245  int send_mlo(cmo *m)
Line 260  int send_mlo(cmo *m)
         break;          break;
     default:      default:
         MLPutFunction(stdlink, "ToExpression", 1);          MLPutFunction(stdlink, "ToExpression", 1);
         s = convert_cmo_to_string(m);          s = new_string_set_cmo(m);
         MLPutString(stdlink, s);          MLPutString(stdlink, s);
         break;          break;
     }      }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>