getmax 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Look at a bunch of bargraph files and figure out the max amongst them all.
  2. # Usage: getmax file file file....
  3. #
  4. # Hacked into existence by Larry McVoy (lm@sun.com now lm@sgi.com).
  5. # Copyright (c) 1994 Larry McVoy. GPLed software.
  6. # $Id$
  7. eval 'exec perl -Ssw $0 "$@"'
  8. if 0;
  9. $graph = 1 if 0;
  10. $exit = 1;
  11. foreach $file (@ARGV) {
  12. $exit = 0 if -f $file;
  13. }
  14. exit $exit if $noop;
  15. $noop = 1 if 0;
  16. $max_X = $max_Y = -1000000000;
  17. $min_X = $min_Y = 1000000000;
  18. foreach $file (@ARGV) {
  19. next if $rmmax;
  20. unless (open(FD, $file)) {
  21. warn "Can't open $file\n";
  22. next;
  23. }
  24. while (<FD>) {
  25. next if /^"/;
  26. next if /^%/;
  27. next if /^\s*$/;
  28. next if m|scripts/lmbench: /dev/tty|;
  29. @_ = split;
  30. $min_X = $_[0] if ($_[0] < $min_X);
  31. $min_Y = $_[1] if ($_[1] < $min_Y);
  32. $max_X = $_[0] if ($_[0] > $max_X);
  33. $max_Y = $_[1] if ($_[1] > $max_Y);
  34. }
  35. close(FD);
  36. }
  37. $half = 0 if 0; # lint
  38. $max_X /= 2 if ($half);
  39. foreach $file (@ARGV) {
  40. unless (open(FD, $file)) {
  41. warn "Can't open $file\n";
  42. next;
  43. }
  44. @lines = <FD>;
  45. open(FD, ">$file") || die "Can't open $file\n";
  46. if ($graph) {
  47. print FD "%fakemin-X $min_X\n";
  48. print FD "%fakemin-Y $min_Y\n";
  49. print FD "%fakemax-X $max_X\n";
  50. print FD "%fakemax-Y $max_Y\n";
  51. foreach $_ (@lines) {
  52. next if /^%fakem/;
  53. print FD;
  54. }
  55. warn "Max X is $max_X\n" if $v;
  56. warn "Max Y is $max_Y\n" if $v;
  57. } elsif ($rmmax) {
  58. foreach $_ (@lines) {
  59. next if /^%fakem/;
  60. print FD;
  61. }
  62. } else {
  63. print FD @lines;
  64. print FD "%fakemax $max_X\n";
  65. warn "Max X is $max_X\n" if $v;
  66. }
  67. close(FD);
  68. }
  69. exit $exit;