summaryrefslogtreecommitdiff
path: root/src/expand-common.h
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2016-06-24 21:48:29 -0400
committerPádraig Brady <P@draigBrady.com>2016-08-09 11:31:00 +0100
commitff2178bf30e3eda566cc1d1670768c6d6694a8ac (patch)
treee8e7c34c1250f671ca3b700799e96b428348138a /src/expand-common.h
parent1c17f61ef993a5ee5fb0d3bc47b7b25782ae386c (diff)
downloadcoreutils-ff2178bf30e3eda566cc1d1670768c6d6694a8ac.tar.xz
maint: refactor common expand(1) and unexpand(1) code
* src/expand.c, src/unexpand.c: Move global variables from here... * src/expand-common.h, src/expand-common.c: ... to here. * src/expand.c, src/unexpand.c: (parse_tab_stops, validate_tab_stops, next_file): Move identical functions to new module. (add_tab_stop): Move to new module, including additional code from 'unexpand' (keeping max_column_width) which will have no effect in when used in 'expand'. Refactor common next-column calculation code into a new function 'get_next_tab_column'. * src/local.mk: (src_expand_SOURCES, src_unexpand_SOURCES): Add 'expand-common.c'; (noinst_HEADERS): Add 'expand-common.h'. * po/POTFILES.in: Add 'expand-common.c'. * tests/misc/expand.pl: Add more tests. * tests/misc/unexpand.pl: Likewise. * TODO: Move conclusions to above test after investigation.
Diffstat (limited to 'src/expand-common.h')
-rw-r--r--src/expand-common.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/expand-common.h b/src/expand-common.h
new file mode 100644
index 000000000..8cb207997
--- /dev/null
+++ b/src/expand-common.h
@@ -0,0 +1,72 @@
+/* expand-common - common functionality for expand/unexapnd
+
+ Copyright (C) 1989-2016 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/>. */
+
+/* If true, convert blanks even after nonblank characters have been
+ read on the line. */
+extern bool convert_entire_line;
+
+/* The maximum distance between tab stops. */
+extern size_t max_column_width;
+
+/* Null-terminated array of input filenames. */
+//extern char **file_list;
+
+/* Default for 'file_list' if no files are given on the command line. */
+//extern char *stdin_argv[];
+
+/* True if we have ever read standard input. */
+//extern bool have_read_stdin;
+
+/* The desired exit status. */
+extern int exit_status;
+
+/* Add tab stop TABVAL to the end of 'tab_list'. */
+extern void
+add_tab_stop (uintmax_t tabval);
+
+/* Add the comma or blank separated list of tab stops STOPS
+ to the list of tab stops. */
+extern void
+parse_tab_stops (char const *stops);
+
+/* TODO: Document */
+extern uintmax_t
+get_next_tab_column (const uintmax_t column, size_t* tab_index,
+ bool* last_tab);
+
+/* Called after all command-line options have been parsed,
+ sets the final tab-stops values */
+extern void
+finalize_tab_stops (void);
+
+
+
+
+/* Sets new file-list */
+extern void
+set_file_list (char **file_list);
+
+/* Close the old stream pointer FP if it is non-NULL,
+ and return a new one opened to read the next input file.
+ Open a filename of '-' as the standard input.
+ Return NULL if there are no more input files. */
+extern FILE *
+next_file (FILE *fp);
+
+/* */
+extern void
+cleanup_file_list_stdin (void);