/*
* 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 2005 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"
/*
* FUNCTION PAGE INDEX
* Function Page Description
* append 16 Append chars to end of line.
* begtrunc 16 Truncate characters from beginning of line.
* center 5 Center text in the work area.
* cnvtspec 7 Convert tab spec to tab positions.
* endtrunc 16 Truncate chars from end of line.
* inputtabs 17 Expand according to input tab specs.
* main 3 MAIN
* inputn 5 Read a command line option number.
* options 4 Process command line options.
* outputtabs 19 Contract according to output tab specs.
* prepend 16 Prepend chars to line.
* process 15 Process one line of input.
* readline 14 Read one line from the file.
* readspec 12 Read a tabspec from a file.
* sstrip 18 Strip SCCS SID char from beginning of line.
* sadd 18 Add SCCS SID chars to end of line.
* type 14 Determine type of a character.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 0,
/* Default tabs */
1, 10, 16, 36, 72, 0, /* IBM 370 Assembler */
1, 10, 16, 40, 72, 0, /* IBM 370 Assembler (alt.) */
1, 8, 12, 16, 20, 55, 0, /* COBOL */
1, 6, 10, 14, 49, 0, /* COBOL (crunched) */
1, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 67, 0,
/* COBOL (crunched, many cols.) */
1, 7, 11, 15, 19, 23, 0, /* FORTRAN */
1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 0,
/* PL/1 */
1, 10, 55, 0, /* SNOBOL */
1, 12, 20, 44, 0 }, /* UNIVAC Assembler */
&tabtbl[0], /* Default specification */
static struct f {
char option;
int param;
static void append(int);
static void begtrunc(int);
static void center(void);
static int cnvtspec(char *);
static void endtrunc(int);
static int inputn(char *);
static void inputtabs(int);
static void options(int, char **);
static void outputtabs(int);
static void prepend(int);
static int readspec(char *);
static void sadd(void);
static void sstrip(void);
static char type(char);
int
{
if (optionf) { /* Write tab spec format line. */
}
if (files) {
while (--argc) {
if (*scan != '-') {
"newform: can't open %s\n", scan);
exit(1);
}
}
}
} else {
}
return (0);
}
static void
{
int n; /* Temporary number holder */
char c; /* Option character */
/* changes to option parsing includes checks for exceeding */
/* initial buffer sizes */
while (--argc > 0) {
if (*scan++ == '-') {
switch (c = *scan++) {
case 'a':
flp++;
else {
"prefix request larger than "
"buffer, %d\n", NCOLS);
exit(1);
}
break;
case 'b':
case 'e':
flp++;
break;
case 'p':
flp++;
else {
"prefix request larger than "
"buffer, %d\n", NCOLS);
exit(1);
}
break;
case 'c':
flp++;
break;
case 'f':
optionf++;
flp++;
break;
case 'i':
flp++;
break;
case 'o':
break;
/* Above allows the -o-0 option to be ignored. */
okludge++;
okludge--;
flp++;
break;
case 'l':
flp++;
else {
"line length request larger "
exit(1);
}
break;
case 's':
flp++;
soption++;
break;
default:
goto usageerr;
}
}
else
files++;
}
return;
exit(1);
}
/* _________________________________________________________________ */
static int
/* Pointer to string of digits */
{
int n; /* Number */
char c; /* Character being scanned */
n = 0;
n = n * 10 + c - '0';
return (n);
}
/* _________________________________________________________________ */
static void
{
exit(1);
}
} else {
}
}
static int
/* Pointer to spec string. */
{
char c, /* Temporary */
state = 0;
while (state >= 0) {
c = *p++;
switch (state) {
case 0:
switch (type(c)) {
case '\0':
spectype = 0;
state = -1;
break;
case NUMBER:
state = 1;
tp = 0;
break;
case '-':
state = 3;
break;
default:
goto tabspecerr;
}
break;
case 1:
switch (type(c)) {
case '\0':
spectype = 11;
state = -1;
break;
case NUMBER:
state = 1;
break;
case ',':
state = 2;
break;
default:
goto tabspecerr;
}
break;
case 2:
state = 1;
}
else
goto tabspecerr;
break;
case 3:
switch (type(c)) {
case '-':
state = 4;
break;
case 'a':
state = 5;
break;
case 'c':
state = 7;
break;
case 'f':
state = 10;
break;
case 'p':
state = 11;
break;
case 's':
state = 12;
break;
case 'u':
state = 13;
break;
case NUMBER:
state = 14;
number[0] = c - '0';
break;
default:
goto tabspecerr;
}
break;
case 4:
if (c == '\0') {
spectype = 12;
state = -1;
} else {
filep = --p;
spectype = 13;
state = -1;
}
break;
case 5:
if (c == '\0') {
spectype = 1;
state = -1;
} else if (c == '2')
state = 6;
else
goto tabspecerr;
break;
case 6:
if (c == '\0') {
spectype = 2;
state = -1;
}
else
goto tabspecerr;
break;
case 7:
switch (c) {
case '\0':
spectype = 3;
state = -1;
break;
case '2':
state = 8;
break;
case '3':
state = 9;
break;
default:
goto tabspecerr;
}
break;
case 8:
if (c == '\0') {
spectype = 4;
state = -1;
}
else
goto tabspecerr;
break;
case 9:
if (c == '\0') {
spectype = 5;
state = -1;
}
else
goto tabspecerr;
break;
case 10:
if (c == '\0') {
spectype = 6;
state = -1;
}
else
goto tabspecerr;
break;
case 11:
if (c == '\0') {
spectype = 7;
state = -1;
}
else
goto tabspecerr;
break;
case 12:
if (c == '\0') {
spectype = 8;
state = -1;
}
else
goto tabspecerr;
break;
case 13:
if (c == '\0') {
spectype = 9;
state = -1;
}
else
goto tabspecerr;
break;
case 14:
state = 14;
} else if (c == '\0') {
spectype = 10;
state = -1;
} else
goto tabspecerr;
break;
}
}
if (spectype <= 9)
return (spectype);
if (spectype == 10) {
*nexttab = 1;
}
*nexttab++ = '\0';
return (spectype);
}
if (spectype == 11) {
*nexttab++ = 1;
goto tabspecerr;
}
*nexttab++ = '\0';
return (spectype);
}
if (lock == 1) {
"newform: tabspec indirection illegal\n");
exit(1);
}
lock = 1;
if (spectype == 12) {
if (sitabspec >= 0) {
} else {
kludge = 1;
}
}
}
if (spectype == 13) {
"newform: can't open %s\n", filep);
exit(1);
}
}
lock = 0;
return (tspec);
"tabspec is \t-a\t-a2\t-c\t-c2\t-c3\t-f\t-p\t-s\n");
"\t\t-u\t--\t--file\t-number\tnumber,..,number\n");
exit(1);
/* NOTREACHED */
}
static int
/* Pointer to buffer to process */
{
char c, /* Char being looked at */
state = 0;
firsttime = 1;
while (state >= 0) {
c = *p++;
switch (state) {
case 0:
break;
case 1:
break;
case 2:
: ((c == ' ') || (c == '\t')) ? 2 : 3;
break;
case 3:
break;
case 4:
if (firsttime) {
tabspecp = --p;
p++;
firsttime = 0;
}
if ((c == ' ') || (c == '\t') || (c == ':')) {
*restore = '\0';
}
: ((c == ' ') || (c == '\t')) ? 5 : 4;
break;
case 5:
break;
case 6:
break;
}
}
if (okludge)
return (value);
}
static char *
/* fp - File to read from */
/* area - Array of characters to read into */
{
int c; /* Current character */
/* check for existence of stdin before attempting to read */
/* kludge refers to reading from stdin to get tabspecs for option -i-- */
;
kludge = 0;
return (xarea);
} else
return (NULL);
} else {
/* check for exceeding size of buffer when reading valid input */
case EOF:
return (NULL);
/* FALLTHROUGH */
case '\n': /* EOF falls through to here */
*area = '\n';
return (xarea);
}
*area = c;
area++;
}
(void) printf("newform: input line larger than buffer area \n");
exit(1);
}
/* NOTREACHED */
}
/* _________________________________________________________________ */
static char
/* Character to check */
{
}
static void
/* File pointer for current input */
{
effll = 80;
pachar = ' ';
/* changes to line parsing includes checks for exceeding */
/* line size when modifying text */
case 'a':
break;
case 'b':
else
"newform: truncate "
"request larger than line, %d \n",
break;
case 'c':
break;
case 'e':
else
"newform: truncate "
"request larger than line, %d \n",
break;
case 'f':
/* Ignored */
break;
case 'i':
break;
case 'l': /* New eff line length */
break;
case 's':
sstrip();
break;
case 'o':
break;
case 'p':
break;
}
}
*++plast = '\0';
}
}
static void
/* Number of characters to append. */
{
*plast = '\n';
}
}
/* _________________________________________________________________ */
static void
/* Number of characters to prepend. */
{
}
}
/* _________________________________________________________________ */
static void
/* Number of characters to truncate. */
{
pfirst += n;
}
}
/* _________________________________________________________________ */
static void
/* Number of characters to truncate. */
{
plast -= n;
else
*plast = '\n';
}
}
static void
/* Pointer to tab specification. */
{
char c; /* Character being scanned */
logcol = 1;
center();
switch (c = *pfirst++) {
case '\b':
*tlast++ = c;
break;
case '\t':
*tlast++ = ' ';
logcol++;
}
tabs++;
break;
default:
*tlast++ = c;
logcol++;
break;
}
}
}
/*
* Add SCCS SID (generated by a "get -m" command) to the end of each line.
* Sequence is as follows for EACH line:
* Check for at least 1 tab. Err if none.
* Strip off all char up to & including first tab.
* If more than 8 char were stripped, the 8 th is replaced by
* a '*' & the remainder are discarded.
* Unless user specified an "a", append blanks to fill
* out line to eff. line length (default= 72 char).
* Truncate lines > eff. line length (default=72).
* Add stripped char to end of line.
*/
static void
sstrip(void)
{
int i, k;
char *c, *savec;
k = -1;
c = pfirst;
while (*c != '\t' && *c != '\n') {
k++;
c++;
}
if (*c != '\t') {
exit(1);
}
savec = c;
c = pfirst;
}
/* ================================================================= */
static void
sadd(void)
{
int i;
*plast = '\n';
}
static void
/* Pointer to tab specification. */
{
char c; /* Character being scanned */
logcol = 1;
switch (c = *pfirst++) {
case '\b':
*tlast++ = c;
break;
case ' ':
do {
*tlast++ = ' ';
logcol++;
*mark++ = '\t';
tabs++;
}
} while (*pfirst++ == ' ');
pfirst--;
break;
default:
logcol++;
*tlast++ = c;
break;
}
}
}