[BACK]Return to test2.c CVS log [TXT][DIR] Up to [local] / OpenXM / doc / oxlib

Annotation of OpenXM/doc/oxlib/test2.c, Revision 1.3

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

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