summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-04-29 12:54:41 -0700
committerKevin McCarthy <kevin@8t8.us>2021-04-29 14:05:13 -0700
commitfdee288a986d37a69e7ecaef2ae28997e4b1d731 (patch)
tree0ad6c3945952239e7d070f01768fc6481bce6356 /doc
parent23b77a20df07f834682cb456984c52940461cd74 (diff)
Modify makedoc.pl to read sort maps for the default value.
Use the map tables to print out a correct default value for sort types. Remove the unneeded SORT_ALPHA type, for $sort_browser documentation, since we can do the lookup now.
Diffstat (limited to 'doc')
-rw-r--r--doc/makedoc.pl83
1 files changed, 75 insertions, 8 deletions
diff --git a/doc/makedoc.pl b/doc/makedoc.pl
index fa2b9359..98d7515d 100644
--- a/doc/makedoc.pl
+++ b/doc/makedoc.pl
@@ -127,14 +127,17 @@ my %quad2human = ("MUTT_YES" => "yes",
my %bool2human = ("1" => "yes",
"0" => "no");
+my %sort_maps = ();
# prototypes
# to update:
# M-1 M-! grep '^sub' makedoc.pl
sub makedoc();
sub flush_doc($);
+sub handle_sort_maps();
+sub handle_sort_map($);
sub handle_confline($);
-sub pretty_default($$);
+sub pretty_default($$$);
sub string_unescape($);
sub string_escape($);
sub print_confline($$$);
@@ -176,7 +179,6 @@ makedoc();
sub makedoc() {
my $line;
- my $lineno = 0;
my $active = 0;
my $docstat = $D_INIT;
@@ -190,6 +192,9 @@ sub makedoc() {
$docstat = flush_doc($docstat);
$active = 0;
}
+ elsif ($line eq '/*+sort+*/') {
+ handle_sort_maps();
+ }
elsif ($active) {
if (($line =~ /^\/\*\*/) || ($line =~ /^\*\*/)) {
$line =~ s/^[\/*]+\s*//;
@@ -237,12 +242,62 @@ sub flush_doc($) {
}
####################
+# Sort maps handling
+####################
+
+sub handle_sort_maps() {
+ my $line;
+ my $mapname;
+
+ while ($line = <STDIN>) {
+ chomp($line);
+ $line =~ s/^\s+//;
+
+ if ($line eq '/*-sort-*/') {
+ return;
+ }
+
+ if (($line =~ /^const\s+struct\s+mapping_t/) &&
+ ($line =~ /\/\*\s*(\S+)\s*\*\/\s*$/)) {
+ $mapname = $1;
+ handle_sort_map($mapname);
+ }
+ }
+}
+
+sub handle_sort_map($) {
+ my ($mapname) = @_;
+ my $line;
+ my $name;
+ my $value;
+
+ $sort_maps{$mapname} = {};
+
+ while ($line = <STDIN>) {
+ chomp($line);
+ $line =~ s/^\s+//;
+
+ if ($line =~ /^{\s*"(\S+)"\s*,\s*(\S+)\s*}/) {
+ $name = $1;
+ $value = $2;
+ if (!exists $sort_maps{$mapname}->{$value}) {
+ $sort_maps{$mapname}->{$value} = $name;
+ }
+ }
+ elsif ($line =~ /^{\s*NULL/) {
+ return;
+ }
+ }
+}
+
+####################
# Confline handling
####################
sub handle_confline($) {
my ($line) = @_;
+ my $subtype = "";
my $localized = 0;
my ($name, $type, $flags, $data, $val) = split(/\s*,\s*/, $line, 5);
$name =~ s/"//g;
@@ -252,7 +307,8 @@ sub handle_confline($) {
$type = "DT_L10N_STR";
}
else {
- $type =~ s/\|.*//;
+ $type =~ s/\|(.*)//;
+ $subtype = $1;
}
$val =~ s/^{\s*\.[lp]\s*=\s*"?//;
@@ -266,13 +322,13 @@ sub handle_confline($) {
# (?<!..) is a zero-width negative lookbehind assertion, asserting
# the first quote isn't preceded by a backslash
$val =~ s/(?<!\\)"\s+"//g;
- $val = pretty_default($type, $val);
+ $val = pretty_default($type, $subtype, $val);
print_confline($name, $type, $val);
}
-sub pretty_default($$) {
- my ($type, $val) = @_;
+sub pretty_default($$$) {
+ my ($type, $subtype, $val) = @_;
if ($type eq "DT_QUAD") {
$val = $quad2human{$val};
@@ -281,11 +337,22 @@ sub pretty_default($$) {
$val = $bool2human{$val};
}
elsif ($type eq "DT_SORT") {
+ my $newval;
+
if ($val !~ /^SORT_/) {
die "Expected SORT_ prefix instead of $val\n";
}
- $val =~ s/^SORT_//;
- $val = lc $val;
+ if (!$subtype) {
+ $subtype = $type;
+ }
+ if (!$sort_maps{$subtype}) {
+ die "Unknown SORT type $subtype\n";
+ }
+ $newval = $sort_maps{$subtype}->{$val};
+ if (!$newval) {
+ die "Unknown SORT value $val for map $subtype\n"
+ }
+ $val = $newval;
}
elsif ($type eq "DT_MAGIC") {
if ($val !~ /^MUTT_/) {