=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/Attic/serv2.c,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -p -r1.1.1.1 -r1.4 --- OpenXM/src/ox_math/Attic/serv2.c 1999/10/29 08:06:41 1.1.1.1 +++ OpenXM/src/ox_math/Attic/serv2.c 1999/11/04 03:05:51 1.4 @@ -1,6 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM$ */ -/* $Id: serv2.c,v 1.1.1.1 1999/10/29 08:06:41 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_math/serv2.c,v 1.3 1999/11/03 10:56:40 ohara Exp $ */ /* Open Mathematica サーバ */ /* ファイルディスクリプタ 3, 4 は open されていると仮定して動作する. */ @@ -18,10 +17,45 @@ #define UNKNOWN_SM_COMMAND 50000 #define MATH_ERROR 50001 - /* MLINK はポインタ型. */ MLINK lp = NULL; + +typedef cmo mlo; +typedef cmo_string mlo_string; +typedef cmo_zz mlo_zz; + +/* cmo_list の派生クラス*/ +typedef struct { + int tag; + int length; + cell *head; + char *function; +} mlo_function; + + +mlo *receive_mlo_zz() +{ + char *s; + mlo *m; + + MLGetString(lp, &s); + fprintf(stderr, "--debug: zz = %s.\n", s); + m = (mlo *)new_cmo_zz_set_string(s); + MLDisownString(lp, s); + return m; +} + +mlo *receive_mlo_string() +{ + char *s; + mlo *m; + MLGetString(lp, &s); + m = (cmo *)new_cmo_string(s); + MLDisownString(lp, s); + return m; +} + /* Mathematica を起動する. */ int MATH_init() { @@ -69,62 +103,75 @@ char *MATH_getObject() return s; } + cmo *MATH_getObject2() { - char *s; - cmo *m; - char **sp; - int i,n; - /* skip any packets before the first ReturnPacket */ while (MLNextPacket(lp) != RETURNPKT) { usleep(10); MLNewPacket(lp); } /* いまはタイプにかかわらず文字列を取得する. */ - switch(MLGetNext(lp)) { + return MATH_getObject3(); +} + +cmo *MATH_getObject3() +{ + char *s; + cmo *m; + cmo *ob; + int i,n; + int type; + + /* いまはタイプにかかわらず文字列を取得する. */ + type = MLGetNext(lp); + switch(type) { case MLTKINT: - fprintf(stderr, "type is INTEGER.\n"); - MLGetString(lp, &s); - m = (cmo *)new_cmo_zz_set_string(s); + fprintf(stderr, "--debug: MLO == MLTKINT.\n"); + m = receive_mlo_zz(); break; case MLTKSTR: - fprintf(stderr, "type is STRING.\n"); + fprintf(stderr, "--debug: MLO == MLTKSTR.\n"); + m = receive_mlo_string(); + break; +#if 0 + case MLTKREAL: + fprintf(stderr, "MLTKREAL is not supported: we use MLTKSTR.\n"); MLGetString(lp, &s); m = (cmo *)new_cmo_string(s); break; case MLTKERR: - fprintf(stderr, "type is ERROR.\n"); - m = gen_error_object(MATH_ERROR); + fprintf(stderr, "--debug: MLO == MLTKERR.\n"); + m = (cmo *)gen_error_object(MATH_ERROR); break; +#endif case MLTKSYM: - fprintf(stderr, "MLTKSYM.\n"); - MLGetString(lp, s); + fprintf(stderr, "--debug: MLO == MLTKSYM.\n"); + /* この部分に問題がある. */ + MLGetSymbol(lp, &s); + fprintf(stderr, "--debug: Symbol \"%s\".\n", s); m = (cmo *)new_cmo_string(s); break; case MLTKFUNC: - fprintf(stderr, "MLTKFUNC.\n"); -#if DEBUG - MLGetString(lp, s); - m = (cmo *)new_cmo_string(s); - break; -#endif - MLGetFunction(lp, sp, &n); - fprintf(stderr, "n = %d\n", n); - for (i=0; i<=n; i++) { - fprintf(stderr, "%s "); + fprintf(stderr, "--debug: MLO == MLTKFUNC.\n"); + MLGetFunction(lp, &s, &n); + fprintf(stderr, "--debug: Function = \"%s\", # of args = %d\n", s, n); + m = new_cmo_list(); + append_cmo_list(m, new_cmo_string(s)); + fflush(stderr); + for (i=0; i 0) { Stack_Pointer--; return Operand_Stack[Stack_Pointer]; } - return NULL; + return new_cmo_null(); } void pops(int n) @@ -217,7 +261,6 @@ void pops(int n) } } - /* sm_XXX 関数群は、エラーのときは 0 以外の値を返し、呼び出し元で エラーオブジェクトをセットする */ int sm_popCMO(int fd_write) @@ -252,8 +295,8 @@ int sm_popString(int fd_write) fprintf(stderr, "code: SM_popString.\n"); #endif - if ((m = pop()) != NULL && (s = CONVERT_CMO_TO_CSTRING(m)) != NULL) { - send_ox_cmo(fd_write, new_cmo_string(s)); + if ((m = pop()) != NULL && (s = convert_cmo_to_string(m)) != NULL) { + send_ox_cmo(fd_write, (cmo *)new_cmo_string(s)); return 0; } return SM_popString; @@ -343,7 +386,7 @@ int execute_sm_command(int fd_write, int code) case SM_executeFunction: err = sm_executeFunction(fd_write); break; - case SM_setMathcap: + case SM_setMathCap: pop(); /* 無視する */ break; default: @@ -352,6 +395,6 @@ int execute_sm_command(int fd_write, int code) } if (err != 0) { - push(gen_error_object(err)); + push((cmo *)gen_error_object(err)); } }