/**************************************************************************/
/*                                                                        */
/*                                 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_wint.c,v 1.2 1997/09/25 17:22:59 ae59 Exp $ */
/*
$Log: f_wint.c,v $
 * Revision 1.2  1997/09/25  17:22:59  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:22:39  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : f_wint.c                              */
/*                                                              */
/*      Entry           : void f_wint(device,i,TotalWidth)      */
/*                        f_text *device;                       */
/*                        a_intg i,TotalWidth;                  */
/*                                                              */
/*      Arguments       : device - file descriptor              */
/*                        i - integer value to be written       */
/*                        TotalWidth - number of characters     */
/*                                                              */
/*      Description     : perform PASCAL integer write.         */
/*                                                              */
/*      Note            : BS PASCAL Standard 6.9.3.2            */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : cast to char at buffer assignm. =b=        */
/*      1991-02-01 : f_putc() used instead of f_putc()          */
/*      1991-02-01 : argument changed to f_text                 */
/*      1991-01-28 : MINUS_SIGN used                            */
/*      1990-10-31 : fprintf replaced by fputc                  */
/*                   left adjust output if width is negative    */
/*      1990-07-12 : LINT_ARGS prototype, cp renamed            */
/****************************************************************/

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

#ifdef LINT_ARGS
local void f_wint(f_text *device,a_intg i,a_intg TotalWidth)
#else
local void f_wint(device,i,TotalWidth)

f_text *device;
a_intg i;
a_intg TotalWidth;
#endif
        {
        a_intg IntDigits;
        a_bool sign;
        char *buffer;
        a_btyp b;

        buffer = (char *)b_cp__;

        IntDigits = 0;
        if (i<0)
           {
           if (i==MININT) b = MSB;
           else b = -i;
           sign = TRUE;
           }
        else
           {
           b = i;
           sign = FALSE;
           }

        do
           {
           buffer[IntDigits++] = (char) (b%10+'0');
           b /= 10;
           }
        while (b>0);

        if (TotalWidth>0)
           {
           if (TotalWidth>=IntDigits+1)
              {
              for (i=0;i<TotalWidth-IntDigits-1;i++)
                 f_putc((a_char)' ',device);
              f_putc((a_char)((sign) ? MINUS_SIGN : ' '),device);
              }
           else
              if (sign) f_putc((a_char)MINUS_SIGN,device);

           while (--IntDigits>=0)
              f_putc((a_char)buffer[IntDigits],device);
           }
        else
           {
           if ((TotalWidth = -TotalWidth-IntDigits-1)>=0)
              f_putc((a_char)((sign) ? MINUS_SIGN : ' '),device);
           else if (sign)
              f_putc((a_char)MINUS_SIGN,device);
           for (i = --IntDigits;i>=0;i--)
              f_putc((a_char)buffer[i],device);
           while (++i<TotalWidth)
              f_putc((a_char)' ',device);
           }

        return;
        }
