]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/perl/UCW/Configure.pm
UCW::Configure: Flush STDOUT after logging
[libucw.git] / ucw / perl / UCW / Configure.pm
index 958a08422b01d16d130230cc13f9c14aa6b3d408..83b70e0d8fe722863b84979221b934d2ecedef85 100644 (file)
@@ -1,6 +1,6 @@
 #      Perl module for UCW Configure Scripts
 #
-#      (c) 2005--2008 Martin Mares <mj@ucw.cz>
+#      (c) 2005--2010 Martin Mares <mj@ucw.cz>
 #
 #      This software may be freely distributed and used according to the terms
 #      of the GNU Lesser General Public License.
@@ -16,7 +16,7 @@ BEGIN {
        our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
        $VERSION = 1.0;
        @ISA = qw(Exporter);
-       @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile &DebugDump &PostConfig &AtWrite);
+       @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &TestBool &Include &Finish &FindFile &TryFindFile &DebugDump &PostConfig &AtWrite);
        @EXPORT_OK = qw();
        %EXPORT_TAGS = ();
 }
@@ -33,14 +33,17 @@ sub DebugDump() {
 
 sub Log($) {
        print @_;
+       STDOUT->flush;
 }
 
 sub Notice($) {
        print @_ if $vars{"VERBOSE"};
+       STDOUT->flush;
 }
 
 sub Warn($) {
        print "WARNING: ", @_;
+       STDOUT->flush;
 }
 
 sub Fail($) {
@@ -89,17 +92,34 @@ sub Override($;$) {
 sub Test($$$) {
        my ($var,$msg,$sub) = @_;
        Log "$msg ... ";
-       if (!IsSet($var)) {
-               Set $var, &$sub();
+       if (IsSet($var)) {
+               Log Get($var) . " (preset)\n";
+       } else {
+               my $val = &$sub();
+               Set($var, $val);
+               Log "$val\n";
+       }
+}
+
+sub TestBool($$$) {
+       my ($var,$msg,$sub) = @_;
+       Log "$msg ... ";
+       if (IsSet($var) || IsGiven($var)) {
+               Log ((Get($var) ? "yes" : "no") . " (set)\n");
+       } else {
+               my ($val, $comment) = &$sub();
+               Set($var, $val);
+               Log (($val ? "yes" : "no") . "\n");
        }
-       Log Get($var) . "\n";
 }
 
 sub TryFindFile($) {
        my ($f) = @_;
-       if (-f $f) {
-               return $f;
-       } elsif ($f !~ /^\// && -f (Get("SRCDIR")."/$f")) {
+       if ($f =~ m{^/}) {
+               return (-f $f) ? $f : undef;
+       } elsif (-f $f) {
+               return "./$f";
+       } elsif (-f (Get("SRCDIR")."/$f")) {
                return Get("SRCDIR")."/$f";
        } else {
                return undef;