#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_remove_list_items.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)15	1.4 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_remove_list_items.sh, hacmp, 61haes_r714 11/28/11 15:15:49
#
#=head1 NAME
#
# KLIB_UTIL_LIST_remove_list_items - Remove specified items from a list
#
#=head1 SYNOPSIS
#
# typeset list="a b c d e f g h"
# KLIB_UTIL_LIST_remove_list_items list "a" "d" "e"
#
#=head1 DESCRIPTION
#
# Remove an unlimited number of items from a list
#
#=head1 ARGUMENTS
#
#   1: [by ref] is the name not value of original list
#               the original list will be rebuilt after its contents
#               are saved. The returned list will not have the same
#               order as the original list, just the same members
#               excluding those listed on the command line
#
#   2+: [scalar] Any number of items to be removed from the original list
#
#=head1 RETURN
#
#       0 - success,
#       1 - failed,
#
#=head1 COPYRIGHT
#
#(C) COPYRIGHT International Business Machines Corp. 2005
#All Rights Reserved
#
#=cut
#
function KLIB_UTIL_LIST_remove_list_items
{
  . /usr/es/lib/ksh93/func_include

  typeset -n orig_list=$1
  typeset -n remove_list=$2
  typeset -A keep_set
  typeset -A remove_set
  typeset key
  shift

  for key in $orig_list; do
    keep_set[$key]=:
  done

  while shift; (( $# )); do
    key=$1
    if [[ -n "${keep_set[$key]}" ]]; then
        unset keep_set[$key]
        remove_set[$key]=:
    fi
  done
  orig_list="${!keep_set[*]}"
  remove_list="${!remove_set[*]}"
}
