19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1985 Sun Microsystems, Inc. 39b50d902SRodney W. Grimes * Copyright (c) 1980, 1993 49b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 59b50d902SRodney W. Grimes * All rights reserved. 69b50d902SRodney W. Grimes * 79b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 89b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 99b50d902SRodney W. Grimes * are met: 109b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 129b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 139b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 149b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 159b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 169b50d902SRodney W. Grimes * must display the following acknowledgement: 179b50d902SRodney W. Grimes * This product includes software developed by the University of 189b50d902SRodney W. Grimes * California, Berkeley and its contributors. 199b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 209b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 219b50d902SRodney W. Grimes * without specific prior written permission. 229b50d902SRodney W. Grimes * 239b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 249b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 259b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 269b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 279b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 289b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 299b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 309b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 319b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 329b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 339b50d902SRodney W. Grimes * SUCH DAMAGE. 349b50d902SRodney W. Grimes */ 35e026a48cSDavid E. O'Brien 369b50d902SRodney W. Grimes #ifndef lint 37e026a48cSDavid E. O'Brien #if 0 389b50d902SRodney W. Grimes static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; 397916863dSJens Schweikhardt #endif 40e026a48cSDavid E. O'Brien #endif /* not lint */ 41e026a48cSDavid E. O'Brien #include <sys/cdefs.h> 42e026a48cSDavid E. O'Brien __FBSDID("$FreeBSD$"); 43e026a48cSDavid E. O'Brien 449b50d902SRodney W. Grimes #include <stdio.h> 459b50d902SRodney W. Grimes #include <stdlib.h> 469b50d902SRodney W. Grimes #include "indent_globs.h" 477916863dSJens Schweikhardt #include "indent.h" 489b50d902SRodney W. Grimes /* 499b50d902SRodney W. Grimes * NAME: 509b50d902SRodney W. Grimes * pr_comment 519b50d902SRodney W. Grimes * 529b50d902SRodney W. Grimes * FUNCTION: 539b50d902SRodney W. Grimes * This routine takes care of scanning and printing comments. 549b50d902SRodney W. Grimes * 559b50d902SRodney W. Grimes * ALGORITHM: 569b50d902SRodney W. Grimes * 1) Decide where the comment should be aligned, and if lines should 579b50d902SRodney W. Grimes * be broken. 589b50d902SRodney W. Grimes * 2) If lines should not be broken and filled, just copy up to end of 599b50d902SRodney W. Grimes * comment. 609b50d902SRodney W. Grimes * 3) If lines should be filled, then scan thru input_buffer copying 619b50d902SRodney W. Grimes * characters to com_buf. Remember where the last blank, tab, or 629b50d902SRodney W. Grimes * newline was. When line is filled, print up to last blank and 639b50d902SRodney W. Grimes * continue copying. 649b50d902SRodney W. Grimes * 659b50d902SRodney W. Grimes * HISTORY: 669b50d902SRodney W. Grimes * November 1976 D A Willcox of CAC Initial coding 679b50d902SRodney W. Grimes * 12/6/76 D A Willcox of CAC Modification to handle 689b50d902SRodney W. Grimes * UNIX-style comments 699b50d902SRodney W. Grimes * 709b50d902SRodney W. Grimes */ 719b50d902SRodney W. Grimes 729b50d902SRodney W. Grimes /* 739b50d902SRodney W. Grimes * this routine processes comments. It makes an attempt to keep comments from 749b50d902SRodney W. Grimes * going over the max line length. If a line is too long, it moves everything 759b50d902SRodney W. Grimes * from the last blank to the next comment line. Blanks and tabs from the 769b50d902SRodney W. Grimes * beginning of the input line are removed 779b50d902SRodney W. Grimes */ 789b50d902SRodney W. Grimes 797916863dSJens Schweikhardt void 807916863dSJens Schweikhardt pr_comment(void) 819b50d902SRodney W. Grimes { 829b50d902SRodney W. Grimes int now_col; /* column we are in now */ 839b50d902SRodney W. Grimes int adj_max_col; /* Adjusted max_col for when we decide to 849b50d902SRodney W. Grimes * spill comments over the right margin */ 859b50d902SRodney W. Grimes char *last_bl; /* points to the last blank in the output 869b50d902SRodney W. Grimes * buffer */ 879b50d902SRodney W. Grimes char *t_ptr; /* used for moving string */ 889b50d902SRodney W. Grimes int unix_comment; /* tri-state variable used to decide if it is 899b50d902SRodney W. Grimes * a unix-style comment. 0 means only blanks 907916863dSJens Schweikhardt * since /+*, 1 means regular style comment, 2 919b50d902SRodney W. Grimes * means unix style comment */ 929b50d902SRodney W. Grimes int break_delim = comment_delimiter_on_blankline; 939b50d902SRodney W. Grimes int l_just_saw_decl = ps.just_saw_decl; 949b50d902SRodney W. Grimes /* 957916863dSJens Schweikhardt * int ps.last_nl = 0; true iff the last significant thing 969b50d902SRodney W. Grimes * weve seen is a newline 979b50d902SRodney W. Grimes */ 989b50d902SRodney W. Grimes int one_liner = 1; /* true iff this comment is a one-liner */ 999b50d902SRodney W. Grimes adj_max_col = max_col; 1009b50d902SRodney W. Grimes ps.just_saw_decl = 0; 1019b50d902SRodney W. Grimes last_bl = 0; /* no blanks found so far */ 1029b50d902SRodney W. Grimes ps.box_com = false; /* at first, assume that we are not in 1039b50d902SRodney W. Grimes * a boxed comment or some other 1049b50d902SRodney W. Grimes * comment that should not be touched */ 1059b50d902SRodney W. Grimes ++ps.out_coms; /* keep track of number of comments */ 1069b50d902SRodney W. Grimes unix_comment = 1; /* set flag to let us figure out if there is a 1079b50d902SRodney W. Grimes * unix-style comment ** DISABLED: use 0 to 1089b50d902SRodney W. Grimes * reenable this hack! */ 1099b50d902SRodney W. Grimes 1109b50d902SRodney W. Grimes /* Figure where to align and how to treat the comment */ 1119b50d902SRodney W. Grimes 1129b50d902SRodney W. Grimes if (ps.col_1 && !format_col1_comments) { /* if comment starts in column 1139b50d902SRodney W. Grimes * 1 it should not be touched */ 1149b50d902SRodney W. Grimes ps.box_com = true; 1159b50d902SRodney W. Grimes ps.com_col = 1; 1169b50d902SRodney W. Grimes } 1179b50d902SRodney W. Grimes else { 118a5e1cac0SDavid E. O'Brien if (*buf_ptr == '-' || *buf_ptr == '*' || 119a5e1cac0SDavid E. O'Brien (*buf_ptr == '\n' && !format_block_comments)) { 120a5e1cac0SDavid E. O'Brien ps.box_com = true; /* A comment with a '-' or '*' immediately 1217916863dSJens Schweikhardt * after the /+* is assumed to be a boxed 122a5e1cac0SDavid E. O'Brien * comment. A comment with a newline 1237916863dSJens Schweikhardt * immediately after the /+* is assumed to 124a5e1cac0SDavid E. O'Brien * be a block comment and is treated as a 125a5e1cac0SDavid E. O'Brien * box comment unless format_block_comments 126a5e1cac0SDavid E. O'Brien * is nonzero (the default). */ 1279b50d902SRodney W. Grimes break_delim = 0; 1289b50d902SRodney W. Grimes } 1299b50d902SRodney W. Grimes if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) { 1309b50d902SRodney W. Grimes /* klg: check only if this line is blank */ 1319b50d902SRodney W. Grimes /* 1329b50d902SRodney W. Grimes * If this (*and previous lines are*) blank, dont put comment way 1339b50d902SRodney W. Grimes * out at left 1349b50d902SRodney W. Grimes */ 1359b50d902SRodney W. Grimes ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1; 1369b50d902SRodney W. Grimes adj_max_col = block_comment_max_col; 1379b50d902SRodney W. Grimes if (ps.com_col <= 1) 1389b50d902SRodney W. Grimes ps.com_col = 1 + !format_col1_comments; 1399b50d902SRodney W. Grimes } 1409b50d902SRodney W. Grimes else { 14190af6a72SJuli Mallett int target_col; 1429b50d902SRodney W. Grimes break_delim = 0; 1439b50d902SRodney W. Grimes if (s_code != e_code) 1449b50d902SRodney W. Grimes target_col = count_spaces(compute_code_target(), s_code); 1459b50d902SRodney W. Grimes else { 1469b50d902SRodney W. Grimes target_col = 1; 1479b50d902SRodney W. Grimes if (s_lab != e_lab) 1489b50d902SRodney W. Grimes target_col = count_spaces(compute_label_target(), s_lab); 1499b50d902SRodney W. Grimes } 1509b50d902SRodney W. Grimes ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind; 1519b50d902SRodney W. Grimes if (ps.com_col < target_col) 1529b50d902SRodney W. Grimes ps.com_col = ((target_col + 7) & ~7) + 1; 1539b50d902SRodney W. Grimes if (ps.com_col + 24 > adj_max_col) 1549b50d902SRodney W. Grimes adj_max_col = ps.com_col + 24; 1559b50d902SRodney W. Grimes } 1569b50d902SRodney W. Grimes } 1579b50d902SRodney W. Grimes if (ps.box_com) { 1589b50d902SRodney W. Grimes buf_ptr[-2] = 0; 1599b50d902SRodney W. Grimes ps.n_comment_delta = 1 - count_spaces(1, in_buffer); 1609b50d902SRodney W. Grimes buf_ptr[-2] = '/'; 1619b50d902SRodney W. Grimes } 1629b50d902SRodney W. Grimes else { 1639b50d902SRodney W. Grimes ps.n_comment_delta = 0; 1649b50d902SRodney W. Grimes while (*buf_ptr == ' ' || *buf_ptr == '\t') 1659b50d902SRodney W. Grimes buf_ptr++; 1669b50d902SRodney W. Grimes } 1679b50d902SRodney W. Grimes ps.comment_delta = 0; 1687916863dSJens Schweikhardt *e_com++ = '/'; /* put '/' followed by '*' into buffer */ 1699b50d902SRodney W. Grimes *e_com++ = '*'; 1709b50d902SRodney W. Grimes if (*buf_ptr != ' ' && !ps.box_com) 1719b50d902SRodney W. Grimes *e_com++ = ' '; 1729b50d902SRodney W. Grimes 1739b50d902SRodney W. Grimes *e_com = '\0'; 1749b50d902SRodney W. Grimes if (troff) { 1759b50d902SRodney W. Grimes now_col = 1; 1769b50d902SRodney W. Grimes adj_max_col = 80; 1779b50d902SRodney W. Grimes } 1789b50d902SRodney W. Grimes else 1799b50d902SRodney W. Grimes now_col = count_spaces(ps.com_col, s_com); /* figure what column we 1809b50d902SRodney W. Grimes * would be in if we 1819b50d902SRodney W. Grimes * printed the comment 1829b50d902SRodney W. Grimes * now */ 1839b50d902SRodney W. Grimes 1849b50d902SRodney W. Grimes /* Start to copy the comment */ 1859b50d902SRodney W. Grimes 1869b50d902SRodney W. Grimes while (1) { /* this loop will go until the comment is 1879b50d902SRodney W. Grimes * copied */ 1889b50d902SRodney W. Grimes if (*buf_ptr > 040 && *buf_ptr != '*') 1899b50d902SRodney W. Grimes ps.last_nl = 0; 1909b50d902SRodney W. Grimes CHECK_SIZE_COM; 1919b50d902SRodney W. Grimes switch (*buf_ptr) { /* this checks for various spcl cases */ 1929b50d902SRodney W. Grimes case 014: /* check for a form feed */ 1939b50d902SRodney W. Grimes if (!ps.box_com) { /* in a text comment, break the line here */ 1949b50d902SRodney W. Grimes ps.use_ff = true; 1959b50d902SRodney W. Grimes /* fix so dump_line uses a form feed */ 1969b50d902SRodney W. Grimes dump_line(); 1979b50d902SRodney W. Grimes last_bl = 0; 1989b50d902SRodney W. Grimes *e_com++ = ' '; 1999b50d902SRodney W. Grimes *e_com++ = '*'; 2009b50d902SRodney W. Grimes *e_com++ = ' '; 2019b50d902SRodney W. Grimes while (*++buf_ptr == ' ' || *buf_ptr == '\t'); 2029b50d902SRodney W. Grimes } 2039b50d902SRodney W. Grimes else { 2049b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) 2059b50d902SRodney W. Grimes fill_buffer(); 2069b50d902SRodney W. Grimes *e_com++ = 014; 2079b50d902SRodney W. Grimes } 2089b50d902SRodney W. Grimes break; 2099b50d902SRodney W. Grimes 2109b50d902SRodney W. Grimes case '\n': 2119b50d902SRodney W. Grimes if (had_eof) { /* check for unexpected eof */ 2129b50d902SRodney W. Grimes printf("Unterminated comment\n"); 2139b50d902SRodney W. Grimes *e_com = '\0'; 2149b50d902SRodney W. Grimes dump_line(); 2159b50d902SRodney W. Grimes return; 2169b50d902SRodney W. Grimes } 2179b50d902SRodney W. Grimes one_liner = 0; 2189b50d902SRodney W. Grimes if (ps.box_com || ps.last_nl) { /* if this is a boxed comment, 2199b50d902SRodney W. Grimes * we dont ignore the newline */ 2209b50d902SRodney W. Grimes if (s_com == e_com) { 2219b50d902SRodney W. Grimes *e_com++ = ' '; 2229b50d902SRodney W. Grimes *e_com++ = ' '; 2239b50d902SRodney W. Grimes } 2249b50d902SRodney W. Grimes *e_com = '\0'; 2259b50d902SRodney W. Grimes if (!ps.box_com && e_com - s_com > 3) { 2269b50d902SRodney W. Grimes if (break_delim == 1 && s_com[0] == '/' 2279b50d902SRodney W. Grimes && s_com[1] == '*' && s_com[2] == ' ') { 2289b50d902SRodney W. Grimes char *t = e_com; 2299b50d902SRodney W. Grimes break_delim = 2; 2309b50d902SRodney W. Grimes e_com = s_com + 2; 2319b50d902SRodney W. Grimes *e_com = 0; 2329b50d902SRodney W. Grimes if (blanklines_before_blockcomments) 2339b50d902SRodney W. Grimes prefix_blankline_requested = 1; 2349b50d902SRodney W. Grimes dump_line(); 2359b50d902SRodney W. Grimes e_com = t; 2369b50d902SRodney W. Grimes s_com[0] = s_com[1] = s_com[2] = ' '; 2379b50d902SRodney W. Grimes } 2389b50d902SRodney W. Grimes dump_line(); 2399b50d902SRodney W. Grimes CHECK_SIZE_COM; 2409b50d902SRodney W. Grimes *e_com++ = ' '; 2419b50d902SRodney W. Grimes *e_com++ = ' '; 2429b50d902SRodney W. Grimes } 2439b50d902SRodney W. Grimes dump_line(); 2449b50d902SRodney W. Grimes now_col = ps.com_col; 2459b50d902SRodney W. Grimes } 2469b50d902SRodney W. Grimes else { 2479b50d902SRodney W. Grimes ps.last_nl = 1; 2489b50d902SRodney W. Grimes if (unix_comment != 1) { /* we not are in unix_style 2499b50d902SRodney W. Grimes * comment */ 2509b50d902SRodney W. Grimes if (unix_comment == 0 && s_code == e_code) { 2519b50d902SRodney W. Grimes /* 2529b50d902SRodney W. Grimes * if it is a UNIX-style comment, ignore the 2539b50d902SRodney W. Grimes * requirement that previous line be blank for 2549b50d902SRodney W. Grimes * unindention 2559b50d902SRodney W. Grimes */ 2569b50d902SRodney W. Grimes ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1; 2579b50d902SRodney W. Grimes if (ps.com_col <= 1) 2589b50d902SRodney W. Grimes ps.com_col = 2; 2599b50d902SRodney W. Grimes } 2609b50d902SRodney W. Grimes unix_comment = 2; /* permanently remember that we are in 2619b50d902SRodney W. Grimes * this type of comment */ 2629b50d902SRodney W. Grimes dump_line(); 2639b50d902SRodney W. Grimes ++line_no; 2649b50d902SRodney W. Grimes now_col = ps.com_col; 2659b50d902SRodney W. Grimes *e_com++ = ' '; 2669b50d902SRodney W. Grimes /* 2679b50d902SRodney W. Grimes * fix so that the star at the start of the line will line 2689b50d902SRodney W. Grimes * up 2699b50d902SRodney W. Grimes */ 2709b50d902SRodney W. Grimes do /* flush leading white space */ 2719b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) 2729b50d902SRodney W. Grimes fill_buffer(); 2739b50d902SRodney W. Grimes while (*buf_ptr == ' ' || *buf_ptr == '\t'); 2749b50d902SRodney W. Grimes break; 2759b50d902SRodney W. Grimes } 2769b50d902SRodney W. Grimes if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t') 2779b50d902SRodney W. Grimes last_bl = e_com - 1; 2789b50d902SRodney W. Grimes /* 2799b50d902SRodney W. Grimes * if there was a space at the end of the last line, remember 2809b50d902SRodney W. Grimes * where it was 2819b50d902SRodney W. Grimes */ 2829b50d902SRodney W. Grimes else { /* otherwise, insert one */ 2839b50d902SRodney W. Grimes last_bl = e_com; 2849b50d902SRodney W. Grimes CHECK_SIZE_COM; 2859b50d902SRodney W. Grimes *e_com++ = ' '; 2869b50d902SRodney W. Grimes ++now_col; 2879b50d902SRodney W. Grimes } 2889b50d902SRodney W. Grimes } 2899b50d902SRodney W. Grimes ++line_no; /* keep track of input line number */ 2909b50d902SRodney W. Grimes if (!ps.box_com) { 2919b50d902SRodney W. Grimes int nstar = 1; 2929b50d902SRodney W. Grimes do { /* flush any blanks and/or tabs at start of 2939b50d902SRodney W. Grimes * next line */ 2949b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) 2959b50d902SRodney W. Grimes fill_buffer(); 2969b50d902SRodney W. Grimes if (*buf_ptr == '*' && --nstar >= 0) { 2979b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) 2989b50d902SRodney W. Grimes fill_buffer(); 2999b50d902SRodney W. Grimes if (*buf_ptr == '/') 3009b50d902SRodney W. Grimes goto end_of_comment; 3019b50d902SRodney W. Grimes } 3029b50d902SRodney W. Grimes } while (*buf_ptr == ' ' || *buf_ptr == '\t'); 3039b50d902SRodney W. Grimes } 3049b50d902SRodney W. Grimes else if (++buf_ptr >= buf_end) 3059b50d902SRodney W. Grimes fill_buffer(); 3069b50d902SRodney W. Grimes break; /* end of case for newline */ 3079b50d902SRodney W. Grimes 3089b50d902SRodney W. Grimes case '*': /* must check for possibility of being at end 3099b50d902SRodney W. Grimes * of comment */ 3109b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) /* get to next char after * */ 3119b50d902SRodney W. Grimes fill_buffer(); 3129b50d902SRodney W. Grimes 3139b50d902SRodney W. Grimes if (unix_comment == 0) /* set flag to show we are not in 3149b50d902SRodney W. Grimes * unix-style comment */ 3159b50d902SRodney W. Grimes unix_comment = 1; 3169b50d902SRodney W. Grimes 3179b50d902SRodney W. Grimes if (*buf_ptr == '/') { /* it is the end!!! */ 3189b50d902SRodney W. Grimes end_of_comment: 3199b50d902SRodney W. Grimes if (++buf_ptr >= buf_end) 3209b50d902SRodney W. Grimes fill_buffer(); 3219b50d902SRodney W. Grimes 3229b50d902SRodney W. Grimes if (*(e_com - 1) != ' ' && !ps.box_com) { /* insure blank before 3239b50d902SRodney W. Grimes * end */ 3249b50d902SRodney W. Grimes *e_com++ = ' '; 3259b50d902SRodney W. Grimes ++now_col; 3269b50d902SRodney W. Grimes } 3279b50d902SRodney W. Grimes if (break_delim == 1 && !one_liner && s_com[0] == '/' 3289b50d902SRodney W. Grimes && s_com[1] == '*' && s_com[2] == ' ') { 3299b50d902SRodney W. Grimes char *t = e_com; 3309b50d902SRodney W. Grimes break_delim = 2; 3319b50d902SRodney W. Grimes e_com = s_com + 2; 3329b50d902SRodney W. Grimes *e_com = 0; 3339b50d902SRodney W. Grimes if (blanklines_before_blockcomments) 3349b50d902SRodney W. Grimes prefix_blankline_requested = 1; 3359b50d902SRodney W. Grimes dump_line(); 3369b50d902SRodney W. Grimes e_com = t; 3379b50d902SRodney W. Grimes s_com[0] = s_com[1] = s_com[2] = ' '; 3389b50d902SRodney W. Grimes } 3399b50d902SRodney W. Grimes if (break_delim == 2 && e_com > s_com + 3 3409b50d902SRodney W. Grimes /* now_col > adj_max_col - 2 && !ps.box_com */ ) { 3419b50d902SRodney W. Grimes *e_com = '\0'; 3429b50d902SRodney W. Grimes dump_line(); 3439b50d902SRodney W. Grimes now_col = ps.com_col; 3449b50d902SRodney W. Grimes } 3459b50d902SRodney W. Grimes CHECK_SIZE_COM; 3469b50d902SRodney W. Grimes *e_com++ = '*'; 3479b50d902SRodney W. Grimes *e_com++ = '/'; 3489b50d902SRodney W. Grimes *e_com = '\0'; 3499b50d902SRodney W. Grimes ps.just_saw_decl = l_just_saw_decl; 3509b50d902SRodney W. Grimes return; 3519b50d902SRodney W. Grimes } 3529b50d902SRodney W. Grimes else { /* handle isolated '*' */ 3539b50d902SRodney W. Grimes *e_com++ = '*'; 3549b50d902SRodney W. Grimes ++now_col; 3559b50d902SRodney W. Grimes } 3569b50d902SRodney W. Grimes break; 3579b50d902SRodney W. Grimes default: /* we have a random char */ 3589b50d902SRodney W. Grimes if (unix_comment == 0 && *buf_ptr != ' ' && *buf_ptr != '\t') 3599b50d902SRodney W. Grimes unix_comment = 1; /* we are not in unix-style comment */ 3609b50d902SRodney W. Grimes 3619b50d902SRodney W. Grimes *e_com = *buf_ptr++; 3629b50d902SRodney W. Grimes if (buf_ptr >= buf_end) 3639b50d902SRodney W. Grimes fill_buffer(); 3649b50d902SRodney W. Grimes 3659b50d902SRodney W. Grimes if (*e_com == '\t') /* keep track of column */ 3669b50d902SRodney W. Grimes now_col = ((now_col - 1) & tabmask) + tabsize + 1; 3679b50d902SRodney W. Grimes else if (*e_com == '\b') /* this is a backspace */ 3689b50d902SRodney W. Grimes --now_col; 3699b50d902SRodney W. Grimes else 3709b50d902SRodney W. Grimes ++now_col; 3719b50d902SRodney W. Grimes 3729b50d902SRodney W. Grimes if (*e_com == ' ' || *e_com == '\t') 3739b50d902SRodney W. Grimes last_bl = e_com; 3749b50d902SRodney W. Grimes /* remember we saw a blank */ 3759b50d902SRodney W. Grimes 3769b50d902SRodney W. Grimes ++e_com; 3779b50d902SRodney W. Grimes if (now_col > adj_max_col && !ps.box_com && unix_comment == 1 && e_com[-1] > ' ') { 3789b50d902SRodney W. Grimes /* 3799b50d902SRodney W. Grimes * the comment is too long, it must be broken up 3809b50d902SRodney W. Grimes */ 3819b50d902SRodney W. Grimes if (break_delim == 1 && s_com[0] == '/' 3829b50d902SRodney W. Grimes && s_com[1] == '*' && s_com[2] == ' ') { 3839b50d902SRodney W. Grimes char *t = e_com; 3849b50d902SRodney W. Grimes break_delim = 2; 3859b50d902SRodney W. Grimes e_com = s_com + 2; 3869b50d902SRodney W. Grimes *e_com = 0; 3879b50d902SRodney W. Grimes if (blanklines_before_blockcomments) 3889b50d902SRodney W. Grimes prefix_blankline_requested = 1; 3899b50d902SRodney W. Grimes dump_line(); 3909b50d902SRodney W. Grimes e_com = t; 3919b50d902SRodney W. Grimes s_com[0] = s_com[1] = s_com[2] = ' '; 3929b50d902SRodney W. Grimes } 3939b50d902SRodney W. Grimes if (last_bl == 0) { /* we have seen no blanks */ 3949b50d902SRodney W. Grimes last_bl = e_com; /* fake it */ 3959b50d902SRodney W. Grimes *e_com++ = ' '; 3969b50d902SRodney W. Grimes } 3979b50d902SRodney W. Grimes *e_com = '\0'; /* print what we have */ 3989b50d902SRodney W. Grimes *last_bl = '\0'; 3999b50d902SRodney W. Grimes while (last_bl > s_com && last_bl[-1] < 040) 4009b50d902SRodney W. Grimes *--last_bl = 0; 4019b50d902SRodney W. Grimes e_com = last_bl; 4029b50d902SRodney W. Grimes dump_line(); 4039b50d902SRodney W. Grimes 4049b50d902SRodney W. Grimes *e_com++ = ' '; /* add blanks for continuation */ 4059b50d902SRodney W. Grimes *e_com++ = ' '; 4069b50d902SRodney W. Grimes *e_com++ = ' '; 4079b50d902SRodney W. Grimes 4089b50d902SRodney W. Grimes t_ptr = last_bl + 1; 4099b50d902SRodney W. Grimes last_bl = 0; 4109b50d902SRodney W. Grimes if (t_ptr >= e_com) { 4119b50d902SRodney W. Grimes while (*t_ptr == ' ' || *t_ptr == '\t') 4129b50d902SRodney W. Grimes t_ptr++; 4139b50d902SRodney W. Grimes while (*t_ptr != '\0') { /* move unprinted part of 4149b50d902SRodney W. Grimes * comment down in buffer */ 4159b50d902SRodney W. Grimes if (*t_ptr == ' ' || *t_ptr == '\t') 4169b50d902SRodney W. Grimes last_bl = e_com; 4179b50d902SRodney W. Grimes *e_com++ = *t_ptr++; 4189b50d902SRodney W. Grimes } 4199b50d902SRodney W. Grimes } 4209b50d902SRodney W. Grimes *e_com = '\0'; 4219b50d902SRodney W. Grimes now_col = count_spaces(ps.com_col, s_com); /* recompute current 4229b50d902SRodney W. Grimes * position */ 4239b50d902SRodney W. Grimes } 4249b50d902SRodney W. Grimes break; 4259b50d902SRodney W. Grimes } 4269b50d902SRodney W. Grimes } 4279b50d902SRodney W. Grimes } 428