bytespersec = 0; if (statbytes > 0) { bytespersec = statbytes; if (elapsed > 0.0) bytespersec /= elapsed; } for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++) bytespersec >>= 10;  nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1);  snprintf(buf, sizeof(buf), "\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s", curfile, nspaces, spaces, ratio, (long long)abbrevsize, prefixes[ai], ai == 0 ? ' ' : 'B', (long long)(bytespersec / 1024), (int)((bytespersec % 1024) * 10 / 1024), prefixes[bi] );
progressmeter(int flag){	static const char prefixes[] = " KMGTP";	static struct timeval lastupdate;	static off_t lastsize;	struct timeval now, td, wait;	off_t cursize, abbrevsize;	double elapsed;	int ratio, barlength, i, remaining;	char buf[512];	if (flag == -1) {		(void) gettimeofday(&start, (struct timezone *) 0);		lastupdate = start;		lastsize = 0;	}	if (foregroundproc() == 0)		return;	(void) gettimeofday(&now, (struct timezone *) 0);	cursize = statbytes;	if (totalbytes != 0) {		ratio = 100.0 * cursize / totalbytes;		ratio = MAX(ratio, 0);		ratio = MIN(ratio, 100);	} else		ratio = 100;	snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);	barlength = getttywidth() - 51;	if (barlength > 0) {		i = barlength * ratio / 100;		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),		    "|%.*s%*s|", i,		    "*******************************************************"		    "*******************************************************"		    "*******************************************************"		    "*******************************************************"		    "*******************************************************"		    "*******************************************************"		    "*******************************************************",		    barlength - i, "");	}	i = 0;	abbrevsize = cursize;	while (abbrevsize >= 100000 && i < sizeof(prefixes)) {		i++;		abbrevsize >>= 10;	}	snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5llu %c%c ",	    (unsigned long long) abbrevsize, prefixes[i],	    prefixes[i] == ' ' ? ' ' : 'B');	timersub(&now, &lastupdate, &wait);	if (cursize > lastsize) {		lastupdate = now;		lastsize = cursize;		if (wait.tv_sec >= STALLTIME) {			start.tv_sec += wait.tv_sec;			start.tv_usec += wait.tv_usec;		}		wait.tv_sec = 0;	}	timersub(&now, &start, &td);	elapsed = td.tv_sec + (td.tv_usec / 1000000.0);	if (flag != 1 &&	    (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) {		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),		    "   --:-- ETA");	} else if (wait.tv_sec >= STALLTIME) {		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),		    " - stalled -");	} else {		if (flag != 1)			remaining = (int)(totalbytes / (statbytes / elapsed) -			    elapsed);		else			remaining = elapsed;		i = remaining / 3600;		if (i)			snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),			    "%2d:", i);		else			snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),			    "   ");		i = remaining % 3600;		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),		    "%02d:%02d%s", i / 60, i % 60,		    (flag != 1) ? " ETA" : "    ");	}	atomicio(write, fileno(stdout), buf, strlen(buf));	if (flag == -1) {		signal(SIGALRM, updateprogressmeter);		alarm(PROGRESSTIME);	} else if (flag == 1) {		alarm(0);		atomicio(write, fileno(stdout), "\n", 1);		statbytes = 0;	}}