X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Farray%2Ftest%2FtestLits_generate.pl;fp=ccan%2Farray%2Ftest%2FtestLits_generate.pl;h=0000000000000000000000000000000000000000;hb=6ba4abebd2fdaba81a0dad774de3cd8fc99304dc;hp=af41b8869ed2811b5ade13ede2f6eae8a73969a9;hpb=460f62ce63a6ef4aaa0f8840474c039f7e73399f;p=ccan diff --git a/ccan/array/test/testLits_generate.pl b/ccan/array/test/testLits_generate.pl deleted file mode 100755 index af41b886..00000000 --- a/ccan/array/test/testLits_generate.pl +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -my $amount = 10; -my $maxLen = 509; -srand(0); - -my $templateFile = 'testLits.h.template'; -my $outFile = 'testLits.h'; - -open(TF, $templateFile); - -open(OUT, '>'.$outFile); -select OUT; - -my $inLoop = 0; -my $loopText = ''; - -foreach my $line () { - $line =~ s/\@amount/$amount/g; - if (!$inLoop) { - if ($line =~ /\@forEachRandomString/) { - $inLoop = 1; - next; - } - print $line; - } elsif ($inLoop == 1) { - if ($line =~ /\@end/) { - $inLoop = 0; - #handle $loopText - for (my $i=0; $i<$amount; $i++) { - my $str = randomCString($maxLen); - my $lt = $loopText; - $lt =~ s/\@i/$i/g; - $lt =~ s/\@str/\"$str\"/g; - print "$lt\n"; - } - $loopText = ''; - next; - } - $loopText .= $line; - } -} - -close(OUT); -close(TF); - -#argument: maxLen -sub randomCString { - my $len = int(rand($_[0]+1)); - my $lastWasHex = 0; - my $str = ''; - - for (my $i=0; $i<$len; $i++) { - my $cn = int(rand(255)) + 1; - my $c = chr($cn); - if ($lastWasHex && ($c =~ /[0-9A-Fa-f]/)) { - $lastWasHex = 1; - $str .= sprintf("\\x%02X", $cn); - } elsif ($c =~ /[\t\n\013\f\r]/) { - $lastWasHex = 0; - $c =~ tr/\t\n\013\f\r/tnvfr/; - $str .= '\\'.$c; - } elsif ($cn<32 || $cn>126) { - $lastWasHex = 1; - $str .= sprintf("\\x%02X", $cn); - } else { - $lastWasHex = 0; - if ($c =~ /[\"\\]/) { - $str .= '\\'.$c; - } else { - $str .= $c; - } - } - } - return $str; -}