#!/usr/bin/perl # Generate a skew table use Getopt::Std; $skew= 4; # defaults $sectors= 64; getopts('hos:k:'); if ($opt_h) { print "Usage:\n skew -s N -k K\n"; print " N is sectors/track (default 64),\n"; print " K is skew factor (default 5)\n"; print " -o octal\n"; exit(1); } $skew= $opt_k if defined $opt_k; $sectors= $opt_s if defined $opt_s; for ($i= 0; $i < $opt_s; ++$i) { # mark table to make bad factors stand out $S[$i]= 99999; } # Fill in the skew table. Note that many combinations of # sector & skew do not repeat; we fix most of these by # incrementing N if an iteration would overwrite a previous. $n= 0; for ($i= 0; $i < $sectors; ++$i) { $S[$n]= $i; $n += $skew; if ($n >= $sectors) { # wraparound, $n -= $sectors; # modulo SECTORS, ++$n if $S[$n] || $n == 0; } } # Display the table. print "Skew table, ${sectors}x$skew, "; print $opt_o ? "octal" : "decimal"; $n= 0; for ($i= 0; $i < $sectors; ++$i) { if ($opt_o) { print sprintf ("\n%02o: ", $i) if $i % $skew == 0; print sprintf ("%2o ", $S[$i]); } else { print sprintf ("\n%02d: ", $i) if $i % $skew == 0; print sprintf ("%2d ", $S[$i]); } } print "\n";