#!/usr/bin/perl

# $Id: status,v 1.2 1998/04/06 01:45:46 dshaw Exp $

# This is a simple program to just print out the status of the X10 system
# You can use it as a base for your own programs

# gather all of the X10_ prefixed keys
foreach $var (keys %ENV)
	{
	push(@x10,$var) if($var=~s/^X10_//);
	}

# sort the list numerically, and then alphabetically.
foreach $key (sort alpha sort numerically @x10)
	{
	$val=$ENV{"X10_$key"};
	print "$key is";
	print " [on]" if($val & 0x80);
	print " [addressed]" if($val & 0x40);
	print " [appliance]" if($val & 0x20);
	print "\n";
	}

print "\n";

sub numerically
	{
	# sort numerically, but leave off the initial letter (A-P)
	return substr($a,1) <=> substr($b,1);
	}

sub alpha
	{
	# sort alpha, using only the initial letter (A-P)
	return substr($a,0,1) cmp substr($b,0,1);
	}

