2 * Copyright (c) 2013-2014 Devin Teske <dteske@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/types.h>
42 extern long long dpv_overall_read;
45 extern int dpv_interrupt; /* Set to TRUE in interrupt handler */
46 extern int dpv_abort; /* Set to true in callback to abort */
49 * Display types for use with display_type member of dpv_config structure
52 DPV_DISPLAY_LIBDIALOG = 0, /* Display using dialog(3) (default) */
53 DPV_DISPLAY_STDOUT, /* Display on stdout */
54 DPV_DISPLAY_DIALOG, /* Display using spawned dialog(1) */
55 DPV_DISPLAY_XDIALOG, /* Display using spawned Xdialog(1) */
59 * Output types for use with output_type member of dpv_config structure
62 DPV_OUTPUT_NONE = 0, /* No output (default) */
63 DPV_OUTPUT_FILE, /* Read `output' member as file path */
64 DPV_OUTPUT_SHELL, /* Read `output' member as shell cmd */
68 * Activity types for use with status member of dpv_file_node structure.
69 * If you set a status other than DPV_STATUS_RUNNING on the current file in the
70 * action callback of dpv_config structure, you'll end callbacks for that
74 DPV_STATUS_RUNNING = 0, /* Running (default) */
75 DPV_STATUS_DONE, /* Completed */
76 DPV_STATUS_FAILED, /* Oops, something went wrong */
80 * Anatomy of file option; pass an array of these as dpv() file_list argument
81 * terminated with a NULL pointer.
83 struct dpv_file_node {
84 enum dpv_status status; /* status of read operation */
85 char *msg; /* display instead of "Done/Fail" */
86 char *name; /* name of file to read */
87 char *path; /* path to file */
88 long long length; /* expected size */
89 long long read; /* number units read (e.g., bytes) */
90 struct dpv_file_node *next; /* pointer to next (end with NULL) */
94 * Anatomy of config option to pass as dpv() config argument
97 enum dpv_display display_type; /* Display (default TYPE_LIBDIALOG) */
98 enum dpv_output output_type; /* Output (default TYPE_NONE) */
99 int debug; /* Enable debugging output on stderr */
100 int display_limit; /* Files per `page'. Default -1 */
101 int label_size; /* Label size. Default 28 */
102 int pbar_size; /* Mini-progress size. See dpv(3) */
103 int dialog_updates_per_second; /* Progress updates/s. Default 16 */
104 int status_updates_per_second; /* dialog(3) status updates/second.
106 uint16_t options; /* Special options. Default 0 */
107 char *title; /* widget title */
108 char *backtitle; /* Widget backtitle */
109 char *aprompt; /* Prompt append. Default NULL */
110 char *pprompt; /* Prompt prefix. Default NULL */
111 char *msg_done; /* Progress text. Default `Done' */
112 char *msg_fail; /* Progress text. Default `Fail' */
113 char *msg_pending; /* Progress text. Default `Pending' */
114 char *output; /* Output format string; see dpv(3) */
115 const char *status_solo; /* dialog(3) solo-status format.
116 * Default DPV_STATUS_SOLO */
117 const char *status_many; /* dialog(3) many-status format.
118 * Default DPV_STATUS_MANY */
121 * Function pointer; action to perform data transfer
123 int (*action)(struct dpv_file_node *file, int out);
127 * Macros for dpv() options bitmask argument
129 #define DPV_TEST_MODE 0x0001 /* Test mode (fake reading data) */
130 #define DPV_WIDE_MODE 0x0002 /* prefix/append bump dialog width */
131 #define DPV_NO_LABELS 0x0004 /* Hide file_node.name labels */
132 #define DPV_USE_COLOR 0x0008 /* Override to force color output */
133 #define DPV_NO_OVERRUN 0x0010 /* Stop transfers when they hit 100% */
136 * Limits (modify with extreme care)
138 #define DPV_APROMPT_MAX 4096 /* Buffer size for `-a text' */
139 #define DPV_DISPLAY_LIMIT 10 /* Max file progress lines */
140 #define DPV_PPROMPT_MAX 4096 /* Buffer size for `-p text' */
141 #define DPV_STATUS_FORMAT_MAX 80 /* Buffer size for `-u format' */
144 * Extra display information
146 #define DPV_STATUS_SOLO "%'10lli bytes read @ %'9.1f bytes/sec."
147 #define DPV_STATUS_MANY (DPV_STATUS_SOLO " [%i/%i busy/wait]")
152 #define DPV_DONE_DEFAULT "Done"
153 #define DPV_FAIL_DEFAULT "Fail"
154 #define DPV_PENDING_DEFAULT "Pending"
158 int dpv(struct dpv_config *_config, struct dpv_file_node *_file_list);
161 #endif /* !_DPV_H_ */