| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: indent.c,v 1.54 2021/03/13 12:52:24 rillig Exp $ */ | | 1 | /* $NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 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.54 2021/03/13 12:52:24 rillig Exp $"); | | 49 | __RCSID("$NetBSD: indent.c,v 1.55 2021/03/13 13:14:14 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> |
| @@ -1111,61 +1111,65 @@ process_comma(int dec_ind, int tabs_to_v | | | @@ -1111,61 +1111,65 @@ process_comma(int dec_ind, int tabs_to_v |
1111 | } | | 1111 | } |
1112 | | | 1112 | |
1113 | static void | | 1113 | static void |
1114 | process_preprocessing(void) | | 1114 | process_preprocessing(void) |
1115 | { | | 1115 | { |
1116 | if (s_com != e_com || s_lab != e_lab || s_code != e_code) | | 1116 | if (s_com != e_com || s_lab != e_lab || s_code != e_code) |
1117 | dump_line(); | | 1117 | dump_line(); |
1118 | check_size_label(1); | | 1118 | check_size_label(1); |
1119 | *e_lab++ = '#'; /* move whole line to 'label' buffer */ | | 1119 | *e_lab++ = '#'; /* move whole line to 'label' buffer */ |
1120 | | | 1120 | |
1121 | { | | 1121 | { |
1122 | int in_comment = 0; | | 1122 | int in_comment = 0; |
1123 | int com_start = 0; | | 1123 | int com_start = 0; |
1124 | char quote = 0; | | 1124 | char quote = '\0'; |
1125 | int com_end = 0; | | 1125 | int com_end = 0; |
1126 | | | 1126 | |
1127 | while (*buf_ptr == ' ' || *buf_ptr == '\t') { | | 1127 | while (*buf_ptr == ' ' || *buf_ptr == '\t') { |
1128 | buf_ptr++; | | 1128 | buf_ptr++; |
1129 | if (buf_ptr >= buf_end) | | 1129 | if (buf_ptr >= buf_end) |
1130 | fill_buffer(); | | 1130 | fill_buffer(); |
1131 | } | | 1131 | } |
1132 | while (*buf_ptr != '\n' || (in_comment && !had_eof)) { | | 1132 | while (*buf_ptr != '\n' || (in_comment && !had_eof)) { |
1133 | check_size_label(2); | | 1133 | check_size_label(2); |
1134 | *e_lab = *buf_ptr++; | | 1134 | *e_lab = *buf_ptr++; |
1135 | if (buf_ptr >= buf_end) | | 1135 | if (buf_ptr >= buf_end) |
1136 | fill_buffer(); | | 1136 | fill_buffer(); |
1137 | switch (*e_lab++) { | | 1137 | switch (*e_lab++) { |
1138 | case '\\': | | 1138 | case '\\': |
1139 | if (!in_comment) { | | 1139 | if (!in_comment) { |
1140 | *e_lab++ = *buf_ptr++; | | 1140 | *e_lab++ = *buf_ptr++; |
1141 | if (buf_ptr >= buf_end) | | 1141 | if (buf_ptr >= buf_end) |
1142 | fill_buffer(); | | 1142 | fill_buffer(); |
1143 | } | | 1143 | } |
1144 | break; | | 1144 | break; |
1145 | case '/': | | 1145 | case '/': |
1146 | if (*buf_ptr == '*' && !in_comment && !quote) { | | 1146 | if (*buf_ptr == '*' && !in_comment && quote == '\0') { |
1147 | in_comment = 1; | | 1147 | in_comment = 1; |
1148 | *e_lab++ = *buf_ptr++; | | 1148 | *e_lab++ = *buf_ptr++; |
1149 | com_start = e_lab - s_lab - 2; | | 1149 | com_start = e_lab - s_lab - 2; |
1150 | } | | 1150 | } |
1151 | break; | | 1151 | break; |
1152 | case '"': | | 1152 | case '"': |
1153 | if (quote == '"') | | 1153 | if (quote == '"') |
1154 | quote = 0; | | 1154 | quote = '\0'; |
| | | 1155 | else if (quote == '\0') |
| | | 1156 | quote = '"'; |
1155 | break; | | 1157 | break; |
1156 | case '\'': | | 1158 | case '\'': |
1157 | if (quote == '\'') | | 1159 | if (quote == '\'') |
1158 | quote = 0; | | 1160 | quote = '\0'; |
| | | 1161 | else if (quote == '\0') |
| | | 1162 | quote = '\''; |
1159 | break; | | 1163 | break; |
1160 | case '*': | | 1164 | case '*': |
1161 | if (*buf_ptr == '/' && in_comment) { | | 1165 | if (*buf_ptr == '/' && in_comment) { |
1162 | in_comment = 0; | | 1166 | in_comment = 0; |
1163 | *e_lab++ = *buf_ptr++; | | 1167 | *e_lab++ = *buf_ptr++; |
1164 | com_end = e_lab - s_lab; | | 1168 | com_end = e_lab - s_lab; |
1165 | } | | 1169 | } |
1166 | break; | | 1170 | break; |
1167 | } | | 1171 | } |
1168 | } | | 1172 | } |
1169 | | | 1173 | |
1170 | while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) | | 1174 | while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) |
1171 | e_lab--; | | 1175 | e_lab--; |