17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22*779fc935Sceastha /* 23*779fc935Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*779fc935Sceastha * Use is subject to license terms. 25*779fc935Sceastha */ 26*779fc935Sceastha 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 30*779fc935Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 32*779fc935Sceastha /* 33*779fc935Sceastha * FUNCTION PAGE INDEX 34*779fc935Sceastha * Function Page Description 35*779fc935Sceastha * append 16 Append chars to end of line. 36*779fc935Sceastha * begtrunc 16 Truncate characters from beginning of line. 37*779fc935Sceastha * center 5 Center text in the work area. 38*779fc935Sceastha * cnvtspec 7 Convert tab spec to tab positions. 39*779fc935Sceastha * endtrunc 16 Truncate chars from end of line. 40*779fc935Sceastha * inputtabs 17 Expand according to input tab specs. 41*779fc935Sceastha * main 3 MAIN 42*779fc935Sceastha * inputn 5 Read a command line option number. 43*779fc935Sceastha * options 4 Process command line options. 44*779fc935Sceastha * outputtabs 19 Contract according to output tab specs. 45*779fc935Sceastha * prepend 16 Prepend chars to line. 46*779fc935Sceastha * process 15 Process one line of input. 47*779fc935Sceastha * readline 14 Read one line from the file. 48*779fc935Sceastha * readspec 12 Read a tabspec from a file. 49*779fc935Sceastha * sstrip 18 Strip SCCS SID char from beginning of line. 50*779fc935Sceastha * sadd 18 Add SCCS SID chars to end of line. 51*779fc935Sceastha * type 14 Determine type of a character. 52*779fc935Sceastha */ 537c478bd9Sstevel@tonic-gate 54*779fc935Sceastha #include <stdlib.h> 55*779fc935Sceastha #include <string.h> 567c478bd9Sstevel@tonic-gate #include <stdio.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #define MAXOPTS 50 597c478bd9Sstevel@tonic-gate #define NCOLS 512 607c478bd9Sstevel@tonic-gate #define MAXLINE 512 617c478bd9Sstevel@tonic-gate #define NUMBER '0' 627c478bd9Sstevel@tonic-gate #define LINELEN 80 637c478bd9Sstevel@tonic-gate 64*779fc935Sceastha static int tabtbl[500] = { /* Table containing tab stops */ 657c478bd9Sstevel@tonic-gate 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 0, 667c478bd9Sstevel@tonic-gate /* Default tabs */ 677c478bd9Sstevel@tonic-gate 1, 10, 16, 36, 72, 0, /* IBM 370 Assembler */ 687c478bd9Sstevel@tonic-gate 1, 10, 16, 40, 72, 0, /* IBM 370 Assembler (alt.) */ 697c478bd9Sstevel@tonic-gate 1, 8, 12, 16, 20, 55, 0, /* COBOL */ 707c478bd9Sstevel@tonic-gate 1, 6, 10, 14, 49, 0, /* COBOL (crunched) */ 717c478bd9Sstevel@tonic-gate 1, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 67, 0, 727c478bd9Sstevel@tonic-gate /* COBOL (crunched, many cols.) */ 737c478bd9Sstevel@tonic-gate 1, 7, 11, 15, 19, 23, 0, /* FORTRAN */ 747c478bd9Sstevel@tonic-gate 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 0, 757c478bd9Sstevel@tonic-gate /* PL/1 */ 767c478bd9Sstevel@tonic-gate 1, 10, 55, 0, /* SNOBOL */ 777c478bd9Sstevel@tonic-gate 1, 12, 20, 44, 0 }, /* UNIVAC Assembler */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate *nexttab = &tabtbl[87], /* Pointer to next empty slot */ 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate *spectbl[40] = { /* Table of pointers into tabtbl */ 827c478bd9Sstevel@tonic-gate &tabtbl[0], /* Default specification */ 837c478bd9Sstevel@tonic-gate &tabtbl[11], /* -a specification */ 847c478bd9Sstevel@tonic-gate &tabtbl[17], /* -a2 specification */ 857c478bd9Sstevel@tonic-gate &tabtbl[23], /* -c specification */ 867c478bd9Sstevel@tonic-gate &tabtbl[30], /* -c2 specification */ 877c478bd9Sstevel@tonic-gate &tabtbl[36], /* -c3 specification */ 887c478bd9Sstevel@tonic-gate &tabtbl[54], /* -f specification */ 897c478bd9Sstevel@tonic-gate &tabtbl[61], /* -p specification */ 907c478bd9Sstevel@tonic-gate &tabtbl[78], /* -s specification */ 917c478bd9Sstevel@tonic-gate &tabtbl[82] }, /* -u specification */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate savek; /* Stores char count stripped from front of line. */ 94*779fc935Sceastha static int nextspec = 10, /* Index to next slot */ 957c478bd9Sstevel@tonic-gate sitabspec = -1, /* Index to "standard input" spec. */ 967c478bd9Sstevel@tonic-gate effll = 80, /* Effective line length */ 977c478bd9Sstevel@tonic-gate optionf = 0, /* 'f' option set */ 987c478bd9Sstevel@tonic-gate soption = 0, /* 's' option used. */ 997c478bd9Sstevel@tonic-gate files = 0, /* Number of input files */ 1007c478bd9Sstevel@tonic-gate kludge = 0, /* Kludge to allow reread of 1st line */ 1017c478bd9Sstevel@tonic-gate okludge = 0, /* Kludge to indicate reading "o" option */ 1027c478bd9Sstevel@tonic-gate lock = 0; /* Lock to prevent file indirection */ 1037c478bd9Sstevel@tonic-gate 104*779fc935Sceastha static char pachar = ' ', /* Prepend/append character */ 1057c478bd9Sstevel@tonic-gate work[3*NCOLS+1], /* Work area */ 1067c478bd9Sstevel@tonic-gate *pfirst, /* Pointer to beginning of line */ 1077c478bd9Sstevel@tonic-gate *plast, /* Pointer to end of line */ 1087c478bd9Sstevel@tonic-gate *wfirst = &work[0], /* Pointer to beginning of work area */ 1097c478bd9Sstevel@tonic-gate *wlast = &work[3*NCOLS], /* Pointer to end of work area */ 1107c478bd9Sstevel@tonic-gate siline[NCOLS], /* First standard input line */ 1117c478bd9Sstevel@tonic-gate savchr[8], /* Holds char stripped from line start */ 112*779fc935Sceastha format[80] = "-8"; /* Array to hold format line */ 1137c478bd9Sstevel@tonic-gate 114*779fc935Sceastha static struct f { 1157c478bd9Sstevel@tonic-gate char option; 1167c478bd9Sstevel@tonic-gate int param; 1177c478bd9Sstevel@tonic-gate } optl[MAXOPTS], /* List of command line options */ 1187c478bd9Sstevel@tonic-gate *flp = optl; /* Pointer to next open slot */ 119*779fc935Sceastha 120*779fc935Sceastha static void append(int); 121*779fc935Sceastha static void begtrunc(int); 122*779fc935Sceastha static void center(void); 123*779fc935Sceastha static int cnvtspec(char *); 124*779fc935Sceastha static void endtrunc(int); 125*779fc935Sceastha static int inputn(char *); 126*779fc935Sceastha static void inputtabs(int); 127*779fc935Sceastha static void options(int, char **); 128*779fc935Sceastha static void outputtabs(int); 129*779fc935Sceastha static void prepend(int); 130*779fc935Sceastha static void process(FILE *); 131*779fc935Sceastha static char *readline(FILE *, char *); 132*779fc935Sceastha static int readspec(char *); 133*779fc935Sceastha static void sadd(void); 134*779fc935Sceastha static void sstrip(void); 135*779fc935Sceastha static char type(char); 136*779fc935Sceastha 137*779fc935Sceastha int 138*779fc935Sceastha main(int argc, char **argv) 1397c478bd9Sstevel@tonic-gate { 1407c478bd9Sstevel@tonic-gate char *scan; /* String scan pointer */ 1417c478bd9Sstevel@tonic-gate FILE *fp; /* Pointer to current file */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate options(argc, argv); 144*779fc935Sceastha if (optionf) { /* Write tab spec format line. */ 145*779fc935Sceastha (void) fputs("<:t", stdout); 146*779fc935Sceastha (void) fputs(format, stdout); 147*779fc935Sceastha (void) fputs(" d:>\n", stdout); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate if (files) { 1507c478bd9Sstevel@tonic-gate while (--argc) { 1517c478bd9Sstevel@tonic-gate scan = *++argv; 1527c478bd9Sstevel@tonic-gate if (*scan != '-') { 1537c478bd9Sstevel@tonic-gate if ((fp = fopen(scan, "r")) == NULL) { 154*779fc935Sceastha (void) fprintf(stderr, 1557c478bd9Sstevel@tonic-gate "newform: can't open %s\n", scan); 1567c478bd9Sstevel@tonic-gate exit(1); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate process(fp); 159*779fc935Sceastha (void) fclose(fp); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } 162*779fc935Sceastha } else { 1637c478bd9Sstevel@tonic-gate process(stdin); 1647c478bd9Sstevel@tonic-gate } 165*779fc935Sceastha return (0); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate 169*779fc935Sceastha static void 170*779fc935Sceastha options(int argc, char **argv) /* Process command line options */ 1717c478bd9Sstevel@tonic-gate { 1727c478bd9Sstevel@tonic-gate int n; /* Temporary number holder */ 173*779fc935Sceastha char *scan; /* Pointer to individual option strings */ 174*779fc935Sceastha char c; /* Option character */ 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* changes to option parsing includes checks for exceeding */ 1777c478bd9Sstevel@tonic-gate /* initial buffer sizes */ 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate while (--argc > 0) { 1807c478bd9Sstevel@tonic-gate scan = *++argv; 1817c478bd9Sstevel@tonic-gate if (*scan++ == '-') { 1827c478bd9Sstevel@tonic-gate switch (c = *scan++) { 1837c478bd9Sstevel@tonic-gate case 'a': 1847c478bd9Sstevel@tonic-gate flp->option = 'a'; 1857c478bd9Sstevel@tonic-gate flp->param = inputn(scan); 1867c478bd9Sstevel@tonic-gate if (flp->param <= NCOLS) 1877c478bd9Sstevel@tonic-gate flp++; 1887c478bd9Sstevel@tonic-gate else { 189*779fc935Sceastha (void) fprintf(stderr, "newform: " 190*779fc935Sceastha "prefix request larger than " 191*779fc935Sceastha "buffer, %d\n", NCOLS); 1927c478bd9Sstevel@tonic-gate exit(1); 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate break; 1957c478bd9Sstevel@tonic-gate case 'b': 1967c478bd9Sstevel@tonic-gate case 'e': 1977c478bd9Sstevel@tonic-gate flp->option = c; 1987c478bd9Sstevel@tonic-gate flp->param = inputn(scan); 1997c478bd9Sstevel@tonic-gate flp++; 2007c478bd9Sstevel@tonic-gate break; 2017c478bd9Sstevel@tonic-gate case 'p': 2027c478bd9Sstevel@tonic-gate flp->option = 'p'; 2037c478bd9Sstevel@tonic-gate flp->param = inputn(scan); 2047c478bd9Sstevel@tonic-gate if (flp->param <= NCOLS) 2057c478bd9Sstevel@tonic-gate flp++; 2067c478bd9Sstevel@tonic-gate else { 207*779fc935Sceastha (void) fprintf(stderr, "newform: " 208*779fc935Sceastha "prefix request larger than " 209*779fc935Sceastha "buffer, %d\n", NCOLS); 2107c478bd9Sstevel@tonic-gate exit(1); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate break; 2137c478bd9Sstevel@tonic-gate case 'c': 2147c478bd9Sstevel@tonic-gate flp->option = 'c'; 2157c478bd9Sstevel@tonic-gate flp->param = *scan ? *scan : ' '; 2167c478bd9Sstevel@tonic-gate flp++; 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate case 'f': 2197c478bd9Sstevel@tonic-gate flp->option = 'f'; 2207c478bd9Sstevel@tonic-gate optionf++; 2217c478bd9Sstevel@tonic-gate flp++; 2227c478bd9Sstevel@tonic-gate break; 2237c478bd9Sstevel@tonic-gate case 'i': 2247c478bd9Sstevel@tonic-gate flp->option = 'i'; 2257c478bd9Sstevel@tonic-gate flp->param = cnvtspec(scan); 2267c478bd9Sstevel@tonic-gate flp++; 2277c478bd9Sstevel@tonic-gate break; 2287c478bd9Sstevel@tonic-gate case 'o': 229*779fc935Sceastha if (*scan == '-' && *(scan+1) == '0' && 230*779fc935Sceastha *(scan+2) == '\0') 231*779fc935Sceastha break; 2327c478bd9Sstevel@tonic-gate /* Above allows the -o-0 option to be ignored. */ 2337c478bd9Sstevel@tonic-gate flp->option = 'o'; 234*779fc935Sceastha (void) strcpy(format, scan); 2357c478bd9Sstevel@tonic-gate okludge++; 2367c478bd9Sstevel@tonic-gate flp->param = cnvtspec(scan); 2377c478bd9Sstevel@tonic-gate okludge--; 238*779fc935Sceastha if (flp->param == 0) 239*779fc935Sceastha (void) strcpy(format, "-8"); 2407c478bd9Sstevel@tonic-gate flp++; 2417c478bd9Sstevel@tonic-gate break; 2427c478bd9Sstevel@tonic-gate case 'l': 2437c478bd9Sstevel@tonic-gate flp->option = 'l'; 2447c478bd9Sstevel@tonic-gate flp->param = ((n = inputn(scan)) ? n : 72); 2457c478bd9Sstevel@tonic-gate if (flp->param <= (3*NCOLS)) 2467c478bd9Sstevel@tonic-gate flp++; 2477c478bd9Sstevel@tonic-gate else { 248*779fc935Sceastha (void) fprintf(stderr, "newform: " 249*779fc935Sceastha "line length request larger " 250*779fc935Sceastha "than buffer, %d \n", (3*NCOLS)); 2517c478bd9Sstevel@tonic-gate exit(1); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate break; 2547c478bd9Sstevel@tonic-gate case 's': 2557c478bd9Sstevel@tonic-gate flp->option = 's'; 2567c478bd9Sstevel@tonic-gate flp++; 2577c478bd9Sstevel@tonic-gate soption++; 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate default: 2607c478bd9Sstevel@tonic-gate goto usageerr; 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate else 2647c478bd9Sstevel@tonic-gate files++; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate return; 2677c478bd9Sstevel@tonic-gate usageerr: 268*779fc935Sceastha (void) fprintf(stderr, "usage: newform [-s] [-itabspec] [-otabspec] "); 269*779fc935Sceastha (void) fprintf(stderr, "[-pn] [-en] [-an] [-f] [-cchar]\n\t\t"); 270*779fc935Sceastha (void) fprintf(stderr, "[-ln] [-bn] [file ...]\n"); 2717c478bd9Sstevel@tonic-gate exit(1); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 2747c478bd9Sstevel@tonic-gate 275*779fc935Sceastha static int 276*779fc935Sceastha inputn(char *scan) /* Read a command option number */ 277*779fc935Sceastha /* Pointer to string of digits */ 2787c478bd9Sstevel@tonic-gate { 2797c478bd9Sstevel@tonic-gate int n; /* Number */ 2807c478bd9Sstevel@tonic-gate char c; /* Character being scanned */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate n = 0; 2837c478bd9Sstevel@tonic-gate while ((c = *scan++) >= '0' && c <= '9') 2847c478bd9Sstevel@tonic-gate n = n * 10 + c - '0'; 2857c478bd9Sstevel@tonic-gate return (n); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 2887c478bd9Sstevel@tonic-gate 289*779fc935Sceastha static void 290*779fc935Sceastha center(void) /* Center the text in the work area. */ 2917c478bd9Sstevel@tonic-gate { 292*779fc935Sceastha char *tfirst; /* Pointer for moving buffer down */ 293*779fc935Sceastha char *tlast; /* Pointer for moving buffer up */ 294*779fc935Sceastha char *tptr; /* Temporary */ 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate if (plast - pfirst > MAXLINE) { 297*779fc935Sceastha (void) fprintf(stderr, "newform: internal line too long\n"); 2987c478bd9Sstevel@tonic-gate exit(1); 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate if (pfirst < &work[NCOLS]) { 3017c478bd9Sstevel@tonic-gate tlast = plast + (&work[NCOLS] - pfirst); 3027c478bd9Sstevel@tonic-gate tptr = tlast; 3037c478bd9Sstevel@tonic-gate while (plast >= pfirst) *tlast-- = *plast--; 3047c478bd9Sstevel@tonic-gate pfirst = ++tlast; 3057c478bd9Sstevel@tonic-gate plast = tptr; 306*779fc935Sceastha } else { 3077c478bd9Sstevel@tonic-gate tfirst = &work[NCOLS]; 3087c478bd9Sstevel@tonic-gate tptr = tfirst; 3097c478bd9Sstevel@tonic-gate while (pfirst <= plast) *tfirst++ = *pfirst++; 3107c478bd9Sstevel@tonic-gate plast = --tfirst; 3117c478bd9Sstevel@tonic-gate pfirst = tptr; 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate } 314*779fc935Sceastha 315*779fc935Sceastha static int 316*779fc935Sceastha cnvtspec(char *p) /* Convert tab specification to tab positions. */ 317*779fc935Sceastha /* Pointer to spec string. */ 3187c478bd9Sstevel@tonic-gate { 3197c478bd9Sstevel@tonic-gate int state, /* DFA state */ 3207c478bd9Sstevel@tonic-gate spectype, /* Specification type */ 3217c478bd9Sstevel@tonic-gate number[40], /* Array of read-in numbers */ 3227c478bd9Sstevel@tonic-gate tp, /* Pointer to last number */ 3237c478bd9Sstevel@tonic-gate ix; /* Temporary */ 3247c478bd9Sstevel@tonic-gate int tspec = 0; /* Tab spec pointer */ 3257c478bd9Sstevel@tonic-gate char c, /* Temporary */ 326*779fc935Sceastha *filep; /* Pointer to file name */ 327*779fc935Sceastha FILE *fp; /* File pointer */ 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate state = 0; 3307c478bd9Sstevel@tonic-gate while (state >= 0) { 3317c478bd9Sstevel@tonic-gate c = *p++; 3327c478bd9Sstevel@tonic-gate switch (state) { 3337c478bd9Sstevel@tonic-gate case 0: 3347c478bd9Sstevel@tonic-gate switch (type(c)) { 3357c478bd9Sstevel@tonic-gate case '\0': 3367c478bd9Sstevel@tonic-gate spectype = 0; 3377c478bd9Sstevel@tonic-gate state = -1; 3387c478bd9Sstevel@tonic-gate break; 3397c478bd9Sstevel@tonic-gate case NUMBER: 3407c478bd9Sstevel@tonic-gate state = 1; 3417c478bd9Sstevel@tonic-gate tp = 0; 3427c478bd9Sstevel@tonic-gate number[tp] = c - '0'; 3437c478bd9Sstevel@tonic-gate break; 3447c478bd9Sstevel@tonic-gate case '-': 3457c478bd9Sstevel@tonic-gate state = 3; 3467c478bd9Sstevel@tonic-gate break; 3477c478bd9Sstevel@tonic-gate default: 3487c478bd9Sstevel@tonic-gate goto tabspecerr; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate break; 3517c478bd9Sstevel@tonic-gate case 1: 3527c478bd9Sstevel@tonic-gate switch (type(c)) { 3537c478bd9Sstevel@tonic-gate case '\0': 3547c478bd9Sstevel@tonic-gate spectype = 11; 3557c478bd9Sstevel@tonic-gate state = -1; 3567c478bd9Sstevel@tonic-gate break; 3577c478bd9Sstevel@tonic-gate case NUMBER: 3587c478bd9Sstevel@tonic-gate state = 1; 3597c478bd9Sstevel@tonic-gate number[tp] = number[tp] * 10 + c - '0'; 3607c478bd9Sstevel@tonic-gate break; 3617c478bd9Sstevel@tonic-gate case ',': 3627c478bd9Sstevel@tonic-gate state = 2; 3637c478bd9Sstevel@tonic-gate break; 3647c478bd9Sstevel@tonic-gate default: 3657c478bd9Sstevel@tonic-gate goto tabspecerr; 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate break; 3687c478bd9Sstevel@tonic-gate case 2: 3697c478bd9Sstevel@tonic-gate if (type(c) == NUMBER) { 3707c478bd9Sstevel@tonic-gate state = 1; 3717c478bd9Sstevel@tonic-gate number[++tp] = c - '0'; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate else 3747c478bd9Sstevel@tonic-gate goto tabspecerr; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate break; 3777c478bd9Sstevel@tonic-gate case 3: 3787c478bd9Sstevel@tonic-gate switch (type(c)) { 3797c478bd9Sstevel@tonic-gate case '-': 3807c478bd9Sstevel@tonic-gate state = 4; 3817c478bd9Sstevel@tonic-gate break; 3827c478bd9Sstevel@tonic-gate case 'a': 3837c478bd9Sstevel@tonic-gate state = 5; 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate case 'c': 3867c478bd9Sstevel@tonic-gate state = 7; 3877c478bd9Sstevel@tonic-gate break; 3887c478bd9Sstevel@tonic-gate case 'f': 3897c478bd9Sstevel@tonic-gate state = 10; 3907c478bd9Sstevel@tonic-gate break; 3917c478bd9Sstevel@tonic-gate case 'p': 3927c478bd9Sstevel@tonic-gate state = 11; 3937c478bd9Sstevel@tonic-gate break; 3947c478bd9Sstevel@tonic-gate case 's': 3957c478bd9Sstevel@tonic-gate state = 12; 3967c478bd9Sstevel@tonic-gate break; 3977c478bd9Sstevel@tonic-gate case 'u': 3987c478bd9Sstevel@tonic-gate state = 13; 3997c478bd9Sstevel@tonic-gate break; 4007c478bd9Sstevel@tonic-gate case NUMBER: 4017c478bd9Sstevel@tonic-gate state = 14; 4027c478bd9Sstevel@tonic-gate number[0] = c - '0'; 4037c478bd9Sstevel@tonic-gate break; 4047c478bd9Sstevel@tonic-gate default: 4057c478bd9Sstevel@tonic-gate goto tabspecerr; 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate break; 4087c478bd9Sstevel@tonic-gate case 4: 4097c478bd9Sstevel@tonic-gate if (c == '\0') { 4107c478bd9Sstevel@tonic-gate spectype = 12; 4117c478bd9Sstevel@tonic-gate state = -1; 412*779fc935Sceastha } else { 4137c478bd9Sstevel@tonic-gate filep = --p; 4147c478bd9Sstevel@tonic-gate spectype = 13; 4157c478bd9Sstevel@tonic-gate state = -1; 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate break; 4187c478bd9Sstevel@tonic-gate case 5: 4197c478bd9Sstevel@tonic-gate if (c == '\0') { 4207c478bd9Sstevel@tonic-gate spectype = 1; 4217c478bd9Sstevel@tonic-gate state = -1; 422*779fc935Sceastha } else if (c == '2') 4237c478bd9Sstevel@tonic-gate state = 6; 4247c478bd9Sstevel@tonic-gate else 4257c478bd9Sstevel@tonic-gate goto tabspecerr; 4267c478bd9Sstevel@tonic-gate break; 4277c478bd9Sstevel@tonic-gate case 6: 4287c478bd9Sstevel@tonic-gate if (c == '\0') { 4297c478bd9Sstevel@tonic-gate spectype = 2; 4307c478bd9Sstevel@tonic-gate state = -1; 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate else 4337c478bd9Sstevel@tonic-gate goto tabspecerr; 4347c478bd9Sstevel@tonic-gate break; 4357c478bd9Sstevel@tonic-gate case 7: 4367c478bd9Sstevel@tonic-gate switch (c) { 4377c478bd9Sstevel@tonic-gate case '\0': 4387c478bd9Sstevel@tonic-gate spectype = 3; 4397c478bd9Sstevel@tonic-gate state = -1; 4407c478bd9Sstevel@tonic-gate break; 4417c478bd9Sstevel@tonic-gate case '2': 4427c478bd9Sstevel@tonic-gate state = 8; 4437c478bd9Sstevel@tonic-gate break; 4447c478bd9Sstevel@tonic-gate case '3': 4457c478bd9Sstevel@tonic-gate state = 9; 4467c478bd9Sstevel@tonic-gate break; 4477c478bd9Sstevel@tonic-gate default: 4487c478bd9Sstevel@tonic-gate goto tabspecerr; 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate break; 4517c478bd9Sstevel@tonic-gate case 8: 4527c478bd9Sstevel@tonic-gate if (c == '\0') { 4537c478bd9Sstevel@tonic-gate spectype = 4; 4547c478bd9Sstevel@tonic-gate state = -1; 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate else 4577c478bd9Sstevel@tonic-gate goto tabspecerr; 4587c478bd9Sstevel@tonic-gate break; 4597c478bd9Sstevel@tonic-gate case 9: 4607c478bd9Sstevel@tonic-gate if (c == '\0') { 4617c478bd9Sstevel@tonic-gate spectype = 5; 4627c478bd9Sstevel@tonic-gate state = -1; 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate else 4657c478bd9Sstevel@tonic-gate goto tabspecerr; 4667c478bd9Sstevel@tonic-gate break; 4677c478bd9Sstevel@tonic-gate case 10: 4687c478bd9Sstevel@tonic-gate if (c == '\0') { 4697c478bd9Sstevel@tonic-gate spectype = 6; 4707c478bd9Sstevel@tonic-gate state = -1; 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate else 4737c478bd9Sstevel@tonic-gate goto tabspecerr; 4747c478bd9Sstevel@tonic-gate break; 4757c478bd9Sstevel@tonic-gate case 11: 4767c478bd9Sstevel@tonic-gate if (c == '\0') { 4777c478bd9Sstevel@tonic-gate spectype = 7; 4787c478bd9Sstevel@tonic-gate state = -1; 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate else 4817c478bd9Sstevel@tonic-gate goto tabspecerr; 4827c478bd9Sstevel@tonic-gate break; 4837c478bd9Sstevel@tonic-gate case 12: 4847c478bd9Sstevel@tonic-gate if (c == '\0') { 4857c478bd9Sstevel@tonic-gate spectype = 8; 4867c478bd9Sstevel@tonic-gate state = -1; 4877c478bd9Sstevel@tonic-gate } 4887c478bd9Sstevel@tonic-gate else 4897c478bd9Sstevel@tonic-gate goto tabspecerr; 4907c478bd9Sstevel@tonic-gate break; 4917c478bd9Sstevel@tonic-gate case 13: 4927c478bd9Sstevel@tonic-gate if (c == '\0') { 4937c478bd9Sstevel@tonic-gate spectype = 9; 4947c478bd9Sstevel@tonic-gate state = -1; 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate else 4977c478bd9Sstevel@tonic-gate goto tabspecerr; 4987c478bd9Sstevel@tonic-gate break; 4997c478bd9Sstevel@tonic-gate case 14: 5007c478bd9Sstevel@tonic-gate if (type(c) == NUMBER) { 5017c478bd9Sstevel@tonic-gate state = 14; 5027c478bd9Sstevel@tonic-gate number[0] = number[0] * 10 + c - '0'; 503*779fc935Sceastha } else if (c == '\0') { 5047c478bd9Sstevel@tonic-gate spectype = 10; 5057c478bd9Sstevel@tonic-gate state = -1; 506*779fc935Sceastha } else 5077c478bd9Sstevel@tonic-gate goto tabspecerr; 5087c478bd9Sstevel@tonic-gate break; 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate } 511*779fc935Sceastha if (spectype <= 9) 512*779fc935Sceastha return (spectype); 5137c478bd9Sstevel@tonic-gate if (spectype == 10) { 5147c478bd9Sstevel@tonic-gate spectype = nextspec++; 5157c478bd9Sstevel@tonic-gate spectbl[spectype] = nexttab; 5167c478bd9Sstevel@tonic-gate *nexttab = 1; 5177c478bd9Sstevel@tonic-gate if (number[0] == 0) number[0] = 1; /* Prevent infinite loop. */ 5187c478bd9Sstevel@tonic-gate while (*nexttab < LINELEN) { 5197c478bd9Sstevel@tonic-gate *(nexttab + 1) = *nexttab; 5207c478bd9Sstevel@tonic-gate *++nexttab += number[0]; 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate *nexttab++ = '\0'; 5237c478bd9Sstevel@tonic-gate return (spectype); 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate if (spectype == 11) { 5267c478bd9Sstevel@tonic-gate spectype = nextspec++; 5277c478bd9Sstevel@tonic-gate spectbl[spectype] = nexttab; 5287c478bd9Sstevel@tonic-gate *nexttab++ = 1; 5297c478bd9Sstevel@tonic-gate for (ix = 0; ix <= tp; ix++) { 5307c478bd9Sstevel@tonic-gate *nexttab++ = number[ix]; 5317c478bd9Sstevel@tonic-gate if ((number[ix] >= number[ix+1]) && (ix != tp)) 5327c478bd9Sstevel@tonic-gate goto tabspecerr; 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate *nexttab++ = '\0'; 5357c478bd9Sstevel@tonic-gate return (spectype); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate if (lock == 1) { 538*779fc935Sceastha (void) fprintf(stderr, 539*779fc935Sceastha "newform: tabspec indirection illegal\n"); 5407c478bd9Sstevel@tonic-gate exit(1); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate lock = 1; 5437c478bd9Sstevel@tonic-gate if (spectype == 12) { 5447c478bd9Sstevel@tonic-gate if (sitabspec >= 0) { 5457c478bd9Sstevel@tonic-gate tspec = sitabspec; 546*779fc935Sceastha } else { 547*779fc935Sceastha if (readline(stdin, siline) != NULL) { 5487c478bd9Sstevel@tonic-gate kludge = 1; 5497c478bd9Sstevel@tonic-gate tspec = readspec(siline); 5507c478bd9Sstevel@tonic-gate sitabspec = tspec; 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate if (spectype == 13) { 5557c478bd9Sstevel@tonic-gate if ((fp = fopen(filep, "r")) == NULL) { 556*779fc935Sceastha (void) fprintf(stderr, 557*779fc935Sceastha "newform: can't open %s\n", filep); 5587c478bd9Sstevel@tonic-gate exit(1); 5597c478bd9Sstevel@tonic-gate } 560*779fc935Sceastha (void) readline(fp, work); 561*779fc935Sceastha (void) fclose(fp); 5627c478bd9Sstevel@tonic-gate tspec = readspec(work); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate lock = 0; 5657c478bd9Sstevel@tonic-gate return (tspec); 5667c478bd9Sstevel@tonic-gate tabspecerr: 567*779fc935Sceastha (void) fprintf(stderr, "newform: tabspec in error\n"); 568*779fc935Sceastha (void) fprintf(stderr, 569*779fc935Sceastha "tabspec is \t-a\t-a2\t-c\t-c2\t-c3\t-f\t-p\t-s\n"); 570*779fc935Sceastha (void) fprintf(stderr, 571*779fc935Sceastha "\t\t-u\t--\t--file\t-number\tnumber,..,number\n"); 5727c478bd9Sstevel@tonic-gate exit(1); 573*779fc935Sceastha /* NOTREACHED */ 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate 576*779fc935Sceastha static int 577*779fc935Sceastha readspec(char *p) /* Read a tabspec from a file */ 578*779fc935Sceastha /* Pointer to buffer to process */ 5797c478bd9Sstevel@tonic-gate { 5807c478bd9Sstevel@tonic-gate int state, /* Current state */ 5817c478bd9Sstevel@tonic-gate firsttime, /* Flag to indicate spec found */ 5827c478bd9Sstevel@tonic-gate value; /* Function value */ 5837c478bd9Sstevel@tonic-gate char c, /* Char being looked at */ 5847c478bd9Sstevel@tonic-gate *tabspecp, /* Pointer to spec string */ 5857c478bd9Sstevel@tonic-gate *restore = " ", /* Character to be restored */ 5867c478bd9Sstevel@tonic-gate repch; /* Character to replace with */ 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate state = 0; 5897c478bd9Sstevel@tonic-gate firsttime = 1; 5907c478bd9Sstevel@tonic-gate while (state >= 0) { 5917c478bd9Sstevel@tonic-gate c = *p++; 5927c478bd9Sstevel@tonic-gate switch (state) { 5937c478bd9Sstevel@tonic-gate case 0: 5947c478bd9Sstevel@tonic-gate state = (c == '<') ? 1 : 0; 5957c478bd9Sstevel@tonic-gate break; 5967c478bd9Sstevel@tonic-gate case 1: 5977c478bd9Sstevel@tonic-gate state = (c == ':') ? 2 : 0; 5987c478bd9Sstevel@tonic-gate break; 5997c478bd9Sstevel@tonic-gate case 2: 6007c478bd9Sstevel@tonic-gate state = (c == 't') ? 4 6017c478bd9Sstevel@tonic-gate : ((c == ' ') || (c == '\t')) ? 2 : 3; 6027c478bd9Sstevel@tonic-gate break; 6037c478bd9Sstevel@tonic-gate case 3: 6047c478bd9Sstevel@tonic-gate state = ((c == ' ') || (c == '\t')) ? 2 : 3; 6057c478bd9Sstevel@tonic-gate break; 6067c478bd9Sstevel@tonic-gate case 4: 6077c478bd9Sstevel@tonic-gate if (firsttime) { 6087c478bd9Sstevel@tonic-gate tabspecp = --p; 6097c478bd9Sstevel@tonic-gate p++; 6107c478bd9Sstevel@tonic-gate firsttime = 0; 6117c478bd9Sstevel@tonic-gate } 6127c478bd9Sstevel@tonic-gate if ((c == ' ') || (c == '\t') || (c == ':')) { 6137c478bd9Sstevel@tonic-gate repch = *(restore = p - 1); 6147c478bd9Sstevel@tonic-gate *restore = '\0'; 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate state = (c == ':') ? 6 6177c478bd9Sstevel@tonic-gate : ((c == ' ') || (c == '\t')) ? 5 : 4; 6187c478bd9Sstevel@tonic-gate break; 6197c478bd9Sstevel@tonic-gate case 5: 6207c478bd9Sstevel@tonic-gate state = (c == ':') ? 6 : 5; 6217c478bd9Sstevel@tonic-gate break; 6227c478bd9Sstevel@tonic-gate case 6: 6237c478bd9Sstevel@tonic-gate state = (c == '>') ? -2 : 5; 6247c478bd9Sstevel@tonic-gate break; 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate if (c == '\n') state = -1; 6277c478bd9Sstevel@tonic-gate } 628*779fc935Sceastha if (okludge) 629*779fc935Sceastha (void) strcpy(format, tabspecp); 6307c478bd9Sstevel@tonic-gate value = (state == -1) ? 0 : cnvtspec(tabspecp); 6317c478bd9Sstevel@tonic-gate *restore = repch; 6327c478bd9Sstevel@tonic-gate return (value); 6337c478bd9Sstevel@tonic-gate } 634*779fc935Sceastha 635*779fc935Sceastha static char * 636*779fc935Sceastha readline(FILE *fp, char *area) /* Read one line from the file. */ 637*779fc935Sceastha /* fp - File to read from */ 638*779fc935Sceastha /* area - Array of characters to read into */ 6397c478bd9Sstevel@tonic-gate { 6407c478bd9Sstevel@tonic-gate int c; /* Current character */ 6417c478bd9Sstevel@tonic-gate char *xarea, /* Temporary pointer to character array */ 6427c478bd9Sstevel@tonic-gate *temp; /* Array pointer */ 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* check for existence of stdin before attempting to read */ 6477c478bd9Sstevel@tonic-gate /* kludge refers to reading from stdin to get tabspecs for option -i-- */ 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate xarea = area; 6507c478bd9Sstevel@tonic-gate if (kludge && (fp == stdin)) { 6517c478bd9Sstevel@tonic-gate if (fp != NULL) { 6527c478bd9Sstevel@tonic-gate temp = siline; 653*779fc935Sceastha while ((*area++ = *temp++) != '\n') 654*779fc935Sceastha ; 6557c478bd9Sstevel@tonic-gate kludge = 0; 6567c478bd9Sstevel@tonic-gate return (xarea); 657*779fc935Sceastha } else 6587c478bd9Sstevel@tonic-gate return (NULL); 659*779fc935Sceastha } else { 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate /* check for exceeding size of buffer when reading valid input */ 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate while (wlast - area) { 6647c478bd9Sstevel@tonic-gate switch (c = getc(fp)) { 6657c478bd9Sstevel@tonic-gate case EOF: 6667c478bd9Sstevel@tonic-gate if (area == xarea) 6677c478bd9Sstevel@tonic-gate return (NULL); 668*779fc935Sceastha /* FALLTHROUGH */ 6697c478bd9Sstevel@tonic-gate case '\n': /* EOF falls through to here */ 6707c478bd9Sstevel@tonic-gate *area = '\n'; 6717c478bd9Sstevel@tonic-gate return (xarea); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate *area = c; 674*779fc935Sceastha area++; 6757c478bd9Sstevel@tonic-gate } 676*779fc935Sceastha (void) printf("newform: input line larger than buffer area \n"); 6777c478bd9Sstevel@tonic-gate exit(1); 6787c478bd9Sstevel@tonic-gate } 679*779fc935Sceastha /* NOTREACHED */ 6807c478bd9Sstevel@tonic-gate } 6817c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 6827c478bd9Sstevel@tonic-gate 683*779fc935Sceastha static char 684*779fc935Sceastha type(char c) /* Determine type of a character */ 685*779fc935Sceastha /* Character to check */ 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate return ((c >= '0') && (c <= '9') ? NUMBER : c); 6887c478bd9Sstevel@tonic-gate } 689*779fc935Sceastha 690*779fc935Sceastha static void 691*779fc935Sceastha process(FILE *fp) /* Process one line of input */ 692*779fc935Sceastha /* File pointer for current input */ 6937c478bd9Sstevel@tonic-gate { 6947c478bd9Sstevel@tonic-gate struct f *lp; /* Pointer to structs */ 6957c478bd9Sstevel@tonic-gate char chrnow; /* For int to char conversion. */ 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate while (readline(fp, &work[NCOLS]) != NULL) { 6987c478bd9Sstevel@tonic-gate effll = 80; 6997c478bd9Sstevel@tonic-gate pachar = ' '; 7007c478bd9Sstevel@tonic-gate pfirst = plast = &work[NCOLS]; 7017c478bd9Sstevel@tonic-gate while (*plast != '\n') plast++; 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate /* changes to line parsing includes checks for exceeding */ 7047c478bd9Sstevel@tonic-gate /* line size when modifying text */ 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate for (lp = optl; lp < flp; lp++) { 7077c478bd9Sstevel@tonic-gate switch (lp->option) { 7087c478bd9Sstevel@tonic-gate case 'a': 7097c478bd9Sstevel@tonic-gate append(lp->param); 7107c478bd9Sstevel@tonic-gate break; 7117c478bd9Sstevel@tonic-gate case 'b': 7127c478bd9Sstevel@tonic-gate if (lp->param <= (plast - pfirst)) 7137c478bd9Sstevel@tonic-gate begtrunc(lp->param); 7147c478bd9Sstevel@tonic-gate else 715*779fc935Sceastha (void) fprintf(stderr, 716*779fc935Sceastha "newform: truncate " 717*779fc935Sceastha "request larger than line, %d \n", 718*779fc935Sceastha (plast - pfirst)); 7197c478bd9Sstevel@tonic-gate break; 7207c478bd9Sstevel@tonic-gate case 'c': 7217c478bd9Sstevel@tonic-gate chrnow = lp->param; 7227c478bd9Sstevel@tonic-gate pachar = chrnow ? chrnow : ' '; 7237c478bd9Sstevel@tonic-gate break; 7247c478bd9Sstevel@tonic-gate case 'e': 7257c478bd9Sstevel@tonic-gate if (lp->param <= (plast - pfirst)) 7267c478bd9Sstevel@tonic-gate endtrunc(lp->param); 7277c478bd9Sstevel@tonic-gate else 728*779fc935Sceastha (void) fprintf(stderr, 729*779fc935Sceastha "newform: truncate " 730*779fc935Sceastha "request larger than line, %d \n", 731*779fc935Sceastha (plast - pfirst)); 7327c478bd9Sstevel@tonic-gate break; 7337c478bd9Sstevel@tonic-gate case 'f': 7347c478bd9Sstevel@tonic-gate /* Ignored */ 7357c478bd9Sstevel@tonic-gate break; 7367c478bd9Sstevel@tonic-gate case 'i': 7377c478bd9Sstevel@tonic-gate inputtabs(lp->param); 7387c478bd9Sstevel@tonic-gate break; 7397c478bd9Sstevel@tonic-gate case 'l': /* New eff line length */ 7407c478bd9Sstevel@tonic-gate effll = lp->param ? lp->param : 72; 7417c478bd9Sstevel@tonic-gate break; 7427c478bd9Sstevel@tonic-gate case 's': 7437c478bd9Sstevel@tonic-gate sstrip(); 7447c478bd9Sstevel@tonic-gate break; 7457c478bd9Sstevel@tonic-gate case 'o': 7467c478bd9Sstevel@tonic-gate outputtabs(lp->param); 7477c478bd9Sstevel@tonic-gate break; 7487c478bd9Sstevel@tonic-gate case 'p': 7497c478bd9Sstevel@tonic-gate prepend(lp->param); 7507c478bd9Sstevel@tonic-gate break; 7517c478bd9Sstevel@tonic-gate } 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate if (soption) sadd(); 7547c478bd9Sstevel@tonic-gate *++plast = '\0'; 755*779fc935Sceastha (void) fputs(pfirst, stdout); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate } 758*779fc935Sceastha 759*779fc935Sceastha static void 760*779fc935Sceastha append(int n) /* Append characters to end of line. */ 761*779fc935Sceastha /* Number of characters to append. */ 7627c478bd9Sstevel@tonic-gate { 7637c478bd9Sstevel@tonic-gate if (plast - pfirst < effll) { 7647c478bd9Sstevel@tonic-gate n = n ? n : effll - (plast - pfirst); 7657c478bd9Sstevel@tonic-gate if (plast + n > wlast) center(); 7667c478bd9Sstevel@tonic-gate while (n--) *plast++ = pachar; 7677c478bd9Sstevel@tonic-gate *plast = '\n'; 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 7717c478bd9Sstevel@tonic-gate 772*779fc935Sceastha static void 773*779fc935Sceastha prepend(int n) /* Prepend characters to line. */ 774*779fc935Sceastha /* Number of characters to prepend. */ 7757c478bd9Sstevel@tonic-gate { 7767c478bd9Sstevel@tonic-gate if (plast - pfirst < effll) { 7777c478bd9Sstevel@tonic-gate n = n ? n : effll - (plast - pfirst); 7787c478bd9Sstevel@tonic-gate if (pfirst - n < wfirst) center(); 7797c478bd9Sstevel@tonic-gate while (n--) *--pfirst = pachar; 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 7837c478bd9Sstevel@tonic-gate 784*779fc935Sceastha static void 785*779fc935Sceastha begtrunc(int n) /* Truncate characters from beginning of line. */ 786*779fc935Sceastha /* Number of characters to truncate. */ 7877c478bd9Sstevel@tonic-gate { 7887c478bd9Sstevel@tonic-gate if (plast - pfirst > effll) { 7897c478bd9Sstevel@tonic-gate n = n ? n : plast - pfirst - effll; 7907c478bd9Sstevel@tonic-gate pfirst += n; 7917c478bd9Sstevel@tonic-gate if (pfirst >= plast) 7927c478bd9Sstevel@tonic-gate *(pfirst = plast = &work[NCOLS]) = '\n'; 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate } 7957c478bd9Sstevel@tonic-gate /* _________________________________________________________________ */ 7967c478bd9Sstevel@tonic-gate 797*779fc935Sceastha static void 798*779fc935Sceastha endtrunc(int n) /* Truncate characters from end of line. */ 799*779fc935Sceastha /* Number of characters to truncate. */ 8007c478bd9Sstevel@tonic-gate { 8017c478bd9Sstevel@tonic-gate if (plast - pfirst > effll) { 8027c478bd9Sstevel@tonic-gate n = n ? n : plast - pfirst - effll; 8037c478bd9Sstevel@tonic-gate plast -= n; 8047c478bd9Sstevel@tonic-gate if (pfirst >= plast) 8057c478bd9Sstevel@tonic-gate *(pfirst = plast = &work[NCOLS]) = '\n'; 8067c478bd9Sstevel@tonic-gate else 8077c478bd9Sstevel@tonic-gate *plast = '\n'; 8087c478bd9Sstevel@tonic-gate } 8097c478bd9Sstevel@tonic-gate } 810*779fc935Sceastha 811*779fc935Sceastha static void 812*779fc935Sceastha inputtabs(int p) /* Expand according to input tab specifications. */ 813*779fc935Sceastha /* Pointer to tab specification. */ 8147c478bd9Sstevel@tonic-gate { 8157c478bd9Sstevel@tonic-gate int *tabs; /* Pointer to tabs */ 8167c478bd9Sstevel@tonic-gate char *tfirst, /* Pointer to new buffer start */ 8177c478bd9Sstevel@tonic-gate *tlast; /* Pointer to new buffer end */ 818*779fc935Sceastha char c; /* Character being scanned */ 8197c478bd9Sstevel@tonic-gate int logcol; /* Logical column */ 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate tabs = spectbl[p]; 8227c478bd9Sstevel@tonic-gate tfirst = tlast = work; 8237c478bd9Sstevel@tonic-gate logcol = 1; 8247c478bd9Sstevel@tonic-gate center(); 8257c478bd9Sstevel@tonic-gate while (pfirst <= plast) { 8267c478bd9Sstevel@tonic-gate if (logcol >= *tabs) tabs++; 8277c478bd9Sstevel@tonic-gate switch (c = *pfirst++) { 8287c478bd9Sstevel@tonic-gate case '\b': 8297c478bd9Sstevel@tonic-gate if (logcol > 1) logcol--; 8307c478bd9Sstevel@tonic-gate *tlast++ = c; 8317c478bd9Sstevel@tonic-gate if (logcol < *tabs) tabs--; 8327c478bd9Sstevel@tonic-gate break; 8337c478bd9Sstevel@tonic-gate case '\t': 8347c478bd9Sstevel@tonic-gate while (logcol < *tabs) { 8357c478bd9Sstevel@tonic-gate *tlast++ = ' '; 8367c478bd9Sstevel@tonic-gate logcol++; 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate tabs++; 8397c478bd9Sstevel@tonic-gate break; 8407c478bd9Sstevel@tonic-gate default: 8417c478bd9Sstevel@tonic-gate *tlast++ = c; 8427c478bd9Sstevel@tonic-gate logcol++; 8437c478bd9Sstevel@tonic-gate break; 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate } 8467c478bd9Sstevel@tonic-gate pfirst = tfirst; 8477c478bd9Sstevel@tonic-gate plast = --tlast; 8487c478bd9Sstevel@tonic-gate } 849*779fc935Sceastha /* 850*779fc935Sceastha * Add SCCS SID (generated by a "get -m" command) to the end of each line. 851*779fc935Sceastha * Sequence is as follows for EACH line: 852*779fc935Sceastha * Check for at least 1 tab. Err if none. 853*779fc935Sceastha * Strip off all char up to & including first tab. 854*779fc935Sceastha * If more than 8 char were stripped, the 8 th is replaced by 855*779fc935Sceastha * a '*' & the remainder are discarded. 856*779fc935Sceastha * Unless user specified an "a", append blanks to fill 857*779fc935Sceastha * out line to eff. line length (default= 72 char). 858*779fc935Sceastha * Truncate lines > eff. line length (default=72). 859*779fc935Sceastha * Add stripped char to end of line. 860*779fc935Sceastha */ 861*779fc935Sceastha static void 862*779fc935Sceastha sstrip(void) 8637c478bd9Sstevel@tonic-gate { 864*779fc935Sceastha int i, k; 8657c478bd9Sstevel@tonic-gate char *c, *savec; 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate k = -1; 8687c478bd9Sstevel@tonic-gate c = pfirst; 869*779fc935Sceastha while (*c != '\t' && *c != '\n') { 870*779fc935Sceastha k++; 871*779fc935Sceastha c++; 872*779fc935Sceastha } 873*779fc935Sceastha if (*c != '\t') { 874*779fc935Sceastha (void) fprintf(stderr, "not -s format\r\n"); 875*779fc935Sceastha exit(1); 876*779fc935Sceastha } 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate savec = c; 8797c478bd9Sstevel@tonic-gate c = pfirst; 8807c478bd9Sstevel@tonic-gate savek = (k > 7) ? 7 : k; 8817c478bd9Sstevel@tonic-gate for (i = 0; i <= savek; i++) savchr[i] = *c++; /* Tab not saved */ 8827c478bd9Sstevel@tonic-gate if (k > 7) savchr[7] = '*'; 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate pfirst = ++savec; /* Point pfirst to char after tab */ 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate /* ================================================================= */ 8877c478bd9Sstevel@tonic-gate 888*779fc935Sceastha static void 889*779fc935Sceastha sadd(void) 8907c478bd9Sstevel@tonic-gate { 891*779fc935Sceastha int i; 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate for (i = 0; i <= savek; i++) *plast++ = savchr[i]; 8947c478bd9Sstevel@tonic-gate *plast = '\n'; 8957c478bd9Sstevel@tonic-gate } 896*779fc935Sceastha 897*779fc935Sceastha static void 898*779fc935Sceastha outputtabs(int p) /* Contract according to output tab specifications. */ 899*779fc935Sceastha /* Pointer to tab specification. */ 9007c478bd9Sstevel@tonic-gate { 9017c478bd9Sstevel@tonic-gate int *tabs; /* Pointer to tabs */ 9027c478bd9Sstevel@tonic-gate char *tfirst, /* Pointer to new buffer start */ 9037c478bd9Sstevel@tonic-gate *tlast, /* Pointer to new buffer end */ 9047c478bd9Sstevel@tonic-gate *mark; /* Marker pointer */ 905*779fc935Sceastha char c; /* Character being scanned */ 9067c478bd9Sstevel@tonic-gate int logcol; /* Logical column */ 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate tabs = spectbl[p]; 9097c478bd9Sstevel@tonic-gate tfirst = tlast = pfirst; 9107c478bd9Sstevel@tonic-gate logcol = 1; 9117c478bd9Sstevel@tonic-gate while (pfirst <= plast) { 9127c478bd9Sstevel@tonic-gate if (logcol == *tabs) tabs++; 9137c478bd9Sstevel@tonic-gate switch (c = *pfirst++) { 9147c478bd9Sstevel@tonic-gate case '\b': 9157c478bd9Sstevel@tonic-gate if (logcol > 1) logcol--; 9167c478bd9Sstevel@tonic-gate *tlast++ = c; 9177c478bd9Sstevel@tonic-gate if (logcol < *tabs) tabs--; 9187c478bd9Sstevel@tonic-gate break; 9197c478bd9Sstevel@tonic-gate case ' ': 9207c478bd9Sstevel@tonic-gate mark = tlast; 9217c478bd9Sstevel@tonic-gate do { 9227c478bd9Sstevel@tonic-gate *tlast++ = ' '; 9237c478bd9Sstevel@tonic-gate logcol++; 9247c478bd9Sstevel@tonic-gate if (logcol == *tabs) { 9257c478bd9Sstevel@tonic-gate *mark++ = '\t'; 9267c478bd9Sstevel@tonic-gate tlast = mark; 9277c478bd9Sstevel@tonic-gate tabs++; 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate } while (*pfirst++ == ' '); 9307c478bd9Sstevel@tonic-gate pfirst--; 9317c478bd9Sstevel@tonic-gate break; 9327c478bd9Sstevel@tonic-gate default: 9337c478bd9Sstevel@tonic-gate logcol++; 9347c478bd9Sstevel@tonic-gate *tlast++ = c; 9357c478bd9Sstevel@tonic-gate break; 9367c478bd9Sstevel@tonic-gate } 9377c478bd9Sstevel@tonic-gate } 9387c478bd9Sstevel@tonic-gate pfirst = tfirst; 9397c478bd9Sstevel@tonic-gate plast = --tlast; 9407c478bd9Sstevel@tonic-gate } 941