Annotation of OpenXM/src/ox_toolkit/print.c, Revision 1.7
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.7 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/print.c,v 1.6 2018/04/04 09:44:09 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);
1.7 ! ohara 20: static void print_cmo_zz(cmo_zz* c);
! 21: static void print_cmo_qq(cmo_qq* c);
1.6 ohara 22: static void print_cmo_tree(cmo_tree* c);
1.1 ohara 23:
24: void print_cmo(cmo* c)
25: {
26: int tag = c->tag;
1.5 ohara 27: char *s = get_symbol_by_tag(tag);
28: if (s != NULL) {
29: ox_printf("(%s", s);
1.1 ohara 30: }else {
1.4 ohara 31: ox_printf("(%d", tag);
1.1 ohara 32: }
33:
34: switch(tag) {
35: case CMO_LIST:
36: print_cmo_list((cmo_list *)c);
37: break;
38: case CMO_INT32:
39: print_cmo_int32((cmo_int32 *)c);
40: break;
41: case CMO_MATHCAP:
42: case CMO_INDETERMINATE:
43: case CMO_RING_BY_NAME:
44: case CMO_ERROR2:
45: print_cmo_mathcap((cmo_mathcap *)c);
46: break;
47: case CMO_STRING:
48: print_cmo_string((cmo_string *)c);
49: break;
50: case CMO_NULL:
51: case CMO_ZERO:
52: case CMO_DMS_GENERIC:
1.4 ohara 53: ox_printf(")");
1.1 ohara 54: break;
1.7 ! ohara 55: case CMO_ZZ:
! 56: print_cmo_zz((cmo_zz *)c);
! 57: break;
! 58: case CMO_QQ:
! 59: print_cmo_qq((cmo_qq *)c);
! 60: break;
1.6 ohara 61: case CMO_BIGFLOAT:
62: print_cmo_bf((cmo_bf *)c);
63: break;
64: case CMO_IEEE_DOUBLE_FLOAT:
65: case CMO_64BIT_MACHINE_DOUBLE:
66: print_cmo_double((cmo_double *)c);
67: break;
68: case CMO_TREE:
69: print_cmo_tree((cmo_tree *)c);
70: break;
1.1 ohara 71: default:
1.4 ohara 72: ox_printf("\nprint_cmo() does not know how to print cmo of type %d.\n", tag);
1.1 ohara 73: }
74: }
75:
76: static void print_cmo_int32(cmo_int32* c)
77: {
1.4 ohara 78: ox_printf(", %d)", c->i);
1.1 ohara 79: }
80:
81: static void print_cmo_list(cmo_list* this)
82: {
83: cell* cp = list_first(this);
1.4 ohara 84: ox_printf("[%d]", list_length(this));
1.1 ohara 85: while(!list_endof(this, cp)) {
1.4 ohara 86: ox_printf(", ");
1.1 ohara 87: print_cmo(cp->cmo);
88: cp=list_next(cp);
89: }
1.4 ohara 90: ox_printf(")");
1.1 ohara 91: }
92:
93: static void print_cmo_mathcap(cmo_mathcap* c)
94: {
1.4 ohara 95: ox_printf(", ");
1.1 ohara 96: print_cmo(c->ob);
1.4 ohara 97: ox_printf(")");
1.1 ohara 98: }
99:
100: static void print_cmo_string(cmo_string* c)
101: {
1.4 ohara 102: ox_printf(", \"%s\")", c->s);
1.1 ohara 103: }
104:
1.6 ohara 105: static void print_cmo_double(cmo_double* c)
106: {
107: ox_printf(", %.14f)", c->d);
108: }
109:
1.7 ! ohara 110: static void print_cmo_zz(cmo_zz* c)
! 111: {
! 112: char buf[4096];
! 113: gmp_sprintf(buf, ", %Zd)", c->mpz);
! 114: ox_printf("%s", buf);
! 115: }
! 116:
! 117: static void print_cmo_qq(cmo_qq* c)
! 118: {
! 119: char buf[4096];
! 120: gmp_sprintf(buf, ", %Qd)", c->mpq);
! 121: ox_printf("%s", buf);
! 122: }
! 123:
1.6 ohara 124: static void print_cmo_bf(cmo_bf* c)
125: {
126: char buf[4096];
127: mpfr_sprintf(buf, ", %.12f)", c->mpfr);
128: ox_printf("%s", buf);
129: }
130:
131: static void print_cmo_tree(cmo_tree* c)
132: {
133: ox_printf(", ");
134: print_cmo(c->name);
135: ox_printf(", ");
136: print_cmo(c->attributes);
137: ox_printf(", ");
138: print_cmo(c->leaves);
139: ox_printf(")");
140: }
141:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>