[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 09/11: [grog]: Refactor macro package inference.
From: |
G. Branden Robinson |
Subject: |
[groff] 09/11: [grog]: Refactor macro package inference. |
Date: |
Sat, 31 Jul 2021 10:36:30 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 958d997c2e069b193efe2f0990848ff21a8bc848
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Jul 31 18:49:51 2021 +1000
[grog]: Refactor macro package inference.
* src/utils/grog/grog.pl: Refactor macro package inference.
- Stop manually populating `Groff` hash. (It's itching for a rename.)
- Stop calling now-dead subroutine `infer_macro_packages`.
(do_line): Always store the names of all macros called to the `Groff`
hash, incrementing it. Now it's a proper scoreboard. Populate
`inferred_main_package` from here upon encountering characteristic
(i.e., uniquely named) macros of each package. Bug fix: drop "SP"
from list of characteristic mom(7) macros; it's shared with mm(7).
(infer_man_or_ms_package): Update comment. Return 0 (false) if
document appears to be "raw", using no full-service macro package.
(infer_macro_packages): Delete; do_line() does this work.
Also update Vim modeline; cindent works better.
---
ChangeLog | 17 ++++++++
src/utils/grog/grog.pl | 103 +++++++++----------------------------------------
2 files changed, 35 insertions(+), 85 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 05238df..de6c4d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2021-07-31 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * src/utils/grog/grog.pl: Refactor macro package inference.
+ - Stop manually populating `Groff` hash. (It's itching for a
+ rename.)
+ - Stop calling now-dead subroutine `infer_macro_packages`.
+ (do_line): Always store the names of all macros called to the
+ `Groff` hash, incrementing it. Now it's a proper scoreboard.
+ Populate `inferred_main_package` from here upon encountering
+ characteristic (i.e., uniquely named) macros of each package.
+ Bug fix: drop "SP" from list of characteristic mom(7) macros;
+ it's shared with mm(7).
+ (infer_man_or_ms_package): Update comment. Return 0 (false) if
+ document appears to be "raw", using no full-service macro
+ package.
+ (infer_macro_packages): Delete; do_line() does this work.
+
+2021-07-31 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* src/utils/grog/grog.pl: Refactor preprocessor inference.
- Add new list, `inferred_preprocessor`.
- Drop preprocessor-related keys from `Groff` hash.
diff --git a/src/utils/grog/grog.pl b/src/utils/grog/grog.pl
index e6cad5b..c083982 100644
--- a/src/utils/grog/grog.pl
+++ b/src/utils/grog/grog.pl
@@ -108,14 +108,7 @@ my @macro_man_or_ms = ('B', 'I', 'BI',
'IP', 'LP', 'PP');
my %user_macro;
-my %Groff =
- (
- # for mdoc and mdoc-old
- # .Oo and .Oc for modern mdoc, only .Oo for mdoc-old
- 'Oo' => 0, # mdoc and mdoc-old
- 'Oc' => 0, # mdoc
- 'Dd' => 0, # mdoc
- ); # end of %Groff
+my %Groff = ();
my @standard_macro = ();
push(@standard_macro, @macro_ms, @macro_man, @macro_man_or_ms);
@@ -393,6 +386,7 @@ sub do_line {
return if (grep(/^\Q$command\E$/, @request));
$have_seen_first_macro_call = 1;
+ $Groff{$command}++;
######################################################################
@@ -400,34 +394,16 @@ sub do_line {
######################################################################
##########
- # modern mdoc
-
- if ( $command =~ /^(Dd)$/ ) {
- $Groff{'Dd'}++; # for modern mdoc
- return;
- }
-
- # In the old version of -mdoc 'Oo' is a toggle, in the new it's
- # closed by 'Oc'.
- if ( $command =~ /^Oc$/ ) {
- $Groff{'Oc'}++; # only for modern mdoc
- return;
- }
-
-
- ##########
- # old and modern mdoc
-
- if ( $command =~ /^Oo$/ ) {
- $Groff{'Oo'}++; # for mdoc and mdoc-old
+ # mdoc
+ if ( $command =~ /^Dd$/ ) {
+ $inferred_main_package = 'doc';
return;
}
-
##########
# old mdoc
if ( $command =~ /^(Tp|Dp|De|Cx|Cl)$/ ) {
- $Groff{'mdoc-old'}++; # true for old mdoc
+ $inferred_main_package = 'doc-old';
return;
}
@@ -438,7 +414,7 @@ sub do_line {
[ilnp]p|
sh
)$/x ) {
- $Groff{'me'}++; # for me
+ $inferred_main_package = 'e';
return;
}
@@ -455,16 +431,18 @@ sub do_line {
PH|
SA
)$/x ) {
- $Groff{'mm'}++; # for mm and mmse
if ( $command =~ /^LO$/ ) {
if ( $args =~ /^(DNAMN|MDAT|BIL|KOMP|DBET|BET|SIDOR)/ ) {
- $Groff{'mmse'}++; # for mmse
+ $inferred_main_package = 'mse';
+ return;
}
} elsif ( $command =~ /^LT$/ ) {
if ( $args =~ /^(SVV|SVH)/ ) {
- $Groff{'mmse'}++; # for mmse
+ $inferred_main_package = 'mse';
+ return;
}
}
+ $inferred_main_package = 'm';
return;
}
@@ -495,20 +473,15 @@ sub do_line {
PAPER|
PRINTSTYLE|
PT_SIZE|
- SP|
START|
T_MARGIN|
TITLE|
TOC|
TOC_AFTER_HERE
)$/x ) {
- $Groff{'mom'}++; # for mom
+ $inferred_main_package = 'om';
return;
}
-
- for my $key (@standard_macro) {
- $Groff{$key}++ if ($command eq $key);
- }
} # do_line()
my @m = ();
@@ -564,8 +537,9 @@ sub infer_man_or_ms_package {
}
if (!$ms_score && !$man_score) {
- # The input may be a "raw" roff document; this is not a problem.
- # Do nothing special.
+ # The input may be a "raw" roff document; this is not a problem,
+ # but it does mean no package was inferred.
+ return 0;
} elsif ($ms_score == $man_score) {
# If there was no TH call, it's not a (valid) man(7) document.
if (!$Groff{'TH'}) {
@@ -585,47 +559,6 @@ sub infer_man_or_ms_package {
} # infer_man_or_ms_package()
-# Return true (1) if a main/full-service/exclusive package is inferred.
-sub infer_macro_packages {
- # mdoc
- if ( ( $Groff{'Oo'} && $Groff{'Oc'} ) || $Groff{'Dd'} ) {
- $Groff{'Oc'} = 0;
- $Groff{'Oo'} = 0;
- $inferred_main_package = 'doc';
- return 1; # true
- }
- if ( $Groff{'mdoc-old'} || $Groff{'Oo'} ) {
- $inferred_main_package = 'doc';
- return 1; # true
- }
-
- # me
- if ( $Groff{'me'} ) {
- $inferred_main_package = 'e';
- return 1; # true
- }
-
- # mm and mmse
- if ( $Groff{'mm'} ) {
- $inferred_main_package = 'm';
- return 1; # true
- }
- # XXX: Is this necessary? mmse "mso"s mm, but we probably already
- # detected mm macro calls anyway. --GBR
- if ( $Groff{'mmse'} ) { # Swedish mm
- return 1; # true
- }
-
- # mom
- if ( $Groff{'mom'} ) {
- $inferred_main_package = 'om';
- return 1; # true
- }
-
- return 0;
-} # infer_macro_packages()
-
-
sub construct_command {
my $file_args_included; # file args now only at 1st preproc
unshift @command, 'groff';
@@ -729,7 +662,7 @@ $groff_version = '@VERSION@' unless
($in_unbuilt_source_tree);
if ($have_any_valid_arguments) {
&infer_preprocessors();
- &infer_macro_packages() || &infer_man_or_ms_package();
+ &infer_man_or_ms_package() unless ($inferred_main_package);
&construct_command();
}
@@ -741,4 +674,4 @@ exit 0;
# fill-column: 72
# mode: CPerl
# End:
-# vim: set autoindent noexpandtab shiftwidth=2 softtabstop=2 textwidth=72:
+# vim: set cindent noexpandtab shiftwidth=2 softtabstop=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 09/11: [grog]: Refactor macro package inference.,
G. Branden Robinson <=