diff options
author | Assaf Gordon <assafgordon@gmail.com> | 2015-07-17 23:30:30 -0400 |
---|---|---|
committer | Assaf Gordon <assafgordon@gmail.com> | 2015-09-12 02:27:32 +0000 |
commit | bd1bc2b3fe1c87744cc251334cc1c804075b027c (patch) | |
tree | 5baeb6bacf915762980ff3e87cd4f203814ffc28 /src/set-fields.h | |
parent | 5bbdcd2a02d9686edb788c46fc953192acdc6796 (diff) | |
download | coreutils-bd1bc2b3fe1c87744cc251334cc1c804075b027c.tar.xz |
cut: refactor into set-fields module
Extract the functionality of parsing --field=LIST into a separate
module, to be used by other programs.
* src/cut.c: move field parsing code from here ...
* src/set-fields.{c,h}: ... to here.
(set_fields): generalize by supporting multiple parsing/reporting
options.
(struct range_pair): rename to field_range_pair.
* src/local.mk: link cut with set-field.
* po/POTFILES.in: add set-field.c
* tests/misc/cut.pl: update wording of error messages
Diffstat (limited to 'src/set-fields.h')
-rw-r--r-- | src/set-fields.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/set-fields.h b/src/set-fields.h new file mode 100644 index 000000000..2c55c2984 --- /dev/null +++ b/src/set-fields.h @@ -0,0 +1,49 @@ +/* set-fields.h -- parse field list argument + + Copyright (C) 2015 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef SET_FIELDS_H +# define SET_FIELDS_H + +struct field_range_pair + { + size_t lo; + size_t hi; + }; + +/* Array of `struct range_pair' holding all the finite ranges. */ +extern struct field_range_pair *frp; + +/* Number of finite ranges specified by the user. */ +extern size_t n_frp; + +/* field list parsing options */ +enum +{ + SETFLD_ALLOW_DASH = 0x01, /* allow single dash meaning 'all fields' */ + SETFLD_COMPLEMENT = 0x02, /* complement the field list */ + SETFLD_ERRMSG_USE_POS = 0x04 /* when reporting errors, say 'position' instead + of 'field' (used with cut -b/-c) */ +}; + +/* allocates and initializes the FRP array and N_FRP count */ +void +set_fields (const char *fieldstr, unsigned int options); + +/* frees memory allocated by set_fields() */ +void +reset_fields (void); + +#endif |