#!/usr/bin/perl

# This script is included for debugging purposes ONLY.
# It sends meta-random commands to ledd trying thus to make
# it crash.
#
# With previous versions (version <= 0.3.0) it was also quite successful
# at it, but it seems that (without knowing it) I have fixed the bug...
# I still have no idea where it was...
#
# You can stop it with:
#   killall garbage.pl


# Report on exit
sub catch_zap {
    print STDERR "Gave it $n lines.\n";
    exit 0;
}
$SIG{HUP} = \&catch_zap;
$SIG{INT} = \&catch_zap;
$SIG{QUIT} = \&catch_zap;
$SIG{TERM} = \&catch_zap;

@cmds=("n1","n6","s5","s9","c","c8","cn3","csn7",
       "N","S","C","N","S","C",
       "on","off","normal","blink","on","off","normal","blink",
       "10","100","200","300","700","900","1000",
       "set","set","anim","anim","nop",
       "frequency","dutycycle","duty" . chr(4) . "cycle",
       "blah","set n7","ncd","fqdn","csnsnCNsNSCssncSCSnscsnCS",
       "574893758493075","5543646436","432435","543643",
       "loop","loop");


### Generate some random commands:
for ($i=0; $i<3; $i++) {
    $rnd=rand()*30;
    $str="";
    for ($j=0; $j<$rnd; $j++) {
	$str=$str . chr(int(rand()*250)+1);
    }
    push @cmds,$str;
}
for ($i=0; $i<5; $i++) {
    $rnd=rand()*20;
    $str="";
    $letters="ncsNCSncsNCSncsNCSncsNCSxXxX0123456789";
    for ($j=0; $j<$rnd; $j++) {
	$str=$str . substr($letters,int(rand()*length($letters)),1);
    }
    push @cmds,$str;
}


for ($n=0; ; $n++) {
    $rnd=rand();
    if ($rnd<0.4) {
	$cmd="set ";
    } elsif ($rnd<0.8) {
	$cmd="anim ";
    } else {
	$cmd="";
    }
    $rnd=rand()*15;
    for ($i=0; $i<$rnd; $i++) {
	$cmd=join(" ",($cmd,$cmds[int(rand()*($#cmds+1))]));
    }
#    printf("Giving command >%s<\n",$cmd);
    print "$cmd\n";
#    sleep 1;
}

