5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or https://opensource.org/licenses/CDDL-1.0.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
22 # Copyright 2016 Nexenta Systems, Inc.
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 # @(#)cstyle 1.58 98/09/09 (from shannon)
28 #ident "%Z%%M% %I% %E% SMI"
30 # cstyle - check for some common stylistic errors.
32 # cstyle is a sort of "lint" for C coding style.
33 # It attempts to check for the style used in the
34 # kernel, sometimes known as "Bill Joy Normal Form".
36 # There's a lot this can't check for, like proper indentation
37 # of code blocks. There's also a lot more this could check for.
39 # A note to the non perl literate:
41 # perl regular expressions are pretty much like egrep
42 # regular expressions, with the following special symbols
44 # \s any space character
45 # \S any non-space character
46 # \w any "word" character [a-zA-Z0-9_]
47 # \W any non-word character
50 # \b word boundary (between \w and \W)
51 # \B non-word boundary
61 "usage: cstyle [-cgpvP] file...
62 -c check continuation indentation inside functions
63 -g print github actions' workflow commands
64 -p perform some of the more picky checks
66 -P check for use of non-POSIX types
71 if (!getopts
("cghpvCP", \
%opts)) {
76 my $check_continuation = $opts{'c'};
77 my $github_workflow = $opts{'g'} || $ENV{'CI'};
78 my $picky = $opts{'p'};
79 my $verbose = $opts{'v'};
80 my $check_posix_types = $opts{'P'};
82 my ($filename, $line, $prev); # shared globals
85 my $hdr_comment_start;
88 $fmt = "%s: %d: %s\n%s\n";
90 $fmt = "%s: %d: %s\n";
93 $hdr_comment_start = qr/^\s*\/\
*$/;
95 # Note, following must be in single quotes so that \s and \w work right.
96 my $typename = '(int|char|short|long|unsigned|float|double' .
97 '|\w+_t|struct\s+\w+|union\s+\w+|FILE)';
99 # mapping of old types to POSIX compatible types
101 'unchar' => 'uchar_t',
102 'ushort' => 'ushort_t',
104 'ulong' => 'ulong_t',
106 'u_short' => 'ushort_t',
107 'u_long' => 'ulong_t',
108 'u_char' => 'uchar_t',
112 my $lint_re = qr/\/\
*(?
:
113 NOTREACHED
|LINTLIBRARY
|VARARGS
[0-9]*|
114 CONSTCOND
|CONSTANTCOND
|CONSTANTCONDITION
|EMPTY
|
115 FALLTHRU
|FALLTHROUGH
|LINTED
.*?
|PRINTFLIKE
[0-9]*|
116 PROTOLIB
[0-9]*|SCANFLIKE
[0-9]*|CSTYLED
.*?
119 my $warlock_re = qr/\/\
*\s
*(?
:
120 VARIABLES\ PROTECTED\ BY
|
121 MEMBERS\ PROTECTED\ BY
|
122 ALL\ MEMBERS\ PROTECTED\ BY
|
123 READ
-ONLY\ VARIABLES
:|
125 VARIABLES\ READABLE\ WITHOUT\ LOCK
:|
126 MEMBERS\ READABLE\ WITHOUT\ LOCK
:|
128 LOCK\ UNNEEDED\ BECAUSE
|
130 LOCK\ HELD\ ON\ ENTRY
:|
131 READ\ LOCK\ HELD\ ON\ ENTRY
:|
132 WRITE\ LOCK\ HELD\ ON\ ENTRY
:|
133 LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT
:|
134 READ\ LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT
:|
135 WRITE\ LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT
:|
136 LOCK\ RELEASED\ AS\ SIDE\ EFFECT
:|
137 LOCK\ UPGRADED\ AS\ SIDE\ EFFECT
:|
138 LOCK\ DOWNGRADED\ AS\ SIDE\ EFFECT
:|
139 FUNCTIONS\ CALLED\ THROUGH\ POINTER
|
140 FUNCTIONS\ CALLED\ THROUGH\ MEMBER
|
144 my $err_stat = 0; # exit status
147 foreach my $arg (@ARGV) {
148 my $fh = new IO
::File
$arg, "r";
150 printf "%s: can not open\n", $arg;
157 &cstyle
("<stdin>", *STDIN
);
161 my $no_errs = 0; # set for CSTYLED-protected lines
167 printf $fmt, $filename, $., $error, $line;
169 printf $fmt, $filename, $., $error;
171 if ($github_workflow) {
172 printf "::error file=%s,line=%s::%s\n", $filename, $., $error;
179 my ($prevline, $error) = @_;
180 my $out = $prevline."\n".$line;
183 printf $fmt, $filename, $., $error, $out;
185 printf $fmt, $filename, $., $error;
195 printf $fmt, $filename, $. - 1, $error, $prev;
197 printf $fmt, $filename, $. - 1, $error;
205 my ($fn, $filehandle) = @_;
206 $filename = $fn; # share it globally
212 my $comment_done = 0;
213 my $in_warlock_comment = 0;
214 my $in_macro_call = 0;
216 my $in_function_header = 0;
217 my $function_header_full_indent = 0;
218 my $in_declaration = 0;
225 my ($okmsg, $comment_prefix);
231 line
: while (<$filehandle>) {
232 s/\r?\n$//; # strip return and newline
234 # save the original line, then remove all text from within
235 # double or single quotes, we do not want to check such text.
240 # C allows strings to be continued with a backslash at the end of
241 # the line. We translate that into a quoted string on the previous
242 # line followed by an initial quote on the next line.
244 # (we assume that no-one will use backslash-continuation with character
247 $_ = '"' . $_ if ($in_string && !$nocheck && !$in_comment);
250 # normal strings and characters
252 s/'([^\\']|\\[^xX0]|\\0[0-9]*|\\[xX][0-9a-fA-F]*)'/''/g;
253 s/"([^\\"]|\\.)*"/\"\"/g;
256 # detect string continuation
258 if ($nocheck || $in_comment) {
262 # Now that all full strings are replaced with "", we check
263 # for unfinished strings continuing onto the next line.
266 (s/([^"](?:"")*)"([^\\"]|\\.)*\\$/$1""/ ||
267 s/^("")*"([^\\"]|\\.)*\\$/""/);
271 # figure out if we are in a cpp directive
273 $in_cpp = $next_in_cpp || /^\s*#/; # continued or started
274 $next_in_cpp = $in_cpp && /\\$/; # only if continued
276 # strip off trailing backslashes, which appear in long macros
279 # an /* END CSTYLED */ comment ends a no-check block.
281 if (/\/\
* *END *CSTYLED
*\
*\
//) {
289 # a /*CSTYLED*/ comment indicates that the next line is ok.
296 if (/\/\
* *CSTYLED
.*\
*\
//) {
297 /^.*\/\
* *CSTYLED
*(.*) *\
*\
/.*$/;
306 # check length of line.
307 # first, a quick check to see if there is any chance of being too long.
308 if (($line =~ tr/\t/\t/) * 7 + length($line) > 80) {
309 # yes, there is a chance.
310 # replace tabs with spaces and check again.
313 s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
314 if (length($eline) > 80) {
315 err
("line > 80 characters");
319 # ignore NOTE(...) annotations (assumes NOTE is on lines by itself).
320 if ($note_level || /\b_?NOTE\s*\(/) { # if in NOTE or this is NOTE
321 s/[^()]//g; # eliminate all non-parens
322 $note_level += s/\(//g - length; # update paren nest level
326 # a /* BEGIN CSTYLED */ comment starts a no-check block.
327 if (/\/\
* *BEGIN *CSTYLED
*\
*\
//) {
331 # a /*CSTYLED*/ comment indicates that the next line is ok.
332 if (/\/\
* *CSTYLED
.*\
*\
//) {
333 /^.*\/\
* *CSTYLED
*(.*) *\
*\
/.*$/;
337 if (/\/\
/ *CSTYLED/) {
338 /^.*\/\
/ *CSTYLED *(.*)$/;
343 # universal checks; apply to everything
345 err
("spaces between tabs");
348 err
("tabs between spaces");
351 err
("space or tab at end of line");
353 if (/[^ \t(]\/\
*/ && !/\w\
(\
/\*.*\*\/\
);/) {
354 err
("comment preceded by non-blank");
357 err
("ARGSUSED directive");
360 # is this the beginning or ending of a function?
361 # (not if "struct foo\n{\n")
362 if (/^\{$/ && $prev =~ /\)\s*(const\s*)?(\/\
*.*\
*\
/\s*)?\\?$/) {
365 $in_function_header = 0;
366 $function_header_full_indent = 0;
370 if (/^\}\s*(\/\
*.*\
*\
/\s*)*$/) {
371 if ($prev =~ /^\s*return\s*;/) {
372 err_prev
("unneeded return at end of function");
375 reset_indent
(); # we don't check between functions
379 if ($in_function_header && ! /^ (\w|\.)/ ) {
380 if (/^\{\}$/ # empty functions
381 || /;/ #run function with multiline arguments
382 || /#/ #preprocessor commands
383 || /^[^\s\\]*\(.*\)$/ #functions without ; at the end
384 || /^$/ #function declaration can't have empty line
386 $in_function_header = 0;
387 $function_header_full_indent = 0;
388 } elsif ($prev =~ /^__attribute__/) { #__attribute__((*))
389 $in_function_header = 0;
390 $function_header_full_indent = 0;
393 } elsif ($picky && ! (/^\t/ && $function_header_full_indent != 0)) {
395 err
("continuation line should be indented by 4 spaces");
399 # If this looks like a top-level macro invocation, remember it so we
400 # don't mistake it for a function declaration below.
401 if (/^[A-Za-z_][A-Za-z_0-9]*\(/) {
406 # If this matches something of form "foo(", it's probably a function
407 # definition, unless it ends with ") bar;", in which case it's a declaration
408 # that uses a macro to generate the type.
410 if (!$in_macro_call && /^\w+\(/ && !/\) \w+;/) {
411 $in_function_header = 1;
413 $function_header_full_indent = 1;
416 if ($in_function_header && /^\{$/) {
417 $in_function_header = 0;
418 $function_header_full_indent = 0;
421 if ($in_function_header && /\);$/) {
422 $in_function_header = 0;
423 $function_header_full_indent = 0;
425 if ($in_function_header && /\{$/ ) {
427 err
("opening brace on same line as function header");
429 $in_function_header = 0;
430 $function_header_full_indent = 0;
435 if ($in_warlock_comment && /\*\//) {
436 $in_warlock_comment = 0;
441 # a blank line terminates the declarations within a function.
442 # XXX - but still a problem in sub-blocks.
443 if ($in_declaration && /^$/) {
451 # does this looks like the start of a block comment?
452 if (/$hdr_comment_start/) {
454 err
("block comment not indented by tabs");
458 $comment_prefix = $1;
462 # are we still in the block comment?
464 if (/^$comment_prefix \*\/$/) {
468 err
("improper block comment close");
469 } elsif (!/^$comment_prefix \*[ \t]/ &&
470 !/^$comment_prefix \*$/) {
471 err
("improper block comment");
475 # check for errors that might occur in comments and in code.
477 # allow spaces to be used to draw pictures in all comments.
478 if (/[^ ] / && !/".* .*"/ && !$in_comment) {
479 err
("spaces instead of tabs");
481 if (/^ / && !/^ \*[ \t\/]/ && !/^ \
*$/ &&
482 (!/^ (\w|\.)/ || $in_function != 0)) {
483 err
("indent by spaces instead of tabs");
485 if (/^\t+ [^ \t\*]/ || /^\t+ \S/ || /^\t+ \S/) {
486 err
("continuation line not indented by 4 spaces");
488 if (/$warlock_re/ && !/\*\//) {
489 $in_warlock_comment = 1;
493 if (/^\s*\/\
*./ && !/^\s
*\
/\*.*\*\// && !/$hdr_comment_start/) {
494 err
("improper first line of block comment");
497 if ($in_comment) { # still in comment, don't do further checks
502 if ((/[^(]\/\
*\S
/ || /^\
/\*\S/) && !/$lint_re/) {
503 err
("missing blank after open comment");
505 if (/\S\*\/[^)]|\S\
*\
/$/ && !/$lint_re/) {
506 err
("missing blank before close comment");
508 # check for unterminated single line comments, but allow them when
509 # they are used to comment out the argument list of a function
511 if (/\S.*\/\
*/ && !/\S
.*\
/\*.*\*\// && !/\
(\
/\*/) {
512 err
("unterminated single line comment");
515 if (/^(#else|#endif|#include)(.*)$/) {
520 # Enforce ANSI rules for #else and #endif: no noncomment
521 # identifiers are allowed after #endif or #else. Allow
522 # C++ comments since they seem to be a fact of life.
523 if ((($1 eq "#endif") || ($1 eq "#else")) &&
525 (!($clause =~ /^\s+\/\
*.*\
*\
/$/)) &&
526 (!($clause =~ /^\s+\/\
/.*$/))) {
527 err
("non-comment text following " .
528 "$directive (or malformed $directive " .
536 # delete any comments and check everything else. Note that
537 # ".*?" is a non-greedy match, so that we don't get confused by
538 # multiple comments on the same line.
540 s/\/\*.*?\*\//\x01/g;
541 s/\/\/(?
:\s
.*)?
$/\x01/; # Valid C++ comments
543 # After stripping correctly spaced comments, check for (and strip) comments
544 # without a blank. By checking this after clearing out C++ comments that
545 # correctly have a blank, we guarantee URIs in a C++ comment will not cause
547 if (s!//.*$!\x01!) { # C++ comments
548 err
("missing blank after start comment");
551 # delete any trailing whitespace; we have already checked for that.
554 # following checks do not apply to text in comments.
556 if (/[^<>\s][!<>=]=/ || /[^<>][!<>=]=[^\s,]/ ||
557 (/[^->]>[^,=>\s]/ && !/[^->]>$/) ||
558 (/[^<]<[^,=<\s]/ && !/[^<]<$/) ||
559 /[^<\s]<[^<]/ || /[^->\s]>[^>]/) {
560 err
("missing space around relational operator");
562 if (/\S>>=/ || /\S<<=/ || />>=\S/ || /<<=\S/ || /\S[-+*\/&|^%]=/ ||
563 (/[^-+*\/&|^%!<>=\s
]=[^=]/ && !/[^-+*\
/&|^%!<>=\s]=$/) ||
564 (/[^!<>=]=[^=\s]/ && !/[^!<>=]=$/)) {
565 # XXX - should only check this for C++ code
566 # XXX - there are probably other forms that should be allowed
567 if (!/\soperator=/) {
568 err
("missing space around assignment operator");
571 if (/[,;]\S/ && !/\bfor \(;;\)/) {
572 err
("comma or semicolon followed by non-blank");
574 # allow "for" statements to have empty "while" clauses
575 # allow macro invocations to have empty parameters
576 if (/\s[,;]/ && !/^[\t]+;$/ &&
577 !($in_macro_call || /^\s*for \([^;]*; ;[^;]*\)/)) {
578 err
("comma or semicolon preceded by blank");
580 if (/^\s*(&&|\|\|)/) {
581 err
("improper boolean continuation");
583 if (/\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
584 err
("more than one space around boolean operator");
586 if (/\b(for|if|while|switch|sizeof|return|case)\(/) {
587 err
("missing space between keyword and paren");
589 if (/(\b(for|if|while|switch|return)\b.*){2,}/ && !/^#define/) {
590 # multiple "case" and "sizeof" allowed
591 err
("more than one keyword on line");
593 if (/\b(for|if|while|switch|sizeof|return|case)\s\s+\(/ &&
595 err
("extra space between keyword and paren");
597 # try to detect "func (x)" but not "if (x)" or
598 # "#define foo (x)" or "int (*func)();"
601 # strip off all keywords on the line
602 s/\b(for|if|while|switch|return|case|sizeof)\s\(/XXX(/g;
604 s/^#define\s+\w+\s+\(/XXX(/;
605 # do not match things like "void (*f)();"
606 # or "typedef void (func_t)();"
608 s/\b($typename|void)\s+\(+/XXX(/og;
610 err
("extra space between function name and left paren");
614 # try to detect "int foo(x)", but not "extern int foo(x);"
615 # XXX - this still trips over too many legitimate things,
616 # like "int foo(x,\n\ty);"
617 # if (/^(\w+(\s|\*)+)+\w+\(/ && !/\)[;,](\s|\x01)*$/ &&
618 # !/^(extern|static)\b/) {
619 # err("return type of function not on separate line");
621 # this is a close approximation
622 if (/^(\w+(\s|\*)+)+\w+\(.*\)(\s|\x01)*$/ &&
623 !/^(extern|static)\b/) {
624 err
("return type of function not on separate line");
627 err
("#define followed by space instead of tab");
629 if (/^\s*return\W[^;]*;/ && !/^\s*return\s*\(.*\);/) {
630 err
("unparenthesized return expression");
632 if (/\bsizeof\b/ && !/\bsizeof\s*\(.*\)/) {
633 err
("unparenthesized sizeof expression");
636 err
("whitespace after left paren");
638 # Allow "for" statements to have empty "continue" clauses.
639 # Allow right paren on its own line unless we're being picky (-p).
640 if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/ && ($picky || !/^\s*\)/)) {
641 err
("whitespace before right paren");
643 if (/^\s*\(void\)[^ ]/) {
644 err
("missing space after (void) cast");
646 if (/\S\{/ && !/\{\{/) {
647 err
("missing space before left brace");
649 if ($in_function && /^\s+\{/ &&
650 ($prev =~ /\)\s*$/ || $prev =~ /\bstruct\s+\w+$/)) {
651 err
("left brace starting a line");
653 if (/\}(else|while)/) {
654 err
("missing space after right brace");
656 if (/\}\s\s+(else|while)/) {
657 err
("extra space after right brace");
659 if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
660 err
("obsolete use of VOID or STATIC");
662 if (/\b$typename\*/o) {
663 err
("missing space between type name and *");
666 err
("preprocessor statement not in column 1");
669 err
("blank after preprocessor #");
671 if (/!\s*(strcmp|strncmp|bcmp)\s*\(/) {
672 err
("don't use boolean ! with comparison functions");
676 # We completely ignore, for purposes of indentation:
677 # * lines outside of functions
678 # * preprocessor lines
680 if ($check_continuation && $in_function && !$in_cpp) {
684 # try to detect spaces after casts, but allow (e.g.)
685 # "sizeof (int) + 1", "void (*funcptr)(int) = foo;", and
686 # "int foo(int) __NORETURN;"
687 if ((/^\($typename( \*+)?\)\s/o ||
688 /\W\($typename( \*+)?\)\s/o) &&
689 !/sizeof\s*\($typename( \*)?\)\s/o &&
690 !/\($typename( \*+)?\)\s+=[^=]/o) {
691 err
("space after cast");
693 if (/\b$typename\s*\*\s/o &&
694 !/\b$typename\s*\*\s+const\b/o) {
695 err
("unary * followed by space");
698 if ($check_posix_types && !$in_macro_call) {
699 # try to detect old non-POSIX types.
700 # POSIX requires all non-standard typedefs to end in _t,
701 # but historically these have been used.
703 # We don't check inside macro invocations because macros have
704 # legitmate uses for these names in function generators.
705 if (/\b(unchar|ushort|uint|ulong|u_int|u_short|u_long|u_char|quad)\b/) {
706 err
("non-POSIX typedef $1 used: use $old2posix{$1} instead");
710 if ($prev =~ /^\s*\}$/) {
712 "else and right brace should be on same line");
716 # Macro invocations end with a closing paren, and possibly a semicolon.
717 # We do this check down here to make sure all the regular checks are
718 # applied to calls that appear entirely on a single line.
719 if ($in_macro_call && /\);?$/) {
727 err
("last line in file is blank");
733 # Continuation-line checking
735 # The rest of this file contains the code for the continuation checking
736 # engine. It's a pretty simple state machine which tracks the expression
737 # depth (unmatched '('s and '['s).
739 # Keep in mind that the argument to process_indent() has already been heavily
740 # processed; all comments have been replaced by control-A, and the contents of
741 # strings and character constants have been elided.
744 my $cont_in; # currently inside of a continuation
745 my $cont_off; # skipping an initializer or definition
746 my $cont_noerr; # suppress cascading errors
747 my $cont_start; # the line being continued
748 my $cont_base; # the base indentation
749 my $cont_first; # this is the first line of a statement
750 my $cont_multiseg; # this continuation has multiple segments
752 my $cont_special; # this is a C statement (if, for, etc.)
753 my $cont_macro; # this is a macro
754 my $cont_case; # this is a multi-line case
756 my @cont_paren; # the stack of unmatched ( and [s we've seen
769 # replace labels with tabs. Note that there may be multiple
774 while (/^(\t*)( *(?:(?:\w+\s*)|(?:case\b[^:]*)): *)(.*)$/) {
775 my ($pre_tabs, $label, $rest) = ($1, $2, $3);
777 while ($label =~ s/^([^\t]*)(\t+)//) {
778 $_ .= "\t" x
(length($2) + length($1) / 8);
780 $_ .= ("\t" x
(length($label) / 8)).$rest;
790 local $_ = $_[0]; # preserve the global $_
792 s/\x01//g; # No comments
793 s/\s+$//; # Strip trailing whitespace
795 return if (/^$/); # skip empty lines
797 # regexps used below; keywords taking (), macros, and continued cases
798 my $special = '(?:(?:\}\s*)?else\s+)?(?:if|for|while|switch)\b';
799 my $macro = '[A-Z_][A-Z_0-9]*\(';
800 my $case = 'case\b[^:]*$';
802 # skip over enumerations, array definitions, initializers, etc.
803 if ($cont_off <= 0 && !/^\s*$special/ &&
804 (/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*))\{/ ||
805 (/^\s*\{/ && $prev =~ /=\s*(?:\/\
*.*\
*\
/\s*)*$/))) {
807 $cont_off = tr/{/{/ - tr/}/}/;
811 $cont_off += tr/{/{/ - tr/}/}/;
819 err
("non-continuation indented 4 spaces");
820 $cont_noerr = 1; # stop reporting
822 $_ = delabel
($_); # replace labels with tabs
824 # check if the statement is complete
825 return if (/^\s*\}?$/);
826 return if (/^\s*\}?\s*else\s*\{?$/);
827 return if (/^\s*do\s*\{?$/);
829 return if (/\}[,;]?$/);
831 # Allow macros on their own lines
832 return if (/^\s*[A-Z_][A-Z_0-9]*$/);
834 # cases we don't deal with, generally non-kosher
836 err
("stuff after {");
840 # Get the base line, and set up the state machine
848 # certain things need special processing
849 $cont_special = /^\s*$special/?
1 : 0;
850 $cont_macro = /^\s*$macro/?
1 : 0;
851 $cont_case = /^\s*$case/?
1 : 0;
855 # Strings may be pulled back to an earlier (half-)tabstop
856 unless ($cont_noerr || /^$cont_base / ||
857 (/^\t*(?: )?(?:gettext\()?\"/ && !/^$cont_base\t/)) {
858 err_prefix
($cont_start,
859 "continuation should be indented 4 spaces");
863 my $rest = $_; # keeps the remainder of the line
866 # The split matches 0 characters, so that each 'special' character
867 # is processed separately. Parens and brackets are pushed and
868 # popped off the @cont_paren stack. For normal processing, we wait
869 # until a ; or { terminates the statement. "special" processing
870 # (if/for/while/switch) is allowed to stop when the stack empties,
871 # as is macro processing. Case statements are terminated with a :
872 # and an empty paren stack.
874 foreach $_ (split /[^\(\)\[\]\{\}\;\:]*/) {
875 next if (length($_) == 0);
877 # rest contains the remainder of the line
878 my $rxp = "[^\Q$_\E]*\Q$_\E";
882 push @cont_paren, $_;
883 } elsif (/\)/ || /\]/) {
887 my $old = (pop @cont_paren);
888 if (!defined($old)) {
889 err
("unexpected '$cur'");
892 } elsif ($old ne $_) {
893 err
("'$cur' mismatched with '$old'");
899 # If the stack is now empty, do special processing
900 # for if/for/while/switch and macro statements.
902 next if (@cont_paren != 0);
904 if ($rest =~ /^\s*\{?$/) {
908 if ($rest =~ /^\s*;$/) {
909 err
("empty if/for/while body ".
910 "not on its own line");
914 if (!$cont_first && $cont_multiseg == 1) {
915 err_prefix
($cont_start,
916 "multiple statements continued ".
917 "over multiple lines");
919 } elsif ($cont_multiseg == 0) {
922 # We've finished this section, start
923 # processing the next.
935 } elsif (!$cont_special) {
936 err
("unexpected ;") if (@cont_paren != 0);
937 if (!$cont_first && $cont_multiseg == 1) {
938 err_prefix
($cont_start,
939 "multiple statements continued ".
940 "over multiple lines");
942 } elsif ($cont_multiseg == 0) {
949 if ($rest =~ /^\s*special/) {
950 err
("if/for/while/switch not started ".
956 err
("{ while in parens/brackets") if (@cont_paren != 0);
957 err
("stuff after {") if ($rest =~ /[^\s}]/);
961 err
("} while in parens/brackets") if (@cont_paren != 0);
962 if (!$cont_special && $rest !~ /^\s*(while|else)\b/) {
966 err
("stuff after }");
971 } elsif (/\:/ && $cont_case && @cont_paren == 0) {
972 err
("stuff after multi-line case") if ($rest !~ /$^/);
978 # End of a statement or if/while/for loop. Reset
979 # cont_special and cont_macro based on the rest of the
981 $cont_special = ($rest =~ /^\s*$special/)?
1 : 0;
982 $cont_macro = ($rest =~ /^\s*$macro/)?
1 : 0;
986 $cont_noerr = 0 if (!$cont_in);