/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: e_tprt.c,v 1.4 1997/09/25 17:16:47 ae59 Exp $ */
/*
$Log: e_tprt.c,v $
 * Revision 1.4  1997/09/25  17:16:47  ae59
 * Copyright-message
 *
 * Revision 1.3  1995/05/12  14:06:33  ae59
 * cast to long in long output format.
 *
 * Revision 1.2  1994/11/02  13:32:15  ae59
 * add DEC_alpha_c case at double from var arg, no long output format
 *
 * Revision 1.1  1994/01/27  13:22:17  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : e_tprt.c                              */
/*                                                              */
/*      Entry           : void e_tprt(e_argc,e_argv)            */
/*                        int e_argc;                           */
/*                        va_list e_argv;                       */
/*                                                              */
/*      Arguments       : e_argc - number of arguments          */
/*                        e_argv - reference to arguments       */
/*                                                              */
/*      Description     : Print variable argument list.         */
/*                                                              */
/*      Note            : e_argc must be even.                  */
/*                        e_argv is a list of pairs representing*/
/*                        integer values for the data type      */
/*                        specification and pointers to the     */
/*                        objects.                              */
/*                        Displaying stops if one result        */
/*                        argument is detected or the list ends.*/
/*                                                              */
/*      Date            : 1993-12-22                            */
/*      1993-12-22 : corrected E_TLNG output=b=                 */
/*      1993-02-16 : update from Dr. Cordes =b=                 */
/*      1992-12-26 : E_TLNG case added                          */
/*      1991-11-22 : text changed                               */
/*      1991-02-13 : new data characterization E_TSTG           */
/*      1991-01-23 : missing 'else' supplied for case (msg==0). */
/*                   do not display number if E_TRES is set.    */
/*                   TRAP_REAL uses r_writ() to display real.   */
/*      1990-12-13 : ultraprecision actually not used           */
/*      1990-11-28 : e_rtyp,e_rptr set if E_TRES detected       */
/*      1990-10-17 : "0x" displayed in front of hexvalues       */
/*      1990-07-23 : E_TINT objects are of type a_intg          */
/*                   variable p must be of type a_intg          */
/*      1990-07-12 : E_Type + E_TMSG indicates special header   */
/*      1990-07-04 : LINT_ARGS prototype                        */
/*                   f_errr replaces stderr                     */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern char *e_head;
extern f_text f_errr;
extern int e_rtyp;
extern a_VOID e_rptr;
#endif

