xref: /dragonfly/contrib/tnftp/src/progressbar.h (revision 790cc7ef)
1 /*	$NetBSD: progressbar.h,v 1.10 2021/04/25 07:50:37 lukem Exp $	*/
2 /*	from	NetBSD: progressbar.h,v 1.9 2021/01/06 04:43:14 lukem Exp	*/
3 
4 /*-
5  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Luke Mewburn.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef STANDALONE_PROGRESS
34 #include <setjmp.h>
35 #endif	/* !STANDALONE_PROGRESS */
36 
37 #ifndef	GLOBAL
38 #define	GLOBAL	extern
39 #endif
40 
41 
42 #define	STALLTIME	5	/* # of seconds of no xfer before "stalling" */
43 
44 typedef void (*sigfunc)(int);
45 
46 
47 GLOBAL	FILE   *ttyout;		/* stdout, or stderr if retrieving to stdout */
48 
49 GLOBAL	int	progress;	/* display transfer progress bar */
50 GLOBAL	int	ttywidth;	/* width of tty */
51 
52 GLOBAL	off_t	bytes;		/* current # of bytes read */
53 GLOBAL	off_t	filesize;	/* size of file being transferred */
54 GLOBAL	off_t	restart_point;	/* offset to restart transfer */
55 GLOBAL	char   *prefix;		/* Text written left of progress bar */
56 
57 
58 #ifndef	STANDALONE_PROGRESS
59 GLOBAL	int	fromatty;	/* input is from a terminal */
60 GLOBAL	int	verbose;	/* print messages coming back from server */
61 GLOBAL	int	quit_time;	/* maximum time to wait if stalled */
62 
63 GLOBAL	const char  *direction;	/* direction transfer is occurring */
64 
65 GLOBAL	sigjmp_buf toplevel;	/* non-local goto stuff for cmd scanner */
66 #endif	/* !STANDALONE_PROGRESS */
67 
68 int	foregroundproc(void);
69 void	alarmtimer(int);
70 void	progressmeter(int);
71 sigfunc	xsignal(int, sigfunc);
72 
73 #ifndef STANDALONE_PROGRESS
74 void	psummary(int);
75 void	ptransfer(int);
76 #endif	/* !STANDALONE_PROGRESS */
77 
78 #ifdef NO_LONG_LONG
79 # define LLF		"%ld"
80 # define LLFP(x)	"%" x "ld"
81 # define LLT		long
82 # define ULLF		"%lu"
83 # define ULLFP(x)	"%" x "lu"
84 # define ULLT		unsigned long
85 #else
86 #if defined(HAVE_PRINTF_QD)
87 # define LLF		"%qd"
88 # define LLFP(x)	"%" x "qd"
89 # define LLT		long long
90 # define ULLF		"%qu"
91 # define ULLFP(x)	"%" x "qu"
92 # define ULLT		unsigned long long
93 #else /* !defined(HAVE_PRINTF_QD) */
94 # define LLF		"%lld"
95 # define LLFP(x)	"%" x "lld"
96 # define LLT		long long
97 # define ULLF		"%llu"
98 # define ULLFP(x)	"%" x "llu"
99 # define ULLT		unsigned long long
100 #endif /* !defined(HAVE_PRINTF_QD) */
101 #endif
102