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

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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.6     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/print.c,v 1.5 2003/02/03 23:13:23 ohara Exp $ */
1.1       ohara       3:
                      4: /*
                      5: Functions in this module print a given CMO to console.
                      6: These functions are used for debugging.
                      7: */
                      8:
                      9: #include <stdio.h>
                     10: #include <stdlib.h>
                     11: #include "ox_toolkit.h"
                     12: #include "parse.h"
                     13:
                     14: static void print_cmo_int32(cmo_int32* c);
                     15: static void print_cmo_list(cmo_list* li);
                     16: static void print_cmo_mathcap(cmo_mathcap* c);
                     17: static void print_cmo_string(cmo_string* c);
1.6     ! ohara      18: static void print_cmo_double(cmo_double* c);
        !            19: static void print_cmo_bf(cmo_bf* c);
        !            20: static void print_cmo_tree(cmo_tree* c);
1.1       ohara      21:
                     22: void print_cmo(cmo* c)
                     23: {
                     24:     int tag = c->tag;
1.5       ohara      25:     char *s = get_symbol_by_tag(tag);
                     26:     if (s != NULL) {
                     27:         ox_printf("(%s", s);
1.1       ohara      28:     }else {
1.4       ohara      29:         ox_printf("(%d", tag);
1.1       ohara      30:     }
                     31:
                     32:     switch(tag) {
                     33:     case CMO_LIST:
                     34:         print_cmo_list((cmo_list *)c);
                     35:         break;
                     36:     case CMO_INT32:
                     37:         print_cmo_int32((cmo_int32 *)c);
                     38:         break;
                     39:     case CMO_MATHCAP:
                     40:     case CMO_INDETERMINATE:
                     41:     case CMO_RING_BY_NAME:
                     42:     case CMO_ERROR2:
                     43:         print_cmo_mathcap((cmo_mathcap *)c);
                     44:         break;
                     45:     case CMO_STRING:
                     46:         print_cmo_string((cmo_string *)c);
                     47:         break;
                     48:     case CMO_NULL:
                     49:     case CMO_ZERO:
                     50:     case CMO_DMS_GENERIC:
1.4       ohara      51:         ox_printf(")");
1.1       ohara      52:         break;
1.6     ! ohara      53:     case CMO_BIGFLOAT:
        !            54:         print_cmo_bf((cmo_bf *)c);
        !            55:         break;
        !            56:     case CMO_IEEE_DOUBLE_FLOAT:
        !            57:     case CMO_64BIT_MACHINE_DOUBLE:
        !            58:         print_cmo_double((cmo_double *)c);
        !            59:         break;
        !            60:     case CMO_TREE:
        !            61:         print_cmo_tree((cmo_tree *)c);
        !            62:         break;
1.1       ohara      63:     default:
1.4       ohara      64:         ox_printf("\nprint_cmo() does not know how to print cmo of type %d.\n", tag);
1.1       ohara      65:     }
                     66: }
                     67:
                     68: static void print_cmo_int32(cmo_int32* c)
                     69: {
1.4       ohara      70:     ox_printf(", %d)", c->i);
1.1       ohara      71: }
                     72:
                     73: static void print_cmo_list(cmo_list* this)
                     74: {
                     75:     cell* cp = list_first(this);
1.4       ohara      76:     ox_printf("[%d]", list_length(this));
1.1       ohara      77:     while(!list_endof(this, cp)) {
1.4       ohara      78:         ox_printf(", ");
1.1       ohara      79:         print_cmo(cp->cmo);
                     80:         cp=list_next(cp);
                     81:     }
1.4       ohara      82:     ox_printf(")");
1.1       ohara      83: }
                     84:
                     85: static void print_cmo_mathcap(cmo_mathcap* c)
                     86: {
1.4       ohara      87:     ox_printf(", ");
1.1       ohara      88:     print_cmo(c->ob);
1.4       ohara      89:     ox_printf(")");
1.1       ohara      90: }
                     91:
                     92: static void print_cmo_string(cmo_string* c)
                     93: {
1.4       ohara      94:     ox_printf(", \"%s\")", c->s);
1.1       ohara      95: }
                     96:
1.6     ! ohara      97: static void print_cmo_double(cmo_double* c)
        !            98: {
        !            99:     ox_printf(", %.14f)", c->d);
        !           100: }
        !           101:
        !           102: static void print_cmo_bf(cmo_bf* c)
        !           103: {
        !           104:        char buf[4096];
        !           105:     mpfr_sprintf(buf, ", %.12f)", c->mpfr);
        !           106:     ox_printf("%s", buf);
        !           107: }
        !           108:
        !           109: static void print_cmo_tree(cmo_tree* c)
        !           110: {
        !           111:     ox_printf(", ");
        !           112:     print_cmo(c->name);
        !           113:     ox_printf(", ");
        !           114:     print_cmo(c->attributes);
        !           115:     ox_printf(", ");
        !           116:     print_cmo(c->leaves);
        !           117:     ox_printf(")");
        !           118: }
        !           119:

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