summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-11-02 17:06:52 +0000
committerJim Meyering <jim@meyering.net>1995-11-02 17:06:52 +0000
commitac821ab1efc5cf399416a430a89c2c1ce78189be (patch)
tree595106a85d93df91514772da2e8706e1eb7e5d31 /src
parent6e146d42169470866f809ee948a5c72a08b0de73 (diff)
downloadcoreutils-ac821ab1efc5cf399416a430a89c2c1ce78189be.tar.xz
Reorder functions to obviate forward dcls.
Remove forward dcls.
Diffstat (limited to 'src')
-rw-r--r--src/unexpand.c281
1 files changed, 137 insertions, 144 deletions
diff --git a/src/unexpand.c b/src/unexpand.c
index 4fd93788f..cdd121a3d 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -58,13 +58,6 @@
char *xmalloc ();
char *xrealloc ();
-static FILE *next_file ();
-static void add_tabstop ();
-static void parse_tabstops ();
-static void unexpand ();
-static void usage ();
-static void validate_tabstops ();
-
/* The name this program was run with. */
char *program_name;
@@ -114,82 +107,18 @@ static struct option const longopts[] =
{NULL, 0, NULL, 0}
};
-void
-main (argc, argv)
- int argc;
- char **argv;
-{
- int tabval = -1; /* Value of tabstop being read, or -1. */
- int c; /* Option character. */
-
- have_read_stdin = 0;
- exit_status = 0;
- convert_entire_line = 0;
- tab_list = NULL;
- first_free_tab = 0;
- program_name = argv[0];
-
- while ((c = getopt_long (argc, argv, "at:,0123456789", longopts, (int *) 0))
- != EOF)
- {
- switch (c)
- {
- case 0:
- break;
-
- case '?':
- usage (1);
- case 'a':
- convert_entire_line = 1;
- break;
- case 't':
- convert_entire_line = 1;
- parse_tabstops (optarg);
- break;
- case ',':
- add_tabstop (tabval);
- tabval = -1;
- break;
- default:
- if (tabval == -1)
- tabval = 0;
- tabval = tabval * 10 + c - '0';
- break;
- }
- }
-
- if (show_version)
- {
- printf ("unexpand - %s\n", version_string);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
- add_tabstop (tabval);
-
- validate_tabstops (tab_list, first_free_tab);
-
- if (first_free_tab == 0)
- tab_size = 8;
- else if (first_free_tab == 1)
- tab_size = tab_list[0];
- else
- tab_size = 0;
-
- if (optind == argc)
- file_list = stdin_argv;
- else
- file_list = &argv[optind];
-
- unexpand ();
+/* Add tab stop TABVAL to the end of `tab_list', except
+ if TABVAL is -1, do nothing. */
- if (have_read_stdin && fclose (stdin) == EOF)
- error (1, errno, "-");
- if (fclose (stdout) == EOF)
- error (1, errno, _("write error"));
- exit (exit_status);
+static void
+add_tabstop (tabval)
+ int tabval;
+{
+ if (tabval == -1)
+ return;
+ if (first_free_tab % TABLIST_BLOCK == 0)
+ tab_list = (int *) xrealloc (tab_list, first_free_tab + TABLIST_BLOCK);
+ tab_list[first_free_tab++] = tabval;
}
/* Add the comma or blank separated list of tabstops STOPS
@@ -221,20 +150,6 @@ parse_tabstops (stops)
add_tabstop (tabval);
}
-/* Add tab stop TABVAL to the end of `tab_list', except
- if TABVAL is -1, do nothing. */
-
-static void
-add_tabstop (tabval)
- int tabval;
-{
- if (tabval == -1)
- return;
- if (first_free_tab % TABLIST_BLOCK == 0)
- tab_list = (int *) xrealloc (tab_list, first_free_tab + TABLIST_BLOCK);
- tab_list[first_free_tab++] = tabval;
-}
-
/* Check that the list of tabstops TABS, with ENTRIES entries,
contains only nonzero, ascending values. */
@@ -256,6 +171,54 @@ validate_tabstops (tabs, entries)
}
}
+/* 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. */
+
+static FILE *
+next_file (fp)
+ FILE *fp;
+{
+ static char *prev_file;
+ char *file;
+
+ if (fp)
+ {
+ if (ferror (fp))
+ {
+ error (0, errno, "%s", prev_file);
+ exit_status = 1;
+ }
+ if (fp == stdin)
+ clearerr (fp); /* Also clear EOF. */
+ else if (fclose (fp) == EOF)
+ {
+ error (0, errno, "%s", prev_file);
+ exit_status = 1;
+ }
+ }
+
+ while ((file = *file_list++) != NULL)
+ {
+ if (file[0] == '-' && file[1] == '\0')
+ {
+ have_read_stdin = 1;
+ prev_file = file;
+ return stdin;
+ }
+ fp = fopen (file, "r");
+ if (fp)
+ {
+ prev_file = file;
+ return fp;
+ }
+ error (0, errno, "%s", file);
+ exit_status = 1;
+ }
+ return NULL;
+}
+
/* Change spaces to tabs, writing to stdout.
Read each file in `file_list', in order. */
@@ -391,54 +354,6 @@ unexpand ()
}
}
-/* 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. */
-
-static FILE *
-next_file (fp)
- FILE *fp;
-{
- static char *prev_file;
- char *file;
-
- if (fp)
- {
- if (ferror (fp))
- {
- error (0, errno, "%s", prev_file);
- exit_status = 1;
- }
- if (fp == stdin)
- clearerr (fp); /* Also clear EOF. */
- else if (fclose (fp) == EOF)
- {
- error (0, errno, "%s", prev_file);
- exit_status = 1;
- }
- }
-
- while ((file = *file_list++) != NULL)
- {
- if (file[0] == '-' && file[1] == '\0')
- {
- have_read_stdin = 1;
- prev_file = file;
- return stdin;
- }
- fp = fopen (file, "r");
- if (fp)
- {
- prev_file = file;
- return fp;
- }
- error (0, errno, "%s", file);
- exit_status = 1;
- }
- return NULL;
-}
-
static void
usage (status)
int status;
@@ -467,3 +382,81 @@ Instead of -t NUMBER or -t LIST, -NUMBER or -LIST may be used.\n\
}
exit (status);
}
+
+void
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int tabval = -1; /* Value of tabstop being read, or -1. */
+ int c; /* Option character. */
+
+ have_read_stdin = 0;
+ exit_status = 0;
+ convert_entire_line = 0;
+ tab_list = NULL;
+ first_free_tab = 0;
+ program_name = argv[0];
+
+ while ((c = getopt_long (argc, argv, "at:,0123456789", longopts, (int *) 0))
+ != EOF)
+ {
+ switch (c)
+ {
+ case 0:
+ break;
+
+ case '?':
+ usage (1);
+ case 'a':
+ convert_entire_line = 1;
+ break;
+ case 't':
+ convert_entire_line = 1;
+ parse_tabstops (optarg);
+ break;
+ case ',':
+ add_tabstop (tabval);
+ tabval = -1;
+ break;
+ default:
+ if (tabval == -1)
+ tabval = 0;
+ tabval = tabval * 10 + c - '0';
+ break;
+ }
+ }
+
+ if (show_version)
+ {
+ printf ("unexpand - %s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage (0);
+
+ add_tabstop (tabval);
+
+ validate_tabstops (tab_list, first_free_tab);
+
+ if (first_free_tab == 0)
+ tab_size = 8;
+ else if (first_free_tab == 1)
+ tab_size = tab_list[0];
+ else
+ tab_size = 0;
+
+ if (optind == argc)
+ file_list = stdin_argv;
+ else
+ file_list = &argv[optind];
+
+ unexpand ();
+
+ if (have_read_stdin && fclose (stdin) == EOF)
+ error (1, errno, "-");
+ if (fclose (stdout) == EOF)
+ error (1, errno, _("write error"));
+ exit (exit_status);
+}