/**************************************************************************/
/*                                                                        */
/*                                 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: f_rhex.c,v 1.2 1997/09/25 17:21:42 ae59 Exp $ */
/*
$Log: f_rhex.c,v $
 * Revision 1.2  1997/09/25  17:21:42  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:22:34  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : f_rhex.c                              */
/*                                                              */
/*      Entry           : void f_rhex(desc,r,mode)              */
/*                        f_text *desc;                         */
/*                        a_real *r;                            */
/*                        a_char mode;                          */
/*                                                              */
/*      Arguments       : desc   - device descriptor            */
/*                        r      - real variable                */
/*                        mode   - read mode                    */
/*                                 'x' = hexadecimal            */
/*                                                              */
/*      Description     : read real value in special format     */
/*                                                              */
/*      Date            : 1991-02-01                            */
/*      1991-02-01 : f_getc() used instead of fgetc()           */
/*      1991-01-29 : code reduced using b_text()                */
/*      1990-11-15 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

#ifdef LINT_ARGS
local void f_rhex(f_text *desc,a_real *r,a_char mode)
#else
local void f_rhex(desc,r,mode)

f_text *desc;
a_real *r;
a_char mode;
#endif
        {
        int i;
        a_btyp b = ZERO;

        E_TPUSH("f_rhex")

        if (b_text(desc,TRUE))
           {
           while (desc->eof==FALSE && desc->win.ch[0]==' ')
              f_getc(desc);

           switch(mode)
              {
              case 'X' :
              case 'x' :
                 for (i=0;i<16;i++)
                    {
                    b <<= 4;
                    if (desc->eof==TRUE)
                       {
                       e_trap(I_O_ERROR,4,E_TMSG,20,
                              E_TSTR+E_TEXT(8),desc->name);
                       break;
                       }
                    else if (desc->eoln==TRUE)
                       {
                       e_trap(I_O_ERROR,4,E_TMSG,53,
                              E_TSTR+E_TEXT(8),desc->name);
                       break;
                       }
                    else if (isdigit(desc->win.ch[0]))
                       b += desc->win.ch[0]-'0';
                    else if (isalpha(desc->win.ch[0]))
                       b += toupper(desc->win.ch[0])-('A'-10);
                    else
                       {
                       e_trap(I_O_ERROR,4,E_TMSG,52,
                              E_TCHR+E_TEXT(10),&desc->win.ch[0]);
                       break;
                       }

                    f_getc(desc);

                    if (i==7)
                       {
                       ((a_btyp *)r)[B_HPART] = b;
                       b = ZERO;
                       }
                    else if (i==15) ((a_btyp *)r)[B_LPART] = b;
                    }
                 break;

              default :
                 e_trap(I_O_ERROR,4,E_TMSG,51,E_TCHR,&mode);
              }
           }

        E_TPOPP("f_rhex")
        return;
        }
