#!/usr/local/bin/perl
#
# Read a spice "deck" file with line continuation using '+' and write it out
# with really long lines.
#
# example input:
# .model foo nmos
# +Level=49
# +ACM=3
#
# corresponding output:
# .mode foo nmos Level=49 ACM=3
#
# $Log: spicecontline,v $
# Revision 1.1  1999/12/08 14:17:21  tell
# Moved in files from the old "hcutil" that weren't RCS'ed
#
#

use IO::File;

if($#ARGV != 0) {
	print STDERR "usage: spicecontline file\n";
	exit(1);
}

$fh = new IO::File $ARGV[0], "r";
if(!defined($fh)) {
	print STDERR "$ARGV[0]: $!\n";
	exit(1);
}

while($_ = &get_line_cont($fh)) {
	print $_;
}

$fh->close;

#############################################################################
# Return a single logical line from a spice file, 
# handling continuation with '+'
#

sub get_line_cont
{
	my($f) = @_;
	my($line, $nline);
	
	if(defined($pushback_line)) {
		$line = $pushback_line;
		undef $pushback_line;
	} else {
		$line = $f->getline;
	}
	if(! $line) {
		return $line;
	}
		
	$nline = $f->getline;
	while($nline =~ m/^\+/) {
		$nline =~ s/^\+/ /;
		$line =~ s/\n$//;
		$line .= $nline;
		$nline = $f->getline;
	}
	if($nline) {
		$pushback_line = $nline;
	}

	return $line;
}
