args.c

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

Generated on Thu Jun 28 09:13:03 2007 for bar by  doxygen 1.5.1