/**************************************************************************/
/*                                                                        */
/*                                 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_ixch.c,v 1.2 1997/09/25 18:00:35 ae59 Exp $ */
/*
$Log: s_ixch.c,v $
 * Revision 1.2  1997/09/25  18:00:35  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:42  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : s_ixch.c                              */
/*                                                              */
/*      Entry           : a_intg s_ixch(i,length)               */
/*                        a_intg i;                             */
/*                        size_t length                         */
/*                                                              */
/*      Arguments       : i - index to component of string      */
/*                        length - length of string             */
/*                                                              */
/*      Description     : Determine offset to component of      */
/*                        string with index checking.           */
/*                                                              */
/*      Note            : -1 is returned in case of error       */
/*                                                              */
/*      Date            : 1990-11-20                            */
/*      1990-11-20 : 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 a_intg s_ixch(a_intg i,size_t length)
#else
local a_intg s_ixch(i,length)

a_intg i;
size_t length;
#endif
        {
        a_intg res,l,u;

        E_TPUSH("s_ixch")

        if (i>0 && i<=length) res = i-1;
        else
           {
           l = 1;
           u = length;
           e_trap(INDEX_RANGE,6,E_TINT+E_TEXT(4),&i,
                                E_TINT+E_TEXT(5),&l,
                                E_TINT+E_TEXT(6),&u);
           res = -1;
           }

        E_TPOPP("s_ixch")
        return(res);
        }
