From: Alan T. DeKok Date: Mon, 11 Sep 2023 09:36:47 +0000 (-0400) Subject: just use tabs function instead of hand-rolling things X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb1a612093b2f57940b4272e59cd2d2510316582;p=thirdparty%2Ffreeradius-server.git just use tabs function instead of hand-rolling things --- diff --git a/scripts/dict/format.pl b/scripts/dict/format.pl index 30765a77b7a..2cc3ac92fc4 100755 --- a/scripts/dict/format.pl +++ b/scripts/dict/format.pl @@ -262,53 +262,13 @@ while (@ARGV) { # STRUCT name attr value # if (/^STRUCT\s+([-\w]+)\s+([-\w\/,.]+)\s+(\w+)(.*)/) { - my $attr = $2; - my $len = length $attr; - - if ($len < 32) { - my $lenx = 32 - $len; - $lenx += 7; # round up - $lenx /= 8; - $lenx = int $lenx; - $tabsa = "\t" x $lenx; - if ($tabsa eq "") { - $tabsa = " "; - $len += 1; - } else { - $len -= $len % 8; - $len += 8 * length $tabsa; - } - } else { - $tabsa = " "; - $len += 1; - } - - # - # For the code below, we assume that the attribute lengths - # - my $lena; - if ($len < 32) { - $lena = 0; - } else { - $lena = $len - 32; - } - my $name = $1; - $len = length $name; - if ($len < 24) { - my $lenx = 24 - $lena - $len; - $lenx += 7; # round up - $lenx /= 8; - $lenx = int $lenx; - $tabsn = "\t" x $lenx; - if ($tabsn eq "") { - $tabsn = " "; - } - } else { - $tabsn = " "; - } + my $key = $2; + + my $tabs = tabs(32, $name); + my $tabsv = tabs(24, $key); - push @output, "STRUCT\t$name$tabsa$attr$tabsn$3$4\n"; + push @output, "STRUCT\t$name$tabs$key$tabsv$3$4\n"; next; } @@ -331,52 +291,12 @@ while (@ARGV) { # if (/^VALUE\s+([-\w]+)\s+([-\w\/,.]+)\s+(\w+)(.*)/) { my $attr = $1; - my $len = length $attr; - - if ($len < 32) { - my $lenx = 32 - $len; - $lenx += 7; # round up - $lenx /= 8; - $lenx = int $lenx; - $tabsa = "\t" x $lenx; - if ($tabsa eq "") { - $tabsa = " "; - $len += 1; - } else { - $len -= $len % 8; - $len += 8 * length $tabsa; - } - } else { - $tabsa = " "; - $len += 1; - } - - # - # For the code below, we assume that the attribute lengths - # - my $lena; - if ($len < 32) { - $lena = 0; - } else { - $lena = $len - 32; - } - my $name = $2; - $len = length $name; - if ($len < 24) { - my $lenx = 24 - $lena - $len; - $lenx += 7; # round up - $lenx /= 8; - $lenx = int $lenx; - $tabsn = "\t" x $lenx; - if ($tabsn eq "") { - $tabsn = " "; - } - } else { - $tabsn = " "; - } - push @output, "VALUE\t$attr$tabsa$name$tabsn$3$4\n"; + my $tabs = tabs(32, $attr); + my $tabsa = tabs(24, $name); + + push @output, "VALUE\t$attr$tabs$name$tabsa$3$4\n"; next; }