Home | History | Annotate | Line # | Download | only in indent
pr_comment.c revision 1.9
      1  1.9       agc /*	$NetBSD: pr_comment.c,v 1.9 2003/08/07 11:14:09 agc 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.9       agc  *
      7  1.9       agc  * Redistribution and use in source and binary forms, with or without
      8  1.9       agc  * modification, are permitted provided that the following conditions
      9  1.9       agc  * are met:
     10  1.9       agc  * 1. Redistributions of source code must retain the above copyright
     11  1.9       agc  *    notice, this list of conditions and the following disclaimer.
     12  1.9       agc  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.9       agc  *    notice, this list of conditions and the following disclaimer in the
     14  1.9       agc  *    documentation and/or other materials provided with the distribution.
     15  1.9       agc  * 3. Neither the name of the University nor the names of its contributors
     16  1.9       agc  *    may be used to endorse or promote products derived from this software
     17  1.9       agc  *    without specific prior written permission.
     18  1.9       agc  *
     19  1.9       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  1.9       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.9       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.9       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  1.9       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.9       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.9       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.9       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.9       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.9       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.9       agc  * SUCH DAMAGE.
     30  1.9       agc  */
     31  1.9       agc 
     32  1.9       agc /*
     33  1.5       mrg  * Copyright (c) 1976 Board of Trustees of the University of Illinois.
     34  1.1       cgd  * Copyright (c) 1985 Sun Microsystems, Inc.
     35  1.1       cgd  * All rights reserved.
     36  1.1       cgd  *
     37  1.1       cgd  * Redistribution and use in source and binary forms, with or without
     38  1.1       cgd  * modification, are permitted provided that the following conditions
     39  1.1       cgd  * are met:
     40  1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     41  1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     42  1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     44  1.1       cgd  *    documentation and/or other materials provided with the distribution.
     45  1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     46  1.1       cgd  *    must display the following acknowledgement:
     47  1.1       cgd  *	This product includes software developed by the University of
     48  1.1       cgd  *	California, Berkeley and its contributors.
     49  1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     50  1.1       cgd  *    may be used to endorse or promote products derived from this software
     51  1.1       cgd  *    without specific prior written permission.
     52  1.1       cgd  *
     53  1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  1.1       cgd  * SUCH DAMAGE.
     64  1.1       cgd  */
     65  1.1       cgd 
     66  1.6     lukem #include <sys/cdefs.h>
     67  1.1       cgd #ifndef lint
     68  1.5       mrg #if 0
     69  1.5       mrg static char sccsid[] = "@(#)pr_comment.c	8.1 (Berkeley) 6/6/93";
     70  1.5       mrg #else
     71  1.9       agc __RCSID("$NetBSD: pr_comment.c,v 1.9 2003/08/07 11:14:09 agc Exp $");
     72  1.5       mrg #endif
     73  1.6     lukem #endif				/* not lint */
     74  1.1       cgd 
     75  1.1       cgd #include <stdio.h>
     76  1.1       cgd #include <stdlib.h>
     77  1.8  christos #include <ctype.h>
     78  1.1       cgd #include "indent_globs.h"
     79  1.1       cgd 
     80  1.1       cgd /*
     81  1.1       cgd  * NAME:
     82  1.1       cgd  *	pr_comment
     83  1.1       cgd  *
     84  1.1       cgd  * FUNCTION:
     85  1.1       cgd  *	This routine takes care of scanning and printing comments.
     86  1.1       cgd  *
     87  1.1       cgd  * ALGORITHM:
     88  1.1       cgd  *	1) Decide where the comment should be aligned, and if lines should
     89  1.1       cgd  *	   be broken.
     90  1.1       cgd  *	2) If lines should not be broken and filled, just copy up to end of
     91  1.1       cgd  *	   comment.
     92  1.1       cgd  *	3) If lines should be filled, then scan thru input_buffer copying
     93  1.1       cgd  *	   characters to com_buf.  Remember where the last blank, tab, or
     94  1.1       cgd  *	   newline was.  When line is filled, print up to last blank and
     95  1.1       cgd  *	   continue copying.
     96  1.1       cgd  *
     97  1.1       cgd  * HISTORY:
     98  1.1       cgd  *	November 1976	D A Willcox of CAC	Initial coding
     99  1.1       cgd  *	12/6/76		D A Willcox of CAC	Modification to handle
    100  1.1       cgd  *						UNIX-style comments
    101  1.1       cgd  *
    102  1.1       cgd  */
    103  1.1       cgd 
    105  1.1       cgd /*
    106  1.1       cgd  * this routine processes comments.  It makes an attempt to keep comments from
    107  1.1       cgd  * going over the max line length.  If a line is too long, it moves everything
    108  1.1       cgd  * from the last blank to the next comment line.  Blanks and tabs from the
    109  1.1       cgd  * beginning of the input line are removed
    110  1.1       cgd  */
    111  1.1       cgd 
    112  1.6     lukem 
    113  1.7       wiz void
    114  1.1       cgd pr_comment(void)
    115  1.6     lukem {
    116  1.6     lukem 	int     now_col;	/* column we are in now */
    117  1.1       cgd 	int     adj_max_col;	/* Adjusted max_col for when we decide to
    118  1.6     lukem 				 * spill comments over the right margin */
    119  1.1       cgd 	char   *last_bl;	/* points to the last blank in the output
    120  1.6     lukem 				 * buffer */
    121  1.6     lukem 	char   *t_ptr;		/* used for moving string */
    122  1.1       cgd 	int     unix_comment;	/* tri-state variable used to decide if it is
    123  1.6     lukem 				 * a unix-style comment. 0 means only blanks
    124  1.6     lukem 				 * since start, 1 means regular style comment,
    125  1.6     lukem 				 * 2 means unix style comment */
    126  1.6     lukem 	int     break_delim = comment_delimiter_on_blankline;
    127  1.6     lukem 	int     l_just_saw_decl = ps.just_saw_decl;
    128  1.6     lukem 	/*
    129  1.6     lukem          * int         ps.last_nl = 0;	/ * true iff the last significant thing
    130  1.6     lukem          * weve seen is a newline
    131  1.6     lukem          */
    132  1.6     lukem 	int     one_liner = 1;	/* true iff this comment is a one-liner */
    133  1.6     lukem 	adj_max_col = max_col;
    134  1.6     lukem 	ps.just_saw_decl = 0;
    135  1.6     lukem 	last_bl = 0;		/* no blanks found so far */
    136  1.6     lukem 	ps.box_com = false;	/* at first, assume that we are not in a boxed
    137  1.6     lukem 				 * comment or some other comment that should
    138  1.6     lukem 				 * not be touched */
    139  1.6     lukem 	++ps.out_coms;		/* keep track of number of comments */
    140  1.1       cgd 	unix_comment = 1;	/* set flag to let us figure out if there is a
    141  1.1       cgd 				 * unix-style comment ** DISABLED: use 0 to
    142  1.1       cgd 				 * reenable this hack! */
    143  1.6     lukem 
    144  1.1       cgd 	/* Figure where to align and how to treat the comment */
    145  1.6     lukem 
    146  1.6     lukem 	if (ps.col_1 && !format_col1_comments) {	/* if comment starts in
    147  1.6     lukem 							 * column 1 it should
    148  1.6     lukem 							 * not be touched */
    149  1.6     lukem 		ps.box_com = true;
    150  1.6     lukem 		ps.com_col = 1;
    151  1.6     lukem 	} else {
    152  1.6     lukem 		if (*buf_ptr == '-' || *buf_ptr == '*' || *buf_ptr == '\n') {
    153  1.6     lukem 			ps.box_com = true;	/* a comment with a '-', '*'
    154  1.6     lukem 						 * or newline immediately
    155  1.6     lukem 						 * after the start comment is
    156  1.6     lukem 						 * assumed to be a boxed
    157  1.6     lukem 						 * comment */
    158  1.1       cgd 			break_delim = 0;
    159  1.6     lukem 		}
    160  1.6     lukem 		if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) {
    161  1.1       cgd 			/* klg: check only if this line is blank */
    162  1.6     lukem 			/*
    163  1.6     lukem 		         * If this (*and previous lines are*) blank, dont put comment way
    164  1.6     lukem 		         * out at left
    165  1.1       cgd 		         */
    166  1.6     lukem 			ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
    167  1.1       cgd 			adj_max_col = block_comment_max_col;
    168  1.6     lukem 			if (ps.com_col <= 1)
    169  1.6     lukem 				ps.com_col = 1 + !format_col1_comments;
    170  1.6     lukem 		} else {
    171  1.6     lukem 			int     target_col;
    172  1.6     lukem 			break_delim = 0;
    173  1.6     lukem 			if (s_code != e_code)
    174  1.6     lukem 				target_col = count_spaces(compute_code_target(), s_code);
    175  1.6     lukem 			else {
    176  1.6     lukem 				target_col = 1;
    177  1.6     lukem 				if (s_lab != e_lab)
    178  1.6     lukem 					target_col = count_spaces(compute_label_target(), s_lab);
    179  1.6     lukem 			}
    180  1.6     lukem 			ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind;
    181  1.6     lukem 			if (ps.com_col < target_col)
    182  1.6     lukem 				ps.com_col = ((target_col + 7) & ~7) + 1;
    183  1.6     lukem 			if (ps.com_col + 24 > adj_max_col)
    184  1.1       cgd 				adj_max_col = ps.com_col + 24;
    185  1.6     lukem 		}
    186  1.6     lukem 	}
    187  1.6     lukem 	if (ps.box_com) {
    188  1.6     lukem 		buf_ptr[-2] = 0;
    189  1.6     lukem 		ps.n_comment_delta = 1 - count_spaces(1, in_buffer);
    190  1.6     lukem 		buf_ptr[-2] = '/';
    191  1.6     lukem 	} else {
    192  1.6     lukem 		ps.n_comment_delta = 0;
    193  1.6     lukem 		while (*buf_ptr == ' ' || *buf_ptr == '\t')
    194  1.6     lukem 			buf_ptr++;
    195  1.6     lukem 	}
    196  1.6     lukem 	ps.comment_delta = 0;
    197  1.6     lukem 	*e_com++ = '/';		/* put '/' + '*' into buffer */
    198  1.6     lukem 	*e_com++ = '*';
    199  1.6     lukem 	if (*buf_ptr != ' ' && !ps.box_com)
    200  1.6     lukem 		*e_com++ = ' ';
    201  1.6     lukem 
    202  1.6     lukem 	*e_com = '\0';
    203  1.6     lukem 	if (troff) {
    204  1.6     lukem 		now_col = 1;
    205  1.6     lukem 		adj_max_col = 80;
    206  1.6     lukem 	} else
    207  1.6     lukem 		now_col = count_spaces(ps.com_col, s_com);	/* figure what column we
    208  1.6     lukem 								 * would be in if we
    209  1.6     lukem 								 * printed the comment
    210  1.1       cgd 								 * now */
    211  1.6     lukem 
    212  1.1       cgd 	/* Start to copy the comment */
    213  1.6     lukem 
    214  1.6     lukem 	while (1) {		/* this loop will go until the comment is
    215  1.8  christos 				 * copied */
    216  1.6     lukem 		if (!iscntrl((unsigned char)*buf_ptr) && *buf_ptr != '*')
    217  1.1       cgd 			ps.last_nl = 0;
    218  1.6     lukem 		CHECK_SIZE_COM;
    219  1.6     lukem 		switch (*buf_ptr) {	/* this checks for various spcl cases */
    220  1.6     lukem 		case 014:	/* check for a form feed */
    221  1.6     lukem 			if (!ps.box_com) {	/* in a text comment, break
    222  1.6     lukem 						 * the line here */
    223  1.6     lukem 				ps.use_ff = true;
    224  1.6     lukem 				/* fix so dump_line uses a form feed */
    225  1.6     lukem 				dump_line();
    226  1.6     lukem 				last_bl = 0;
    227  1.6     lukem 				*e_com++ = ' ';
    228  1.6     lukem 				*e_com++ = '*';
    229  1.6     lukem 				*e_com++ = ' ';
    230  1.6     lukem 				while (*++buf_ptr == ' ' || *buf_ptr == '\t');
    231  1.6     lukem 			} else {
    232  1.6     lukem 				if (++buf_ptr >= buf_end)
    233  1.6     lukem 					fill_buffer();
    234  1.6     lukem 				*e_com++ = 014;
    235  1.6     lukem 			}
    236  1.6     lukem 			break;
    237  1.6     lukem 
    238  1.6     lukem 		case '\n':
    239  1.6     lukem 			if (had_eof) {	/* check for unexpected eof */
    240  1.6     lukem 				printf("Unterminated comment\n");
    241  1.6     lukem 				*e_com = '\0';
    242  1.6     lukem 				dump_line();
    243  1.6     lukem 				return;
    244  1.6     lukem 			}
    245  1.6     lukem 			one_liner = 0;
    246  1.6     lukem 			if (ps.box_com || ps.last_nl) {	/* if this is a boxed
    247  1.6     lukem 							 * comment, we dont
    248  1.6     lukem 							 * ignore the newline */
    249  1.6     lukem 				if (s_com == e_com) {
    250  1.6     lukem 					*e_com++ = ' ';
    251  1.6     lukem 					*e_com++ = ' ';
    252  1.6     lukem 				}
    253  1.6     lukem 				*e_com = '\0';
    254  1.6     lukem 				if (!ps.box_com && e_com - s_com > 3) {
    255  1.6     lukem 					if (break_delim == 1 && s_com[0] == '/'
    256  1.6     lukem 					    && s_com[1] == '*' && s_com[2] == ' ') {
    257  1.6     lukem 						char   *t = e_com;
    258  1.6     lukem 						break_delim = 2;
    259  1.6     lukem 						e_com = s_com + 2;
    260  1.6     lukem 						*e_com = 0;
    261  1.6     lukem 						if (blanklines_before_blockcomments)
    262  1.6     lukem 							prefix_blankline_requested = 1;
    263  1.6     lukem 						dump_line();
    264  1.6     lukem 						e_com = t;
    265  1.6     lukem 						s_com[0] = s_com[1] = s_com[2] = ' ';
    266  1.6     lukem 					}
    267  1.6     lukem 					dump_line();
    268  1.6     lukem 					CHECK_SIZE_COM;
    269  1.6     lukem 					*e_com++ = ' ';
    270  1.6     lukem 					*e_com++ = ' ';
    271  1.6     lukem 				}
    272  1.6     lukem 				dump_line();
    273  1.6     lukem 				now_col = ps.com_col;
    274  1.6     lukem 			} else {
    275  1.6     lukem 				ps.last_nl = 1;
    276  1.6     lukem 				if (unix_comment != 1) {	/* we not are in
    277  1.6     lukem 								 * unix_style comment */
    278  1.6     lukem 					if (unix_comment == 0 && s_code == e_code) {
    279  1.6     lukem 						/*
    280  1.6     lukem 						 * if it is a UNIX-style comment, ignore the
    281  1.6     lukem 						 * requirement that previous line be blank for
    282  1.6     lukem 						 * unindention
    283  1.6     lukem 						 */
    284  1.6     lukem 						ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
    285  1.6     lukem 						if (ps.com_col <= 1)
    286  1.6     lukem 							ps.com_col = 2;
    287  1.6     lukem 					}
    288  1.6     lukem 					unix_comment = 2;	/* permanently remember
    289  1.6     lukem 								 * that we are in this
    290  1.6     lukem 								 * type of comment */
    291  1.6     lukem 					dump_line();
    292  1.6     lukem 					++line_no;
    293  1.6     lukem 					now_col = ps.com_col;
    294  1.6     lukem 					*e_com++ = ' ';
    295  1.6     lukem 					/*
    296  1.6     lukem 				         * fix so that the star at the start of the line will line
    297  1.6     lukem 				         * up
    298  1.6     lukem 				         */
    299  1.6     lukem 					do	/* flush leading white space */
    300  1.6     lukem 						if (++buf_ptr >= buf_end)
    301  1.6     lukem 							fill_buffer();
    302  1.6     lukem 					while (*buf_ptr == ' ' || *buf_ptr == '\t');
    303  1.6     lukem 					break;
    304  1.6     lukem 				}
    305  1.6     lukem 				if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t')
    306  1.6     lukem 					last_bl = e_com - 1;
    307  1.6     lukem 				/*
    308  1.6     lukem 				 * if there was a space at the end of the last line, remember
    309  1.6     lukem 				 * where it was
    310  1.6     lukem 				 */
    311  1.6     lukem 				else {	/* otherwise, insert one */
    312  1.6     lukem 					last_bl = e_com;
    313  1.6     lukem 					CHECK_SIZE_COM;
    314  1.6     lukem 					*e_com++ = ' ';
    315  1.6     lukem 					++now_col;
    316  1.6     lukem 				}
    317  1.6     lukem 			}
    318  1.6     lukem 			++line_no;	/* keep track of input line number */
    319  1.6     lukem 			if (!ps.box_com) {
    320  1.6     lukem 				int     nstar = 1;
    321  1.6     lukem 				do {	/* flush any blanks and/or tabs at
    322  1.6     lukem 					 * start of next line */
    323  1.6     lukem 					if (++buf_ptr >= buf_end)
    324  1.6     lukem 						fill_buffer();
    325  1.6     lukem 					if (*buf_ptr == '*' && --nstar >= 0) {
    326  1.6     lukem 						if (++buf_ptr >= buf_end)
    327  1.6     lukem 							fill_buffer();
    328  1.6     lukem 						if (*buf_ptr == '/')
    329  1.6     lukem 							goto end_of_comment;
    330  1.6     lukem 					}
    331  1.6     lukem 				} while (*buf_ptr == ' ' || *buf_ptr == '\t');
    332  1.6     lukem 			} else
    333  1.6     lukem 				if (++buf_ptr >= buf_end)
    334  1.6     lukem 					fill_buffer();
    335  1.1       cgd 			break;	/* end of case for newline */
    336  1.6     lukem 
    337  1.6     lukem 		case '*':	/* must check for possibility of being at end
    338  1.6     lukem 				 * of comment */
    339  1.6     lukem 			if (++buf_ptr >= buf_end)	/* get to next char
    340  1.6     lukem 							 * after * */
    341  1.6     lukem 				fill_buffer();
    342  1.6     lukem 
    343  1.6     lukem 			if (unix_comment == 0)	/* set flag to show we are not
    344  1.6     lukem 						 * in unix-style comment */
    345  1.6     lukem 				unix_comment = 1;
    346  1.6     lukem 
    347  1.6     lukem 			if (*buf_ptr == '/') {	/* it is the end!!! */
    348  1.6     lukem 		end_of_comment:
    349  1.6     lukem 				if (++buf_ptr >= buf_end)
    350  1.6     lukem 					fill_buffer();
    351  1.6     lukem 
    352  1.6     lukem 				if (*(e_com - 1) != ' ' && !ps.box_com) {	/* insure blank before
    353  1.6     lukem 										 * end */
    354  1.6     lukem 					*e_com++ = ' ';
    355  1.6     lukem 					++now_col;
    356  1.6     lukem 				}
    357  1.6     lukem 				if (break_delim == 1 && !one_liner && s_com[0] == '/'
    358  1.6     lukem 				    && s_com[1] == '*' && s_com[2] == ' ') {
    359  1.6     lukem 					char   *t = e_com;
    360  1.6     lukem 					break_delim = 2;
    361  1.6     lukem 					e_com = s_com + 2;
    362  1.6     lukem 					*e_com = 0;
    363  1.6     lukem 					if (blanklines_before_blockcomments)
    364  1.6     lukem 						prefix_blankline_requested = 1;
    365  1.6     lukem 					dump_line();
    366  1.6     lukem 					e_com = t;
    367  1.6     lukem 					s_com[0] = s_com[1] = s_com[2] = ' ';
    368  1.6     lukem 				}
    369  1.6     lukem 				if (break_delim == 2 && e_com > s_com + 3
    370  1.6     lukem 				     /* now_col > adj_max_col - 2 && !ps.box_com */ ) {
    371  1.6     lukem 					*e_com = '\0';
    372  1.6     lukem 					dump_line();
    373  1.6     lukem 					now_col = ps.com_col;
    374  1.6     lukem 				}
    375  1.6     lukem 				CHECK_SIZE_COM;
    376  1.6     lukem 				*e_com++ = '*';
    377  1.6     lukem 				*e_com++ = '/';
    378  1.6     lukem 				*e_com = '\0';
    379  1.6     lukem 				ps.just_saw_decl = l_just_saw_decl;
    380  1.6     lukem 				return;
    381  1.6     lukem 			} else {/* handle isolated '*' */
    382  1.6     lukem 				*e_com++ = '*';
    383  1.6     lukem 				++now_col;
    384  1.6     lukem 			}
    385  1.6     lukem 			break;
    386  1.6     lukem 		default:	/* we have a random char */
    387  1.6     lukem 			if (unix_comment == 0 && *buf_ptr != ' ' && *buf_ptr != '\t')
    388  1.6     lukem 				unix_comment = 1;	/* we are not in
    389  1.6     lukem 							 * unix-style comment */
    390  1.6     lukem 
    391  1.6     lukem 			*e_com = *buf_ptr++;
    392  1.6     lukem 			if (buf_ptr >= buf_end)
    393  1.6     lukem 				fill_buffer();
    394  1.6     lukem 
    395  1.6     lukem 			if (*e_com == '\t')	/* keep track of column */
    396  1.6     lukem 				now_col = ((now_col - 1) & tabmask) + tabsize + 1;
    397  1.6     lukem 			else
    398  1.6     lukem 				if (*e_com == '\b')	/* this is a backspace */
    399  1.6     lukem 					--now_col;
    400  1.6     lukem 				else
    401  1.6     lukem 					++now_col;
    402  1.6     lukem 
    403  1.6     lukem 			if (*e_com == ' ' || *e_com == '\t')
    404  1.6     lukem 				last_bl = e_com;
    405  1.6     lukem 			/* remember we saw a blank */
    406  1.6     lukem 
    407  1.8  christos 			++e_com;
    408  1.8  christos 			if (now_col > adj_max_col && !ps.box_com && unix_comment == 1
    409  1.8  christos 				&& !iscntrl((unsigned char)e_com[-1])
    410  1.6     lukem 				&& !isblank((unsigned char)e_com[-1])) {
    411  1.6     lukem 				/*
    412  1.6     lukem 				 * the comment is too long, it must be broken up
    413  1.6     lukem 				 */
    414  1.6     lukem 				if (break_delim == 1 && s_com[0] == '/'
    415  1.6     lukem 				    && s_com[1] == '*' && s_com[2] == ' ') {
    416  1.6     lukem 					char   *t = e_com;
    417  1.6     lukem 					break_delim = 2;
    418  1.6     lukem 					e_com = s_com + 2;
    419  1.6     lukem 					*e_com = 0;
    420  1.6     lukem 					if (blanklines_before_blockcomments)
    421  1.6     lukem 						prefix_blankline_requested = 1;
    422  1.6     lukem 					dump_line();
    423  1.6     lukem 					e_com = t;
    424  1.6     lukem 					s_com[0] = s_com[1] = s_com[2] = ' ';
    425  1.6     lukem 				}
    426  1.6     lukem 				if (last_bl == 0) {	/* we have seen no
    427  1.6     lukem 							 * blanks */
    428  1.6     lukem 					last_bl = e_com;	/* fake it */
    429  1.6     lukem 					*e_com++ = ' ';
    430  1.6     lukem 				}
    431  1.6     lukem 				*e_com = '\0';	/* print what we have */
    432  1.8  christos 				*last_bl = '\0';
    433  1.6     lukem 				while (last_bl > s_com && iscntrl((unsigned char)last_bl[-1]) )
    434  1.6     lukem 					*--last_bl = 0;
    435  1.6     lukem 				e_com = last_bl;
    436  1.6     lukem 				dump_line();
    437  1.6     lukem 
    438  1.6     lukem 				*e_com++ = ' ';	/* add blanks for continuation */
    439  1.6     lukem 				*e_com++ = ' ';
    440  1.6     lukem 				*e_com++ = ' ';
    441  1.6     lukem 
    442  1.6     lukem 				t_ptr = last_bl + 1;
    443  1.6     lukem 				last_bl = 0;
    444  1.6     lukem 				if (t_ptr >= e_com) {
    445  1.6     lukem 					while (*t_ptr == ' ' || *t_ptr == '\t')
    446  1.6     lukem 						t_ptr++;
    447  1.6     lukem 					while (*t_ptr != '\0') {	/* move unprinted part
    448  1.6     lukem 									 * of comment down in
    449  1.6     lukem 									 * buffer */
    450  1.6     lukem 						if (*t_ptr == ' ' || *t_ptr == '\t')
    451  1.6     lukem 							last_bl = e_com;
    452  1.6     lukem 						*e_com++ = *t_ptr++;
    453  1.6     lukem 					}
    454  1.6     lukem 				}
    455  1.6     lukem 				*e_com = '\0';
    456  1.6     lukem 				now_col = count_spaces(ps.com_col, s_com);	/* recompute current
    457  1.6     lukem 										 * position */
    458  1.6     lukem 			}
    459  1.1       cgd 			break;
    460  1.1       cgd 		}
    461  1.1       cgd 	}
    462                }
    463