1 /* 2 * Functions used across the program. 3 */ 4 5 #ifndef _PV_H 6 #define _PV_H 1 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 /* 13 * Opaque structure for PV internal state. 14 */ 15 struct pvstate_s; 16 typedef struct pvstate_s *pvstate_t; 17 18 /* 19 * Valid number types for pv_getnum_check(). 20 */ 21 typedef enum { 22 PV_NUMTYPE_INTEGER, 23 PV_NUMTYPE_DOUBLE 24 } pv_numtype_t; 25 26 27 /* 28 * Simple string functions for processing numbers. 29 */ 30 31 /* 32 * Return the given string converted to a double. 33 */ 34 extern double pv_getnum_d(const char *); 35 36 /* 37 * Return the given string converted to an unsigned integer. 38 */ 39 extern unsigned int pv_getnum_ui(const char *); 40 41 /* 42 * Return the given string converted to an unsigned long long. 43 */ 44 extern unsigned long long pv_getnum_ull(const char *); 45 46 /* 47 * Return zero if the given string is a number of the given type. NB an 48 * integer is both a valid integer and a valid double. 49 */ 50 extern int pv_getnum_check(const char *, pv_numtype_t); 51 52 /* 53 * Main PV functions. 54 */ 55 56 /* 57 * Create a new state structure, and return it, or 0 (NULL) on error. 58 */ 59 extern pvstate_t pv_state_alloc(const char *); 60 61 /* 62 * Set the formatting string, given a set of old-style formatting options. 63 */ 64 extern void pv_state_set_format(pvstate_t state, bool progress, 65 bool timer, bool eta, 66 bool fineta, bool rate, 67 bool average_rate, bool bytes, 68 bool bufpercent, 69 unsigned int lastwritten, 70 const char *name); 71 72 /* 73 * Set the various options. 74 */ 75 extern void pv_state_force_set(pvstate_t, bool); 76 extern void pv_state_cursor_set(pvstate_t, bool); 77 extern void pv_state_numeric_set(pvstate_t, bool); 78 extern void pv_state_wait_set(pvstate_t, bool); 79 extern void pv_state_delay_start_set(pvstate_t, double); 80 extern void pv_state_linemode_set(pvstate_t, bool); 81 extern void pv_state_null_set(pvstate_t, bool); 82 extern void pv_state_no_op_set(pvstate_t, bool); 83 extern void pv_state_skip_errors_set(pvstate_t, unsigned int); 84 extern void pv_state_stop_at_size_set(pvstate_t, bool); 85 extern void pv_state_rate_limit_set(pvstate_t, unsigned long long); 86 extern void pv_state_target_buffer_size_set(pvstate_t, unsigned long long); 87 extern void pv_state_no_splice_set(pvstate_t, bool); 88 extern void pv_state_size_set(pvstate_t, unsigned long long); 89 extern void pv_state_interval_set(pvstate_t, double); 90 extern void pv_state_width_set(pvstate_t, unsigned int); 91 extern void pv_state_height_set(pvstate_t, unsigned int); 92 extern void pv_state_name_set(pvstate_t, const char *); 93 extern void pv_state_format_string_set(pvstate_t, const char *); 94 extern void pv_state_watch_pid_set(pvstate_t, unsigned int); 95 extern void pv_state_watch_fd_set(pvstate_t, int); 96 97 extern void pv_state_inputfiles(pvstate_t, int, const char **); 98 99 /* 100 * Work out whether we are in the foreground. 101 */ 102 extern bool pv_in_foreground(void); 103 104 /* 105 * Work out the terminal size. 106 */ 107 extern void pv_screensize(unsigned int *width, unsigned int *height); 108 109 /* 110 * Calculate the total size of all input files. 111 */ 112 extern unsigned long long pv_calc_total_size(pvstate_t); 113 114 /* 115 * Set up signal handlers ready for running the main loop. 116 */ 117 extern void pv_sig_init(pvstate_t); 118 119 /* 120 * Enter the main transfer loop, transferring all input files to the output. 121 */ 122 extern int pv_main_loop(pvstate_t); 123 124 /* 125 * Watch the selected file descriptor of the selected process. 126 */ 127 extern int pv_watchfd_loop(pvstate_t); 128 129 /* 130 * Watch the selected process. 131 */ 132 extern int pv_watchpid_loop(pvstate_t); 133 134 /* 135 * Shut down signal handlers after running the main loop. 136 */ 137 extern void pv_sig_fini(pvstate_t); 138 139 /* 140 * Free a state structure, after which it can no longer be used. 141 */ 142 extern void pv_state_free(pvstate_t); 143 144 145 #ifdef ENABLE_DEBUGGING 146 # if __STDC_VERSION__ < 199901L 147 # if __GNUC__ >= 2 148 # define __func__ __FUNCTION__ 149 # else 150 # define __func__ "<unknown>" 151 # endif 152 # endif 153 # define debug(x,...) debugging_output(__func__, __FILE__, __LINE__, x, __VA_ARGS__) 154 #else 155 # define debug(x,...) do { } while (0) 156 #endif 157 158 /* 159 * Output debugging information, if debugging is enabled. 160 */ 161 void debugging_output(const char *, const char *, int, const char *, ...); 162 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 #endif /* _PV_H */ 169 170 /* EOF */ 171