[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] cut -v
From: |
Bonzini |
Subject: |
[PATCH] cut -v |
Date: |
Sat, 5 Oct 2002 10:03:53 +0200 |
Hi Jim,
here is a patch to support a -v option that reverses the fields to be
printed by cut. The patch is against coreutils-4.5.1. (I already sent it to
you privately but it did not pass through the mail filter).
I don't think papers are needed for such a small patch, but I can send
them if you want.
2002-10-04 Paolo Bonzini <bonzini@gnu.org>
* src/cut.c (print_kth): take invert_match into account
(main): interpret -v option
(longopts): added --invert-match option
(usage): document --v / --invert-match option
Paolo Bonzini
*** coreutils-4.5.1/src/cut.c Sat Aug 31 09:32:33 2002
--- cut.c Fri Oct 4 13:21:21 2002
***************
*** 123,128 ****
--- 123,132 ----
with field mode. */
static int suppress_non_delimited;
+ /* If nonzero print all the character or fields except those that
+ were specified. */
+ static int invert_match;
+
/* The delimeter character for field mode. */
static int delim;
***************
*** 150,155 ****
--- 154,160 ----
{"fields", required_argument, 0, 'f'},
{"delimiter", required_argument, 0, 'd'},
{"only-delimited", no_argument, 0, 's'},
+ {"invert-match", no_argument, 0, 'v'},
{"output-delimiter", required_argument, 0, OUTPUT_DELIMITER_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
***************
*** 191,196 ****
--- 196,204 ----
--output-delimiter=STRING use STRING as the output delimiter\n\
the default is to use the input delimiter\n\
"), stdout);
+ fputs (_("\
+ -v, --invert-match print only the fields that were not indicated\n\
+ "), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
***************
*** 213,220 ****
static int
print_kth (unsigned int k)
{
! return ((0 < eol_range_start && eol_range_start <= k)
|| (k <= max_range_endpoint && printable_field[k]));
}
/* Given the list of field or byte range specifications FIELDSTR, set
--- 221,231 ----
static int
print_kth (unsigned int k)
{
! int given_in_command_line;
! given_in_command_line = ((0 < eol_range_start && eol_range_start <= k)
|| (k <= max_range_endpoint && printable_field[k]));
+
+ return given_in_command_line ^ invert_match;
}
/* Given the list of field or byte range specifications FIELDSTR, set
***************
*** 610,616 ****
delim = '\0';
have_read_stdin = 0;
! while ((optc = getopt_long (argc, argv, "b:c:d:f:ns", longopts, NULL))
!= -1)
{
switch (optc)
{
--- 621,627 ----
delim = '\0';
have_read_stdin = 0;
! while ((optc = getopt_long (argc, argv, "b:c:d:f:nsv", longopts, NULL))
!= -1)
{
switch (optc)
{
***************
*** 660,665 ****
--- 671,680 ----
suppress_non_delimited = 1;
break;
+ case 'v':
+ invert_match = 1;
+ break;
+
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] cut -v,
Bonzini <=