#!/import/perl/bin/perl -nw
# Edit the above for your site or invoke as "perl -n encode_wizard_outline"
# $Id: encode_wizard_outline,v 1.2 1992/11/05 18:13:22 putz Exp $
# Created by Steve Putz <putz@parc.xerox.com>
#
# This converts a single Sharp Wizard outline file in the text format
# produced by the decode_wizard_outline script (without line folding)
# into the format accepted by the wizcom program.  Use with caution and
# at your own risk, since this does no format checking and transferring
# incorrectly encoded data to the Wizard can cause nasty problems.
# Example:
#
#   encode_wizard_outline outline.text | wizcom -write -outline
#

if (eof) {
    $hex = sprintf("%06X", $len);
    $hexlen = substr($hex,4,2) . substr($hex,2,2) .substr($hex,0,2);
    $hex = sprintf("%04X", $nitems);
    $hexitems = substr($hex,2,2) .substr($hex,0,2);
    printf "00%06s%04s", $hexlen, $hexitems;
    print "$data";
    $len = 0;
    $data = "";
}

next unless /^( *)([-*]) *(.*)/;

if (length($1) == 0) {
    $depth = 0;
} else {		# first indented line determines spaces/level
    $indent = length($1) unless defined($indent);
    $depth = length($1)/$indent;
}

$haschild = ($2 eq "*");
$dspchild = $haschild;
$hide = 0;
$full = 1;
$text = $3;
$ctrl = pack("C b8", $depth|128, $full.$hide.$dspchild.$haschild."0001");
$item = $ctrl . $text . "\\";
$len += length($item);
$data .= $item . "\n";
$nitems++;
