Annotation of OpenXM/doc/oxlib/test2.c, Revision 1.5
1.5 ! ohara 1: /* $OpenXM: OpenXM/doc/oxlib/test2.c,v 1.4 2003/03/08 07:49:59 takayama Exp $ */
! 2: #include <stdio.h>
! 3: #include <ox/cmotag.h>
1.4 takayama 4: #include <ox/smCommand.h>
5:
1.1 takayama 6:
1.3 noro 7: char *test2_ox_pop_string();
1.1 takayama 8:
9: main() {
10: char *s;
1.2 noro 11: asir_ox_init(1); /* Use the network byte order */
1.1 takayama 12:
13: /* Loading the file xm */
14: /* This part generates a core dump. I'm trying to find a reason. */
15: asir_ox_push_string("xm");
16: asir_ox_push_int32(1);
17: asir_ox_push_string("load");
18: asir_ox_push_cmd(SM_executeFunction);
19:
20:
21: asir_ox_push_string("fctr(x^10-1);");
22: asir_ox_push_cmd(SM_executeStringByLocalParser);
23:
24: /*
25: asir_ox_push_string("x^10-1;");
26: asir_ox_push_cmd(SM_executeStringByLocalParser);
27: asir_ox_push_int32(1);
28: asir_ox_push_string("fctr");
29: asir_ox_push_cmd(SM_executeFunction);
30: */
31:
1.3 noro 32: s = test2_ox_pop_string();
1.1 takayama 33: printf("%s\n",s);
34:
35: printf("------------------------------------------\n");
36: asir_ox_push_object_given_by_a_string("12345;");
1.3 noro 37: s = test2_ox_pop_string();
1.1 takayama 38: printf("%s\n",s);
39:
40: }
41:
42: asir_ox_push_int32(int k) {
43: static unsigned char p[8];
44: *((int *)p) = htonl((int) CMO_INT32);
45: *((int *)(p+4)) = htonl(k);
46: debug_packet(p,8);
47: asir_ox_push_cmo(p);
48: }
49:
50: asir_ox_push_string(char *s) {
51: unsigned char *p;
52: p = (unsigned char *)GC_malloc(strlen(s)+8);
53: if (sizeof(int) != 4) {
54: fprintf(stderr,"sizeof(int) is not equal to 4.\n"); exit(1);
55: }
56: *((int *)p) = htonl((int) CMO_STRING);
57: *((int *)(p+4)) = htonl((int ) strlen(s));
58: strcpy(p+8,s);
59: debug_packet(p,strlen(s)+8);
60: asir_ox_push_cmo(p);
61: }
62:
63: asir_ox_push_object_given_by_a_string(char *s) {
64: asir_ox_push_string(s);
65: asir_ox_push_cmd(SM_executeStringByLocalParser);
66: }
67:
1.3 noro 68: char *test2_ox_pop_string() {
1.1 takayama 69: int size;
70: char *s;
71: int tag;
72: asir_ox_push_int32(1);
73: asir_ox_push_string("rtostr");
74: asir_ox_push_cmd(SM_executeFunction);
75:
76: size = asir_ox_peek_cmo_size();
77: s = (char *)GC_malloc(size+1);
78: asir_ox_pop_cmo(s,size+1);
79: s[size] = 0;
80: tag = ntohl(*((int *)s));
81: if (tag != CMO_STRING) {
82: fprintf(stderr,"asir_ox_pop_string: the cmo object is not a string. Returns the empty string.\n");
83: return("");
84: }else{
85: return(s+8);
86: }
87: }
1.3 noro 88:
1.1 takayama 89: debug_packet(char *p,int size) {
90: int i;
91: for (i=0; i<size; i++) {
92: printf(" %2x ",p[i]);
93: if ((p[i] >= ' ') && (p[i] < 0x7f)) {
94: printf("(%c) ",p[i]);
95: }
96: }
97: printf("\n");
98: }
99:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>