Skip to content

Commit da986f5

Browse files
Add command line options --stdout and --stderr to select the output of the printed text.
1 parent 8c40579 commit da986f5

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

pm/AutoLaTeX/Core/Main.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ The provided functions are:
3131
=cut
3232
package AutoLaTeX::Core::Main;
3333

34-
$VERSION = '24.0';
35-
$COPYRIGHT_YEAR = '2013';
34+
$VERSION = '25.0';
35+
$COPYRIGHT_YEAR = '2014';
3636
@ISA = ('Exporter');
3737
@EXPORT = qw( &analyzeCommandLineOptions &mainProgram &detectMainTeXFile ) ;
3838
@EXPORT_OK = qw();
@@ -185,6 +185,10 @@ sub analyzeCommandLineOptions(\%) {
185185

186186
'set=s%' => sub { $cfg->{'generation.set'}{$_[1]} = $_[2]; },
187187

188+
'stdout' => sub { redirectToSTDOUT(); },
189+
190+
'stderr' => sub { redirectToSTDERR(); },
191+
188192
'synctex!' => sub { $cfg->{'generation.synctex'} = ($_[1] ? 'yes' : 'no'); },
189193

190194
'xelatex' => sub {

pm/AutoLaTeX/Core/Util.pm

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ package AutoLaTeX::Core::Util;
3838

3939
our $INTERNAL_MESSAGE_PREFIX = '';
4040

41-
our $VERSION = '11.0';
41+
our $VERSION = '12.0';
4242

4343
@ISA = ('Exporter');
4444
@EXPORT = qw( &isHash &isArray &removeFromArray &arrayContains &getAutoLaTeXDir
@@ -51,7 +51,7 @@ our $VERSION = '11.0';
5151
&readFileLines &writeFileLines &runCommandOrFailRedirectTo
5252
&runCommandSilently &removePathPrefix &trim &trim_ws &formatText
5353
&makeMessage &makeMessageLong &secure_unlink &str2language
54-
&killSubProcesses &toANSI &toUTF8 ) ;
54+
&killSubProcesses &toANSI &toUTF8 &redirectToSTDOUT &redirectToSTDERR ) ;
5555
@EXPORT_OK = qw( $INTERNAL_MESSAGE_PREFIX );
5656

5757
require 5.014;
@@ -67,6 +67,7 @@ use Data::Dumper;
6767

6868
use AutoLaTeX::Core::IntUtils;
6969

70+
local *AUTOLATEXCONSOLE = *STDERR;
7071
my $autoLaTeXName = undef;
7172
my $autoLaTeXDirectory = undef;
7273
my $autoLaTeXLaunchingName = undef;
@@ -81,6 +82,34 @@ my %launchedSubProcesses = ();
8182

8283
=pod
8384
85+
=item B<redirectToSTDOUT()>
86+
87+
Redirect the verbosing text on the STDOUT in place of STDERR.
88+
89+
I<Returns:> None.
90+
91+
=cut
92+
sub redirectToSTDOUT() {
93+
*AUTOLATEXCONSOLE = *STDOUT;
94+
1;
95+
}
96+
97+
=pod
98+
99+
=item B<redirectToSTDERR()>
100+
101+
Redirect the verbosing text on the STDERR in place of STDOUT.
102+
103+
I<Returns:> None.
104+
105+
=cut
106+
sub redirectToSTDERR() {
107+
*AUTOLATEXCONSOLE = *STDERR;
108+
1;
109+
}
110+
111+
=pod
112+
84113
=item B<toANSI(@)>
85114
86115
Convert the given elements from UTF-8 to ANSI.
@@ -233,11 +262,11 @@ sub setAutoLaTeXInfo($$$) {
233262
close(*VERSIONFILE);
234263
}
235264
else {
236-
print STDERR formatText(_T("No read access to the VERSION file of AutoLaTeX. AutoLaTeX should not be properly installed. Assuming version: {}\n"),$autoLaTeXVersion);
265+
print AUTOLATEXCONSOLE formatText(_T("No read access to the VERSION file of AutoLaTeX. AutoLaTeX should not be properly installed. Assuming version: {}\n"),$autoLaTeXVersion);
237266
}
238267
}
239268
else {
240-
print STDERR formatText(_T("Unable to find the VERSION file of AutoLaTeX. AutoLaTeX should not be properly installed. Assuming version: {}\n"), $autoLaTeXVersion);
269+
print AUTOLATEXCONSOLE formatText(_T("Unable to find the VERSION file of AutoLaTeX. AutoLaTeX should not be properly installed. Assuming version: {}\n"), $autoLaTeXVersion);
241270
}
242271
}
243272

