00001 #include "config.h"
00002
00003 #include "headers.h"
00004 #include "error.h"
00005 #include "fd.h"
00006 #include "io.h"
00007 #include "display.h"
00008 #include "args.h"
00009
00010 #ifndef HAVE_SPRINTF
00011 # error *** ERROR: This system does not have sprintf()
00012 #endif
00013
00014 struct _options_list {
00015 char *short_option1;
00016 char *short_option2;
00017 char *long_option1;
00018 char *long_option2;
00019 char *rc_option;
00020 char *arg_description;
00021 char *description;
00022 int (*cl_func)(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00023 int (*rc_func)(FILE *ferr, char *filename, int line, char *tag, char *value);
00024 };
00025
00026 typedef struct _options_list options_list;
00027
00028 struct _colors_list {
00029 char *name;
00030 char *code;
00031 };
00032
00033 typedef struct _colors_list colors_list;
00034
00035
00036 char _parsing_blocks = 0;
00037
00038 int parse_infile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00039 int parse_outfile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00040 int parse_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00041 int parse_completed_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00042 int parse_throttle_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00043 int parse_buffer_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00044 int parse_block_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00045 int parse_interval_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00046 int parse_timeout_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00047 int parse_kilo_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00048 int parse_width_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00049 int parse_width_minus_one_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00050 int parse_height_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00051 int parse_height_minus_one_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00052 int parse_twiddle_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00053 int parse_count_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00054 int parse_throughput_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00055 int parse_time_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00056 int parse_elapsed_only_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00057 int parse_percent_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00058 int parse_bar_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00059 int parse_summary_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00060 int parse_ansi_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00061 int parse_displays_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00062 int parse_help_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00063 int parse_version_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00064 int parse_throughput_bits_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00065 int parse_count_bits_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00066 int parse_title_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00067 int parse_display_title_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00068 int parse_total_percent_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00069
00070 int parse_space_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00071 int parse_twiddle_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00072 int parse_twiddle_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00073 int parse_twiddle_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00074 int parse_title_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00075 int parse_title_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00076 int parse_title_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00077 int parse_count_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00078 int parse_count_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00079 int parse_count_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00080 int parse_throughput_label_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00081 int parse_throughput_label_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00082 int parse_throughput_label_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00083 int parse_throughput_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00084 int parse_throughput_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00085 int parse_throughput_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00086 int parse_time_label_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00087 int parse_time_label_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00088 int parse_time_label_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00089 int parse_time_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00090 int parse_time_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00091 int parse_time_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00092 int parse_percent_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00093 int parse_percent_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00094 int parse_percent_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00095 int parse_bar_openbrace_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00096 int parse_bar_closebrace_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00097 int parse_bar_complete_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00098 int parse_bar_incomplete_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00099 int parse_barbrace_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00100 int parse_barbrace_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00101 int parse_barbrace_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00102 int parse_bar_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00103 int parse_bar_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00104 int parse_bar_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00105 int parse_infofile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00106 int parse_display_numeric_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00107 int parse_display_wait_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num);
00108
00109 int parse_throttle_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00110 int parse_buffer_size_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00111 int parse_block_size_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00112 int parse_interval_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00113 int parse_timeout_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00114 int parse_kilo_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00115 int parse_width_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00116 int parse_width_minus_one_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00117 int parse_height_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00118 int parse_height_minus_one_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00119 int parse_twiddle_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00120 int parse_count_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00121 int parse_throughput_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00122 int parse_time_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00123 int parse_elapsed_only_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00124 int parse_percent_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00125 int parse_bar_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00126 int parse_summary_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00127 int parse_ansi_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00128 int parse_throughput_bits_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00129 int parse_count_bits_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00130 int parse_title_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00131 int parse_display_title_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00132 int parse_total_percent_rc(FILE *ferr, char* filename, int line, char *tag, char *value);
00133
00134 int parse_space_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00135 int parse_twiddle_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00136 int parse_twiddle_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00137 int parse_twiddle_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00138 int parse_title_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00139 int parse_title_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00140 int parse_title_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00141 int parse_count_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00142 int parse_count_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00143 int parse_count_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00144 int parse_throughput_label_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00145 int parse_throughput_label_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00146 int parse_throughput_label_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00147 int parse_throughput_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00148 int parse_throughput_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00149 int parse_throughput_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00150 int parse_time_label_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00151 int parse_time_label_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00152 int parse_time_label_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00153 int parse_time_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00154 int parse_time_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00155 int parse_time_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00156 int parse_percent_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00157 int parse_percent_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00158 int parse_percent_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00159 int parse_bar_openbrace_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00160 int parse_bar_closebrace_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00161 int parse_bar_complete_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00162 int parse_bar_incomplete_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00163 int parse_barbrace_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00164 int parse_barbrace_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00165 int parse_barbrace_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00166 int parse_bar_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00167 int parse_bar_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00168 int parse_bar_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00169 int parse_infofile_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00170 int parse_display_numeric_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00171 int parse_display_wait_rc(FILE *ferr, char *filename, int line, char *tag, char *value);
00172
00173 options_list options[] = {
00174 {
00175 "-if", 0, "--in-file", 0, 0, "<file>",
00176 "Read input from <file>. Default: stdin",
00177 parse_infile_commandline,
00178 0
00179 },
00180 {
00181 "-of", 0, "--out-file", 0, 0, "<file>",
00182 "Write output to <file>. Default: stdout",
00183 parse_outfile_commandline,
00184 0
00185 },
00186 {
00187 "-s", 0, "--size", 0, 0, "<size>",
00188 "Expect an input stream of <size> bytes.",
00189 parse_size_commandline,
00190 0
00191 },
00192 {
00193 "-c", 0, "--completed", 0, 0, "<size>",
00194 "Expect to continue an input stream at <size> bytes.",
00195 parse_completed_commandline,
00196 0
00197 },
00198 {
00199 "-th", 0, "--throttle", 0, "throttle", "<rate>",
00200 "Throttle I/O rate to <rate> bytes per second.",
00201 parse_throttle_commandline,
00202 parse_throttle_rc,
00203 },
00204 {
00205 "-bs", 0, "--buffer-size", 0, "buffer-size", "<size>",
00206 "Allocate an I/O buffer of <size> bytes. Default: 1024",
00207 parse_buffer_size_commandline,
00208 parse_buffer_size_rc
00209 },
00210 {
00211 "-bl", 0, "--block-size", 0, "block-size", "<size>",
00212 "Assume blocks of <size> bytes when parsing sizes in blocks. Default: 1024",
00213 parse_block_size_commandline,
00214 parse_block_size_rc
00215 },
00216 {
00217 "-i", 0, "--interval", 0, "interval", "<secs>",
00218 "Update the display every <secs> seconds. Default: 1",
00219 parse_interval_commandline,
00220 parse_interval_rc
00221 },
00222 {
00223 "-t", 0, "--timeout", 0, "timeout", "<usecs>",
00224 "Wait <usecs> microseconds for a change in I/O. Default: 250000",
00225 parse_timeout_commandline,
00226 parse_timeout_rc
00227 },
00228 {
00229 "-k", 0, "--kilo", 0, "kilobyte", "1000|1024",
00230 "Use 1000 or 1024 as the size of a kilobyte. Default: 1024",
00231 parse_kilo_commandline,
00232 parse_kilo_rc
00233 },
00234 {
00235 "-sw", 0, "--screen-width", 0, "screen-width", "<width>",
00236 "Assume a screen width of <width> characters. Default: 80",
00237 parse_width_commandline,
00238 parse_width_rc
00239 },
00240 {
00241 "-sw-1", "-sw-0", "--screen-width-minus-one", "--screen-width-minus-zero", "screen-width-minus-one", 0,
00242 "Use one character less than the maximum screen width. Default: off",
00243 parse_width_minus_one_commandline,
00244 parse_width_minus_one_rc
00245 },
00246 {
00247 "-sh", 0, "--screen-height", 0, "screen-height", "<height>",
00248 "Assume a screen height of <height> characters. Default: 24",
00249 parse_height_commandline,
00250 parse_height_rc
00251 },
00252 {
00253 "-sh-1", "-sh-0", "--screen-height-minus-one", "--screen-height-minus-zero", "screen-width-minus-one", 0,
00254 "Use one character less than the maximum screen height. Default: off",
00255 parse_height_minus_one_commandline,
00256 parse_height_minus_one_rc
00257 },
00258 {
00259 "-ti", 0, "--title", 0, "title", "<string>",
00260 "Title string to be displayed in the status line.",
00261 parse_title_commandline,
00262 parse_title_rc
00263 },
00264 {
00265 "-dti", "-nti", "--display-title", "--no-title", "display-title", 0,
00266 "Display title string. Default: on",
00267 parse_display_title_commandline,
00268 parse_display_title_rc
00269 },
00270 {
00271 "-dtw", "-ntw", "--display-twiddle", "--no-twiddle", "display-twiddle", 0,
00272 "Turn on/off the twiddle in the display. Default: on",
00273 parse_twiddle_commandline,
00274 parse_twiddle_rc
00275 },
00276 {
00277 "-dc", "-nc", "--display-count", "--no-count", "display-count", 0,
00278 "Turn on/off the data count in the display. Default: on",
00279 parse_count_commandline,
00280 parse_count_rc
00281 },
00282 {
00283 "-dcb", "-ncb", "--display-count-bits", "--no-count-bits", "display-count-bits", 0,
00284 "Display the data count as bits instead of bytes. Default: off",
00285 parse_count_bits_commandline,
00286 parse_count_bits_rc,
00287 },
00288 {
00289 "-dth", "-nth", "--display-throughput", "--no-throughput", "display-throughput", 0,
00290 "Turn on/off the data throughput in the display. Default: on",
00291 parse_throughput_commandline,
00292 parse_throughput_rc
00293 },
00294 {
00295 "-dthb", "-nthb", "--display-throughput-bits", "--no-throughput-bits", "display-throughput-bits", 0,
00296 "Display throughput as bits/sec instead of bytes/sec. Default: off",
00297 parse_throughput_bits_commandline,
00298 parse_throughput_bits_rc,
00299 },
00300 {
00301 "-dt", "-nt", "--display-time", "--no-time", "display-time", 0,
00302 "Turn on/off the time in the display. Default: on",
00303 parse_time_commandline,
00304 parse_time_rc
00305 },
00306 {
00307 "-de", "-ne", "--display-elapsed-only", "--no-elapsed-only", "display-elapsed-only", 0,
00308 "Turn on/off displaying time as elapsed only (no eta). Default: off",
00309 parse_elapsed_only_commandline,
00310 parse_elapsed_only_rc
00311 },
00312 {
00313 "-dp", "-np", "--display-percent", "--no-percent", "display-percent", 0,
00314 "Turn on/off the percent complete in the display. Default: on",
00315 parse_percent_commandline,
00316 parse_percent_rc
00317 },
00318 {
00319 "-db", "-nb", "--display-bar", "--no-bar", "display-bar", 0,
00320 "Turn on/off the progress bar in the display. Default: on",
00321 parse_bar_commandline,
00322 parse_bar_rc
00323 },
00324 {
00325 "-dtp", "-ntp", "--display-total-percent", "--no-total-percent", "display-total-percent", 0,
00326 "Turn on/off the percent of expected data in the summary. Default: on",
00327 parse_total_percent_commandline,
00328 parse_total_percent_rc
00329 },
00330 {
00331 "-ds", "-ns", "--display-summary", "--no-summary", "display-summary", 0,
00332 "Turn on/off the summary information when complete. Default: on",
00333 parse_summary_commandline,
00334 parse_summary_rc
00335 },
00336 {
00337 "-da", "-dn", "--display-all", "--display-none", 0, 0,
00338 "Turn on/off all displays. Default: all on",
00339 parse_displays_commandline,
00340 0
00341 },
00342 {
00343 "-dan", "-nan", "--display-ansi", "--no-ansi", "display-ansi", 0,
00344 "Turn on/off the use of ansi color codes in the display. Default is: off",
00345 parse_ansi_commandline,
00346 parse_ansi_rc
00347 },
00348
00349 {
00350 "-spbg", 0, "--space-background", 0, "space-background", "<color>",
00351 "Use <color> as the background for spacing between display objects.",
00352 parse_space_bg_color_commandline,
00353 parse_space_bg_color_rc
00354 },
00355
00356 {
00357 "-twfg", 0, "--twiddle-foreground", 0, "twiddle-foreground", "<color>",
00358 "Use <color> as the twiddle foreground.",
00359 parse_twiddle_fg_color_commandline,
00360 parse_twiddle_fg_color_rc
00361 },
00362 {
00363 "-twbg", 0, "--twiddle-background", 0, "twiddle-background", "<color>",
00364 "Use <color> as the twiddle background.",
00365 parse_twiddle_bg_color_commandline,
00366 parse_twiddle_bg_color_rc
00367 },
00368 {
00369 "-twb", "-twn", "--twiddle-bold", "--twiddle-normal", "twiddle-bold", 0,
00370 "Display the twiddle ansi foreground color in bold or normal.",
00371 parse_twiddle_fg_bold_commandline,
00372 parse_twiddle_fg_bold_rc
00373 },
00374
00375 {
00376 "-tifg", 0, "--title-foreground", 0, "title-foreground", "<color>",
00377 "Use <color> as the title foreground.",
00378 parse_title_fg_color_commandline,
00379 parse_title_fg_color_rc
00380 },
00381 {
00382 "-tibg", 0, "--title-background", 0, "title-background", "<color>",
00383 "Use <color> as the title background.",
00384 parse_title_bg_color_commandline,
00385 parse_title_bg_color_rc
00386 },
00387 {
00388 "-tib", "-tin", "--title-bold", "--title-normal", "title-bold", 0,
00389 "Display the title ansi foreground color in bold or normal.",
00390 parse_title_fg_bold_commandline,
00391 parse_title_fg_bold_rc
00392 },
00393
00394 {
00395 "-cfg", 0, "--count-foreground", 0, "count-foreground", "<color>",
00396 "Use <color> as the count foreground.",
00397 parse_count_fg_color_commandline,
00398 parse_count_fg_color_rc
00399 },
00400 {
00401 "-cbg", 0, "--count-background", 0, "count-background", "<color>",
00402 "Use <color> as the count background.",
00403 parse_count_bg_color_commandline,
00404 parse_count_bg_color_rc
00405 },
00406 {
00407 "-cb", "-cn", "--count-bold", "--count-normal", "count-bold", 0,
00408 "Display the count ansi foreground color in bold or normal.",
00409 parse_count_fg_bold_commandline,
00410 parse_count_fg_bold_rc
00411 },
00412
00413 {
00414 "-thfg", 0, "--throughput-foreground", 0, "throughput-foreground", "<color>",
00415 "Use <color> as the throughput foreground.",
00416 parse_throughput_fg_color_commandline,
00417 parse_throughput_fg_color_rc
00418 },
00419 {
00420 "-thbg", 0, "--throughput-background", 0, "throughput-background", "<color>",
00421 "Use <color> as the throughput background.",
00422 parse_throughput_bg_color_commandline,
00423 parse_throughput_bg_color_rc
00424 },
00425 {
00426 "-thb", "-thn", "--throughput-bold", "--throughput-normal", "throughput-bold", 0,
00427 "Display the throughput ansi foreground color in bold or normal.",
00428 parse_throughput_fg_bold_commandline,
00429 parse_throughput_fg_bold_rc
00430 },
00431
00432 {
00433 "-thlfg", 0, "--throughput-label-foreground", 0, "throughput-label-foreground", "<color>",
00434 "Use <color> as the throughput label foreground.",
00435 parse_throughput_label_fg_color_commandline,
00436 parse_throughput_label_fg_color_rc
00437 },
00438 {
00439 "-thlbg", 0, "--throughput-label-background", 0, "throughput-label-background", "<color>",
00440 "Use <color> as the throughput label background.",
00441 parse_throughput_label_bg_color_commandline,
00442 parse_throughput_label_bg_color_rc
00443 },
00444 {
00445 "-thlb", "-thln", "--throughput-label-bold", "--throughput-label-normal", "throughput-label-bold", 0,
00446 "Display the throughput label ansi foreground color in bold or normal.",
00447 parse_throughput_label_fg_bold_commandline,
00448 parse_throughput_label_fg_bold_rc
00449 },
00450
00451 {
00452 "-tfg", 0, "--time-foreground", 0, "time-foreground", "<color>",
00453 "Use <color> as the time foreground.",
00454 parse_time_fg_color_commandline,
00455 parse_time_fg_color_rc
00456 },
00457 {
00458 "-tbg", 0, "--time-background", 0, "time-background", "<color>",
00459 "Use <color> as the time background.",
00460 parse_time_bg_color_commandline,
00461 parse_time_bg_color_rc
00462 },
00463 {
00464 "-tb", "-tn", "--time-bold", "--time-normal", "time-bold", 0,
00465 "Display the time ansi foreground color in bold or normal.",
00466 parse_time_fg_bold_commandline,
00467 parse_time_fg_bold_rc
00468 },
00469
00470 {
00471 "-tlfg", 0, "--time-label-foreground", 0, "time-label-foreground", "<color>",
00472 "Use <color> as the time label foreground.",
00473 parse_time_label_fg_color_commandline,
00474 parse_time_label_fg_color_rc
00475 },
00476 {
00477 "-tlbg", 0, "--time-label-background", 0, "time-label-background", "<color>",
00478 "Use <color> as the time label background.",
00479 parse_time_label_bg_color_commandline,
00480 parse_time_label_bg_color_rc
00481 },
00482 {
00483 "-tlb", "-tln", "--time-label-bold", "--time-label-normal", "time-label-bold", 0,
00484 "Display the time label ansi foreground color in bold or normal.",
00485 parse_time_label_fg_bold_commandline,
00486 parse_time_label_fg_bold_rc
00487 },
00488
00489 {
00490 "-pfg", 0, "--percent-foreground", 0, "percent-foreground", "<color>",
00491 "Use <color> as the percent foreground.",
00492 parse_percent_fg_color_commandline,
00493 parse_percent_fg_color_rc
00494 },
00495 {
00496 "-pbg", 0, "--percent-background", 0, "percent-background", "<color>",
00497 "Use <color> as the percent background.",
00498 parse_percent_bg_color_commandline,
00499 parse_percent_bg_color_rc
00500 },
00501 {
00502 "-pb", "-pn", "--percent-bold", "--percent-normal", "percent-bold", 0,
00503 "Display the percent ansi foreground color in bold or normal.",
00504 parse_percent_fg_bold_commandline,
00505 parse_percent_fg_bold_rc
00506 },
00507
00508 {
00509 "-bobc", 0, "--bar-openbrace-char", 0, "bar-openbrace-char", "<char>",
00510 "Use <char> as the open brace character on the progress bar.",
00511 parse_bar_openbrace_char_commandline,
00512 parse_bar_openbrace_char_rc
00513 },
00514 {
00515 "-bcbc", 0, "--bar-closebrace-char", 0, "bar-closebrace-char", "<char>",
00516 "Use <char> as the close brace character on the progress bar.",
00517 parse_bar_closebrace_char_commandline,
00518 parse_bar_closebrace_char_rc
00519 },
00520 {
00521 "-bcc", 0, "--bar-complete-char", 0, "bar-complete-char", "<char>",
00522 "Use <char> as the completed character on the progress bar.",
00523 parse_bar_complete_char_commandline,
00524 parse_bar_complete_char_rc
00525 },
00526 {
00527 "-bic", 0, "--bar-incomplete-char", 0, "bar-incomplete-char", "<char>",
00528 "Use <char> as the completed character on the progress bar.",
00529 parse_bar_incomplete_char_commandline,
00530 parse_bar_incomplete_char_rc
00531 },
00532
00533 {
00534 "-bbfg", 0, "--bar-brace-foreground", 0, "bar-brace-foreground", "<color>",
00535 "Use <color> as the foreground color for the braces on the progress bar.",
00536 parse_barbrace_fg_color_commandline,
00537 parse_barbrace_fg_color_rc
00538 },
00539 {
00540 "-bbbg", 0, "--bar-brace-background", 0, "bar-brace-background", "<color>",
00541 "Use <color> as the background color for the braces on the progress bar.",
00542 parse_barbrace_bg_color_commandline,
00543 parse_barbrace_bg_color_rc
00544 },
00545 {
00546 "-bbb", "-bbn", "--bar-brace-bold", "--bar-brace-normal", "bar-brace-bold", 0,
00547 "Display the progress bar braces' ansi foreground color in bold or normal.",
00548 parse_barbrace_fg_bold_commandline,
00549 parse_barbrace_fg_bold_rc
00550 },
00551
00552 {
00553 "-bfg", 0, "--bar-foreground", 0, "bar-foreground", "<color>",
00554 "Use <color> as the foreground color for the progress bar.",
00555 parse_bar_fg_color_commandline,
00556 parse_bar_fg_color_rc
00557 },
00558 {
00559 "-bbg", 0, "--bar-background", 0, "bar-background", "<color>",
00560 "Use <color> as the background color for the progress bar.",
00561 parse_bar_bg_color_commandline,
00562 parse_bar_bg_color_rc
00563 },
00564 {
00565 "-bb", "-bn", "--bar-bold", "--bar-normal", "bar-bold", 0,
00566 "Display the progress bar ansi foreground color in bold or normal.",
00567 parse_bar_fg_bold_commandline,
00568 parse_bar_fg_bold_rc
00569 },
00570
00571 {
00572 "-inf", 0, "--info-file", 0, "info-file", 0,
00573 "Display the contents of an information file as data is copied.",
00574 parse_infofile_commandline,
00575 parse_infofile_rc
00576 },
00577
00578 {
00579 "-dnum", 0, "--display-numeric", 0, "display-numeric", 0,
00580 "Only display the percent complete, one integer per line.",
00581 parse_display_numeric_commandline,
00582 parse_display_numeric_rc
00583 },
00584
00585 {
00586 "-dw", 0, "--display-wait", 0, "display-wait", 0,
00587 "Wait for the fist byte of data before displaying anything.",
00588 parse_display_wait_commandline,
00589 parse_display_wait_rc
00590 },
00591
00592 {
00593 "-h", 0, "--help", 0, 0, 0,
00594 "Display this help text and exit.",
00595 parse_help_commandline,
00596 0
00597 },
00598 {
00599 "-v", 0, "--version", 0, 0, 0,
00600 "Display version and exit.",
00601 parse_version_commandline,
00602 0
00603 },
00604 { 0, 0, 0, 0, 0, 0, 0 }
00605 };
00606
00607 colors_list fg_colors[] = {
00608 { "black", "[30m" },
00609 { "red", "[31m" },
00610 { "green", "[32m" },
00611 { "yellow", "[33m" },
00612 { "blue", "[34m" },
00613 { "magenta", "[35m" },
00614 { "cyan", "[36m" },
00615 { "white", "[37m" },
00616 { 0, 0 }
00617 };
00618
00619 colors_list bg_colors[] = {
00620 { "black", "[40m" },
00621 { "red", "[41m" },
00622 { "green", "[42m" },
00623 { "yellow", "[43m" },
00624 { "blue", "[44m" },
00625 { "magenta", "[45m" },
00626 { "cyan", "[46m" },
00627 { "white", "[47m" },
00628 { 0, 0 }
00629 };
00630
00631 void version(FILE *out)
00632 {
00633 fprintf(out, "%s version %s\n", PACKAGE, VERSION);
00634 }
00635
00636 void help(FILE *out)
00637 {
00638 int o = 0;
00639 int screen_used = 0;
00640 char option_buffer[256];
00641
00642 fprintf(out, "Usage:\n");
00643 fprintf(out, "\n");
00644
00645
00646
00647
00648 fprintf(out, " bar ");
00649 screen_used = 7;
00650 for (o = 0; options[o].cl_func != 0; o++) {
00651 char *short_option1 = options[o].short_option1;
00652 char *short_option2 = options[o].short_option2;
00653 char *arg_description = options[o].arg_description;
00654
00655 sprintf(option_buffer, "[ %s%s%s%s%s ]",
00656 short_option1,
00657 (short_option2 != 0) ? "|" : "",
00658 (short_option2 != 0) ? short_option2 : "",
00659 (arg_description != 0) ? " " : "",
00660 (arg_description != 0) ? arg_description : ""
00661 );
00662 if (d.screen_width - screen_used < strlen(option_buffer)) {
00663 fprintf(out, "\n ");
00664 screen_used = 7;
00665 }
00666 fprintf(out, "%s", option_buffer);
00667 screen_used += strlen(option_buffer);
00668 }
00669
00670 fprintf(out, "\n");
00671 fprintf(out, "\n");
00672
00673
00674
00675
00676 fprintf(out, " bar ");
00677 screen_used = 7;
00678 for (o = 0; options[o].cl_func != 0; o++) {
00679 char *long_option1 = options[o].long_option1;
00680 char *long_option2 = options[o].long_option2;
00681 char *arg_description = options[o].arg_description;
00682
00683 sprintf(option_buffer, "[ %s%s%s%s%s ]",
00684 long_option1,
00685 (long_option2 != 0) ? "|" : "",
00686 (long_option2 != 0) ? long_option2 : "",
00687 (arg_description != 0) ? " " : "",
00688 (arg_description != 0) ? arg_description : ""
00689 );
00690 if (d.screen_width - screen_used < strlen(option_buffer)) {
00691 fprintf(out, "\n ");
00692 screen_used = 7;
00693 }
00694 fprintf(out, "%s", option_buffer);
00695 screen_used += strlen(option_buffer);
00696 }
00697
00698 fprintf(out, "\n");
00699 fprintf(out, "\n");
00700
00701
00702
00703
00704 for (o = 0; options[o].cl_func != 0; o++) {
00705 char *short_option1 = options[o].short_option1;
00706 char *short_option2 = options[o].short_option2;
00707 char *long_option1 = options[o].long_option1;
00708 char *long_option2 = options[o].long_option2;
00709 char *arg_description = options[o].arg_description;
00710 char *description = options[o].description;
00711
00712 fprintf(out, " %s %s\n",
00713 short_option1,
00714 (arg_description != 0) ? arg_description : ""
00715 );
00716 if (short_option2 != 0) {
00717 fprintf(out, " %s %s\n",
00718 short_option2,
00719 (arg_description != 0) ? arg_description : ""
00720 );
00721 }
00722 fprintf(out, " %s %s\n",
00723 long_option1,
00724 (arg_description != 0) ? arg_description : ""
00725 );
00726 if (long_option2 != 0) {
00727 fprintf(out, " %s %s\n",
00728 long_option2,
00729 (arg_description != 0) ? arg_description : ""
00730 );
00731 }
00732 fprintf(out, "\n");
00733 fprintf(out, " %s\n", description);
00734 fprintf(out, "\n");
00735 }
00736 }
00737
00738 int isOpt(char *s)
00739 {
00740 int o = 0;
00741
00742 while (options[o].cl_func != 0) {
00743 if (strcmp(s, options[o].short_option1) == 0)
00744 return(o);
00745 if ((options[o].short_option2 != 0)
00746 && (strcmp(s, options[o].short_option2) == 0))
00747 return(o);
00748 if (strcmp(s, options[o].long_option1) == 0)
00749 return(o);
00750 if ((options[o].long_option2 != 0)
00751 && (strcmp(s, options[o].long_option2) == 0))
00752 return(o);
00753 if ((options[o].rc_option != 0)
00754 && (strcasecmp(s, options[o].rc_option) == 0))
00755 return(o);
00756 o++;
00757 }
00758 return(-1);
00759 }
00760
00761 int safe_add(uint64 *n, uint64 a)
00762 {
00763 uint64 t = *n;
00764
00765 if (MAX_UINT64 - t < a)
00766 return(1);
00767 t += a;
00768
00769
00770 if (t < *n)
00771 return(1);
00772 *n = t;
00773 return(0);
00774 }
00775
00776 int safe_mul(uint64 *n, uint64 x)
00777 {
00778 uint64 a1, a2;
00779 uint64 t = 0;
00780 uint64 multiplier;
00781
00782 if (x < *n) {
00783 a1 = *n;
00784 a2 = x;
00785 }
00786 else {
00787 a2 = *n;
00788 a1 = x;
00789 }
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 multiplier = MAX_SAFE_MULTIPLIER;
00801 while (a2 > 0) {
00802 while (multiplier > a2)
00803 multiplier /= 10;
00804 if (safe_add(&t, a1*multiplier) != 0)
00805 return(1);
00806 a2 -= multiplier;
00807 }
00808 *n = t;
00809 return(0);
00810 }
00811
00812 int parse_char(FILE *ferr, char *s, char *c)
00813 {
00814 char ch = s[0];
00815
00816 if (strlen(s) == 0)
00817 return(0);
00818
00819 if (ch == '\0')
00820 return(0);
00821
00822 if (!isgraph(ch) && !isspace(ch)) {
00823 print_error(ferr, "Could not parse character: 0x%x (hex), %d (decimal)", ch, ch);
00824 print_esup(ferr, "Character must be pritable");
00825 return(1);
00826 }
00827
00828 *c = ch;
00829 return(0);
00830 }
00831
00832 int parse_num(FILE *ferr, char *s, uint64 *n, uint64 min, uint64 max)
00833 {
00834 char *ptr_decimal = 0;
00835 char *ptr_unit = 0;
00836 char *ptr_start = 0;
00837 char *ptr_end = 0;
00838 char *ptr = 0;
00839 uint64 w = 0;
00840 uint64 f = 0;
00841 uint64 unit_multiplier = 1;
00842 uint64 multiplier = 0;
00843 uint64 tmp = 0;
00844 uint64 new_n = 0;
00845 size_t num_whole_part = 0;
00846 size_t num_fractional_part = 0;
00847
00848 *n = 0;
00849
00850 if (strlen(s) == 0)
00851 return(0);
00852
00853 ptr_decimal = s;
00854 while ((*ptr_decimal != '\0') && (*ptr_decimal != '.'))
00855 ptr_decimal++;
00856
00857 ptr_unit = s;
00858 while ((*ptr_unit != '\0') && (isdigit((int)*ptr_unit) || (*ptr_unit == '.')))
00859 ptr_unit++;
00860 if ((*ptr_unit != '\0') && (*(ptr_unit+1) != '\0')) {
00861 print_error(ferr, "Could not parse number: %s", s);
00862 print_esup(ferr, "Unit multiplier parse error at: \"%s\"", ptr_unit);
00863 print_esup(ferr, "Unit multiplier should be the last character");
00864 return(1);
00865 }
00866
00867 if (*ptr_decimal != '\0') {
00868 num_whole_part = (size_t)(ptr_decimal - s);
00869 num_fractional_part = (size_t)(ptr_unit - ptr_decimal - 1);
00870 }
00871 else if (*ptr_unit != '\0') {
00872 num_whole_part = (size_t)(ptr_unit - s);
00873 }
00874 else {
00875 num_whole_part = strlen(s);
00876 }
00877
00878 if ((num_whole_part == 0) && (num_fractional_part == 0)) {
00879 print_error(ferr, "Could not parse number: %s", s);
00880 print_esup(ferr, "No digits found");
00881 return(1);
00882 }
00883
00884 switch (toupper(*ptr_unit)) {
00885 case '\0':
00886 break;
00887 case 'K':
00888 unit_multiplier *= (uint64)d.k;
00889 break;
00890 case 'M':
00891 unit_multiplier *= (uint64)d.k;
00892 unit_multiplier *= (uint64)d.k;
00893 break;
00894 case 'G':
00895 unit_multiplier *= (uint64)d.k;
00896 unit_multiplier *= (uint64)d.k;
00897 unit_multiplier *= (uint64)d.k;
00898 break;
00899 case 'T':
00900 unit_multiplier *= (uint64)d.k;
00901 unit_multiplier *= (uint64)d.k;
00902 unit_multiplier *= (uint64)d.k;
00903 unit_multiplier *= (uint64)d.k;
00904 break;
00905 case 'P':
00906 unit_multiplier *= (uint64)d.k;
00907 unit_multiplier *= (uint64)d.k;
00908 unit_multiplier *= (uint64)d.k;
00909 unit_multiplier *= (uint64)d.k;
00910 unit_multiplier *= (uint64)d.k;
00911 break;
00912 case 'E':
00913 unit_multiplier *= (uint64)d.k;
00914 unit_multiplier *= (uint64)d.k;
00915 unit_multiplier *= (uint64)d.k;
00916 unit_multiplier *= (uint64)d.k;
00917 unit_multiplier *= (uint64)d.k;
00918 unit_multiplier *= (uint64)d.k;
00919 break;
00920 case 'B':
00921 if (_parsing_blocks == 0) {
00922 unit_multiplier *= (uint64)io.block_size;
00923 }
00924 else {
00925 print_error(ferr, "Cannot specify block size in terms of blocks");
00926 print_esup(ferr, "Expected: 'k', 'm', 'g', 't', 'p', or 'e'");
00927 return(1);
00928 }
00929 break;
00930 default:
00931 print_error(ferr, "Cannot parse number: %s", s);
00932 print_esup(ferr, "Invalid unit multiplier: '%c'", *ptr_unit);
00933 print_esup(ferr, "Expected: 'b', 'k', 'm', 'g', 't', 'p', or 'e'");
00934 return(1);
00935 break;
00936 }
00937
00938 ptr_start = s;
00939 if (*ptr_decimal == '.')
00940 ptr_end = ptr_decimal;
00941 else
00942 ptr_end = ptr_unit;
00943
00944 multiplier = 1;
00945 if (ptr_start != ptr_end) {
00946 for (ptr = ptr_start+1; ptr != ptr_end; ptr++) {
00947 if (safe_mul(&multiplier, 10) != 0) {
00948 print_error(ferr, "Whole number precision error at: %s", ptr);
00949 print_esup(ferr, "Whole number portion too large");
00950 return(1);
00951 }
00952 }
00953 }
00954 for (ptr = ptr_start; ptr != ptr_end; ptr++) {
00955 tmp = (uint64)((*ptr) - '0');
00956 if (tmp != 0) {
00957 if (safe_mul(&tmp, multiplier) != 0) {
00958 print_error(ferr, "Multiplication overflow error");
00959 print_esup(ferr, "Could not parse number at: %s", ptr);
00960 return(1);
00961 }
00962 if (safe_add(&w, tmp) != 0) {
00963 print_error(ferr, "Addition overflow error");
00964 print_esup(ferr, "Could not parse number at: %s", ptr);
00965 return(1);
00966 }
00967 }
00968 multiplier /= 10;
00969 }
00970 if (safe_mul(&w, unit_multiplier) != 0) {
00971 print_error(ferr, "Multiplication overflow error");
00972 print_esup(ferr, "Number too large: %s", s);
00973 return(1);
00974 }
00975
00976 if (*ptr_decimal == '.') {
00977 ptr_start = ptr_decimal+1;
00978 ptr_end = ptr_unit;
00979 multiplier = 1;
00980 for (ptr = ptr_start; ptr != ptr_end; ptr++) {
00981 tmp = (*ptr) - '0';
00982 if (tmp != 0) {
00983 if (safe_mul(&tmp, unit_multiplier) != 0) {
00984 print_error(ferr, "Multiplication overflow error");
00985 print_esup(ferr, "Could not parse fraction at: %s", ptr);
00986 return(1);
00987 }
00988 tmp /= multiplier;
00989 tmp += 5;
00990 tmp /= 10;
00991 if (safe_add(&f, tmp) != 0) {
00992 print_error(ferr, "Addition overflow error");
00993 print_esup(ferr, "Could not parse fraction at: %s", ptr);
00994 }
00995 }
00996 if (safe_mul(&multiplier, 10) != 0) {
00997 print_error(ferr, "Multiplication overflow error");
00998 print_esup(ferr, "Could not parse fraction at: %s", ptr);
00999 return(1);
01000 }
01001 if (multiplier > unit_multiplier)
01002 break;
01003 }
01004 }
01005
01006 new_n = w;
01007 if (safe_add(&new_n, f) != 0) {
01008 print_error(ferr, "Addition overflow error");
01009 print_esup(ferr, "Number too large: %s", s);
01010 return(1);
01011 }
01012
01013 if (new_n < min) {
01014 print_error(ferr, "Number too small: %s", s);
01015 print_esup(ferr, "Value must be %llu or greater", UINT64_CTYPE(min));
01016 return(1);
01017 }
01018 if (new_n > max) {
01019 print_error(ferr, "Number too large: %s", s);
01020 print_esup(ferr, "Value must be %llu or less", UINT64_CTYPE(max));
01021 return(1);
01022 }
01023
01024 *n = new_n;
01025
01026 return(0);
01027 }
01028
01029 int parse_infile_value(FILE *ferr, char *value)
01030 {
01031 if (strcmp(value, "-") != 0) {
01032 io.in = open(value, O_RDONLY
01033 #ifdef O_LARGEFILE
01034 |O_LARGEFILE
01035 #endif
01036 );
01037 if (io.in < 0) {
01038 print_error(ferr, "Cannot open file for reading: %s", value);
01039 return(1);
01040 }
01041 if (fdIsFile(io.in) && fdFileSize(io.in, &io.total_size) == 0) {
01042 io.total_size_known = 1;
01043 }
01044 io.in_path = value;
01045 }
01046 return(0);
01047 }
01048
01049 int parse_infile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01050 {
01051 if ((*arg_num)+1 == argc) {
01052 print_error(ferr, "Missing filename after %s", argv[(*arg_num)]);
01053 return(1);
01054 }
01055 if (parse_infile_value(ferr, argv[(*arg_num)+1]) != 0)
01056 return(1);
01057 (*arg_num)++;
01058 return(0);
01059 }
01060
01061 int parse_outfile_value(FILE *ferr, char *value)
01062 {
01063 struct stat st;
01064 char str[4096] = { 0 };
01065 char copy_flag = 0;
01066 char *basename = 0;
01067
01068 if (stat(value, &st) == 0) {
01069 if (S_ISDIR(st.st_mode)) {
01070 if (io.in_path == 0) {
01071 print_error(ferr, "No input file specified");
01072 return(1);
01073 }
01074 basename = io.in_path + strlen(io.in_path);
01075 while ((basename != io.in_path) && (*basename != '/')) {
01076 basename--;
01077 }
01078 if (*basename == '/') {
01079 basename++;
01080 }
01081 if (strcpy(str,value) == 0) {
01082 print_error(ferr, "strcpy() failed constructing output filename");
01083 return(1);
01084 }
01085 if (strcat(str,"/") == 0) {
01086 print_error(ferr, "strcat() failed constructing output filename");
01087 return(1);
01088 }
01089 if (strcat(str,basename) == 0) {
01090 print_error(ferr, "strcat() failed constructing output filename");
01091 return(1);
01092 }
01093 value = str;
01094 copy_flag = 1;
01095 }
01096 }
01097 if (strcmp(value, "-") != 0) {
01098 io.out = open(value, O_WRONLY|O_CREAT
01099 #ifdef O_LARGEFILE
01100 |O_LARGEFILE
01101 #endif
01102 , S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
01103 if (io.out < 0) {
01104 print_error(ferr, "Cannot open file for writing: %s", value);
01105 return(1);
01106 }
01107 }
01108 if (copy_flag == 1) {
01109 if (chmod(str,st.st_mode) != 0) {
01110 print_error(ferr, "Cannot set file modes on output file: %s", value);
01111 }
01112 }
01113 return(0);
01114 }
01115
01116 int parse_outfile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01117 {
01118 if ((*arg_num)+1 == argc) {
01119 print_error(ferr, "Missing filename after %s", argv[(*arg_num)]);
01120 return(1);
01121 }
01122 if (parse_outfile_value(ferr, argv[(*arg_num)+1]) != 0)
01123 return(1);
01124 (*arg_num)++;
01125 return(0);
01126 }
01127
01128 int parse_size_value(FILE *ferr, char *value)
01129 {
01130 uint64 n = 0;
01131
01132 if (parse_num(ferr, value, &n, 0, MAX_UINT64) != 0) {
01133 return(1);
01134 }
01135 io.total_size = n;
01136 io.total_size_known = 1;
01137 return(0);
01138 }
01139
01140 int parse_completed_value(FILE *ferr, char *value)
01141 {
01142 uint64 n = 0;
01143
01144 if (parse_num(ferr, value, &n, 0, MAX_UINT64) != 0) {
01145 return(1);
01146 }
01147 io.total_read = n;
01148 io.total_write = n;
01149 io.continue_size = n;
01150 return(0);
01151 }
01152
01153 int parse_throttle_value(FILE *ferr, char *value)
01154 {
01155 uint64 n = 0;
01156
01157 if (parse_num(ferr, value, &n, 0, MAX_UINT64) != 0) {
01158 return(1);
01159 }
01160 io.throttle = n+1;
01161 return(0);
01162 }
01163
01164 int parse_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01165 {
01166 if ((*arg_num)+1 == argc) {
01167 print_error(ferr, "Missing size after %s", argv[(*arg_num)]);
01168 return(1);
01169 }
01170 parse_size_value(ferr, argv[(*arg_num)+1]);
01171 (*arg_num)++;
01172 return(0);
01173 }
01174
01175 int parse_completed_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01176 {
01177 if ((*arg_num)+1 == argc) {
01178 print_error(ferr, "Missing size after %s", argv[(*arg_num)]);
01179 return(1);
01180 }
01181 parse_completed_value(ferr, argv[(*arg_num)+1]);
01182 (*arg_num)++;
01183 return(0);
01184 }
01185
01186 int parse_throttle_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01187 {
01188 if ((*arg_num)+1 == argc) {
01189 print_error(ferr, "Missing rate after %s", argv[(*arg_num)]);
01190 return(1);
01191 }
01192 parse_throttle_value(ferr, argv[(*arg_num)+1]);
01193 (*arg_num)++;
01194 return(0);
01195 }
01196
01197 int parse_throttle_rc(FILE *ferr, char* filename, int line, char *tag, char *value)
01198 {
01199 if (parse_throttle_value(ferr, value) != 0) {
01200 print_esup(ferr, "In file: %s[%d]", filename, line);
01201 return(1);
01202 }
01203 return(0);
01204 }
01205
01206 int parse_buffer_size_value(FILE *ferr, char *value)
01207 {
01208 uint64 n = 0;
01209
01210 if (parse_num(ferr, value, &n, 1, MAX_SIZE_T) != 0) {
01211 return(1);
01212 }
01213 io.buffer_size = (size_t)n;
01214 return(0);
01215 }
01216
01217 int parse_buffer_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01218 {
01219 if ((*arg_num)+1 == argc) {
01220 print_error(ferr, "Missing size after %s", argv[(*arg_num)]);
01221 return(1);
01222 }
01223 parse_buffer_size_value(ferr, argv[(*arg_num)+1]);
01224 (*arg_num)++;
01225 return(0);
01226 }
01227
01228 int parse_buffer_size_rc(FILE *ferr, char* filename, int line, char *tag, char *value)
01229 {
01230 if (parse_buffer_size_value(ferr, value) != 0) {
01231 print_esup(ferr, "In file: %s[%d]", filename, line);
01232 return(1);
01233 }
01234 return(0);
01235 }
01236
01237 int parse_block_size_value(FILE *ferr, char *value)
01238 {
01239 uint64 n = 0;
01240 int r;
01241
01242 _parsing_blocks = 1;
01243 r = parse_num(ferr, value, &n, 1, MAX_SIZE_T);
01244 _parsing_blocks = 0;
01245 if (r != 0) {
01246 return(1);
01247 }
01248 io.block_size = (size_t)n;
01249 return(0);
01250 }
01251
01252 int parse_block_size_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01253 {
01254 if ((*arg_num)+1 == argc) {
01255 print_error(ferr, "Missing size after %s", argv[(*arg_num)]);
01256 return(1);
01257 }
01258 parse_block_size_value(ferr, argv[(*arg_num)+1]);
01259 (*arg_num)++;
01260 return(0);
01261 }
01262
01263 int parse_block_size_rc(FILE *ferr, char* filename, int line, char *tag, char *value)
01264 {
01265 if (parse_block_size_value(ferr, value) != 0) {
01266 print_esup(ferr, "In file: %s[%d]", filename, line);
01267 return(1);
01268 }
01269 return(0);
01270 }
01271
01272 int parse_interval_value(FILE *ferr, char *value)
01273 {
01274 int n = 0;
01275 char check[4096] = { 0 };
01276
01277 sscanf(value, "%d", &n);
01278 sprintf(check, "%d", n);
01279 if (strcmp(value, check) != 0) {
01280 print_error(ferr, "Type mismatch or number too large: %s", value);
01281 return(1);
01282 }
01283 if ((n < 1) || (n > 60*60*24)) {
01284 print_error(ferr, "Invalid display interval: %s", value);
01285 return(1);
01286 }
01287 d.display_interval = n;
01288 return(0);
01289 }
01290
01291 int parse_interval_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01292 {
01293 if ((*arg_num)+1 == argc) {
01294 print_error(ferr, "Missing seconds after %s", argv[(*arg_num)]);
01295 return(1);
01296 }
01297 if (parse_interval_value(ferr, argv[(*arg_num)+1]) != 0)
01298 print_esup(ferr, "Ignoring given interval");
01299 (*arg_num)++;
01300 return(0);
01301 }
01302
01303 int parse_interval_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01304 {
01305 if (parse_interval_value(ferr, value) != 0) {
01306 print_esup(ferr, "In file: %s[%d]", filename, line);
01307 return(1);
01308 }
01309 return(0);
01310 }
01311
01312 int parse_timeout_value(FILE *ferr, char *value)
01313 {
01314 unsigned long n = 0;
01315 char check[4096] = { 0 };
01316
01317 sscanf(value, "%lu", &n);
01318 sprintf(check, "%lu", n);
01319 if (strcmp(value, check) != 0) {
01320 print_error(ferr, "Type mismatch or number too large: %s", value);
01321 return(1);
01322 }
01323 if (n > 999999) {
01324 print_error(ferr, "Type mismatch or number too large: %s", value);
01325 return(1);
01326 }
01327 io.timeout = (uint32)n;
01328 return(0);
01329 }
01330
01331 int parse_timeout_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01332 {
01333 if ((*arg_num)+1 == argc) {
01334 print_error(ferr, "Missing microseconds after %s", argv[(*arg_num)]);
01335 return(1);
01336 }
01337 if (parse_timeout_value(ferr, argv[(*arg_num)+1]) != 0)
01338 print_esup(ferr, "Ignoring given timeout");
01339 (*arg_num)++;
01340 return(0);
01341 }
01342
01343 int parse_timeout_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01344 {
01345 if (parse_timeout_value(ferr, value) != 0) {
01346 print_esup(ferr, "In file: %s[%d]", filename, line);
01347 return(1);
01348 }
01349 return(0);
01350 }
01351
01352 int parse_kilo_value(FILE *ferr, char *value)
01353 {
01354 if (strcmp(value, "1000") == 0) {
01355 d.k = 1000;
01356 return(0);
01357 }
01358 if (strcmp(value, "1024") == 0) {
01359 d.k = 1024;
01360 return(0);
01361 }
01362 return(1);
01363 }
01364
01365 int parse_kilo_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01366 {
01367 if ((*arg_num)+1 == argc) {
01368 print_error(ferr, "Missing option after %s", argv[(*arg_num)]);
01369 return(1);
01370 }
01371 if (parse_kilo_value(ferr, argv[(*arg_num)+1]) != 0) {
01372 print_error(ferr, "Invalid option for %s: %s",
01373 argv[(*arg_num)], argv[(*arg_num)+1]);
01374 return(1);
01375 }
01376 (*arg_num)++;
01377 return(0);
01378 }
01379
01380 int parse_kilo_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01381 {
01382 if (parse_kilo_value(ferr, value) != 0) {
01383 print_esup(ferr, "In file: %s[%d]", filename, line);
01384 return(1);
01385 }
01386 return(0);
01387 }
01388
01389 int parse_width_value(FILE *ferr, char *value)
01390 {
01391 int n = 0;
01392
01393 sscanf(value, "%d", &n);
01394 if (n < 1) {
01395 print_error(ferr, "Invalid screen width: %s", value);
01396 return(1);
01397 }
01398 d.screen_width = n;
01399 d.manual_width = 1;
01400 return(0);
01401 }
01402
01403 int parse_height_value(FILE *ferr, char *value)
01404 {
01405 int n = 0;
01406
01407 sscanf(value, "%d", &n);
01408 if (n < 1) {
01409 print_error(ferr, "Invalid screen height: %s", value);
01410 return(1);
01411 }
01412 d.screen_height = n;
01413 d.manual_height = 1;
01414 return(0);
01415 }
01416
01417 int parse_width_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01418 {
01419 if ((*arg_num)+1 == argc) {
01420 print_error(ferr, "Missing width after %s", argv[(*arg_num)]);
01421 return(1);
01422 }
01423 if (parse_width_value(ferr, argv[(*arg_num)+1]) != 0)
01424 return(1);
01425 (*arg_num)++;
01426 return(0);
01427 }
01428
01429 int parse_height_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01430 {
01431 if ((*arg_num)+1 == argc) {
01432 print_error(ferr, "Missing height after %s", argv[(*arg_num)]);
01433 return(1);
01434 }
01435 if (parse_height_value(ferr, argv[(*arg_num)+1]) != 0)
01436 return(1);
01437 (*arg_num)++;
01438 return(0);
01439 }
01440
01441 int parse_width_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01442 {
01443 if (parse_width_value(ferr, value) != 0) {
01444 print_esup(ferr, "In file: %s[%d]", filename, line);
01445 return(1);
01446 }
01447 return(0);
01448 }
01449
01450 int parse_height_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01451 {
01452 if (parse_height_value(ferr, value) != 0) {
01453 print_esup(ferr, "In file: %s[%d]", filename, line);
01454 return(1);
01455 }
01456 return(0);
01457 }
01458
01459 int parse_switch_commandline(char *arg, options_list *option, int *sw)
01460 {
01461 if ((option->short_option1 != 0) && (strcmp(arg, option->short_option1) == 0))
01462 (*sw) = 1;
01463 if ((option->long_option1 != 0) && (strcmp(arg, option->long_option1) == 0))
01464 (*sw) = 1;
01465 if ((option->short_option2 != 0) && (strcmp(arg, option->short_option2) == 0))
01466 (*sw) = 0;
01467 if ((option->long_option2 != 0) && (strcmp(arg, option->long_option2) == 0))
01468 (*sw) = 0;
01469 return(0);
01470 }
01471
01472 int parse_switch_rc(FILE *ferr, char *filename, int line, char *value, int *sw)
01473 {
01474 if ((strcasecmp(value, "on") == 0)
01475 || (strcasecmp(value, "yes") == 0)
01476 || (strcasecmp(value, "y") == 0)
01477 || (strcasecmp(value, "true") == 0)
01478 || (strcasecmp(value, "t") == 0)
01479 || (strcasecmp(value, "1") == 0)
01480 )
01481 {
01482 (*sw) = 1;
01483 }
01484 else if ((strcasecmp(value, "off") == 0)
01485 || (strcasecmp(value, "no") == 0)
01486 || (strcasecmp(value, "n") == 0)
01487 || (strcasecmp(value, "false") == 0)
01488 || (strcasecmp(value, "f") == 0)
01489 || (strcasecmp(value, "0") == 0)
01490 )
01491 {
01492 (*sw) = 0;
01493 }
01494 else {
01495 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
01496 print_esup(ferr, "Unknown switch value: %s", value);
01497 return(1);
01498 }
01499 return(0);
01500 }
01501
01502 int parse_switch_all_commandline(char *arg, options_list *option)
01503 {
01504 if ((option->short_option1 != 0) && (strcmp(arg, option->short_option1) == 0)) {
01505 d.display_twiddle = 1;
01506 d.display_title = 1;
01507 d.display_datacount = 1;
01508 d.display_throughput = 1;
01509 d.display_time = 1;
01510 d.display_percent = 1;
01511 d.display_bar = 1;
01512 d.display_summary = 1;
01513 }
01514 if ((option->long_option1 != 0) && (strcmp(arg, option->long_option1) == 0)) {
01515 d.display_twiddle = 1;
01516 d.display_title = 1;
01517 d.display_datacount = 1;
01518 d.display_throughput = 1;
01519 d.display_time = 1;
01520 d.display_percent = 1;
01521 d.display_bar = 1;
01522 d.display_summary = 1;
01523 }
01524 if ((option->short_option2 != 0) && (strcmp(arg, option->short_option2) == 0)) {
01525 d.display_twiddle = 0;
01526 d.display_title = 0;
01527 d.display_datacount = 0;
01528 d.display_throughput = 0;
01529 d.display_time = 0;
01530 d.display_percent = 0;
01531 d.display_bar = 0;
01532 d.display_summary = 0;
01533 }
01534 if ((option->long_option2 != 0) && (strcmp(arg, option->long_option2) == 0)) {
01535 d.display_twiddle = 0;
01536 d.display_title = 0;
01537 d.display_datacount = 0;
01538 d.display_throughput = 0;
01539 d.display_time = 0;
01540 d.display_percent = 0;
01541 d.display_bar = 0;
01542 d.display_summary = 0;
01543 }
01544 return(0);
01545 }
01546
01547 int parse_width_minus_one_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01548 {
01549 int r;
01550
01551 r = parse_switch_commandline(
01552 argv[(*arg_num)],
01553 &options[option_num],
01554 &d.screen_width_minus_one
01555 );
01556 return(r);
01557 }
01558
01559 int parse_width_minus_one_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01560 {
01561 int r;
01562
01563 r = parse_switch_rc(ferr, filename, line, value,
01564 &d.screen_width_minus_one
01565 );
01566 return(r);
01567 }
01568
01569 int parse_height_minus_one_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01570 {
01571 int r;
01572
01573 r = parse_switch_commandline(
01574 argv[(*arg_num)],
01575 &options[option_num],
01576 &d.screen_height_minus_one
01577 );
01578 return(r);
01579 }
01580
01581 int parse_height_minus_one_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01582 {
01583 int r;
01584
01585 r = parse_switch_rc(ferr, filename, line, value,
01586 &d.screen_height_minus_one
01587 );
01588 return(r);
01589 }
01590
01591 int parse_twiddle_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01592 {
01593 int r;
01594
01595 r = parse_switch_commandline(
01596 argv[(*arg_num)],
01597 &options[option_num],
01598 &d.display_twiddle
01599 );
01600 return(r);
01601 }
01602
01603 int parse_twiddle_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01604 {
01605 int r;
01606
01607 r = parse_switch_rc(ferr, filename, line, value,
01608 &d.display_twiddle
01609 );
01610 return(r);
01611 }
01612
01613 int parse_count_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01614 {
01615 int r;
01616
01617 r = parse_switch_commandline(
01618 argv[(*arg_num)],
01619 &options[option_num],
01620 &d.display_datacount
01621 );
01622 return(r);
01623 }
01624
01625 int parse_count_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01626 {
01627 int r;
01628
01629 r = parse_switch_rc(ferr, filename, line, value,
01630 &d.display_datacount
01631 );
01632 return(r);
01633 }
01634
01635 int parse_throughput_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01636 {
01637 int r;
01638
01639 r = parse_switch_commandline(
01640 argv[(*arg_num)],
01641 &options[option_num],
01642 &d.display_throughput
01643 );
01644 return(r);
01645 }
01646
01647 int parse_throughput_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01648 {
01649 int r;
01650
01651 r = parse_switch_rc(ferr, filename, line, value,
01652 &d.display_throughput
01653 );
01654 return(r);
01655 }
01656
01657 int parse_time_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01658 {
01659 int r;
01660
01661 r = parse_switch_commandline(
01662 argv[(*arg_num)],
01663 &options[option_num],
01664 &d.display_time
01665 );
01666 return(r);
01667 }
01668
01669 int parse_elapsed_only_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01670 {
01671 int r;
01672
01673 r = parse_switch_commandline(
01674 argv[(*arg_num)],
01675 &options[option_num],
01676 &d.display_elapsed_only
01677 );
01678 return(r);
01679 }
01680
01681 int parse_time_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01682 {
01683 int r;
01684
01685 r = parse_switch_rc(ferr, filename, line, value,
01686 &d.display_time
01687 );
01688 return(r);
01689 }
01690
01691 int parse_elapsed_only_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01692 {
01693 int r;
01694
01695 r = parse_switch_rc(ferr, filename, line, value,
01696 &d.display_elapsed_only
01697 );
01698 return(r);
01699 }
01700
01701 int parse_percent_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01702 {
01703 int r;
01704
01705 r = parse_switch_commandline(
01706 argv[(*arg_num)],
01707 &options[option_num],
01708 &d.display_percent
01709 );
01710 return(r);
01711 }
01712
01713 int parse_percent_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01714 {
01715 int r;
01716
01717 r = parse_switch_rc(ferr, filename, line, value,
01718 &d.display_percent
01719 );
01720 return(r);
01721 }
01722
01723 int parse_bar_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01724 {
01725 int r;
01726
01727 r = parse_switch_commandline(
01728 argv[(*arg_num)],
01729 &options[option_num],
01730 &d.display_bar
01731 );
01732 return(r);
01733 }
01734
01735 int parse_bar_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01736 {
01737 int r;
01738
01739 r = parse_switch_rc(ferr, filename, line, value,
01740 &d.display_bar
01741 );
01742 return(r);
01743 }
01744
01745 int parse_title_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01746 {
01747 if ((*arg_num)+1 == argc) {
01748 print_error(ferr, "Missing title string after %s", argv[(*arg_num)]);
01749 return(1);
01750 }
01751 sprintf(d.title, "%.*s", 80, argv[(*arg_num)+1]);
01752 (*arg_num)++;
01753 return(0);
01754 }
01755
01756 int parse_title_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01757 {
01758 sprintf(d.title, "%.*s", 80, value);
01759 return(0);
01760 }
01761
01762 int parse_total_percent_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01763 {
01764 int r;
01765
01766 r = parse_switch_commandline(
01767 argv[(*arg_num)],
01768 &options[option_num],
01769 &d.total_display_percent
01770 );
01771 return(r);
01772 }
01773
01774 int parse_total_percent_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01775 {
01776 int r;
01777
01778 r = parse_switch_rc(ferr, filename, line, value,
01779 &d.total_display_percent
01780 );
01781 return(r);
01782 }
01783
01784 int parse_summary_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01785 {
01786 int r;
01787
01788 r = parse_switch_commandline(
01789 argv[(*arg_num)],
01790 &options[option_num],
01791 &d.display_summary
01792 );
01793 return(r);
01794 }
01795
01796 int parse_summary_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01797 {
01798 int r;
01799
01800 r = parse_switch_rc(ferr, filename, line, value,
01801 &d.display_summary
01802 );
01803 return(r);
01804 }
01805
01806 int parse_display_title_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01807 {
01808 int r;
01809
01810 r = parse_switch_commandline(
01811 argv[(*arg_num)],
01812 &options[option_num],
01813 &d.display_title
01814 );
01815 return(r);
01816 }
01817
01818 int parse_display_title_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01819 {
01820 int r;
01821
01822 r = parse_switch_rc(ferr, filename, line, value,
01823 &d.display_title
01824 );
01825 return(r);
01826 }
01827
01828 int parse_ansi_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01829 {
01830 int r;
01831
01832 r = parse_switch_commandline(
01833 argv[(*arg_num)],
01834 &options[option_num],
01835 &d.display_ansi
01836 );
01837 return(r);
01838 }
01839
01840 int parse_ansi_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01841 {
01842 int r;
01843
01844 r = parse_switch_rc(ferr, filename, line, value,
01845 &d.display_ansi
01846 );
01847 return(r);
01848 }
01849
01850 int parse_throughput_bits_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01851 {
01852 int r;
01853
01854 r = parse_switch_rc(ferr, filename, line, value,
01855 &d.display_throughput_bits
01856 );
01857 return(r);
01858 }
01859
01860 int parse_count_bits_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01861 {
01862 int r;
01863
01864 r = parse_switch_rc(ferr, filename, line, value,
01865 &d.display_count_bits
01866 );
01867 return(r);
01868 }
01869
01870 int parse_displays_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01871 {
01872 int r;
01873
01874 r = parse_switch_all_commandline(
01875 argv[(*arg_num)],
01876 &options[option_num]
01877 );
01878 return(r);
01879 }
01880
01881 int parse_help_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01882 {
01883 help(ferr);
01884 return(1);
01885 }
01886
01887 int parse_version_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01888 {
01889 version(ferr);
01890 return(1);
01891 }
01892
01893 int parse_throughput_bits_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01894 {
01895 int r;
01896
01897 r = parse_switch_commandline(
01898 argv[(*arg_num)],
01899 &options[option_num],
01900 &d.display_throughput_bits
01901 );
01902 return(r);
01903 }
01904
01905 int parse_count_bits_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01906 {
01907 int r;
01908
01909 r = parse_switch_commandline(
01910 argv[(*arg_num)],
01911 &options[option_num],
01912 &d.display_count_bits
01913 );
01914 return(r);
01915 }
01916
01917 int isColor(char *s, colors_list *list)
01918 {
01919 int c = 0;
01920
01921 while (list[c].name != 0) {
01922 if (strcasecmp(s, list[c].name) == 0)
01923 return(c);
01924 c++;
01925 }
01926 return(-1);
01927 }
01928
01929 int parse_color(FILE *ferr, char *value, colors_list *list, char **code_ptr)
01930 {
01931 int c;
01932
01933 *code_ptr = 0;
01934 if (strcasecmp(value, "normal") == 0)
01935 return(0);
01936 c = isColor(value, list);
01937 if (c == -1) {
01938 print_error(ferr, "Invalid color: %s", value);
01939 return(1);
01940 }
01941 *code_ptr = list[c].code;
01942 return(0);
01943 }
01944
01945 int parse_space_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01946 {
01947 char *code = 0;
01948
01949 if ((*arg_num)+1 == argc) {
01950 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
01951 print_esup(ferr, "Ignoring color code");
01952 return(0);
01953 }
01954 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
01955 print_esup(ferr, "Ignoring color code");
01956 else {
01957 d.space_bg_color = code;
01958 }
01959 (*arg_num)++;
01960 return(0);
01961 }
01962
01963 int parse_space_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01964 {
01965 char *code = 0;
01966
01967 if (parse_color(ferr, value, bg_colors, &code) != 0) {
01968 print_esup(ferr, "in file: %s[%d]", filename, line);
01969 return(1);
01970 }
01971 d.space_bg_color = code;
01972 return(0);
01973 }
01974
01975 int parse_twiddle_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
01976 {
01977 char *code = 0;
01978
01979 if ((*arg_num)+1 == argc) {
01980 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
01981 print_esup(ferr, "Ignoring color code");
01982 return(0);
01983 }
01984 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
01985 print_esup(ferr, "Ignoring color code");
01986 else {
01987 d.twiddle_fg_color = code;
01988 }
01989 (*arg_num)++;
01990 return(0);
01991 }
01992
01993 int parse_twiddle_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
01994 {
01995 char *code = 0;
01996
01997 if (parse_color(ferr, value, fg_colors, &code) != 0) {
01998 print_esup(ferr, "In file: %s[%d]", filename, line);
01999 return(1);
02000 }
02001 d.twiddle_fg_color = code;
02002 return(0);
02003 }
02004
02005 int parse_twiddle_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02006 {
02007 char *code = 0;
02008
02009 if ((*arg_num)+1 == argc) {
02010 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02011 print_esup(ferr, "Ignoring color code");
02012 return(0);
02013 }
02014 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02015 print_esup(ferr, "Ignoring color code");
02016 else {
02017 d.twiddle_bg_color = code;
02018 }
02019 (*arg_num)++;
02020 return(0);
02021 }
02022
02023 int parse_twiddle_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02024 {
02025 char *code = 0;
02026
02027 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02028 print_esup(ferr, "in file: %s[%d]", filename, line);
02029 return(1);
02030 }
02031 d.twiddle_bg_color = code;
02032 return(0);
02033 }
02034
02035 int parse_twiddle_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02036 {
02037 int r;
02038
02039 r = parse_switch_commandline(
02040 argv[(*arg_num)],
02041 &options[option_num],
02042 &d.twiddle_fg_bold
02043 );
02044 return(r);
02045 }
02046
02047 int parse_twiddle_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02048 {
02049 int r;
02050
02051 r = parse_switch_rc(ferr, filename, line, value,
02052 &d.twiddle_fg_bold
02053 );
02054 return(r);
02055 }
02056
02057 int parse_title_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02058 {
02059 char *code = 0;
02060
02061 if ((*arg_num)+1 == argc) {
02062 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02063 print_esup(ferr, "Ignoring color code");
02064 return(0);
02065 }
02066 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02067 print_esup(ferr, "Ignoring color code");
02068 else {
02069 d.title_fg_color = code;
02070 }
02071 (*arg_num)++;
02072 return(0);
02073 }
02074
02075 int parse_title_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02076 {
02077 char *code = 0;
02078
02079 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02080 print_esup(ferr, "In file: %s[%d]", filename, line);
02081 return(1);
02082 }
02083 d.title_fg_color = code;
02084 return(0);
02085 }
02086
02087 int parse_title_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02088 {
02089 char *code = 0;
02090
02091 if ((*arg_num)+1 == argc) {
02092 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02093 print_esup(ferr, "Ignoring color code");
02094 return(0);
02095 }
02096 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02097 print_esup(ferr, "Ignoring color code");
02098 else {
02099 d.title_bg_color = code;
02100 }
02101 (*arg_num)++;
02102 return(0);
02103 }
02104
02105 int parse_title_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02106 {
02107 char *code = 0;
02108
02109 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02110 print_esup(ferr, "in file: %s[%d]", filename, line);
02111 return(1);
02112 }
02113 d.title_bg_color = code;
02114 return(0);
02115 }
02116
02117 int parse_title_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02118 {
02119 int r;
02120
02121 r = parse_switch_commandline(
02122 argv[(*arg_num)],
02123 &options[option_num],
02124 &d.title_fg_bold
02125 );
02126 return(r);
02127 }
02128
02129 int parse_title_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02130 {
02131 int r;
02132
02133 r = parse_switch_rc(ferr, filename, line, value,
02134 &d.title_fg_bold
02135 );
02136 return(r);
02137 }
02138
02139 int parse_count_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02140 {
02141 char *code = 0;
02142
02143 if ((*arg_num)+1 == argc) {
02144 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02145 print_esup(ferr, "Ignoring color code");
02146 return(0);
02147 }
02148 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02149 print_esup(ferr, "Ignoring color code");
02150 else {
02151 d.datacount_fg_color = code;
02152 }
02153 (*arg_num)++;
02154 return(0);
02155 }
02156
02157 int parse_count_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02158 {
02159 char *code = 0;
02160
02161 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02162 print_esup(ferr, "In file: %s[%d]", filename, line);
02163 return(1);
02164 }
02165 d.datacount_fg_color = code;
02166 return(0);
02167 }
02168
02169 int parse_count_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02170 {
02171 char *code = 0;
02172
02173 if ((*arg_num)+1 == argc) {
02174 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02175 print_esup(ferr, "Ignoring color code");
02176 return(0);
02177 }
02178 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02179 print_esup(ferr, "Ignoring color code");
02180 else {
02181 d.datacount_bg_color = code;
02182 }
02183 (*arg_num)++;
02184 return(0);
02185 }
02186
02187 int parse_count_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02188 {
02189 char *code = 0;
02190
02191 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02192 print_esup(ferr, "in file: %s[%d]", filename, line);
02193 return(1);
02194 }
02195 d.datacount_bg_color = code;
02196 return(0);
02197 }
02198
02199 int parse_count_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02200 {
02201 int r;
02202
02203 r = parse_switch_commandline(
02204 argv[(*arg_num)],
02205 &options[option_num],
02206 &d.datacount_fg_bold
02207 );
02208 return(r);
02209 }
02210
02211 int parse_count_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02212 {
02213 int r;
02214
02215 r = parse_switch_rc(ferr, filename, line, value,
02216 &d.datacount_fg_bold
02217 );
02218 return(r);
02219 }
02220
02221 int parse_throughput_label_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02222 {
02223 char *code = 0;
02224
02225 if ((*arg_num)+1 == argc) {
02226 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02227 print_esup(ferr, "Ignoring color code");
02228 return(0);
02229 }
02230 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02231 print_esup(ferr, "Ignoring color code");
02232 else {
02233 d.throughput_label_fg_color = code;
02234 }
02235 (*arg_num)++;
02236 return(0);
02237 }
02238
02239 int parse_throughput_label_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02240 {
02241 char *code = 0;
02242
02243 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02244 print_esup(ferr, "In file: %s[%d]", filename, line);
02245 return(1);
02246 }
02247 d.throughput_label_fg_color = code;
02248 return(0);
02249 }
02250
02251 int parse_throughput_label_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02252 {
02253 char *code = 0;
02254
02255 if ((*arg_num)+1 == argc) {
02256 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02257 print_esup(ferr, "Ignoring color code");
02258 return(0);
02259 }
02260 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02261 print_esup(ferr, "Ignoring color code");
02262 else {
02263 d.throughput_label_bg_color = code;
02264 }
02265 (*arg_num)++;
02266 return(0);
02267 }
02268
02269 int parse_throughput_label_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02270 {
02271 char *code = 0;
02272
02273 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02274 print_esup(ferr, "in file: %s[%d]", filename, line);
02275 return(1);
02276 }
02277 d.throughput_label_bg_color = code;
02278 return(0);
02279 }
02280
02281 int parse_throughput_label_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02282 {
02283 int r;
02284
02285 r = parse_switch_commandline(
02286 argv[(*arg_num)],
02287 &options[option_num],
02288 &d.throughput_label_fg_bold
02289 );
02290 return(r);
02291 }
02292
02293 int parse_throughput_label_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02294 {
02295 int r;
02296
02297 r = parse_switch_rc(ferr, filename, line, value,
02298 &d.throughput_label_fg_bold
02299 );
02300 return(r);
02301 }
02302
02303 int parse_throughput_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02304 {
02305 char *code = 0;
02306
02307 if ((*arg_num)+1 == argc) {
02308 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02309 print_esup(ferr, "Ignoring color code");
02310 return(0);
02311 }
02312 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02313 print_esup(ferr, "Ignoring color code");
02314 else {
02315 d.throughput_fg_color = code;
02316 }
02317 (*arg_num)++;
02318 return(0);
02319 }
02320
02321 int parse_throughput_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02322 {
02323 char *code = 0;
02324
02325 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02326 print_esup(ferr, "In file: %s[%d]", filename, line);
02327 return(1);
02328 }
02329 d.throughput_fg_color = code;
02330 return(0);
02331 }
02332
02333 int parse_throughput_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02334 {
02335 char *code = 0;
02336
02337 if ((*arg_num)+1 == argc) {
02338 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02339 print_esup(ferr, "Ignoring color code");
02340 return(0);
02341 }
02342 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02343 print_esup(ferr, "Ignoring color code");
02344 else {
02345 d.throughput_bg_color = code;
02346 }
02347 (*arg_num)++;
02348 return(0);
02349 }
02350
02351 int parse_throughput_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02352 {
02353 char *code = 0;
02354
02355 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02356 print_esup(ferr, "in file: %s[%d]", filename, line);
02357 return(1);
02358 }
02359 d.throughput_bg_color = code;
02360 return(0);
02361 }
02362
02363 int parse_throughput_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02364 {
02365 int r;
02366
02367 r = parse_switch_commandline(
02368 argv[(*arg_num)],
02369 &options[option_num],
02370 &d.throughput_fg_bold
02371 );
02372 return(r);
02373 }
02374
02375 int parse_throughput_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02376 {
02377 int r;
02378
02379 r = parse_switch_rc(ferr, filename, line, value,
02380 &d.throughput_fg_bold
02381 );
02382 return(r);
02383 }
02384
02385 int parse_time_label_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02386 {
02387 char *code = 0;
02388
02389 if ((*arg_num)+1 == argc) {
02390 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02391 print_esup(ferr, "Ignoring color code");
02392 return(0);
02393 }
02394 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02395 print_esup(ferr, "Ignoring color code");
02396 else {
02397 d.time_label_fg_color = code;
02398 }
02399 (*arg_num)++;
02400 return(0);
02401 }
02402
02403 int parse_time_label_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02404 {
02405 char *code = 0;
02406
02407 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02408 print_esup(ferr, "In file: %s[%d]", filename, line);
02409 return(1);
02410 }
02411 d.time_label_fg_color = code;
02412 return(0);
02413 }
02414
02415 int parse_time_label_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02416 {
02417 char *code = 0;
02418
02419 if ((*arg_num)+1 == argc) {
02420 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02421 print_esup(ferr, "Ignoring color code");
02422 return(0);
02423 }
02424 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02425 print_esup(ferr, "Ignoring color code");
02426 else {
02427 d.time_label_bg_color = code;
02428 }
02429 (*arg_num)++;
02430 return(0);
02431 }
02432
02433 int parse_time_label_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02434 {
02435 char *code = 0;
02436
02437 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02438 print_esup(ferr, "in file: %s[%d]", filename, line);
02439 return(1);
02440 }
02441 d.time_label_bg_color = code;
02442 return(0);
02443 }
02444
02445 int parse_time_label_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02446 {
02447 int r;
02448
02449 r = parse_switch_commandline(
02450 argv[(*arg_num)],
02451 &options[option_num],
02452 &d.time_label_fg_bold
02453 );
02454 return(r);
02455 }
02456
02457 int parse_time_label_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02458 {
02459 int r;
02460
02461 r = parse_switch_rc(ferr, filename, line, value,
02462 &d.time_label_fg_bold
02463 );
02464 return(r);
02465 }
02466
02467 int parse_time_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02468 {
02469 char *code = 0;
02470
02471 if ((*arg_num)+1 == argc) {
02472 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02473 print_esup(ferr, "Ignoring color code");
02474 return(0);
02475 }
02476 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02477 print_esup(ferr, "Ignoring color code");
02478 else {
02479 d.time_fg_color = code;
02480 }
02481 (*arg_num)++;
02482 return(0);
02483 }
02484
02485 int parse_time_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02486 {
02487 char *code = 0;
02488
02489 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02490 print_esup(ferr, "In file: %s[%d]", filename, line);
02491 return(1);
02492 }
02493 d.time_fg_color = code;
02494 return(0);
02495 }
02496
02497 int parse_time_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02498 {
02499 char *code = 0;
02500
02501 if ((*arg_num)+1 == argc) {
02502 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02503 print_esup(ferr, "Ignoring color code");
02504 return(0);
02505 }
02506 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02507 print_esup(ferr, "Ignoring color code");
02508 else {
02509 d.time_bg_color = code;
02510 }
02511 (*arg_num)++;
02512 return(0);
02513 }
02514
02515 int parse_time_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02516 {
02517 char *code = 0;
02518
02519 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02520 print_esup(ferr, "in file: %s[%d]", filename, line);
02521 return(1);
02522 }
02523 d.time_bg_color = code;
02524 return(0);
02525 }
02526
02527 int parse_time_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02528 {
02529 int r;
02530
02531 r = parse_switch_commandline(
02532 argv[(*arg_num)],
02533 &options[option_num],
02534 &d.time_fg_bold
02535 );
02536 return(r);
02537 }
02538
02539 int parse_time_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02540 {
02541 int r;
02542
02543 r = parse_switch_rc(ferr, filename, line, value,
02544 &d.time_fg_bold
02545 );
02546 return(r);
02547 }
02548
02549 int parse_percent_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02550 {
02551 char *code = 0;
02552
02553 if ((*arg_num)+1 == argc) {
02554 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02555 print_esup(ferr, "Ignoring color code");
02556 return(0);
02557 }
02558 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02559 print_esup(ferr, "Ignoring color code");
02560 else {
02561 d.percent_fg_color = code;
02562 }
02563 (*arg_num)++;
02564 return(0);
02565 }
02566
02567 int parse_percent_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02568 {
02569 char *code = 0;
02570
02571 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02572 print_esup(ferr, "In file: %s[%d]", filename, line);
02573 return(1);
02574 }
02575 d.percent_fg_color = code;
02576 return(0);
02577 }
02578
02579 int parse_percent_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02580 {
02581 char *code = 0;
02582
02583 if ((*arg_num)+1 == argc) {
02584 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02585 print_esup(ferr, "Ignoring color code");
02586 return(0);
02587 }
02588 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02589 print_esup(ferr, "Ignoring color code");
02590 else {
02591 d.percent_bg_color = code;
02592 }
02593 (*arg_num)++;
02594 return(0);
02595 }
02596
02597 int parse_percent_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02598 {
02599 char *code = 0;
02600
02601 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02602 print_esup(ferr, "in file: %s[%d]", filename, line);
02603 return(1);
02604 }
02605 d.percent_bg_color = code;
02606 return(0);
02607 }
02608
02609 int parse_percent_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02610 {
02611 int r;
02612
02613 r = parse_switch_commandline(
02614 argv[(*arg_num)],
02615 &options[option_num],
02616 &d.percent_fg_bold
02617 );
02618 return(r);
02619 }
02620
02621 int parse_percent_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02622 {
02623 int r;
02624
02625 r = parse_switch_rc(ferr, filename, line, value,
02626 &d.percent_fg_bold
02627 );
02628 return(r);
02629 }
02630
02631 int parse_bar_openbrace_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02632 {
02633 char ch = '\0';
02634
02635 if ((*arg_num)+1 == argc) {
02636 print_error(ferr, "Missing bar open brace character after %s", argv[(*arg_num)]);
02637 print_esup(ferr, "Ignoring bar open brace character");
02638 return(0);
02639 }
02640 if (parse_char(ferr, argv[(*arg_num)+1], &ch) != 0)
02641 print_esup(ferr, "Ignoring bar open brace character");
02642 else {
02643 d.bar_open_brace = ch;
02644 }
02645 (*arg_num)++;
02646 return(0);
02647 }
02648
02649 int parse_bar_openbrace_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02650 {
02651 if (parse_char(ferr, value, &d.bar_open_brace) != 0) {
02652 print_esup(ferr, "In file: %s[%d]", filename, line);
02653 return(1);
02654 }
02655 return(0);
02656 }
02657
02658 int parse_bar_closebrace_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02659 {
02660 char ch = '\0';
02661
02662 if ((*arg_num)+1 == argc) {
02663 print_error(ferr, "Missing bar close brace character after %s", argv[(*arg_num)]);
02664 print_esup(ferr, "Ignoring bar close brace character");
02665 return(0);
02666 }
02667 if (parse_char(ferr, argv[(*arg_num)+1], &ch) != 0)
02668 print_esup(ferr, "Ignoring bar close brace character");
02669 else {
02670 d.bar_close_brace = ch;
02671 }
02672 (*arg_num)++;
02673 return(0);
02674 }
02675
02676 int parse_bar_closebrace_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02677 {
02678 if (parse_char(ferr, value, &d.bar_close_brace) != 0) {
02679 print_esup(ferr, "In file: %s[%d]", filename, line);
02680 return(1);
02681 }
02682 return(0);
02683 }
02684
02685 int parse_bar_complete_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02686 {
02687 char ch = '\0';
02688
02689 if ((*arg_num)+1 == argc) {
02690 print_error(ferr, "Missing bar complete character after %s", argv[(*arg_num)]);
02691 print_esup(ferr, "Ignoring bar complete character");
02692 return(0);
02693 }
02694 if (parse_char(ferr, argv[(*arg_num)+1], &ch) != 0)
02695 print_esup(ferr, "Ignoring bar complete character");
02696 else {
02697 d.bar_complete = ch;
02698 }
02699 (*arg_num)++;
02700 return(0);
02701 }
02702
02703 int parse_bar_complete_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02704 {
02705 if (parse_char(ferr, value, &d.bar_complete) != 0) {
02706 print_esup(ferr, "In file: %s[%d]", filename, line);
02707 return(1);
02708 }
02709 return(0);
02710 }
02711
02712 int parse_bar_incomplete_char_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02713 {
02714 char ch = '\0';
02715
02716 if ((*arg_num)+1 == argc) {
02717 print_error(ferr, "Missing bar incomplete character after %s", argv[(*arg_num)]);
02718 print_esup(ferr, "Ignoring bar incomplete character");
02719 return(0);
02720 }
02721 if (parse_char(ferr, argv[(*arg_num)+1], &ch) != 0)
02722 print_esup(ferr, "Ignoring bar incomplete character");
02723 else {
02724 d.bar_incomplete = ch;
02725 }
02726 (*arg_num)++;
02727 return(0);
02728 }
02729
02730 int parse_bar_incomplete_char_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02731 {
02732 if (parse_char(ferr, value, &d.bar_incomplete) != 0) {
02733 print_esup(ferr, "In file: %s[%d]", filename, line);
02734 return(1);
02735 }
02736 return(0);
02737 }
02738
02739 int parse_barbrace_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02740 {
02741 char *code = 0;
02742
02743 if ((*arg_num)+1 == argc) {
02744 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02745 print_esup(ferr, "Ignoring color code");
02746 return(0);
02747 }
02748 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02749 print_esup(ferr, "Ignoring color code");
02750 else {
02751 d.barbrace_fg_color = code;
02752 }
02753 (*arg_num)++;
02754 return(0);
02755 }
02756
02757 int parse_barbrace_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02758 {
02759 char *code = 0;
02760
02761 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02762 print_esup(ferr, "In file: %s[%d]", filename, line);
02763 return(1);
02764 }
02765 d.barbrace_fg_color = code;
02766 return(0);
02767 }
02768
02769 int parse_barbrace_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02770 {
02771 char *code = 0;
02772
02773 if ((*arg_num)+1 == argc) {
02774 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02775 print_esup(ferr, "Ignoring color code");
02776 return(0);
02777 }
02778 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02779 print_esup(ferr, "Ignoring color code");
02780 else {
02781 d.barbrace_bg_color = code;
02782 }
02783 (*arg_num)++;
02784 return(0);
02785 }
02786
02787 int parse_barbrace_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02788 {
02789 char *code = 0;
02790
02791 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02792 print_esup(ferr, "in file: %s[%d]", filename, line);
02793 return(1);
02794 }
02795 d.barbrace_bg_color = code;
02796 return(0);
02797 }
02798
02799 int parse_barbrace_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02800 {
02801 int r;
02802
02803 r = parse_switch_commandline(
02804 argv[(*arg_num)],
02805 &options[option_num],
02806 &d.barbrace_fg_bold
02807 );
02808 return(r);
02809 }
02810
02811 int parse_barbrace_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02812 {
02813 int r;
02814
02815 r = parse_switch_rc(ferr, filename, line, value,
02816 &d.barbrace_fg_bold
02817 );
02818 return(r);
02819 }
02820
02821 int parse_bar_fg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02822 {
02823 char *code = 0;
02824
02825 if ((*arg_num)+1 == argc) {
02826 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02827 print_esup(ferr, "Ignoring color code");
02828 return(0);
02829 }
02830 if (parse_color(ferr, argv[(*arg_num)+1], fg_colors, &code) != 0)
02831 print_esup(ferr, "Ignoring color code");
02832 else {
02833 d.bar_fg_color = code;
02834 }
02835 (*arg_num)++;
02836 return(0);
02837 }
02838
02839 int parse_bar_fg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02840 {
02841 char *code = 0;
02842
02843 if (parse_color(ferr, value, fg_colors, &code) != 0) {
02844 print_esup(ferr, "In file: %s[%d]", filename, line);
02845 return(1);
02846 }
02847 d.bar_fg_color = code;
02848 return(0);
02849 }
02850
02851 int parse_bar_bg_color_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02852 {
02853 char *code = 0;
02854
02855 if ((*arg_num)+1 == argc) {
02856 print_error(ferr, "Missing color name after %s", argv[(*arg_num)]);
02857 print_esup(ferr, "Ignoring color code");
02858 return(0);
02859 }
02860 if (parse_color(ferr, argv[(*arg_num)+1], bg_colors, &code) != 0)
02861 print_esup(ferr, "Ignoring color code");
02862 else {
02863 d.bar_bg_color = code;
02864 }
02865 (*arg_num)++;
02866 return(0);
02867 }
02868
02869 int parse_bar_bg_color_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02870 {
02871 char *code = 0;
02872
02873 if (parse_color(ferr, value, bg_colors, &code) != 0) {
02874 print_esup(ferr, "in file: %s[%d]", filename, line);
02875 return(1);
02876 }
02877 d.bar_bg_color = code;
02878 return(0);
02879 }
02880
02881 int parse_bar_fg_bold_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02882 {
02883 int r;
02884
02885 r = parse_switch_commandline(
02886 argv[(*arg_num)],
02887 &options[option_num],
02888 &d.bar_fg_bold
02889 );
02890 return(r);
02891 }
02892
02893 int parse_bar_fg_bold_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02894 {
02895 int r;
02896
02897 r = parse_switch_rc(ferr, filename, line, value,
02898 &d.bar_fg_bold
02899 );
02900 return(r);
02901 }
02902
02903 int parse_infofile_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02904 {
02905 if ((*arg_num)+1 == argc) {
02906 print_error(ferr, "Missing pathname after %s", argv[(*arg_num)]);
02907 return(1);
02908 }
02909 d.info_file = argv[(*arg_num)+1];
02910 (*arg_num)++;
02911 return(0);
02912 }
02913
02914 int parse_infofile_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02915 {
02916 d.info_file = value;
02917 return(0);
02918 }
02919
02920 int parse_display_numeric_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02921 {
02922 int r;
02923
02924 r = parse_switch_commandline(
02925 argv[(*arg_num)],
02926 &options[option_num],
02927 &d.display_numeric
02928 );
02929 return(r);
02930 }
02931
02932 int parse_display_numeric_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02933 {
02934 int r;
02935
02936 r = parse_switch_rc(ferr, filename, line, value,
02937 &d.display_numeric
02938 );
02939 return(r);
02940 }
02941
02942 int parse_display_wait_commandline(FILE *ferr, int argc, char *argv[], int *arg_num, int option_num)
02943 {
02944 int r;
02945
02946 r = parse_switch_commandline(
02947 argv[(*arg_num)],
02948 &options[option_num],
02949 &d.display_wait
02950 );
02951 return(r);
02952 }
02953
02954 int parse_display_wait_rc(FILE *ferr, char *filename, int line, char *tag, char *value)
02955 {
02956 int r;
02957
02958 r = parse_switch_rc(ferr, filename, line, value,
02959 &d.display_wait
02960 );
02961 return(r);
02962 }
02963
02964 int parse_args(FILE *ferr, int argc, char *argv[])
02965 {
02966 int c = 0;
02967 int o = 0;
02968
02969 for (c = 1; c < argc; c++) {
02970 o = isOpt(argv[c]);
02971 if (o != -1) {
02972 if (options[o].cl_func == parse_kilo_commandline) {
02973 if (options[o].cl_func(ferr, argc, argv, &c, o) != 0)
02974 return(1);
02975 }
02976 else if (options[o].cl_func == parse_help_commandline) {
02977 if (options[o].cl_func(ferr, argc, argv, &c, o) != 0)
02978 return(1);
02979 }
02980 else if (options[o].cl_func == parse_version_commandline) {
02981 if (options[o].cl_func(ferr, argc, argv, &c, o) != 0)
02982 return(1);
02983 }
02984 else if (options[o].cl_func == parse_block_size_commandline) {
02985 if (options[o].cl_func(ferr, argc, argv, &c, 0) != 0)
02986 return(1);
02987 }
02988 else if (options[o].arg_description != 0) {
02989 c++;
02990 }
02991 }
02992 }
02993
02994 for (c = 1; c < argc; c++) {
02995 o = isOpt(argv[c]);
02996 if (o == -1) {
02997 if (io.in == STDIN_FILENO) {
02998 if (parse_infile_value(ferr,argv[c]) != 0) {
02999 return(1);
03000 }
03001 }
03002 else if (io.out == STDOUT_FILENO) {
03003 if (parse_outfile_value(ferr,argv[c]) != 0) {
03004 return(1);
03005 }
03006 }
03007 else {
03008 print_error(ferr, "Unknown command line option: %s", argv[c]);
03009 return(1);
03010 }
03011 }
03012 else {
03013 if (options[o].cl_func(ferr, argc, argv, &c, o) != 0)
03014 return(1);
03015 }
03016 }
03017 return(0);
03018 }
03019
03020 int parse_rc_by_tag(FILE *ferr, char* filename, int line, char *tag, char *value)
03021 {
03022 int o = 0;
03023
03024 o = isOpt(tag);
03025 if (o == -1) {
03026 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03027 print_esup(ferr, "Unknown tag: %s", tag);
03028 return(1);
03029 }
03030 if (options[o].rc_func(ferr, filename, line, tag, value) != 0)
03031 return(1);
03032 return(0);
03033 }
03034
03035 int parse_rcfile(FILE *ferr, char *filename)
03036 {
03037 FILE *rcfile = 0;
03038 char tag[80];
03039 char value[80];
03040 int c;
03041 int line = 0;
03042 char ch;
03043
03044 if (access(filename, F_OK) != 0)
03045 return(0);
03046
03047 rcfile = fopen(filename, "r");
03048 if (rcfile == 0) {
03049 print_error(ferr, "Cannot open rc file for reading: %s", filename);
03050 return(1);
03051 }
03052
03053 while (!feof(rcfile)) {
03054 line++;
03055
03056 for (c = 0; c < 80; c++) {
03057 tag[c] = 0;
03058 value[c] = 0;
03059 }
03060
03061 ch = fgetc(rcfile);
03062 if (feof(rcfile)) {
03063 return(0);
03064 }
03065 if (ch == '#') {
03066 while (!feof(rcfile) && (ch != '\n'))
03067 ch = fgetc(rcfile);
03068 continue;
03069 }
03070 c = 0;
03071 while (!feof(rcfile) && (isalnum((int)ch) || (ch == '-')) && (c < 80)) {
03072 tag[strlen(tag)] = ch;
03073 ch = fgetc(rcfile);
03074 c++;
03075 }
03076
03077 if (c == 80) {
03078 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03079 print_esup(ferr, "Tag too long");
03080 return(1);
03081 }
03082 if (feof(rcfile)) {
03083 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03084 print_esup(ferr, "Unexpected end of file reached");
03085 return(1);
03086 }
03087 if (strlen(tag) == 0) {
03088 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03089 print_esup(ferr, "No tag");
03090 return(1);
03091 }
03092 if (ch != ':') {
03093 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03094 print_esup(ferr, "':' delimiter expected between tag and value");
03095 return(1);
03096 }
03097
03098 ch = fgetc(rcfile);
03099 while (!feof(rcfile) && ((ch == ' ') || (ch == '\t')))
03100 ch = fgetc(rcfile);
03101 if (ch == '\n') {
03102 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03103 print_esup(ferr, "No value found after tag: %s", tag);
03104 return(1);
03105 }
03106 c = 0;
03107 while (!feof(rcfile) && (ch != '\n') && (c < 80)) {
03108 value[strlen(value)] = ch;
03109 ch = fgetc(rcfile);
03110 c++;
03111 }
03112 if (c == 80) {
03113 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03114 print_esup(ferr, "Value too long");
03115 return(1);
03116 }
03117 if (strlen(value) == 0) {
03118 print_error(ferr, "Parse error in rc file: %s[%d]", filename, line);
03119 print_esup(ferr, "No value for tag: %s", tag);
03120 return(1);
03121 }
03122
03123 if (parse_rc_by_tag(ferr, filename, line, tag, value) != 0)
03124 return(1);
03125 }
03126
03127 fclose(rcfile);
03128 return(0);
03129 }
03130
03131 int parse_rcfiles(FILE *ferr)
03132 {
03133 char filename[4096] = { 0 };
03134 char * home_dir = 0;
03135
03136 if (access("/etc/clpbarrc", R_OK) == 0) {
03137 sprintf(filename, "/etc/clpbarrc");
03138 }
03139 if (strlen(filename) > 0)
03140 if (parse_rcfile(ferr, filename) != 0)
03141 return(1);
03142
03143 home_dir = getenv("HOME");
03144 if (home_dir != 0) {
03145 sprintf(filename, "%.*s/.barrc", 4088, home_dir);
03146 if (parse_rcfile(ferr, filename) != 0)
03147 return(1);
03148 }
03149
03150 sprintf(filename, "./.barrc");
03151 if (parse_rcfile(ferr, filename) != 0)
03152 return(1);
03153
03154 return(0);
03155 }
03156