]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't keep adding numbers
authorAlan T. DeKok <aland@freeradius.org>
Thu, 28 Oct 2021 14:46:35 +0000 (10:46 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 29 Oct 2021 13:25:31 +0000 (09:25 -0400)
scripts/build/logid-update.pl

index 3a6ec038a0ba28abf4578409d09cd53815815488..3dd78e649bf57967e9fd62cfa347fec74a9c7f79 100755 (executable)
@@ -17,24 +17,68 @@ use Data::Dumper;
 my $status = 0;
 my $max_id;
 my $regex;
+my %files;
+my %lines;
+my %messages;
 
 sub process {
     my $file = shift;
+    my $text;
+    my $id;
+    my $line;
 
     open(my $FILE, "<", $file) or die "Failed to open $file: $!\n";
     open(my $OUTPUT, ">", "$file.tmp") or die "Failed to create $file.tmp: $!\n";
 
+    $line = 0;
     while (<$FILE>) {
+       $line++;
+
        #
        #  Change the various non-ID messages to ID-based messages
        #
        #  Allow "R" variants of the macros, and DEBUG(2,3,4)
        #
-       if (s/^(\s*R?(DEBUG|P?ERROR|INFO)[0-9]?)\((\s*0\s*,)?/${1}_ID\(\@/g) {
+       #  Allow DEBUG(0, ...) to mean "please assign an ID".
+       #
+       if (! s/^(\s*R?(DEBUG|P?ERROR|INFO)[0-9]?)\((\s*\d+\s*,)?/${1}_ID\(\@/g) {
+           print $OUTPUT $_;
+           next;
+       }
+
+       #  Remember the number so that later regexes don't nuke it.
+       $id = $3;
+
+       #
+       #  If there's no number, or it's 0, allocate one.
+       #
+       if (! defined $id || ($id eq '0,')) {
            s/_ID\(\@/\($max_id, /;
-           $max_id++;
+           $id = $max_id++;
+       } else {
+           #
+           #  Ensure that the numbers are stable.
+           #
+           s/_ID\(\@/\($id/;
+           $id =~ s/,//;
        }
 
+       #
+       #  Try to get the actual message.
+       #
+       my $text = $_;
+       $text =~ s/^[^"]+//;
+       $text =~ s/",.*/"/;
+       $text =~ s/"\).*/"/;
+       chop $text;
+
+       #
+       #  Remember where everything is.
+       #
+       $files{$id} = $file;
+       $lines{$id} = $line;
+       $messages{$id} = $text;
+
        print $OUTPUT $_;
     }