@@ -308,7 +337,7 @@ sub showManual(@) {
308337
exit(0);
309338
}
310339
}
311-
print STDERR _T("no manual page found\n");
340+
print AUTOLATEXCONSOLE _T("no manual page found\n");
312341
exit(255);
313342
}
314343

@@ -623,7 +652,7 @@ sub printDbgFor($@) {
623652
if ($debugLevel>=$requestedLevel) {
624653
my @text = makeMessage(60,$dbgIndent,@_);
625654
foreach my $p (@text) {
626-
print STDERR ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), " $p", "\n");
655+
print AUTOLATEXCONSOLE ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), " $p", "\n");
627656
$INTERNAL_MESSAGE_PREFIX = '';
628657
}
629658
}
@@ -643,7 +672,7 @@ sub dumpDbgFor($@) {
643672
use Data::Dumper;
644673
my @text = makeMessage(60,$dbgIndent,Dumper(@_));
645674
foreach my $p (@text) {
646-
print STDERR ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), " $p", "\n");
675+
print AUTOLATEXCONSOLE ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), " $p", "\n");
647676
$INTERNAL_MESSAGE_PREFIX = '';
648677
}
649678
}
@@ -675,7 +704,7 @@ display an error message and exit. The parameters will be displayed separated by
675704
676705
=cut
677706
sub printErr(@) {
678-
print STDERR formatErr(@_);
707+
print AUTOLATEXCONSOLE formatErr(@_);
679708
exit(255);
680709
undef;
681710
}
@@ -690,7 +719,7 @@ display a warning message. The parameters will be displayed separated by a space
690719
sub printWarn(@) {
691720
my @text = makeMessage(50,0,@_);
692721
foreach my $p (@text) {
693-
print STDERR ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), ' ', formatText(_T("Warning: {}"),"$p"), "\n");
722+
print AUTOLATEXCONSOLE ($INTERNAL_MESSAGE_PREFIX, _T("[AutoLaTeX]"), ' ', formatText(_T("Warning: {}"),"$p"), "\n");
694723
$INTERNAL_MESSAGE_PREFIX = '';
695724
}
696725
1;
@@ -741,7 +770,7 @@ sub runCommandOrFailRedirectTo($@) {
741770
if ($exitcode!=0) {
742771
open(*LOGFILE, "< autolatex_exec_stderr.log") or printErr(formatText(_T("{}: {}"), "autolatex_exec_stderr.log", $!));
743772
while (my $line = <LOGFILE>) {
744-
print STDERR $INTERNAL_MESSAGE_PREFIX.$line;
773+
print AUTOLATEXCONSOLE $INTERNAL_MESSAGE_PREFIX.$line;
745774
$INTERNAL_MESSAGE_PREFIX = '';
746775
}
747776
close(*LOGFILE);
@@ -851,7 +880,7 @@ sub runCommandOrFail(@) {
851880
close(*LOGFILE);
852881
open(*LOGFILE, "< autolatex_exec_stderr.log") or printErr(formatText(_T("{}: {}"), "autolatex_exec_stderr.log", $!));
853882
while (my $line = <LOGFILE>) {
854-
print STDERR $INTERNAL_MESSAGE_PREFIX.$line;
883+
print AUTOLATEXCONSOLE $INTERNAL_MESSAGE_PREFIX.$line;
855884
$INTERNAL_MESSAGE_PREFIX = '';
856885
}
857886
close(*LOGFILE);
@@ -933,7 +962,7 @@ sub runCommandOrFailFromInput($@) {
933962
close(*LOGFILE);
934963
open(*LOGFILE, "< autolatex_exec_stderr.log") or printErr(formatText(_T("{}: {}"), "autolatex_exec_stderr.log", $!));
935964
while (my $line = <LOGFILE>) {
936-
print STDERR $INTERNAL_MESSAGE_PREFIX.$line;
965+
print AUTOLATEXCONSOLE $INTERNAL_MESSAGE_PREFIX.$line;
937966
$INTERNAL_MESSAGE_PREFIX = '';
938967
}
939968
close(*LOGFILE);

0 commit comments

Comments
 (0)