1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.14 */ 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate /* FUNCTION PAGE INDEX 29*0Sstevel@tonic-gate Function Page Description 30*0Sstevel@tonic-gate append 16 Append chars to end of line. 31*0Sstevel@tonic-gate begtrunc 16 Truncate characters from beginning of line. 32*0Sstevel@tonic-gate center 5 Center text in the work area. 33*0Sstevel@tonic-gate cnvtspec 7 Convert tab spec to tab positions. 34*0Sstevel@tonic-gate endtrunc 16 Truncate chars from end of line. 35*0Sstevel@tonic-gate inputtabs 17 Expand according to input tab specs. 36*0Sstevel@tonic-gate main 3 MAIN 37*0Sstevel@tonic-gate inputn 5 Read a command line option number. 38*0Sstevel@tonic-gate options 4 Process command line options. 39*0Sstevel@tonic-gate outputtabs 19 Contract according to output tab specs. 40*0Sstevel@tonic-gate prepend 16 Prepend chars to line. 41*0Sstevel@tonic-gate process 15 Process one line of input. 42*0Sstevel@tonic-gate readline 14 Read one line from the file. 43*0Sstevel@tonic-gate readspec 12 Read a tabspec from a file. 44*0Sstevel@tonic-gate sstrip 18 Strip SCCS SID char from beginning of line. 45*0Sstevel@tonic-gate sadd 18 Add SCCS SID chars to end of line. 46*0Sstevel@tonic-gate type 14 Determine type of a character. */ 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate #include <stdio.h> 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate #define MAXOPTS 50 51*0Sstevel@tonic-gate #define NCOLS 512 52*0Sstevel@tonic-gate #define MAXLINE 512 53*0Sstevel@tonic-gate #define NUMBER '0' 54*0Sstevel@tonic-gate #define LINELEN 80 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate int tabtbl[500] = { /* Table containing tab stops */ 57*0Sstevel@tonic-gate 1,9,17,25,33,41,49,57,65,73,0, 58*0Sstevel@tonic-gate /* Default tabs */ 59*0Sstevel@tonic-gate 1,10,16,36,72,0, /* IBM 370 Assembler */ 60*0Sstevel@tonic-gate 1,10,16,40,72,0, /* IBM 370 Assembler (alt.) */ 61*0Sstevel@tonic-gate 1,8,12,16,20,55,0, /* COBOL */ 62*0Sstevel@tonic-gate 1,6,10,14,49,0, /* COBOL (crunched) */ 63*0Sstevel@tonic-gate 1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67,0, 64*0Sstevel@tonic-gate /* COBOL (crunched, many cols.) */ 65*0Sstevel@tonic-gate 1,7,11,15,19,23,0, /* FORTRAN */ 66*0Sstevel@tonic-gate 1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61,0, 67*0Sstevel@tonic-gate /* PL/1 */ 68*0Sstevel@tonic-gate 1,10,55,0, /* SNOBOL */ 69*0Sstevel@tonic-gate 1,12,20,44,0 }, /* UNIVAC Assembler */ 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate *nexttab = &tabtbl[87], /* Pointer to next empty slot */ 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate *spectbl[40] = { /* Table of pointers into tabtbl */ 74*0Sstevel@tonic-gate &tabtbl[0], /* Default specification */ 75*0Sstevel@tonic-gate &tabtbl[11], /* -a specification */ 76*0Sstevel@tonic-gate &tabtbl[17], /* -a2 specification */ 77*0Sstevel@tonic-gate &tabtbl[23], /* -c specification */ 78*0Sstevel@tonic-gate &tabtbl[30], /* -c2 specification */ 79*0Sstevel@tonic-gate &tabtbl[36], /* -c3 specification */ 80*0Sstevel@tonic-gate &tabtbl[54], /* -f specification */ 81*0Sstevel@tonic-gate &tabtbl[61], /* -p specification */ 82*0Sstevel@tonic-gate &tabtbl[78], /* -s specification */ 83*0Sstevel@tonic-gate &tabtbl[82] }, /* -u specification */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate savek; /* Stores char count stripped from front of line. */ 86*0Sstevel@tonic-gate int nextspec = 10, /* Index to next slot */ 87*0Sstevel@tonic-gate sitabspec = -1, /* Index to "standard input" spec. */ 88*0Sstevel@tonic-gate effll = 80, /* Effective line length */ 89*0Sstevel@tonic-gate optionf = 0, /* 'f' option set */ 90*0Sstevel@tonic-gate soption = 0, /* 's' option used. */ 91*0Sstevel@tonic-gate files = 0, /* Number of input files */ 92*0Sstevel@tonic-gate kludge = 0, /* Kludge to allow reread of 1st line */ 93*0Sstevel@tonic-gate okludge = 0, /* Kludge to indicate reading "o" option*/ 94*0Sstevel@tonic-gate lock = 0; /* Lock to prevent file indirection */ 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate char pachar = ' ', /* Prepend/append character */ 97*0Sstevel@tonic-gate work[3*NCOLS+1], /* Work area */ 98*0Sstevel@tonic-gate *pfirst, /* Pointer to beginning of line */ 99*0Sstevel@tonic-gate *plast, /* Pointer to end of line */ 100*0Sstevel@tonic-gate *wfirst = &work[0], /* Pointer to beginning of work area */ 101*0Sstevel@tonic-gate *wlast = &work[3*NCOLS], /* Pointer to end of work area */ 102*0Sstevel@tonic-gate siline[NCOLS], /* First standard input line */ 103*0Sstevel@tonic-gate savchr[8], /* Holds char stripped from line start */ 104*0Sstevel@tonic-gate format[80] = "-8", /* Array to hold format line */ 105*0Sstevel@tonic-gate *strcpy(); /* Eliminates a warning by 'lint'. */ 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate struct f { 108*0Sstevel@tonic-gate char option; 109*0Sstevel@tonic-gate int param; 110*0Sstevel@tonic-gate } optl[MAXOPTS], /* List of command line options */ 111*0Sstevel@tonic-gate *flp = optl; /* Pointer to next open slot */ 112*0Sstevel@tonic-gate main(argc,argv) /* Main procedure */ 113*0Sstevel@tonic-gate int argc; /* Count of command line arguments */ 114*0Sstevel@tonic-gate char **argv; /* Array of pointers to arguments */ 115*0Sstevel@tonic-gate { 116*0Sstevel@tonic-gate char *scan; /* String scan pointer */ 117*0Sstevel@tonic-gate FILE *fp; /* Pointer to current file */ 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate options(argc,argv); 120*0Sstevel@tonic-gate if (optionf) /* Write tab spec format line. */ 121*0Sstevel@tonic-gate {fputs("<:t",stdout); 122*0Sstevel@tonic-gate fputs(format,stdout); 123*0Sstevel@tonic-gate fputs(" d:>\n",stdout); 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate if (files) { 126*0Sstevel@tonic-gate while (--argc) { 127*0Sstevel@tonic-gate scan = *++argv; 128*0Sstevel@tonic-gate if (*scan != '-') { 129*0Sstevel@tonic-gate if ((fp = fopen(scan,"r")) == NULL) { 130*0Sstevel@tonic-gate fprintf(stderr, 131*0Sstevel@tonic-gate "newform: can't open %s\n",scan); 132*0Sstevel@tonic-gate exit(1); 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate process(fp); 135*0Sstevel@tonic-gate fclose(fp); 136*0Sstevel@tonic-gate } 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate else { 140*0Sstevel@tonic-gate process(stdin); 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate exit(0); 143*0Sstevel@tonic-gate } 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate options(argc, argv) /* Process command line options */ 147*0Sstevel@tonic-gate register int argc; /* Count of arguments */ 148*0Sstevel@tonic-gate register char **argv; /* Array of pointers to arguments */ 149*0Sstevel@tonic-gate { 150*0Sstevel@tonic-gate int n; /* Temporary number holder */ 151*0Sstevel@tonic-gate register char *scan, /* Pointer to individual option strings */ 152*0Sstevel@tonic-gate c; /* Option character */ 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate /* changes to option parsing includes checks for exceeding */ 155*0Sstevel@tonic-gate /* initial buffer sizes */ 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate while (--argc > 0) { 158*0Sstevel@tonic-gate scan = *++argv; 159*0Sstevel@tonic-gate if (*scan++ == '-') { 160*0Sstevel@tonic-gate switch (c = *scan++) { 161*0Sstevel@tonic-gate case 'a': 162*0Sstevel@tonic-gate flp->option = 'a'; 163*0Sstevel@tonic-gate flp->param = inputn(scan); 164*0Sstevel@tonic-gate if (flp->param <=NCOLS) 165*0Sstevel@tonic-gate flp++; 166*0Sstevel@tonic-gate else { 167*0Sstevel@tonic-gate fprintf(stderr,"newform: prefix request larger than buffer, %d\n", NCOLS); 168*0Sstevel@tonic-gate exit(1); 169*0Sstevel@tonic-gate } 170*0Sstevel@tonic-gate break; 171*0Sstevel@tonic-gate case 'b': 172*0Sstevel@tonic-gate case 'e': 173*0Sstevel@tonic-gate flp->option = c; 174*0Sstevel@tonic-gate flp->param = inputn(scan); 175*0Sstevel@tonic-gate flp++; 176*0Sstevel@tonic-gate break; 177*0Sstevel@tonic-gate case 'p': 178*0Sstevel@tonic-gate flp->option = 'p'; 179*0Sstevel@tonic-gate flp->param = inputn(scan); 180*0Sstevel@tonic-gate if (flp->param <=NCOLS) 181*0Sstevel@tonic-gate flp++; 182*0Sstevel@tonic-gate else { 183*0Sstevel@tonic-gate fprintf(stderr,"newform: prefix request larger than buffer, %d\n", NCOLS); 184*0Sstevel@tonic-gate exit(1); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate break; 187*0Sstevel@tonic-gate case 'c': 188*0Sstevel@tonic-gate flp->option = 'c'; 189*0Sstevel@tonic-gate flp->param = *scan ? *scan : ' '; 190*0Sstevel@tonic-gate flp++; 191*0Sstevel@tonic-gate break; 192*0Sstevel@tonic-gate case 'f': 193*0Sstevel@tonic-gate flp->option = 'f'; 194*0Sstevel@tonic-gate optionf++; 195*0Sstevel@tonic-gate flp++; 196*0Sstevel@tonic-gate break; 197*0Sstevel@tonic-gate case 'i': 198*0Sstevel@tonic-gate flp->option = 'i'; 199*0Sstevel@tonic-gate flp->param = cnvtspec(scan); 200*0Sstevel@tonic-gate flp++; 201*0Sstevel@tonic-gate break; 202*0Sstevel@tonic-gate case 'o': 203*0Sstevel@tonic-gate if(*scan=='-' && *(scan+1)=='0' && *(scan+2)=='\0')break; 204*0Sstevel@tonic-gate /* Above allows the -o-0 option to be ignored. */ 205*0Sstevel@tonic-gate flp->option = 'o'; 206*0Sstevel@tonic-gate strcpy(format,scan); 207*0Sstevel@tonic-gate okludge++; 208*0Sstevel@tonic-gate flp->param = cnvtspec(scan); 209*0Sstevel@tonic-gate okludge--; 210*0Sstevel@tonic-gate if(flp->param == 0) strcpy(format,"-8"); 211*0Sstevel@tonic-gate flp++; 212*0Sstevel@tonic-gate break; 213*0Sstevel@tonic-gate case 'l': 214*0Sstevel@tonic-gate flp->option = 'l'; 215*0Sstevel@tonic-gate flp->param = ((n = inputn(scan)) ? n : 72); 216*0Sstevel@tonic-gate if (flp->param <= (3*NCOLS)) 217*0Sstevel@tonic-gate flp++; 218*0Sstevel@tonic-gate else { 219*0Sstevel@tonic-gate fprintf(stderr, "newform: line length request larger than buffer, %d \n", (3*NCOLS)); 220*0Sstevel@tonic-gate exit(1); 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate break; 223*0Sstevel@tonic-gate case 's': 224*0Sstevel@tonic-gate flp->option = 's'; 225*0Sstevel@tonic-gate flp++; 226*0Sstevel@tonic-gate soption++; 227*0Sstevel@tonic-gate break; 228*0Sstevel@tonic-gate default: 229*0Sstevel@tonic-gate goto usageerr; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate } 232*0Sstevel@tonic-gate else 233*0Sstevel@tonic-gate files++; 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate return; 236*0Sstevel@tonic-gate usageerr: 237*0Sstevel@tonic-gate fprintf(stderr,"usage: newform [-s] [-itabspec] [-otabspec] "); 238*0Sstevel@tonic-gate fprintf(stderr,"[-pn] [-en] [-an] [-f] [-cchar]\n\t\t"); 239*0Sstevel@tonic-gate fprintf(stderr,"[-ln] [-bn] [file ...]\n"); 240*0Sstevel@tonic-gate exit(1); 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate /* _________________________________________________________________ */ 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate int inputn(scan) /* Read a command option number */ 245*0Sstevel@tonic-gate register char *scan; /* Pointer to string of digits */ 246*0Sstevel@tonic-gate { 247*0Sstevel@tonic-gate int n; /* Number */ 248*0Sstevel@tonic-gate char c; /* Character being scanned */ 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate n = 0; 251*0Sstevel@tonic-gate while ((c = *scan++) >= '0' && c <= '9') 252*0Sstevel@tonic-gate n = n * 10 + c - '0'; 253*0Sstevel@tonic-gate return(n); 254*0Sstevel@tonic-gate } 255*0Sstevel@tonic-gate /* _________________________________________________________________ */ 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate center() /* Center the text in the work area. */ 258*0Sstevel@tonic-gate { 259*0Sstevel@tonic-gate char *tfirst, /* Pointer for moving buffer down */ 260*0Sstevel@tonic-gate *tlast, /* Pointer for moving buffer up */ 261*0Sstevel@tonic-gate *tptr; /* Temporary */ 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate if (plast - pfirst > MAXLINE) { 264*0Sstevel@tonic-gate fprintf(stderr,"newform: internal line too long\n"); 265*0Sstevel@tonic-gate exit(1); 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate if (pfirst < &work[NCOLS]) { 268*0Sstevel@tonic-gate tlast = plast + (&work[NCOLS] - pfirst); 269*0Sstevel@tonic-gate tptr = tlast; 270*0Sstevel@tonic-gate while (plast >= pfirst) *tlast-- = *plast--; 271*0Sstevel@tonic-gate pfirst = ++tlast; 272*0Sstevel@tonic-gate plast = tptr; 273*0Sstevel@tonic-gate } 274*0Sstevel@tonic-gate else { 275*0Sstevel@tonic-gate tfirst = &work[NCOLS]; 276*0Sstevel@tonic-gate tptr = tfirst; 277*0Sstevel@tonic-gate while (pfirst <= plast) *tfirst++ = *pfirst++; 278*0Sstevel@tonic-gate plast = --tfirst; 279*0Sstevel@tonic-gate pfirst = tptr; 280*0Sstevel@tonic-gate } 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate int cnvtspec(p) /* Convert tab specification to tab positions. */ 283*0Sstevel@tonic-gate register char *p; /* Pointer to spec string. */ 284*0Sstevel@tonic-gate { 285*0Sstevel@tonic-gate int state, /* DFA state */ 286*0Sstevel@tonic-gate spectype, /* Specification type */ 287*0Sstevel@tonic-gate number[40], /* Array of read-in numbers */ 288*0Sstevel@tonic-gate tp, /* Pointer to last number */ 289*0Sstevel@tonic-gate ix; /* Temporary */ 290*0Sstevel@tonic-gate int tspec=0; /* Tab spec pointer */ 291*0Sstevel@tonic-gate char c, /* Temporary */ 292*0Sstevel@tonic-gate *stptr, /* Pointer to stdin */ 293*0Sstevel@tonic-gate *filep, /* Pointer to file name */ 294*0Sstevel@tonic-gate type(), /* Function */ 295*0Sstevel@tonic-gate *readline(); /* Function */ 296*0Sstevel@tonic-gate FILE *fopen(), /* File open routine */ 297*0Sstevel@tonic-gate *fp; /* File pointer */ 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate state = 0; 300*0Sstevel@tonic-gate while (state >= 0) { 301*0Sstevel@tonic-gate c = *p++; 302*0Sstevel@tonic-gate switch (state) { 303*0Sstevel@tonic-gate case 0: 304*0Sstevel@tonic-gate switch (type(c)) { 305*0Sstevel@tonic-gate case '\0': 306*0Sstevel@tonic-gate spectype = 0; 307*0Sstevel@tonic-gate state = -1; 308*0Sstevel@tonic-gate break; 309*0Sstevel@tonic-gate case NUMBER: 310*0Sstevel@tonic-gate state = 1; 311*0Sstevel@tonic-gate tp = 0; 312*0Sstevel@tonic-gate number[tp] = c - '0'; 313*0Sstevel@tonic-gate break; 314*0Sstevel@tonic-gate case '-': 315*0Sstevel@tonic-gate state = 3; 316*0Sstevel@tonic-gate break; 317*0Sstevel@tonic-gate default: 318*0Sstevel@tonic-gate goto tabspecerr; 319*0Sstevel@tonic-gate } 320*0Sstevel@tonic-gate break; 321*0Sstevel@tonic-gate case 1: 322*0Sstevel@tonic-gate switch (type(c)) { 323*0Sstevel@tonic-gate case '\0': 324*0Sstevel@tonic-gate spectype = 11; 325*0Sstevel@tonic-gate state = -1; 326*0Sstevel@tonic-gate break; 327*0Sstevel@tonic-gate case NUMBER: 328*0Sstevel@tonic-gate state = 1; 329*0Sstevel@tonic-gate number[tp] = number[tp] * 10 + c - '0'; 330*0Sstevel@tonic-gate break; 331*0Sstevel@tonic-gate case ',': 332*0Sstevel@tonic-gate state = 2; 333*0Sstevel@tonic-gate break; 334*0Sstevel@tonic-gate default: 335*0Sstevel@tonic-gate goto tabspecerr; 336*0Sstevel@tonic-gate } 337*0Sstevel@tonic-gate break; 338*0Sstevel@tonic-gate case 2: 339*0Sstevel@tonic-gate if (type(c) == NUMBER) { 340*0Sstevel@tonic-gate state = 1; 341*0Sstevel@tonic-gate number[++tp] = c - '0'; 342*0Sstevel@tonic-gate } 343*0Sstevel@tonic-gate else 344*0Sstevel@tonic-gate goto tabspecerr; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate break; 347*0Sstevel@tonic-gate case 3: 348*0Sstevel@tonic-gate switch (type(c)) { 349*0Sstevel@tonic-gate case '-': 350*0Sstevel@tonic-gate state = 4; 351*0Sstevel@tonic-gate break; 352*0Sstevel@tonic-gate case 'a': 353*0Sstevel@tonic-gate state = 5; 354*0Sstevel@tonic-gate break; 355*0Sstevel@tonic-gate case 'c': 356*0Sstevel@tonic-gate state = 7; 357*0Sstevel@tonic-gate break; 358*0Sstevel@tonic-gate case 'f': 359*0Sstevel@tonic-gate state = 10; 360*0Sstevel@tonic-gate break; 361*0Sstevel@tonic-gate case 'p': 362*0Sstevel@tonic-gate state = 11; 363*0Sstevel@tonic-gate break; 364*0Sstevel@tonic-gate case 's': 365*0Sstevel@tonic-gate state = 12; 366*0Sstevel@tonic-gate break; 367*0Sstevel@tonic-gate case 'u': 368*0Sstevel@tonic-gate state = 13; 369*0Sstevel@tonic-gate break; 370*0Sstevel@tonic-gate case NUMBER: 371*0Sstevel@tonic-gate state = 14; 372*0Sstevel@tonic-gate number[0] = c - '0'; 373*0Sstevel@tonic-gate break; 374*0Sstevel@tonic-gate default: 375*0Sstevel@tonic-gate goto tabspecerr; 376*0Sstevel@tonic-gate } 377*0Sstevel@tonic-gate break; 378*0Sstevel@tonic-gate case 4: 379*0Sstevel@tonic-gate if (c == '\0') { 380*0Sstevel@tonic-gate spectype = 12; 381*0Sstevel@tonic-gate state = -1; 382*0Sstevel@tonic-gate } 383*0Sstevel@tonic-gate else { 384*0Sstevel@tonic-gate filep = --p; 385*0Sstevel@tonic-gate spectype = 13; 386*0Sstevel@tonic-gate state = -1; 387*0Sstevel@tonic-gate } 388*0Sstevel@tonic-gate break; 389*0Sstevel@tonic-gate case 5: 390*0Sstevel@tonic-gate if (c == '\0') { 391*0Sstevel@tonic-gate spectype = 1; 392*0Sstevel@tonic-gate state = -1; 393*0Sstevel@tonic-gate } 394*0Sstevel@tonic-gate else if (c == '2') 395*0Sstevel@tonic-gate state = 6; 396*0Sstevel@tonic-gate else 397*0Sstevel@tonic-gate goto tabspecerr; 398*0Sstevel@tonic-gate break; 399*0Sstevel@tonic-gate case 6: 400*0Sstevel@tonic-gate if (c == '\0') { 401*0Sstevel@tonic-gate spectype = 2; 402*0Sstevel@tonic-gate state = -1; 403*0Sstevel@tonic-gate } 404*0Sstevel@tonic-gate else 405*0Sstevel@tonic-gate goto tabspecerr; 406*0Sstevel@tonic-gate break; 407*0Sstevel@tonic-gate case 7: 408*0Sstevel@tonic-gate switch (c) { 409*0Sstevel@tonic-gate case '\0': 410*0Sstevel@tonic-gate spectype = 3; 411*0Sstevel@tonic-gate state = -1; 412*0Sstevel@tonic-gate break; 413*0Sstevel@tonic-gate case '2': 414*0Sstevel@tonic-gate state = 8; 415*0Sstevel@tonic-gate break; 416*0Sstevel@tonic-gate case '3': 417*0Sstevel@tonic-gate state = 9; 418*0Sstevel@tonic-gate break; 419*0Sstevel@tonic-gate default: 420*0Sstevel@tonic-gate goto tabspecerr; 421*0Sstevel@tonic-gate } 422*0Sstevel@tonic-gate break; 423*0Sstevel@tonic-gate case 8: 424*0Sstevel@tonic-gate if (c == '\0') { 425*0Sstevel@tonic-gate spectype = 4; 426*0Sstevel@tonic-gate state = -1; 427*0Sstevel@tonic-gate } 428*0Sstevel@tonic-gate else 429*0Sstevel@tonic-gate goto tabspecerr; 430*0Sstevel@tonic-gate break; 431*0Sstevel@tonic-gate case 9: 432*0Sstevel@tonic-gate if (c == '\0') { 433*0Sstevel@tonic-gate spectype = 5; 434*0Sstevel@tonic-gate state = -1; 435*0Sstevel@tonic-gate } 436*0Sstevel@tonic-gate else 437*0Sstevel@tonic-gate goto tabspecerr; 438*0Sstevel@tonic-gate break; 439*0Sstevel@tonic-gate case 10: 440*0Sstevel@tonic-gate if (c == '\0') { 441*0Sstevel@tonic-gate spectype = 6; 442*0Sstevel@tonic-gate state = -1; 443*0Sstevel@tonic-gate } 444*0Sstevel@tonic-gate else 445*0Sstevel@tonic-gate goto tabspecerr; 446*0Sstevel@tonic-gate break; 447*0Sstevel@tonic-gate case 11: 448*0Sstevel@tonic-gate if (c == '\0') { 449*0Sstevel@tonic-gate spectype = 7; 450*0Sstevel@tonic-gate state = -1; 451*0Sstevel@tonic-gate } 452*0Sstevel@tonic-gate else 453*0Sstevel@tonic-gate goto tabspecerr; 454*0Sstevel@tonic-gate break; 455*0Sstevel@tonic-gate case 12: 456*0Sstevel@tonic-gate if (c == '\0') { 457*0Sstevel@tonic-gate spectype = 8; 458*0Sstevel@tonic-gate state = -1; 459*0Sstevel@tonic-gate } 460*0Sstevel@tonic-gate else 461*0Sstevel@tonic-gate goto tabspecerr; 462*0Sstevel@tonic-gate break; 463*0Sstevel@tonic-gate case 13: 464*0Sstevel@tonic-gate if (c == '\0') { 465*0Sstevel@tonic-gate spectype = 9; 466*0Sstevel@tonic-gate state = -1; 467*0Sstevel@tonic-gate } 468*0Sstevel@tonic-gate else 469*0Sstevel@tonic-gate goto tabspecerr; 470*0Sstevel@tonic-gate break; 471*0Sstevel@tonic-gate case 14: 472*0Sstevel@tonic-gate if (type(c) == NUMBER) { 473*0Sstevel@tonic-gate state = 14; 474*0Sstevel@tonic-gate number[0] = number[0] * 10 + c - '0'; 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate else if (c == '\0') { 477*0Sstevel@tonic-gate spectype = 10; 478*0Sstevel@tonic-gate state = -1; 479*0Sstevel@tonic-gate } 480*0Sstevel@tonic-gate else 481*0Sstevel@tonic-gate goto tabspecerr; 482*0Sstevel@tonic-gate break; 483*0Sstevel@tonic-gate } 484*0Sstevel@tonic-gate } 485*0Sstevel@tonic-gate if (spectype <= 9) return(spectype); 486*0Sstevel@tonic-gate if (spectype == 10) { 487*0Sstevel@tonic-gate spectype = nextspec++; 488*0Sstevel@tonic-gate spectbl[spectype] = nexttab; 489*0Sstevel@tonic-gate *nexttab = 1; 490*0Sstevel@tonic-gate if(number[0] == 0)number[0] = 1; /* Prevent infinite loop. */ 491*0Sstevel@tonic-gate while (*nexttab < LINELEN) { 492*0Sstevel@tonic-gate *(nexttab + 1) = *nexttab; 493*0Sstevel@tonic-gate *++nexttab += number[0]; 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate *nexttab++ = '\0'; 496*0Sstevel@tonic-gate return(spectype); 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate if (spectype == 11) { 499*0Sstevel@tonic-gate spectype = nextspec++; 500*0Sstevel@tonic-gate spectbl[spectype] = nexttab; 501*0Sstevel@tonic-gate *nexttab++ = 1; 502*0Sstevel@tonic-gate for (ix = 0; ix <= tp; ix++) { 503*0Sstevel@tonic-gate *nexttab++ = number[ix]; 504*0Sstevel@tonic-gate if ((number[ix] >= number[ix+1]) && (ix != tp)) 505*0Sstevel@tonic-gate goto tabspecerr; 506*0Sstevel@tonic-gate } 507*0Sstevel@tonic-gate *nexttab++ = '\0'; 508*0Sstevel@tonic-gate return(spectype); 509*0Sstevel@tonic-gate } 510*0Sstevel@tonic-gate if (lock == 1) { 511*0Sstevel@tonic-gate fprintf(stderr,"newform: tabspec indirection illegal\n"); 512*0Sstevel@tonic-gate exit(1); 513*0Sstevel@tonic-gate } 514*0Sstevel@tonic-gate lock = 1; 515*0Sstevel@tonic-gate if (spectype == 12) { 516*0Sstevel@tonic-gate if (sitabspec >= 0) { 517*0Sstevel@tonic-gate tspec = sitabspec; 518*0Sstevel@tonic-gate } 519*0Sstevel@tonic-gate else { 520*0Sstevel@tonic-gate if ( (stptr=readline(stdin,siline)) != NULL){ 521*0Sstevel@tonic-gate kludge = 1; 522*0Sstevel@tonic-gate tspec = readspec(siline); 523*0Sstevel@tonic-gate sitabspec = tspec; 524*0Sstevel@tonic-gate } 525*0Sstevel@tonic-gate } 526*0Sstevel@tonic-gate } 527*0Sstevel@tonic-gate if (spectype == 13) { 528*0Sstevel@tonic-gate if ((fp = fopen(filep,"r")) == NULL) { 529*0Sstevel@tonic-gate fprintf(stderr,"newform: can't open %s\n", filep); 530*0Sstevel@tonic-gate exit(1); 531*0Sstevel@tonic-gate } 532*0Sstevel@tonic-gate readline(fp,work); 533*0Sstevel@tonic-gate fclose(fp); 534*0Sstevel@tonic-gate tspec = readspec(work); 535*0Sstevel@tonic-gate } 536*0Sstevel@tonic-gate lock = 0; 537*0Sstevel@tonic-gate return(tspec); 538*0Sstevel@tonic-gate tabspecerr: 539*0Sstevel@tonic-gate fprintf(stderr,"newform: tabspec in error\n"); 540*0Sstevel@tonic-gate fprintf(stderr,"tabspec is \t-a\t-a2\t-c\t-c2\t-c3\t-f\t-p\t-s\n"); 541*0Sstevel@tonic-gate fprintf(stderr,"\t\t-u\t--\t--file\t-number\tnumber,..,number\n"); 542*0Sstevel@tonic-gate exit(1); 543*0Sstevel@tonic-gate return(-1); /* Stops 'lint's complaint about return(e) VS return. */ 544*0Sstevel@tonic-gate } 545*0Sstevel@tonic-gate int readspec(p) /* Read a tabspec from a file */ 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate register char *p; /* Pointer to buffer to process */ 548*0Sstevel@tonic-gate { 549*0Sstevel@tonic-gate int state, /* Current state */ 550*0Sstevel@tonic-gate firsttime, /* Flag to indicate spec found */ 551*0Sstevel@tonic-gate value; /* Function value */ 552*0Sstevel@tonic-gate char c, /* Char being looked at */ 553*0Sstevel@tonic-gate *tabspecp, /* Pointer to spec string */ 554*0Sstevel@tonic-gate *restore = " ", /* Character to be restored */ 555*0Sstevel@tonic-gate repch; /* Character to replace with */ 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate state = 0; 558*0Sstevel@tonic-gate firsttime = 1; 559*0Sstevel@tonic-gate while (state >= 0) { 560*0Sstevel@tonic-gate c = *p++; 561*0Sstevel@tonic-gate switch (state) { 562*0Sstevel@tonic-gate case 0: 563*0Sstevel@tonic-gate state = (c == '<') ? 1 : 0; 564*0Sstevel@tonic-gate break; 565*0Sstevel@tonic-gate case 1: 566*0Sstevel@tonic-gate state = (c == ':') ? 2 : 0; 567*0Sstevel@tonic-gate break; 568*0Sstevel@tonic-gate case 2: 569*0Sstevel@tonic-gate state = (c == 't') ? 4 570*0Sstevel@tonic-gate : ((c == ' ') || (c == '\t')) ? 2 : 3; 571*0Sstevel@tonic-gate break; 572*0Sstevel@tonic-gate case 3: 573*0Sstevel@tonic-gate state = ((c == ' ') || (c == '\t')) ? 2 : 3; 574*0Sstevel@tonic-gate break; 575*0Sstevel@tonic-gate case 4: 576*0Sstevel@tonic-gate if (firsttime) { 577*0Sstevel@tonic-gate tabspecp = --p; 578*0Sstevel@tonic-gate p++; 579*0Sstevel@tonic-gate firsttime = 0; 580*0Sstevel@tonic-gate } 581*0Sstevel@tonic-gate if ((c == ' ') || (c == '\t') || (c == ':')) { 582*0Sstevel@tonic-gate repch = *(restore = p - 1); 583*0Sstevel@tonic-gate *restore = '\0'; 584*0Sstevel@tonic-gate } 585*0Sstevel@tonic-gate state = (c == ':') ? 6 586*0Sstevel@tonic-gate : ((c == ' ') || (c == '\t')) ? 5 : 4; 587*0Sstevel@tonic-gate break; 588*0Sstevel@tonic-gate case 5: 589*0Sstevel@tonic-gate state = (c == ':') ? 6 : 5; 590*0Sstevel@tonic-gate break; 591*0Sstevel@tonic-gate case 6: 592*0Sstevel@tonic-gate state = (c == '>') ? -2 : 5; 593*0Sstevel@tonic-gate break; 594*0Sstevel@tonic-gate } 595*0Sstevel@tonic-gate if (c == '\n') state = -1; 596*0Sstevel@tonic-gate } 597*0Sstevel@tonic-gate if (okludge) strcpy(format,tabspecp); 598*0Sstevel@tonic-gate value = (state == -1) ? 0 : cnvtspec(tabspecp); 599*0Sstevel@tonic-gate *restore = repch; 600*0Sstevel@tonic-gate return(value); 601*0Sstevel@tonic-gate } 602*0Sstevel@tonic-gate char *readline(fp,area) /* Read one line from the file. */ 603*0Sstevel@tonic-gate FILE *fp; /* File to read from */ 604*0Sstevel@tonic-gate char *area; /* Array of characters to read into */ 605*0Sstevel@tonic-gate { 606*0Sstevel@tonic-gate int c; /* Current character */ 607*0Sstevel@tonic-gate char *xarea, /* Temporary pointer to character array */ 608*0Sstevel@tonic-gate UNDEF = '\377', /* Undefined char for return */ 609*0Sstevel@tonic-gate *temp; /* Array pointer */ 610*0Sstevel@tonic-gate 611*0Sstevel@tonic-gate 612*0Sstevel@tonic-gate 613*0Sstevel@tonic-gate /* check for existence of stdin before attempting to read */ 614*0Sstevel@tonic-gate /* kludge refers to reading from stdin to get tabspecs for option -i-- */ 615*0Sstevel@tonic-gate 616*0Sstevel@tonic-gate xarea = area; 617*0Sstevel@tonic-gate if (kludge && (fp == stdin)) { 618*0Sstevel@tonic-gate if (fp != NULL) { 619*0Sstevel@tonic-gate temp = siline; 620*0Sstevel@tonic-gate while ((*area++ = *temp++) != '\n') ; 621*0Sstevel@tonic-gate kludge = 0; 622*0Sstevel@tonic-gate return(xarea); 623*0Sstevel@tonic-gate } 624*0Sstevel@tonic-gate else 625*0Sstevel@tonic-gate return(NULL); 626*0Sstevel@tonic-gate } 627*0Sstevel@tonic-gate else { 628*0Sstevel@tonic-gate 629*0Sstevel@tonic-gate /* check for exceeding size of buffer when reading valid input */ 630*0Sstevel@tonic-gate 631*0Sstevel@tonic-gate while ( wlast - area ) { 632*0Sstevel@tonic-gate switch(c = getc(fp)){ 633*0Sstevel@tonic-gate case EOF: 634*0Sstevel@tonic-gate if (area == xarea) 635*0Sstevel@tonic-gate return(NULL); 636*0Sstevel@tonic-gate case '\n': /*EOF falls through to here*/ 637*0Sstevel@tonic-gate *area = '\n'; 638*0Sstevel@tonic-gate return(xarea); 639*0Sstevel@tonic-gate } 640*0Sstevel@tonic-gate *area=c; 641*0Sstevel@tonic-gate *area++; 642*0Sstevel@tonic-gate } 643*0Sstevel@tonic-gate printf("newform: input line larger than buffer area \n"); 644*0Sstevel@tonic-gate exit(1); 645*0Sstevel@tonic-gate } 646*0Sstevel@tonic-gate return(&UNDEF); /* Stops 'lint's complaint about return(e) VS return. */ 647*0Sstevel@tonic-gate } 648*0Sstevel@tonic-gate /* _________________________________________________________________ */ 649*0Sstevel@tonic-gate 650*0Sstevel@tonic-gate char type(c) /* Determine type of a character */ 651*0Sstevel@tonic-gate char c; /* Character to check */ 652*0Sstevel@tonic-gate { 653*0Sstevel@tonic-gate return((c >= '0') && (c <= '9') ? NUMBER : c); 654*0Sstevel@tonic-gate } 655*0Sstevel@tonic-gate process(fp) /* Process one line of input */ 656*0Sstevel@tonic-gate FILE *fp; /* File pointer for current input */ 657*0Sstevel@tonic-gate { 658*0Sstevel@tonic-gate struct f *lp; /* Pointer to structs */ 659*0Sstevel@tonic-gate char *readline(); /* Function */ 660*0Sstevel@tonic-gate char chrnow; /* For int to char conversion. */ 661*0Sstevel@tonic-gate 662*0Sstevel@tonic-gate while (readline(fp,&work[NCOLS]) != NULL) { 663*0Sstevel@tonic-gate effll = 80; 664*0Sstevel@tonic-gate pachar = ' '; 665*0Sstevel@tonic-gate pfirst = plast = &work[NCOLS]; 666*0Sstevel@tonic-gate while (*plast != '\n') plast++; 667*0Sstevel@tonic-gate 668*0Sstevel@tonic-gate /* changes to line parsing includes checks for exceeding */ 669*0Sstevel@tonic-gate /* line size when modifying text */ 670*0Sstevel@tonic-gate 671*0Sstevel@tonic-gate for (lp = optl ; lp < flp ; lp++) { 672*0Sstevel@tonic-gate switch (lp->option) { 673*0Sstevel@tonic-gate case 'a': 674*0Sstevel@tonic-gate append(lp->param); 675*0Sstevel@tonic-gate break; 676*0Sstevel@tonic-gate case 'b': 677*0Sstevel@tonic-gate if (lp->param <= (plast - pfirst)) 678*0Sstevel@tonic-gate begtrunc(lp->param); 679*0Sstevel@tonic-gate else 680*0Sstevel@tonic-gate fprintf(stderr,"newform: truncate request larger than line, %d \n", (plast - pfirst)); 681*0Sstevel@tonic-gate break; 682*0Sstevel@tonic-gate case 'c': 683*0Sstevel@tonic-gate chrnow = lp->param; 684*0Sstevel@tonic-gate pachar = chrnow ? chrnow : ' '; 685*0Sstevel@tonic-gate break; 686*0Sstevel@tonic-gate case 'e': 687*0Sstevel@tonic-gate if (lp->param <= (plast - pfirst)) 688*0Sstevel@tonic-gate endtrunc(lp->param); 689*0Sstevel@tonic-gate else 690*0Sstevel@tonic-gate fprintf(stderr,"newform: truncate request larger than line, %d \n", (plast - pfirst)); 691*0Sstevel@tonic-gate break; 692*0Sstevel@tonic-gate case 'f': 693*0Sstevel@tonic-gate /* Ignored */ 694*0Sstevel@tonic-gate break; 695*0Sstevel@tonic-gate case 'i': 696*0Sstevel@tonic-gate inputtabs(lp->param); 697*0Sstevel@tonic-gate break; 698*0Sstevel@tonic-gate case 'l': /* New eff line length */ 699*0Sstevel@tonic-gate effll = lp->param ? lp->param : 72; 700*0Sstevel@tonic-gate break; 701*0Sstevel@tonic-gate case 's': 702*0Sstevel@tonic-gate sstrip(); 703*0Sstevel@tonic-gate break; 704*0Sstevel@tonic-gate case 'o': 705*0Sstevel@tonic-gate outputtabs(lp->param); 706*0Sstevel@tonic-gate break; 707*0Sstevel@tonic-gate case 'p': 708*0Sstevel@tonic-gate prepend(lp->param); 709*0Sstevel@tonic-gate break; 710*0Sstevel@tonic-gate } 711*0Sstevel@tonic-gate } 712*0Sstevel@tonic-gate if(soption)sadd(); 713*0Sstevel@tonic-gate *++plast = '\0'; 714*0Sstevel@tonic-gate fputs(pfirst,stdout); 715*0Sstevel@tonic-gate } 716*0Sstevel@tonic-gate } 717*0Sstevel@tonic-gate append(n) /* Append characters to end of line. */ 718*0Sstevel@tonic-gate int n; /* Number of characters to append. */ 719*0Sstevel@tonic-gate { 720*0Sstevel@tonic-gate if (plast - pfirst < effll) { 721*0Sstevel@tonic-gate n = n ? n : effll - (plast - pfirst); 722*0Sstevel@tonic-gate if (plast + n > wlast) center(); 723*0Sstevel@tonic-gate while (n--) *plast++ = pachar; 724*0Sstevel@tonic-gate *plast = '\n'; 725*0Sstevel@tonic-gate } 726*0Sstevel@tonic-gate } 727*0Sstevel@tonic-gate /* _________________________________________________________________ */ 728*0Sstevel@tonic-gate 729*0Sstevel@tonic-gate prepend(n) /* Prepend characters to line. */ 730*0Sstevel@tonic-gate int n; /* Number of characters to prepend. */ 731*0Sstevel@tonic-gate { 732*0Sstevel@tonic-gate if (plast - pfirst < effll) { 733*0Sstevel@tonic-gate n = n ? n : effll - (plast - pfirst); 734*0Sstevel@tonic-gate if (pfirst - n < wfirst) center(); 735*0Sstevel@tonic-gate while (n--) *--pfirst = pachar; 736*0Sstevel@tonic-gate } 737*0Sstevel@tonic-gate } 738*0Sstevel@tonic-gate /* _________________________________________________________________ */ 739*0Sstevel@tonic-gate 740*0Sstevel@tonic-gate begtrunc(n) /* Truncate characters from beginning of line. */ 741*0Sstevel@tonic-gate int n; /* Number of characters to truncate. */ 742*0Sstevel@tonic-gate { 743*0Sstevel@tonic-gate if (plast - pfirst > effll) { 744*0Sstevel@tonic-gate n = n ? n : plast - pfirst - effll; 745*0Sstevel@tonic-gate pfirst += n; 746*0Sstevel@tonic-gate if (pfirst >= plast) 747*0Sstevel@tonic-gate *(pfirst = plast = &work[NCOLS]) = '\n'; 748*0Sstevel@tonic-gate } 749*0Sstevel@tonic-gate } 750*0Sstevel@tonic-gate /* _________________________________________________________________ */ 751*0Sstevel@tonic-gate 752*0Sstevel@tonic-gate endtrunc(n) /* Truncate characters from end of line.*/ 753*0Sstevel@tonic-gate int n; /* Number of characters to truncate. */ 754*0Sstevel@tonic-gate { 755*0Sstevel@tonic-gate if (plast - pfirst > effll) { 756*0Sstevel@tonic-gate n = n ? n : plast - pfirst - effll; 757*0Sstevel@tonic-gate plast -= n; 758*0Sstevel@tonic-gate if (pfirst >= plast) 759*0Sstevel@tonic-gate *(pfirst = plast = &work[NCOLS]) = '\n'; 760*0Sstevel@tonic-gate else 761*0Sstevel@tonic-gate *plast = '\n'; 762*0Sstevel@tonic-gate } 763*0Sstevel@tonic-gate } 764*0Sstevel@tonic-gate inputtabs(p) /* Expand according to input tab specifications.*/ 765*0Sstevel@tonic-gate int p; /* Pointer to tab specification. */ 766*0Sstevel@tonic-gate { 767*0Sstevel@tonic-gate int *tabs; /* Pointer to tabs */ 768*0Sstevel@tonic-gate char *tfirst, /* Pointer to new buffer start */ 769*0Sstevel@tonic-gate *tlast; /* Pointer to new buffer end */ 770*0Sstevel@tonic-gate register char c; /* Character being scanned */ 771*0Sstevel@tonic-gate int logcol; /* Logical column */ 772*0Sstevel@tonic-gate 773*0Sstevel@tonic-gate tabs = spectbl[p]; 774*0Sstevel@tonic-gate tfirst = tlast = work; 775*0Sstevel@tonic-gate logcol = 1; 776*0Sstevel@tonic-gate center(); 777*0Sstevel@tonic-gate while (pfirst <= plast) { 778*0Sstevel@tonic-gate if (logcol >= *tabs) tabs++; 779*0Sstevel@tonic-gate switch (c = *pfirst++) { 780*0Sstevel@tonic-gate case '\b': 781*0Sstevel@tonic-gate if (logcol > 1) logcol--; 782*0Sstevel@tonic-gate *tlast++ = c; 783*0Sstevel@tonic-gate if (logcol < *tabs) tabs--; 784*0Sstevel@tonic-gate break; 785*0Sstevel@tonic-gate case '\t': 786*0Sstevel@tonic-gate while (logcol < *tabs) { 787*0Sstevel@tonic-gate *tlast++ = ' '; 788*0Sstevel@tonic-gate logcol++; 789*0Sstevel@tonic-gate } 790*0Sstevel@tonic-gate tabs++; 791*0Sstevel@tonic-gate break; 792*0Sstevel@tonic-gate default: 793*0Sstevel@tonic-gate *tlast++ = c; 794*0Sstevel@tonic-gate logcol++; 795*0Sstevel@tonic-gate break; 796*0Sstevel@tonic-gate } 797*0Sstevel@tonic-gate } 798*0Sstevel@tonic-gate pfirst = tfirst; 799*0Sstevel@tonic-gate plast = --tlast; 800*0Sstevel@tonic-gate } 801*0Sstevel@tonic-gate /* Add SCCS SID (generated by a "get -m" command) to the end of each line. 802*0Sstevel@tonic-gate Sequence is as follows for EACH line: 803*0Sstevel@tonic-gate Check for at least 1 tab. Err if none. 804*0Sstevel@tonic-gate Strip off all char up to & including first tab. 805*0Sstevel@tonic-gate If more than 8 char were stripped, the 8 th is replaced by 806*0Sstevel@tonic-gate a '*' & the remainder are discarded. 807*0Sstevel@tonic-gate Unless user specified an "a", append blanks to fill 808*0Sstevel@tonic-gate out line to eff. line length (default= 72 char). 809*0Sstevel@tonic-gate Truncate lines > eff. line length (default=72). 810*0Sstevel@tonic-gate Add stripped char to end of line. */ 811*0Sstevel@tonic-gate sstrip() 812*0Sstevel@tonic-gate { 813*0Sstevel@tonic-gate register int i, k; 814*0Sstevel@tonic-gate char *c,*savec; 815*0Sstevel@tonic-gate 816*0Sstevel@tonic-gate k = -1; 817*0Sstevel@tonic-gate c = pfirst; 818*0Sstevel@tonic-gate while(*c != '\t' && *c != '\n'){k++; c++;} 819*0Sstevel@tonic-gate if(*c != '\t'){fprintf(stderr,"not -s format\r\n"); exit(1);} 820*0Sstevel@tonic-gate 821*0Sstevel@tonic-gate savec = c; 822*0Sstevel@tonic-gate c = pfirst; 823*0Sstevel@tonic-gate savek = (k > 7) ? 7 : k; 824*0Sstevel@tonic-gate for(i=0; i <= savek; i++)savchr[i] = *c++; /* Tab not saved */ 825*0Sstevel@tonic-gate if(k > 7)savchr[7] = '*'; 826*0Sstevel@tonic-gate 827*0Sstevel@tonic-gate pfirst = ++savec; /* Point pfirst to char after tab */ 828*0Sstevel@tonic-gate } 829*0Sstevel@tonic-gate /* ================================================================= */ 830*0Sstevel@tonic-gate 831*0Sstevel@tonic-gate sadd() 832*0Sstevel@tonic-gate { 833*0Sstevel@tonic-gate register int i; 834*0Sstevel@tonic-gate 835*0Sstevel@tonic-gate for(i=0; i <= savek; i++)*plast++ = savchr[i]; 836*0Sstevel@tonic-gate *plast = '\n'; 837*0Sstevel@tonic-gate } 838*0Sstevel@tonic-gate outputtabs(p) /* Contract according to output tab specifications. */ 839*0Sstevel@tonic-gate int p; /* Pointer to tab specification. */ 840*0Sstevel@tonic-gate { 841*0Sstevel@tonic-gate int *tabs; /* Pointer to tabs */ 842*0Sstevel@tonic-gate char *tfirst, /* Pointer to new buffer start */ 843*0Sstevel@tonic-gate *tlast, /* Pointer to new buffer end */ 844*0Sstevel@tonic-gate *mark; /* Marker pointer */ 845*0Sstevel@tonic-gate register char c; /* Character being scanned */ 846*0Sstevel@tonic-gate int logcol; /* Logical column */ 847*0Sstevel@tonic-gate 848*0Sstevel@tonic-gate tabs = spectbl[p]; 849*0Sstevel@tonic-gate tfirst = tlast = pfirst; 850*0Sstevel@tonic-gate logcol = 1; 851*0Sstevel@tonic-gate while (pfirst <= plast) { 852*0Sstevel@tonic-gate if (logcol == *tabs) tabs++; 853*0Sstevel@tonic-gate switch (c = *pfirst++) { 854*0Sstevel@tonic-gate case '\b': 855*0Sstevel@tonic-gate if (logcol > 1) logcol--; 856*0Sstevel@tonic-gate *tlast++ = c; 857*0Sstevel@tonic-gate if (logcol < *tabs) tabs--; 858*0Sstevel@tonic-gate break; 859*0Sstevel@tonic-gate case ' ': 860*0Sstevel@tonic-gate mark = tlast; 861*0Sstevel@tonic-gate do { 862*0Sstevel@tonic-gate *tlast++ = ' '; 863*0Sstevel@tonic-gate logcol++; 864*0Sstevel@tonic-gate if (logcol == *tabs) { 865*0Sstevel@tonic-gate *mark++ = '\t'; 866*0Sstevel@tonic-gate tlast = mark; 867*0Sstevel@tonic-gate tabs++; 868*0Sstevel@tonic-gate } 869*0Sstevel@tonic-gate } while (*pfirst++ == ' '); 870*0Sstevel@tonic-gate pfirst--; 871*0Sstevel@tonic-gate break; 872*0Sstevel@tonic-gate default: 873*0Sstevel@tonic-gate logcol++; 874*0Sstevel@tonic-gate *tlast++ = c; 875*0Sstevel@tonic-gate break; 876*0Sstevel@tonic-gate } 877*0Sstevel@tonic-gate } 878*0Sstevel@tonic-gate pfirst = tfirst; 879*0Sstevel@tonic-gate plast = --tlast; 880*0Sstevel@tonic-gate } 881