newform.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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.14 */
/* 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 <stdio.h>
#define MAXOPTS 50
#define NCOLS 512
#define MAXLINE 512
#define NUMBER '0'
#define LINELEN 80
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 */
savek; /* Stores char count stripped from front of line. */
optionf = 0, /* 'f' option set */
soption = 0, /* 's' option used. */
files = 0, /* Number of input files */
kludge = 0, /* Kludge to allow reread of 1st line */
okludge = 0, /* Kludge to indicate reading "o" option*/
lock = 0; /* Lock to prevent file indirection */
*pfirst, /* Pointer to beginning of line */
*plast, /* Pointer to end of line */
*strcpy(); /* Eliminates a warning by 'lint'. */
struct f {
char option;
int param;
int argc; /* Count of command line arguments */
char **argv; /* Array of pointers to arguments */
{
char *scan; /* String scan pointer */
if (optionf) /* Write tab spec format line. */
}
if (files) {
while (--argc) {
if (*scan != '-') {
"newform: can't open %s\n",scan);
exit(1);
}
}
}
}
else {
}
exit(0);
}
register int argc; /* Count of arguments */
register char **argv; /* Array of pointers to arguments */
{
int n; /* Temporary number holder */
register char *scan, /* Pointer to individual option strings */
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 {
exit(1);
}
break;
case 'b':
case 'e':
flp++;
break;
case 'p':
flp++;
else {
exit(1);
}
break;
case 'c':
flp++;
break;
case 'f':
optionf++;
flp++;
break;
case 'i':
flp++;
break;
case 'o':
/* Above allows the -o-0 option to be ignored. */
okludge++;
okludge--;
flp++;
break;
case 'l':
flp++;
else {
exit(1);
}
break;
case 's':
flp++;
soption++;
break;
default:
goto usageerr;
}
}
else
files++;
}
return;
exit(1);
}
/* _________________________________________________________________ */
register char *scan; /* Pointer to string of digits */
{
int n; /* Number */
char c; /* Character being scanned */
n = 0;
n = n * 10 + c - '0';
return(n);
}
/* _________________________________________________________________ */
center() /* Center the text in the work area. */
{
char *tfirst, /* Pointer for moving buffer down */
*tlast, /* Pointer for moving buffer up */
*tptr; /* Temporary */
exit(1);
}
}
else {
}
}
int cnvtspec(p) /* Convert tab specification to tab positions. */
register char *p; /* Pointer to spec string. */
{
int state, /* DFA state */
spectype, /* Specification type */
tp, /* Pointer to last number */
ix; /* Temporary */
int tspec=0; /* Tab spec pointer */
char c, /* Temporary */
*stptr, /* Pointer to stdin */
*filep, /* Pointer to file name */
type(), /* Function */
*readline(); /* Function */
*fp; /* File pointer */
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 == 10) {
*nexttab = 1;
}
*nexttab++ = '\0';
return(spectype);
}
if (spectype == 11) {
*nexttab++ = 1;
goto tabspecerr;
}
*nexttab++ = '\0';
return(spectype);
}
if (lock == 1) {
exit(1);
}
lock = 1;
if (spectype == 12) {
if (sitabspec >= 0) {
}
else {
kludge = 1;
}
}
}
if (spectype == 13) {
exit(1);
}
}
lock = 0;
return(tspec);
exit(1);
return(-1); /* Stops 'lint's complaint about return(e) VS return. */
}
int readspec(p) /* Read a tabspec from a file */
register char *p; /* Pointer to buffer to process */
{
int state, /* Current state */
firsttime, /* Flag to indicate spec found */
value; /* Function value */
char c, /* Char being looked at */
*tabspecp, /* Pointer to spec string */
repch; /* Character to replace with */
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;
}
}
return(value);
}
char *area; /* Array of characters to read into */
{
int c; /* Current character */
char *xarea, /* Temporary pointer to character array */
*temp; /* Array pointer */
/* 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);
case '\n': /*EOF falls through to here*/
*area = '\n';
return(xarea);
}
*area=c;
*area++;
}
printf("newform: input line larger than buffer area \n");
exit(1);
}
return(&UNDEF); /* Stops 'lint's complaint about return(e) VS return. */
}
/* _________________________________________________________________ */
char type(c) /* Determine type of a character */
char c; /* Character to check */
{
}
{
struct f *lp; /* Pointer to structs */
char *readline(); /* Function */
char chrnow; /* For int to char conversion. */
effll = 80;
pachar = ' ';
/* changes to line parsing includes checks for exceeding */
/* line size when modifying text */
case 'a':
break;
case 'b':
else
break;
case 'c':
break;
case 'e':
else
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';
}
}
append(n) /* Append characters to end of line. */
int n; /* Number of characters to append. */
{
*plast = '\n';
}
}
/* _________________________________________________________________ */
prepend(n) /* Prepend characters to line. */
int n; /* Number of characters to prepend. */
{
}
}
/* _________________________________________________________________ */
begtrunc(n) /* Truncate characters from beginning of line. */
int n; /* Number of characters to truncate. */
{
pfirst += n;
}
}
/* _________________________________________________________________ */
endtrunc(n) /* Truncate characters from end of line.*/
int n; /* Number of characters to truncate. */
{
plast -= n;
else
*plast = '\n';
}
}
inputtabs(p) /* Expand according to input tab specifications.*/
int p; /* Pointer to tab specification. */
{
int *tabs; /* Pointer to tabs */
char *tfirst, /* Pointer to new buffer start */
*tlast; /* Pointer to new buffer end */
register char c; /* Character being scanned */
int logcol; /* Logical column */
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. */
sstrip()
{
register int i, k;
char *c,*savec;
k = -1;
c = pfirst;
while(*c != '\t' && *c != '\n'){k++; c++;}
savec = c;
c = pfirst;
}
/* ================================================================= */
sadd()
{
register int i;
*plast = '\n';
}
outputtabs(p) /* Contract according to output tab specifications. */
int p; /* Pointer to tab specification. */
{
int *tabs; /* Pointer to tabs */
char *tfirst, /* Pointer to new buffer start */
*tlast, /* Pointer to new buffer end */
*mark; /* Marker pointer */
register char c; /* Character being scanned */
int logcol; /* Logical column */
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;
}
}
}