2 * Copyright (c) 1985 Sun Microsystems, Inc.
3 * Copyright (c) 1980, 1993
4 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34static char sccsid[] =
"@(#)pr_comment.c 8.1 (Berkeley) 6/6/93";
52 * This routine takes care of scanning and printing comments.
55 * 1) Decide where the comment should be aligned, and if lines should
57 * 2) If lines should not be broken and filled, just copy up to end of
59 * 3) If lines should be filled, then scan thru input_buffer copying
60 * characters to com_buf. Remember where the last blank, tab, or
61 * newline was. When line is filled, print up to last blank and
65 * November 1976 D A Willcox of CAC Initial coding
66 * 12/6/76 D A Willcox of CAC Modification to handle
72 * this routine processes comments. It makes an attempt to keep comments from
73 * going over the max line length. If a line is too long, it moves everything
74 * from the last blank to the next comment line. Blanks and tabs from the
75 * beginning of the input line are removed
81 int now_col;
/* column we are in now */
82 int adj_max_col;
/* Adjusted max_col for when we decide to
83 * spill comments over the right margin */
84 char *last_bl;
/* points to the last blank in the output
86 char *t_ptr;
/* used for moving string */
91 last_bl = NULL;
/* no blanks found so far */
92 ps.
box_com =
false;
/* at first, assume that we are not in
93 * a boxed comment or some other
94 * comment that should not be touched */
95 ++
ps.
out_coms;
/* keep track of number of comments */
97 /* Figure where to align and how to treat the comment */
100 * 1 it should not be touched */
108 ps.
box_com =
true;
/* A comment with a '-' or '*' immediately
109 * after the /+* is assumed to be a boxed
110 * comment. A comment with a newline
111 * immediately after the /+* is assumed to
112 * be a block comment and is treated as a
113 * box comment unless format_block_comments
114 * is nonzero (the default). */
118 /* klg: check only if this line is blank */
120 * If this (*and previous lines are*) blank, dont put comment way
139 (strncmp(
s_lab,
"#endif", 6) == 0 ||
140 strncmp(
s_lab,
"#else", 5) == 0))
154 * Find out how much indentation there was originally, because that
155 * much will have to be ignored by pad_output() in dump_line(). This
156 * is a box comment, so nothing changes -- not even indentation.
158 * The comment we're about to read usually comes from in_buffer,
159 * unless it has been copied into save_com.
173 *
e_com++ =
'/';
/* put '/' followed by '*' into buffer */
179 * Don't put a break delimiter if this is a one-liner that won't wrap.
182 for (t_ptr =
buf_ptr; *t_ptr !=
'0円' && *t_ptr !=
'\n'; t_ptr++) {
185 if (t_ptr[0] ==
'*' && t_ptr[1] ==
'/') {
204 /* Start to copy the comment */
206 while (1) {
/* this loop will go until the comment is
208 switch (*
buf_ptr) {
/* this checks for various spcl cases */
209 case 014:
/* check for a form feed */
211 if (!
ps.
box_com) {
/* in a text comment, break the line here */
213 /* fix so dump_line uses a form feed */
229 if (
had_eof) {
/* check for unexpected eof */
230 printf(
"Unterminated comment\n");
237 * we dont ignore the newline */
251 if (*(
e_com - 1) ==
' ' || *(
e_com - 1) ==
'\t')
254 * if there was a space at the end of the last line, remember
257 else {
/* otherwise, insert one */
262 ++
line_no;
/* keep track of input line number */
265 do {
/* flush any blanks and/or tabs at start of
269 if (*
buf_ptr ==
'*' && --nstar >= 0) {
279 break;
/* end of case for newline */
281 case '*':
/* must check for possibility of being at end
286 if (*
buf_ptr ==
'/') {
/* it is the end!!! */
299 *
e_com++ =
' ';
/* ensure blank before end */
304 else /* handle isolated '*' */
307 default:
/* we have a random char */
315 last_bl =
e_com;
/* remember we saw a blank */
318 }
while (!memchr(
"*\n\r\b\t", *
buf_ptr, 6) &&
319 (now_col <= adj_max_col || !last_bl));
323 * the comment is too long, it must be broken up
325 if (last_bl == NULL) {
336 for (t_ptr = last_bl + 1; *t_ptr ==
' ' || *t_ptr ==
'\t';
341 * t_ptr will be somewhere between e_com (dump_line() reset)
342 * and l_com. So it's safe to copy byte by byte from t_ptr
343 * to e_com without any CHECK_SIZE_COM().
345 while (*t_ptr !=
'0円') {
346 if (*t_ptr ==
' ' || *t_ptr ==
'\t')
int compute_code_target(void)
int compute_label_target(void)
int count_spaces_until(int, char *, char *)
int count_spaces(int, char *)
int block_comment_max_col
#define CHECK_SIZE_COM(desired_size)
int prefix_blankline_requested
int blanklines_before_blockcomments
int format_block_comments
int comment_delimiter_on_blankline
if(TABLE==NULL||TABLE_index==NULL)