#****************************************************************************
#  ##   ##         #####   #####  ##     **       NoSQL RDBMS - addcol      *
#  ###  ##        ####### ####### ##     **        $Revision: 2.1 $			*
#  #### ##        ###     ##   ## ##     ************************************
#  #######  ####  #####   ##   ## ##     **      Carlo Strozzi (c) 1998     *
#  ####### ######   ##### ## # ## ##     ************************************
#  ## #### ##  ##     ### ##  ### ##     **           Written by            *
#  ##  ### ###### ####### ######  ###### **          Carlo Strozzi          *
#  ##   ##  ####   #####   #### # ###### **     e-mail: carlos@linux.it     *
#****************************************************************************
#   NoSQL RDBMS, Copyright (C) 1998 Carlo Strozzi.                          *
#   This program comes with ABSOLUTELY NO WARRANTY; for details             *
#   refer to the GNU General Public License.                                *
#****************************************************************************
#
#  Append new empty columns to a table.
#
#  The columns specified on the command line are appended to the right
#  of the existing ones. The program does not check for duplicates.
#
#  This NoSQL operator reads a table STDIN and write a new
#  table to STDOUT.
#
########################################################################

########################################################################
# BEGIN block
########################################################################

BEGIN \
{
  NULL = ""; FS = OFS = "\t";
  split( __nosql_args,new_cols, " " )
}

########################################################################
# Main loop
########################################################################

NR == 1 \
{
  while ( new_cols[++i] != NULL )
  {
	$0 = $0 OFS new_cols[i]
	padding = padding OFS
  }

  # Remove extra OFS from the beginning of header and dashline.

  sub( /^\t/, NULL, $0 )
  sub( /^\t/, NULL, padding )

  # print header and dashline (if not null).

  if ( $0 != NULL ) { print; gsub( /[^\t]/, "-" ); print }
}

NR == 2 { next }

NR > 2 { print $0, padding }

