/contrib/bind9/doc/misc/sort-options.pl

https://bitbucket.org/freebsd/freebsd-head/ · Perl · 50 lines · 27 code · 3 blank · 20 comment · 6 complexity · 57106889aa535ccec27fc188e7a2d75a MD5 · raw file

  1. #!/bin/perl
  2. #
  3. # Copyright (C) 2007 Internet Systems Consortium, Inc. ("ISC")
  4. #
  5. # Permission to use, copy, modify, and/or distribute this software for any
  6. # purpose with or without fee is hereby granted, provided that the above
  7. # copyright notice and this permission notice appear in all copies.
  8. #
  9. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. # PERFORMANCE OF THIS SOFTWARE.
  16. # $Id: sort-options.pl,v 1.3 2007/09/24 23:46:48 tbox Exp $
  17. sub sortlevel() {
  18. my @options = ();
  19. my $fin = "";
  20. my $i = 0;
  21. while (<>) {
  22. if (/^\s*};$/) {
  23. $fin = $_;
  24. # print 2, $_;
  25. last;
  26. }
  27. next if (/^$/);
  28. if (/{$/) {
  29. # print 3, $_;
  30. my $sec = $_;
  31. push(@options, $sec . sortlevel());
  32. } else {
  33. push(@options, $_);
  34. # print 1, $_;
  35. }
  36. $i++;
  37. }
  38. my $result = "";
  39. foreach my $i (sort @options) {
  40. $result = ${result}.${i};
  41. $result = $result."\n" if ($i =~ /^[a-z]/i);
  42. # print 5, ${i};
  43. }
  44. $result = ${result}.${fin};
  45. return ($result);
  46. }
  47. print sortlevel();