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

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

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

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