| version 1.2, 1999/11/02 06:11:58 |
version 1.6, 1999/12/15 02:49:55 |
|
|
| /* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
| /* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_math/testclient.c,v 1.5 1999/12/14 09:31:56 ohara Exp $ */ |
| /* $Id$ */ |
|
| |
|
| /* |
|
| ソケットで通信する場合のサーバの立ち上げ方。 |
|
| dc3$ cd ~/openasir/bin |
|
| dc3$ ./ox -ox ox_sm1 -host dc3 |
|
| */ |
|
| |
|
| #include <stdio.h> |
#include <stdio.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <unistd.h> |
#include <unistd.h> |
| Line 35 int dumpx(int fd, int n) |
|
| Line 28 int dumpx(int fd, int n) |
|
| return len; |
return len; |
| } |
} |
| |
|
| int mathematica_main() |
/* 平成11年11月7日 */ |
| { |
#define VERSION 0x11110700 |
| int fd = sv->stream; |
#define ID_STRING "testclient version 0.11110700" |
| char* s = "Plus[31415926535, -1234567]"; |
|
| char* s2 = "Plus[1, 2]"; |
|
| char* s_result; |
|
| cmo* m = NULL; |
|
| |
|
| fprintf(stderr, "%s\n", s2); |
int prompt() |
| ox_executeStringByLocalParser(sv, s2); |
|
| |
|
| m = ox_pop_cmo(sv, sv->stream); |
|
| fprintf(stderr, "the tag of result is %d.\n", m->tag); |
|
| |
|
| fprintf(stderr, "executeFunction(\"Plus\", 2, zz(5), zz(3))\n"); |
|
| send_ox_cmo(sv->stream, new_cmo_zz_set_si(3)); |
|
| send_ox_cmo(sv->stream, new_cmo_zz_set_si(5)); |
|
| send_ox_cmo(sv->stream, new_cmo_int32(2)); /* number of arguments */ |
|
| send_ox_cmo(sv->stream, new_cmo_string("Plus")); |
|
| send_ox_command(sv->stream, SM_executeFunction); |
|
| |
|
| s_result = ox_popString(sv, sv->stream); |
|
| fprintf(stderr, "result = %s.\n", s_result); |
|
| |
|
| return; |
|
| } |
|
| |
|
| void asir_main() |
|
| { |
{ |
| cmo* m = NULL; |
printf("> "); |
| int fd = sv->stream; |
|
| |
|
| send_ox_cmo(sv->stream, new_cmo_int32(12345)); |
|
| ox_executeStringByLocalParser(sv, "print(\"Hello world!!\");"); |
|
| fprintf(stderr, "result = %s.\n", ox_popString(sv, sv->stream)); |
|
| return; |
|
| |
|
| send_ox_command(fd, SM_popString); |
|
| receive_ox_tag(fd); /* OX_DATA */ |
|
| m = receive_cmo(fd); |
|
| |
|
| m = ox_pop_cmo(sv, sv->stream); |
|
| fprintf(stderr, "tag = %d.\n", m->tag); |
|
| } |
} |
| |
|
| void asir_main0() |
|
| { |
|
| |
|
| char* sf1 = "diff((x+2*y)^2,x);"; |
int test_0() |
| |
|
| /* この辺は ox_asir に実行させる場合に使う。 */ |
|
| ox_executeStringByLocalParser(sv, "print(\"Hello world!!\");"); |
|
| |
|
| ox_executeStringByLocalParser(sv, "diff((x+2*y)^2,x);"); |
|
| fprintf(stderr, |
|
| "I let Asir evaluate \"%s\"\n and get a result \"%s\"\n", sf1, ox_popString(sv, sv->stream)); |
|
| } |
|
| |
|
| void asir_main1() |
|
| { |
{ |
| send_ox_cmo(sv->stream, new_cmo_zz_set_si(10)); |
cmo* c = NULL; |
| send_ox_command(sv->stream, SM_popCMO); |
#ifdef DEBUG |
| fprintf(stderr, "I send SM_popCMO.\n"); |
fprintf(stderr, "testclient:: calling ox_mathcap().\n"); |
| |
c = ox_mathcap(sv); |
| dumpx(sv->stream, 17); |
fprintf(stderr, "testclient:: cmo received.(%p)\n", c); |
| } |
#else |
| |
c = ox_mathcap(sv); |
| void asir_main2() |
|
| { |
|
| cmo* m = NULL; |
|
| |
|
| /* add 関数の定義 */ |
|
| /* char* adddef = "def add(X,Y){return X+Y;};"; */ |
|
| |
|
| /* この辺は ox_asir に実行させる場合に使う。 */ |
|
| /* ox_executeStringByLocalParser(sv, adddef); */ |
|
| send_ox_cmo(sv->stream, new_cmo_int32(3)); |
|
| send_ox_cmo(sv->stream, new_cmo_int32(5)); |
|
| send_ox_cmo(sv->stream, new_cmo_int32(2)); /* number of arguments */ |
|
| send_ox_cmo(sv->stream, new_cmo_string("igcd")); |
|
| send_ox_command(sv->stream, SM_executeFunction); |
|
| /* この段階でCMO_ERROR2 が積まれるはず */ |
|
| |
|
| send_ox_command(sv->stream, SM_popCMO); |
|
| |
|
| #if 0 |
|
| fprintf(stderr, "dump:\n"); |
|
| dumpx(sv->stream, 36); |
|
| return; |
|
| #endif |
#endif |
| |
print_cmo(c); |
| |
fflush(stderr); |
| |
send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING)); |
| |
|
| receive_ox_tag(sv->stream); /* OX_DATA */ |
ox_reset(sv); |
| m = receive_cmo(sv->stream); |
send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]")); |
| fprintf(stderr, "tag is (%d).\n", m->tag); |
send_ox_command(sv->stream, SM_executeStringByLocalParser); |
| |
send_ox_command(sv->stream, SM_popCMO); |
| |
receive_ox_tag(sv->stream); |
| |
c = receive_cmo(sv->stream); |
| |
fprintf(stderr, "testclient:: cmo received.\n"); |
| |
print_cmo(c); |
| } |
} |
| |
|
| void asir_main3() |
int test_1() |
| { |
{ |
| int i1, i2; |
cmo *c = NULL; |
| cmo_zz* z1; |
cmo *m = make_mathcap_object(1000, "test!"); |
| cmo_zz* z2; |
fprintf(stderr, "testclient:: test cmo_mathcap.\n"); |
| |
send_ox_cmo(sv->stream, m); |
| i1 = 2*7; |
send_ox_command(sv->stream, SM_popCMO); |
| i2 = 2*11; |
receive_ox_tag(sv->stream); |
| |
c = receive_cmo(sv->stream); |
| z1 = new_cmo_zz_set_si(i1); |
fprintf(stderr, "testclient:: cmo received.(%p)\n", c); |
| z2 = new_cmo_zz_set_si(i2); |
print_cmo(c); |
| fprintf(stderr, "i1 = %d, i2 = %d.\n", i1, i2); |
fputc('\n', stderr); |
| |
|
| send_ox_cmo(sv->stream, z1); |
|
| send_ox_cmo(sv->stream, z2); |
|
| send_ox_cmo(sv->stream, new_cmo_int32(2)); /* number of arguments */ |
|
| send_ox_cmo(sv->stream, new_cmo_string("igcd")); |
|
| send_ox_command(sv->stream, SM_executeFunction); |
|
| |
|
| fprintf(stderr, "result1 = (%s).\n", ox_popString(sv, sv->stream)); |
|
| } |
} |
| |
|
| void sm_main() |
|
| { |
|
| ox_mathcap(sv); |
|
| } |
|
| |
|
| /* 平成11年7月10日 */ |
|
| #define VERSION 0x11071000 |
|
| #define ID_STRING "client version 0.11071000" |
|
| |
|
| int prompt() |
|
| { |
|
| printf(":- "); |
|
| } |
|
| |
|
| |
|
| int main(int argc, char* argv[]) |
int main(int argc, char* argv[]) |
| { |
{ |
| ox* m = NULL; |
ox* m = NULL; |
| cmo* c = NULL; |
cmo* c = NULL; |
| int code; |
int code; |
| |
char *server = "ox_sm1"; |
| |
|
| setbuf(stderr, NULL); |
setbuf(stderr, NULL); |
| |
|
| if (argc>1) { |
if (argc>1) { |
| fprintf(stderr, "I use ox_math.\n"); |
server = argv[1]; |
| sv = ox_start("localhost", "ox", "ox_math"); |
|
| ox_mathcap(sv); |
|
| send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING)); |
|
| }else { |
|
| fprintf(stderr, "I use ox_sm1.\n"); |
|
| sv = ox_start("localhost", "ox", "ox_sm1"); |
|
| } |
} |
| |
fprintf(stderr, "testclient:: I use %s as an OX server.\n", server); |
| |
sv = ox_start("localhost", "ox", server); |
| |
if (sv == NULL) { |
| |
fprintf(stderr, "testclient:: I cannot connect to servers.\n"); |
| |
exit(1); |
| |
} |
| |
|
| ox_reset(sv); |
if (strcmp(server, "ox_math")==0) { |
| send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]")); |
test_1(); |
| send_ox_command(sv->stream, SM_executeStringByLocalParser); |
} |
| send_ox_command(sv->stream, SM_popCMO); |
|
| fprintf(stderr, "for debug.\n"); |
|
| |
|
| receive_ox_tag(sv->stream); |
|
| fprintf(stderr, "for debug.\n"); |
|
| c = receive_cmo(sv->stream); |
|
| fprintf(stderr, "for debug.\n"); |
|
| fprintf(stderr, "local:: cmo received.\n"); |
|
| print_cmo(c); |
|
| |
|
| while(prompt(), (m = parse()) != NULL) { |
while(prompt(), (m = parse()) != NULL) { |
| send_ox(sv, m); |
send_ox(sv->stream, m); |
| if (m->tag == OX_COMMAND) { |
if (m->tag == OX_COMMAND) { |
| code = ((ox_command *)m)->command; |
code = ((ox_command *)m)->command; |
| if (code >= 1024) { |
if (code >= 1024) { |
| Line 208 int main(int argc, char* argv[]) |
|
| Line 107 int main(int argc, char* argv[]) |
|
| }else if (code == SM_popCMO || code == SM_popString) { |
}else if (code == SM_popCMO || code == SM_popString) { |
| receive_ox_tag(sv->stream); |
receive_ox_tag(sv->stream); |
| c = receive_cmo(sv->stream); |
c = receive_cmo(sv->stream); |
| fprintf(stderr, "local:: cmo received.\n"); |
fprintf(stderr, "testclient:: cmo received.\n"); |
| print_cmo(c); |
print_cmo(c); |
| } |
} |
| } |
} |
| } |
} |
| |
|
| #if 0 |
|
| sm_main(); |
|
| asir_main(); |
|
| mathematica_main(); |
|
| #endif |
|
| |
|
| ox_reset(sv); |
ox_reset(sv); |
| fprintf(stderr, "The client resets.\n"); |
fprintf(stderr, "The testclient resets.\n"); |
| ox_close(sv); |
ox_close(sv); |
| fprintf(stderr, "The client halts.\n"); |
fprintf(stderr, "The testclient halts.\n"); |
| |
|
| return 0; |
return 0; |
| } |
} |