Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/lib/libdpv/dpv.h
39475 views
1
/*-
2
* Copyright (c) 2013-2016 Devin Teske <[email protected]>
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
*
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
* SUCH DAMAGE.
25
*/
26
27
#ifndef _DPV_H_
28
#define _DPV_H_
29
30
#include <sys/types.h>
31
32
#ifndef TRUE
33
#define TRUE 1
34
#endif
35
#ifndef FALSE
36
#define FALSE 0
37
#endif
38
39
/* localeconv(3) */
40
#define LC_NUMERIC_DEFAULT "en_US.ISO8859-1"
41
42
/* Data to process */
43
extern long long dpv_overall_read;
44
45
/* Interrupt flag */
46
extern int dpv_interrupt; /* Set to TRUE in interrupt handler */
47
extern int dpv_abort; /* Set to true in callback to abort */
48
49
/*
50
* Display types for use with display_type member of dpv_config structure
51
*/
52
enum dpv_display {
53
DPV_DISPLAY_LIBDIALOG = 0, /* Display using dialog(3) (default) */
54
DPV_DISPLAY_STDOUT, /* Display on stdout */
55
DPV_DISPLAY_DIALOG, /* Display using spawned dialog(1) */
56
DPV_DISPLAY_XDIALOG, /* Display using spawned Xdialog(1) */
57
};
58
59
/*
60
* Output types for use with output_type member of dpv_config structure
61
*/
62
enum dpv_output {
63
DPV_OUTPUT_NONE = 0, /* No output (default) */
64
DPV_OUTPUT_FILE, /* Read `output' member as file path */
65
DPV_OUTPUT_SHELL, /* Read `output' member as shell cmd */
66
};
67
68
/*
69
* Activity types for use with status member of dpv_file_node structure.
70
* If you set a status other than DPV_STATUS_RUNNING on the current file in the
71
* action callback of dpv_config structure, you'll end callbacks for that
72
* dpv_file_node.
73
*/
74
enum dpv_status {
75
DPV_STATUS_RUNNING = 0, /* Running (default) */
76
DPV_STATUS_DONE, /* Completed */
77
DPV_STATUS_FAILED, /* Oops, something went wrong */
78
};
79
80
/*
81
* Anatomy of file option; pass an array of these as dpv() file_list argument
82
* terminated with a NULL pointer.
83
*/
84
struct dpv_file_node {
85
enum dpv_status status; /* status of read operation */
86
char *msg; /* display instead of "Done/Fail" */
87
char *name; /* name of file to read */
88
char *path; /* path to file */
89
long long length; /* expected size */
90
long long read; /* number units read (e.g., bytes) */
91
struct dpv_file_node *next; /* pointer to next (end with NULL) */
92
};
93
94
/*
95
* Anatomy of config option to pass as dpv() config argument
96
*/
97
struct dpv_config {
98
uint8_t keep_tite; /* Prevent visually distracting exit */
99
enum dpv_display display_type; /* Display (default TYPE_LIBDIALOG) */
100
enum dpv_output output_type; /* Output (default TYPE_NONE) */
101
int debug; /* Enable debugging output on stderr */
102
int display_limit; /* Files per `page'. Default -1 */
103
int label_size; /* Label size. Default 28 */
104
int pbar_size; /* Mini-progress size. See dpv(3) */
105
int dialog_updates_per_second; /* Progress updates/s. Default 16 */
106
int status_updates_per_second; /* dialog(3) status updates/second.
107
* Default 2 */
108
uint16_t options; /* Special options. Default 0 */
109
char *title; /* widget title */
110
char *backtitle; /* Widget backtitle */
111
char *aprompt; /* Prompt append. Default NULL */
112
char *pprompt; /* Prompt prefix. Default NULL */
113
char *msg_done; /* Progress text. Default `Done' */
114
char *msg_fail; /* Progress text. Default `Fail' */
115
char *msg_pending; /* Progress text. Default `Pending' */
116
char *output; /* Output format string; see dpv(3) */
117
const char *status_solo; /* dialog(3) solo-status format.
118
* Default DPV_STATUS_SOLO */
119
const char *status_many; /* dialog(3) many-status format.
120
* Default DPV_STATUS_MANY */
121
122
/*
123
* Function pointer; action to perform data transfer
124
*/
125
int (*action)(struct dpv_file_node *file, int out);
126
};
127
128
/*
129
* Macros for dpv() options bitmask argument
130
*/
131
#define DPV_TEST_MODE 0x0001 /* Test mode (fake reading data) */
132
#define DPV_WIDE_MODE 0x0002 /* prefix/append bump dialog width */
133
#define DPV_NO_LABELS 0x0004 /* Hide file_node.name labels */
134
#define DPV_USE_COLOR 0x0008 /* Override to force color output */
135
#define DPV_NO_OVERRUN 0x0010 /* Stop transfers when they hit 100% */
136
137
/*
138
* Limits (modify with extreme care)
139
*/
140
#define DPV_APROMPT_MAX 4096 /* Buffer size for `-a text' */
141
#define DPV_DISPLAY_LIMIT 10 /* Max file progress lines */
142
#define DPV_PPROMPT_MAX 4096 /* Buffer size for `-p text' */
143
#define DPV_STATUS_FORMAT_MAX 80 /* Buffer size for `-u format' */
144
145
/*
146
* Extra display information
147
*/
148
#define DPV_STATUS_SOLO "%'10lli bytes read @ %'9.1f bytes/sec."
149
#define DPV_STATUS_MANY (DPV_STATUS_SOLO " [%i/%i busy/wait]")
150
151
/*
152
* Strings
153
*/
154
#define DPV_DONE_DEFAULT "Done"
155
#define DPV_FAIL_DEFAULT "Fail"
156
#define DPV_PENDING_DEFAULT "Pending"
157
158
__BEGIN_DECLS
159
void dpv_free(void);
160
int dpv(struct dpv_config *_config, struct dpv_file_node *_file_list);
161
__END_DECLS
162
163
#endif /* !_DPV_H_ */
164
165