#!/usr/bin/perl

# $Id: parse-status,v 1.1 1998/04/04 06:08:58 dshaw Exp $

# Parses the status file that can be created and maintained by Xtend
# by using the "Statusfile" keyword in .xtendrc

$file=$ARGV[0];
$unit=1;
$house=1;

if($file eq "")
	{
	die "Usage: parse-status <filename>\n";
	}

open(STATFILE,$file) || die "Couldn't open $file";

while(read(STATFILE,$byte,1))
	{
	$byte=unpack("C",$byte);

	if($byte != 0)
		{
		print chr(64+$house).$unit.":\t";
		print " [on]" if($byte & 0x80);
		print " [addressed]" if($byte & 0x40);
		print " [appliance]" if($byte & 0x20);
		print "\n";
		}

	# throw away the other byte.  This will be used in the next version.
	read(STATFILE,$byte,1);
	$unit++;
	if($unit>16)
		{
		$house++;
		$unit=1;
		}
	}
