expand.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1989 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <libintl.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <wchar.h>
/*
* expand - expand tabs to equivalent spaces
*/
static int nstops = 0;
static int tabstops[100];
static int isClocale;
static void getstops(const char *);
static void usage(void);
int
int argc;
char *argv[];
{
register int c, column;
register int n;
register int i, j;
char *locale;
int len;
int p_col;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/*
* First, look for and extract any "-<number>" args then pass
* them to getstops().
*/
for (i = 1; i < argc; i++) {
break;
if (*argv[i] != '-')
continue;
continue;
tflag++;
/* Pull this arg from list */
for (j = i; j < (argc-1); j++)
argc--;
}
switch (flag) {
case 't':
if (tflag)
usage();
break;
default:
usage();
break;
}
}
do {
if (argc > 0) {
exit(1);
/* NOTREACHED */
}
argc--;
argv++;
}
column = 0;
for (;;) {
break;
}
c = *p1++;
switch (c) {
case '\t':
if (nstops == 0) {
do {
(void) putchar(' ');
column++;
} while (column & 07);
continue;
}
if (nstops == 1) {
do {
(void) putchar(' ');
column++;
} while (
(tabstops[0] - 1));
continue;
}
for (n = 0; n < nstops; n++)
break;
if (n == nstops) {
(void) putchar(' ');
column++;
continue;
}
(void) putchar(' ');
column++;
}
continue;
case '\b':
if (column)
column--;
(void) putchar('\b');
continue;
default:
if (isClocale) {
(void) putchar(c);
column++;
continue;
}
if (isascii(c)) {
(void) putchar(c);
column++;
continue;
}
p1--;
(unsigned int)MB_CUR_MAX) {
for (n = 0; n < len; n++)
stdin)) > 0)
}
(unsigned int)MB_CUR_MAX)
len = (unsigned int)MB_CUR_MAX;
(void) putchar(c);
column++;
p1++;
continue;
}
continue;
case '\n':
(void) putchar(c);
column = 0;
continue;
}
}
} while (argc > 0);
return (0);
/* NOTREACHED */
}
static void
{
register int i;
for (;;) {
i = 0;
if (i <= 0 || i > INT_MAX) {
"expand: invalid tablist\n"));
usage();
}
"expand: tablist must be increasing\n"));
usage();
}
if (*cp == 0)
break;
"expand: invalid tablist\n"));
usage();
}
cp++;
}
}
static void
usage(void)
{
"usage: expand [-t tablist] [file ...]\n"
" expand [-tabstop] [-tab1,tab2,...,tabn] [file ...]\n"));
exit(2);
/* NOTREACHED */
}