forked from sarabander/sicp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
texi2any
executable file
·1392 lines (1256 loc) · 51 KB
/
texi2any
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/perl
# texi2any: Texinfo converter.
#
# Copyright 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# Original author: Patrice Dumas <pertusus@free.fr>
# Parts (also from Patrice Dumas) come from texi2html.pl or texi2html.init.
# for POSIX::setlocale and File::Spec
require 5.00405;
use strict;
# for file names portability
use File::Spec;
# to determine the path separator and null file
use Config;
# for dirname and fileparse
use File::Basename;
#use Cwd;
use Getopt::Long qw(GetOptions);
# for carp
#use Carp;
Getopt::Long::Configure("gnu_getopt");
# This big BEGIN block deals with finding modules and
# some dependencies that we ship
# * in source or
# * installed or
# * installed relative to the script
BEGIN
{
# emulate -w
$^W = 1;
my ($real_command_name, $command_directory, $command_suffix)
= fileparse($0, '.pl');
my $datadir = '/usr/local/share';
my $package = 'texinfo';
my $updir = File::Spec->updir();
my $texinfolibdir;
my $lib_dir;
# in-source run
if (($command_suffix eq '.pl' and !(defined($ENV{'TEXINFO_DEV_SOURCE'})
and $ENV{'TEXINFO_DEV_SOURCE'} eq 0)) or $ENV{'TEXINFO_DEV_SOURCE'}) {
if (defined($ENV{'top_srcdir'})) {
$texinfolibdir = File::Spec->catdir($ENV{'top_srcdir'}, 'tp');
} else {
$texinfolibdir = $command_directory;
}
$lib_dir = File::Spec->catdir($texinfolibdir, 'maintain');
unshift @INC, $texinfolibdir;
} elsif ($datadir ne '@' .'datadir@' and $package ne '@' . 'PACKAGE@'
and $datadir ne '') {
$texinfolibdir = File::Spec->catdir($datadir, $package);
# try to make package relocatable, will only work if standard relative paths
# are used
if (! -f File::Spec->catfile($texinfolibdir, 'Texinfo', 'Parser.pm')
and -f File::Spec->catfile($command_directory, $updir, 'share',
'texinfo', 'Texinfo', 'Parser.pm')) {
$texinfolibdir = File::Spec->catdir($command_directory, $updir,
'share', 'texinfo');
}
$lib_dir = $texinfolibdir;
unshift @INC, $texinfolibdir;
}
# '@USE_EXTERNAL_LIBINTL @ and similar are substituted in the
# makefile using values from configure
if (defined($texinfolibdir)) {
if ('no' ne 'yes') {
unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'libintl-perl', 'lib'));
}
if ('no' ne 'yes') {
unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'Unicode-EastAsianWidth', 'lib'));
}
if ('no' ne 'yes') {
unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'Text-Unidecode', 'lib'));
}
}
}
use lib 'lib'; # use modified version of HTML.pm in directory 'lib' (A.R)
use Texinfo::Convert::Texinfo;
use Texinfo::Parser;
use Texinfo::Structuring;
use Texinfo::Convert::Info;
use Texinfo::Convert::HTML;
use Texinfo::Convert::TexinfoXML;
use Texinfo::Convert::TexinfoSXML;
use Texinfo::Convert::DocBook;
use Texinfo::Convert::TextContent;
use Texinfo::Convert::PlainTexinfo;
use Texinfo::Convert::IXINSXML;
use DebugTexinfo::DebugCount;
use DebugTexinfo::DebugTree;
my ($real_command_name, $command_directory, $command_suffix)
= fileparse($0, '.pl');
# this associates the command line options to the arrays set during
# command line parsing.
my @css_files = ();
my @css_refs = ();
my $cmdline_options = { 'CSS_FILES' => \@css_files,
'CSS_REFS' => \@css_refs };
# determine the path separators
my $path_separator = $Config{'path_sep'};
$path_separator = ':' if (!defined($path_separator));
my $quoted_path_separator = quotemeta($path_separator);
# Paths and file names
my $curdir = File::Spec->curdir();
my $updir = File::Spec->updir();
# set by configure, prefix for the sysconfdir and so on
# This could be used in the eval
my $prefix = '/usr/local';
my $datarootdir;
my $sysconfdir;
my $pkgdatadir;
my $datadir;
my $fallback_prefix = File::Spec->catdir(File::Spec->rootdir(), 'usr', 'local');
# We need to eval as $prefix has to be expanded. However when we haven't
# run configure @sysconfdir will be expanded as an array, thus we verify
# whether configure was run or not
if ('/usr/local/etc' ne '@' . 'sysconfdir@') {
$sysconfdir = eval '"/usr/local/etc"';
} else {
$sysconfdir = File::Spec->catdir($fallback_prefix, 'etc');
}
if ('/usr/local/share' ne '@' . 'datarootdir@') {
$datarootdir = eval '"/usr/local/share"';
} else {
$datarootdir = File::Spec->catdir($fallback_prefix, 'share');
}
if ('/usr/local/share' ne '@' . 'datadir@' and 'texinfo' ne '@' . 'PACKAGE@') {
$datadir = eval '"/usr/local/share"';
my $package = 'texinfo';
$pkgdatadir = File::Spec->catdir($datadir, $package);
} else {
$datadir = File::Spec->catdir($fallback_prefix, 'share');
$pkgdatadir = File::Spec->catdir($datadir, 'texinfo');
}
# work-around in case libintl-perl do not do it itself
# see http://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable
if ((defined($ENV{"LC_ALL"}) and $ENV{"LC_ALL"} =~ /^(C|POSIX)$/)
or (defined($ENV{"LANG"}) and $ENV{"LANG"} =~ /^(C|POSIX)$/)) {
delete $ENV{"LANGUAGE"} if defined($ENV{"LANGUAGE"});
}
#my $messages_textdomain = 'texinfo';
my $messages_textdomain = 'texinfo';
$messages_textdomain = 'texinfo' if ($messages_textdomain eq '@'.'PACKAGE@');
my $strings_textdomain = 'texinfo' . '_document';
$strings_textdomain = 'texinfo_document'
if ($strings_textdomain eq '@'.'PACKAGE@' . '_document');
sub __($) {
my $msgid = shift;
return Locale::Messages::dgettext($messages_textdomain, $msgid);
}
sub __p($$) {
my $context = shift;
my $msgid = shift;
return Locale::Messages::dpgettext($messages_textdomain, $context, $msgid);
}
my $srcdir;
if (defined($ENV{'top_srcdir'})) {
$srcdir = File::Spec->catdir($ENV{'top_srcdir'}, 'tp');
} else {
$srcdir = $command_directory;
}
my $libsrcdir = File::Spec->catdir($srcdir, 'maintain');
# we want a reliable way to switch locale, so we don't use the system
# gettext.
Locale::Messages->select_package('gettext_pp');
#my @search_locale_dirs = ("$datadir/locale", (map $_ . '/LocaleData', @INC),
# qw (/usr/share/locale /usr/local/share/locale));
if (($command_suffix eq '.pl' and !(defined($ENV{'TEXINFO_DEV_SOURCE'})
and $ENV{'TEXINFO_DEV_SOURCE'} eq 0)) or $ENV{'TEXINFO_DEV_SOURCE'}) {
# in case of build from the source directory, out of source build,
# this helps to locate the locales.
my $locales_dir_found = 0;
foreach my $locales_dir (
File::Spec->catdir($libsrcdir, $updir, 'LocaleData'),
File::Spec->catdir($curdir, 'LocaleData'),
File::Spec->catdir($updir, $updir, $updir, 'tp', 'LocaleData')) {
if (-d $locales_dir) {
Locale::Messages::bindtextdomain ($strings_textdomain, $locales_dir);
# the messages in this domain are not regenerated automatically,
# only when calling ./maintain/regenerate_perl_module_files.sh
Locale::Messages::bindtextdomain ($messages_textdomain, $locales_dir);
$locales_dir_found = 1;
last;
}
}
if (!$locales_dir_found) {
warn "Locales dir for document strings not found\n";
}
} else {
Locale::Messages::bindtextdomain ($strings_textdomain,
File::Spec->catdir($datadir, 'locale'));
Locale::Messages::bindtextdomain ($messages_textdomain,
File::Spec->catdir($datadir, 'locale'));
}
#Locale::Messages::bindtextdomain ($messages_textdomain,
# File::Spec->catdir($datadir, 'locale'));
# Version setting is complicated, because we cope with
# * script with configure values substituted or not
# * script shipped as part of texinfo or as a standalone perl module
# When shipped as a perl modules, $hardcoded_version is set to undef here
# by a sed one liner. The consequence is that configure.ac is not used
# to retrieve the version number.
# Otherwise this is only used as a safety value, and should never be used
# in practice as a regexp extracts the version from configure.ac.
my $hardcoded_version = "0.00-hardcoded";
# Version set in configure.ac
my $configured_version = '5.1';
if ($configured_version eq '@' . 'PACKAGE_VERSION@') {
# if not configured, and $hardcoded_version is set search for the version
# in configure.ac
if (defined($hardcoded_version)) {
if (open (CONFIGURE,
"< ".File::Spec->catfile($srcdir, $updir, 'configure.ac'))) {
while (<CONFIGURE>) {
if (/^AC_INIT\(\[[^\]]+\]\s*,\s*\[([^\]]+)\]\s*,/) {
$configured_version = "$1+dev"; # +dev to distinguish from installed
last;
}
}
close (CONFIGURE);
}
# This should never be used, but is a safety value
$configured_version = $hardcoded_version if (!defined($configured_version));
} else {
# used in the standalone perl module, as $hardcoded_version is undef
# and it should never be configured in that setup
$configured_version = $Texinfo::Parser::VERSION;
}
}
my $configured_package = 'texinfo';
$configured_package = 'Texinfo' if ($configured_package eq '@' . 'PACKAGE@');
my $configured_name = 'GNU Texinfo';
$configured_name = $configured_package
if ($configured_name eq '@' .'PACKAGE_NAME@');
my $configured_name_version = "$configured_name $configured_version";
my $configured_url = 'http://www.gnu.org/software/texinfo/';
$configured_url = 'http://www.gnu.org/software/texinfo/'
if ($configured_url eq '@' .'PACKAGE_URL@');
my $texinfo_dtd_version = '5.0';
# $hardcoded_version is undef for a standalone perl module
if ($texinfo_dtd_version eq '@' . 'TEXINFO_DTD_VERSION@') {
$texinfo_dtd_version = undef;
if (defined($hardcoded_version)) {
if (open (CONFIGURE,
"< ".File::Spec->catfile($srcdir, $updir, 'configure.ac'))) {
while (<CONFIGURE>) {
if (/^TEXINFO_DTD_VERSION=([0-9]\S*)/) {
$texinfo_dtd_version = "$1";
last;
}
}
close (CONFIGURE);
}
}
}
# Used in case it is not hardcoded in configure and for standalone perl module
$texinfo_dtd_version = $configured_version
if (!defined($texinfo_dtd_version));
# defaults for options relevant in the main program, not undef, and also
# defaults for all the converters.
# Other relevant options (undef) are NO_WARN FORCE OUTFILE
# Others are set in the converters (SHOW_MENU).
my $converter_default_options = {
'ERROR_LIMIT' => 100,
'TEXI2DVI' => 'texi2dvi',
'PACKAGE_VERSION' => $configured_version,
'PACKAGE' => $configured_package,
'PACKAGE_NAME' => $configured_name,
'PACKAGE_AND_VERSION' => $configured_name_version,
'PACKAGE_URL' => $configured_url,
'PROGRAM' => $real_command_name,
'TEXINFO_DTD_VERSION' => $texinfo_dtd_version,
};
# determine configuration directories.
my $conf_file_name = 'Config' ;
my $texinfo_htmlxref = 'htmlxref.cnf';
# directories for texinfo configuration files
my @language_config_dirs = File::Spec->catdir($curdir, '.texinfo');
push @language_config_dirs, File::Spec->catdir($ENV{'HOME'}, '.texinfo')
if (defined($ENV{'HOME'}));
push @language_config_dirs, File::Spec->catdir($sysconfdir, 'texinfo')
if (defined($sysconfdir));
push @language_config_dirs, File::Spec->catdir($datadir, 'texinfo')
if (defined($datadir));
my @texinfo_config_dirs = ($curdir, @language_config_dirs);
my @program_config_dirs;
my @program_init_dirs;
my $program_name = 'texi2any';
@program_config_dirs = ($curdir, File::Spec->catdir($curdir, ".$program_name"));
push @program_config_dirs, File::Spec->catdir($ENV{'HOME'}, ".$program_name")
if (defined($ENV{'HOME'}));
push @program_config_dirs, File::Spec->catdir($sysconfdir, $program_name)
if (defined($sysconfdir));
push @program_config_dirs, File::Spec->catdir($datadir, $program_name)
if (defined($datadir));
@program_init_dirs = @program_config_dirs;
foreach my $texinfo_config_dir (@language_config_dirs) {
push @program_init_dirs, File::Spec->catdir($texinfo_config_dir, 'init');
}
# Namespace for configuration
{
package Texinfo::Config;
#use Carp;
# passed from main program
my $cmdline_options;
my $default_options;
# used in main program
our $options = {};
sub _load_config($$) {
$default_options = shift;
$cmdline_options = shift;
#print STDERR "cmdline_options: ".join('|',keys(%$cmdline_options))."\n";
}
sub _load_init_file($) {
my $file = shift;
eval { require($file) ;};
my $e = $@;
if ($e ne '') {
main::document_warn(sprintf(main::__("error loading %s: %s\n"),
$file, $e));
}
}
# FIXME: maybe use an opaque return status that can be used to retrieve
# an error message?
sub set_from_init_file($$) {
my $var = shift;
my $value = shift;
if (!Texinfo::Common::valid_option($var)) {
# carp may be better, but infortunately, it points to the routine that
# loads the file, and not to the init file.
main::document_warn(sprintf(main::__("%s: unknown variable %s"),
'set_from_init_file', $var));
return 0;
} elsif (Texinfo::Common::obsolete_option($var)) {
main::document_warn(sprintf(main::__("%s: obsolete variable %s\n"),
'set_from_init_file', $var));
}
return 0 if (defined($cmdline_options->{$var}));
delete $default_options->{$var};
$options->{$var} = $value;
return 1;
}
sub set_from_cmdline($$) {
my $var = shift;
my $value = shift;
delete $options->{$var};
delete $default_options->{$var};
if (!Texinfo::Common::valid_option($var)) {
main::document_warn(sprintf(main::__("%s: unknown variable %s\n"),
'set_from_cmdline', $var));
return 0;
} elsif (Texinfo::Common::obsolete_option($var)) {
main::document_warn(sprintf(main::__("obsolete variable %s\n"),
'set_from_cmdline', $var));
}
$cmdline_options->{$var} = $value;
return 1;
}
# This also could get and set some @-command results.
# FIXME But it does not take into account what happens during conversion,
# for that something like $converter->get_conf(...) has to be used.
sub get_conf($) {
my $var = shift;
if (exists($cmdline_options->{$var})) {
return $cmdline_options->{$var};
} elsif (exists($options->{$var})) {
return $options->{$var};
} elsif (exists($default_options->{$var})) {
return $default_options->{$var};
} else {
return undef;
}
}
}
# back in main program namespace
# file: file name to locate. It can be a file path.
# directories: a reference on a array containing a list of directories to
# search the file in.
# all_files: if true collect all the files with that name, otherwise stop
# at first match.
sub locate_init_file($$$)
{
my $file = shift;
my $directories = shift;
my $all_files = shift;
if (File::Spec->file_name_is_absolute($file)) {
return $file if (-e $file and -r $file);
} else {
my @files;
foreach my $dir (@$directories) {
next unless (-d $dir);
my $possible_file = File::Spec->catfile($dir, $file);
if ($all_files) {
push (@files, $possible_file)
if (-e $possible_file and -r $possible_file);
} else {
return $possible_file if (-e $possible_file and -r $possible_file);
}
}
return @files if ($all_files);
}
return undef;
}
sub locate_and_load_init_file($$)
{
my $filename = shift;
my $directories = shift;
my $file = locate_init_file($filename, $directories, 0);
if (defined($file)) {
Texinfo::Config::_load_init_file($file);
} else {
document_warn(sprintf(__("could not read init file %s"), $filename));
}
}
# read initialization files
foreach my $file (locate_init_file($conf_file_name,
[ reverse(@program_config_dirs) ], 1)) {
Texinfo::Config::_load_init_file($file);
}
sub set_from_cmdline($$) {
return &Texinfo::Config::set_from_cmdline(@_);
}
sub set_from_init_file($$) {
return &Texinfo::Config::set_from_init_file(@_);
}
sub get_conf($) {
return &Texinfo::Config::get_conf(@_);
}
my @input_file_suffixes = ('.txi','.texinfo','.texi','.txinfo','');
my @texi2dvi_args = ();
my $format = 'info';
# this is the format associated with the output format, which is replaced
# when the output format changes. It may also be removed if there is the
# corresponding --no-ifformat.
my $default_expanded_format = [ $format ];
my @conf_dirs = ();
my @include_dirs = ();
my @prepend_dirs = ();
# options for all the files
my $parser_default_options = {'expanded_formats' => [],
'values' => {'txicommandconditionals' => 1},
'gettext' => \&__,
'pgettext' => \&__p,};
Texinfo::Config::_load_config($converter_default_options, $cmdline_options);
sub set_expansion($$) {
my $region = shift;
my $set = shift;
$set = 1 if (!defined($set));
if ($set) {
push @{$parser_default_options->{'expanded_formats'}}, $region
unless (grep {$_ eq $region} @{$parser_default_options->{'expanded_formats'}});
} else {
@{$parser_default_options->{'expanded_formats'}} =
grep {$_ ne $region} @{$parser_default_options->{'expanded_formats'}};
@{$default_expanded_format}
= grep {$_ ne $region} @{$default_expanded_format};
}
}
my $format_from_command_line = 0;
my %format_command_line_names = (
'xml' => 'texinfoxml',
);
my %formats_table = (
'info' => {
'nodes_tree' => 1,
'floats' => 1,
'converter' => sub{Texinfo::Convert::Info->converter(@_)},
},
'plaintext' => {
'nodes_tree' => 1,
'floats' => 1,
'converter' => sub{Texinfo::Convert::Plaintext->converter(@_)},
},
'html' => {
'nodes_tree' => 1,
'floats' => 1,
'split' => 1,
'internal_links' => 1,
'simple_menu' => 1,
'move_index_entries_after_items' => 1,
'converter' => sub{Texinfo::Convert::HTML->converter(@_)},
},
'texinfoxml' => {
'nodes_tree' => 1,
'converter' => sub{Texinfo::Convert::TexinfoXML->converter(@_)},
'floats' => 1,
},
'texinfosxml' => {
'nodes_tree' => 1,
'converter' => sub{Texinfo::Convert::TexinfoSXML->converter(@_)},
'floats' => 1,
},
'ixinsxml' => {
'nodes_tree' => 1,
'converter' => sub{Texinfo::Convert::IXINSXML->converter(@_)},
},
'docbook' => {
'move_index_entries_after_items' => 1,
'converter' => sub{Texinfo::Convert::DocBook->converter(@_)},
},
'pdf' => {
'texi2dvi_format' => 1,
},
'ps' => {
'texi2dvi_format' => 1,
},
'dvi' => {
'texi2dvi_format' => 1,
},
'dvipdf' => {
'texi2dvi_format' => 1,
},
'debugcount' => {
'nodes_tree' => 1,
'floats' => 1,
'converter' => sub{DebugTexinfo::DebugCount->converter(@_)},
},
'debugtree' => {
'split' => 1,
'converter' => sub{DebugTexinfo::DebugTree->converter(@_)},
},
'textcontent' => {
'converter' => sub{Texinfo::Convert::TextContent->converter(@_)},
},
'rawtext' => {
'converter' => sub{Texinfo::Convert::Text->converter(@_)},
},
'plaintexinfo' => {
'converter' => sub{Texinfo::Convert::PlainTexinfo->converter(@_)},
},
'parse' => {
},
'structure' => {
'nodes_tree' => 1,
'floats' => 1,
'split' => 1,
},
);
my $call_texi2dvi = 0;
# previous_format should be in argument if there is a possibility of error.
# as a fallback, the $format global variable is used.
sub set_format($;$$)
{
my $set_format = shift;
my $previous_format = shift;
$previous_format = $format if (!defined($previous_format));
my $do_not_override_command_line = shift;
my $new_format;
if ($format_command_line_names{$set_format}) {
$new_format = $format_command_line_names{$set_format};
} else {
$new_format = $set_format;
}
my $expanded_format = $set_format;
if (!$formats_table{$new_format}) {
document_warn(sprintf(__("ignoring unrecognized TEXINFO_OUTPUT_FORMAT value `%s'\n"),
$new_format));
$new_format = $previous_format;
} else {
if ($format_from_command_line and $do_not_override_command_line) {
$new_format = $previous_format;
} else {
if ($formats_table{$new_format}->{'texi2dvi_format'}) {
$call_texi2dvi = 1;
push @texi2dvi_args, '--'.$new_format;
$expanded_format = 'tex';
}
$default_expanded_format = [$expanded_format]
if ($Texinfo::Common::texinfo_output_formats{$expanded_format});
$format_from_command_line = 1
unless ($do_not_override_command_line);
}
}
return $new_format;
}
sub set_global_format($)
{
my $set_format = shift;
$format = set_format($set_format);
}
sub document_warn($) {
return if (get_conf('NO_WARN'));
my $text = shift;
chomp ($text);
warn(sprintf(__p("program name: warning: warning_message",
"%s: warning: %s\n"), $real_command_name, $text));
}
sub _exit($$)
{
my $error_count = shift;
my $opened_files = shift;
if ($error_count and $opened_files and !get_conf('FORCE')) {
while (@$opened_files) {
my $opened_file = shift (@$opened_files);
unlink ($opened_file);
}
}
exit (1) if ($error_count and (!get_conf('FORCE')
or $error_count > get_conf('ERROR_LIMIT')));
}
sub handle_errors($$$)
{
my $self = shift;
my $error_count = shift;
my $opened_files = shift;
my ($errors, $new_error_count) = $self->errors();
$error_count += $new_error_count if ($new_error_count);
foreach my $error_message (@$errors) {
warn $error_message->{'error_line'} if ($error_message->{'type'} eq 'error'
or !get_conf('NO_WARN'));
}
_exit($error_count, $opened_files);
return $error_count;
}
sub _get_converter_default($)
{
my $option = shift;
return $Texinfo::Convert::Converter::all_converters_defaults{$option}
if (defined($Texinfo::Convert::Converter::all_converters_defaults{$option}));
return undef;
}
sub makeinfo_help()
{
my $makeinfo_help =
__("Usage: makeinfo [OPTION]... TEXINFO-FILE...\n")
. __(" or: texi2any [OPTION]... TEXINFO-FILE...\n")
."\n".
__("Translate Texinfo source documentation to various other formats, by default
Info files suitable for reading online with Emacs or standalone GNU Info.\n")
."\n";
$makeinfo_help .= sprintf(__("General options:
--document-language=STR locale to use in translating Texinfo keywords
for the output document (default C).
--error-limit=NUM quit after NUM errors (default %d).
--force preserve output even if errors.
--help display this help and exit.
--no-validate suppress node cross-reference validation.
--no-warn suppress warnings (but not errors).
--conf-dir=DIR search also for initialization files in DIR.
--init-file=FILE load FILE to modify the default behavior.
-c, --set-customization-variable VAR=VAL set customization variable VAR
to VAL.
-v, --verbose explain what is being done.
--version display version information and exit.\n"), get_conf('ERROR_LIMIT'))
."\n";
$makeinfo_help .= __("Output format selection (default is to produce Info):
--docbook output Docbook XML rather than Info.
--html output HTML rather than Info.
--plaintext output plain text rather than Info.
--xml output Texinfo XML rather than Info.
--dvi, --dvipdf, --ps, --pdf call texi2dvi to generate given output.\n")
."\n";
$makeinfo_help .= __("General output options:
-E, --macro-expand=FILE output macro-expanded source to FILE,
ignoring any \@setfilename.
--no-headers suppress node separators, Node: lines, and menus
from Info output (thus producing plain text)
or from HTML (thus producing shorter output).
Also, if producing Info, write to
standard output by default
--no-split suppress any splitting of the output;
generate only one output file.
--[no-]number-sections output chapter and sectioning numbers;
default is on.
-o, --output=DEST output to DEST.
With split output, create DEST as a directory
and put the output files there.
With non-split output, if DEST is already
a directory or ends with a /,
put the output file there.
Otherwise, DEST names the output file.\n")
."\n";
$makeinfo_help .= sprintf(__("Options for Info and plain text:
--disable-encoding do not output accented and special characters
in Info output based on \@documentencoding.
--enable-encoding override --disable-encoding (default).
--fill-column=NUM break Info lines at NUM characters (default %d).
--footnote-style=STYLE output footnotes in Info according to STYLE:
`separate' to put them in their own node;
`end' to put them at the end of the node, in
which they are defined (this is the default).
--paragraph-indent=VAL indent Info paragraphs by VAL spaces (default %d).
If VAL is `none', do not indent; if VAL is
`asis', preserve existing indentation.
--split-size=NUM split Info files at size NUM (default %d).\n"),
_get_converter_default('fillcolumn'),
_get_converter_default('paragraphindent'),
_get_converter_default('SPLIT_SIZE'))
."\n";
$makeinfo_help .= __("Options for HTML:
--css-include=FILE include FILE in HTML <style> output;
read stdin if FILE is -.
--css-ref=URL generate CSS reference to URL.
--internal-links=FILE produce list of internal links in FILE.
--split=SPLIT split at SPLIT, where SPLIT may be `chapter',
`section' or `node'.
--transliterate-file-names use file names in ASCII transliteration.
--node-files produce redirection files for nodes and
anchors; default is set only if split.\n")
."\n";
$makeinfo_help .= __("Options for XML and Docbook:
--output-indent=VAL does nothing, retained for compatibility.\n")
."\n";
$makeinfo_help .= __("Options for DVI/PS/PDF:
--Xopt=OPT pass OPT to texi2dvi; can be repeated.\n")
."\n";
$makeinfo_help .= __("Input file options:
--commands-in-node-names does nothing, retained for compatibility.
-D VAR define the variable VAR, as with \@set.
-I DIR append DIR to the \@include search path.
-P DIR prepend DIR to the \@include search path.
-U VAR undefine the variable VAR, as with \@clear.\n")
."\n";
$makeinfo_help .= __("Conditional processing in input:
--ifdocbook process \@ifdocbook and \@docbook even if
not generating Docbook.
--ifhtml process \@ifhtml and \@html even if not generating HTML.
--ifinfo process \@ifinfo even if not generating Info.
--ifplaintext process \@ifplaintext even if not generating plain text.
--iftex process \@iftex and \@tex.
--ifxml process \@ifxml and \@xml.
--no-ifdocbook do not process \@ifdocbook and \@docbook text.
--no-ifhtml do not process \@ifhtml and \@html text.
--no-ifinfo do not process \@ifinfo text.
--no-ifplaintext do not process \@ifplaintext text.
--no-iftex do not process \@iftex and \@tex text.
--no-ifxml do not process \@ifxml and \@xml text.
Also, for the --no-ifFORMAT options, do process \@ifnotFORMAT text.\n")
."\n";
$makeinfo_help .= __(" The defaults for the \@if... conditionals depend on the output format:
if generating Docbook, --ifdocbook is on and the others are off;
if generating HTML, --ifhtml is on and the others are off;
if generating Info, --ifinfo is on and the others are off;
if generating plain text, --ifplaintext is on and the others are off;
if generating XML, --ifxml is on and the others are off.\n")
."\n";
$makeinfo_help .= __("Examples:
makeinfo foo.texi write Info to foo's \@setfilename
makeinfo --html foo.texi write HTML to \@setfilename
makeinfo --xml foo.texi write Texinfo XML to \@setfilename
makeinfo --docbook foo.texi write Docbook XML to \@setfilename
makeinfo --plaintext foo.texi write plain text to standard output
makeinfo --pdf foo.texi write PDF using texi2dvi
makeinfo --html --no-headers foo.texi write html without node lines, menus
makeinfo --number-sections foo.texi write Info with numbered sections
makeinfo --no-split foo.texi write one Info file however big\n")
."\n";
$makeinfo_help .= __("Email bug reports to bug-texinfo\@gnu.org,
general questions and discussion to help-texinfo\@gnu.org.
Texinfo home page: http://www.gnu.org/software/texinfo/") ."\n";
return $makeinfo_help;
}
my $Xopt_arg_nr = 0;
my $latex2html_file = 'latex2html.pm';
my $result_options = Getopt::Long::GetOptions (
'help|h' => sub { print makeinfo_help(); exit 0; },
'version|V' => sub {print "$real_command_name (GNU texinfo) $configured_version\n\n";
printf __("Copyright (C) %s Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.\n"), "2013";
exit 0;},
'macro-expand|E=s' => sub { set_from_cmdline('MACRO_EXPAND', $_[1]); },
'ifhtml!' => sub { set_expansion('html', $_[1]); },
'ifinfo!' => sub { set_expansion('info', $_[1]); },
'ifxml!' => sub { set_expansion('xml', $_[1]); },
'ifdocbook!' => sub { set_expansion('docbook', $_[1]); },
'iftex!' => sub { set_expansion('tex', $_[1]); },
'ifplaintext!' => sub { set_expansion('plaintext', $_[1]); },
'I=s' => sub { push @texi2dvi_args, ('-'.$_[0], $_[1]);
push @include_dirs, split(/$quoted_path_separator/, $_[1]); },
'conf-dir=s' => sub { push @conf_dirs, split(/$quoted_path_separator/, $_[1]); },
'P=s' => sub { unshift @prepend_dirs, split(/$quoted_path_separator/, $_[1]); },
'number-sections!' => sub { set_from_cmdline('NUMBER_SECTIONS', $_[1]); },
'number-footnotes!' => sub { set_from_cmdline('NUMBER_FOOTNOTES', $_[1]); },
'node-files!' => sub { set_from_cmdline('NODE_FILES', $_[1]); },
'footnote-style=s' => sub {
if ($_[1] eq 'end' or $_[1] eq 'separate') {
set_from_cmdline('footnotestyle', $_[1]);
} else {
die sprintf(__("%s: --footnote-style arg must be `separate' or `end', not `%s'.\n"), $real_command_name, $_[1]);
}
},
'split=s' => sub { my $split = $_[1];
my @messages
= Texinfo::Common::warn_unknown_split($_[1], \&__);
if (@messages) {
foreach my $message (@messages) {
document_warn($message);
}
$split = 'node';
}
set_from_cmdline('SPLIT', $split); },
'no-split' => sub { set_from_cmdline('SPLIT', '');
set_from_cmdline('SPLIT_SIZE', undef);},
'headers!' => sub { set_from_cmdline('HEADERS', $_[1]);
set_from_cmdline('SHOW_MENU', $_[1]);
$format = 'plaintext' if (!$_[1] and $format eq 'info'); },
'output|out|o=s' => sub {
my $var = 'OUTFILE';
if ($_[1] =~ m:/$: or -d $_[1]) {
$var = 'SUBDIR';
}
set_from_cmdline($var, $_[1]);
set_from_cmdline('OUT', $_[1]);
push @texi2dvi_args, '-o', $_[1];
},
'no-validate|no-pointer-validate' => sub {
set_from_cmdline('novalidate',$_[1]);
$parser_default_options->{'novalidate'} = $_[1];
},
'no-warn' => sub { set_from_cmdline('NO_WARN', $_[1]); },
'verbose|v!' => sub {set_from_cmdline('VERBOSE', $_[1]);
push @texi2dvi_args, '--verbose'; },
'document-language=s' => sub {
set_from_cmdline('documentlanguage', $_[1]);
$parser_default_options->{'documentlanguage'} = $_[1];
my @messages
= Texinfo::Common::warn_unknown_language($_[1], \&__);
foreach my $message (@messages) {
document_warn($message);
}
},
'D=s' => sub {$parser_default_options->{'values'}->{$_[1]} = 1;},
'U=s' => sub {delete $parser_default_options->{'values'}->{$_[1]};},
'init-file=s' => sub {
locate_and_load_init_file($_[1], [ @conf_dirs, @program_init_dirs ]);
},
'set-customization-variable|c=s' => sub {
my $var_val = $_[1];
if ($var_val =~ s/^(\w+)\s*=?\s*//) {
my $var = $1;
my $value = $var_val;
if ($value =~ /^undef$/i) {
$value = undef;
}
# special case, this is a pseudo format for debug
if ($var eq 'TEXINFO_OUTPUT_FORMAT') {
$format = set_format($value, $format, 1);
} elsif ($var eq 'TEXI2HTML') {
$format = set_format('html');
$parser_default_options->{'values'}->{'texi2html'} = 1;
}
set_from_cmdline($var, $value);
# FIXME do that here or when all command line options are processed?
if ($var eq 'L2H' and get_conf('L2H')) {
locate_and_load_init_file($latex2html_file,
[ @conf_dirs, @program_init_dirs ]);
}
}
},
'css-include=s' => \@css_files,
'css-ref=s' => \@css_refs,
'transliterate-file-names!' =>
sub {set_from_cmdline('TRANSLITERATE_FILE_NAMES', $_[1]);},
'error-limit|e=i' => sub { set_from_cmdline('ERROR_LIMIT', $_[1]); },
'split-size=s' => sub {set_from_cmdline('SPLIT_SIZE', $_[1])},
'paragraph-indent|p=s' => sub {
my $value = $_[1];
if ($value =~ /^([0-9]+)$/ or $value eq 'none' or $value eq 'asis') {
set_from_cmdline('paragraphindent', $_[1]);
} else {
die sprintf(__("%s: --paragraph-indent arg must be numeric/`none'/`asis', not `%s'.\n"),
$real_command_name, $value);
}
},
'fill-column|f=i' => sub {set_from_cmdline('FILLCOLUMN',$_[1]);},
'enable-encoding' => sub {set_from_cmdline('ENABLE_ENCODING',$_[1]);
$parser_default_options->{'ENABLE_ENCODING'} = $_[1];},
'disable-encoding' => sub {set_from_cmdline('ENABLE_ENCODING', 0);
$parser_default_options->{'ENABLE_ENCODING'} = 0;},
'internal-links=s' => sub {set_from_cmdline('INTERNAL_LINKS', $_[1]);},
'force|F' => sub {set_from_cmdline('FORCE', $_[1]);},
'commands-in-node-names' => sub { ;},
'output-indent=i' => sub { ;},
'reference-limit=i' => sub { ;},
'Xopt=s' => sub {push @texi2dvi_args, $_[1]; $Xopt_arg_nr++},
'silent|quiet' => sub {set_from_cmdline('SILENT', $_[1]);
push @texi2dvi_args, '--'.$_[0];},
'plaintext' => sub {$format = $_[0];},
'html' => sub {$format = set_format($_[0]);},
'info' => sub {$format = set_format($_[0]);},
'docbook' => sub {$format = set_format($_[0]);},
'xml' => sub {$format = set_format($_[0]);},
'dvi' => sub {$format = set_format($_[0]);},
'dvipdf' => sub {$format = set_format($_[0]);},
'ps' => sub {$format = set_format($_[0]);},
'pdf' => sub {$format = set_format($_[0]);},
'debug=i' => sub {set_from_cmdline('DEBUG', $_[1]);
$parser_default_options->{'DEBUG'} = $_[1];
push @texi2dvi_args, '--'.$_[0]; },
);
exit 1 if (!$result_options);
# For tests, set some strings to values not changing with releases
my %test_conf = (
'PACKAGE_VERSION' => '',
'PACKAGE' => 'texinfo',