/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* col - filter reverse carraige motions
*
*/
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>
#include <stdlib.h>
#include <wctype.h>
int greeked;
int half;
int pcp = 0;
char *pgmname;
static void store(int);
static void fetch(int);
static void incr(void);
static void decr(void);
static void incr_line(int);
static int wcscrwidth(wchar_t);
int
{
int i, n;
int opt;
int greek;
int c;
char byte;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
switch (opt) {
case 'b':
bflag++;
break;
case 'x':
xflag++;
break;
case 'f':
fflag++;
break;
case 'p':
pflag++;
break;
case '?':
default:
exit(2);
}
if (argc >= 1) {
exit(2);
}
cp = 0;
ll = 0;
greek = 0;
if (*line) {
incr_line(1);
}
*line = 'X';
incr_line(1);
}
if (c != '\b')
if (esc_chars)
esc_chars = '\0';
switch (c) {
case '\n':
if (*line)
incr_line(1);
incr_line(1);
*line = 'Y';
incr_line(1);
*line = '\0';
temp_off = '1';
}
incr();
incr();
cp = 0;
continue;
case '\0':
continue;
case ESC:
c = getwchar();
switch (c) {
case '7': /* reverse full line feed */
decr();
decr();
break;
case '8': /* reverse half line feed */
if (fflag)
decr();
else {
if (--half < -1) {
decr();
decr();
half += 2;
}
}
break;
case '9': /* forward half line feed */
if (fflag)
incr();
else {
if (++half > 0) {
incr();
incr();
half -= 2;
}
}
break;
default:
if (pflag) { /* pass through esc */
incr_line(1);
*line = c;
incr_line(1);
*line = '\0';
esc_chars = 1;
if (c == 'X')
underline = 1;
if (c == 'Y' && underline)
if (c == ']')
smart = 1;
if (c == '[')
smart = '\0';
}
break;
}
continue;
case SO:
greeked++;
continue;
case SI:
greek = 0;
continue;
case RLF:
decr();
decr();
continue;
case '\r':
cp = 0;
continue;
case '\t':
continue;
case '\b':
if (esc_chars) {
*line = '\b';
incr_line(1);
*line = '\0';
} else if (cp > 0)
cp--;
continue;
case ' ':
cp++;
continue;
default:
if (iswprint(c)) { /* if printable */
if (!greek) {
cp += wcscrwidth(c);
}
/*
* EUC (apply SO only when there can
* be corresponding character in CS1)
*/
else if (iswascii(c)) {
n == 1) {
} else {
cp += wcscrwidth(c);
}
} else {
cp += wcscrwidth(c);
}
gettext("col: Line too long\n"));
exit(2);
}
}
continue;
}
}
for (i = 0; i < PL; i++)
return (0);
}
static void
{
int n, i;
lp = 0;
}
if (*line != '\b')
if (esc_chars)
esc_chars = '\0';
switch (*line) {
case ESC:
incr_line(1);
esc_chars = 1;
break;
case '\0':
*line = ' ';
lp++;
break;
case '\b':
/* if ( ! esc_chars ) */
lp--;
break;
default:
}
incr_line(1);
}
while (*line == '\b') {
/*
* EUC (For a multi-column character, backspace characters
* are assumed to be used like "__^H^HXX", where "XX"
* represents a two-column character, and a backspace
* always goes back by one column.)
*/
n++;
lp--;
}
i = *line;
incr_line(1);
i = wcscrwidth(i);
n -= i;
lp += i;
}
}
incr_line(6);
widthc = wcscrwidth(c);
*line = c;
*line = c;
incr_line(1);
for (i = 0; i < n; i++) {
*line = ' ';
incr_line(1);
}
lp = 0;
} else {
n -= wcscrwidth(i)) {
i = *p1++;
}
*line = c;
} else {
gettext("col: Line too long.\n"));
exit(1);
}
} else {
gettext("col: Line too long.\n"));
exit(1);
}
}
} else {
incr_line(1);
incr_line(1);
*line = '[';
incr_line(1);
*line = '\b';
incr_line(1);
incr_line(1);
*line = ']';
incr_line(1);
*line = c;
incr_line(1);
while (c1) {
incr_line(1);
}
} else {
incr_line(1);
*line = '\b';
incr_line(1);
*line = c;
incr_line(1);
while (c1) {
incr_line(1);
}
} else {
incr_line(1);
}
for (i = 0; i < width; i++) {
*line = '\b';
incr_line(1);
}
*line = c;
incr_line(1);
*line = ' ';
incr_line(1);
}
}
}
lp = 0;
}
}
static void
{
* sizeof (wchar_t));
/* fprintf(stderr, "%s: no storage\n", pgmname); */
exit(2);
}
}
static void
{
wchar_t *p;
p = lbuff;
while (*p)
*p++ = '\0';
lp = 0;
}
static void
{
static int cline = 0;
int ncp;
wchar_t *p;
char cshifted;
int c;
static int gflag = 0;
if (*s) {
if (gflag) {
gflag = 0;
}
(void) putchar('\n');
pcp = 0;
cline += 2;
}
(void) putchar('9');
cline++;
}
if (pcp)
(void) putchar('\r');
pcp = 0;
p = s;
while (*p) {
while (*p++ == ' ') {
(void) putchar('\t');
}
}
if (!*--p)
break;
(void) putchar(' ');
pcp++;
}
if (greeked) {
*p != '\b' &&
if (gflag)
else
}
}
}
c = *p;
if (greeked) {
} else
(void) putwchar(c);
} else
(void) putwchar(c);
if (c == '\b') {
pcp++;
} else
pcp--;
} else {
pcp += wcscrwidth(c);
}
p++;
}
}
}
static void
incr(void)
{
mustwr++;
}
}
static void
decr(void)
{
}
}
static void
{
while (p1 >= s)
}
/*
* incr_line - increments line pointer and checks for array out of bounds
* amt: assumed to be >= 1
* exit on error to avoid line pointer accessing out of the array
*/
static void
{
} else {
exit(1);
}
}
static int
{
int nc;
if (wc == 0) {
/*
* if wc is a null character, needs to
* return 1 instead of 0.
*/
return (1);
}
if (nc > 0) {
return (nc);
} else {
return (0);
}
}