Don't be verbose if stdout is not a tty.

This commit is contained in:
paul 2002-01-31 20:01:49 +00:00
parent a2e43c99b0
commit 779b348a81
2 changed files with 10 additions and 4 deletions

View File

@ -44,6 +44,8 @@ my $VERSION='1.0';
my(%db,$N,$A,$T,$E,$C,$R, $lang,$append,$verbose,$i, $cc, $file, $tied);
my $outistty = (-t STDOUT);
while ($ARGV[0] =~ /^-(.)(\S*)/) {
shift(@ARGV);
$append=1,next if ($1 eq 'a');
@ -105,7 +107,7 @@ sub write_global {
die("Cant find country.dat");
$i=0;
while (<IN>) {
print "$i\r" if (++$i % 10==0 && $verbose);
print "$i\r" if (++$i % 10==0 && $verbose && $outistty);
s/\s*#.*$//; # kill comments
next if /^$/; # skip empty
if (/^N:(.*)/) {
@ -246,7 +248,7 @@ sub write_cc {
$db{$vers}=$value;
$i=0;
while (<IN>) {
print "$i\r" if (++$i % 10==0 && $verbose);
print "$i\r" if (++$i % 10==0 && $verbose && $outistty);
s/\s*#.*$//; # kill comments
next if /^$/; # skip empty
my ($num, $ort, $len);

View File

@ -73,6 +73,7 @@ void usage(char *argv[]) {
static int (*zones)[3];
static int *numbers;
static bool verbose=false;
static bool stdoutisatty=true; /* assume the worst :-) */
static int table[256];
static int tablelen, keylen, keydigs, maxnum;
static int n, nn;
@ -104,7 +105,7 @@ static void read_rzfile(char *rf) {
printf("Reading %s\n", rf);
while (fgets(line, BUFSIZ, fp)) {
if (verbose && (n % 1000) == 0) {
if (verbose && stdoutisatty && (n % 1000) == 0) {
printf("%d\r", n);
fflush(stdout);
}
@ -262,7 +263,7 @@ static void write_db(char * df) {
UC uc;
unsigned char buf[4];
if (verbose && (i % 1000) == 0) {
if (verbose && stdoutisatty && (i % 1000) == 0) {
printf("%d\r", i);
fflush(stdout);
}
@ -358,6 +359,9 @@ int main (int argc, char *argv[])
case 'l' : numlen = atoi(optarg); break;
}
}
if (verbose)
stdoutisatty = isatty(fileno(stdout));
read_rzfile(rf);
make_table();
write_db(df);