#!/usr/bin/perl
# Original code: mktbl,v 2.7 1993/03/29 13:34:46 hobbs
#
$RCS_ID = '$Id: nsq-mktbl,v 1.0 1998/05/14 11:08:25 carlos Exp $' ;
$0 =~ s-.*/-- ;
$HelpInfo = <<EOH ;

		    NoSQL Operator: $0

Usage: $0 [options]

Options:
    -edit    Edit form of output, used primarily by 'nsq-ed'.
    -help    Print this help info.

Makes a file of data in columns (with visible column delimiters) into an
rdbtable.  The column delimeter is the pipe symbol (|).

This operator reads a file via STDIN and writes an rdbtable via STDOUT.
Options may be abbreviated.

$RCS_ID

			----------------------
NoSQL RDBMS, Copyright (C) 1998 Carlo Strozzi.
This program comes with ABSOLUTELY NO WARRANTY; for details
refer to the GNU General Public License.

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., 59 Temple Place Suite 330, Boston, MA 02111-1307
USA.
			----------------------

EOH
#    -sK     K will be the visible column delimiter, which may be multi-char.
#	     Default is '|', e.g. a space, a vertical bar, and a space.
while ( $ARGV[0] =~ /^-/ ) {				# Get args
    $_ = shift ;
    if( /-e.*/ ){ $EDT++ ; next ; }
    if( /^-h.*/ ){ print $HelpInfo ; exit 1 ; }
    die "\nBad arg: $_\n", "For help type \"$0 -help\".\n" ; 
}
while(<>){
    if( $EDT && /^\.\.>>>/ ){ print ; next ; }	# control line
    if( /^\s*#/ ){ print ; next ; } 	# comment 
    s/^\s+// ;
    s/\s+$/\n/ ;
    s-\s*\|[ \t]*-\t-g ;
    $_ = "\n" if $_ eq "" ;	# safety valve
    print ;
}
