/*
   <p><i>chopinsert()</i> function</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include "environ.h"

#ifdef OS9
#include <strings.h>
#else
#include <string.h>
#endif

/* 
   <i>chopinsert()</i> is called to add a missing item into the array.
   <u>Table</u> is the array into which the item must be inserted. 
   <u>Items</u> contains the number of items in the array. It is
   incremented to reflect the new number of items in the array after
   a successful insertion. <u>Tablimit</u> contains the maximum number
   of items that can be held in the array. <u>Newitem</u>
   is a pointer to the item to be added to the array.
   <u>InsertPoint</u> is the subscript of the correct insertion place
   in the array. It is returned by <i>chopsearch()</i>.

    <b>See also:</b> <i>chopsearch()</i>.
*/
int chopinsert(void **Table,
               int *Items,
               int Tablimit,
               void *NewItem,
               int InsertPoint)
{
   int i;

   if (*Items >= Tablimit)
       return(Tablimit);

   for (i = *Items; i > InsertPoint; i--)
      Table[i] = Table[i-1];

   (*Items)++;
      Table[InsertPoint] = NewItem;

   return(0);
}
