/**************************************************************************/
/*                                                                        */
/*                                 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: s_ins2.c,v 1.2 1997/09/25 18:00:08 ae59 Exp $ */
/*
$Log: s_ins2.c,v $
 * Revision 1.2  1997/09/25  18:00:08  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:41  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : s_ins2.c                              */
/*                                                              */
/*      Entries         : a_VOID s_ins2(s,rs,re)                */
/*                        s_etof s;                             */
/*                        a_intg rs,re;                         */
/*                                                              */
/*      Arguments       : s = set                               */
/*                        rs = start of element range           */
/*                        re = end of element range             */
/*                                                              */
/*      Function value  : pointer to updated set                */
/*                                                              */
/*      Description     : Add element range rs-re to set s.     */
/*                                                              */
/*      Date            : 1992-01-24                            */
/*      1992-01-24 : must not clear bits that are already set   */
/*      1991-08-27 : do not set bits individually               */
/*      1991-07-08 : It is no error if rs is greater than re    */
/*      1991-01-29 : 0x80 casted with (unsigned 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 a_VOID s_ins2(s_etof s,a_intg rs,a_intg re)
#else
local a_VOID s_ins2(s,rs,re)

s_etof s;
a_intg rs;
a_intg re;
#endif
        {
        register a_intg i,k;
        static unsigned char bits[] =
           { 0xFF,0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01 };

        E_TPUSH("s_ins2")

        if (rs<0 || re>s_SIZE*BITS_PER_CHAR-1)
           e_trap(INDEX_RANGE,4,E_TINT+E_TEXT(5),&rs,
                                E_TINT+E_TEXT(6),&re);
        else
           {
           if ((i = rs>>LOG_BITS_PER_CHAR)<(k = re>>LOG_BITS_PER_CHAR))
              {
              s[i] |= bits[rs&MOD_BITS_PER_CHAR];
              while (++i<k) s[i] = 0xFF;
              s[i] |= ~(bits[re&MOD_BITS_PER_CHAR]>>1);
              }
           else
              {
              s[i] |= bits[rs&MOD_BITS_PER_CHAR] & 
                      ~(bits[re&MOD_BITS_PER_CHAR]>>1);
              }
           }

        E_TPOPP("s_ins2")
        return((a_VOID)&s[0]);
        }
