xref: /illumos-gate/usr/src/cmd/dd/dd.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  *	convert and copy
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include	<stdio.h>
38*7c478bd9Sstevel@tonic-gate #include	<signal.h>
39*7c478bd9Sstevel@tonic-gate #include	<fcntl.h>
40*7c478bd9Sstevel@tonic-gate #include	<sys/param.h>
41*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
42*7c478bd9Sstevel@tonic-gate #include	<sys/sysmacros.h>
43*7c478bd9Sstevel@tonic-gate #include	<sys/stat.h>
44*7c478bd9Sstevel@tonic-gate #include	<unistd.h>
45*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
46*7c478bd9Sstevel@tonic-gate #include	<locale.h>
47*7c478bd9Sstevel@tonic-gate #include	<string.h>
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /* The BIG parameter is machine dependent.  It should be a long integer	*/
50*7c478bd9Sstevel@tonic-gate /* constant that can be used by the number parser to check the validity	*/
51*7c478bd9Sstevel@tonic-gate /* of numeric parameters.  On 16-bit machines, it should probably be	*/
52*7c478bd9Sstevel@tonic-gate /* the maximum unsigned integer, 0177777L.  On 32-bit machines where	*/
53*7c478bd9Sstevel@tonic-gate /* longs are the same size as ints, the maximum signed integer is more	*/
54*7c478bd9Sstevel@tonic-gate /* appropriate.  This value is 017777777777L. In 64 bit environments,   */
55*7c478bd9Sstevel@tonic-gate /* the maximum signed integer value is 0777777777777777777777LL		*/
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #define	BIG	0777777777777777777777LL
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #define	BSIZE	512
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /* Option parameters */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #define	COPY		0	/* file copy, preserve input block size */
64*7c478bd9Sstevel@tonic-gate #define	REBLOCK		1	/* file copy, change block size */
65*7c478bd9Sstevel@tonic-gate #define	LCREBLOCK	2	/* file copy, convert to lower case */
66*7c478bd9Sstevel@tonic-gate #define	UCREBLOCK	3	/* file copy, convert to upper case */
67*7c478bd9Sstevel@tonic-gate #define	NBASCII		4	/* file copy, convert from EBCDIC to ASCII */
68*7c478bd9Sstevel@tonic-gate #define	LCNBASCII	5	/* file copy, EBCDIC to lower case ASCII */
69*7c478bd9Sstevel@tonic-gate #define	UCNBASCII	6	/* file copy, EBCDIC to upper case ASCII */
70*7c478bd9Sstevel@tonic-gate #define	NBEBCDIC	7	/* file copy, convert from ASCII to EBCDIC */
71*7c478bd9Sstevel@tonic-gate #define	LCNBEBCDIC	8	/* file copy, ASCII to lower case EBCDIC */
72*7c478bd9Sstevel@tonic-gate #define	UCNBEBCDIC	9	/* file copy, ASCII to upper case EBCDIC */
73*7c478bd9Sstevel@tonic-gate #define	NBIBM		10	/* file copy, convert from ASCII to IBM */
74*7c478bd9Sstevel@tonic-gate #define	LCNBIBM		11	/* file copy, ASCII to lower case IBM */
75*7c478bd9Sstevel@tonic-gate #define	UCNBIBM		12	/* file copy, ASCII to upper case IBM */
76*7c478bd9Sstevel@tonic-gate #define	UNBLOCK		13	/* convert blocked ASCII to ASCII */
77*7c478bd9Sstevel@tonic-gate #define	LCUNBLOCK	14	/* convert blocked ASCII to lower case ASCII */
78*7c478bd9Sstevel@tonic-gate #define	UCUNBLOCK	15	/* convert blocked ASCII to upper case ASCII */
79*7c478bd9Sstevel@tonic-gate #define	ASCII		16	/* convert blocked EBCDIC to ASCII */
80*7c478bd9Sstevel@tonic-gate #define	LCASCII		17	/* convert blocked EBCDIC to lower case ASCII */
81*7c478bd9Sstevel@tonic-gate #define	UCASCII		18	/* convert blocked EBCDIC to upper case ASCII */
82*7c478bd9Sstevel@tonic-gate #define	BLOCK		19	/* convert ASCII to blocked ASCII */
83*7c478bd9Sstevel@tonic-gate #define	LCBLOCK		20	/* convert ASCII to lower case blocked ASCII */
84*7c478bd9Sstevel@tonic-gate #define	UCBLOCK		21	/* convert ASCII to upper case blocked ASCII */
85*7c478bd9Sstevel@tonic-gate #define	EBCDIC		22	/* convert ASCII to blocked EBCDIC */
86*7c478bd9Sstevel@tonic-gate #define	LCEBCDIC	23	/* convert ASCII to lower case blocked EBCDIC */
87*7c478bd9Sstevel@tonic-gate #define	UCEBCDIC	24	/* convert ASCII to upper case blocked EBCDIC */
88*7c478bd9Sstevel@tonic-gate #define	IBM		25	/* convert ASCII to blocked IBM */
89*7c478bd9Sstevel@tonic-gate #define	LCIBM		26	/* convert ASCII to lower case blocked IBM */
90*7c478bd9Sstevel@tonic-gate #define	UCIBM		27	/* convert ASCII to upper case blocked IBM */
91*7c478bd9Sstevel@tonic-gate #define	LCASE		01	/* flag - convert to lower case */
92*7c478bd9Sstevel@tonic-gate #define	UCASE		02	/* flag - convert to upper case */
93*7c478bd9Sstevel@tonic-gate #define	SWAB		04	/* flag - swap bytes before conversion */
94*7c478bd9Sstevel@tonic-gate #define	NERR		010	/* flag - proceed on input errors */
95*7c478bd9Sstevel@tonic-gate #define	SYNC		020	/* flag - pad short input blocks with nulls */
96*7c478bd9Sstevel@tonic-gate #define	BADLIMIT	5	/* give up if no progress after BADLIMIT trys */
97*7c478bd9Sstevel@tonic-gate #define	SVR4XLATE	0	/* use default EBCDIC translation */
98*7c478bd9Sstevel@tonic-gate #define	BSDXLATE	1	/* use BSD-compatible EBCDIC translation */
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate #define	USAGE\
101*7c478bd9Sstevel@tonic-gate 	"usage: dd [if=file] [of=file] [ibs=n|nk|nb|nxm] [obs=n|nk|nb|nxm]\n"\
102*7c478bd9Sstevel@tonic-gate 	"	   [bs=n|nk|nb|nxm] [cbs=n|nk|nb|nxm] [files=n] [skip=n]\n"\
103*7c478bd9Sstevel@tonic-gate 	"	   [iseek=n] [oseek=n] [seek=n] [count=n] [conv=[ascii]\n"\
104*7c478bd9Sstevel@tonic-gate 	"	   [,ebcdic][,ibm][,asciib][,ebcdicb][,ibmb]\n"\
105*7c478bd9Sstevel@tonic-gate 	"	   [,block|unblock][,lcase|ucase][,swab]\n"\
106*7c478bd9Sstevel@tonic-gate 	"	   [,noerror][,notrunc][,sync]]\n"
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /* Global references */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /* Local routine declarations */
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate static int	match(char *);
113*7c478bd9Sstevel@tonic-gate static void		term();
114*7c478bd9Sstevel@tonic-gate static unsigned long long	number();
115*7c478bd9Sstevel@tonic-gate static unsigned char	*flsh();
116*7c478bd9Sstevel@tonic-gate static void		stats();
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /* Local data definitions */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate static unsigned ibs;	/* input buffer size */
121*7c478bd9Sstevel@tonic-gate static unsigned obs;	/* output buffer size */
122*7c478bd9Sstevel@tonic-gate static unsigned bs;	/* buffer size, overrules ibs and obs */
123*7c478bd9Sstevel@tonic-gate static unsigned cbs;	/* conversion buffer size, used for block conversions */
124*7c478bd9Sstevel@tonic-gate static unsigned ibc;	/* number of bytes still in the input buffer */
125*7c478bd9Sstevel@tonic-gate static unsigned obc;	/* number of bytes in the output buffer */
126*7c478bd9Sstevel@tonic-gate static unsigned cbc;	/* number of bytes in the conversion buffer */
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate static int	ibf;	/* input file descriptor */
129*7c478bd9Sstevel@tonic-gate static int	obf;	/* output file descriptor */
130*7c478bd9Sstevel@tonic-gate static int	cflag;	/* conversion option flags */
131*7c478bd9Sstevel@tonic-gate static int	skipf;	/* if skipf == 1, skip rest of input line */
132*7c478bd9Sstevel@tonic-gate static unsigned long long	nifr;	/* count of full input records */
133*7c478bd9Sstevel@tonic-gate static unsigned long long	nipr;	/* count of partial input records */
134*7c478bd9Sstevel@tonic-gate static unsigned long long	nofr;	/* count of full output records */
135*7c478bd9Sstevel@tonic-gate static unsigned long long	nopr;	/* count of partial output records */
136*7c478bd9Sstevel@tonic-gate static unsigned long long	ntrunc;	/* count of truncated input lines */
137*7c478bd9Sstevel@tonic-gate static unsigned long long	nbad;	/* count of bad records since last */
138*7c478bd9Sstevel@tonic-gate 					/* good one */
139*7c478bd9Sstevel@tonic-gate static int	files;	/* number of input files to concatenate (tape only) */
140*7c478bd9Sstevel@tonic-gate static off_t	skip;	/* number of input records to skip */
141*7c478bd9Sstevel@tonic-gate static off_t	iseekn;	/* number of input records to seek past */
142*7c478bd9Sstevel@tonic-gate static off_t	oseekn;	/* number of output records to seek past */
143*7c478bd9Sstevel@tonic-gate static unsigned long long	count;	/* number of input records to copy */
144*7c478bd9Sstevel@tonic-gate 			/* (0 = all) */
145*7c478bd9Sstevel@tonic-gate static int	trantype; /* BSD or SVr4 compatible EBCDIC */
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate static char		*string;	/* command arg pointer */
148*7c478bd9Sstevel@tonic-gate static char		*ifile;		/* input file name pointer */
149*7c478bd9Sstevel@tonic-gate static char		*ofile;		/* output file name pointer */
150*7c478bd9Sstevel@tonic-gate static unsigned char	*ibuf;		/* input buffer pointer */
151*7c478bd9Sstevel@tonic-gate static unsigned char	*obuf;		/* output buffer pointer */
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate /* This is an EBCDIC to ASCII conversion table	*/
154*7c478bd9Sstevel@tonic-gate /* from a proposed BTL standard April 16, 1979	*/
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate static unsigned char svr4_etoa [] =
157*7c478bd9Sstevel@tonic-gate {
158*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177,
159*7c478bd9Sstevel@tonic-gate 	0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017,
160*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207,
161*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037,
162*7c478bd9Sstevel@tonic-gate 	0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033,
163*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007,
164*7c478bd9Sstevel@tonic-gate 	0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004,
165*7c478bd9Sstevel@tonic-gate 	0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032,
166*7c478bd9Sstevel@tonic-gate 	0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246,
167*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0325, 0056, 0074, 0050, 0053, 0174,
168*7c478bd9Sstevel@tonic-gate 	0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
169*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0041, 0044, 0052, 0051, 0073, 0176,
170*7c478bd9Sstevel@tonic-gate 	0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267,
171*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0313, 0054, 0045, 0137, 0076, 0077,
172*7c478bd9Sstevel@tonic-gate 	0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301,
173*7c478bd9Sstevel@tonic-gate 	0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042,
174*7c478bd9Sstevel@tonic-gate 	0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
175*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311,
176*7c478bd9Sstevel@tonic-gate 	0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160,
177*7c478bd9Sstevel@tonic-gate 	0161, 0162, 0136, 0314, 0315, 0316, 0317, 0320,
178*7c478bd9Sstevel@tonic-gate 	0321, 0345, 0163, 0164, 0165, 0166, 0167, 0170,
179*7c478bd9Sstevel@tonic-gate 	0171, 0172, 0322, 0323, 0324, 0133, 0326, 0327,
180*7c478bd9Sstevel@tonic-gate 	0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
181*7c478bd9Sstevel@tonic-gate 	0340, 0341, 0342, 0343, 0344, 0135, 0346, 0347,
182*7c478bd9Sstevel@tonic-gate 	0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
183*7c478bd9Sstevel@tonic-gate 	0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355,
184*7c478bd9Sstevel@tonic-gate 	0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120,
185*7c478bd9Sstevel@tonic-gate 	0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363,
186*7c478bd9Sstevel@tonic-gate 	0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130,
187*7c478bd9Sstevel@tonic-gate 	0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371,
188*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
189*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377,
190*7c478bd9Sstevel@tonic-gate };
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate /* This is an ASCII to EBCDIC conversion table	*/
193*7c478bd9Sstevel@tonic-gate /* from a proposed BTL standard April 16, 1979	*/
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate static unsigned char svr4_atoe [] =
196*7c478bd9Sstevel@tonic-gate {
197*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
198*7c478bd9Sstevel@tonic-gate 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
199*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046,
200*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
201*7c478bd9Sstevel@tonic-gate 	0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175,
202*7c478bd9Sstevel@tonic-gate 	0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
203*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
204*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
205*7c478bd9Sstevel@tonic-gate 	0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
206*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
207*7c478bd9Sstevel@tonic-gate 	0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346,
208*7c478bd9Sstevel@tonic-gate 	0347, 0350, 0351, 0255, 0340, 0275, 0232, 0155,
209*7c478bd9Sstevel@tonic-gate 	0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
210*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
211*7c478bd9Sstevel@tonic-gate 	0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246,
212*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0251, 0300, 0117, 0320, 0137, 0007,
213*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027,
214*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
215*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010,
216*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
217*7c478bd9Sstevel@tonic-gate 	0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110,
218*7c478bd9Sstevel@tonic-gate 	0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
219*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147,
220*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
221*7c478bd9Sstevel@tonic-gate 	0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215,
222*7c478bd9Sstevel@tonic-gate 	0216, 0217, 0220, 0152, 0233, 0234, 0235, 0236,
223*7c478bd9Sstevel@tonic-gate 	0237, 0240, 0252, 0253, 0254, 0112, 0256, 0257,
224*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
225*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0241, 0276, 0277,
226*7c478bd9Sstevel@tonic-gate 	0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
227*7c478bd9Sstevel@tonic-gate 	0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355,
228*7c478bd9Sstevel@tonic-gate 	0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
229*7c478bd9Sstevel@tonic-gate };
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate /* Table for ASCII to IBM (alternate EBCDIC) code conversion	*/
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate static unsigned char svr4_atoibm[] =
234*7c478bd9Sstevel@tonic-gate {
235*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
236*7c478bd9Sstevel@tonic-gate 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
237*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046,
238*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
239*7c478bd9Sstevel@tonic-gate 	0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175,
240*7c478bd9Sstevel@tonic-gate 	0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
241*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
242*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
243*7c478bd9Sstevel@tonic-gate 	0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
244*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
245*7c478bd9Sstevel@tonic-gate 	0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346,
246*7c478bd9Sstevel@tonic-gate 	0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155,
247*7c478bd9Sstevel@tonic-gate 	0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
248*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
249*7c478bd9Sstevel@tonic-gate 	0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246,
250*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007,
251*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027,
252*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
253*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010,
254*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
255*7c478bd9Sstevel@tonic-gate 	0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110,
256*7c478bd9Sstevel@tonic-gate 	0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
257*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147,
258*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
259*7c478bd9Sstevel@tonic-gate 	0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215,
260*7c478bd9Sstevel@tonic-gate 	0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236,
261*7c478bd9Sstevel@tonic-gate 	0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257,
262*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
263*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
264*7c478bd9Sstevel@tonic-gate 	0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
265*7c478bd9Sstevel@tonic-gate 	0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355,
266*7c478bd9Sstevel@tonic-gate 	0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
267*7c478bd9Sstevel@tonic-gate };
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate /* Table for conversion of ASCII to lower case ASCII	*/
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate static unsigned char utol[] =
272*7c478bd9Sstevel@tonic-gate {
273*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
274*7c478bd9Sstevel@tonic-gate 	0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
275*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
276*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
277*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
278*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
279*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
280*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
281*7c478bd9Sstevel@tonic-gate 	0100, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
282*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
283*7c478bd9Sstevel@tonic-gate 	0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
284*7c478bd9Sstevel@tonic-gate 	0170, 0171, 0172, 0133, 0134, 0135, 0136, 0137,
285*7c478bd9Sstevel@tonic-gate 	0140, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
286*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
287*7c478bd9Sstevel@tonic-gate 	0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
288*7c478bd9Sstevel@tonic-gate 	0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177,
289*7c478bd9Sstevel@tonic-gate 	0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
290*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
291*7c478bd9Sstevel@tonic-gate 	0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
292*7c478bd9Sstevel@tonic-gate 	0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
293*7c478bd9Sstevel@tonic-gate 	0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
294*7c478bd9Sstevel@tonic-gate 	0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
295*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
296*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
297*7c478bd9Sstevel@tonic-gate 	0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
298*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
299*7c478bd9Sstevel@tonic-gate 	0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
300*7c478bd9Sstevel@tonic-gate 	0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
301*7c478bd9Sstevel@tonic-gate 	0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
302*7c478bd9Sstevel@tonic-gate 	0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
303*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
304*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
305*7c478bd9Sstevel@tonic-gate };
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate /* Table for conversion of ASCII to upper case ASCII	*/
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate static unsigned char ltou[] =
310*7c478bd9Sstevel@tonic-gate {
311*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
312*7c478bd9Sstevel@tonic-gate 	0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
313*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
314*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
315*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
316*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
317*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
318*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
319*7c478bd9Sstevel@tonic-gate 	0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
320*7c478bd9Sstevel@tonic-gate 	0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
321*7c478bd9Sstevel@tonic-gate 	0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
322*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
323*7c478bd9Sstevel@tonic-gate 	0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
324*7c478bd9Sstevel@tonic-gate 	0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
325*7c478bd9Sstevel@tonic-gate 	0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
326*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
327*7c478bd9Sstevel@tonic-gate 	0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
328*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
329*7c478bd9Sstevel@tonic-gate 	0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
330*7c478bd9Sstevel@tonic-gate 	0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
331*7c478bd9Sstevel@tonic-gate 	0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
332*7c478bd9Sstevel@tonic-gate 	0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
333*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
334*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
335*7c478bd9Sstevel@tonic-gate 	0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
336*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
337*7c478bd9Sstevel@tonic-gate 	0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
338*7c478bd9Sstevel@tonic-gate 	0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
339*7c478bd9Sstevel@tonic-gate 	0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
340*7c478bd9Sstevel@tonic-gate 	0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
341*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
342*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
343*7c478bd9Sstevel@tonic-gate };
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate /* BSD-compatible EBCDIC to ASCII translate table */
346*7c478bd9Sstevel@tonic-gate 
347*7c478bd9Sstevel@tonic-gate static unsigned char	bsd_etoa[] =
348*7c478bd9Sstevel@tonic-gate {
349*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177,
350*7c478bd9Sstevel@tonic-gate 	0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017,
351*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207,
352*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037,
353*7c478bd9Sstevel@tonic-gate 	0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033,
354*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007,
355*7c478bd9Sstevel@tonic-gate 	0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004,
356*7c478bd9Sstevel@tonic-gate 	0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032,
357*7c478bd9Sstevel@tonic-gate 	0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246,
358*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0133, 0056, 0074, 0050, 0053, 0041,
359*7c478bd9Sstevel@tonic-gate 	0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
360*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0135, 0044, 0052, 0051, 0073, 0136,
361*7c478bd9Sstevel@tonic-gate 	0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267,
362*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0174, 0054, 0045, 0137, 0076, 0077,
363*7c478bd9Sstevel@tonic-gate 	0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301,
364*7c478bd9Sstevel@tonic-gate 	0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042,
365*7c478bd9Sstevel@tonic-gate 	0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
366*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311,
367*7c478bd9Sstevel@tonic-gate 	0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160,
368*7c478bd9Sstevel@tonic-gate 	0161, 0162, 0313, 0314, 0315, 0316, 0317, 0320,
369*7c478bd9Sstevel@tonic-gate 	0321, 0176, 0163, 0164, 0165, 0166, 0167, 0170,
370*7c478bd9Sstevel@tonic-gate 	0171, 0172, 0322, 0323, 0324, 0325, 0326, 0327,
371*7c478bd9Sstevel@tonic-gate 	0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
372*7c478bd9Sstevel@tonic-gate 	0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
373*7c478bd9Sstevel@tonic-gate 	0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
374*7c478bd9Sstevel@tonic-gate 	0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355,
375*7c478bd9Sstevel@tonic-gate 	0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120,
376*7c478bd9Sstevel@tonic-gate 	0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363,
377*7c478bd9Sstevel@tonic-gate 	0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130,
378*7c478bd9Sstevel@tonic-gate 	0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371,
379*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
380*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377,
381*7c478bd9Sstevel@tonic-gate };
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate /* BSD-compatible ASCII to EBCDIC translate table */
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate static unsigned char	bsd_atoe[] =
386*7c478bd9Sstevel@tonic-gate {
387*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
388*7c478bd9Sstevel@tonic-gate 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
389*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046,
390*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
391*7c478bd9Sstevel@tonic-gate 	0100, 0117, 0177, 0173, 0133, 0154, 0120, 0175,
392*7c478bd9Sstevel@tonic-gate 	0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
393*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
394*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
395*7c478bd9Sstevel@tonic-gate 	0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
396*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
397*7c478bd9Sstevel@tonic-gate 	0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346,
398*7c478bd9Sstevel@tonic-gate 	0347, 0350, 0351, 0112, 0340, 0132, 0137, 0155,
399*7c478bd9Sstevel@tonic-gate 	0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
400*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
401*7c478bd9Sstevel@tonic-gate 	0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246,
402*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0251, 0300, 0152, 0320, 0241, 0007,
403*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027,
404*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
405*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010,
406*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
407*7c478bd9Sstevel@tonic-gate 	0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110,
408*7c478bd9Sstevel@tonic-gate 	0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
409*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147,
410*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
411*7c478bd9Sstevel@tonic-gate 	0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215,
412*7c478bd9Sstevel@tonic-gate 	0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236,
413*7c478bd9Sstevel@tonic-gate 	0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257,
414*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
415*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
416*7c478bd9Sstevel@tonic-gate 	0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
417*7c478bd9Sstevel@tonic-gate 	0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355,
418*7c478bd9Sstevel@tonic-gate 	0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
419*7c478bd9Sstevel@tonic-gate };
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate /* BSD-compatible ASCII to IBM translate table */
422*7c478bd9Sstevel@tonic-gate 
423*7c478bd9Sstevel@tonic-gate static unsigned char	bsd_atoibm[] =
424*7c478bd9Sstevel@tonic-gate {
425*7c478bd9Sstevel@tonic-gate 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
426*7c478bd9Sstevel@tonic-gate 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
427*7c478bd9Sstevel@tonic-gate 	0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046,
428*7c478bd9Sstevel@tonic-gate 	0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
429*7c478bd9Sstevel@tonic-gate 	0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175,
430*7c478bd9Sstevel@tonic-gate 	0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
431*7c478bd9Sstevel@tonic-gate 	0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
432*7c478bd9Sstevel@tonic-gate 	0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
433*7c478bd9Sstevel@tonic-gate 	0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
434*7c478bd9Sstevel@tonic-gate 	0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
435*7c478bd9Sstevel@tonic-gate 	0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346,
436*7c478bd9Sstevel@tonic-gate 	0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155,
437*7c478bd9Sstevel@tonic-gate 	0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
438*7c478bd9Sstevel@tonic-gate 	0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
439*7c478bd9Sstevel@tonic-gate 	0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246,
440*7c478bd9Sstevel@tonic-gate 	0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007,
441*7c478bd9Sstevel@tonic-gate 	0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027,
442*7c478bd9Sstevel@tonic-gate 	0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
443*7c478bd9Sstevel@tonic-gate 	0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010,
444*7c478bd9Sstevel@tonic-gate 	0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
445*7c478bd9Sstevel@tonic-gate 	0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110,
446*7c478bd9Sstevel@tonic-gate 	0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
447*7c478bd9Sstevel@tonic-gate 	0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147,
448*7c478bd9Sstevel@tonic-gate 	0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
449*7c478bd9Sstevel@tonic-gate 	0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215,
450*7c478bd9Sstevel@tonic-gate 	0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236,
451*7c478bd9Sstevel@tonic-gate 	0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257,
452*7c478bd9Sstevel@tonic-gate 	0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
453*7c478bd9Sstevel@tonic-gate 	0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
454*7c478bd9Sstevel@tonic-gate 	0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
455*7c478bd9Sstevel@tonic-gate 	0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355,
456*7c478bd9Sstevel@tonic-gate 	0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
457*7c478bd9Sstevel@tonic-gate };
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate /* set up to use SVr4 ascii-ebcdic translation by default */
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate static unsigned char *atoe = svr4_atoe;
462*7c478bd9Sstevel@tonic-gate static unsigned char *etoa = svr4_etoa;
463*7c478bd9Sstevel@tonic-gate static unsigned char *atoibm = svr4_atoibm;
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 
466*7c478bd9Sstevel@tonic-gate void
467*7c478bd9Sstevel@tonic-gate main(argc, argv)
468*7c478bd9Sstevel@tonic-gate int argc;
469*7c478bd9Sstevel@tonic-gate char **argv;
470*7c478bd9Sstevel@tonic-gate {
471*7c478bd9Sstevel@tonic-gate 	unsigned char *ip, *op; /* input and output buffer pointers */
472*7c478bd9Sstevel@tonic-gate 	int c;		/* character counter */
473*7c478bd9Sstevel@tonic-gate 	int ic;		/* input character */
474*7c478bd9Sstevel@tonic-gate 	int conv;		/* conversion option code */
475*7c478bd9Sstevel@tonic-gate 	int trunc;		/* whether output file is truncated */
476*7c478bd9Sstevel@tonic-gate 	struct stat file_stat;
477*7c478bd9Sstevel@tonic-gate 
478*7c478bd9Sstevel@tonic-gate 	/* Set option defaults */
479*7c478bd9Sstevel@tonic-gate 
480*7c478bd9Sstevel@tonic-gate 	ibs = BSIZE;
481*7c478bd9Sstevel@tonic-gate 	obs = BSIZE;
482*7c478bd9Sstevel@tonic-gate 	files = 1;
483*7c478bd9Sstevel@tonic-gate 	conv = COPY;
484*7c478bd9Sstevel@tonic-gate 	trunc = 1;			/* default: truncate output file */
485*7c478bd9Sstevel@tonic-gate 	trantype = SVR4XLATE;  /* use SVR4 EBCDIC by default */
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate 	/* Parse command options */
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
490*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
491*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
492*7c478bd9Sstevel@tonic-gate #endif
493*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
494*7c478bd9Sstevel@tonic-gate 
495*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "")) != EOF)
496*7c478bd9Sstevel@tonic-gate 		switch (c) {
497*7c478bd9Sstevel@tonic-gate 			case '?':
498*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, USAGE);
499*7c478bd9Sstevel@tonic-gate 			exit(2);
500*7c478bd9Sstevel@tonic-gate 		}
501*7c478bd9Sstevel@tonic-gate 
502*7c478bd9Sstevel@tonic-gate 	/* not getopt()'ed because dd has no options but only operand(s) */
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	for (c = optind; c < argc; c++)
505*7c478bd9Sstevel@tonic-gate 	{
506*7c478bd9Sstevel@tonic-gate 		string = argv[c];
507*7c478bd9Sstevel@tonic-gate 		if (match("ibs="))
508*7c478bd9Sstevel@tonic-gate 		{
509*7c478bd9Sstevel@tonic-gate 			ibs = (unsigned)number(BIG);
510*7c478bd9Sstevel@tonic-gate 			continue;
511*7c478bd9Sstevel@tonic-gate 		}
512*7c478bd9Sstevel@tonic-gate 		if (match("obs="))
513*7c478bd9Sstevel@tonic-gate 		{
514*7c478bd9Sstevel@tonic-gate 			obs = (unsigned)number(BIG);
515*7c478bd9Sstevel@tonic-gate 			continue;
516*7c478bd9Sstevel@tonic-gate 		}
517*7c478bd9Sstevel@tonic-gate 		if (match("cbs="))
518*7c478bd9Sstevel@tonic-gate 		{
519*7c478bd9Sstevel@tonic-gate 			cbs = (unsigned)number(BIG);
520*7c478bd9Sstevel@tonic-gate 			continue;
521*7c478bd9Sstevel@tonic-gate 		}
522*7c478bd9Sstevel@tonic-gate 		if (match("bs="))
523*7c478bd9Sstevel@tonic-gate 		{
524*7c478bd9Sstevel@tonic-gate 			bs = (unsigned)number(BIG);
525*7c478bd9Sstevel@tonic-gate 			continue;
526*7c478bd9Sstevel@tonic-gate 		}
527*7c478bd9Sstevel@tonic-gate 		if (match("if="))
528*7c478bd9Sstevel@tonic-gate 		{
529*7c478bd9Sstevel@tonic-gate 			ifile = string;
530*7c478bd9Sstevel@tonic-gate 			continue;
531*7c478bd9Sstevel@tonic-gate 		}
532*7c478bd9Sstevel@tonic-gate 		if (match("of="))
533*7c478bd9Sstevel@tonic-gate 		{
534*7c478bd9Sstevel@tonic-gate 			ofile = string;
535*7c478bd9Sstevel@tonic-gate 			continue;
536*7c478bd9Sstevel@tonic-gate 		}
537*7c478bd9Sstevel@tonic-gate 		if (match("skip="))
538*7c478bd9Sstevel@tonic-gate 		{
539*7c478bd9Sstevel@tonic-gate 			skip = number(BIG);
540*7c478bd9Sstevel@tonic-gate 			continue;
541*7c478bd9Sstevel@tonic-gate 		}
542*7c478bd9Sstevel@tonic-gate 		if (match("iseek="))
543*7c478bd9Sstevel@tonic-gate 		{
544*7c478bd9Sstevel@tonic-gate 			iseekn = number(BIG);
545*7c478bd9Sstevel@tonic-gate 			continue;
546*7c478bd9Sstevel@tonic-gate 		}
547*7c478bd9Sstevel@tonic-gate 		if (match("oseek="))
548*7c478bd9Sstevel@tonic-gate 		{
549*7c478bd9Sstevel@tonic-gate 			oseekn = number(BIG);
550*7c478bd9Sstevel@tonic-gate 			continue;
551*7c478bd9Sstevel@tonic-gate 		}
552*7c478bd9Sstevel@tonic-gate 		if (match("seek="))		/* retained for compatibility */
553*7c478bd9Sstevel@tonic-gate 		{
554*7c478bd9Sstevel@tonic-gate 			oseekn = number(BIG);
555*7c478bd9Sstevel@tonic-gate 			continue;
556*7c478bd9Sstevel@tonic-gate 		}
557*7c478bd9Sstevel@tonic-gate 		if (match("count="))
558*7c478bd9Sstevel@tonic-gate 		{
559*7c478bd9Sstevel@tonic-gate 			count = number(BIG);
560*7c478bd9Sstevel@tonic-gate 			continue;
561*7c478bd9Sstevel@tonic-gate 		}
562*7c478bd9Sstevel@tonic-gate 		if (match("files="))
563*7c478bd9Sstevel@tonic-gate 		{
564*7c478bd9Sstevel@tonic-gate 			files = (int)number(BIG);
565*7c478bd9Sstevel@tonic-gate 			continue;
566*7c478bd9Sstevel@tonic-gate 		}
567*7c478bd9Sstevel@tonic-gate 		if (match("conv="))
568*7c478bd9Sstevel@tonic-gate 		{
569*7c478bd9Sstevel@tonic-gate 			for (;;)
570*7c478bd9Sstevel@tonic-gate 			{
571*7c478bd9Sstevel@tonic-gate 				if (match(","))
572*7c478bd9Sstevel@tonic-gate 				{
573*7c478bd9Sstevel@tonic-gate 					continue;
574*7c478bd9Sstevel@tonic-gate 				}
575*7c478bd9Sstevel@tonic-gate 				if (*string == '\0')
576*7c478bd9Sstevel@tonic-gate 				{
577*7c478bd9Sstevel@tonic-gate 					break;
578*7c478bd9Sstevel@tonic-gate 				}
579*7c478bd9Sstevel@tonic-gate 				if (match("block"))
580*7c478bd9Sstevel@tonic-gate 				{
581*7c478bd9Sstevel@tonic-gate 					conv = BLOCK;
582*7c478bd9Sstevel@tonic-gate 					continue;
583*7c478bd9Sstevel@tonic-gate 				}
584*7c478bd9Sstevel@tonic-gate 				if (match("unblock"))
585*7c478bd9Sstevel@tonic-gate 				{
586*7c478bd9Sstevel@tonic-gate 					conv = UNBLOCK;
587*7c478bd9Sstevel@tonic-gate 					continue;
588*7c478bd9Sstevel@tonic-gate 				}
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 				/* ebcdicb, ibmb, and asciib must precede */
591*7c478bd9Sstevel@tonic-gate 				/* ebcdic, ibm, and ascii in this test */
592*7c478bd9Sstevel@tonic-gate 
593*7c478bd9Sstevel@tonic-gate 				if (match("ebcdicb"))
594*7c478bd9Sstevel@tonic-gate 				{
595*7c478bd9Sstevel@tonic-gate 					conv = EBCDIC;
596*7c478bd9Sstevel@tonic-gate 					trantype = BSDXLATE;
597*7c478bd9Sstevel@tonic-gate 					continue;
598*7c478bd9Sstevel@tonic-gate 				}
599*7c478bd9Sstevel@tonic-gate 				if (match("ibmb"))
600*7c478bd9Sstevel@tonic-gate 				{
601*7c478bd9Sstevel@tonic-gate 					conv = IBM;
602*7c478bd9Sstevel@tonic-gate 					trantype = BSDXLATE;
603*7c478bd9Sstevel@tonic-gate 					continue;
604*7c478bd9Sstevel@tonic-gate 				}
605*7c478bd9Sstevel@tonic-gate 				if (match("asciib"))
606*7c478bd9Sstevel@tonic-gate 				{
607*7c478bd9Sstevel@tonic-gate 					conv = ASCII;
608*7c478bd9Sstevel@tonic-gate 					trantype = BSDXLATE;
609*7c478bd9Sstevel@tonic-gate 					continue;
610*7c478bd9Sstevel@tonic-gate 				}
611*7c478bd9Sstevel@tonic-gate 				if (match("ebcdic"))
612*7c478bd9Sstevel@tonic-gate 				{
613*7c478bd9Sstevel@tonic-gate 					conv = EBCDIC;
614*7c478bd9Sstevel@tonic-gate 					trantype = SVR4XLATE;
615*7c478bd9Sstevel@tonic-gate 					continue;
616*7c478bd9Sstevel@tonic-gate 				}
617*7c478bd9Sstevel@tonic-gate 				if (match("ibm"))
618*7c478bd9Sstevel@tonic-gate 				{
619*7c478bd9Sstevel@tonic-gate 					conv = IBM;
620*7c478bd9Sstevel@tonic-gate 					trantype = SVR4XLATE;
621*7c478bd9Sstevel@tonic-gate 					continue;
622*7c478bd9Sstevel@tonic-gate 				}
623*7c478bd9Sstevel@tonic-gate 				if (match("ascii"))
624*7c478bd9Sstevel@tonic-gate 				{
625*7c478bd9Sstevel@tonic-gate 					conv = ASCII;
626*7c478bd9Sstevel@tonic-gate 					trantype = SVR4XLATE;
627*7c478bd9Sstevel@tonic-gate 					continue;
628*7c478bd9Sstevel@tonic-gate 				}
629*7c478bd9Sstevel@tonic-gate 				if (match("lcase"))
630*7c478bd9Sstevel@tonic-gate 				{
631*7c478bd9Sstevel@tonic-gate 					cflag |= LCASE;
632*7c478bd9Sstevel@tonic-gate 					continue;
633*7c478bd9Sstevel@tonic-gate 				}
634*7c478bd9Sstevel@tonic-gate 				if (match("ucase"))
635*7c478bd9Sstevel@tonic-gate 				{
636*7c478bd9Sstevel@tonic-gate 					cflag |= UCASE;
637*7c478bd9Sstevel@tonic-gate 					continue;
638*7c478bd9Sstevel@tonic-gate 				}
639*7c478bd9Sstevel@tonic-gate 				if (match("swab"))
640*7c478bd9Sstevel@tonic-gate 				{
641*7c478bd9Sstevel@tonic-gate 					cflag |= SWAB;
642*7c478bd9Sstevel@tonic-gate 					continue;
643*7c478bd9Sstevel@tonic-gate 				}
644*7c478bd9Sstevel@tonic-gate 				if (match("noerror"))
645*7c478bd9Sstevel@tonic-gate 				{
646*7c478bd9Sstevel@tonic-gate 					cflag |= NERR;
647*7c478bd9Sstevel@tonic-gate 					continue;
648*7c478bd9Sstevel@tonic-gate 				}
649*7c478bd9Sstevel@tonic-gate 				if (match("notrunc"))
650*7c478bd9Sstevel@tonic-gate 				{
651*7c478bd9Sstevel@tonic-gate 					trunc = 0;
652*7c478bd9Sstevel@tonic-gate 					continue;
653*7c478bd9Sstevel@tonic-gate 				}
654*7c478bd9Sstevel@tonic-gate 				if (match("sync"))
655*7c478bd9Sstevel@tonic-gate 				{
656*7c478bd9Sstevel@tonic-gate 					cflag |= SYNC;
657*7c478bd9Sstevel@tonic-gate 					continue;
658*7c478bd9Sstevel@tonic-gate 				}
659*7c478bd9Sstevel@tonic-gate 				goto badarg;
660*7c478bd9Sstevel@tonic-gate 			}
661*7c478bd9Sstevel@tonic-gate 			continue;
662*7c478bd9Sstevel@tonic-gate 		}
663*7c478bd9Sstevel@tonic-gate 		badarg:
664*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "dd: %s \"%s\"\n",
665*7c478bd9Sstevel@tonic-gate 			gettext("bad argument:"), string);
666*7c478bd9Sstevel@tonic-gate 		exit(2);
667*7c478bd9Sstevel@tonic-gate 	}
668*7c478bd9Sstevel@tonic-gate 
669*7c478bd9Sstevel@tonic-gate 	/* Perform consistency checks on options, decode strange conventions */
670*7c478bd9Sstevel@tonic-gate 
671*7c478bd9Sstevel@tonic-gate 	if (bs)
672*7c478bd9Sstevel@tonic-gate 	{
673*7c478bd9Sstevel@tonic-gate 		ibs = obs = bs;
674*7c478bd9Sstevel@tonic-gate 	}
675*7c478bd9Sstevel@tonic-gate 	if ((ibs == 0) || (obs == 0))
676*7c478bd9Sstevel@tonic-gate 	{
677*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "dd: %s\n",
678*7c478bd9Sstevel@tonic-gate 			gettext("buffer sizes cannot be zero"));
679*7c478bd9Sstevel@tonic-gate 		exit(2);
680*7c478bd9Sstevel@tonic-gate 	}
681*7c478bd9Sstevel@tonic-gate 	if (conv == COPY)
682*7c478bd9Sstevel@tonic-gate 	{
683*7c478bd9Sstevel@tonic-gate 		if ((bs == 0) || (cflag&(LCASE|UCASE)))
684*7c478bd9Sstevel@tonic-gate 		{
685*7c478bd9Sstevel@tonic-gate 			conv = REBLOCK;
686*7c478bd9Sstevel@tonic-gate 		}
687*7c478bd9Sstevel@tonic-gate 	}
688*7c478bd9Sstevel@tonic-gate 	if (cbs == 0)
689*7c478bd9Sstevel@tonic-gate 	{
690*7c478bd9Sstevel@tonic-gate 		switch (conv)
691*7c478bd9Sstevel@tonic-gate 		{
692*7c478bd9Sstevel@tonic-gate 		case BLOCK:
693*7c478bd9Sstevel@tonic-gate 		case UNBLOCK:
694*7c478bd9Sstevel@tonic-gate 			conv = REBLOCK;
695*7c478bd9Sstevel@tonic-gate 			break;
696*7c478bd9Sstevel@tonic-gate 
697*7c478bd9Sstevel@tonic-gate 		case ASCII:
698*7c478bd9Sstevel@tonic-gate 			conv = NBASCII;
699*7c478bd9Sstevel@tonic-gate 			break;
700*7c478bd9Sstevel@tonic-gate 
701*7c478bd9Sstevel@tonic-gate 		case EBCDIC:
702*7c478bd9Sstevel@tonic-gate 			conv = NBEBCDIC;
703*7c478bd9Sstevel@tonic-gate 			break;
704*7c478bd9Sstevel@tonic-gate 
705*7c478bd9Sstevel@tonic-gate 		case IBM:
706*7c478bd9Sstevel@tonic-gate 			conv = NBIBM;
707*7c478bd9Sstevel@tonic-gate 			break;
708*7c478bd9Sstevel@tonic-gate 		}
709*7c478bd9Sstevel@tonic-gate 	}
710*7c478bd9Sstevel@tonic-gate 
711*7c478bd9Sstevel@tonic-gate 	/* Expand options into lower and upper case versions if necessary */
712*7c478bd9Sstevel@tonic-gate 
713*7c478bd9Sstevel@tonic-gate 	switch (conv)
714*7c478bd9Sstevel@tonic-gate 	{
715*7c478bd9Sstevel@tonic-gate 	case REBLOCK:
716*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
717*7c478bd9Sstevel@tonic-gate 			conv = LCREBLOCK;
718*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
719*7c478bd9Sstevel@tonic-gate 			conv = UCREBLOCK;
720*7c478bd9Sstevel@tonic-gate 		break;
721*7c478bd9Sstevel@tonic-gate 
722*7c478bd9Sstevel@tonic-gate 	case UNBLOCK:
723*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
724*7c478bd9Sstevel@tonic-gate 			conv = LCUNBLOCK;
725*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
726*7c478bd9Sstevel@tonic-gate 			conv = UCUNBLOCK;
727*7c478bd9Sstevel@tonic-gate 		break;
728*7c478bd9Sstevel@tonic-gate 
729*7c478bd9Sstevel@tonic-gate 	case BLOCK:
730*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
731*7c478bd9Sstevel@tonic-gate 			conv = LCBLOCK;
732*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
733*7c478bd9Sstevel@tonic-gate 			conv = UCBLOCK;
734*7c478bd9Sstevel@tonic-gate 		break;
735*7c478bd9Sstevel@tonic-gate 
736*7c478bd9Sstevel@tonic-gate 	case ASCII:
737*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
738*7c478bd9Sstevel@tonic-gate 			conv = LCASCII;
739*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
740*7c478bd9Sstevel@tonic-gate 			conv = UCASCII;
741*7c478bd9Sstevel@tonic-gate 		break;
742*7c478bd9Sstevel@tonic-gate 
743*7c478bd9Sstevel@tonic-gate 	case NBASCII:
744*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
745*7c478bd9Sstevel@tonic-gate 			conv = LCNBASCII;
746*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
747*7c478bd9Sstevel@tonic-gate 			conv = UCNBASCII;
748*7c478bd9Sstevel@tonic-gate 		break;
749*7c478bd9Sstevel@tonic-gate 
750*7c478bd9Sstevel@tonic-gate 	case EBCDIC:
751*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
752*7c478bd9Sstevel@tonic-gate 			conv = LCEBCDIC;
753*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
754*7c478bd9Sstevel@tonic-gate 			conv = UCEBCDIC;
755*7c478bd9Sstevel@tonic-gate 		break;
756*7c478bd9Sstevel@tonic-gate 
757*7c478bd9Sstevel@tonic-gate 	case NBEBCDIC:
758*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
759*7c478bd9Sstevel@tonic-gate 			conv = LCNBEBCDIC;
760*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
761*7c478bd9Sstevel@tonic-gate 			conv = UCNBEBCDIC;
762*7c478bd9Sstevel@tonic-gate 		break;
763*7c478bd9Sstevel@tonic-gate 
764*7c478bd9Sstevel@tonic-gate 	case IBM:
765*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
766*7c478bd9Sstevel@tonic-gate 			conv = LCIBM;
767*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
768*7c478bd9Sstevel@tonic-gate 			conv = UCIBM;
769*7c478bd9Sstevel@tonic-gate 		break;
770*7c478bd9Sstevel@tonic-gate 
771*7c478bd9Sstevel@tonic-gate 	case NBIBM:
772*7c478bd9Sstevel@tonic-gate 		if (cflag&LCASE)
773*7c478bd9Sstevel@tonic-gate 			conv = LCNBIBM;
774*7c478bd9Sstevel@tonic-gate 		else if (cflag&UCASE)
775*7c478bd9Sstevel@tonic-gate 			conv = UCNBIBM;
776*7c478bd9Sstevel@tonic-gate 		break;
777*7c478bd9Sstevel@tonic-gate 	}
778*7c478bd9Sstevel@tonic-gate 
779*7c478bd9Sstevel@tonic-gate 	/* If BSD-compatible translation is selected, change the tables */
780*7c478bd9Sstevel@tonic-gate 
781*7c478bd9Sstevel@tonic-gate 	if (trantype == BSDXLATE) {
782*7c478bd9Sstevel@tonic-gate 		atoe = bsd_atoe;
783*7c478bd9Sstevel@tonic-gate 		atoibm = bsd_atoibm;
784*7c478bd9Sstevel@tonic-gate 		etoa = bsd_etoa;
785*7c478bd9Sstevel@tonic-gate 	}
786*7c478bd9Sstevel@tonic-gate 	/* Open the input file, or duplicate standard input */
787*7c478bd9Sstevel@tonic-gate 
788*7c478bd9Sstevel@tonic-gate 	ibf = -1;
789*7c478bd9Sstevel@tonic-gate 	if (ifile)
790*7c478bd9Sstevel@tonic-gate 	{
791*7c478bd9Sstevel@tonic-gate 		ibf = open(ifile, 0);
792*7c478bd9Sstevel@tonic-gate 	}
793*7c478bd9Sstevel@tonic-gate #ifndef STANDALONE
794*7c478bd9Sstevel@tonic-gate 	else
795*7c478bd9Sstevel@tonic-gate 	{
796*7c478bd9Sstevel@tonic-gate 		ifile = "";
797*7c478bd9Sstevel@tonic-gate 		ibf = dup(0);
798*7c478bd9Sstevel@tonic-gate 	}
799*7c478bd9Sstevel@tonic-gate #endif
800*7c478bd9Sstevel@tonic-gate 	if (ibf == -1)
801*7c478bd9Sstevel@tonic-gate 	{
802*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "dd: %s: ", ifile);
803*7c478bd9Sstevel@tonic-gate 		perror("open");
804*7c478bd9Sstevel@tonic-gate 		exit(2);
805*7c478bd9Sstevel@tonic-gate 	}
806*7c478bd9Sstevel@tonic-gate 
807*7c478bd9Sstevel@tonic-gate 	/* Open the output file, or duplicate standard output */
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate 	obf = -1;
810*7c478bd9Sstevel@tonic-gate 	if (ofile)
811*7c478bd9Sstevel@tonic-gate 	{
812*7c478bd9Sstevel@tonic-gate 		if (trunc == 0)	/* do not truncate output file */
813*7c478bd9Sstevel@tonic-gate 			obf = open(ofile, (O_WRONLY|O_CREAT),
814*7c478bd9Sstevel@tonic-gate 			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
815*7c478bd9Sstevel@tonic-gate 		else if (oseekn && (trunc == 1))
816*7c478bd9Sstevel@tonic-gate 		{
817*7c478bd9Sstevel@tonic-gate 			obf = open(ofile, O_WRONLY|O_CREAT,
818*7c478bd9Sstevel@tonic-gate 			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
819*7c478bd9Sstevel@tonic-gate 			if (obf == -1)
820*7c478bd9Sstevel@tonic-gate 			{
821*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "dd: %s: ", ofile);
822*7c478bd9Sstevel@tonic-gate 				perror("open");
823*7c478bd9Sstevel@tonic-gate 				exit(2);
824*7c478bd9Sstevel@tonic-gate 			}
825*7c478bd9Sstevel@tonic-gate 			(void) fstat(obf, &file_stat);
826*7c478bd9Sstevel@tonic-gate 			if (((file_stat.st_mode & S_IFMT) == S_IFREG) &&
827*7c478bd9Sstevel@tonic-gate 			    (ftruncate(obf, (((off_t)oseekn) * ((off_t)obs)))
828*7c478bd9Sstevel@tonic-gate 				== -1))
829*7c478bd9Sstevel@tonic-gate 			{
830*7c478bd9Sstevel@tonic-gate 				perror("ftruncate");
831*7c478bd9Sstevel@tonic-gate 				exit(2);
832*7c478bd9Sstevel@tonic-gate 			}
833*7c478bd9Sstevel@tonic-gate 		}
834*7c478bd9Sstevel@tonic-gate 		else
835*7c478bd9Sstevel@tonic-gate 			obf = creat(ofile,
836*7c478bd9Sstevel@tonic-gate 			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
837*7c478bd9Sstevel@tonic-gate 	}
838*7c478bd9Sstevel@tonic-gate #ifndef STANDALONE
839*7c478bd9Sstevel@tonic-gate 	else
840*7c478bd9Sstevel@tonic-gate 	{
841*7c478bd9Sstevel@tonic-gate 		ofile = "";
842*7c478bd9Sstevel@tonic-gate 		obf = dup(1);
843*7c478bd9Sstevel@tonic-gate 	}
844*7c478bd9Sstevel@tonic-gate #endif
845*7c478bd9Sstevel@tonic-gate 	if (obf == -1)
846*7c478bd9Sstevel@tonic-gate 	{
847*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "dd: %s: ", ofile);
848*7c478bd9Sstevel@tonic-gate 		perror("open");
849*7c478bd9Sstevel@tonic-gate 		exit(2);
850*7c478bd9Sstevel@tonic-gate 	}
851*7c478bd9Sstevel@tonic-gate 
852*7c478bd9Sstevel@tonic-gate 	/* Expand memory to get an input buffer */
853*7c478bd9Sstevel@tonic-gate 
854*7c478bd9Sstevel@tonic-gate 	ibuf = (unsigned char *)valloc(ibs + 10);
855*7c478bd9Sstevel@tonic-gate 
856*7c478bd9Sstevel@tonic-gate 	/* If no conversions, the input buffer is the output buffer */
857*7c478bd9Sstevel@tonic-gate 
858*7c478bd9Sstevel@tonic-gate 	if (conv == COPY)
859*7c478bd9Sstevel@tonic-gate 	{
860*7c478bd9Sstevel@tonic-gate 		obuf = ibuf;
861*7c478bd9Sstevel@tonic-gate 	}
862*7c478bd9Sstevel@tonic-gate 
863*7c478bd9Sstevel@tonic-gate 	/* Expand memory to get an output buffer. Leave enough room at the */
864*7c478bd9Sstevel@tonic-gate 	/* end to convert a logical record when doing block conversions. */
865*7c478bd9Sstevel@tonic-gate 
866*7c478bd9Sstevel@tonic-gate 	else
867*7c478bd9Sstevel@tonic-gate 	{
868*7c478bd9Sstevel@tonic-gate 		obuf = (unsigned char *)valloc(obs + cbs + 10);
869*7c478bd9Sstevel@tonic-gate 	}
870*7c478bd9Sstevel@tonic-gate 	if ((ibuf == (unsigned char *)NULL) || (obuf == (unsigned char *)NULL))
871*7c478bd9Sstevel@tonic-gate 	{
872*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
873*7c478bd9Sstevel@tonic-gate 			"dd: %s\n", gettext("not enough memory"));
874*7c478bd9Sstevel@tonic-gate 		exit(2);
875*7c478bd9Sstevel@tonic-gate 	}
876*7c478bd9Sstevel@tonic-gate 
877*7c478bd9Sstevel@tonic-gate 	/* Enable a statistics message on SIGINT */
878*7c478bd9Sstevel@tonic-gate 
879*7c478bd9Sstevel@tonic-gate #ifndef STANDALONE
880*7c478bd9Sstevel@tonic-gate 	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
881*7c478bd9Sstevel@tonic-gate 	{
882*7c478bd9Sstevel@tonic-gate 		(void) signal(SIGINT, term);
883*7c478bd9Sstevel@tonic-gate 	}
884*7c478bd9Sstevel@tonic-gate #endif
885*7c478bd9Sstevel@tonic-gate 	/* Skip input blocks */
886*7c478bd9Sstevel@tonic-gate 
887*7c478bd9Sstevel@tonic-gate 	while (skip)
888*7c478bd9Sstevel@tonic-gate 	{
889*7c478bd9Sstevel@tonic-gate 		ibc = read(ibf, (char *)ibuf, ibs);
890*7c478bd9Sstevel@tonic-gate 		if (ibc == (unsigned)-1)
891*7c478bd9Sstevel@tonic-gate 		{
892*7c478bd9Sstevel@tonic-gate 			if (++nbad > BADLIMIT)
893*7c478bd9Sstevel@tonic-gate 			{
894*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "dd: %s\n",
895*7c478bd9Sstevel@tonic-gate 					gettext("skip failed"));
896*7c478bd9Sstevel@tonic-gate 				exit(2);
897*7c478bd9Sstevel@tonic-gate 			}
898*7c478bd9Sstevel@tonic-gate 			else
899*7c478bd9Sstevel@tonic-gate 			{
900*7c478bd9Sstevel@tonic-gate 				perror("read");
901*7c478bd9Sstevel@tonic-gate 			}
902*7c478bd9Sstevel@tonic-gate 		}
903*7c478bd9Sstevel@tonic-gate 		else
904*7c478bd9Sstevel@tonic-gate 		{
905*7c478bd9Sstevel@tonic-gate 			if (ibc == 0)
906*7c478bd9Sstevel@tonic-gate 			{
907*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "dd: %s\n",
908*7c478bd9Sstevel@tonic-gate 				gettext("cannot skip past end-of-file"));
909*7c478bd9Sstevel@tonic-gate 				exit(3);
910*7c478bd9Sstevel@tonic-gate 			}
911*7c478bd9Sstevel@tonic-gate 			else
912*7c478bd9Sstevel@tonic-gate 			{
913*7c478bd9Sstevel@tonic-gate 				nbad = 0;
914*7c478bd9Sstevel@tonic-gate 			}
915*7c478bd9Sstevel@tonic-gate 		}
916*7c478bd9Sstevel@tonic-gate 		skip--;
917*7c478bd9Sstevel@tonic-gate 	}
918*7c478bd9Sstevel@tonic-gate 
919*7c478bd9Sstevel@tonic-gate 	/* Seek past input blocks */
920*7c478bd9Sstevel@tonic-gate 
921*7c478bd9Sstevel@tonic-gate 	if (iseekn && lseek(ibf, (((off_t)iseekn) * ((off_t)ibs)), 1) == -1)
922*7c478bd9Sstevel@tonic-gate 	{
923*7c478bd9Sstevel@tonic-gate 		perror("lseek");
924*7c478bd9Sstevel@tonic-gate 		exit(2);
925*7c478bd9Sstevel@tonic-gate 	}
926*7c478bd9Sstevel@tonic-gate 
927*7c478bd9Sstevel@tonic-gate 	/* Seek past output blocks */
928*7c478bd9Sstevel@tonic-gate 
929*7c478bd9Sstevel@tonic-gate 	if (oseekn && lseek(obf, (((off_t)oseekn) * ((off_t)obs)), 1) == -1)
930*7c478bd9Sstevel@tonic-gate 	{
931*7c478bd9Sstevel@tonic-gate 		perror("lseek");
932*7c478bd9Sstevel@tonic-gate 		exit(2);
933*7c478bd9Sstevel@tonic-gate 	}
934*7c478bd9Sstevel@tonic-gate 
935*7c478bd9Sstevel@tonic-gate 	/* Initialize all buffer pointers */
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate 	skipf = 0;	/* not skipping an input line */
938*7c478bd9Sstevel@tonic-gate 	ibc = 0;	/* no input characters yet */
939*7c478bd9Sstevel@tonic-gate 	obc = 0;	/* no output characters yet */
940*7c478bd9Sstevel@tonic-gate 	cbc = 0;	/* the conversion buffer is empty */
941*7c478bd9Sstevel@tonic-gate 	op = obuf;	/* point to the output buffer */
942*7c478bd9Sstevel@tonic-gate 
943*7c478bd9Sstevel@tonic-gate 	/* Read and convert input blocks until end of file(s) */
944*7c478bd9Sstevel@tonic-gate 
945*7c478bd9Sstevel@tonic-gate 	for (;;)
946*7c478bd9Sstevel@tonic-gate 	{
947*7c478bd9Sstevel@tonic-gate 		if ((count == 0) || (nifr+nipr < count))
948*7c478bd9Sstevel@tonic-gate 		{
949*7c478bd9Sstevel@tonic-gate 		/* If proceed on error is enabled, zero the input buffer */
950*7c478bd9Sstevel@tonic-gate 
951*7c478bd9Sstevel@tonic-gate 			if (cflag&NERR)
952*7c478bd9Sstevel@tonic-gate 			{
953*7c478bd9Sstevel@tonic-gate 				ip = ibuf + ibs;
954*7c478bd9Sstevel@tonic-gate 				c = ibs;
955*7c478bd9Sstevel@tonic-gate 				if (c & 1)	/* if the size is odd, */
956*7c478bd9Sstevel@tonic-gate 				{
957*7c478bd9Sstevel@tonic-gate 					*--ip = 0;	/* clear the odd byte */
958*7c478bd9Sstevel@tonic-gate 				}
959*7c478bd9Sstevel@tonic-gate 				if (c >>= 1)		/* divide by two */
960*7c478bd9Sstevel@tonic-gate 				{
961*7c478bd9Sstevel@tonic-gate 					do {	/* clear two at a time */
962*7c478bd9Sstevel@tonic-gate 						*--ip = 0;
963*7c478bd9Sstevel@tonic-gate 						*--ip = 0;
964*7c478bd9Sstevel@tonic-gate 					} while (--c);
965*7c478bd9Sstevel@tonic-gate 				}
966*7c478bd9Sstevel@tonic-gate 			}
967*7c478bd9Sstevel@tonic-gate 
968*7c478bd9Sstevel@tonic-gate 			/* Read the next input block */
969*7c478bd9Sstevel@tonic-gate 
970*7c478bd9Sstevel@tonic-gate 			ibc = read(ibf, (char *)ibuf, ibs);
971*7c478bd9Sstevel@tonic-gate 
972*7c478bd9Sstevel@tonic-gate 			/* Process input errors */
973*7c478bd9Sstevel@tonic-gate 
974*7c478bd9Sstevel@tonic-gate 			if (ibc == (unsigned)-1)
975*7c478bd9Sstevel@tonic-gate 			{
976*7c478bd9Sstevel@tonic-gate 				perror("read");
977*7c478bd9Sstevel@tonic-gate 				if (((cflag&NERR) == 0) || (++nbad > BADLIMIT))
978*7c478bd9Sstevel@tonic-gate 				{
979*7c478bd9Sstevel@tonic-gate 					while (obc)
980*7c478bd9Sstevel@tonic-gate 					{
981*7c478bd9Sstevel@tonic-gate 						(void) flsh();
982*7c478bd9Sstevel@tonic-gate 					}
983*7c478bd9Sstevel@tonic-gate 					term(2);
984*7c478bd9Sstevel@tonic-gate 				}
985*7c478bd9Sstevel@tonic-gate 				else
986*7c478bd9Sstevel@tonic-gate 				{
987*7c478bd9Sstevel@tonic-gate 					stats();
988*7c478bd9Sstevel@tonic-gate 					ibc = ibs; /* assume a full block */
989*7c478bd9Sstevel@tonic-gate 				}
990*7c478bd9Sstevel@tonic-gate 			}
991*7c478bd9Sstevel@tonic-gate 			else
992*7c478bd9Sstevel@tonic-gate 			{
993*7c478bd9Sstevel@tonic-gate 				nbad = 0;
994*7c478bd9Sstevel@tonic-gate 			}
995*7c478bd9Sstevel@tonic-gate 		}
996*7c478bd9Sstevel@tonic-gate 
997*7c478bd9Sstevel@tonic-gate 		/* Record count satisfied, simulate end of file */
998*7c478bd9Sstevel@tonic-gate 
999*7c478bd9Sstevel@tonic-gate 		else
1000*7c478bd9Sstevel@tonic-gate 		{
1001*7c478bd9Sstevel@tonic-gate 			ibc = 0;
1002*7c478bd9Sstevel@tonic-gate 			files = 1;
1003*7c478bd9Sstevel@tonic-gate 		}
1004*7c478bd9Sstevel@tonic-gate 
1005*7c478bd9Sstevel@tonic-gate 		/* Process end of file */
1006*7c478bd9Sstevel@tonic-gate 
1007*7c478bd9Sstevel@tonic-gate 		if (ibc == 0)
1008*7c478bd9Sstevel@tonic-gate 		{
1009*7c478bd9Sstevel@tonic-gate 			switch (conv)
1010*7c478bd9Sstevel@tonic-gate 			{
1011*7c478bd9Sstevel@tonic-gate 			case UNBLOCK:
1012*7c478bd9Sstevel@tonic-gate 			case LCUNBLOCK:
1013*7c478bd9Sstevel@tonic-gate 			case UCUNBLOCK:
1014*7c478bd9Sstevel@tonic-gate 			case ASCII:
1015*7c478bd9Sstevel@tonic-gate 			case LCASCII:
1016*7c478bd9Sstevel@tonic-gate 			case UCASCII:
1017*7c478bd9Sstevel@tonic-gate 
1018*7c478bd9Sstevel@tonic-gate 				/* Trim trailing blanks from the last line */
1019*7c478bd9Sstevel@tonic-gate 
1020*7c478bd9Sstevel@tonic-gate 				if ((c = cbc) != 0)
1021*7c478bd9Sstevel@tonic-gate 				{
1022*7c478bd9Sstevel@tonic-gate 					do {
1023*7c478bd9Sstevel@tonic-gate 						if ((*--op) != ' ')
1024*7c478bd9Sstevel@tonic-gate 						{
1025*7c478bd9Sstevel@tonic-gate 							op++;
1026*7c478bd9Sstevel@tonic-gate 							break;
1027*7c478bd9Sstevel@tonic-gate 						}
1028*7c478bd9Sstevel@tonic-gate 					} while (--c);
1029*7c478bd9Sstevel@tonic-gate 					*op++ = '\n';
1030*7c478bd9Sstevel@tonic-gate 					obc -= cbc - c - 1;
1031*7c478bd9Sstevel@tonic-gate 					cbc = 0;
1032*7c478bd9Sstevel@tonic-gate 
1033*7c478bd9Sstevel@tonic-gate 					/* Flush the output buffer if full */
1034*7c478bd9Sstevel@tonic-gate 
1035*7c478bd9Sstevel@tonic-gate 					while (obc >= obs)
1036*7c478bd9Sstevel@tonic-gate 					{
1037*7c478bd9Sstevel@tonic-gate 						op = flsh();
1038*7c478bd9Sstevel@tonic-gate 					}
1039*7c478bd9Sstevel@tonic-gate 				}
1040*7c478bd9Sstevel@tonic-gate 				break;
1041*7c478bd9Sstevel@tonic-gate 
1042*7c478bd9Sstevel@tonic-gate 			case BLOCK:
1043*7c478bd9Sstevel@tonic-gate 			case LCBLOCK:
1044*7c478bd9Sstevel@tonic-gate 			case UCBLOCK:
1045*7c478bd9Sstevel@tonic-gate 			case EBCDIC:
1046*7c478bd9Sstevel@tonic-gate 			case LCEBCDIC:
1047*7c478bd9Sstevel@tonic-gate 			case UCEBCDIC:
1048*7c478bd9Sstevel@tonic-gate 			case IBM:
1049*7c478bd9Sstevel@tonic-gate 			case LCIBM:
1050*7c478bd9Sstevel@tonic-gate 			case UCIBM:
1051*7c478bd9Sstevel@tonic-gate 
1052*7c478bd9Sstevel@tonic-gate 			/* Pad trailing blanks if the last line is short */
1053*7c478bd9Sstevel@tonic-gate 
1054*7c478bd9Sstevel@tonic-gate 				if (cbc)
1055*7c478bd9Sstevel@tonic-gate 				{
1056*7c478bd9Sstevel@tonic-gate 					obc += c = cbs - cbc;
1057*7c478bd9Sstevel@tonic-gate 					cbc = 0;
1058*7c478bd9Sstevel@tonic-gate 					if (c > 0)
1059*7c478bd9Sstevel@tonic-gate 					{
1060*7c478bd9Sstevel@tonic-gate 					/* Use the right kind of blank */
1061*7c478bd9Sstevel@tonic-gate 
1062*7c478bd9Sstevel@tonic-gate 						switch (conv)
1063*7c478bd9Sstevel@tonic-gate 						{
1064*7c478bd9Sstevel@tonic-gate 						case BLOCK:
1065*7c478bd9Sstevel@tonic-gate 						case LCBLOCK:
1066*7c478bd9Sstevel@tonic-gate 						case UCBLOCK:
1067*7c478bd9Sstevel@tonic-gate 							ic = ' ';
1068*7c478bd9Sstevel@tonic-gate 							break;
1069*7c478bd9Sstevel@tonic-gate 
1070*7c478bd9Sstevel@tonic-gate 						case EBCDIC:
1071*7c478bd9Sstevel@tonic-gate 						case LCEBCDIC:
1072*7c478bd9Sstevel@tonic-gate 						case UCEBCDIC:
1073*7c478bd9Sstevel@tonic-gate 							ic = atoe[' '];
1074*7c478bd9Sstevel@tonic-gate 							break;
1075*7c478bd9Sstevel@tonic-gate 
1076*7c478bd9Sstevel@tonic-gate 						case IBM:
1077*7c478bd9Sstevel@tonic-gate 						case LCIBM:
1078*7c478bd9Sstevel@tonic-gate 						case UCIBM:
1079*7c478bd9Sstevel@tonic-gate 							ic = atoibm[' '];
1080*7c478bd9Sstevel@tonic-gate 							break;
1081*7c478bd9Sstevel@tonic-gate 						}
1082*7c478bd9Sstevel@tonic-gate 
1083*7c478bd9Sstevel@tonic-gate 						/* Pad with trailing blanks */
1084*7c478bd9Sstevel@tonic-gate 
1085*7c478bd9Sstevel@tonic-gate 						do {
1086*7c478bd9Sstevel@tonic-gate 							*op++ = ic;
1087*7c478bd9Sstevel@tonic-gate 						} while (--c);
1088*7c478bd9Sstevel@tonic-gate 					}
1089*7c478bd9Sstevel@tonic-gate 				}
1090*7c478bd9Sstevel@tonic-gate 
1091*7c478bd9Sstevel@tonic-gate 
1092*7c478bd9Sstevel@tonic-gate 				/* Flush the output buffer if full */
1093*7c478bd9Sstevel@tonic-gate 
1094*7c478bd9Sstevel@tonic-gate 				while (obc >= obs)
1095*7c478bd9Sstevel@tonic-gate 				{
1096*7c478bd9Sstevel@tonic-gate 					op = flsh();
1097*7c478bd9Sstevel@tonic-gate 				}
1098*7c478bd9Sstevel@tonic-gate 				break;
1099*7c478bd9Sstevel@tonic-gate 			}
1100*7c478bd9Sstevel@tonic-gate 
1101*7c478bd9Sstevel@tonic-gate 			/* If no more files to read, flush the output buffer */
1102*7c478bd9Sstevel@tonic-gate 
1103*7c478bd9Sstevel@tonic-gate 			if (--files <= 0)
1104*7c478bd9Sstevel@tonic-gate 			{
1105*7c478bd9Sstevel@tonic-gate 				(void) flsh();
1106*7c478bd9Sstevel@tonic-gate 				if ((close(obf) != 0) || (fclose(stdout) != 0))
1107*7c478bd9Sstevel@tonic-gate 				{
1108*7c478bd9Sstevel@tonic-gate 					perror(gettext("dd: close error"));
1109*7c478bd9Sstevel@tonic-gate 					exit(2);
1110*7c478bd9Sstevel@tonic-gate 				}
1111*7c478bd9Sstevel@tonic-gate 				term(0);	/* successful exit */
1112*7c478bd9Sstevel@tonic-gate 			}
1113*7c478bd9Sstevel@tonic-gate 			else
1114*7c478bd9Sstevel@tonic-gate 			{
1115*7c478bd9Sstevel@tonic-gate 				continue;	/* read the next file */
1116*7c478bd9Sstevel@tonic-gate 			}
1117*7c478bd9Sstevel@tonic-gate 		}
1118*7c478bd9Sstevel@tonic-gate 
1119*7c478bd9Sstevel@tonic-gate 		/* Normal read, check for special cases */
1120*7c478bd9Sstevel@tonic-gate 
1121*7c478bd9Sstevel@tonic-gate 		else if (ibc == ibs)
1122*7c478bd9Sstevel@tonic-gate 		{
1123*7c478bd9Sstevel@tonic-gate 			nifr++;		/* count another full input record */
1124*7c478bd9Sstevel@tonic-gate 		}
1125*7c478bd9Sstevel@tonic-gate 		else
1126*7c478bd9Sstevel@tonic-gate 		{
1127*7c478bd9Sstevel@tonic-gate 			nipr++;		/* count a partial input record */
1128*7c478bd9Sstevel@tonic-gate 
1129*7c478bd9Sstevel@tonic-gate 			/* If `sync' enabled, pad nulls */
1130*7c478bd9Sstevel@tonic-gate 
1131*7c478bd9Sstevel@tonic-gate 			if ((cflag&SYNC) && ((cflag&NERR) == 0))
1132*7c478bd9Sstevel@tonic-gate 			{
1133*7c478bd9Sstevel@tonic-gate 				c = ibs - ibc;
1134*7c478bd9Sstevel@tonic-gate 				ip = ibuf + ibs;
1135*7c478bd9Sstevel@tonic-gate 				do {
1136*7c478bd9Sstevel@tonic-gate 				if ((conv == BLOCK) || (conv == UNBLOCK))
1137*7c478bd9Sstevel@tonic-gate 					*--ip = ' ';
1138*7c478bd9Sstevel@tonic-gate 				else
1139*7c478bd9Sstevel@tonic-gate 					*--ip = '\0';
1140*7c478bd9Sstevel@tonic-gate 				} while (--c);
1141*7c478bd9Sstevel@tonic-gate 				ibc = ibs;
1142*7c478bd9Sstevel@tonic-gate 			}
1143*7c478bd9Sstevel@tonic-gate 		}
1144*7c478bd9Sstevel@tonic-gate 
1145*7c478bd9Sstevel@tonic-gate 		/* Swap the bytes in the input buffer if necessary */
1146*7c478bd9Sstevel@tonic-gate 
1147*7c478bd9Sstevel@tonic-gate 		if (cflag&SWAB)
1148*7c478bd9Sstevel@tonic-gate 		{
1149*7c478bd9Sstevel@tonic-gate 			ip = ibuf;
1150*7c478bd9Sstevel@tonic-gate 			if (ibc & 1)	/* if the byte count is odd, */
1151*7c478bd9Sstevel@tonic-gate 			{
1152*7c478bd9Sstevel@tonic-gate 				ip[ibc] = 0;  /* make it even, pad with zero */
1153*7c478bd9Sstevel@tonic-gate 			}
1154*7c478bd9Sstevel@tonic-gate 			c = ibc >> 1;	/* compute the pair count */
1155*7c478bd9Sstevel@tonic-gate 			do {
1156*7c478bd9Sstevel@tonic-gate 				ic = *ip++;
1157*7c478bd9Sstevel@tonic-gate 				ip[-1] = *ip;
1158*7c478bd9Sstevel@tonic-gate 				*ip++ = ic;
1159*7c478bd9Sstevel@tonic-gate 			} while (--c);		/* do two bytes at a time */
1160*7c478bd9Sstevel@tonic-gate 		}
1161*7c478bd9Sstevel@tonic-gate 
1162*7c478bd9Sstevel@tonic-gate 		/* Select the appropriate conversion loop */
1163*7c478bd9Sstevel@tonic-gate 
1164*7c478bd9Sstevel@tonic-gate 		ip = ibuf;
1165*7c478bd9Sstevel@tonic-gate 		switch (conv)
1166*7c478bd9Sstevel@tonic-gate 		{
1167*7c478bd9Sstevel@tonic-gate 
1168*7c478bd9Sstevel@tonic-gate 		/* Simple copy: no conversion, preserve the input block size */
1169*7c478bd9Sstevel@tonic-gate 
1170*7c478bd9Sstevel@tonic-gate 		case COPY:
1171*7c478bd9Sstevel@tonic-gate 			obc = ibc;
1172*7c478bd9Sstevel@tonic-gate 			(void) flsh();
1173*7c478bd9Sstevel@tonic-gate 			break;
1174*7c478bd9Sstevel@tonic-gate 
1175*7c478bd9Sstevel@tonic-gate 		/* Simple copy: pack all output into equal sized blocks */
1176*7c478bd9Sstevel@tonic-gate 
1177*7c478bd9Sstevel@tonic-gate 		case REBLOCK:
1178*7c478bd9Sstevel@tonic-gate 		case LCREBLOCK:
1179*7c478bd9Sstevel@tonic-gate 		case UCREBLOCK:
1180*7c478bd9Sstevel@tonic-gate 		case NBASCII:
1181*7c478bd9Sstevel@tonic-gate 		case LCNBASCII:
1182*7c478bd9Sstevel@tonic-gate 		case UCNBASCII:
1183*7c478bd9Sstevel@tonic-gate 		case NBEBCDIC:
1184*7c478bd9Sstevel@tonic-gate 		case LCNBEBCDIC:
1185*7c478bd9Sstevel@tonic-gate 		case UCNBEBCDIC:
1186*7c478bd9Sstevel@tonic-gate 		case NBIBM:
1187*7c478bd9Sstevel@tonic-gate 		case LCNBIBM:
1188*7c478bd9Sstevel@tonic-gate 		case UCNBIBM:
1189*7c478bd9Sstevel@tonic-gate 			while ((c = ibc) != 0)
1190*7c478bd9Sstevel@tonic-gate 			{
1191*7c478bd9Sstevel@tonic-gate 				if (c > (obs - obc))
1192*7c478bd9Sstevel@tonic-gate 				{
1193*7c478bd9Sstevel@tonic-gate 					c = obs - obc;
1194*7c478bd9Sstevel@tonic-gate 				}
1195*7c478bd9Sstevel@tonic-gate 				ibc -= c;
1196*7c478bd9Sstevel@tonic-gate 				obc += c;
1197*7c478bd9Sstevel@tonic-gate 				switch (conv)
1198*7c478bd9Sstevel@tonic-gate 				{
1199*7c478bd9Sstevel@tonic-gate 				case REBLOCK:
1200*7c478bd9Sstevel@tonic-gate 					do {
1201*7c478bd9Sstevel@tonic-gate 						*op++ = *ip++;
1202*7c478bd9Sstevel@tonic-gate 					} while (--c);
1203*7c478bd9Sstevel@tonic-gate 					break;
1204*7c478bd9Sstevel@tonic-gate 
1205*7c478bd9Sstevel@tonic-gate 				case LCREBLOCK:
1206*7c478bd9Sstevel@tonic-gate 					do {
1207*7c478bd9Sstevel@tonic-gate 						*op++ = utol[*ip++];
1208*7c478bd9Sstevel@tonic-gate 					} while (--c);
1209*7c478bd9Sstevel@tonic-gate 					break;
1210*7c478bd9Sstevel@tonic-gate 
1211*7c478bd9Sstevel@tonic-gate 				case UCREBLOCK:
1212*7c478bd9Sstevel@tonic-gate 					do {
1213*7c478bd9Sstevel@tonic-gate 						*op++ = ltou[*ip++];
1214*7c478bd9Sstevel@tonic-gate 					} while (--c);
1215*7c478bd9Sstevel@tonic-gate 					break;
1216*7c478bd9Sstevel@tonic-gate 
1217*7c478bd9Sstevel@tonic-gate 				case NBASCII:
1218*7c478bd9Sstevel@tonic-gate 					do {
1219*7c478bd9Sstevel@tonic-gate 						*op++ = etoa[*ip++];
1220*7c478bd9Sstevel@tonic-gate 					} while (--c);
1221*7c478bd9Sstevel@tonic-gate 					break;
1222*7c478bd9Sstevel@tonic-gate 
1223*7c478bd9Sstevel@tonic-gate 				case LCNBASCII:
1224*7c478bd9Sstevel@tonic-gate 					do {
1225*7c478bd9Sstevel@tonic-gate 						*op++ = utol[etoa[*ip++]];
1226*7c478bd9Sstevel@tonic-gate 					} while (--c);
1227*7c478bd9Sstevel@tonic-gate 					break;
1228*7c478bd9Sstevel@tonic-gate 
1229*7c478bd9Sstevel@tonic-gate 				case UCNBASCII:
1230*7c478bd9Sstevel@tonic-gate 					do {
1231*7c478bd9Sstevel@tonic-gate 						*op++ = ltou[etoa[*ip++]];
1232*7c478bd9Sstevel@tonic-gate 					} while (--c);
1233*7c478bd9Sstevel@tonic-gate 					break;
1234*7c478bd9Sstevel@tonic-gate 
1235*7c478bd9Sstevel@tonic-gate 				case NBEBCDIC:
1236*7c478bd9Sstevel@tonic-gate 					do {
1237*7c478bd9Sstevel@tonic-gate 						*op++ = atoe[*ip++];
1238*7c478bd9Sstevel@tonic-gate 					} while (--c);
1239*7c478bd9Sstevel@tonic-gate 					break;
1240*7c478bd9Sstevel@tonic-gate 
1241*7c478bd9Sstevel@tonic-gate 				case LCNBEBCDIC:
1242*7c478bd9Sstevel@tonic-gate 					do {
1243*7c478bd9Sstevel@tonic-gate 						*op++ = atoe[utol[*ip++]];
1244*7c478bd9Sstevel@tonic-gate 					} while (--c);
1245*7c478bd9Sstevel@tonic-gate 					break;
1246*7c478bd9Sstevel@tonic-gate 
1247*7c478bd9Sstevel@tonic-gate 				case UCNBEBCDIC:
1248*7c478bd9Sstevel@tonic-gate 					do {
1249*7c478bd9Sstevel@tonic-gate 						*op++ = atoe[ltou[*ip++]];
1250*7c478bd9Sstevel@tonic-gate 					} while (--c);
1251*7c478bd9Sstevel@tonic-gate 					break;
1252*7c478bd9Sstevel@tonic-gate 
1253*7c478bd9Sstevel@tonic-gate 				case NBIBM:
1254*7c478bd9Sstevel@tonic-gate 					do {
1255*7c478bd9Sstevel@tonic-gate 						*op++ = atoibm[*ip++];
1256*7c478bd9Sstevel@tonic-gate 					} while (--c);
1257*7c478bd9Sstevel@tonic-gate 					break;
1258*7c478bd9Sstevel@tonic-gate 
1259*7c478bd9Sstevel@tonic-gate 				case LCNBIBM:
1260*7c478bd9Sstevel@tonic-gate 					do {
1261*7c478bd9Sstevel@tonic-gate 						*op++ = atoibm[utol[*ip++]];
1262*7c478bd9Sstevel@tonic-gate 					} while (--c);
1263*7c478bd9Sstevel@tonic-gate 					break;
1264*7c478bd9Sstevel@tonic-gate 
1265*7c478bd9Sstevel@tonic-gate 				case UCNBIBM:
1266*7c478bd9Sstevel@tonic-gate 					do {
1267*7c478bd9Sstevel@tonic-gate 						*op++ = atoibm[ltou[*ip++]];
1268*7c478bd9Sstevel@tonic-gate 					} while (--c);
1269*7c478bd9Sstevel@tonic-gate 					break;
1270*7c478bd9Sstevel@tonic-gate 				}
1271*7c478bd9Sstevel@tonic-gate 				if (obc >= obs)
1272*7c478bd9Sstevel@tonic-gate 				{
1273*7c478bd9Sstevel@tonic-gate 					op = flsh();
1274*7c478bd9Sstevel@tonic-gate 				}
1275*7c478bd9Sstevel@tonic-gate 			}
1276*7c478bd9Sstevel@tonic-gate 			break;
1277*7c478bd9Sstevel@tonic-gate 
1278*7c478bd9Sstevel@tonic-gate 	/* Convert from blocked records to lines terminated by newline */
1279*7c478bd9Sstevel@tonic-gate 
1280*7c478bd9Sstevel@tonic-gate 		case UNBLOCK:
1281*7c478bd9Sstevel@tonic-gate 		case LCUNBLOCK:
1282*7c478bd9Sstevel@tonic-gate 		case UCUNBLOCK:
1283*7c478bd9Sstevel@tonic-gate 		case ASCII:
1284*7c478bd9Sstevel@tonic-gate 		case LCASCII:
1285*7c478bd9Sstevel@tonic-gate 		case UCASCII:
1286*7c478bd9Sstevel@tonic-gate 			while ((c = ibc) != 0)
1287*7c478bd9Sstevel@tonic-gate 			{
1288*7c478bd9Sstevel@tonic-gate 				if (c > (cbs - cbc))
1289*7c478bd9Sstevel@tonic-gate 						/* if more than one record, */
1290*7c478bd9Sstevel@tonic-gate 				{
1291*7c478bd9Sstevel@tonic-gate 					c = cbs - cbc;
1292*7c478bd9Sstevel@tonic-gate 						/* only copy one record */
1293*7c478bd9Sstevel@tonic-gate 				}
1294*7c478bd9Sstevel@tonic-gate 				ibc -= c;
1295*7c478bd9Sstevel@tonic-gate 				cbc += c;
1296*7c478bd9Sstevel@tonic-gate 				obc += c;
1297*7c478bd9Sstevel@tonic-gate 				switch (conv)
1298*7c478bd9Sstevel@tonic-gate 				{
1299*7c478bd9Sstevel@tonic-gate 				case UNBLOCK:
1300*7c478bd9Sstevel@tonic-gate 					do {
1301*7c478bd9Sstevel@tonic-gate 						*op++ = *ip++;
1302*7c478bd9Sstevel@tonic-gate 					} while (--c);
1303*7c478bd9Sstevel@tonic-gate 					break;
1304*7c478bd9Sstevel@tonic-gate 
1305*7c478bd9Sstevel@tonic-gate 				case LCUNBLOCK:
1306*7c478bd9Sstevel@tonic-gate 					do {
1307*7c478bd9Sstevel@tonic-gate 						*op++ = utol[*ip++];
1308*7c478bd9Sstevel@tonic-gate 					} while (--c);
1309*7c478bd9Sstevel@tonic-gate 					break;
1310*7c478bd9Sstevel@tonic-gate 
1311*7c478bd9Sstevel@tonic-gate 				case UCUNBLOCK:
1312*7c478bd9Sstevel@tonic-gate 					do {
1313*7c478bd9Sstevel@tonic-gate 						*op++ = ltou[*ip++];
1314*7c478bd9Sstevel@tonic-gate 					} while (--c);
1315*7c478bd9Sstevel@tonic-gate 					break;
1316*7c478bd9Sstevel@tonic-gate 
1317*7c478bd9Sstevel@tonic-gate 				case ASCII:
1318*7c478bd9Sstevel@tonic-gate 					do {
1319*7c478bd9Sstevel@tonic-gate 						*op++ = etoa[*ip++];
1320*7c478bd9Sstevel@tonic-gate 					} while (--c);
1321*7c478bd9Sstevel@tonic-gate 					break;
1322*7c478bd9Sstevel@tonic-gate 
1323*7c478bd9Sstevel@tonic-gate 				case LCASCII:
1324*7c478bd9Sstevel@tonic-gate 					do {
1325*7c478bd9Sstevel@tonic-gate 						*op++ = utol[etoa[*ip++]];
1326*7c478bd9Sstevel@tonic-gate 					} while (--c);
1327*7c478bd9Sstevel@tonic-gate 					break;
1328*7c478bd9Sstevel@tonic-gate 
1329*7c478bd9Sstevel@tonic-gate 				case UCASCII:
1330*7c478bd9Sstevel@tonic-gate 					do {
1331*7c478bd9Sstevel@tonic-gate 						*op++ = ltou[etoa[*ip++]];
1332*7c478bd9Sstevel@tonic-gate 					} while (--c);
1333*7c478bd9Sstevel@tonic-gate 					break;
1334*7c478bd9Sstevel@tonic-gate 				}
1335*7c478bd9Sstevel@tonic-gate 
1336*7c478bd9Sstevel@tonic-gate 				/* Trim trailing blanks if the line is full */
1337*7c478bd9Sstevel@tonic-gate 
1338*7c478bd9Sstevel@tonic-gate 				if (cbc == cbs)
1339*7c478bd9Sstevel@tonic-gate 				{
1340*7c478bd9Sstevel@tonic-gate 					c = cbs; /* `do - while' is usually */
1341*7c478bd9Sstevel@tonic-gate 					do {		/* faster than `for' */
1342*7c478bd9Sstevel@tonic-gate 						if ((*--op) != ' ')
1343*7c478bd9Sstevel@tonic-gate 						{
1344*7c478bd9Sstevel@tonic-gate 							op++;
1345*7c478bd9Sstevel@tonic-gate 							break;
1346*7c478bd9Sstevel@tonic-gate 						}
1347*7c478bd9Sstevel@tonic-gate 					} while (--c);
1348*7c478bd9Sstevel@tonic-gate 					*op++ = '\n';
1349*7c478bd9Sstevel@tonic-gate 					obc -= cbs - c - 1;
1350*7c478bd9Sstevel@tonic-gate 					cbc = 0;
1351*7c478bd9Sstevel@tonic-gate 
1352*7c478bd9Sstevel@tonic-gate 					/* Flush the output buffer if full */
1353*7c478bd9Sstevel@tonic-gate 
1354*7c478bd9Sstevel@tonic-gate 					while (obc >= obs)
1355*7c478bd9Sstevel@tonic-gate 					{
1356*7c478bd9Sstevel@tonic-gate 						op = flsh();
1357*7c478bd9Sstevel@tonic-gate 					}
1358*7c478bd9Sstevel@tonic-gate 				}
1359*7c478bd9Sstevel@tonic-gate 			}
1360*7c478bd9Sstevel@tonic-gate 			break;
1361*7c478bd9Sstevel@tonic-gate 
1362*7c478bd9Sstevel@tonic-gate 		/* Convert to blocked records */
1363*7c478bd9Sstevel@tonic-gate 
1364*7c478bd9Sstevel@tonic-gate 		case BLOCK:
1365*7c478bd9Sstevel@tonic-gate 		case LCBLOCK:
1366*7c478bd9Sstevel@tonic-gate 		case UCBLOCK:
1367*7c478bd9Sstevel@tonic-gate 		case EBCDIC:
1368*7c478bd9Sstevel@tonic-gate 		case LCEBCDIC:
1369*7c478bd9Sstevel@tonic-gate 		case UCEBCDIC:
1370*7c478bd9Sstevel@tonic-gate 		case IBM:
1371*7c478bd9Sstevel@tonic-gate 		case LCIBM:
1372*7c478bd9Sstevel@tonic-gate 		case UCIBM:
1373*7c478bd9Sstevel@tonic-gate 			while ((c = ibc) != 0)
1374*7c478bd9Sstevel@tonic-gate 			{
1375*7c478bd9Sstevel@tonic-gate 				int nlflag = 0;
1376*7c478bd9Sstevel@tonic-gate 
1377*7c478bd9Sstevel@tonic-gate 			/* We may have to skip to the end of a long line */
1378*7c478bd9Sstevel@tonic-gate 
1379*7c478bd9Sstevel@tonic-gate 				if (skipf)
1380*7c478bd9Sstevel@tonic-gate 				{
1381*7c478bd9Sstevel@tonic-gate 					do {
1382*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) == '\n')
1383*7c478bd9Sstevel@tonic-gate 						{
1384*7c478bd9Sstevel@tonic-gate 							skipf = 0;
1385*7c478bd9Sstevel@tonic-gate 							c--;
1386*7c478bd9Sstevel@tonic-gate 							break;
1387*7c478bd9Sstevel@tonic-gate 						}
1388*7c478bd9Sstevel@tonic-gate 					} while (--c);
1389*7c478bd9Sstevel@tonic-gate 					if ((ibc = c) == 0)
1390*7c478bd9Sstevel@tonic-gate 					{
1391*7c478bd9Sstevel@tonic-gate 						continue;
1392*7c478bd9Sstevel@tonic-gate 							/* read another block */
1393*7c478bd9Sstevel@tonic-gate 					}
1394*7c478bd9Sstevel@tonic-gate 				}
1395*7c478bd9Sstevel@tonic-gate 
1396*7c478bd9Sstevel@tonic-gate 				/* If anything left, copy until newline */
1397*7c478bd9Sstevel@tonic-gate 
1398*7c478bd9Sstevel@tonic-gate 				if (c > (cbs - cbc + 1))
1399*7c478bd9Sstevel@tonic-gate 				{
1400*7c478bd9Sstevel@tonic-gate 					c = cbs - cbc + 1;
1401*7c478bd9Sstevel@tonic-gate 				}
1402*7c478bd9Sstevel@tonic-gate 				ibc -= c;
1403*7c478bd9Sstevel@tonic-gate 				cbc += c;
1404*7c478bd9Sstevel@tonic-gate 				obc += c;
1405*7c478bd9Sstevel@tonic-gate 
1406*7c478bd9Sstevel@tonic-gate 				switch (conv)
1407*7c478bd9Sstevel@tonic-gate 				{
1408*7c478bd9Sstevel@tonic-gate 				case BLOCK:
1409*7c478bd9Sstevel@tonic-gate 					do {
1410*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1411*7c478bd9Sstevel@tonic-gate 						{
1412*7c478bd9Sstevel@tonic-gate 							*op++ = ic;
1413*7c478bd9Sstevel@tonic-gate 						}
1414*7c478bd9Sstevel@tonic-gate 						else
1415*7c478bd9Sstevel@tonic-gate 						{
1416*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1417*7c478bd9Sstevel@tonic-gate 							break;
1418*7c478bd9Sstevel@tonic-gate 						}
1419*7c478bd9Sstevel@tonic-gate 					} while (--c);
1420*7c478bd9Sstevel@tonic-gate 					break;
1421*7c478bd9Sstevel@tonic-gate 
1422*7c478bd9Sstevel@tonic-gate 				case LCBLOCK:
1423*7c478bd9Sstevel@tonic-gate 					do {
1424*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1425*7c478bd9Sstevel@tonic-gate 						{
1426*7c478bd9Sstevel@tonic-gate 							*op++ = utol[ic];
1427*7c478bd9Sstevel@tonic-gate 						}
1428*7c478bd9Sstevel@tonic-gate 						else
1429*7c478bd9Sstevel@tonic-gate 						{
1430*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1431*7c478bd9Sstevel@tonic-gate 							break;
1432*7c478bd9Sstevel@tonic-gate 						}
1433*7c478bd9Sstevel@tonic-gate 					} while (--c);
1434*7c478bd9Sstevel@tonic-gate 					break;
1435*7c478bd9Sstevel@tonic-gate 
1436*7c478bd9Sstevel@tonic-gate 				case UCBLOCK:
1437*7c478bd9Sstevel@tonic-gate 					do {
1438*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1439*7c478bd9Sstevel@tonic-gate 						{
1440*7c478bd9Sstevel@tonic-gate 							*op++ = ltou[ic];
1441*7c478bd9Sstevel@tonic-gate 						}
1442*7c478bd9Sstevel@tonic-gate 						else
1443*7c478bd9Sstevel@tonic-gate 						{
1444*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1445*7c478bd9Sstevel@tonic-gate 							break;
1446*7c478bd9Sstevel@tonic-gate 						}
1447*7c478bd9Sstevel@tonic-gate 					} while (--c);
1448*7c478bd9Sstevel@tonic-gate 					break;
1449*7c478bd9Sstevel@tonic-gate 
1450*7c478bd9Sstevel@tonic-gate 				case EBCDIC:
1451*7c478bd9Sstevel@tonic-gate 					do {
1452*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1453*7c478bd9Sstevel@tonic-gate 						{
1454*7c478bd9Sstevel@tonic-gate 							*op++ = atoe[ic];
1455*7c478bd9Sstevel@tonic-gate 						}
1456*7c478bd9Sstevel@tonic-gate 						else
1457*7c478bd9Sstevel@tonic-gate 						{
1458*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1459*7c478bd9Sstevel@tonic-gate 							break;
1460*7c478bd9Sstevel@tonic-gate 						}
1461*7c478bd9Sstevel@tonic-gate 					} while (--c);
1462*7c478bd9Sstevel@tonic-gate 					break;
1463*7c478bd9Sstevel@tonic-gate 
1464*7c478bd9Sstevel@tonic-gate 				case LCEBCDIC:
1465*7c478bd9Sstevel@tonic-gate 					do {
1466*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1467*7c478bd9Sstevel@tonic-gate 						{
1468*7c478bd9Sstevel@tonic-gate 							*op++ = atoe[utol[ic]];
1469*7c478bd9Sstevel@tonic-gate 						}
1470*7c478bd9Sstevel@tonic-gate 						else
1471*7c478bd9Sstevel@tonic-gate 						{
1472*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1473*7c478bd9Sstevel@tonic-gate 							break;
1474*7c478bd9Sstevel@tonic-gate 						}
1475*7c478bd9Sstevel@tonic-gate 					} while (--c);
1476*7c478bd9Sstevel@tonic-gate 					break;
1477*7c478bd9Sstevel@tonic-gate 
1478*7c478bd9Sstevel@tonic-gate 				case UCEBCDIC:
1479*7c478bd9Sstevel@tonic-gate 					do {
1480*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1481*7c478bd9Sstevel@tonic-gate 						{
1482*7c478bd9Sstevel@tonic-gate 							*op++ = atoe[ltou[ic]];
1483*7c478bd9Sstevel@tonic-gate 						}
1484*7c478bd9Sstevel@tonic-gate 						else
1485*7c478bd9Sstevel@tonic-gate 						{
1486*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1487*7c478bd9Sstevel@tonic-gate 							break;
1488*7c478bd9Sstevel@tonic-gate 						}
1489*7c478bd9Sstevel@tonic-gate 					} while (--c);
1490*7c478bd9Sstevel@tonic-gate 					break;
1491*7c478bd9Sstevel@tonic-gate 
1492*7c478bd9Sstevel@tonic-gate 				case IBM:
1493*7c478bd9Sstevel@tonic-gate 					do {
1494*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1495*7c478bd9Sstevel@tonic-gate 						{
1496*7c478bd9Sstevel@tonic-gate 							*op++ = atoibm[ic];
1497*7c478bd9Sstevel@tonic-gate 						}
1498*7c478bd9Sstevel@tonic-gate 						else
1499*7c478bd9Sstevel@tonic-gate 						{
1500*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1501*7c478bd9Sstevel@tonic-gate 							break;
1502*7c478bd9Sstevel@tonic-gate 						}
1503*7c478bd9Sstevel@tonic-gate 					} while (--c);
1504*7c478bd9Sstevel@tonic-gate 					break;
1505*7c478bd9Sstevel@tonic-gate 
1506*7c478bd9Sstevel@tonic-gate 				case LCIBM:
1507*7c478bd9Sstevel@tonic-gate 					do {
1508*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1509*7c478bd9Sstevel@tonic-gate 						{
1510*7c478bd9Sstevel@tonic-gate 						*op++ = atoibm[utol[ic]];
1511*7c478bd9Sstevel@tonic-gate 						}
1512*7c478bd9Sstevel@tonic-gate 						else
1513*7c478bd9Sstevel@tonic-gate 						{
1514*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1515*7c478bd9Sstevel@tonic-gate 							break;
1516*7c478bd9Sstevel@tonic-gate 						}
1517*7c478bd9Sstevel@tonic-gate 					} while (--c);
1518*7c478bd9Sstevel@tonic-gate 					break;
1519*7c478bd9Sstevel@tonic-gate 
1520*7c478bd9Sstevel@tonic-gate 				case UCIBM:
1521*7c478bd9Sstevel@tonic-gate 					do {
1522*7c478bd9Sstevel@tonic-gate 						if ((ic = *ip++) != '\n')
1523*7c478bd9Sstevel@tonic-gate 						{
1524*7c478bd9Sstevel@tonic-gate 						*op++ = atoibm[ltou[ic]];
1525*7c478bd9Sstevel@tonic-gate 						}
1526*7c478bd9Sstevel@tonic-gate 						else
1527*7c478bd9Sstevel@tonic-gate 						{
1528*7c478bd9Sstevel@tonic-gate 							nlflag = 1;
1529*7c478bd9Sstevel@tonic-gate 							break;
1530*7c478bd9Sstevel@tonic-gate 						}
1531*7c478bd9Sstevel@tonic-gate 					} while (--c);
1532*7c478bd9Sstevel@tonic-gate 					break;
1533*7c478bd9Sstevel@tonic-gate 				}
1534*7c478bd9Sstevel@tonic-gate 
1535*7c478bd9Sstevel@tonic-gate 			/* If newline found, update all the counters and */
1536*7c478bd9Sstevel@tonic-gate 			/* pointers, pad with trailing blanks if necessary */
1537*7c478bd9Sstevel@tonic-gate 
1538*7c478bd9Sstevel@tonic-gate 				if (nlflag)
1539*7c478bd9Sstevel@tonic-gate 				{
1540*7c478bd9Sstevel@tonic-gate 					ibc += c - 1;
1541*7c478bd9Sstevel@tonic-gate 					obc += cbs - cbc;
1542*7c478bd9Sstevel@tonic-gate 					c += cbs - cbc;
1543*7c478bd9Sstevel@tonic-gate 					cbc = 0;
1544*7c478bd9Sstevel@tonic-gate 					if (c > 0)
1545*7c478bd9Sstevel@tonic-gate 					{
1546*7c478bd9Sstevel@tonic-gate 					/* Use the right kind of blank */
1547*7c478bd9Sstevel@tonic-gate 
1548*7c478bd9Sstevel@tonic-gate 						switch (conv)
1549*7c478bd9Sstevel@tonic-gate 						{
1550*7c478bd9Sstevel@tonic-gate 						case BLOCK:
1551*7c478bd9Sstevel@tonic-gate 						case LCBLOCK:
1552*7c478bd9Sstevel@tonic-gate 						case UCBLOCK:
1553*7c478bd9Sstevel@tonic-gate 							ic = ' ';
1554*7c478bd9Sstevel@tonic-gate 							break;
1555*7c478bd9Sstevel@tonic-gate 
1556*7c478bd9Sstevel@tonic-gate 						case EBCDIC:
1557*7c478bd9Sstevel@tonic-gate 						case LCEBCDIC:
1558*7c478bd9Sstevel@tonic-gate 						case UCEBCDIC:
1559*7c478bd9Sstevel@tonic-gate 							ic = atoe[' '];
1560*7c478bd9Sstevel@tonic-gate 							break;
1561*7c478bd9Sstevel@tonic-gate 
1562*7c478bd9Sstevel@tonic-gate 						case IBM:
1563*7c478bd9Sstevel@tonic-gate 						case LCIBM:
1564*7c478bd9Sstevel@tonic-gate 						case UCIBM:
1565*7c478bd9Sstevel@tonic-gate 							ic = atoibm[' '];
1566*7c478bd9Sstevel@tonic-gate 							break;
1567*7c478bd9Sstevel@tonic-gate 						}
1568*7c478bd9Sstevel@tonic-gate 
1569*7c478bd9Sstevel@tonic-gate 						/* Pad with trailing blanks */
1570*7c478bd9Sstevel@tonic-gate 
1571*7c478bd9Sstevel@tonic-gate 						do {
1572*7c478bd9Sstevel@tonic-gate 							*op++ = ic;
1573*7c478bd9Sstevel@tonic-gate 						} while (--c);
1574*7c478bd9Sstevel@tonic-gate 					}
1575*7c478bd9Sstevel@tonic-gate 				}
1576*7c478bd9Sstevel@tonic-gate 
1577*7c478bd9Sstevel@tonic-gate 			/* If not end of line, this line may be too long */
1578*7c478bd9Sstevel@tonic-gate 
1579*7c478bd9Sstevel@tonic-gate 				else if (cbc > cbs)
1580*7c478bd9Sstevel@tonic-gate 				{
1581*7c478bd9Sstevel@tonic-gate 					skipf = 1; /* note skip in progress */
1582*7c478bd9Sstevel@tonic-gate 					obc--;
1583*7c478bd9Sstevel@tonic-gate 					op--;
1584*7c478bd9Sstevel@tonic-gate 					cbc = 0;
1585*7c478bd9Sstevel@tonic-gate 					ntrunc++;  /* count another long line */
1586*7c478bd9Sstevel@tonic-gate 				}
1587*7c478bd9Sstevel@tonic-gate 
1588*7c478bd9Sstevel@tonic-gate 				/* Flush the output buffer if full */
1589*7c478bd9Sstevel@tonic-gate 
1590*7c478bd9Sstevel@tonic-gate 				while (obc >= obs)
1591*7c478bd9Sstevel@tonic-gate 				{
1592*7c478bd9Sstevel@tonic-gate 					op = flsh();
1593*7c478bd9Sstevel@tonic-gate 				}
1594*7c478bd9Sstevel@tonic-gate 			}
1595*7c478bd9Sstevel@tonic-gate 			break;
1596*7c478bd9Sstevel@tonic-gate 		}
1597*7c478bd9Sstevel@tonic-gate 	}
1598*7c478bd9Sstevel@tonic-gate }
1599*7c478bd9Sstevel@tonic-gate 
1600*7c478bd9Sstevel@tonic-gate /* match ************************************************************** */
1601*7c478bd9Sstevel@tonic-gate /*									*/
1602*7c478bd9Sstevel@tonic-gate /* Compare two text strings for equality				*/
1603*7c478bd9Sstevel@tonic-gate /*									*/
1604*7c478bd9Sstevel@tonic-gate /* Arg:		s - pointer to string to match with a command arg	*/
1605*7c478bd9Sstevel@tonic-gate /* Global arg:	string - pointer to command arg				*/
1606*7c478bd9Sstevel@tonic-gate /*									*/
1607*7c478bd9Sstevel@tonic-gate /* Return:	1 if match, 0 if no match				*/
1608*7c478bd9Sstevel@tonic-gate /*		If match, also reset `string' to point to the text	*/
1609*7c478bd9Sstevel@tonic-gate /*		that follows the matching text.				*/
1610*7c478bd9Sstevel@tonic-gate /*									*/
1611*7c478bd9Sstevel@tonic-gate /* ********************************************************************	*/
1612*7c478bd9Sstevel@tonic-gate 
1613*7c478bd9Sstevel@tonic-gate static int
1614*7c478bd9Sstevel@tonic-gate match(s)
1615*7c478bd9Sstevel@tonic-gate char *s;
1616*7c478bd9Sstevel@tonic-gate {
1617*7c478bd9Sstevel@tonic-gate 	char *cs;
1618*7c478bd9Sstevel@tonic-gate 
1619*7c478bd9Sstevel@tonic-gate 	cs = string;
1620*7c478bd9Sstevel@tonic-gate 	while (*cs++ == *s)
1621*7c478bd9Sstevel@tonic-gate 	{
1622*7c478bd9Sstevel@tonic-gate 		if (*s++ == '\0')
1623*7c478bd9Sstevel@tonic-gate 		{
1624*7c478bd9Sstevel@tonic-gate 			goto true;
1625*7c478bd9Sstevel@tonic-gate 		}
1626*7c478bd9Sstevel@tonic-gate 	}
1627*7c478bd9Sstevel@tonic-gate 	if (*s != '\0')
1628*7c478bd9Sstevel@tonic-gate 	{
1629*7c478bd9Sstevel@tonic-gate 		return (0);
1630*7c478bd9Sstevel@tonic-gate 	}
1631*7c478bd9Sstevel@tonic-gate 
1632*7c478bd9Sstevel@tonic-gate true:
1633*7c478bd9Sstevel@tonic-gate 	cs--;
1634*7c478bd9Sstevel@tonic-gate 	string = cs;
1635*7c478bd9Sstevel@tonic-gate 	return (1);
1636*7c478bd9Sstevel@tonic-gate }
1637*7c478bd9Sstevel@tonic-gate 
1638*7c478bd9Sstevel@tonic-gate /* number ************************************************************* */
1639*7c478bd9Sstevel@tonic-gate /*									*/
1640*7c478bd9Sstevel@tonic-gate /* Convert a numeric arg to binary					*/
1641*7c478bd9Sstevel@tonic-gate /*									*/
1642*7c478bd9Sstevel@tonic-gate /* Arg:		big - maximum valid input number			*/
1643*7c478bd9Sstevel@tonic-gate /* Global arg:	string - pointer to command arg				*/
1644*7c478bd9Sstevel@tonic-gate /*									*/
1645*7c478bd9Sstevel@tonic-gate /* Valid forms:	123 | 123k | 123w | 123b | 123*123 | 123x123		*/
1646*7c478bd9Sstevel@tonic-gate /*		plus combinations such as 2b*3kw*4w			*/
1647*7c478bd9Sstevel@tonic-gate /*									*/
1648*7c478bd9Sstevel@tonic-gate /* Return:	converted number					*/
1649*7c478bd9Sstevel@tonic-gate /*									*/
1650*7c478bd9Sstevel@tonic-gate /* ********************************************************************	*/
1651*7c478bd9Sstevel@tonic-gate 
1652*7c478bd9Sstevel@tonic-gate static unsigned long long
1653*7c478bd9Sstevel@tonic-gate number(big)
1654*7c478bd9Sstevel@tonic-gate long long big;
1655*7c478bd9Sstevel@tonic-gate {
1656*7c478bd9Sstevel@tonic-gate 	char *cs;
1657*7c478bd9Sstevel@tonic-gate 	long long n;
1658*7c478bd9Sstevel@tonic-gate 	long long cut = BIG / 10;	/* limit to avoid overflow */
1659*7c478bd9Sstevel@tonic-gate 
1660*7c478bd9Sstevel@tonic-gate 	cs = string;
1661*7c478bd9Sstevel@tonic-gate 	n = 0;
1662*7c478bd9Sstevel@tonic-gate 	while ((*cs >= '0') && (*cs <= '9') && (n <= cut))
1663*7c478bd9Sstevel@tonic-gate 	{
1664*7c478bd9Sstevel@tonic-gate 		n = n*10 + *cs++ - '0';
1665*7c478bd9Sstevel@tonic-gate 	}
1666*7c478bd9Sstevel@tonic-gate 	for (;;)
1667*7c478bd9Sstevel@tonic-gate 	{
1668*7c478bd9Sstevel@tonic-gate 		switch (*cs++)
1669*7c478bd9Sstevel@tonic-gate 		{
1670*7c478bd9Sstevel@tonic-gate 
1671*7c478bd9Sstevel@tonic-gate 		case 'k':
1672*7c478bd9Sstevel@tonic-gate 			n *= 1024;
1673*7c478bd9Sstevel@tonic-gate 			continue;
1674*7c478bd9Sstevel@tonic-gate 
1675*7c478bd9Sstevel@tonic-gate 		case 'w':
1676*7c478bd9Sstevel@tonic-gate 			n *= 2;
1677*7c478bd9Sstevel@tonic-gate 			continue;
1678*7c478bd9Sstevel@tonic-gate 
1679*7c478bd9Sstevel@tonic-gate 		case 'b':
1680*7c478bd9Sstevel@tonic-gate 			n *= BSIZE;
1681*7c478bd9Sstevel@tonic-gate 			continue;
1682*7c478bd9Sstevel@tonic-gate 
1683*7c478bd9Sstevel@tonic-gate 		case '*':
1684*7c478bd9Sstevel@tonic-gate 		case 'x':
1685*7c478bd9Sstevel@tonic-gate 			string = cs;
1686*7c478bd9Sstevel@tonic-gate 			n *= number(BIG);
1687*7c478bd9Sstevel@tonic-gate 
1688*7c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
1689*7c478bd9Sstevel@tonic-gate 		/* Fall into exit test, recursion has read rest of string */
1690*7c478bd9Sstevel@tonic-gate 		/* End of string, check for a valid number */
1691*7c478bd9Sstevel@tonic-gate 
1692*7c478bd9Sstevel@tonic-gate 		case '\0':
1693*7c478bd9Sstevel@tonic-gate 			if ((n > big) || (n < 0))
1694*7c478bd9Sstevel@tonic-gate 			{
1695*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "dd: %s \"%llu\"\n",
1696*7c478bd9Sstevel@tonic-gate 					gettext("argument out of range:"), n);
1697*7c478bd9Sstevel@tonic-gate 				exit(2);
1698*7c478bd9Sstevel@tonic-gate 			}
1699*7c478bd9Sstevel@tonic-gate 			return (n);
1700*7c478bd9Sstevel@tonic-gate 
1701*7c478bd9Sstevel@tonic-gate 		default:
1702*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "dd: %s \"%s\"\n",
1703*7c478bd9Sstevel@tonic-gate 				gettext("bad numeric argument:"), string);
1704*7c478bd9Sstevel@tonic-gate 			exit(2);
1705*7c478bd9Sstevel@tonic-gate 		}
1706*7c478bd9Sstevel@tonic-gate 	} /* never gets here */
1707*7c478bd9Sstevel@tonic-gate }
1708*7c478bd9Sstevel@tonic-gate 
1709*7c478bd9Sstevel@tonic-gate /* flsh *************************************************************** */
1710*7c478bd9Sstevel@tonic-gate /*									*/
1711*7c478bd9Sstevel@tonic-gate /* Flush the output buffer, move any excess bytes down to the beginning	*/
1712*7c478bd9Sstevel@tonic-gate /*									*/
1713*7c478bd9Sstevel@tonic-gate /* Arg:		none							*/
1714*7c478bd9Sstevel@tonic-gate /* Global args:	obuf, obc, obs, nofr, nopr				*/
1715*7c478bd9Sstevel@tonic-gate /*									*/
1716*7c478bd9Sstevel@tonic-gate /* Return:	Pointer to the first free byte in the output buffer.	*/
1717*7c478bd9Sstevel@tonic-gate /*		Also reset `obc' to account for moved bytes.		*/
1718*7c478bd9Sstevel@tonic-gate /*									*/
1719*7c478bd9Sstevel@tonic-gate /* ********************************************************************	*/
1720*7c478bd9Sstevel@tonic-gate 
1721*7c478bd9Sstevel@tonic-gate static unsigned char
1722*7c478bd9Sstevel@tonic-gate *flsh()
1723*7c478bd9Sstevel@tonic-gate {
1724*7c478bd9Sstevel@tonic-gate 	unsigned char *op, *cp;
1725*7c478bd9Sstevel@tonic-gate 	int bc;
1726*7c478bd9Sstevel@tonic-gate 	unsigned int oc;
1727*7c478bd9Sstevel@tonic-gate 
1728*7c478bd9Sstevel@tonic-gate 	if (obc)			/* don't flush if the buffer is empty */
1729*7c478bd9Sstevel@tonic-gate 	{
1730*7c478bd9Sstevel@tonic-gate 		if (obc >= obs) {
1731*7c478bd9Sstevel@tonic-gate 			oc = obs;
1732*7c478bd9Sstevel@tonic-gate 			nofr++;		/* count a full output buffer */
1733*7c478bd9Sstevel@tonic-gate 		}
1734*7c478bd9Sstevel@tonic-gate 		else
1735*7c478bd9Sstevel@tonic-gate 		{
1736*7c478bd9Sstevel@tonic-gate 			oc = obc;
1737*7c478bd9Sstevel@tonic-gate 			nopr++;		/* count a partial output buffer */
1738*7c478bd9Sstevel@tonic-gate 		}
1739*7c478bd9Sstevel@tonic-gate 		bc = write(obf, (char *)obuf, oc);
1740*7c478bd9Sstevel@tonic-gate 		if (bc != oc) {
1741*7c478bd9Sstevel@tonic-gate 			if (bc < 0)
1742*7c478bd9Sstevel@tonic-gate 				perror("write");
1743*7c478bd9Sstevel@tonic-gate 			else
1744*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
1745*7c478bd9Sstevel@tonic-gate 				gettext("dd: unexpected short write, "
1746*7c478bd9Sstevel@tonic-gate 				"wrote %d bytes, expected %d\n"), bc, oc);
1747*7c478bd9Sstevel@tonic-gate 			term(2);
1748*7c478bd9Sstevel@tonic-gate 		}
1749*7c478bd9Sstevel@tonic-gate 		obc -= oc;
1750*7c478bd9Sstevel@tonic-gate 		op = obuf;
1751*7c478bd9Sstevel@tonic-gate 
1752*7c478bd9Sstevel@tonic-gate 		/* If any data in the conversion buffer, move it into */
1753*7c478bd9Sstevel@tonic-gate 		/* the output buffer */
1754*7c478bd9Sstevel@tonic-gate 
1755*7c478bd9Sstevel@tonic-gate 		if (obc) {
1756*7c478bd9Sstevel@tonic-gate 			cp = obuf + obs;
1757*7c478bd9Sstevel@tonic-gate 			bc = obc;
1758*7c478bd9Sstevel@tonic-gate 			do {
1759*7c478bd9Sstevel@tonic-gate 				*op++ = *cp++;
1760*7c478bd9Sstevel@tonic-gate 			} while (--bc);
1761*7c478bd9Sstevel@tonic-gate 		}
1762*7c478bd9Sstevel@tonic-gate 		return (op);
1763*7c478bd9Sstevel@tonic-gate 	}
1764*7c478bd9Sstevel@tonic-gate 	return (obuf);
1765*7c478bd9Sstevel@tonic-gate }
1766*7c478bd9Sstevel@tonic-gate 
1767*7c478bd9Sstevel@tonic-gate /* term *************************************************************** */
1768*7c478bd9Sstevel@tonic-gate /*									*/
1769*7c478bd9Sstevel@tonic-gate /* Write record statistics, then exit					*/
1770*7c478bd9Sstevel@tonic-gate /*									*/
1771*7c478bd9Sstevel@tonic-gate /* Arg:		c - exit status code					*/
1772*7c478bd9Sstevel@tonic-gate /*									*/
1773*7c478bd9Sstevel@tonic-gate /* Return:	no return, calls exit					*/
1774*7c478bd9Sstevel@tonic-gate /*									*/
1775*7c478bd9Sstevel@tonic-gate /* ********************************************************************	*/
1776*7c478bd9Sstevel@tonic-gate 
1777*7c478bd9Sstevel@tonic-gate static void
1778*7c478bd9Sstevel@tonic-gate term(c)
1779*7c478bd9Sstevel@tonic-gate int c;
1780*7c478bd9Sstevel@tonic-gate {
1781*7c478bd9Sstevel@tonic-gate 	stats();
1782*7c478bd9Sstevel@tonic-gate 	exit(c);
1783*7c478bd9Sstevel@tonic-gate }
1784*7c478bd9Sstevel@tonic-gate 
1785*7c478bd9Sstevel@tonic-gate /* stats ************************************************************** */
1786*7c478bd9Sstevel@tonic-gate /*									*/
1787*7c478bd9Sstevel@tonic-gate /* Write record statistics onto standard error				*/
1788*7c478bd9Sstevel@tonic-gate /*									*/
1789*7c478bd9Sstevel@tonic-gate /* Args:	none							*/
1790*7c478bd9Sstevel@tonic-gate /* Global args:	nifr, nipr, nofr, nopr, ntrunc				*/
1791*7c478bd9Sstevel@tonic-gate /*									*/
1792*7c478bd9Sstevel@tonic-gate /* Return:	void							*/
1793*7c478bd9Sstevel@tonic-gate /*									*/
1794*7c478bd9Sstevel@tonic-gate /* ********************************************************************	*/
1795*7c478bd9Sstevel@tonic-gate 
1796*7c478bd9Sstevel@tonic-gate static void
1797*7c478bd9Sstevel@tonic-gate stats()
1798*7c478bd9Sstevel@tonic-gate {
1799*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("%llu+%llu records in\n"), nifr, nipr);
1800*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("%llu+%llu records out\n"), nofr, nopr);
1801*7c478bd9Sstevel@tonic-gate 	if (ntrunc) {
1802*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
1803*7c478bd9Sstevel@tonic-gate 			gettext("%llu truncated record(s)\n"), ntrunc);
1804*7c478bd9Sstevel@tonic-gate 	}
1805*7c478bd9Sstevel@tonic-gate }
1806