#!/bin/ash
# *********************************************************************
# uniontable: build the "Universal Table" of one or more tables.
#
# Copyright (c) 2006,2007,2009 Carlo Strozzi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# 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 GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# *********************************************************************

# Get local settings and apply defaults.
: ${TMPDIR:=/tmp} ${NOSQL_CHARSET:=utf-8}
: ${NOSQL_INSTALL:=@NOSQL_INSTALL@}
: ${SWU_INSTALL:=@SWU_INSTALL@}
: ${PATH:=@LOCAL_PATH@}

export NOSQL_INSTALL SWU_INSTALL PATH TMPDIR NOSQL_CHARSET

EUSAGE='Usage: uniontable [options] table [table ...]'

[ $# = 0 ] && { echo "$EUSAGE"; exit 1; }

while :
do
  case $1 in
    -o|--output)	shift; o_file="$1" ;;
    -h|--help)
       grep -v '^#' $NOSQL_INSTALL/help/uniontable.txt
       exit 1
    ;;
    --show-copying)
       cat $NOSQL_INSTALL/doc/COPYING
       exit 1
    ;;
    --show-warranty)
       cat $NOSQL_INSTALL/doc/WARRANTY
       exit 1
    ;;
    -N|--no-header)
       args="$args $1"
    ;;
    *)
       break
    ;;
  esac
  shift
done

[ "X$o_file" = X ] || exec > "$o_file"

tabletolist --mux "$@" | muxtotable $args

#EOF
