1#!/bin/perl 2 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# SPDX-License-Identifier: MPL-2.0 6# 7# This Source Code Form is subject to the terms of the Mozilla Public 8# License, v. 2.0. If a copy of the MPL was not distributed with this 9# file, you can obtain one at https://mozilla.org/MPL/2.0/. 10# 11# See the COPYRIGHT file distributed with this work for additional 12# information regarding copyright ownership. 13 14sub sortlevel() { 15 my @options = (); 16 my $fin = ""; 17 my $i = 0; 18 while (<>) { 19 if (/^\s*};$/ || /^\s*}; \/\/.*$/) { 20 $fin = $_; 21 # print 2, $_; 22 last; 23 } 24 next if (/^$/); 25 if (/{$/) { 26 # print 3, $_; 27 my $sec = $_; 28 push(@options, $sec . sortlevel()); 29 } else { 30 push(@options, $_); 31 # print 1, $_; 32 } 33 $i++; 34 } 35 my $result = ""; 36 foreach my $i (sort @options) { 37 $result = ${result}.${i}; 38 $result = $result."\n" if ($i =~ /^[a-z]/i); 39 # print 5, ${i}; 40 } 41 $result = ${result}.${fin}; 42 return ($result); 43} 44 45print sortlevel(); 46