Home | History | Annotate | Line # | Download | only in indent
indent.c revision 1.7
      1  1.7   ross /*	$NetBSD: indent.c,v 1.7 1998/08/25 20:59:37 ross Exp $	*/
      2  1.4    tls 
      3  1.1    cgd /*
      4  1.5    mrg  * Copyright (c) 1980, 1993
      5  1.5    mrg  *	The Regents of the University of California.  All rights reserved.
      6  1.5    mrg  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
      7  1.1    cgd  * Copyright (c) 1985 Sun Microsystems, Inc.
      8  1.1    cgd  * All rights reserved.
      9  1.1    cgd  *
     10  1.1    cgd  * Redistribution and use in source and binary forms, with or without
     11  1.1    cgd  * modification, are permitted provided that the following conditions
     12  1.1    cgd  * are met:
     13  1.1    cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.1    cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.1    cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    cgd  *    documentation and/or other materials provided with the distribution.
     18  1.1    cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.1    cgd  *    must display the following acknowledgement:
     20  1.1    cgd  *	This product includes software developed by the University of
     21  1.1    cgd  *	California, Berkeley and its contributors.
     22  1.1    cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.1    cgd  *    may be used to endorse or promote products derived from this software
     24  1.1    cgd  *    without specific prior written permission.
     25  1.1    cgd  *
     26  1.1    cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1    cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1    cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1    cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1    cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1    cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1    cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1    cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1    cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1    cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1    cgd  * SUCH DAMAGE.
     37  1.1    cgd  */
     38  1.1    cgd 
     39  1.6  lukem #include <sys/cdefs.h>
     40  1.1    cgd #ifndef lint
     41  1.6  lukem __COPYRIGHT("@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\
     42  1.5    mrg @(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\
     43  1.5    mrg @(#) Copyright (c) 1980, 1993\n\
     44  1.6  lukem 	The Regents of the University of California.  All rights reserved.\n");
     45  1.6  lukem #endif				/* not lint */
     46  1.1    cgd 
     47  1.1    cgd #ifndef lint
     48  1.5    mrg #if 0
     49  1.5    mrg static char sccsid[] = "@(#)indent.c	5.17 (Berkeley) 6/7/93";
     50  1.5    mrg #else
     51  1.7   ross __RCSID("$NetBSD: indent.c,v 1.7 1998/08/25 20:59:37 ross Exp $");
     52  1.5    mrg #endif
     53  1.6  lukem #endif				/* not lint */
     54  1.1    cgd 
     55  1.1    cgd #include <sys/param.h>
     56  1.6  lukem #include <ctype.h>
     57  1.6  lukem #include <err.h>
     58  1.6  lukem #include <errno.h>
     59  1.1    cgd #include <fcntl.h>
     60  1.1    cgd #include <stdio.h>
     61  1.1    cgd #include <stdlib.h>
     62  1.1    cgd #include <string.h>
     63  1.6  lukem #include <unistd.h>
     64  1.1    cgd #include "indent_globs.h"
     65  1.1    cgd #include "indent_codes.h"
     66  1.1    cgd 
     67  1.6  lukem char   *in_name = "Standard Input";	/* will always point to name of input
     68  1.6  lukem 					 * file */
     69  1.6  lukem char   *out_name = "Standard Output";	/* will always point to name of output
     70  1.1    cgd 					 * file */
     71  1.6  lukem char    bakfile[MAXPATHLEN] = "";
     72  1.1    cgd 
     73  1.6  lukem int main __P((int, char **));
     74  1.6  lukem 
     75  1.6  lukem int
     76  1.1    cgd main(argc, argv)
     77  1.6  lukem 	int     argc;
     78  1.6  lukem 	char  **argv;
     79  1.1    cgd {
     80  1.1    cgd 
     81  1.6  lukem 	extern int found_err;	/* flag set in diag() on error */
     82  1.6  lukem 	int     dec_ind;	/* current indentation for declarations */
     83  1.6  lukem 	int     di_stack[20];	/* a stack of structure indentation levels */
     84  1.6  lukem 	int     flushed_nl;	/* used when buffering up comments to remember
     85  1.1    cgd 				 * that a newline was passed over */
     86  1.6  lukem 	int     force_nl;	/* when true, code must be broken */
     87  1.6  lukem 	int     hd_type;	/* used to store type of stmt for if (...),
     88  1.1    cgd 				 * for (...), etc */
     89  1.6  lukem 	int     i;		/* local loop counter */
     90  1.6  lukem 	int     scase;		/* set to true when we see a case, so we will
     91  1.1    cgd 				 * know what to do with the following colon */
     92  1.6  lukem 	int     sp_sw;		/* when true, we are in the expressin of
     93  1.1    cgd 				 * if(...), while(...), etc. */
     94  1.6  lukem 	int     squest;		/* when this is positive, we have seen a ?
     95  1.1    cgd 				 * without the matching : in a <c>?<s>:<s>
     96  1.1    cgd 				 * construct */
     97  1.6  lukem 	char   *t_ptr;		/* used for copying tokens */
     98  1.6  lukem 	int     type_code;	/* the type of token, returned by lexi */
     99  1.1    cgd 
    100  1.6  lukem 	int     last_else = 0;	/* true iff last keyword was an else */
    101  1.1    cgd 
    102  1.1    cgd 
    103  1.6  lukem 	/*-----------------------------------------------*\
    104  1.6  lukem         |		      INITIALIZATION		      |
    105  1.6  lukem         \*-----------------------------------------------*/
    106  1.1    cgd 
    107  1.1    cgd 
    108  1.6  lukem 	hd_type = 0;
    109  1.6  lukem 	ps.p_stack[0] = stmt;	/* this is the parser's stack */
    110  1.6  lukem 	ps.last_nl = true;	/* this is true if the last thing scanned was
    111  1.1    cgd 				 * a newline */
    112  1.6  lukem 	ps.last_token = semicolon;
    113  1.6  lukem 	combuf = (char *) malloc(bufsize);
    114  1.6  lukem 	labbuf = (char *) malloc(bufsize);
    115  1.6  lukem 	codebuf = (char *) malloc(bufsize);
    116  1.6  lukem 	tokenbuf = (char *) malloc(bufsize);
    117  1.6  lukem 	l_com = combuf + bufsize - 5;
    118  1.6  lukem 	l_lab = labbuf + bufsize - 5;
    119  1.6  lukem 	l_code = codebuf + bufsize - 5;
    120  1.6  lukem 	l_token = tokenbuf + bufsize - 5;
    121  1.6  lukem 	combuf[0] = codebuf[0] = labbuf[0] = ' ';	/* set up code, label,
    122  1.6  lukem 							 * and comment buffers */
    123  1.6  lukem 	combuf[1] = codebuf[1] = labbuf[1] = '\0';
    124  1.6  lukem 	ps.else_if = 1;		/* Default else-if special processing to on */
    125  1.6  lukem 	s_lab = e_lab = labbuf + 1;
    126  1.6  lukem 	s_code = e_code = codebuf + 1;
    127  1.6  lukem 	s_com = e_com = combuf + 1;
    128  1.6  lukem 	s_token = e_token = tokenbuf + 1;
    129  1.6  lukem 
    130  1.6  lukem 	in_buffer = (char *) malloc(10);
    131  1.6  lukem 	in_buffer_limit = in_buffer + 8;
    132  1.6  lukem 	buf_ptr = buf_end = in_buffer;
    133  1.6  lukem 	line_no = 1;
    134  1.6  lukem 	had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
    135  1.6  lukem 	sp_sw = force_nl = false;
    136  1.6  lukem 	ps.in_or_st = false;
    137  1.6  lukem 	ps.bl_line = true;
    138  1.6  lukem 	dec_ind = 0;
    139  1.6  lukem 	di_stack[ps.dec_nest = 0] = 0;
    140  1.6  lukem 	ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
    141  1.6  lukem 
    142  1.6  lukem 
    143  1.6  lukem 	scase = ps.pcase = false;
    144  1.6  lukem 	squest = 0;
    145  1.6  lukem 	sc_end = 0;
    146  1.6  lukem 	bp_save = 0;
    147  1.6  lukem 	be_save = 0;
    148  1.6  lukem 
    149  1.6  lukem 	output = 0;
    150  1.1    cgd 
    151  1.1    cgd 
    152  1.1    cgd 
    153  1.6  lukem 	/*--------------------------------------------------*\
    154  1.6  lukem         |   		COMMAND LINE SCAN		 |
    155  1.6  lukem         \*--------------------------------------------------*/
    156  1.1    cgd 
    157  1.1    cgd #ifdef undef
    158  1.6  lukem 	max_col = 78;		/* -l78 */
    159  1.6  lukem 	lineup_to_parens = 1;	/* -lp */
    160  1.6  lukem 	ps.ljust_decl = 0;	/* -ndj */
    161  1.6  lukem 	ps.com_ind = 33;	/* -c33 */
    162  1.6  lukem 	star_comment_cont = 1;	/* -sc */
    163  1.6  lukem 	ps.ind_size = 8;	/* -i8 */
    164  1.6  lukem 	verbose = 0;
    165  1.6  lukem 	ps.decl_indent = 16;	/* -di16 */
    166  1.6  lukem 	ps.indent_parameters = 1;	/* -ip */
    167  1.6  lukem 	ps.decl_com_ind = 0;	/* if this is not set to some positive value
    168  1.1    cgd 				 * by an arg, we will set this equal to
    169  1.1    cgd 				 * ps.com_ind */
    170  1.6  lukem 	btype_2 = 1;		/* -br */
    171  1.6  lukem 	cuddle_else = 1;	/* -ce */
    172  1.6  lukem 	ps.unindent_displace = 0;	/* -d0 */
    173  1.6  lukem 	ps.case_indent = 0;	/* -cli0 */
    174  1.6  lukem 	format_col1_comments = 1;	/* -fc1 */
    175  1.6  lukem 	procnames_start_line = 1;	/* -psl */
    176  1.6  lukem 	proc_calls_space = 0;	/* -npcs */
    177  1.6  lukem 	comment_delimiter_on_blankline = 1;	/* -cdb */
    178  1.6  lukem 	ps.leave_comma = 1;	/* -nbc */
    179  1.1    cgd #endif
    180  1.1    cgd 
    181  1.6  lukem 	for (i = 1; i < argc; ++i)
    182  1.6  lukem 		if (strcmp(argv[i], "-npro") == 0)
    183  1.6  lukem 			break;
    184  1.6  lukem 	set_defaults();
    185  1.6  lukem 	if (i >= argc)
    186  1.6  lukem 		set_profile();
    187  1.1    cgd 
    188  1.6  lukem 	for (i = 1; i < argc; ++i) {
    189  1.1    cgd 
    190  1.6  lukem 		/*
    191  1.6  lukem 		 * look thru args (if any) for changes to defaults
    192  1.6  lukem 		 */
    193  1.6  lukem 		if (argv[i][0] != '-') {	/* no flag on parameter */
    194  1.6  lukem 			if (input == 0) {	/* we must have the input file */
    195  1.6  lukem 				in_name = argv[i];	/* remember name of
    196  1.6  lukem 							 * input file */
    197  1.6  lukem 				input = fopen(in_name, "r");
    198  1.6  lukem 				if (input == 0)	/* check for open error */
    199  1.6  lukem 					err(1, "%s", in_name);
    200  1.6  lukem 				continue;
    201  1.6  lukem 			} else
    202  1.6  lukem 				if (output == 0) {	/* we have the output
    203  1.6  lukem 							 * file */
    204  1.6  lukem 					out_name = argv[i];	/* remember name of
    205  1.6  lukem 								 * output file */
    206  1.6  lukem 					if (strcmp(in_name, out_name) == 0) {	/* attempt to overwrite
    207  1.6  lukem 										 * the file */
    208  1.6  lukem 						fprintf(stderr, "indent: input and output files must be different\n");
    209  1.6  lukem 						exit(1);
    210  1.6  lukem 					}
    211  1.6  lukem 					output = fopen(out_name, "w");
    212  1.6  lukem 					if (output == 0)	/* check for create
    213  1.6  lukem 								 * error */
    214  1.6  lukem 						err(1, "%s", out_name);
    215  1.6  lukem 					continue;
    216  1.6  lukem 				}
    217  1.6  lukem 			fprintf(stderr, "indent: unknown parameter: %s\n", argv[i]);
    218  1.6  lukem 			exit(1);
    219  1.6  lukem 		} else
    220  1.6  lukem 			set_option(argv[i]);
    221  1.6  lukem 	}			/* end of for */
    222  1.6  lukem 	if (input == 0) {
    223  1.6  lukem 		fprintf(stderr, "indent: usage: indent file [ outfile ] [ options ]\n");
    224  1.6  lukem 		exit(1);
    225  1.6  lukem 	}
    226  1.7   ross 	if (output == 0) {
    227  1.6  lukem 		if (troff)
    228  1.6  lukem 			output = stdout;
    229  1.6  lukem 		else {
    230  1.6  lukem 			out_name = in_name;
    231  1.6  lukem 			bakcopy();
    232  1.1    cgd 		}
    233  1.7   ross 	}
    234  1.6  lukem 	if (ps.com_ind <= 1)
    235  1.6  lukem 		ps.com_ind = 2;	/* dont put normal comments before column 2 */
    236  1.6  lukem 	if (troff) {
    237  1.6  lukem 		if (bodyf.font[0] == 0)
    238  1.6  lukem 			parsefont(&bodyf, "R");
    239  1.6  lukem 		if (scomf.font[0] == 0)
    240  1.6  lukem 			parsefont(&scomf, "I");
    241  1.6  lukem 		if (blkcomf.font[0] == 0)
    242  1.6  lukem 			blkcomf = scomf, blkcomf.size += 2;
    243  1.6  lukem 		if (boxcomf.font[0] == 0)
    244  1.6  lukem 			boxcomf = blkcomf;
    245  1.6  lukem 		if (stringf.font[0] == 0)
    246  1.6  lukem 			parsefont(&stringf, "L");
    247  1.6  lukem 		if (keywordf.font[0] == 0)
    248  1.6  lukem 			parsefont(&keywordf, "B");
    249  1.6  lukem 		writefdef(&bodyf, 'B');
    250  1.6  lukem 		writefdef(&scomf, 'C');
    251  1.6  lukem 		writefdef(&blkcomf, 'L');
    252  1.6  lukem 		writefdef(&boxcomf, 'X');
    253  1.6  lukem 		writefdef(&stringf, 'S');
    254  1.6  lukem 		writefdef(&keywordf, 'K');
    255  1.1    cgd 	}
    256  1.6  lukem 	if (block_comment_max_col <= 0)
    257  1.6  lukem 		block_comment_max_col = max_col;
    258  1.6  lukem 	if (ps.decl_com_ind <= 0)	/* if not specified by user, set this */
    259  1.6  lukem 		ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) : ps.com_ind;
    260  1.6  lukem 	if (continuation_indent == 0)
    261  1.6  lukem 		continuation_indent = ps.ind_size;
    262  1.6  lukem 	fill_buffer();		/* get first batch of stuff into input buffer */
    263  1.6  lukem 
    264  1.6  lukem 	parse(semicolon);
    265  1.6  lukem 	{
    266  1.6  lukem 		char   *p = buf_ptr;
    267  1.6  lukem 		int     col = 1;
    268  1.6  lukem 
    269  1.6  lukem 		while (1) {
    270  1.6  lukem 			if (*p == ' ')
    271  1.6  lukem 				col++;
    272  1.6  lukem 			else
    273  1.6  lukem 				if (*p == '\t')
    274  1.6  lukem 					col = ((col - 1) & ~7) + 9;
    275  1.6  lukem 				else
    276  1.6  lukem 					break;
    277  1.6  lukem 			p++;
    278  1.6  lukem 		}
    279  1.6  lukem 		if (col > ps.ind_size)
    280  1.6  lukem 			ps.ind_level = ps.i_l_follow = col / ps.ind_size;
    281  1.1    cgd 	}
    282  1.6  lukem 	if (troff) {
    283  1.6  lukem 		char   *p = in_name, *beg = in_name;
    284  1.6  lukem 
    285  1.6  lukem 		while (*p)
    286  1.6  lukem 			if (*p++ == '/')
    287  1.6  lukem 				beg = p;
    288  1.6  lukem 		fprintf(output, ".Fn \"%s\"\n", beg);
    289  1.1    cgd 	}
    290  1.6  lukem 	/*
    291  1.6  lukem          * START OF MAIN LOOP
    292  1.6  lukem          */
    293  1.1    cgd 
    294  1.6  lukem 	while (1) {		/* this is the main loop.  it will go until we
    295  1.1    cgd 				 * reach eof */
    296  1.6  lukem 		int     is_procname;
    297  1.1    cgd 
    298  1.6  lukem 		type_code = lexi();	/* lexi reads one token.  The actual
    299  1.6  lukem 					 * characters read are stored in
    300  1.6  lukem 					 * "token". lexi returns a code
    301  1.6  lukem 					 * indicating the type of token */
    302  1.6  lukem 		is_procname = ps.procname[0];
    303  1.1    cgd 
    304  1.6  lukem 		/*
    305  1.6  lukem 		 * The following code moves everything following an if (), while (),
    306  1.6  lukem 		 * else, etc. up to the start of the following stmt to a buffer. This
    307  1.6  lukem 		 * allows proper handling of both kinds of brace placement.
    308  1.6  lukem 		 */
    309  1.6  lukem 
    310  1.6  lukem 		flushed_nl = false;
    311  1.6  lukem 		while (ps.search_brace) {	/* if we scanned an if(),
    312  1.6  lukem 						 * while(), etc., we might
    313  1.6  lukem 						 * need to copy stuff into a
    314  1.6  lukem 						 * buffer we must loop,
    315  1.6  lukem 						 * copying stuff into
    316  1.6  lukem 						 * save_com, until we find the
    317  1.6  lukem 						 * start of the stmt which
    318  1.6  lukem 						 * follows the if, or whatever */
    319  1.6  lukem 			switch (type_code) {
    320  1.6  lukem 			case newline:
    321  1.6  lukem 				++line_no;
    322  1.6  lukem 				flushed_nl = true;
    323  1.6  lukem 			case form_feed:
    324  1.6  lukem 				break;	/* form feeds and newlines found here
    325  1.6  lukem 					 * will be ignored */
    326  1.6  lukem 
    327  1.6  lukem 			case lbrace:	/* this is a brace that starts the
    328  1.6  lukem 					 * compound stmt */
    329  1.6  lukem 				if (sc_end == 0) {	/* ignore buffering if a
    330  1.6  lukem 							 * comment wasnt stored
    331  1.6  lukem 							 * up */
    332  1.6  lukem 					ps.search_brace = false;
    333  1.6  lukem 					goto check_type;
    334  1.6  lukem 				}
    335  1.6  lukem 				if (btype_2) {
    336  1.6  lukem 					save_com[0] = '{';	/* we either want to put
    337  1.6  lukem 								 * the brace right after
    338  1.6  lukem 								 * the if */
    339  1.6  lukem 					goto sw_buffer;	/* go to common code to
    340  1.6  lukem 							 * get out of this loop */
    341  1.6  lukem 				}
    342  1.6  lukem 			case comment:	/* we have a comment, so we must copy
    343  1.6  lukem 					 * it into the buffer */
    344  1.6  lukem 				if (!flushed_nl || sc_end != 0) {
    345  1.6  lukem 					if (sc_end == 0) {	/* if this is the first
    346  1.6  lukem 								 * comment, we must set
    347  1.6  lukem 								 * up the buffer */
    348  1.6  lukem 						save_com[0] = save_com[1] = ' ';
    349  1.6  lukem 						sc_end = &(save_com[2]);
    350  1.6  lukem 					} else {
    351  1.6  lukem 						*sc_end++ = '\n';	/* add newline between
    352  1.6  lukem 									 * comments */
    353  1.6  lukem 						*sc_end++ = ' ';
    354  1.6  lukem 						--line_no;
    355  1.6  lukem 					}
    356  1.6  lukem 					*sc_end++ = '/';	/* copy in start of
    357  1.6  lukem 								 * comment */
    358  1.6  lukem 					*sc_end++ = '*';
    359  1.6  lukem 
    360  1.6  lukem 					for (;;) {	/* loop until we get to
    361  1.6  lukem 							 * the end of the
    362  1.6  lukem 							 * comment */
    363  1.6  lukem 						*sc_end = *buf_ptr++;
    364  1.6  lukem 						if (buf_ptr >= buf_end)
    365  1.6  lukem 							fill_buffer();
    366  1.6  lukem 
    367  1.6  lukem 						if (*sc_end++ == '*' && *buf_ptr == '/')
    368  1.6  lukem 							break;	/* we are at end of
    369  1.6  lukem 								 * comment */
    370  1.6  lukem 
    371  1.6  lukem 						if (sc_end >= &(save_com[sc_size])) {	/* check for temp buffer
    372  1.6  lukem 											 * overflow */
    373  1.6  lukem 							diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever.");
    374  1.6  lukem 							fflush(output);
    375  1.6  lukem 							exit(1);
    376  1.6  lukem 						}
    377  1.6  lukem 					}
    378  1.6  lukem 					*sc_end++ = '/';	/* add ending slash */
    379  1.6  lukem 					if (++buf_ptr >= buf_end)	/* get past / in buffer */
    380  1.6  lukem 						fill_buffer();
    381  1.6  lukem 					break;
    382  1.6  lukem 				}
    383  1.6  lukem 			default:	/* it is the start of a normal
    384  1.6  lukem 					 * statment */
    385  1.6  lukem 				if (flushed_nl)	/* if we flushed a newline,
    386  1.6  lukem 						 * make sure it is put back */
    387  1.6  lukem 					force_nl = true;
    388  1.6  lukem 				if ((type_code == sp_paren && *token == 'i'
    389  1.6  lukem 					&& last_else && ps.else_if) ||
    390  1.6  lukem 				    (type_code == sp_nparen && *token == 'e'
    391  1.6  lukem 					&& e_code != s_code && e_code[-1] == '}'))
    392  1.6  lukem 					force_nl = false;
    393  1.6  lukem 
    394  1.6  lukem 				if (sc_end == 0) {	/* ignore buffering if
    395  1.6  lukem 							 * comment wasnt saved
    396  1.6  lukem 							 * up */
    397  1.6  lukem 					ps.search_brace = false;
    398  1.6  lukem 					goto check_type;
    399  1.6  lukem 				}
    400  1.6  lukem 				if (force_nl) {	/* if we should insert a nl
    401  1.6  lukem 						 * here, put it into the
    402  1.6  lukem 						 * buffer */
    403  1.6  lukem 					force_nl = false;
    404  1.6  lukem 					--line_no;	/* this will be
    405  1.6  lukem 							 * re-increased when the
    406  1.6  lukem 							 * nl is read from the
    407  1.6  lukem 							 * buffer */
    408  1.6  lukem 					*sc_end++ = '\n';
    409  1.6  lukem 					*sc_end++ = ' ';
    410  1.6  lukem 					if (verbose && !flushed_nl)	/* print error msg if
    411  1.6  lukem 									 * the line was not
    412  1.6  lukem 									 * already broken */
    413  1.6  lukem 						diag(0, "Line broken");
    414  1.6  lukem 					flushed_nl = false;
    415  1.6  lukem 				}
    416  1.6  lukem 				for (t_ptr = token; *t_ptr; ++t_ptr)
    417  1.6  lukem 					*sc_end++ = *t_ptr;	/* copy token into temp
    418  1.6  lukem 								 * buffer */
    419  1.6  lukem 				ps.procname[0] = 0;
    420  1.6  lukem 
    421  1.6  lukem 		sw_buffer:
    422  1.6  lukem 				ps.search_brace = false;	/* stop looking for
    423  1.6  lukem 								 * start of stmt */
    424  1.6  lukem 				bp_save = buf_ptr;	/* save current input
    425  1.6  lukem 							 * buffer */
    426  1.6  lukem 				be_save = buf_end;
    427  1.6  lukem 				buf_ptr = save_com;	/* fix so that
    428  1.6  lukem 							 * subsequent calls to
    429  1.6  lukem 							 * lexi will take tokens
    430  1.6  lukem 							 * out of save_com */
    431  1.6  lukem 				*sc_end++ = ' ';	/* add trailing blank,
    432  1.6  lukem 							 * just in case */
    433  1.6  lukem 				buf_end = sc_end;
    434  1.6  lukem 				sc_end = 0;
    435  1.6  lukem 				break;
    436  1.6  lukem 			}	/* end of switch */
    437  1.6  lukem 			if (type_code != 0)	/* we must make this check,
    438  1.6  lukem 						 * just in case there was an
    439  1.6  lukem 						 * unexpected EOF */
    440  1.6  lukem 				type_code = lexi();	/* read another token */
    441  1.6  lukem 			/* if (ps.search_brace) ps.procname[0] = 0; */
    442  1.6  lukem 			if ((is_procname = ps.procname[0]) && flushed_nl
    443  1.6  lukem 			    && !procnames_start_line && ps.in_decl
    444  1.6  lukem 			    && type_code == ident)
    445  1.6  lukem 				flushed_nl = 0;
    446  1.6  lukem 		}		/* end of while (search_brace) */
    447  1.6  lukem 		last_else = 0;
    448  1.1    cgd check_type:
    449  1.6  lukem 		if (type_code == 0) {	/* we got eof */
    450  1.6  lukem 			if (s_lab != e_lab || s_code != e_code
    451  1.6  lukem 			    || s_com != e_com)	/* must dump end of line */
    452  1.6  lukem 				dump_line();
    453  1.6  lukem 			if (ps.tos > 1)	/* check for balanced braces */
    454  1.6  lukem 				diag(1, "Stuff missing from end of file.");
    455  1.6  lukem 
    456  1.6  lukem 			if (verbose) {
    457  1.6  lukem 				printf("There were %d output lines and %d comments\n",
    458  1.6  lukem 				    ps.out_lines, ps.out_coms);
    459  1.6  lukem 				printf("(Lines with comments)/(Lines with code): %6.3f\n",
    460  1.6  lukem 				    (1.0 * ps.com_lines) / code_lines);
    461  1.6  lukem 			}
    462  1.6  lukem 			fflush(output);
    463  1.6  lukem 			exit(found_err);
    464  1.1    cgd 		}
    465  1.6  lukem 		if (
    466  1.6  lukem 		    (type_code != comment) &&
    467  1.6  lukem 		    (type_code != newline) &&
    468  1.6  lukem 		    (type_code != preesc) &&
    469  1.6  lukem 		    (type_code != form_feed)) {
    470  1.6  lukem 			if (force_nl &&
    471  1.6  lukem 			    (type_code != semicolon) &&
    472  1.6  lukem 			    (type_code != lbrace || !btype_2)) {
    473  1.6  lukem 				/* we should force a broken line here */
    474  1.6  lukem 				if (verbose && !flushed_nl)
    475  1.6  lukem 					diag(0, "Line broken");
    476  1.6  lukem 				flushed_nl = false;
    477  1.6  lukem 				dump_line();
    478  1.6  lukem 				ps.want_blank = false;	/* dont insert blank at
    479  1.6  lukem 							 * line start */
    480  1.6  lukem 				force_nl = false;
    481  1.6  lukem 			}
    482  1.6  lukem 			ps.in_stmt = true;	/* turn on flag which causes
    483  1.6  lukem 						 * an extra level of
    484  1.6  lukem 						 * indentation. this is turned
    485  1.6  lukem 						 * off by a ; or '}' */
    486  1.6  lukem 			if (s_com != e_com) {	/* the turkey has embedded a
    487  1.6  lukem 						 * comment in a line. fix it */
    488  1.6  lukem 				*e_code++ = ' ';
    489  1.6  lukem 				for (t_ptr = s_com; *t_ptr; ++t_ptr) {
    490  1.6  lukem 					CHECK_SIZE_CODE;
    491  1.6  lukem 					*e_code++ = *t_ptr;
    492  1.6  lukem 				}
    493  1.6  lukem 				*e_code++ = ' ';
    494  1.6  lukem 				*e_code = '\0';	/* null terminate code sect */
    495  1.6  lukem 				ps.want_blank = false;
    496  1.6  lukem 				e_com = s_com;
    497  1.6  lukem 			}
    498  1.6  lukem 		} else
    499  1.6  lukem 			if (type_code != comment)	/* preserve force_nl
    500  1.6  lukem 							 * thru a comment */
    501  1.6  lukem 				force_nl = false;	/* cancel forced newline
    502  1.6  lukem 							 * after newline, form
    503  1.6  lukem 							 * feed, etc */
    504  1.1    cgd 
    505  1.1    cgd 
    506  1.1    cgd 
    507  1.6  lukem 		/*-----------------------------------------------------*\
    508  1.6  lukem 		|	   do switch on type of token scanned		|
    509  1.6  lukem 		\*-----------------------------------------------------*/
    510  1.6  lukem 		CHECK_SIZE_CODE;
    511  1.6  lukem 		switch (type_code) {	/* now, decide what to do with the
    512  1.6  lukem 					 * token */
    513  1.6  lukem 
    514  1.6  lukem 		case form_feed:/* found a form feed in line */
    515  1.6  lukem 			ps.use_ff = true;	/* a form feed is treated much
    516  1.6  lukem 						 * like a newline */
    517  1.6  lukem 			dump_line();
    518  1.6  lukem 			ps.want_blank = false;
    519  1.6  lukem 			break;
    520  1.6  lukem 
    521  1.6  lukem 		case newline:
    522  1.6  lukem 			if (ps.last_token != comma || ps.p_l_follow > 0
    523  1.6  lukem 			    || !ps.leave_comma || ps.block_init || !break_comma || s_com != e_com) {
    524  1.6  lukem 				dump_line();
    525  1.6  lukem 				ps.want_blank = false;
    526  1.6  lukem 			}
    527  1.6  lukem 			++line_no;	/* keep track of input line number */
    528  1.6  lukem 			break;
    529  1.1    cgd 
    530  1.6  lukem 		case lparen:	/* got a '(' or '[' */
    531  1.6  lukem 			++ps.p_l_follow;	/* count parens to make Healy
    532  1.6  lukem 						 * happy */
    533  1.6  lukem 			if (ps.want_blank && *token != '[' &&
    534  1.6  lukem 			    (ps.last_token != ident || proc_calls_space
    535  1.6  lukem 				|| (ps.its_a_keyword && (!ps.sizeof_keyword || Bill_Shannon))))
    536  1.6  lukem 				*e_code++ = ' ';
    537  1.6  lukem 			if (ps.in_decl && !ps.block_init)
    538  1.6  lukem 				if (troff && !ps.dumped_decl_indent && !is_procname && ps.last_token == decl) {
    539  1.6  lukem 					ps.dumped_decl_indent = 1;
    540  1.6  lukem 					sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
    541  1.6  lukem 					e_code += strlen(e_code);
    542  1.6  lukem 				} else {
    543  1.6  lukem 					while ((e_code - s_code) < dec_ind) {
    544  1.6  lukem 						CHECK_SIZE_CODE;
    545  1.6  lukem 						*e_code++ = ' ';
    546  1.6  lukem 					}
    547  1.6  lukem 					*e_code++ = token[0];
    548  1.6  lukem 				}
    549  1.6  lukem 			else
    550  1.6  lukem 				*e_code++ = token[0];
    551  1.6  lukem 			ps.paren_indents[ps.p_l_follow - 1] = e_code - s_code;
    552  1.6  lukem 			if (sp_sw && ps.p_l_follow == 1 && extra_expression_indent
    553  1.6  lukem 			    && ps.paren_indents[0] < 2 * ps.ind_size)
    554  1.6  lukem 				ps.paren_indents[0] = 2 * ps.ind_size;
    555  1.6  lukem 			ps.want_blank = false;
    556  1.6  lukem 			if (ps.in_or_st && *token == '(' && ps.tos <= 2) {
    557  1.6  lukem 				/*
    558  1.6  lukem 				 * this is a kluge to make sure that declarations will be
    559  1.6  lukem 				 * aligned right if proc decl has an explicit type on it, i.e.
    560  1.6  lukem 				 * "int a(x) {..."
    561  1.6  lukem 				 */
    562  1.6  lukem 				parse(semicolon);	/* I said this was a
    563  1.6  lukem 							 * kluge... */
    564  1.6  lukem 				ps.in_or_st = false;	/* turn off flag for
    565  1.6  lukem 							 * structure decl or
    566  1.6  lukem 							 * initialization */
    567  1.6  lukem 			}
    568  1.6  lukem 			if (ps.sizeof_keyword)
    569  1.6  lukem 				ps.sizeof_mask |= 1 << ps.p_l_follow;
    570  1.1    cgd 			break;
    571  1.6  lukem 
    572  1.6  lukem 		case rparen:	/* got a ')' or ']' */
    573  1.6  lukem 			rparen_count--;
    574  1.6  lukem 			if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) {
    575  1.6  lukem 				ps.last_u_d = true;
    576  1.6  lukem 				ps.cast_mask &= (1 << ps.p_l_follow) - 1;
    577  1.6  lukem 			}
    578  1.6  lukem 			ps.sizeof_mask &= (1 << ps.p_l_follow) - 1;
    579  1.6  lukem 			if (--ps.p_l_follow < 0) {
    580  1.6  lukem 				ps.p_l_follow = 0;
    581  1.6  lukem 				diag(0, "Extra %c", *token);
    582  1.6  lukem 			}
    583  1.6  lukem 			if (e_code == s_code)	/* if the paren starts the
    584  1.6  lukem 						 * line */
    585  1.6  lukem 				ps.paren_level = ps.p_l_follow;	/* then indent it */
    586  1.6  lukem 
    587  1.6  lukem 			*e_code++ = token[0];
    588  1.6  lukem 			ps.want_blank = true;
    589  1.6  lukem 
    590  1.6  lukem 			if (sp_sw && (ps.p_l_follow == 0)) {	/* check for end of if
    591  1.6  lukem 								 * (...), or some such */
    592  1.6  lukem 				sp_sw = false;
    593  1.6  lukem 				force_nl = true;	/* must force newline
    594  1.6  lukem 							 * after if */
    595  1.6  lukem 				ps.last_u_d = true;	/* inform lexi that a
    596  1.6  lukem 							 * following operator is
    597  1.6  lukem 							 * unary */
    598  1.6  lukem 				ps.in_stmt = false;	/* dont use stmt
    599  1.6  lukem 							 * continuation
    600  1.6  lukem 							 * indentation */
    601  1.6  lukem 
    602  1.6  lukem 				parse(hd_type);	/* let parser worry about if,
    603  1.6  lukem 						 * or whatever */
    604  1.6  lukem 			}
    605  1.6  lukem 			ps.search_brace = btype_2;	/* this should insure
    606  1.6  lukem 							 * that constructs such
    607  1.6  lukem 							 * as main(){...} and
    608  1.6  lukem 							 * int[]{...} have their
    609  1.6  lukem 							 * braces put in the
    610  1.6  lukem 							 * right place */
    611  1.1    cgd 			break;
    612  1.6  lukem 
    613  1.6  lukem 		case unary_op:	/* this could be any unary operation */
    614  1.6  lukem 			if (ps.want_blank)
    615  1.6  lukem 				*e_code++ = ' ';
    616  1.6  lukem 
    617  1.6  lukem 			if (troff && !ps.dumped_decl_indent && ps.in_decl && !is_procname) {
    618  1.6  lukem 				sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
    619  1.6  lukem 				ps.dumped_decl_indent = 1;
    620  1.6  lukem 				e_code += strlen(e_code);
    621  1.6  lukem 			} else {
    622  1.6  lukem 				char   *res = token;
    623  1.6  lukem 
    624  1.6  lukem 				if (ps.in_decl && !ps.block_init) {	/* if this is a unary op
    625  1.6  lukem 									 * in a declaration, we
    626  1.6  lukem 									 * should indent this
    627  1.6  lukem 									 * token */
    628  1.6  lukem 					for (i = 0; token[i]; ++i);	/* find length of token */
    629  1.6  lukem 					while ((e_code - s_code) < (dec_ind - i)) {
    630  1.6  lukem 						CHECK_SIZE_CODE;
    631  1.6  lukem 						*e_code++ = ' ';	/* pad it */
    632  1.6  lukem 					}
    633  1.6  lukem 				}
    634  1.6  lukem 				if (troff && token[0] == '-' && token[1] == '>')
    635  1.6  lukem 					res = "\\(->";
    636  1.6  lukem 				for (t_ptr = res; *t_ptr; ++t_ptr) {
    637  1.6  lukem 					CHECK_SIZE_CODE;
    638  1.6  lukem 					*e_code++ = *t_ptr;
    639  1.6  lukem 				}
    640  1.6  lukem 			}
    641  1.6  lukem 			ps.want_blank = false;
    642  1.1    cgd 			break;
    643  1.6  lukem 
    644  1.6  lukem 		case binary_op:/* any binary operation */
    645  1.6  lukem 			if (ps.want_blank)
    646  1.6  lukem 				*e_code++ = ' ';
    647  1.6  lukem 			{
    648  1.6  lukem 				char   *res = token;
    649  1.6  lukem 
    650  1.6  lukem 				if (troff)
    651  1.6  lukem 					switch (token[0]) {
    652  1.6  lukem 					case '<':
    653  1.6  lukem 						if (token[1] == '=')
    654  1.6  lukem 							res = "\\(<=";
    655  1.6  lukem 						break;
    656  1.6  lukem 					case '>':
    657  1.6  lukem 						if (token[1] == '=')
    658  1.6  lukem 							res = "\\(>=";
    659  1.6  lukem 						break;
    660  1.6  lukem 					case '!':
    661  1.6  lukem 						if (token[1] == '=')
    662  1.6  lukem 							res = "\\(!=";
    663  1.6  lukem 						break;
    664  1.6  lukem 					case '|':
    665  1.6  lukem 						if (token[1] == '|')
    666  1.6  lukem 							res = "\\(br\\(br";
    667  1.6  lukem 						else
    668  1.6  lukem 							if (token[1] == 0)
    669  1.6  lukem 								res = "\\(br";
    670  1.6  lukem 						break;
    671  1.6  lukem 					}
    672  1.6  lukem 				for (t_ptr = res; *t_ptr; ++t_ptr) {
    673  1.6  lukem 					CHECK_SIZE_CODE;
    674  1.6  lukem 					*e_code++ = *t_ptr;	/* move the operator */
    675  1.6  lukem 				}
    676  1.6  lukem 			}
    677  1.6  lukem 			ps.want_blank = true;
    678  1.1    cgd 			break;
    679  1.1    cgd 
    680  1.6  lukem 		case postop:	/* got a trailing ++ or -- */
    681  1.6  lukem 			*e_code++ = token[0];
    682  1.6  lukem 			*e_code++ = token[1];
    683  1.6  lukem 			ps.want_blank = true;
    684  1.6  lukem 			break;
    685  1.1    cgd 
    686  1.6  lukem 		case question:	/* got a ? */
    687  1.6  lukem 			squest++;	/* this will be used when a later
    688  1.6  lukem 					 * colon appears so we can distinguish
    689  1.6  lukem 					 * the <c>?<n>:<n> construct */
    690  1.6  lukem 			if (ps.want_blank)
    691  1.6  lukem 				*e_code++ = ' ';
    692  1.6  lukem 			*e_code++ = '?';
    693  1.6  lukem 			ps.want_blank = true;
    694  1.6  lukem 			break;
    695  1.1    cgd 
    696  1.6  lukem 		case casestmt:	/* got word 'case' or 'default' */
    697  1.6  lukem 			scase = true;	/* so we can process the later colon
    698  1.6  lukem 					 * properly */
    699  1.6  lukem 			goto copy_id;
    700  1.6  lukem 
    701  1.6  lukem 		case colon:	/* got a ':' */
    702  1.6  lukem 			if (squest > 0) {	/* it is part of the <c>?<n>:
    703  1.6  lukem 						 * <n> construct */
    704  1.6  lukem 				--squest;
    705  1.6  lukem 				if (ps.want_blank)
    706  1.6  lukem 					*e_code++ = ' ';
    707  1.6  lukem 				*e_code++ = ':';
    708  1.6  lukem 				ps.want_blank = true;
    709  1.6  lukem 				break;
    710  1.6  lukem 			}
    711  1.6  lukem 			if (ps.in_decl) {
    712  1.6  lukem 				*e_code++ = ':';
    713  1.6  lukem 				ps.want_blank = false;
    714  1.6  lukem 				break;
    715  1.6  lukem 			}
    716  1.6  lukem 			ps.in_stmt = false;	/* seeing a label does not
    717  1.6  lukem 						 * imply we are in a stmt */
    718  1.6  lukem 			for (t_ptr = s_code; *t_ptr; ++t_ptr)
    719  1.6  lukem 				*e_lab++ = *t_ptr;	/* turn everything so
    720  1.6  lukem 							 * far into a label */
    721  1.6  lukem 			e_code = s_code;
    722  1.6  lukem 			*e_lab++ = ':';
    723  1.6  lukem 			*e_lab++ = ' ';
    724  1.6  lukem 			*e_lab = '\0';
    725  1.6  lukem 
    726  1.6  lukem 			force_nl = ps.pcase = scase;	/* ps.pcase will be used
    727  1.6  lukem 							 * by dump_line to
    728  1.6  lukem 							 * decide how to indent
    729  1.6  lukem 							 * the label. force_nl
    730  1.6  lukem 							 * will force a case n:
    731  1.6  lukem 							 * to be on a line by
    732  1.6  lukem 							 * itself */
    733  1.6  lukem 			scase = false;
    734  1.6  lukem 			ps.want_blank = false;
    735  1.6  lukem 			break;
    736  1.1    cgd 
    737  1.6  lukem 		case semicolon:/* got a ';' */
    738  1.6  lukem 			ps.in_or_st = false;	/* we are not in an
    739  1.6  lukem 						 * initialization or structure
    740  1.6  lukem 						 * declaration */
    741  1.6  lukem 			scase = false;	/* these will only need resetting in a
    742  1.6  lukem 					 * error */
    743  1.6  lukem 			squest = 0;
    744  1.6  lukem 			if (ps.last_token == rparen && rparen_count == 0)
    745  1.6  lukem 				ps.in_parameter_declaration = 0;
    746  1.6  lukem 			ps.cast_mask = 0;
    747  1.6  lukem 			ps.sizeof_mask = 0;
    748  1.6  lukem 			ps.block_init = 0;
    749  1.6  lukem 			ps.block_init_level = 0;
    750  1.6  lukem 			ps.just_saw_decl--;
    751  1.6  lukem 
    752  1.6  lukem 			if (ps.in_decl && s_code == e_code && !ps.block_init)
    753  1.6  lukem 				while ((e_code - s_code) < (dec_ind - 1)) {
    754  1.6  lukem 					CHECK_SIZE_CODE;
    755  1.6  lukem 					*e_code++ = ' ';
    756  1.6  lukem 				}
    757  1.6  lukem 
    758  1.6  lukem 			ps.in_decl = (ps.dec_nest > 0);	/* if we were in a first
    759  1.6  lukem 							 * level structure
    760  1.6  lukem 							 * declaration, we arent
    761  1.6  lukem 							 * any more */
    762  1.6  lukem 
    763  1.6  lukem 			if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0) {
    764  1.6  lukem 
    765  1.6  lukem 				/*
    766  1.6  lukem 				 * This should be true iff there were unbalanced parens in the
    767  1.6  lukem 				 * stmt.  It is a bit complicated, because the semicolon might
    768  1.6  lukem 				 * be in a for stmt
    769  1.6  lukem 				 */
    770  1.6  lukem 				diag(1, "Unbalanced parens");
    771  1.6  lukem 				ps.p_l_follow = 0;
    772  1.6  lukem 				if (sp_sw) {	/* this is a check for a if,
    773  1.6  lukem 						 * while, etc. with unbalanced
    774  1.6  lukem 						 * parens */
    775  1.6  lukem 					sp_sw = false;
    776  1.6  lukem 					parse(hd_type);	/* dont lose the if, or
    777  1.6  lukem 							 * whatever */
    778  1.6  lukem 				}
    779  1.6  lukem 			}
    780  1.6  lukem 			*e_code++ = ';';
    781  1.6  lukem 			ps.want_blank = true;
    782  1.6  lukem 			ps.in_stmt = (ps.p_l_follow > 0);	/* we are no longer in
    783  1.6  lukem 								 * the middle of a stmt */
    784  1.6  lukem 
    785  1.6  lukem 			if (!sp_sw) {	/* if not if for (;;) */
    786  1.6  lukem 				parse(semicolon);	/* let parser know about
    787  1.6  lukem 							 * end of stmt */
    788  1.6  lukem 				force_nl = true;	/* force newline after a
    789  1.6  lukem 							 * end of stmt */
    790  1.1    cgd 			}
    791  1.6  lukem 			break;
    792  1.6  lukem 
    793  1.6  lukem 		case lbrace:	/* got a '{' */
    794  1.6  lukem 			ps.in_stmt = false;	/* dont indent the {} */
    795  1.6  lukem 			if (!ps.block_init)
    796  1.6  lukem 				force_nl = true;	/* force other stuff on
    797  1.6  lukem 							 * same line as '{' onto
    798  1.6  lukem 							 * new line */
    799  1.1    cgd 			else
    800  1.6  lukem 				if (ps.block_init_level <= 0)
    801  1.6  lukem 					ps.block_init_level = 1;
    802  1.6  lukem 				else
    803  1.6  lukem 					ps.block_init_level++;
    804  1.6  lukem 
    805  1.6  lukem 			if (s_code != e_code && !ps.block_init) {
    806  1.6  lukem 				if (!btype_2) {
    807  1.6  lukem 					dump_line();
    808  1.6  lukem 					ps.want_blank = false;
    809  1.6  lukem 				} else
    810  1.6  lukem 					if (ps.in_parameter_declaration && !ps.in_or_st) {
    811  1.6  lukem 						ps.i_l_follow = 0;
    812  1.6  lukem 						dump_line();
    813  1.6  lukem 						ps.want_blank = false;
    814  1.6  lukem 					}
    815  1.6  lukem 			}
    816  1.6  lukem 			if (ps.in_parameter_declaration)
    817  1.6  lukem 				prefix_blankline_requested = 0;
    818  1.6  lukem 
    819  1.6  lukem 			if (ps.p_l_follow > 0) {	/* check for preceeding
    820  1.6  lukem 							 * unbalanced parens */
    821  1.6  lukem 				diag(1, "Unbalanced parens");
    822  1.6  lukem 				ps.p_l_follow = 0;
    823  1.6  lukem 				if (sp_sw) {	/* check for unclosed if, for,
    824  1.6  lukem 						 * etc. */
    825  1.6  lukem 					sp_sw = false;
    826  1.6  lukem 					parse(hd_type);
    827  1.6  lukem 					ps.ind_level = ps.i_l_follow;
    828  1.6  lukem 				}
    829  1.6  lukem 			}
    830  1.6  lukem 			if (s_code == e_code)
    831  1.6  lukem 				ps.ind_stmt = false;	/* dont put extra
    832  1.6  lukem 							 * indentation on line
    833  1.6  lukem 							 * with '{' */
    834  1.6  lukem 			if (ps.in_decl && ps.in_or_st) {	/* this is either a
    835  1.6  lukem 								 * structure declaration
    836  1.6  lukem 								 * or an init */
    837  1.6  lukem 				di_stack[ps.dec_nest++] = dec_ind;
    838  1.6  lukem 				/* ?		dec_ind = 0; */
    839  1.6  lukem 			} else {
    840  1.6  lukem 				ps.decl_on_line = false;	/* we cant be in the
    841  1.6  lukem 								 * middle of a
    842  1.6  lukem 								 * declaration, so dont
    843  1.6  lukem 								 * do special
    844  1.6  lukem 								 * indentation of
    845  1.6  lukem 								 * comments */
    846  1.6  lukem 				if (blanklines_after_declarations_at_proctop
    847  1.6  lukem 				    && ps.in_parameter_declaration)
    848  1.6  lukem 					postfix_blankline_requested = 1;
    849  1.6  lukem 				ps.in_parameter_declaration = 0;
    850  1.6  lukem 			}
    851  1.6  lukem 			dec_ind = 0;
    852  1.6  lukem 			parse(lbrace);	/* let parser know about this */
    853  1.6  lukem 			if (ps.want_blank)	/* put a blank before '{' if
    854  1.6  lukem 						 * '{' is not at start of line */
    855  1.1    cgd 				*e_code++ = ' ';
    856  1.6  lukem 			ps.want_blank = false;
    857  1.6  lukem 			*e_code++ = '{';
    858  1.6  lukem 			ps.just_saw_decl = 0;
    859  1.6  lukem 			break;
    860  1.6  lukem 
    861  1.6  lukem 		case rbrace:	/* got a '}' */
    862  1.6  lukem 			if (ps.p_stack[ps.tos] == decl && !ps.block_init)	/* semicolons can be
    863  1.6  lukem 										 * omitted in
    864  1.6  lukem 										 * declarations */
    865  1.6  lukem 				parse(semicolon);
    866  1.6  lukem 			if (ps.p_l_follow) {	/* check for unclosed if, for,
    867  1.6  lukem 						 * else. */
    868  1.6  lukem 				diag(1, "Unbalanced parens");
    869  1.6  lukem 				ps.p_l_follow = 0;
    870  1.6  lukem 				sp_sw = false;
    871  1.6  lukem 			}
    872  1.6  lukem 			ps.just_saw_decl = 0;
    873  1.6  lukem 			ps.block_init_level--;
    874  1.6  lukem 			if (s_code != e_code && !ps.block_init) {	/* '}' must be first on
    875  1.6  lukem 									 * line */
    876  1.6  lukem 				if (verbose)
    877  1.6  lukem 					diag(0, "Line broken");
    878  1.6  lukem 				dump_line();
    879  1.6  lukem 			}
    880  1.6  lukem 			*e_code++ = '}';
    881  1.6  lukem 			ps.want_blank = true;
    882  1.6  lukem 			ps.in_stmt = ps.ind_stmt = false;
    883  1.6  lukem 			if (ps.dec_nest > 0) {	/* we are in multi-level
    884  1.6  lukem 						 * structure declaration */
    885  1.6  lukem 				dec_ind = di_stack[--ps.dec_nest];
    886  1.6  lukem 				if (ps.dec_nest == 0 && !ps.in_parameter_declaration)
    887  1.6  lukem 					ps.just_saw_decl = 2;
    888  1.6  lukem 				ps.in_decl = true;
    889  1.6  lukem 			}
    890  1.6  lukem 			prefix_blankline_requested = 0;
    891  1.6  lukem 			parse(rbrace);	/* let parser know about this */
    892  1.6  lukem 			ps.search_brace = cuddle_else && ps.p_stack[ps.tos] == ifhead
    893  1.6  lukem 			    && ps.il[ps.tos] >= ps.ind_level;
    894  1.6  lukem 			if (ps.tos <= 1 && blanklines_after_procs && ps.dec_nest <= 0)
    895  1.6  lukem 				postfix_blankline_requested = 1;
    896  1.6  lukem 			break;
    897  1.1    cgd 
    898  1.6  lukem 		case swstmt:	/* got keyword "switch" */
    899  1.6  lukem 			sp_sw = true;
    900  1.6  lukem 			hd_type = swstmt;	/* keep this for when we have
    901  1.6  lukem 						 * seen the expression */
    902  1.6  lukem 			goto copy_id;	/* go move the token into buffer */
    903  1.6  lukem 
    904  1.6  lukem 		case sp_paren:	/* token is if, while, for */
    905  1.6  lukem 			sp_sw = true;	/* the interesting stuff is done after
    906  1.6  lukem 					 * the expression is scanned */
    907  1.6  lukem 			hd_type = (*token == 'i' ? ifstmt :
    908  1.6  lukem 			    (*token == 'w' ? whilestmt : forstmt));
    909  1.6  lukem 
    910  1.6  lukem 			/*
    911  1.6  lukem 		         * remember the type of header for later use by parser
    912  1.6  lukem 		         */
    913  1.6  lukem 			goto copy_id;	/* copy the token into line */
    914  1.6  lukem 
    915  1.6  lukem 		case sp_nparen:/* got else, do */
    916  1.6  lukem 			ps.in_stmt = false;
    917  1.6  lukem 			if (*token == 'e') {
    918  1.6  lukem 				if (e_code != s_code && (!cuddle_else || e_code[-1] != '}')) {
    919  1.6  lukem 					if (verbose)
    920  1.6  lukem 						diag(0, "Line broken");
    921  1.6  lukem 					dump_line();	/* make sure this starts
    922  1.6  lukem 							 * a line */
    923  1.6  lukem 					ps.want_blank = false;
    924  1.6  lukem 				}
    925  1.6  lukem 				force_nl = true;	/* also, following stuff
    926  1.6  lukem 							 * must go onto new line */
    927  1.6  lukem 				last_else = 1;
    928  1.6  lukem 				parse(elselit);
    929  1.6  lukem 			} else {
    930  1.6  lukem 				if (e_code != s_code) {	/* make sure this starts
    931  1.6  lukem 							 * a line */
    932  1.6  lukem 					if (verbose)
    933  1.6  lukem 						diag(0, "Line broken");
    934  1.6  lukem 					dump_line();
    935  1.6  lukem 					ps.want_blank = false;
    936  1.6  lukem 				}
    937  1.6  lukem 				force_nl = true;	/* also, following stuff
    938  1.6  lukem 							 * must go onto new line */
    939  1.6  lukem 				last_else = 0;
    940  1.6  lukem 				parse(dolit);
    941  1.6  lukem 			}
    942  1.6  lukem 			goto copy_id;	/* move the token into line */
    943  1.1    cgd 
    944  1.6  lukem 		case decl:	/* we have a declaration type (int, register,
    945  1.6  lukem 				 * etc.) */
    946  1.6  lukem 			parse(decl);	/* let parser worry about indentation */
    947  1.6  lukem 			if (ps.last_token == rparen && ps.tos <= 1) {
    948  1.6  lukem 				ps.in_parameter_declaration = 1;
    949  1.6  lukem 				if (s_code != e_code) {
    950  1.6  lukem 					dump_line();
    951  1.6  lukem 					ps.want_blank = 0;
    952  1.6  lukem 				}
    953  1.1    cgd 			}
    954  1.6  lukem 			if (ps.in_parameter_declaration && ps.indent_parameters && ps.dec_nest == 0) {
    955  1.6  lukem 				ps.ind_level = ps.i_l_follow = 1;
    956  1.6  lukem 				ps.ind_stmt = 0;
    957  1.1    cgd 			}
    958  1.6  lukem 			ps.in_or_st = true;	/* this might be a structure
    959  1.6  lukem 						 * or initialization
    960  1.6  lukem 						 * declaration */
    961  1.6  lukem 			ps.in_decl = ps.decl_on_line = true;
    962  1.6  lukem 			if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
    963  1.6  lukem 				ps.just_saw_decl = 2;
    964  1.6  lukem 			prefix_blankline_requested = 0;
    965  1.6  lukem 			for (i = 0; token[i++];);	/* get length of token */
    966  1.6  lukem 
    967  1.6  lukem 			/*
    968  1.6  lukem 		         * dec_ind = e_code - s_code + (ps.decl_indent>i ? ps.decl_indent
    969  1.6  lukem 		         * : i);
    970  1.6  lukem 		         */
    971  1.6  lukem 			dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
    972  1.6  lukem 			goto copy_id;
    973  1.6  lukem 
    974  1.6  lukem 		case ident:	/* got an identifier or constant */
    975  1.6  lukem 			if (ps.in_decl) {	/* if we are in a declaration,
    976  1.6  lukem 						 * we must indent identifier */
    977  1.6  lukem 				if (ps.want_blank)
    978  1.6  lukem 					*e_code++ = ' ';
    979  1.6  lukem 				ps.want_blank = false;
    980  1.6  lukem 				if (is_procname == 0 || !procnames_start_line) {
    981  1.7   ross 					if (!ps.block_init) {
    982  1.6  lukem 						if (troff && !ps.dumped_decl_indent) {
    983  1.6  lukem 							sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
    984  1.6  lukem 							ps.dumped_decl_indent = 1;
    985  1.6  lukem 							e_code += strlen(e_code);
    986  1.6  lukem 						} else
    987  1.6  lukem 							while ((e_code - s_code) < dec_ind) {
    988  1.6  lukem 								CHECK_SIZE_CODE;
    989  1.6  lukem 								*e_code++ = ' ';
    990  1.6  lukem 							}
    991  1.7   ross 					}
    992  1.6  lukem 				} else {
    993  1.6  lukem 					if (dec_ind && s_code != e_code)
    994  1.6  lukem 						dump_line();
    995  1.6  lukem 					dec_ind = 0;
    996  1.6  lukem 					ps.want_blank = false;
    997  1.6  lukem 				}
    998  1.6  lukem 			} else
    999  1.6  lukem 				if (sp_sw && ps.p_l_follow == 0) {
   1000  1.6  lukem 					sp_sw = false;
   1001  1.6  lukem 					force_nl = true;
   1002  1.6  lukem 					ps.last_u_d = true;
   1003  1.6  lukem 					ps.in_stmt = false;
   1004  1.6  lukem 					parse(hd_type);
   1005  1.6  lukem 				}
   1006  1.6  lukem 	copy_id:
   1007  1.6  lukem 			if (ps.want_blank)
   1008  1.6  lukem 				*e_code++ = ' ';
   1009  1.6  lukem 			if (troff && ps.its_a_keyword) {
   1010  1.6  lukem 				e_code = chfont(&bodyf, &keywordf, e_code);
   1011  1.6  lukem 				for (t_ptr = token; *t_ptr; ++t_ptr) {
   1012  1.6  lukem 					CHECK_SIZE_CODE;
   1013  1.6  lukem 					*e_code++ = keywordf.allcaps && islower(*t_ptr)
   1014  1.6  lukem 					    ? toupper(*t_ptr) : *t_ptr;
   1015  1.6  lukem 				}
   1016  1.6  lukem 				e_code = chfont(&keywordf, &bodyf, e_code);
   1017  1.6  lukem 			} else
   1018  1.6  lukem 				for (t_ptr = token; *t_ptr; ++t_ptr) {
   1019  1.6  lukem 					CHECK_SIZE_CODE;
   1020  1.6  lukem 					*e_code++ = *t_ptr;
   1021  1.6  lukem 				}
   1022  1.6  lukem 			ps.want_blank = true;
   1023  1.1    cgd 			break;
   1024  1.6  lukem 
   1025  1.6  lukem 		case period:	/* treat a period kind of like a binary
   1026  1.6  lukem 				 * operation */
   1027  1.6  lukem 			*e_code++ = '.';	/* move the period into line */
   1028  1.6  lukem 			ps.want_blank = false;	/* dont put a blank after a
   1029  1.6  lukem 						 * period */
   1030  1.1    cgd 			break;
   1031  1.6  lukem 
   1032  1.6  lukem 		case comma:
   1033  1.6  lukem 			ps.want_blank = (s_code != e_code);	/* only put blank after
   1034  1.6  lukem 								 * comma if comma does
   1035  1.6  lukem 								 * not start the line */
   1036  1.6  lukem 			if (ps.in_decl && is_procname == 0 && !ps.block_init)
   1037  1.6  lukem 				while ((e_code - s_code) < (dec_ind - 1)) {
   1038  1.6  lukem 					CHECK_SIZE_CODE;
   1039  1.6  lukem 					*e_code++ = ' ';
   1040  1.6  lukem 				}
   1041  1.6  lukem 
   1042  1.6  lukem 			*e_code++ = ',';
   1043  1.6  lukem 			if (ps.p_l_follow == 0) {
   1044  1.6  lukem 				if (ps.block_init_level <= 0)
   1045  1.6  lukem 					ps.block_init = 0;
   1046  1.6  lukem 				if (break_comma && (!ps.leave_comma || compute_code_target() + (e_code - s_code) > max_col - 8))
   1047  1.6  lukem 					force_nl = true;
   1048  1.6  lukem 			}
   1049  1.1    cgd 			break;
   1050  1.6  lukem 
   1051  1.6  lukem 		case preesc:	/* got the character '#' */
   1052  1.6  lukem 			if ((s_com != e_com) ||
   1053  1.6  lukem 			    (s_lab != e_lab) ||
   1054  1.6  lukem 			    (s_code != e_code))
   1055  1.6  lukem 				dump_line();
   1056  1.6  lukem 			*e_lab++ = '#';	/* move whole line to 'label' buffer */
   1057  1.6  lukem 			{
   1058  1.6  lukem 				int     in_comment = 0;
   1059  1.6  lukem 				int     com_start = 0;
   1060  1.6  lukem 				char    quote = 0;
   1061  1.6  lukem 				int     com_end = 0;
   1062  1.6  lukem 
   1063  1.6  lukem 				while (*buf_ptr == ' ' || *buf_ptr == '\t') {
   1064  1.6  lukem 					buf_ptr++;
   1065  1.6  lukem 					if (buf_ptr >= buf_end)
   1066  1.6  lukem 						fill_buffer();
   1067  1.6  lukem 				}
   1068  1.6  lukem 				while (*buf_ptr != '\n' || in_comment) {
   1069  1.6  lukem 					CHECK_SIZE_LAB;
   1070  1.6  lukem 					*e_lab = *buf_ptr++;
   1071  1.6  lukem 					if (buf_ptr >= buf_end)
   1072  1.6  lukem 						fill_buffer();
   1073  1.6  lukem 					switch (*e_lab++) {
   1074  1.6  lukem 					case BACKSLASH:
   1075  1.6  lukem 						if (troff)
   1076  1.6  lukem 							*e_lab++ = BACKSLASH;
   1077  1.6  lukem 						if (!in_comment) {
   1078  1.6  lukem 							*e_lab++ = *buf_ptr++;
   1079  1.6  lukem 							if (buf_ptr >= buf_end)
   1080  1.6  lukem 								fill_buffer();
   1081  1.6  lukem 						}
   1082  1.6  lukem 						break;
   1083  1.6  lukem 					case '/':
   1084  1.6  lukem 						if (*buf_ptr == '*' && !in_comment && !quote) {
   1085  1.6  lukem 							in_comment = 1;
   1086  1.6  lukem 							*e_lab++ = *buf_ptr++;
   1087  1.6  lukem 							com_start = e_lab - s_lab - 2;
   1088  1.6  lukem 						}
   1089  1.6  lukem 						break;
   1090  1.6  lukem 					case '"':
   1091  1.6  lukem 						if (quote == '"')
   1092  1.6  lukem 							quote = 0;
   1093  1.6  lukem 						break;
   1094  1.6  lukem 					case '\'':
   1095  1.6  lukem 						if (quote == '\'')
   1096  1.6  lukem 							quote = 0;
   1097  1.6  lukem 						break;
   1098  1.6  lukem 					case '*':
   1099  1.6  lukem 						if (*buf_ptr == '/' && in_comment) {
   1100  1.6  lukem 							in_comment = 0;
   1101  1.6  lukem 							*e_lab++ = *buf_ptr++;
   1102  1.6  lukem 							com_end = e_lab - s_lab;
   1103  1.6  lukem 						}
   1104  1.6  lukem 						break;
   1105  1.6  lukem 					}
   1106  1.6  lukem 				}
   1107  1.6  lukem 
   1108  1.6  lukem 				while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
   1109  1.6  lukem 					e_lab--;
   1110  1.6  lukem 				if (e_lab - s_lab == com_end && bp_save == 0) {	/* comment on
   1111  1.6  lukem 										 * preprocessor line */
   1112  1.6  lukem 					if (sc_end == 0)	/* if this is the first
   1113  1.6  lukem 								 * comment, we must set
   1114  1.6  lukem 								 * up the buffer */
   1115  1.6  lukem 						sc_end = &(save_com[0]);
   1116  1.6  lukem 					else {
   1117  1.6  lukem 						*sc_end++ = '\n';	/* add newline between
   1118  1.6  lukem 									 * comments */
   1119  1.6  lukem 						*sc_end++ = ' ';
   1120  1.6  lukem 						--line_no;
   1121  1.6  lukem 					}
   1122  1.6  lukem 					memmove(sc_end, s_lab + com_start, com_end - com_start);
   1123  1.6  lukem 					sc_end += com_end - com_start;
   1124  1.6  lukem 					if (sc_end >= &save_com[sc_size])
   1125  1.6  lukem 						abort();
   1126  1.6  lukem 					e_lab = s_lab + com_start;
   1127  1.6  lukem 					while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
   1128  1.6  lukem 						e_lab--;
   1129  1.6  lukem 					bp_save = buf_ptr;	/* save current input
   1130  1.6  lukem 								 * buffer */
   1131  1.6  lukem 					be_save = buf_end;
   1132  1.6  lukem 					buf_ptr = save_com;	/* fix so that
   1133  1.6  lukem 								 * subsequent calls to
   1134  1.6  lukem 								 * lexi will take tokens
   1135  1.6  lukem 								 * out of save_com */
   1136  1.6  lukem 					*sc_end++ = ' ';	/* add trailing blank,
   1137  1.6  lukem 								 * just in case */
   1138  1.6  lukem 					buf_end = sc_end;
   1139  1.6  lukem 					sc_end = 0;
   1140  1.6  lukem 				}
   1141  1.6  lukem 				*e_lab = '\0';	/* null terminate line */
   1142  1.6  lukem 				ps.pcase = false;
   1143  1.1    cgd 			}
   1144  1.1    cgd 
   1145  1.6  lukem 			if (strncmp(s_lab, "#if", 3) == 0) {
   1146  1.6  lukem 				if (blanklines_around_conditional_compilation) {
   1147  1.6  lukem 					int     c;
   1148  1.6  lukem 					prefix_blankline_requested++;
   1149  1.6  lukem 					while ((c = getc(input)) == '\n');
   1150  1.6  lukem 					ungetc(c, input);
   1151  1.6  lukem 				}
   1152  1.6  lukem 				if (ifdef_level < sizeof state_stack / sizeof state_stack[0]) {
   1153  1.6  lukem 					match_state[ifdef_level].tos = -1;
   1154  1.6  lukem 					state_stack[ifdef_level++] = ps;
   1155  1.6  lukem 				} else
   1156  1.6  lukem 					diag(1, "#if stack overflow");
   1157  1.6  lukem 			} else
   1158  1.6  lukem 				if (strncmp(s_lab, "#else", 5) == 0)
   1159  1.6  lukem 					if (ifdef_level <= 0)
   1160  1.6  lukem 						diag(1, "Unmatched #else");
   1161  1.6  lukem 					else {
   1162  1.6  lukem 						match_state[ifdef_level - 1] = ps;
   1163  1.6  lukem 						ps = state_stack[ifdef_level - 1];
   1164  1.6  lukem 					}
   1165  1.6  lukem 				else
   1166  1.6  lukem 					if (strncmp(s_lab, "#endif", 6) == 0) {
   1167  1.6  lukem 						if (ifdef_level <= 0)
   1168  1.6  lukem 							diag(1, "Unmatched #endif");
   1169  1.6  lukem 						else {
   1170  1.6  lukem 							ifdef_level--;
   1171  1.1    cgd 
   1172  1.1    cgd #ifdef undef
   1173  1.6  lukem 							/*
   1174  1.6  lukem 						         * This match needs to be more intelligent before the
   1175  1.6  lukem 						         * message is useful
   1176  1.6  lukem 						         */
   1177  1.6  lukem 							if (match_state[ifdef_level].tos >= 0
   1178  1.6  lukem 							    && memcmp(&ps, &match_state[ifdef_level], sizeof ps))
   1179  1.6  lukem 								diag(0, "Syntactically inconsistant #ifdef alternatives.");
   1180  1.1    cgd #endif
   1181  1.6  lukem 						}
   1182  1.6  lukem 						if (blanklines_around_conditional_compilation) {
   1183  1.6  lukem 							postfix_blankline_requested++;
   1184  1.6  lukem 							n_real_blanklines = 0;
   1185  1.6  lukem 						}
   1186  1.6  lukem 					}
   1187  1.6  lukem 			break;	/* subsequent processing of the newline
   1188  1.1    cgd 				 * character will cause the line to be printed */
   1189  1.1    cgd 
   1190  1.6  lukem 		case comment:	/* we have gotten a start comment */
   1191  1.6  lukem 			/* this is a biggie */
   1192  1.6  lukem 			if (flushed_nl) {	/* we should force a broken
   1193  1.6  lukem 						 * line here */
   1194  1.6  lukem 				flushed_nl = false;
   1195  1.6  lukem 				dump_line();
   1196  1.6  lukem 				ps.want_blank = false;	/* dont insert blank at
   1197  1.6  lukem 							 * line start */
   1198  1.6  lukem 				force_nl = false;
   1199  1.6  lukem 			}
   1200  1.6  lukem 			pr_comment();
   1201  1.6  lukem 			break;
   1202  1.6  lukem 		}		/* end of big switch stmt */
   1203  1.6  lukem 
   1204  1.6  lukem 		*e_code = '\0';	/* make sure code section is null terminated */
   1205  1.6  lukem 		if (type_code != comment && type_code != newline && type_code != preesc)
   1206  1.6  lukem 			ps.last_token = type_code;
   1207  1.6  lukem 	}			/* end of main while (1) loop */
   1208  1.1    cgd }
   1209  1.1    cgd /*
   1210  1.1    cgd  * copy input file to backup file if in_name is /blah/blah/blah/file, then
   1211  1.1    cgd  * backup file will be ".Bfile" then make the backup file the input and
   1212  1.1    cgd  * original input file the output
   1213  1.1    cgd  */
   1214  1.6  lukem void
   1215  1.1    cgd bakcopy()
   1216  1.1    cgd {
   1217  1.6  lukem 	int     n, bakchn;
   1218  1.6  lukem 	char    buff[8 * 1024];
   1219  1.6  lukem 	char   *p;
   1220  1.6  lukem 
   1221  1.6  lukem 	/* construct file name .Bfile */
   1222  1.6  lukem 	for (p = in_name; *p; p++);	/* skip to end of string */
   1223  1.6  lukem 	while (p > in_name && *p != '/')	/* find last '/' */
   1224  1.6  lukem 		p--;
   1225  1.6  lukem 	if (*p == '/')
   1226  1.6  lukem 		p++;
   1227  1.6  lukem 	sprintf(bakfile, "%s.BAK", p);
   1228  1.6  lukem 
   1229  1.6  lukem 	/* copy in_name to backup file */
   1230  1.6  lukem 	bakchn = creat(bakfile, 0600);
   1231  1.6  lukem 	if (bakchn < 0)
   1232  1.6  lukem 		err(1, "%s", bakfile);
   1233  1.6  lukem 	while ((n = read(fileno(input), buff, sizeof buff)) > 0)
   1234  1.6  lukem 		if (write(bakchn, buff, n) != n)
   1235  1.6  lukem 			err(1, "%s", bakfile);
   1236  1.6  lukem 	if (n < 0)
   1237  1.6  lukem 		err(1, "%s", in_name);
   1238  1.6  lukem 	close(bakchn);
   1239  1.6  lukem 	fclose(input);
   1240  1.6  lukem 
   1241  1.6  lukem 	/* re-open backup file as the input file */
   1242  1.6  lukem 	input = fopen(bakfile, "r");
   1243  1.6  lukem 	if (input == 0)
   1244  1.6  lukem 		err(1, "%s", bakfile);
   1245  1.6  lukem 	/* now the original input file will be the output */
   1246  1.6  lukem 	output = fopen(in_name, "w");
   1247  1.6  lukem 	if (output == 0) {
   1248  1.6  lukem 		unlink(bakfile);
   1249  1.6  lukem 		err(1, "%s", in_name);
   1250  1.6  lukem 	}
   1251  1.1    cgd }
   1252