/**************************************************************************/
/*                                                                        */
/*                                 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_getc.c,v 1.2 1997/09/25 17:19:33 ae59 Exp $ */
/*
$Log: f_getc.c,v $
 * Revision 1.2  1997/09/25  17:19:33  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:22:27  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : f_getc.c                              */
/*                                                              */
/*      Entry           : void f_getc(desc)                     */
/*                        f_text *desc;                         */
/*                                                              */
/*      Arguments       : desc   - descriptor of device         */
/*                                                              */
/*      Description     : get a character from a checked        */
/*                        device.                               */
/*                                                              */
/*      Date            : 1991-09-06                            */
/*      1991-09-06 : reduce maximum line length                 */
/*      1991-07-09 : eoln=FALSE if eof detected in textfile     */
/****************************************************************/

#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_getc(f_text *desc)
#else
local void f_getc(desc)

f_text *desc;
#endif
        {
        int ch; /* !!! must be int !!! */
        size_t i;

        E_TPUSH("f_getc")

        if (desc->text)
           {
           if ((ch = fgetc(desc->fp))==EOF)
              {
              desc->win.ch[0] = ' ';
              desc->eof = TRUE;
              desc->eoln = FALSE;
              }
           else if (ch=='\n')
              {
              desc->win.ch[0] = ' ';
              desc->eoln = TRUE;
              }
           else
              {
              desc->win.ch[0] = ch;
              desc->eoln = FALSE;
              }
           }
        else
           {
           for (i=0;i<desc->ellen;i++)
              {
              if ((ch = fgetc(desc->fp))==EOF)
                 {
                 desc->eof = TRUE;
                 if (i)
                    e_trap(I_O_ERROR,4,E_TMSG,20,
                           E_TSTR+E_TEXT(8),desc->name);
                 break;
                 }
              desc->win.ch[i] = ch;
              }
           }

        E_TPOPP("f_getc")
        return;
        }
