4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
52 * expand - expand tabs to equivalent spaces
54 static int nstops
= 0;
55 static int tabstops
[100];
58 static void getstops(const char *);
59 static void usage(void);
66 static char ibuf
[BUFSIZ
];
67 register int c
, column
;
77 (void) setlocale(LC_ALL
, "");
78 locale
= setlocale(LC_CTYPE
, NULL
);
79 isClocale
= (strcmp(locale
, "C") == 0);
80 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
81 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
83 (void) textdomain(TEXT_DOMAIN
);
86 * First, look for and extract any "-<number>" args then pass
89 for (i
= 1; i
< argc
; i
++) {
90 if (strcmp(argv
[i
], "--") == 0)
95 if (!isdigit(*(argv
[i
]+1)))
101 /* Pull this arg from list */
102 for (j
= i
; j
< (argc
-1); j
++)
107 while ((flag
= getopt(argc
, argv
, "t:")) != EOF
) {
123 argv
= &argv
[optind
];
127 if (freopen(argv
[0], "r", stdin
) == NULL
) {
141 if ((len
= fread(p1
, 1, BUFSIZ
, stdin
)) <= 0)
153 } while (column
& 07);
161 ((column
- 1) % tabstops
[0]) !=
165 for (n
= 0; n
< nstops
; n
++)
166 if (tabstops
[n
] > column
)
173 while (column
< tabstops
[n
]) {
182 (void) putchar('\b');
199 if ((len
= (p2
- p1
)) <
200 (unsigned int)MB_CUR_MAX
) {
201 for (n
= 0; n
< len
; n
++)
205 if ((len
= fread(p2
, 1, BUFSIZ
- n
,
209 if ((len
= (p2
- p1
)) >
210 (unsigned int)MB_CUR_MAX
)
211 len
= (unsigned int)MB_CUR_MAX
;
213 if ((len
= mbtowc(&wc
, p1
, len
)) <= 0) {
220 if ((p_col
= wcwidth(wc
)) < 0)
240 getstops(const char *cp
)
246 while (*cp
>= '0' && *cp
<= '9')
247 i
= i
* 10 + *cp
++ - '0';
249 if (i
<= 0 || i
> INT_MAX
) {
250 (void) fprintf(stderr
, gettext(
251 "expand: invalid tablist\n"));
255 if (nstops
> 0 && i
<= tabstops
[nstops
-1]) {
256 (void) fprintf(stderr
, gettext(
257 "expand: tablist must be increasing\n"));
261 tabstops
[nstops
++] = i
;
265 if (*cp
!= ',' && *cp
!= ' ') {
266 (void) fprintf(stderr
, gettext(
267 "expand: invalid tablist\n"));
277 (void) fprintf(stderr
, gettext(
278 "usage: expand [-t tablist] [file ...]\n"
279 " expand [-tabstop] [-tab1,tab2,...,tabn] [file ...]\n"));