indent: rename pr_comment to process_comment, clean up documentation No functional change.diff -r1.55 -r1.56 src/usr.bin/indent/indent.c
(rillig)
--- src/usr.bin/indent/indent.c 2021/03/13 13:14:14 1.55
+++ src/usr.bin/indent/indent.c 2021/03/13 13:25:23 1.56
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 rillig Exp $ */ | 1 | /* $NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * SPDX-License-Identifier: BSD-4-Clause | 4 | * SPDX-License-Identifier: BSD-4-Clause | |
5 | * | 5 | * | |
6 | * Copyright (c) 1985 Sun Microsystems, Inc. | 6 | * Copyright (c) 1985 Sun Microsystems, Inc. | |
7 | * Copyright (c) 1976 Board of Trustees of the University of Illinois. | 7 | * Copyright (c) 1976 Board of Trustees of the University of Illinois. | |
8 | * Copyright (c) 1980, 1993 | 8 | * Copyright (c) 1980, 1993 | |
9 | * The Regents of the University of California. All rights reserved. | 9 | * The Regents of the University of California. All rights reserved. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -36,27 +36,27 @@ | @@ -36,27 +36,27 @@ | |||
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
37 | * SUCH DAMAGE. | 37 | * SUCH DAMAGE. | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | #if 0 | 40 | #if 0 | |
41 | #ifndef lint | 41 | #ifndef lint | |
42 | static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; | 42 | static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; | |
43 | #endif /* not lint */ | 43 | #endif /* not lint */ | |
44 | #endif | 44 | #endif | |
45 | 45 | |||
46 | #include <sys/cdefs.h> | 46 | #include <sys/cdefs.h> | |
47 | #ifndef lint | 47 | #ifndef lint | |
48 | #if defined(__NetBSD__) | 48 | #if defined(__NetBSD__) | |
49 | __RCSID("$NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 rillig Exp $"); | 49 | __RCSID("$NetBSD: indent.c,v 1.56 2021/03/13 13:25:23 rillig Exp $"); | |
50 | #elif defined(__FreeBSD__) | 50 | #elif defined(__FreeBSD__) | |
51 | __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); | 51 | __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); | |
52 | #endif | 52 | #endif | |
53 | #endif | 53 | #endif | |
54 | 54 | |||
55 | #include <sys/param.h> | 55 | #include <sys/param.h> | |
56 | #if HAVE_CAPSICUM | 56 | #if HAVE_CAPSICUM | |
57 | #include <sys/capsicum.h> | 57 | #include <sys/capsicum.h> | |
58 | #include <capsicum_helpers.h> | 58 | #include <capsicum_helpers.h> | |
59 | #endif | 59 | #endif | |
60 | #include <err.h> | 60 | #include <err.h> | |
61 | #include <errno.h> | 61 | #include <errno.h> | |
62 | #include <fcntl.h> | 62 | #include <fcntl.h> | |
@@ -202,27 +202,27 @@ search_brace(token_type *inout_type_code | @@ -202,27 +202,27 @@ search_brace(token_type *inout_type_code | |||
202 | * has been scanned in this loop, force_nl should be false. | 202 | * has been scanned in this loop, force_nl should be false. | |
203 | * | 203 | * | |
204 | * However, the force_nl == true must be preserved if newline | 204 | * However, the force_nl == true must be preserved if newline | |
205 | * is never scanned in this loop, so this assignment cannot be | 205 | * is never scanned in this loop, so this assignment cannot be | |
206 | * done earlier. | 206 | * done earlier. | |
207 | */ | 207 | */ | |
208 | *inout_force_nl = false; | 208 | *inout_force_nl = false; | |
209 | case form_feed: | 209 | case form_feed: | |
210 | break; | 210 | break; | |
211 | case comment: | 211 | case comment: | |
212 | if (sc_end == NULL) { | 212 | if (sc_end == NULL) { | |
213 | /* | 213 | /* | |
214 | * Copy everything from the start of the line, because | 214 | * Copy everything from the start of the line, because | |
215 | * pr_comment() will use that to calculate original | 215 | * process_comment() will use that to calculate original | |
216 | * indentation of a boxed comment. | 216 | * indentation of a boxed comment. | |
217 | */ | 217 | */ | |
218 | memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); | 218 | memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); | |
219 | save_com = sc_buf + (buf_ptr - in_buffer - 4); | 219 | save_com = sc_buf + (buf_ptr - in_buffer - 4); | |
220 | save_com[0] = save_com[1] = ' '; | 220 | save_com[0] = save_com[1] = ' '; | |
221 | sc_end = &save_com[2]; | 221 | sc_end = &save_com[2]; | |
222 | } | 222 | } | |
223 | *inout_comment_buffered = true; | 223 | *inout_comment_buffered = true; | |
224 | *sc_end++ = '/'; /* copy in start of comment */ | 224 | *sc_end++ = '/'; /* copy in start of comment */ | |
225 | *sc_end++ = '*'; | 225 | *sc_end++ = '*'; | |
226 | for (;;) { /* loop until the end of the comment */ | 226 | for (;;) { /* loop until the end of the comment */ | |
227 | *sc_end = *buf_ptr++; | 227 | *sc_end = *buf_ptr++; | |
228 | if (buf_ptr >= buf_end) | 228 | if (buf_ptr >= buf_end) | |
@@ -1429,28 +1429,28 @@ main_loop(void) | @@ -1429,28 +1429,28 @@ main_loop(void) | |||
1429 | break; | 1429 | break; | |
1430 | 1430 | |||
1431 | case period: | 1431 | case period: | |
1432 | process_period(); | 1432 | process_period(); | |
1433 | break; | 1433 | break; | |
1434 | 1434 | |||
1435 | case comma: | 1435 | case comma: | |
1436 | process_comma(dec_ind, tabs_to_var, &force_nl); | 1436 | process_comma(dec_ind, tabs_to_var, &force_nl); | |
1437 | break; | 1437 | break; | |
1438 | 1438 | |||
1439 | case preprocessing: /* '#' */ | 1439 | case preprocessing: /* '#' */ | |
1440 | process_preprocessing(); | 1440 | process_preprocessing(); | |
1441 | break; | 1441 | break; | |
1442 | case comment: /* we have gotten a '/' followed by '*' */ | 1442 | case comment: /* the initial '/' '*' or '//' of a comment */ | |
1443 | pr_comment(); | 1443 | process_comment(); | |
1444 | break; | 1444 | break; | |
1445 | 1445 | |||
1446 | default: | 1446 | default: | |
1447 | break; | 1447 | break; | |
1448 | } /* end of big switch stmt */ | 1448 | } /* end of big switch stmt */ | |
1449 | 1449 | |||
1450 | *e_code = '\0'; /* make sure code section is null terminated */ | 1450 | *e_code = '\0'; /* make sure code section is null terminated */ | |
1451 | if (type_code != comment && | 1451 | if (type_code != comment && | |
1452 | type_code != newline && | 1452 | type_code != newline && | |
1453 | type_code != preprocessing) | 1453 | type_code != preprocessing) | |
1454 | ps.last_token = type_code; | 1454 | ps.last_token = type_code; | |
1455 | } | 1455 | } | |
1456 | } | 1456 | } |
--- src/usr.bin/indent/indent.h 2021/03/13 10:32:25 1.13
+++ src/usr.bin/indent/indent.h 2021/03/13 13:25:23 1.14
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $ */ | 1 | /* $NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | 4 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |
5 | * | 5 | * | |
6 | * Copyright (c) 2001 Jens Schweikhardt | 6 | * Copyright (c) 2001 Jens Schweikhardt | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE | 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE | |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #if 0 | 31 | #if 0 | |
32 | #if defined(__NetBSD__) | 32 | #if defined(__NetBSD__) | |
33 | __RCSID("$NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $"); | 33 | __RCSID("$NetBSD: indent.h,v 1.14 2021/03/13 13:25:23 rillig Exp $"); | |
34 | #elif defined(__FreeBSD__) | 34 | #elif defined(__FreeBSD__) | |
35 | __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); | 35 | __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $"); | |
36 | #endif | 36 | #endif | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include "indent_codes.h" | 39 | #include "indent_codes.h" | |
40 | #include "indent_globs.h" | 40 | #include "indent_globs.h" | |
41 | 41 | |||
42 | #ifndef nitems | 42 | #ifndef nitems | |
43 | #define nitems(array) (sizeof (array) / sizeof (array[0])) | 43 | #define nitems(array) (sizeof (array) / sizeof (array[0])) | |
44 | #endif | 44 | #endif | |
45 | 45 | |||
46 | void add_typename(const char *); | 46 | void add_typename(const char *); | |
@@ -55,17 +55,17 @@ void debug_vis_range(const char *, const | @@ -55,17 +55,17 @@ void debug_vis_range(const char *, const | |||
55 | void debug_printf(const char *, ...) __printflike(1, 2); | 55 | void debug_printf(const char *, ...) __printflike(1, 2); | |
56 | void debug_println(const char *, ...) __printflike(1, 2); | 56 | void debug_println(const char *, ...) __printflike(1, 2); | |
57 | const char *token_type_name(token_type); | 57 | const char *token_type_name(token_type); | |
58 | #else | 58 | #else | |
59 | #define debug_printf(fmt, ...) do { } while (false) | 59 | #define debug_printf(fmt, ...) do { } while (false) | |
60 | #define debug_println(fmt, ...) do { } while (false) | 60 | #define debug_println(fmt, ...) do { } while (false) | |
61 | #define debug_vis_range(prefix, s, e, suffix) do { } while (false) | 61 | #define debug_vis_range(prefix, s, e, suffix) do { } while (false) | |
62 | #endif | 62 | #endif | |
63 | token_type lexi(struct parser_state *); | 63 | token_type lexi(struct parser_state *); | |
64 | void diag(int, const char *, ...) __printflike(2, 3); | 64 | void diag(int, const char *, ...) __printflike(2, 3); | |
65 | void dump_line(void); | 65 | void dump_line(void); | |
66 | void fill_buffer(void); | 66 | void fill_buffer(void); | |
67 | void parse(token_type); | 67 | void parse(token_type); | |
68 | void pr_comment(void); | 68 | void process_comment(void); | |
69 | void set_defaults(void); | 69 | void set_defaults(void); | |
70 | void set_option(char *); | 70 | void set_option(char *); | |
71 | void set_profile(const char *); | 71 | void set_profile(const char *); |
--- src/usr.bin/indent/Attic/indent_globs.h 2021/03/13 11:19:43 1.18
+++ src/usr.bin/indent/Attic/indent_globs.h 2021/03/13 13:25:23 1.19
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: indent_globs.h,v 1.18 2021/03/13 11:19:43 rillig Exp $ */ | 1 | /* $NetBSD: indent_globs.h,v 1.19 2021/03/13 13:25:23 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * SPDX-License-Identifier: BSD-4-Clause | 4 | * SPDX-License-Identifier: BSD-4-Clause | |
5 | * | 5 | * | |
6 | * Copyright (c) 1985 Sun Microsystems, Inc. | 6 | * Copyright (c) 1985 Sun Microsystems, Inc. | |
7 | * Copyright (c) 1980, 1993 | 7 | * Copyright (c) 1980, 1993 | |
8 | * The Regents of the University of California. All rights reserved. | 8 | * The Regents of the University of California. All rights reserved. | |
9 | * All rights reserved. | 9 | * All rights reserved. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -244,27 +244,27 @@ extern struct parser_state { | @@ -244,27 +244,27 @@ extern struct parser_state { | |||
244 | int i_l_follow; /* the level to which ind_level should be set | 244 | int i_l_follow; /* the level to which ind_level should be set | |
245 | * after the current line is printed */ | 245 | * after the current line is printed */ | |
246 | int in_decl; /* set to true when we are in a declaration | 246 | int in_decl; /* set to true when we are in a declaration | |
247 | * stmt. The processing of braces is then | 247 | * stmt. The processing of braces is then | |
248 | * slightly different */ | 248 | * slightly different */ | |
249 | int in_stmt; /* set to 1 while in a stmt */ | 249 | int in_stmt; /* set to 1 while in a stmt */ | |
250 | int ind_level; /* the current indentation level */ | 250 | int ind_level; /* the current indentation level */ | |
251 | int ind_stmt; /* set to 1 if next line should have an extra | 251 | int ind_stmt; /* set to 1 if next line should have an extra | |
252 | * indentation level because we are in the | 252 | * indentation level because we are in the | |
253 | * middle of a stmt */ | 253 | * middle of a stmt */ | |
254 | int last_u_d; /* set to true after scanning a token which | 254 | int last_u_d; /* set to true after scanning a token which | |
255 | * forces a following operator to be unary */ | 255 | * forces a following operator to be unary */ | |
256 | int out_coms; /* the number of comments processed, set by | 256 | int out_coms; /* the number of comments processed, set by | |
257 | * pr_comment */ | 257 | * process_comment */ | |
258 | int out_lines; /* the number of lines written, set by | 258 | int out_lines; /* the number of lines written, set by | |
259 | * dump_line */ | 259 | * dump_line */ | |
260 | int p_l_follow; /* used to remember how to indent following | 260 | int p_l_follow; /* used to remember how to indent following | |
261 | * statement */ | 261 | * statement */ | |
262 | int paren_level; /* parenthesization level. used to indent | 262 | int paren_level; /* parenthesization level. used to indent | |
263 | * within statements */ | 263 | * within statements */ | |
264 | short paren_indents[20]; /* column positions of each paren */ | 264 | short paren_indents[20]; /* column positions of each paren */ | |
265 | int pcase; /* set to 1 if the current line label is a | 265 | int pcase; /* set to 1 if the current line label is a | |
266 | * case. It is printed differently from a | 266 | * case. It is printed differently from a | |
267 | * regular label */ | 267 | * regular label */ | |
268 | int search_brace; /* set to true by parse when it is necessary | 268 | int search_brace; /* set to true by parse when it is necessary | |
269 | * to buffer up all info up to the start of a | 269 | * to buffer up all info up to the start of a | |
270 | * stmt after an if, while, etc */ | 270 | * stmt after an if, while, etc */ |
--- src/usr.bin/indent/pr_comment.c 2021/03/13 11:27:01 1.27
+++ src/usr.bin/indent/pr_comment.c 2021/03/13 13:25:23 1.28
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $ */ | 1 | /* $NetBSD: pr_comment.c,v 1.28 2021/03/13 13:25:23 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * SPDX-License-Identifier: BSD-4-Clause | 4 | * SPDX-License-Identifier: BSD-4-Clause | |
5 | * | 5 | * | |
6 | * Copyright (c) 1985 Sun Microsystems, Inc. | 6 | * Copyright (c) 1985 Sun Microsystems, Inc. | |
7 | * Copyright (c) 1980, 1993 | 7 | * Copyright (c) 1980, 1993 | |
8 | * The Regents of the University of California. All rights reserved. | 8 | * The Regents of the University of California. All rights reserved. | |
9 | * All rights reserved. | 9 | * All rights reserved. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -36,27 +36,27 @@ | @@ -36,27 +36,27 @@ | |||
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
37 | * SUCH DAMAGE. | 37 | * SUCH DAMAGE. | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | #if 0 | 40 | #if 0 | |
41 | #ifndef lint | 41 | #ifndef lint | |
42 | static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; | 42 | static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; | |
43 | #endif /* not lint */ | 43 | #endif /* not lint */ | |
44 | #endif | 44 | #endif | |
45 | 45 | |||
46 | #include <sys/cdefs.h> | 46 | #include <sys/cdefs.h> | |
47 | #ifndef lint | 47 | #ifndef lint | |
48 | #if defined(__NetBSD__) | 48 | #if defined(__NetBSD__) | |
49 | __RCSID("$NetBSD: pr_comment.c,v 1.27 2021/03/13 11:27:01 rillig Exp $"); | 49 | __RCSID("$NetBSD: pr_comment.c,v 1.28 2021/03/13 13:25:23 rillig Exp $"); | |
50 | #elif defined(__FreeBSD__) | 50 | #elif defined(__FreeBSD__) | |
51 | __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); | 51 | __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); | |
52 | #endif | 52 | #endif | |
53 | #endif | 53 | #endif | |
54 | 54 | |||
55 | #include <err.h> | 55 | #include <err.h> | |
56 | #include <stdio.h> | 56 | #include <stdio.h> | |
57 | #include <stdlib.h> | 57 | #include <stdlib.h> | |
58 | #include <string.h> | 58 | #include <string.h> | |
59 | 59 | |||
60 | #include "indent.h" | 60 | #include "indent.h" | |
61 | 61 | |||
62 | static void | 62 | static void | |
@@ -69,79 +69,66 @@ check_size_comment(size_t desired_size, | @@ -69,79 +69,66 @@ check_size_comment(size_t desired_size, | |||
69 | size_t com_len = e_com - s_com; | 69 | size_t com_len = e_com - s_com; | |
70 | ssize_t blank_pos = *last_bl_ptr != NULL ? *last_bl_ptr - combuf : -1; | 70 | ssize_t blank_pos = *last_bl_ptr != NULL ? *last_bl_ptr - combuf : -1; | |
71 | combuf = realloc(combuf, nsize); | 71 | combuf = realloc(combuf, nsize); | |
72 | if (combuf == NULL) | 72 | if (combuf == NULL) | |
73 | err(1, NULL); | 73 | err(1, NULL); | |
74 | e_com = combuf + com_len + 1; | 74 | e_com = combuf + com_len + 1; | |
75 | if (blank_pos > 0) | 75 | if (blank_pos > 0) | |
76 | *last_bl_ptr = combuf + blank_pos; | 76 | *last_bl_ptr = combuf + blank_pos; | |
77 | l_com = combuf + nsize - 5; | 77 | l_com = combuf + nsize - 5; | |
78 | s_com = combuf + 1; | 78 | s_com = combuf + 1; | |
79 | } | 79 | } | |
80 | 80 | |||
81 | /* | 81 | /* | |
82 | * NAME: | 82 | * Scan, reformat and output a single comment, which is either a block comment | |
83 | * pr_comment | 83 | * starting with '/' '*' or an end-of-line comment starting with '//'. | |
84 | * | 84 | * | |
85 | * FUNCTION: | 85 | * Try to keep comments from going over the maximum line length. If a line is | |
86 | * This routine takes care of scanning and printing comments. | 86 | * too long, move everything starting from the last blank to the next comment | |
87 | * line. Blanks and tabs from the beginning of the input line are removed. | |||
87 | * | 88 | * | |
88 | * ALGORITHM: | 89 | * ALGORITHM: | |
89 | * 1) Decide where the comment should be aligned, and if lines should | 90 | * 1) Decide where the comment should be aligned, and if lines should | |
90 | * be broken. | 91 | * be broken. | |
91 | * 2) If lines should not be broken and filled, just copy up to end of | 92 | * 2) If lines should not be broken and filled, just copy up to end of | |
92 | * comment. | 93 | * comment. | |
93 | * 3) If lines should be filled, then scan thru input_buffer copying | 94 | * 3) If lines should be filled, then scan through the input buffer, | |
94 | * characters to com_buf. Remember where the last blank, tab, or | 95 | * copying characters to com_buf. Remember where the last blank, | |
95 | * newline was. When line is filled, print up to last blank and | 96 | * tab, or newline was. When line is filled, print up to last blank | |
96 | * continue copying. | 97 | * and continue copying. | |
97 | * | |||
98 | * HISTORY: | |||
99 | * November 1976 D A Willcox of CAC Initial coding | |||
100 | * 12/6/76 D A Willcox of CAC Modification to handle | |||
101 | * UNIX-style comments | |||
102 | * | |||
103 | */ | |||
104 | ||||
105 | /* | |||
106 | * this routine processes comments. It makes an attempt to keep comments from | |||
107 | * going over the max line length. If a line is too long, it moves everything | |||
108 | * from the last blank to the next comment line. Blanks and tabs from the | |||
109 | * beginning of the input line are removed | |||
110 | */ | 98 | */ | |
111 | ||||
112 | void | 99 | void | |
113 | pr_comment(void) | 100 | process_comment(void) | |
114 | { | 101 | { | |
115 | int adj_max_line_length; /* Adjusted max_line_length for comments | 102 | int adj_max_line_length; /* Adjusted max_line_length for comments | |
116 | * that spill over the right margin */ | 103 | * that spill over the right margin */ | |
117 | char *last_bl; /* points to the last blank in the output | 104 | char *last_bl; /* points to the last blank in the output | |
118 | * buffer */ | 105 | * buffer */ | |
119 | char *t_ptr; /* used for moving string */ | 106 | char *t_ptr; /* used for moving string */ | |
120 | int break_delim = opt.comment_delimiter_on_blankline; | 107 | int break_delim = opt.comment_delimiter_on_blankline; | |
121 | int l_just_saw_decl = ps.just_saw_decl; | 108 | int l_just_saw_decl = ps.just_saw_decl; | |
122 | 109 | |||
123 | adj_max_line_length = opt.max_line_length; | 110 | adj_max_line_length = opt.max_line_length; | |
124 | ps.just_saw_decl = 0; | 111 | ps.just_saw_decl = 0; | |
125 | last_bl = NULL; /* no blanks found so far */ | 112 | last_bl = NULL; /* no blanks found so far */ | |
126 | ps.box_com = false; /* at first, assume that we are not in | 113 | ps.box_com = false; /* at first, assume that we are not in | |
127 | * a boxed comment or some other | 114 | * a boxed comment or some other | |
128 | * comment that should not be touched */ | 115 | * comment that should not be touched */ | |
129 | ++ps.out_coms; /* keep track of number of comments */ | 116 | ++ps.out_coms; /* keep track of number of comments */ | |
130 | 117 | |||
131 | /* Figure where to align and how to treat the comment */ | 118 | /* Figure where to align and how to treat the comment */ | |
132 | 119 | |||
133 | if (ps.col_1 && !opt.format_col1_comments) { /* if comment starts in column | 120 | if (ps.col_1 && !opt.format_col1_comments) { /* if the comment starts in | |
134 | * 1 it should not be touched */ | 121 | * column 1, it should not be touched */ | |
135 | ps.box_com = true; | 122 | ps.box_com = true; | |
136 | break_delim = false; | 123 | break_delim = false; | |
137 | ps.com_col = 1; | 124 | ps.com_col = 1; | |
138 | } else { | 125 | } else { | |
139 | if (*buf_ptr == '-' || *buf_ptr == '*' || e_token[-1] == '/' || | 126 | if (*buf_ptr == '-' || *buf_ptr == '*' || e_token[-1] == '/' || | |
140 | (*buf_ptr == '\n' && !opt.format_block_comments)) { | 127 | (*buf_ptr == '\n' && !opt.format_block_comments)) { | |
141 | ps.box_com = true; /* A comment with a '-' or '*' immediately | 128 | ps.box_com = true; /* A comment with a '-' or '*' immediately | |
142 | * after the /+* is assumed to be a boxed | 129 | * after the /+* is assumed to be a boxed | |
143 | * comment. A comment with a newline | 130 | * comment. A comment with a newline | |
144 | * immediately after the /+* is assumed to | 131 | * immediately after the /+* is assumed to | |
145 | * be a block comment and is treated as a | 132 | * be a block comment and is treated as a | |
146 | * box comment unless format_block_comments | 133 | * box comment unless format_block_comments | |
147 | * is nonzero (the default). */ | 134 | * is nonzero (the default). */ |