build-system: add Markdown support to parse-descriptor.pl

This cleans up the script a little and makes it more flexible to add other
output formats; and adds Markdown as one such format.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-02-09 10:31:26 -08:00
parent 5085793d9a
commit 3710d44f81

View file

@ -21,10 +21,26 @@ open(STDOUT, ">", $outfi) || croak "can't open $outfi: $!";
my $commentStart = "# ";
my $commentEnd = "";
my $first_mod_txt = ": ";
my $next_mod_txt = ", ";
my $next_vendor_txt = "\n";
my $first_vendor_txt = "";
if ($type eq "html") {
$commentStart = "<!-- ";
$commentEnd = " -->";
$first_mod_txt = "</dt><dd><ul>\n\t <li>";
$next_vendor_txt = "</li></ul>\n </dd>\n <dt>";
$first_vendor_txt = "<dl><dt>";
} elsif ($type eq "md" ) {
$commentStart = "[//]: # '";
$commentEnd = "'";
$first_mod_txt = ":\n- ";
$next_mod_txt = "\n- ";
$next_vendor_txt = "\n\n## ";
$first_vendor_txt = "\n\n## ";
}
printf("%s This file is automatically generated, please edit scripts/parse-descriptor.pl%s\n", $commentStart, $commentEnd);
my $lastVend = "";
@ -39,37 +55,19 @@ my @sortedDescriptors = sort @descriptors;
foreach (@sortedDescriptors) {
($vend, $mod) = split(',', $_);
next if ($vend eq $lastVend && $mod eq $lastMod);
if ($type eq "html") {
if ($vend eq $lastVend) {
printf(", %s", $mod);
} else {
if ($lastVend lt "Seabaer" && $vend gt "Seabaer") {
printf("</li></ul>\n </dd>\n <dt>Seabaer</dt><dd><ul>\n\t <li>T1, H3, HUDC");
}
if ($lastVend lt "Uemis" && $vend gt "Uemis") {
printf("</li></ul>\n </dd>\n <dt>Uemis</dt><dd><ul>\n\t <li>Zürich SDA");
}
if ($lastVend eq "") {
printf("<dl><dt>%s</dt><dd><ul>\n\t <li>%s", $vend, $mod);
} else {
printf("</li></ul>\n </dd>\n <dt>%s</dt><dd><ul>\n\t <li>%s", $vend, $mod);
}
}
if ($vend eq $lastVend) {
printf("%s%s", $next_mod_txt, $mod);
} else {
if ($vend eq $lastVend) {
printf(", %s", $mod);
if ($lastVend lt "Seabaer" && $vend gt "Seabaer") {
printf("%s%s%s%s", $next_vendor_txt, "Seabaer", $first_mod_txt, "T1, H3, HUDC");
}
if ($lastVend lt "Uemis" && $vend gt "Uemis") {
printf("%s%s%s%s", $next_vendor_txt, "Uemis", $first_mod_txt, "Zürich SDA");
}
if ($lastVend eq "") {
printf("%s%s%s%s", $first_vendor_txt, $vend, $first_mod_txt, $mod);
} else {
if ($lastVend lt "Seabaer" && $vend gt "Seabaer") {
printf("\nSeabaer: T1, H3, HUDC");
}
if ($lastVend lt "Uemis" && $vend gt "Uemis") {
printf("\nUemis: Zürich SDA");
}
if ($lastVend eq "") {
printf("%s: %s", $vend, $mod);
} else {
printf("\n%s: %s", $vend, $mod);
}
printf("%s%s%s%s", $next_vendor_txt, $vend, $first_mod_txt, $mod);
}
}
$lastVend = $vend;