/**************************************************************************/
/*                                                                        */
/*                                 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_wrc2.c,v 1.2 1997/09/25 17:23:28 ae59 Exp $ */
/*
$Log: f_wrc2.c,v $
 * Revision 1.2  1997/09/25  17:23:28  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:22:40  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : f_wrc2.c                              */
/*                                                              */
/*      Entry           : void f_wrc2(desc,s,n,w)               */
/*                        f_text *desc;                         */
/*                        a_char s[];                           */
/*                        a_intg n;                             */
/*                        a_intg w;                             */
/*                                                              */
/*      Arguments       : desc   - device descriptor            */
/*                        s      - char array                   */
/*                        n      - length of char array         */
/*                        w      - width of output field        */
/*                                                              */
/*      Description     : perform PASCAL write(array of char:w).*/
/*                                                              */
/*      Date            : 1991-06-27                            */
/*      1991-06-27 : update w if w<0                            */
/*      1991-02-01 : f_putc() used instead of fputc()           */
/*      1991-01-29 : code reduced using b_text()                */
/*      1991-01-25 : fprintf replaced by fputc                  */
/*                   right-most characters on left adjust       */
/*      1990-11-15 : E_TPUSH+E_TPOPP                            */
/*      1990-10-26 : set file window                            */
/*      1990-08-08 : check for invalid width                    */
/*      1990-07-30 : char replaced by a_char                    */
/****************************************************************/

#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_wrc2(f_text *desc,a_char s[],a_intg n,a_intg w)
#else
local void f_wrc2(desc,s,n,w)

f_text *desc;
a_char s[];
a_intg n;
a_intg w;
#endif
        {
        E_TPUSH("f_wrc2")

        if (b_text(desc,FALSE))
           {

           /* left adjust output in field                  */
           if (w<0)
              {
              if ((w += n)>0)
                 {
                 s += w;
                 n -= w;
                 }
              while (--n>=0) f_putc((a_char)*s++,desc);
              while (++w<=0) f_putc((a_char)' ',desc);
              }

           /* right adjust output in field                 */
           else if(w>0)
              {
              for (;w>n;w--) f_putc((a_char)' ',desc);
              while (--w>=0) f_putc((a_char)*s++,desc);
              }
           }

        E_TPOPP("f_wrc2")
        return;
        }
