/* paste: concatenate corresponding lines of each file in parallel(GWRL) */
/* (-s option: serial concatenation like old (127's) paste command */
/* make : cc paste.c -lS */
# define MAXOPNF 12 /* maximal no. of open files (not with -s option) */
# define MAXLINE 512 /* maximal line length */
char del
[MAXLINE
] = {"\t"};
int i
, j
, k
, eofcount
, nfiles
;
char outbuf
[MAXLINE
], c
, l
;
while (argc
> 1 && argv
[1][0] == '-' && (c
= argv
[1][1]) != '\0'){
if((delcount
= move(argv
[1], &del
[0])) == 0) diag("no delimiters\n",1);;
diag("Usage: paste [-s] [-d<delimiterstring>] file1 file2 ...", 1);
if ( ! onefile
) { /* not -s option: parallel line merging */
for (i
= 0; argc
>0 && i
< MAXOPNF
; i
++) {
if (argv
[i
+ 1][0] == '-') {
} else inptr
[i
] = fopen(argv
[i
+ 1], "r");
diag(" : cannot open\n", 1);
if (argc
> 0) diag("too many files\n",1);
for (i
= 0; i
< nfiles
; i
++) {
while((c
= getc(inptr
[i
])) != '\n' && c
!= EOF
) {
if (++j
<= MAXLINE
- 2) *p
++ = c
;
diag("line too long\n",1);
if ( (l
= del
[k
]) != RUB
) *p
++ = l
;
if( c
== EOF
) eofcount
++;
if (l
!= RUB
) *--p
= '\n'; else *p
= '\n';
if (eofcount
< nfiles
) fputs(outbuf
, stdout
);
}while (eofcount
< nfiles
);
} else { /* -s option: serial file pasting (old 127 paste command) */
for (i
= 1; i
<= argc
; i
++) {
} else inptr
[0] = fopen(argv
[i
], "r");
diag(" : cannot open\n", 1);
while((c
= getc(inptr
[0])) != EOF
) {
if (++j
<= MAXLINE
- 2) *p
++ = c
;
else diag("line too long\n",1);
if (l
!= '\n') fputs("\n", stdout
);
if (c
!= '\\') *to
++ = c
;