fb7b54ce0d3f93a91bfaaf17a8bfd9d5e8e6c373
[platform/upstream/groff.git] / src / roff / grog / grog.pl
1 #! /usr/bin/env perl
2 # grog - guess options for groff command
3 # Inspired by doctype script in Kernighan & Pike, Unix Programming
4 # Environment, pp 306-8.
5
6 # Source file position: <groff-source>/src/roff/grog/grog.pl
7 # Installed position: <prefix>/bin/grog
8
9 # Copyright (C) 1993-2014  Free Software Foundation, Inc.
10 # Written by James Clark, maintained by Werner Lemberg.
11 # Rewritten with Perl by Bernd Warken <groff-bernd.warken-72@web.de>.
12 # The macros for identifying the devices were taken from Ralph
13 # Corderoy's `grog.sh' from 2006.
14
15 # This file is part of `grog', which is part of `groff'.
16
17 # `groff' is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by
19 # the Free Software Foundation, either version 2 of the License, or
20 # (at your option) any later version.
21
22 # `groff' is distributed in the hope that it will be useful, but
23 # WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25 # General Public License for more details.
26
27 # You should have received a copy of the GNU General Public License
28 # along with this program. If not, see
29 # <http://www.gnu.org/licenses/gpl-2.0.html>.
30
31 ########################################################################
32
33 require v5.6;
34
35 use warnings;
36 use strict;
37
38 # $Bin is the directory where this script is located
39 use FindBin;
40
41 my $before_make;        # script before run of `make'
42 {
43   my $at = '@';
44   $before_make = 1 if '@VERSION@' eq "${at}VERSION${at}";
45 }
46
47
48 our %at_at;
49 my $grog_dir;
50
51 if ($before_make) { # before installation
52   my $grog_source_dir = $FindBin::Bin;
53   $at_at{'BINDIR'} = $grog_source_dir;
54 # $grog_dir = $grog_source_dir;
55   $grog_dir = '.';
56   my $top = $grog_source_dir . '/../../../';
57   open FILE, '<', $top . 'VERSION' ||
58     die 'Could not open top file VERSION.';
59   my $version = <FILE>;
60   chomp $version;
61   close FILE;
62   open FILE, '<', $top . 'REVISION' ||
63     die 'Could not open top file REVISION.';
64   my $revision = <FILE>;
65   chomp $revision;
66   $at_at{'GROFF_VERSION'} = $version . '.' . $revision;
67 } else { # after installation}
68   $at_at{'GROFF_VERSION'} = '@VERSION@';
69   $at_at{'BINDIR'} = '@BINDIR@';
70   $grog_dir = '@grog_dir@';
71 } # before make
72
73 die "$grog_dir is not an existing directory;" unless -d $grog_dir;
74
75
76 #############
77 # import subs
78
79 unshift(@INC, $grog_dir);
80 require 'subs.pl';
81
82
83 ##########
84 # run subs
85
86 &handle_args();
87 &handle_file_ext(); # see $tmac_ext for gotten value
88 &handle_whole_files();
89 &make_groff_device();
90 &make_groff_preproc();
91 &make_groff_tmac_man_ms() || &make_groff_tmac_others();
92 &make_groff_line_rest();
93
94
95 1;
96 ########################################################################
97 ### Emacs settings
98 # Local Variables:
99 # mode: CPerl
100 # End: