#!/usr/bin/perl
=pod
Simple blackbox style editor.  Looks in your ~/.blackboxrc
and finds out your current style, then it changes $param
to $value. 
by: scott@furt.com	(10-30-2001)
=cut

  if (@ARGV < 2) {
	die "Usage: editbbstyle.pl <param> <new value> 
	Sets <param> to <new value> in your current style file.\n";
  }
	
  my $rc = $ENV{'HOME'}. "/.blackboxrc";
  my $param = shift @ARGV;
  my $value = join(" ", @ARGV);

  my $sfile = &read_bbrc($rc)
  	|| die("Cannot determine which styleFile to edit!");

  &edit_style($sfile, $param, $value)
  	|| die("Could not find $param in $sfile!");

exit;

sub edit_style {
  my ($sfile, $param, $value) = @_;
  my $TEMP, $found;
  
  open(STYLE, "<$sfile") || die("Cannot open $sfile");
    while (my $l = <STYLE>) {
	if ($l =~ /^(\s?)$param:(\s?)/) {
		$found = 1;
		$l = "$1$param:$2$value\n";
	}
	$TEMP .= $l;
    }
  close(STYLE);
  
  return 0 if (!$found);
  
  open (STYLE, ">$sfile") || die("Cannot write $sfile");
    print STYLE $TEMP;
  close(STYLE);

  return 1;
}

#Find out what the current style is
sub read_bbrc {
  my $rc = shift;
  open(RC, "<$rc") || die("Cannot open $rc");
    while (my $l = <RC>) {
	if ($l =~ /session.styleFile:(\s?)(.*)/) {
		close(RC);
		return $2;
	}
    }
  close(RC);
  return 0;
}

