version 1.1.1.1, 1999/10/29 08:06:41 |
version 1.4, 1999/11/07 12:12:56 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_math/testclient.c,v 1.3 1999/11/06 21:39:37 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); |
|
fprintf(stderr, "I send SM_popCMO.\n"); |
|
|
|
dumpx(sv->stream, 17); |
ox_mathcap(sv); |
} |
send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING)); |
|
|
void asir_main2() |
|
{ |
|
cmo* m = NULL; |
|
|
|
/* add 関数の定義 */ |
ox_reset(sv); |
/* char* adddef = "def add(X,Y){return X+Y;};"; */ |
send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]")); |
|
send_ox_command(sv->stream, SM_executeStringByLocalParser); |
/* この辺は 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); |
send_ox_command(sv->stream, SM_popCMO); |
|
receive_ox_tag(sv->stream); |
#if 0 |
c = receive_cmo(sv->stream); |
fprintf(stderr, "dump:\n"); |
fprintf(stderr, "testclient:: cmo received.\n"); |
dumpx(sv->stream, 36); |
print_cmo(c); |
return; |
|
#endif |
|
|
|
receive_ox_tag(sv->stream); /* OX_DATA */ |
|
m = receive_cmo(sv->stream); |
|
fprintf(stderr, "tag is (%d).\n", m->tag); |
|
} |
} |
|
|
void asir_main3() |
|
{ |
|
int i1, i2; |
|
cmo_zz* z1; |
|
cmo_zz* z2; |
|
|
|
i1 = 2*7; |
|
i2 = 2*11; |
|
|
|
z1 = new_cmo_zz_set_si(i1); |
|
z2 = new_cmo_zz_set_si(i2); |
|
fprintf(stderr, "i1 = %d, i2 = %d.\n", i1, i2); |
|
|
|
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(argc, "ox_math")==0) { |
send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]")); |
test_0(); |
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, m); |
if (m->tag == OX_COMMAND) { |
if (m->tag == OX_COMMAND) { |
Line 208 int main(int argc, char* argv[]) |
|
Line 86 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; |
} |
} |