[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
improvement to "paste" patch for Standard C conformance
From: |
Paul Eggert |
Subject: |
improvement to "paste" patch for Standard C conformance |
Date: |
Thu, 02 Sep 2004 18:39:14 -0700 |
I installed the following obvious little "paste" patch to improve on
the one I recently circulated.
2004-09-02 Paul Eggert <address@hidden>
* src/paste.c (paste_parallel): Use index test instead of NULL,
and NULL instead of a separate boolean array.
Index: paste.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/paste.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -p -u -r1.74 -r1.75
--- paste.c 2 Sep 2004 23:56:42 -0000 1.74
+++ paste.c 3 Sep 2004 01:23:15 -0000 1.75
@@ -148,12 +148,10 @@ paste_parallel (size_t nfiles, char **fn
store the delimiters for closed files. */
char *delbuf = xmalloc (nfiles + 2);
- /* Streams open to the files to process. */
+ /* Streams open to the files to process; NULL if the corresponding
+ stream is closed. */
FILE **fileptr = xnmalloc (nfiles + 1, sizeof *fileptr);
- /* Which of these streams are closed. */
- bool *closed = xcalloc (nfiles, sizeof *closed);
-
/* Number of files still open to process. */
size_t files_open;
@@ -181,8 +179,6 @@ paste_parallel (size_t nfiles, char **fn
}
}
- fileptr[files_open] = NULL;
-
if (opened_stdin && have_read_stdin)
error (EXIT_FAILURE, 0, _("standard input is closed"));
@@ -198,11 +194,12 @@ paste_parallel (size_t nfiles, char **fn
size_t delims_saved = 0; /* Number of delims saved in `delbuf'. */
size_t i;
- for (i = 0; fileptr[i] && files_open; i++)
+ for (i = 0; i < nfiles && files_open; i++)
{
int chr IF_LINT (= 0); /* Input character. */
size_t line_length = 0; /* Number of chars in line. */
- if (! closed[i])
+
+ if (fileptr[i])
{
chr = getc (fileptr[i]);
if (chr != EOF && delims_saved)
@@ -224,8 +221,8 @@ paste_parallel (size_t nfiles, char **fn
if (line_length == 0)
{
/* EOF, read error, or closed file.
- If an EOF or error, close the file and mark it in the list. */
- if (! closed[i])
+ If an EOF or error, close the file. */
+ if (fileptr[i])
{
if (ferror (fileptr[i]))
{
@@ -240,11 +237,11 @@ paste_parallel (size_t nfiles, char **fn
ok = false;
}
- closed[i] = true;
+ fileptr[i] = NULL;
files_open--;
}
- if (! fileptr[i + 1])
+ if (i + 1 == nfiles)
{
/* End of this output line.
Is this the end of the whole thing? */
@@ -275,7 +272,7 @@ paste_parallel (size_t nfiles, char **fn
somedone = true;
/* Except for last file, replace last newline with delim. */
- if (fileptr[i + 1])
+ if (i + 1 != nfiles)
{
if (chr != '\n' && chr != EOF)
putc (chr, stdout);
@@ -295,7 +292,6 @@ paste_parallel (size_t nfiles, char **fn
}
}
free (fileptr);
- free (closed);
free (delbuf);
return ok;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- improvement to "paste" patch for Standard C conformance,
Paul Eggert <=