[BACK]Return to sample2.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/sample2.c, Revision 1.6

1.1       ohara       1: /* -*- mode: C -*- */
1.6     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/sample2.c,v 1.5 2003/02/04 20:43:55 ohara Exp $ */
1.1       ohara       3:
                      4: /*
                      5:   This program explains how to get
                      6:   int, char *, and so on from the received data
                      7:   by using low-level functions of OpenXM C library.
                      8: */
                      9:
                     10: #include <stdio.h>
                     11: #include <stdlib.h>
                     12: #include <unistd.h>
1.2       ohara      13: #include "ox_toolkit.h"
1.1       ohara      14:
1.3       ohara      15: void explain_cmo(cmo *);
1.1       ohara      16:
1.3       ohara      17: void explain_cmo_list(cmo_list *c)
1.1       ohara      18: {
1.3       ohara      19:     int len=list_length(c);
                     20:     int i=0;
                     21:     printf("{");
                     22:     for(i=0; i<len; i++) {
                     23:         explain_cmo(list_nth(c, i));
                     24:         printf(", ");
                     25:     }
                     26:     printf("}");
1.1       ohara      27: }
                     28:
1.3       ohara      29: void explain_cmo_int32(cmo_int32 *c)
1.1       ohara      30: {
1.3       ohara      31:     printf("%d", c->i);
1.1       ohara      32: }
                     33:
1.3       ohara      34: void explain_cmo_string(cmo_string *c)
1.1       ohara      35: {
1.3       ohara      36:     printf("%s", c->s);
1.1       ohara      37: }
                     38:
1.6     ! ohara      39: #if defined(WITH_GMP)
1.3       ohara      40: void explain_cmo_zz(cmo_zz *c)
1.1       ohara      41: {
1.3       ohara      42:     printf("%s", new_string_set_cmo((cmo *)c));
1.1       ohara      43: }
1.6     ! ohara      44: #endif /* WITH_GMP */
1.1       ohara      45:
1.3       ohara      46: void explain_cmo(cmo *c)
1.1       ohara      47: {
1.3       ohara      48:     switch(c->tag) {
                     49:     case CMO_LIST:
                     50:         explain_cmo_list((cmo_list *)c);
                     51:         break;
                     52:     case CMO_INT32:
                     53:         explain_cmo_int32((cmo_int32 *)c);
                     54:         break;
                     55:     case CMO_STRING:
                     56:         explain_cmo_string((cmo_string *)c);
                     57:         break;
1.6     ! ohara      58: #if defined(WITH_GMP)
1.3       ohara      59:     case CMO_ZZ:
                     60:         explain_cmo_zz((cmo_zz *)c);
                     61:         break;
1.6     ! ohara      62: #endif /* WITH_GMP */
1.3       ohara      63:     default:
                     64:         printf("cmo");
                     65:     }
1.1       ohara      66: }
                     67:
                     68: int main()
                     69: {
1.3       ohara      70:     OXFILE *s;
                     71:     cmo_list *c;
                     72:     cmo *d;
1.1       ohara      73:
1.5       ohara      74:        ox_stderr_init(stderr);
1.3       ohara      75:     /* starting an OpenXM server */
1.1       ohara      76:     s = ox_start("localhost", "ox", "ox_sm1");
                     77:
1.3       ohara      78:     /* making a list. */
                     79:     c = list_appendl(new_cmo_list(),
                     80:                      (cmo *)new_cmo_int32(10000),
                     81:                      (cmo *)new_cmo_string("Hello"),
1.6     ! ohara      82: #if defined(WITH_GMP)
1.3       ohara      83:                      (cmo *)new_cmo_zz_set_string("3141592653289793238462643383279"),
1.6     ! ohara      84: #endif /* WITH_GMP */
1.3       ohara      85:                      NULL);
                     86:
                     87:     ox_push_cmo(s, (cmo *)c);
                     88:     ox_push_cmd(s, SM_popCMO);
                     89:
                     90:     /* The following equals to ox_get(s) */
                     91:     receive_ox_tag(s);
                     92:     d = receive_cmo(s);
                     93:     explain_cmo(d);
                     94:     printf("\n");
1.1       ohara      95:
                     96:     ox_close(s);
                     97:     return 0;
                     98: }

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