gbranden pushed a commit to branch master
in repository groff.

commit 38b27aeaa49e24de2c90af865e14b2c45c30c0b0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Jun 6 00:16:53 2022 -0500

    [gropdf]: Validate `DESC` file as grops(1) does.
    
    * src/devices/gropdf/gropdf.pl (LoadDesc): Validate device description
      file for essential directives and acceptable values as grops(1) does.
---
 ChangeLog                    |  6 ++++++
 src/devices/gropdf/gropdf.pl | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index c8320535..fe87a4b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-06-06  G. Branden Robinson <[email protected]>
+
+       * src/devices/gropdf/gropdf.pl (LoadDesc): Validate device
+       description file for essential directives and acceptable values
+       as grops(1) does.
+
 2022-06-04  G. Branden Robinson <[email protected]>
 
        [troff, grohtml, grops, grotty]: Update wording of diagnostic
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 9002cd6e..a230eb3c 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -689,6 +689,32 @@ sub LoadDesc
        Die("device description file 'DESC' missing mandatory directive"
            . " '$directive'") if !exists($desc{$directive});
     }
+
+    foreach my $directive ('unitwidth', 'res', 'sizescale')
+    {
+       my $val=$desc{$directive};
+       Die("device description file 'DESC' directive '$directive'"
+           . " value must be positive; got '$val'")
+           if ($val !~ m/^\d+$/ or $val <= 0);
+    }
+
+    if (exists($desc{'hor'}))
+    {
+       my $hor=$desc{'hor'};
+       Die("device horizontal motion quantum must be 1, got '$hor'")
+           if ($hor != 1);
+    }
+
+    if (exists($desc{'vert'}))
+    {
+       my $vert=$desc{'vert'};
+       Die("device vertical motion quantum must be 1, got '$vert'")
+           if ($vert != 1);
+    }
+
+    my ($res,$ss)=($desc{'res'},$desc{'sizescale'});
+    Die("device resolution must be a multiple of 72*sizescale, got"
+       . " '$res' ('sizescale'=$ss)") if (($res % ($ss * 72)) != 0);
 }
 
 sub rad  { $_[0]*3.14159/180 }

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to