3 # gpinyin - European-like Chinese writing 'pinyin' into 'groff'
5 # Source file position: <groff-source>/contrib/gpinyin/gpinyin.pl
6 # Installed position: <prefix>/bin/gpinyin
8 # Copyright (C) 2014-2018 Free Software Foundation, Inc.
10 # Written by Bernd Warken <groff-bernd.warken-72@web.de>.
12 my $version = '1.0.4';
14 # This file is part of 'gpinyin', which is part of 'groff'.
16 # 'groff' is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 2 of the License, or
19 # (at your option) any later version.
21 # 'groff' is distributed in the hope that it will be useful, but
22 # WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 # General Public License for more details.
26 # You can find a copy of the GNU General Public License in the internet
27 # at <http://www.gnu.org/licenses/gpl-2.0.html>.
29 ########################################################################
35 # temporary dir and files
36 use File::Temp qw/ tempfile tempdir /;
38 # needed for temporary dir
41 # for 'copy' and 'move'
44 # for fileparse, dirname and basename
47 # current working directory
50 # $Bin is the directory where this script is located
54 ########################################################################
55 # system variables and exported variables
56 ########################################################################
58 $\ = "\n"; # final part for print command
60 ########################################################################
61 # read-only variables with double-@ construct
62 ########################################################################
64 our $File_split_env_sh;
68 my $before_make; # script before run of 'make'
71 $before_make = 1 if '@VERSION@' eq "${at}VERSION${at}";
75 my $file_gpinyin_test_pl;
79 my $gpinyin_source_dir = $FindBin::Bin;
80 $at_at{'BINDIR'} = $gpinyin_source_dir;
82 $gpinyin_libdir = '@gpinyin_dir@';
84 $at_at{'BINDIR'} = '@BINDIR@';
86 $gpinyin_libdir = '@gpinyin_dir@';
87 unshift(@INC, $gpinyin_libdir);
93 ########################################################################
95 ########################################################################
98 if ( /^(-h|--h|--he|--hel|--help)$/ ) {
99 print q(Usage for the 'gpinyin' program:);
100 print 'gpinyin [-] [--] [filespec...] normal file name arguments';
101 print 'gpinyin [-h|--help] gives usage information';
102 print 'gpinyin [-v|--version] displays the version number';
103 print q(This program is a 'groff' preprocessor that handles ) .
104 q(pinyin parts in 'roff' files.);
106 } elsif (/^(-v|--v|--ve|--ver|--vers|--versi|--versio|--version)$/) {
107 print q('gpinyin' version ) . $version;
113 ########################################################################
115 ########################################################################
117 my $pinyin_mode = 0; # not in Pinyin mode
119 my @output_n = # nroff
124 my @output_t = # troff
129 foreach (<>) { # get line from input
131 s/\s+$//; # remove final spaces
132 # &err('gpinyin: ' . $_);
134 my $line = $_; # with starting blanks
136 # .pinyin start or begin line
137 if ( $line =~ /^[.']\s*pinyin\s+(start|begin)$/ ) {
138 if ( $pinyin_mode ) {
139 # '.pinyin' was started twice, ignore
140 &err( q['.pinyin' starter was run several times] );
141 } else { # new pinyin start
147 # .pinyin stop or end line
148 if ( $line =~ /^[.']\s*pinyin\s+(stop|end)$/ ) {
149 if ( $pinyin_mode ) { # normal stop
151 &finish_pinyin_mode( \@output_n, \@output_t );
153 &err( 'gpinyin: there was a .pinyin stop without ' .
154 'being in pinyin mode' );
159 # now not a .pinyin line
162 if ( $pinyin_mode ) { # within Pinyin
163 my $starting_blanks = '';
164 $starting_blanks = $1 if ( s/^(s+)// ); # handle starting spaces
166 my %outline = &handle_line($starting_blanks, $line);
167 #&err('gpinyin outline n: ' . $outline{'n'} );
168 #&err('gpinyin outline t: ' . $outline{'t'} );
169 push @output_n, $outline{'n'};
170 push @output_t, $outline{'t'};
171 } else { # normal roff line, not within Pinyin
175 } # end of input line
178 ########################################################################
179 # end of file without stopping 'pinyin' mode
180 if ( $pinyin_mode ) {
181 &finish_pinyin_mode( \@output_n, \@output_t );
184 ########################################################################
188 ########################################################################