paste.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1994 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
* All Rights Reserved
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <locale.h>
#include <widec.h>
#include <stdlib.h>
#include <limits.h>
#define MAXOPNF_STR "12"
#define RUB '\177'
/*
* Function prototypes
*/
static void diag(char *, char *);
static void usage();
{
int delcount = 1;
int onefile = 0;
register int c;
register wchar_t *p;
int arg_ind;
int file_ind;
int error = 0;
/* Get locale variables from environment */
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
del[0] = '\t';
/* Get command arguments */
switch (c) {
case 'd' :
if (delcount < 1)
break;
case 's' :
onefile++;
break;
case '?':
usage();
/* NOTREACHED */
break;
}
}
if (!onefile) { /* not -s option: parallel line merging */
/* Find explicit stdin and file names */
diag("paste: cannot open %s\n",
}
}
}
char maxopnf_buf[LINE_MAX];
}
do {
p = &outbuf[0];
eofcount = 0;
j = k = 0;
for (i = 0; i < nfiles; i++) {
c != EOF) {
if (++j <= maxline)
*p++ = c;
else {
diag(
"paste: line too long\n",
NULL);
}
}
*p++ = l;
k = (k + 1) % delcount;
if (c == EOF)
eofcount++;
}
if (l != RUB)
*--p = '\n';
else
*p = '\n';
*++p = 0;
} else { /* -s option: serial file pasting (old 127 paste command) */
p = &outbuf[0];
glue = 0;
j = 0;
k = 0;
t = 0;
if (argv[i][0] == '-' &&
} else if (i >= optind) {
"paste: cannot open %s\n"), argv[i]);
error = 1;
}
}
/* Argument not a file name */
continue;
}
if (j >= maxline) {
t = *--p;
*++p = 0;
p = &outbuf[0];
j = 0;
}
if (glue) {
glue = 0;
l = del[k];
if (l != RUB) {
*p++ = l;
t = l;
j++;
}
k = (k + 1) % delcount;
}
if (c != '\n') {
*p++ = c;
t = c;
j++;
} else glue++;
}
if (t != '\n') {
*p++ = '\n';
j++;
}
if (j > 0) {
*p = 0;
}
}
}
return (error);
}
static void
{
exit(1);
}
static int
{
int i, n;
i = 0;
while (*from) {
if (n <= 0)
return (0); /* invalid character as a delimiter */
from += n;
else {
if (n <= 0)
return (0);
from += n;
switch (wc) {
break;
break;
break;
break;
}
}
i++;
}
return (i);
}
static void
usage()
{
"usage: paste [-s] [-d list] file \n\n"));
exit(1);
}