/*-1* Copyright (c) 2013-2016 Devin Teske <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#ifndef _DPV_H_27#define _DPV_H_2829#include <sys/types.h>3031#ifndef TRUE32#define TRUE 133#endif34#ifndef FALSE35#define FALSE 036#endif3738/* localeconv(3) */39#define LC_NUMERIC_DEFAULT "en_US.ISO8859-1"4041/* Data to process */42extern long long dpv_overall_read;4344/* Interrupt flag */45extern int dpv_interrupt; /* Set to TRUE in interrupt handler */46extern int dpv_abort; /* Set to true in callback to abort */4748/*49* Display types for use with display_type member of dpv_config structure50*/51enum dpv_display {52DPV_DISPLAY_LIBDIALOG = 0, /* Display using dialog(3) (default) */53DPV_DISPLAY_STDOUT, /* Display on stdout */54DPV_DISPLAY_DIALOG, /* Display using spawned dialog(1) */55DPV_DISPLAY_XDIALOG, /* Display using spawned Xdialog(1) */56};5758/*59* Output types for use with output_type member of dpv_config structure60*/61enum dpv_output {62DPV_OUTPUT_NONE = 0, /* No output (default) */63DPV_OUTPUT_FILE, /* Read `output' member as file path */64DPV_OUTPUT_SHELL, /* Read `output' member as shell cmd */65};6667/*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 the70* action callback of dpv_config structure, you'll end callbacks for that71* dpv_file_node.72*/73enum dpv_status {74DPV_STATUS_RUNNING = 0, /* Running (default) */75DPV_STATUS_DONE, /* Completed */76DPV_STATUS_FAILED, /* Oops, something went wrong */77};7879/*80* Anatomy of file option; pass an array of these as dpv() file_list argument81* terminated with a NULL pointer.82*/83struct dpv_file_node {84enum dpv_status status; /* status of read operation */85char *msg; /* display instead of "Done/Fail" */86char *name; /* name of file to read */87char *path; /* path to file */88long long length; /* expected size */89long long read; /* number units read (e.g., bytes) */90struct dpv_file_node *next; /* pointer to next (end with NULL) */91};9293/*94* Anatomy of config option to pass as dpv() config argument95*/96struct dpv_config {97uint8_t keep_tite; /* Prevent visually distracting exit */98enum dpv_display display_type; /* Display (default TYPE_LIBDIALOG) */99enum dpv_output output_type; /* Output (default TYPE_NONE) */100int debug; /* Enable debugging output on stderr */101int display_limit; /* Files per `page'. Default -1 */102int label_size; /* Label size. Default 28 */103int pbar_size; /* Mini-progress size. See dpv(3) */104int dialog_updates_per_second; /* Progress updates/s. Default 16 */105int status_updates_per_second; /* dialog(3) status updates/second.106* Default 2 */107uint16_t options; /* Special options. Default 0 */108char *title; /* widget title */109char *backtitle; /* Widget backtitle */110char *aprompt; /* Prompt append. Default NULL */111char *pprompt; /* Prompt prefix. Default NULL */112char *msg_done; /* Progress text. Default `Done' */113char *msg_fail; /* Progress text. Default `Fail' */114char *msg_pending; /* Progress text. Default `Pending' */115char *output; /* Output format string; see dpv(3) */116const char *status_solo; /* dialog(3) solo-status format.117* Default DPV_STATUS_SOLO */118const char *status_many; /* dialog(3) many-status format.119* Default DPV_STATUS_MANY */120121/*122* Function pointer; action to perform data transfer123*/124int (*action)(struct dpv_file_node *file, int out);125};126127/*128* Macros for dpv() options bitmask argument129*/130#define DPV_TEST_MODE 0x0001 /* Test mode (fake reading data) */131#define DPV_WIDE_MODE 0x0002 /* prefix/append bump dialog width */132#define DPV_NO_LABELS 0x0004 /* Hide file_node.name labels */133#define DPV_USE_COLOR 0x0008 /* Override to force color output */134#define DPV_NO_OVERRUN 0x0010 /* Stop transfers when they hit 100% */135136/*137* Limits (modify with extreme care)138*/139#define DPV_APROMPT_MAX 4096 /* Buffer size for `-a text' */140#define DPV_DISPLAY_LIMIT 10 /* Max file progress lines */141#define DPV_PPROMPT_MAX 4096 /* Buffer size for `-p text' */142#define DPV_STATUS_FORMAT_MAX 80 /* Buffer size for `-u format' */143144/*145* Extra display information146*/147#define DPV_STATUS_SOLO "%'10lli bytes read @ %'9.1f bytes/sec."148#define DPV_STATUS_MANY (DPV_STATUS_SOLO " [%i/%i busy/wait]")149150/*151* Strings152*/153#define DPV_DONE_DEFAULT "Done"154#define DPV_FAIL_DEFAULT "Fail"155#define DPV_PENDING_DEFAULT "Pending"156157__BEGIN_DECLS158void dpv_free(void);159int dpv(struct dpv_config *_config, struct dpv_file_node *_file_list);160__END_DECLS161162#endif /* !_DPV_H_ */163164165