touched up the cut utility

This commit is contained in:
hyung-hwan 2025-06-07 01:34:07 +09:00
parent d235fa023d
commit 7f9ac2047f
4 changed files with 18 additions and 56 deletions

View File

@ -99,27 +99,21 @@ static void print_usage (FILE* out, const hawk_bch_t* argv0, const hawk_bch_t* r
const hawk_bch_t* b2 = (real_argv0? " ": ""); const hawk_bch_t* b2 = (real_argv0? " ": "");
const hawk_bch_t* b3 = (real_argv0? argv0: ""); const hawk_bch_t* b3 = (real_argv0? argv0: "");
fprintf (out, "USAGE: %s%s%s [options] script [file]\n", b1, b2, b3); fprintf (out, "USAGE: %s%s%s [options] selector [file]\n", b1, b2, b3);
fprintf (out, " %s%s%s [options] -f script-file [file]\n", b1, b2, b3); fprintf (out, " %s%s%s [options] -f selector-file [file]\n", b1, b2, b3);
fprintf (out, " %s%s%s [options] -e script [file]\n", b1, b2, b3);
fprintf (out, "Selector as follows:\n");
fprintf (out, " 'd' followed by a delimiter character\n");
fprintf (out, " 'D' followed by an input delimiter character and an output delimiter character\n");
fprintf (out, " 'f' followed by a field number or field number range\n");
fprintf (out, " 'c' followed by a character position or character position range\n");
fprintf (out, " for example, 'f3-5 c1-2 f4 D:,'\n");
fprintf (out, "Options as follows:\n"); fprintf (out, "Options as follows:\n");
fprintf (out, " -h/--help show this message\n"); fprintf (out, " -h/--help show this message\n");
fprintf (out, " -D show extra information\n"); fprintf (out, " -D show extra information\n");
fprintf (out, " -n disable auto-print\n");
fprintf (out, " -e script specify a script\n"); fprintf (out, " -e script specify a script\n");
fprintf (out, " -f file specify a script file\n"); fprintf (out, " -f file specify a script file\n");
fprintf (out, " -o file specify an output file\n"); fprintf (out, " -o file specify an output file\n");
fprintf (out, " -r use the extended regular expression\n");
fprintf (out, " -R enable non-standard extensions to the regular\n");
fprintf (out, " expression\n");
fprintf (out, " -i perform in-place editing. imply -s\n");
fprintf (out, " -s process input files separately\n");
fprintf (out, " -a perform strict address and label check\n");
fprintf (out, " -b allow extended address formats\n");
fprintf (out, " <start~step>,<start,+line>,<start,~line>,<0,/regex/>\n");
fprintf (out, " -x allow text on the same line as c, a, i\n");
fprintf (out, " -y ensure a newline at text end\n");
fprintf (out, " -m/--memory-limit number specify the maximum amount of memory to use in bytes\n"); fprintf (out, " -m/--memory-limit number specify the maximum amount of memory to use in bytes\n");
fprintf (out, " -w expand file wildcards\n"); fprintf (out, " -w expand file wildcards\n");
#if defined(HAWK_OOCH_IS_UCH) #if defined(HAWK_OOCH_IS_UCH)
@ -192,7 +186,7 @@ static int handle_args (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_arg
}; };
static hawk_bcli_t opt = static hawk_bcli_t opt =
{ {
"hDe:f:o:rRisabxym:w", "hDe:f:om:w",
lng lng
}; };
hawk_bci_t c; hawk_bci_t c;
@ -235,32 +229,6 @@ static int handle_args (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_arg
arg->output_file = opt.arg; arg->output_file = opt.arg;
break; break;
case 'i':
/* 'i' implies 's'. */
arg->inplace = 1;
case 's':
arg->separate = 1;
break;
#if 0
case 'a':
arg->option |= HAWK_CUT_STRICT;
break;
case 'b':
arg->option |= HAWK_CUT_EXTENDEDADR;
break;
case 'x':
arg->option |= HAWK_CUT_SAMELINE;
break;
case 'y':
arg->option |= HAWK_CUT_ENSURENL;
break;
#endif
case 'm': case 'm':
arg->memlimit = strtoul(opt.arg, HAWK_NULL, 10); arg->memlimit = strtoul(opt.arg, HAWK_NULL, 10);
break; break;

View File

@ -324,15 +324,7 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
int mask = 0; int mask = 0;
while (hawk_is_ooch_space(c)) NXTSC_GOTO(cut, c, oops); while (hawk_is_ooch_space(c)) NXTSC_GOTO(cut, c, oops);
if (EOF(c)) if (EOF(c)) break;
{
if (cut->sel.count > 0)
{
SETERR0(cut, HAWK_CUT_ESELNV);
return -1;
}
break;
}
if (c == HAWK_T('d')) if (c == HAWK_T('d'))
{ {

View File

@ -798,6 +798,7 @@ static hawk_ooi_t read_input_stream (hawk_cut_t* cut, hawk_cut_io_arg_t* arg, ha
/* == end of file on the current input stream == */ /* == end of file on the current input stream == */
/* ============================================= */ /* ============================================= */
#if 0
if (base == &xtn->s.in && xtn->s.last != HAWK_T('\n')) if (base == &xtn->s.in && xtn->s.last != HAWK_T('\n'))
{ {
/* TODO: different line termination convension */ /* TODO: different line termination convension */
@ -806,6 +807,7 @@ static hawk_ooi_t read_input_stream (hawk_cut_t* cut, hawk_cut_io_arg_t* arg, ha
xtn->s.newline_squeezed = 1; xtn->s.newline_squeezed = 1;
break; break;
} }
#endif
open_next: open_next:
next = base->cur + 1; next = base->cur + 1;