Copyright (C) 2000-2012 |
GNU Info (g-wrap.info)Printing object representationsPrinting object representations =============================== The function for printing a representation of the object should have a declaration similar to this: void PRINT_FN_NAME (TYPE* obj, GWSCM port, int writingp); The first parameter accepts a pointer to the object to be printed, the second parameter accepts a Scheme value representing the Scheme port to write to, and the final argument indicates whether the object is being printed with `display' (`writingp==0') or `write' (`writingp!=0'). The function `gw_puts(char*,GWSCM)' can be used to write a string to the port. Here is an example of a function used for printing a matrix type: void MAT_print(MAT *m, GWSCM scmport, int writingp) { int i, j; char buff[80]; if ( !m ) { gw_puts("MNULL",scmport); return; } if ( writingp ) { sprintf(buff,"(MAT %d %d (", m->m, m->n); gw_puts(buff, scmport); } else { gw_puts("\n", scmport); } for ( i = 0; i < m->m; i++ ) { if ( !writingp ) { gw_puts("[ ", scmport); } for ( j = 0; j < m->n; j++ ) { sprintf(buff,"%lf ", m->me[i][j]); gw_puts(buff, scmport); } if ( !writingp ) { gw_puts("]\n", scmport); } } if ( writingp ) { gw_puts(")) ", scmport); } } automatically generated by info2www version 1.2.2.9 |