[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.8

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

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