static char sccsid
[] = "@(#)pr_comment.c 4.1 (Berkeley) %G%";
This routine takes care of scanning and printing comments.
1) Decide where the comment should be aligned, and if lines should
2) If lines should not be broken and filled, just copy up to end of
3) If lines should be filled, then scan thru input_buffer copying
characters to com_buf. Remember where the last blank, tab, or
newline was. When line is filled, print up to last blank and
out_com = Count number of comments
November 1976 D A Willcox of CAC Initial coding
12/6/76 D A Willcox of CAC Modification to handle
/* this routine processes comments. It makes an attempt to keep comments from
going over the max line length. If a line is too long, it moves everything
from the last blank to the next comment line. Blanks and tabs from the
beginning of the input line are removed */
#include "indent_globs.h";
/* column we are in now */
/* set to true when we are in a "boxed" comment. In that case, the first
non-blank char should be lined up with the / in /* */
/* this comment should not be touched */
/* points to the last blank in the output buffer */
char *t_ptr
; /* used for movinf string */
/* tri-state variable used to decide if it is a unix-style comment. 0 means
only blanks since /*, 1 means regular style comment, 2 means unix style
last_bl
= 0; /* no blanks found so far */
box_com
= col_1_com
= false;
/* at first, assume that we are not in a boxed comment or some other comment
that should not be touched */
++out_coms
; /* keep track of number of comments */
unix_comment
= 0; /* set flag to let us figure out if there is a
/*----------------------------------------------------------*\
| Figure where to align and how to treat the comment
\*----------------------------------------------------------*/
if (col_1
) { /* if comment starts in column 1 it should not
col_1_com
= box_com
= true;
box_com
= true; /* a comment with a '-' immediately after the /*
is assumed to be a boxed comment */
if ( /* bl_line && */ (s_lab
== e_lab
) && (s_code
== e_code
)) {
/* klg: check only if this line is blank */
* If this (*and previous lines are*) blank,
* don't put comment way out at left
com_col
= (ind_level
- unindent_displace
) * ind_size
+ 1;
com_col
= (decl_on_line
|| ind_level
== 0 ? decl_com_ind
: com_ind
);
*e_com
++ = '/'; /* put '/*' into buffer */
if (*buf_ptr
!= ' ' && !box_com
)
now_col
= count_spaces (com_col
, s_com
);
/* figure where what column we would be in if we printed the comment now */
/*----------------------------------------------------------*\
| Start to copy the comment
\*----------------------------------------------------------*/
while (1) { /* this loop will go until the comment is copied
switch (*buf_ptr
) { /* this checks for various spcl cases */
case 014: /* check for a form feed */
if (!box_com
) {/* in a text comment, break the line here */
/* fix so dump_line uses a form feed */
do { /* get rid of leading blanks */
if (++buf_ptr
>= buf_end
)
} while (*buf_ptr
== ' ' || *buf_ptr
== '\t');
if (++buf_ptr
>= buf_end
)
if (had_eof
) { /* check for unexpected eof */
printf ("Unterminated comment\n");
if (box_com
) { /* if this is a boxed comment, we don't ignore
/* if merely a boxed comment, we should line up first
do { /* flush leading non-blanks */
if (++buf_ptr
>= buf_end
)
} while (*buf_ptr
== ' ' || *buf_ptr
== '\t');
else { /* make sure we at least flush the blank */
if (++buf_ptr
>= buf_end
)
/* we are in unix_style comment */
if (unix_comment
== 0 && s_code
== e_code
) {
/* if it is a UNIX-style comment, ignore the requirement
that pervious line be blank for unindention */
com_col
= (ind_level
- unindent_displace
) * ind_size
+ 1;
/* permanently remember that we are in this type of comment */
/* fix so that the star at the start of the line will line up
do /* flush leading white space */
if (++buf_ptr
>= buf_end
)
while (*buf_ptr
== ' ' || *buf_ptr
== '\t');
if (*(e_com
- 1) == ' ' || *(e_com
- 1) == '\t')
/* if there was a space at the end of the last line, remember where
else { /* otherwise, insert one */
++line_no
; /* keep track of input line number */
do { /* copy any blanks and/or tabs at start of next
if (++buf_ptr
>= buf_end
)
} while (*buf_ptr
== ' ' || *buf_ptr
== '\t');
break; /* end of case for newline */
case '*': /* must check for possibility of being at end of
if (++buf_ptr
>= buf_end
)
/* get to next char after * */
/* set flag to show we are not in unix-style
if (++buf_ptr
>= buf_end
)
if (*(e_com
- 1) != ' ' && !box_com
) {
/* insure blank before end */
if (now_col
> max_col
- 2 && !box_com
) {
/* check if star-slash will go over line */
/* move end of comment */
} /* end of end of comment */
else { /* handle isolated '*' */
/* end of processing of * */
default: /* we have a random char */
if (unix_comment
== 0 && *buf_ptr
!= ' ' && *buf_ptr
!= '\t')
/* we are not in unix-style comment */
/* keep track of column */
now_col
= ((now_col
- 1) & tabmask
) + tabsize
+ 1;
/* this is a backspace */
if (*e_com
== ' ' || *e_com
== '\t')
/* remember we saw a blank */
if (now_col
> max_col
&& !box_com
&& unix_comment
== 1) {
/* the comment is too long, it must be broken up */
/* we have seen no blanks */
printf ("%d: Comment too long\n", line_no
);
/* add blanks for continuation */
/* move unprinted pare of comment down in buffer */
if (*t_ptr
== ' ' || *t_ptr
== '\t')
now_col
= count_spaces (com_col
, s_com
);
/* recompute current position */
} /* end of code for splitting a comment */
break; /* end of default case */
} /* end of pr_comment */