File: bar.c

package info (click to toggle)
bar 1.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 928 kB
  • sloc: ansic: 4,381; sh: 3,334; makefile: 264
file content (66 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "config.h"

#include "headers.h"
#include "types.h"
#include "error.h"
#include "fd.h"
#include "io.h"
#include "display.h"
#include "args.h"

/** \mainpage Command Line Progress Bar

Bar is a simple tool to copy a stream of data from input to output while
displaying for the user:

\li The amount of data passed
\li The throughput of the data transfer

and, if the total size of the data stream is known:

\li The estimated time remaining
\li What percent of the data stream has been copied
\li A progress bar

Bar was originally written for the purpose of estimating the amount of time
needed to transfer large amounts (many, many gigabytes) of data across a
network in a tar/ssh pipe.

*/

int main(int argc, char *argv[])
{
	int rval = 0;
#ifdef DEBUG
	int debug = 1;

	fprintf(stderr, "Waiting for debugger to attach...\n");
	while (debug);
#endif
	if (ioInit() != 0) return(1);
	if (displayInit() != 0) return(1);
	if (parse_rcfiles(stderr) != 0) return(1);
	if (parse_args(stderr, argc, argv) != 0) return(1);
	if (ioBegin() != 0) return(1);
	if (displayBegin() != 0) return(1);

	while (!ioIsDone()) {
		ioCheck();
		if (ioRead() < 0) {
			print_error(stderr, "read error");
			rval = 1;
			break;
		}
		if (ioWrite() < 0) {
			print_error(stderr, "write error");
			rval = 1;
			break;
		}
		displayUpdate();
	}

	displayEnd();
	ioEnd();
	return(rval);
}