From 2d7aaaa5cb537cfccbdac8acde3b16f019f34148 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Tue, 31 Jul 2007 21:21:12 +0000 Subject: make rip code work like mmc code for how it does progress reports (use a timer, so that stderr does not get splattered); tested by xsa and others --- usr.bin/cdio/mmc.c | 8 ++++---- usr.bin/cdio/rip.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'usr.bin/cdio') diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index 2e5e892b698..b0390c214ed 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.16 2006/08/28 02:36:43 mjc Exp $ */ +/* $OpenBSD: mmc.c,v 1.17 2007/07/31 21:21:11 deraadt Exp $ */ /* * Copyright (c) 2006 Michael Coulter @@ -223,7 +223,7 @@ writetrack(struct track_info *tr, int track) again: r = ioctl(fd, SCIOCCOMMAND, &scr); if (r != 0) { - printf("%60s\r", ""); + printf("\r%60s", ""); warn("ioctl failed while attempting to write"); return (-1); } @@ -232,7 +232,7 @@ again: goto again; } if (scr.retsts != SCCMD_OK) { - printf("%60s\r", ""); + printf("\r%60s", ""); warnx("ioctl returned bad status while " "attempting to write: %d", scr.retsts); @@ -243,7 +243,7 @@ again: gettimeofday(&tv, NULL); if (lba == end_lba || timercmp(&tv, &otv, >)) { fprintf(stderr, - "track %02d '%c' %08u/%08u %3d%%\r", + "\rtrack %02d '%c' %08u/%08u %3d%%", track, tr->type, lba, end_lba, 100 * lba / end_lba); timeradd(&tv, &atv, &otv); diff --git a/usr.bin/cdio/rip.c b/usr.bin/cdio/rip.c index db26a990e04..0d5997b4c94 100644 --- a/usr.bin/cdio/rip.c +++ b/usr.bin/cdio/rip.c @@ -1,3 +1,5 @@ +/* $OpenBSD: rip.c,v 1.6 2007/07/31 21:21:11 deraadt Exp $ */ + /* * Copyright (c) 2007 Alexey Vatchenko * @@ -356,6 +358,7 @@ read_data_sector(u_int32_t lba, u_char *sec, u_int32_t secsize) int read_track(int fd, struct track_info *ti) { + struct timeval tv, otv, atv; u_int32_t i, blksize, n_sec; u_char *sec; int error; @@ -366,9 +369,19 @@ read_track(int fd, struct track_info *ti) if (sec == NULL) return (-1); + timerclear(&otv); + atv.tv_sec = 1; + atv.tv_usec = 0; + for (i = 0; i < n_sec; ) { - fprintf(stderr, "track %u '%c' %08u/%08u %3u%%\r", ti->track, - (ti->isaudio) ? 'a' : 'd', i, n_sec, 100 * i / n_sec); + gettimeofday(&tv, NULL); + if (timercmp(&tv, &otv, >)) { + fprintf(stderr, "\rtrack %u '%c' %08u/%08u %3u%%", + ti->track, + (ti->isaudio) ? 'a' : 'd', i, n_sec, + 100 * i / n_sec); + timeradd(&tv, &atv, &otv); + } error = read_data_sector(i + ti->start_lba, sec, blksize); if (error == 0) { @@ -388,7 +401,8 @@ read_track(int fd, struct track_info *ti) } free(sec); - fprintf(stderr, "track %u '%c' %08u/%08u 100%%\n", ti->track, + fprintf(stderr, "\rtrack %u '%c' %08u/%08u 100%%\n", + ti->track, (ti->isaudio) ? 'a' : 'd', i, n_sec); return (0); } -- cgit v1.2.3