#include "widechar.h"
#include "strutils.h"
#include "closestream.h"
+#include "optutils.h"
#define BS '\b' /* backspace */
#define TAB '\t' /* tab */
ctl->lines->l_prev = NULL;
}
-int main(int argc, char **argv)
+static void parse_options(struct col_ctl *ctl, int argc, char **argv)
{
- struct col_ctl ctl = {
- .compress_spaces = 1,
- .last_set = CS_NORMAL,
- .max_bufd_lines = 128 * 2,
- };
- register wint_t ch;
- CHAR *c = NULL;
- CSET cur_set; /* current character set */
- LINE *l; /* current line */
- int extra_lines; /* # of lines above first line */
- int cur_col; /* current column */
- int cur_line; /* line number of current position */
- int max_line; /* max value of cur_line */
- int this_line; /* line l points to */
- int nflushd_lines; /* number of lines that were flushed */
- int adjust, opt, warned;
- int ret = EXIT_SUCCESS;
-
static const struct option longopts[] = {
{ "no-backspaces", no_argument, NULL, 'b' },
{ "fine", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'H' },
{ NULL, 0, NULL, 0 }
};
+ static const ul_excl_t excl[] = {
+ { 'h', 'x' },
+ { 0 }
+ };
+ int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+ int opt;
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
- close_stdout_atexit();
+ while ((opt = getopt_long(argc, argv, "bfhl:pxVH", longopts, NULL)) != -1) {
+ err_exclusive_options(opt, longopts, excl, excl_st);
- while ((opt = getopt_long(argc, argv, "bfhl:pxVH", longopts, NULL)) != -1)
switch (opt) {
case 'b': /* do not output backspaces */
- ctl.no_backspaces = 1;
+ ctl->no_backspaces = 1;
break;
case 'f': /* allow half forward line feeds */
- ctl.fine = 1;
+ ctl->fine = 1;
break;
case 'h': /* compress spaces into tabs */
- ctl.compress_spaces = 1;
+ ctl->compress_spaces = 1;
break;
case 'l':
/*
* Buffered line count, which is a value in half
* lines e.g. twice the amount specified.
*/
- ctl.max_bufd_lines = strtou32_or_err(optarg, _("bad -l argument")) * 2;
+ ctl->max_bufd_lines = strtou32_or_err(optarg, _("bad -l argument")) * 2;
break;
case 'p':
- ctl.pass_unknown_seqs = 1;
+ ctl->pass_unknown_seqs = 1;
break;
case 'x': /* do not compress spaces into tabs */
- ctl.compress_spaces = 0;
+ ctl->compress_spaces = 0;
break;
case 'V':
default:
errtryhelp(EXIT_FAILURE);
}
+ }
if (optind != argc) {
warnx(_("bad usage"));
errtryhelp(EXIT_FAILURE);
}
+}
+
+int main(int argc, char **argv)
+{
+ struct col_ctl ctl = {
+ .compress_spaces = 1,
+ .last_set = CS_NORMAL,
+ .max_bufd_lines = 128 * 2,
+ };
+ register wint_t ch;
+ CHAR *c = NULL;
+ CSET cur_set; /* current character set */
+ LINE *l; /* current line */
+ int extra_lines; /* # of lines above first line */
+ int cur_col; /* current column */
+ int cur_line; /* line number of current position */
+ int max_line; /* max value of cur_line */
+ int this_line; /* line l points to */
+ int nflushd_lines; /* number of lines that were flushed */
+ int adjust, warned;
+ int ret = EXIT_SUCCESS;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+ close_stdout_atexit();
adjust = cur_col = extra_lines = warned = 0;
cur_line = max_line = nflushd_lines = this_line = 0;
cur_set = CS_NORMAL;
ctl.lines = l = alloc_line(&ctl);
+ parse_options(&ctl, argc, argv);
+
while (feof(stdin) == 0) {
errno = 0;
if ((ch = getwchar()) == WEOF) {