summaryrefslogtreecommitdiff
path: root/src/roff/groff/read_groff_options.pl
blob: a403fbe71b20b1e08eedff43c1d42fa5903d9990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#! /usr/bin/env perl

use strict;
use warnings;
use diagnostics;


########################################################################
# Legalese
########################################################################

use constant LASTUPDATE => '25 Apr 2013'; # date of last update

### The following constants `LICENSE[12]' are the license for this
### file using `GPL' >= 3

use constant LICENSE1 => q*
read_groff_options.pl - generate lines with the `groff' options.

Source file position: <groff-source>/src/roff/groff/read_groff_options.pl
*;

use constant LICENSE2 => q*
Copyright (C) 2013
  Free Software Foundation, Inc.
  Written by Bernd Warken <groff-bernd.warken-72@web.de>.

This file is part of `groff'.

  `GNU groff' is free software: you can redistribute it and/or modify it
under the terms of the `GNU General Public License' as published by the
`Free Software Foundation', either version 3 of the License, or (at your
option) any later version.

  `GNU groff' is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the `GNU
General Public License' for more details.

  You should have received a copy of the 'GNU General Public License`
along with `groff', see the files `COPYING' and `LICENSE' in the top
directory of the `groff' source package.  If not, see
<http://www.gnu.org/licenses/>.*;


use constant DOCUMENTATION => q*
  This file is not installed, but is used to generate output
containing information of the `groff' options, which are read from the
function `synopsis' of the file `groff.cpp' in
`<groff-source>/src/roff/groff/'.  The output is something like:

groff_noarg: CENRSUVXZabceghijklpstvz
groff_witharg: DFIKLMPTWdfmnorw
*;


##### end legalese

$\ = "\n";    # adds newline at each print
$/ = "\n";    # newline separates input
$| = 1;       # flush after each print or write command


my $file = undef;
{
    use constant FALSE => 0;
    use constant TRUE => 1;

    use File::Spec qw[];

    my $arg = shift;
    my $cpp = 'groff.cpp';

    if ( defined($arg) ) {
	if ( -d $arg ) {
	    $file = File::Spec->catfile($arg, $cpp);
	    $file = undef unless ( -f $file );;
	}
	if ( -f $arg && $arg =~ /groff.cpp$/ ) {
	    $file = $arg;
	}
    } else { # no argument
	if ( -f $cpp ) {
	    $file = $cpp;
	}
    }
    die "read_groff_options.pl: needs a directory with $cpp as argument: $!."
	unless ( defined($file) );

}

# $file is cpp-file

my @lines = ();
{
    open(FH, '<', $file);
    my $start_synopsis = FALSE;
    foreach ( <FH> ) {
	chomp;
	if ( /^void\s+synopsis\(/ ) {
	    $start_synopsis = TRUE;
	    next;
	}
	if ( $start_synopsis ) {
	    if ( /\[-/ ) {
		s/\\n//g;
		push @lines, $_;
		$start_synopsis = FALSE;
	    }
	    next;
	}
	if ( @lines ) {
	    if ( /\[-/ ) {
		s/\\n//g;
		push @lines, $_;
		next;
	    } else {
		last;
	    }
	}
	next;
    }
}

{
    my $noarg = '';
    my $witharg = '';
    my $first = shift @lines;
    chomp $first;
    $first =~ s/^[^-]*-(\w+)\]\s*//;
    $noarg = $1;
    unshift @lines, $first;

    foreach ( @lines ) {
	my $s = $_;
	while ( $s =~ /-/ ) {
	    $s =~ s/^[^-]*-(\w)\w+]//;
	    $witharg .= $1;
	}
    }

    sub sort_opts {
	my @opts = split '', shift;
	@opts = sort @opts;
	return join '', @opts;
    }

    my $res = &sort_opts($noarg);
    print 'groff_noarg: ' . $res;

    $res = &sort_opts($witharg);
    print 'groff_witharg: ' . $res;
}

print '';
print '#' x 30 . ' License ' . '#' x 30;
print q*
groff_options.info - 2 lines with the `groff' options.

This file is generated by the run of `make' in the `groff' source by
the file <groff-source>/src/roff/groff/read_groff_options.pl.

This file `groff_options.info' is installed in the `groff libdir'.*;

print LICENSE2;