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

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

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

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