1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
$NetBSD: patch-ak,v 1.1 2006/01/09 22:45:08 joerg Exp $
--- src/paste.c.orig 2006-01-03 17:23:26.000000000 +0000
+++ src/paste.c
@@ -52,14 +52,6 @@
/* Indicates that no delimiter should be added in the current position. */
#define EMPTY_DELIM '\0'
-static FILE dummy_closed;
-/* Element marking a file that has reached EOF and been closed. */
-#define CLOSED (&dummy_closed)
-
-static FILE dummy_endlist;
-/* Element marking end of list of open files. */
-#define ENDLIST (&dummy_endlist)
-
/* Name this program was run with. */
char *program_name;
@@ -76,6 +68,8 @@ static char *delims;
/* A pointer to the character after the end of `delims'. */
static char const *delim_end;
+#define CLOSED NULL
+
static struct option const longopts[] =
{
{"serial", no_argument, 0, 's'},
@@ -156,7 +150,7 @@ paste_parallel (size_t nfiles, char **fn
store the delimiters for closed files. */
char *delbuf;
FILE **fileptr; /* Streams open to the files to process. */
- size_t files_open; /* Number of files still open to process. */
+ size_t files_open, last_file; /* Number of files still open to process. */
bool opened_stdin = false; /* true if any fopen got fd == STDIN_FILENO */
delbuf = xmalloc (nfiles + 2);
@@ -183,7 +177,7 @@ paste_parallel (size_t nfiles, char **fn
}
}
- fileptr[files_open] = ENDLIST;
+ last_file = files_open;
if (opened_stdin && have_read_stdin)
error (EXIT_FAILURE, 0, _("standard input is closed"));
@@ -200,7 +194,7 @@ 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] != ENDLIST && files_open; i++)
+ for (i = 0; i < last_file && files_open; i++)
{
int chr IF_LINT (= 0); /* Input character. */
size_t line_length = 0; /* Number of chars in line. */
@@ -246,7 +240,7 @@ paste_parallel (size_t nfiles, char **fn
files_open--;
}
- if (fileptr[i + 1] == ENDLIST)
+ if (i + 1 == last_file)
{
/* End of this output line.
Is this the end of the whole thing? */
@@ -277,7 +271,7 @@ paste_parallel (size_t nfiles, char **fn
somedone = true;
/* Except for last file, replace last newline with delim. */
- if (fileptr[i + 1] != ENDLIST)
+ if (i + 1 != last_file)
{
if (chr != '\n' && chr != EOF)
putc (chr, stdout);
|