2022-05-31 12:05:28 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# SPDX-FileCopyrightText: 2022 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#
|
|
|
|
# mbsync - mailbox synchronizer
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my $in_enum = 0;
|
|
|
|
my $conts;
|
|
|
|
while (<>) {
|
|
|
|
s,\s*(?://.*)?$,,;
|
|
|
|
if ($in_enum) {
|
|
|
|
if (/^\)$/) {
|
|
|
|
$conts =~ s/\s//g;
|
|
|
|
$conts =~ s/,$//;
|
|
|
|
my @vals = split(/,/, $conts);
|
2021-12-23 16:43:59 +00:00
|
|
|
my ($pfx, $pfx1);
|
2022-05-31 12:05:28 +00:00
|
|
|
for my $e (@vals) {
|
|
|
|
if (!defined($pfx)) {
|
2021-12-23 16:43:59 +00:00
|
|
|
$pfx1 = $pfx = ($e =~ /^([A-Z]+_)/) ? $1 : "";
|
2022-05-31 12:05:28 +00:00
|
|
|
} elsif (length($pfx)) {
|
|
|
|
$pfx = "" if ((($e =~ /^([A-Z]+_)/) ? $1 : "") ne $pfx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $bit = 1;
|
|
|
|
my $bitn = 0;
|
2021-12-23 16:43:59 +00:00
|
|
|
my (@names, @nameos);
|
|
|
|
my $nameo = 0;
|
2022-05-31 12:05:28 +00:00
|
|
|
for my $e (@vals) {
|
|
|
|
my $bits = ($e =~ s/\((\d+)\)$//) ? $1 : 1;
|
2021-12-23 16:43:59 +00:00
|
|
|
my $n = substr($e, length($pfx));
|
2022-05-31 12:05:28 +00:00
|
|
|
if ($bits != 1) {
|
2021-12-23 16:43:59 +00:00
|
|
|
die("Unsupported field size $bits\n") if ($bits != 2);
|
2022-05-31 12:05:28 +00:00
|
|
|
print "#define $e(b) ($bit << (b))\n";
|
2021-12-23 16:43:59 +00:00
|
|
|
push @names, "F-".$n, "N-".$n;
|
|
|
|
my $nl = length($n) + 3;
|
|
|
|
push @nameos, $nameo, $nameo + $nl;
|
|
|
|
$nameo += $nl * 2;
|
2022-05-31 12:05:28 +00:00
|
|
|
} else {
|
|
|
|
print "#define $e $bit\n";
|
2021-12-23 16:43:59 +00:00
|
|
|
push @names, $n;
|
|
|
|
push @nameos, $nameo;
|
|
|
|
$nameo += length($n) + 1;
|
2022-05-31 12:05:28 +00:00
|
|
|
}
|
|
|
|
$bit <<= $bits;
|
|
|
|
$bitn += $bits;
|
|
|
|
}
|
|
|
|
if (length($pfx)) {
|
|
|
|
print "#define ${pfx}_NUM_BITS $bitn\n";
|
|
|
|
}
|
2021-12-23 16:43:59 +00:00
|
|
|
if (length($pfx1)) {
|
|
|
|
print "#define ${pfx1}_STRINGS \"".join("\\0", @names)."\"\n";
|
|
|
|
print "#define ${pfx1}_OFFSETS ".join(", ", @nameos)."\n";
|
|
|
|
}
|
2022-05-31 12:05:28 +00:00
|
|
|
print "\n";
|
|
|
|
$in_enum = 0;
|
|
|
|
} else {
|
|
|
|
$conts .= $_;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (/^BIT_ENUM\($/) {
|
|
|
|
$conts = "";
|
|
|
|
$in_enum = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|