mirror of https://git.code.sf.net/p/isync/isync
Browse Source
this is a lot more legible, and makes it possible to insert values in the middle without churn. i didn't find a way to do this with the pre-processor, so we now have another code generator. we now use the $< make variable, which requires gmake on netbsd < 9.0, and possibly other systems with an ancient make.wip/maildir-path-under-inbox
Oswald Buddenhagen
3 years ago
10 changed files with 191 additions and 86 deletions
@ -0,0 +1,55 @@
|
||||
#!/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); |
||||
my $pfx; |
||||
for my $e (@vals) { |
||||
if (!defined($pfx)) { |
||||
$pfx = ($e =~ /^([A-Z]+_)/) ? $1 : ""; |
||||
} elsif (length($pfx)) { |
||||
$pfx = "" if ((($e =~ /^([A-Z]+_)/) ? $1 : "") ne $pfx); |
||||
} |
||||
} |
||||
my $bit = 1; |
||||
my $bitn = 0; |
||||
for my $e (@vals) { |
||||
my $bits = ($e =~ s/\((\d+)\)$//) ? $1 : 1; |
||||
if ($bits != 1) { |
||||
print "#define $e(b) ($bit << (b))\n"; |
||||
} else { |
||||
print "#define $e $bit\n"; |
||||
} |
||||
$bit <<= $bits; |
||||
$bitn += $bits; |
||||
} |
||||
if (length($pfx)) { |
||||
print "#define ${pfx}_NUM_BITS $bitn\n"; |
||||
} |
||||
print "\n"; |
||||
$in_enum = 0; |
||||
} else { |
||||
$conts .= $_; |
||||
} |
||||
} else { |
||||
if (/^BIT_ENUM\($/) { |
||||
$conts = ""; |
||||
$in_enum = 1; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue