On 25/06/16 07:44, Assaf Gordon wrote:
> Hello,
>
> The attached patches add more tests to expand/unexpand,
> then incrementally extract common functionality into a new module
> 'expand-common.h'.
> (The patches could be squashed before finalizing them, but easier to follow
> when separate).
>
> This could later serve as a basis for trying to add multibyte handling...
Very nice work, especially adding new tests.
Yes these should probably be squashed before pushing.
Attached is a trivial patch to pass syntax-check.
Size increase is negligible:
lt:coreutils (master)$ size src/{,un}expand
text data bss dec hex filename
39360 1108 496 40964 a004 src/expand
39890 1116 528 41534 a23e src/unexpand
lt:coreutils (expand *)$ size src/{,un}expand
text data bss dec hex filename
39792 1108 512 41412 a1c4 src/expand
40298 1116 512 41926 a3c6 src/unexpand
As part of this, or at least before looking at multibyte changes,
it would be worth considering this proposal for changing the
unexpand algorithm: http://bugs.gnu.org/23335
thanks!
Pádraig
diff --git a/src/expand-common.c b/src/expand-common.c
index 9c94441..41d7003 100644
--- a/src/expand-common.c
+++ b/src/expand-common.c
@@ -66,7 +66,7 @@ int exit_status = EXIT_SUCCESS;
/* Add tab stop TABVAL to the end of 'tab_list'. */
-void
+extern void
add_tab_stop (uintmax_t tabval)
{
uintmax_t prev_column = first_free_tab ? tab_list[first_free_tab - 1] : 0;
@@ -86,7 +86,7 @@ add_tab_stop (uintmax_t tabval)
/* Add the comma or blank separated list of tab stops STOPS
to the list of tab stops. */
-void
+extern void
parse_tab_stops (char const *stops)
{
bool have_tabval = false;
@@ -165,7 +165,7 @@ validate_tab_stops (uintmax_t const *tabs, size_t entries)
tab-stops = N (if value N specified as the only value).
tab-stops = distinct values given on command line (if multiple values given).
*/
-void
+extern void
finalize_tab_stops (void)
{
validate_tab_stops (tab_list, first_free_tab);
@@ -179,7 +179,7 @@ finalize_tab_stops (void)
}
-uintmax_t
+extern uintmax_t
get_next_tab_column (const uintmax_t column, size_t* tab_index,
bool* last_tab)
{
@@ -206,7 +206,7 @@ get_next_tab_column (const uintmax_t column, size_t* tab_index,
/* Sets new file-list */
-void
+extern void
set_file_list (char **list)
{
have_read_stdin = false;
@@ -222,7 +222,7 @@ set_file_list (char **list)
Open a filename of '-' as the standard input.
Return NULL if there are no more input files. */
-FILE *
+extern FILE *
next_file (FILE *fp)
{
static char *prev_file;
@@ -266,7 +266,7 @@ next_file (FILE *fp)
}
/* */
-void
+extern void
cleanup_file_list_stdin (void)
{
if (have_read_stdin && fclose (stdin) != 0)
diff --git a/src/expand-common.h b/src/expand-common.h
index 4d1074b..8cb2079 100644
--- a/src/expand-common.h
+++ b/src/expand-common.h
@@ -35,38 +35,38 @@ extern size_t max_column_width;
extern int exit_status;
/* Add tab stop TABVAL to the end of 'tab_list'. */
-void
+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. */
-void
+extern void
parse_tab_stops (char const *stops);
/* TODO: Document */
-uintmax_t
+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 */
-void
+extern void
finalize_tab_stops (void);
/* Sets new file-list */
-void
+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. */
-FILE *
+extern FILE *
next_file (FILE *fp);
/* */
-void
+extern void
cleanup_file_list_stdin (void);