#ifdef LINT_ARGS
local void e_tprt(int e_argc,va_list e_argv)
#else
local void e_tprt(e_argc,e_argv)
int e_argc;
va_list e_argv;
#endif
        {
        int i,k,res,type,msg;    /* !!! must be int !!! */

        e_rtyp = 0;
        e_rptr = NULL;

        for (i=0;i<e_argc;)
           {
           /* possible pointer allignment problems              */
           type = e_ref(int);

           /* Process message */
           if (type==E_TMSG)
              {
              /* possible pointer allignment problems           */
              type = e_ref(int);
              e_tmsg(type);
              e_argc -= 2;
              continue;
              }

           /* display header if not result argument */
           if ((res = type & E_TRES)==0)
              fprintf(f_errr.fp,"%s",e_head);

           /* display argument number */
           if ((msg=(type & E_TMSG))+res==0)
              fprintf(f_errr.fp,"%1d. ",i/2+1);

           /* display object according to specified type */
           switch (type & ~(E_TMSG+E_TRES))
              {

              case E_TCHR:
                 /* possible pointer allignment problems        */
                 e_rptr = e_ref(char *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       char   : ");
                 fprintf(f_errr.fp,"0x%02.2x   '%c'\n",
                         *(char *)e_rptr,*(char *)e_rptr);
                 break;

              case E_TDBL:
                 /* possible pointer allignment problems        */
#if DEC_ALPHA_C
			  /* double has special alignment other than a_real */
                 e_rptr = (char *)e_ref(double *);
#else
                 e_rptr = (char *)e_ref(a_real *);
#endif
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       real   : 0x");
                 for (k=0;k<D_U_RATIO;k++)
                    fprintf(f_errr.fp,"%08.8lx", (unsigned long)
                  ((a_btyp *)e_rptr)[B_HPART+((B_LPART-B_HPART)/
                                     (D_U_RATIO-1))*k]);
#ifdef TRAP_REAL
                 fprintf(f_errr.fp,"   ");
                 r_writ(f_errr.fp,*(a_real *)e_rptr,16,0,0);
#endif
                 fprintf(f_errr.fp,"\n");
                 break;

              case E_TLNG:
                 /* possible pointer allignment problems        */
                 e_rptr = (char *)e_ref(a_long *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       long   : 0x");
                 for (k=0;k<sizeof(a_long);k++)
fprintf(f_errr.fp,"%02.2x",((unsigned char *)e_rptr)[k]);
                 fprintf(f_errr.fp,"\n");
                 break;

              case E_TDTP:
                 /* possible pointer allignment problems        */
                 e_rptr = (char *)e_ref(dotprecision *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"        dot   : ");
                 if ((*(dotprecision *)e_rptr)[A_STATUS] &
                     A_QUIETNAN)
                    fprintf(f_errr.fp,"qNaN = %08.8lx\n",(unsigned long)
                            (*(dotprecision *)e_rptr)[A_LOWNAN]);
                 else if ((*(dotprecision *)e_rptr)[A_STATUS] &
                          A_PINFINITY)
                    fprintf(f_errr.fp,"+infinity\n");
                 else if ((*(dotprecision *)e_rptr)[A_STATUS] &
                          A_MINFINITY)
                    fprintf(f_errr.fp,"-infinity\n");
                 else if ((*(dotprecision *)e_rptr)[A_BEGIN]==ZERO)
                      fprintf(f_errr.fp,"0\n");
                 else
                    {
                    fprintf(f_errr.fp,"sign='%c' ",
                       ((*(dotprecision *)e_rptr)[A_SIGN])
                        ? '-' : '+');
                    fprintf(f_errr.fp,"begin=%-2ld ",(long)
                       (*(dotprecision *)e_rptr)[A_BEGIN]);
                    fprintf(f_errr.fp,"end=%-2ld ",(long)
                       (*(dotprecision *)e_rptr)[A_END]);
                    for (k=0;k<=(*(dotprecision *)e_rptr)[A_END]-
                         (*(dotprecision *)e_rptr)[A_BEGIN];k++)
                       {
                       if ((k & 7)==0) fprintf(f_errr.fp,"\n%s   ",e_head);
                       fprintf(f_errr.fp,"%08.8lx ",(unsigned long)
                          (*(dotprecision *)e_rptr)
                          [(*(dotprecision *)e_rptr)[A_BEGIN]+k]);
                       }
                    fprintf(f_errr.fp,"\n");
                    }
                 break;

              case E_TINT:
                 /* possible pointer allignment problems        */
                 e_rptr = (char *)e_ref(a_intg *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"   integer    : ");
                 fprintf(f_errr.fp,"0x%08.8lx   ",(long int) *(a_intg *)e_rptr);
                 fprintf(f_errr.fp,"%10ld\n",(long int) *(a_intg *)e_rptr);
                 break;

              case E_TMLT:
                 /* possible pointer allignment problems        */
                 e_rptr = (char *)e_ref(multiprecision *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"     dynamic  : ");
                 if ((*(multiprecision *)e_rptr)->z)
                    fprintf(f_errr.fp,"0\n");
                 else
                    {
                    fprintf(f_errr.fp,"sign='%c' ",
                            ((*(multiprecision *)e_rptr)->s) ? '-' : '+');
                    fprintf(f_errr.fp,"exp=%-10ld ",(long)
                            (*(multiprecision *)e_rptr)->e);
                    fprintf(f_errr.fp,"len=%-10ld ",(long)
                            (*(multiprecision *)e_rptr)->l);
                    for (k=0;k<(*(multiprecision *)e_rptr)->l;k++)
                       {
                       if ((k & 7)==0) fprintf(f_errr.fp,"\n%s   ",e_head);
                       fprintf(f_errr.fp,"%08.8lx ", (unsigned long)
                               (*(multiprecision *)e_rptr)->m[k]);
                       }
                    fprintf(f_errr.fp,"\n");
                    }
                 break;

              case E_TSTR:
                 /* possible pointer allignment problems        */
                 e_rptr = e_ref(char *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       string : ");
                 fprintf(f_errr.fp,"'%s'\n",(char *)e_rptr);
                 break;
/*
              case E_TULT:
                 e_rptr = (char *)e_ref(ultraprecision *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       ultra  : ");
                 if ((*(ultraprecision *)e_rptr)->z)
                    fprintf(f_errr.fp,"0\n");
                 else
                    {
                    fprintf(f_errr.fp,"sign='%c' ",
                    ((*(ultraprecision *)e_rptr)->s) ? '-' : '+');
                    fprintf(f_errr.fp,"exp=%-10d ",
                    (*(ultraprecision *)e_rptr)->e);
                    fprintf(f_errr.fp,"len=%-10d ",
                    (*(ultraprecision *)e_rptr)->l);
                    for (k=0;k<(*(ultraprecision *)e_rptr)->l;k++)
                       {
                       if ((k & 7)==0)
                          fprintf(f_errr.fp,"\n%s   ",e_head);
                       fprintf(f_errr.fp,"%08.8lx ", (unsigned long)
                       (*(ultraprecision *)e_rptr)->m[k]);
                       }
                    fprintf(f_errr.fp,"\n");
                    }
                 break;
*/
              case E_TSTG:
                 /* possible pointer allignment problems        */
                 e_rptr = (char *)e_ref(s_trng *);
                 if (res) break;
                 if (msg) e_tmsg(msg);
                 else fprintf(f_errr.fp,"       string : ");
                 fprintf(f_errr.fp,"'");
                 for (k=0;k<((s_trng *)e_rptr)->clen;k++)
                    fprintf(f_errr.fp,"'%c'\n",
                    ((s_trng *)e_rptr)->ptr[k]);
                 fprintf(f_errr.fp,"'\n");
                 break;
              }
           i += 2;

           /* Display stops if result */
           if (res)
              {
              e_rtyp = type ^ E_TRES;
              return;
              }
           }

        return;
        }
