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 http://www.opensolaris.org/os/licensing.
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]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # @(#)cstyle 1.58 98/09/09 (from shannon)
27 #ident "%Z%%M% %I% %E% SMI"
29 # cstyle - check for some common stylistic errors.
31 # cstyle is a sort of "lint" for C coding style.
32 # It attempts to check for the style used in the
33 # kernel, sometimes known as "Bill Joy Normal Form".
35 # There's a lot this can't check for, like proper indentation
36 # of code blocks. There's also a lot more this could check for.
38 # A note to the non perl literate:
40 # perl regular expressions are pretty much like egrep
41 # regular expressions, with the following special symbols
43 # \s any space character
44 # \S any non-space character
45 # \w any "word" character [a-zA-Z0-9_]
46 # \W any non-word character
49 # \b word boundary (between \w and \W)
50 # \B non-word boundary
59 "usage: cstyle [-chpvCP] [-o constructs] file ...
60 -c check continuation indentation inside functions
61 -h perform heuristic checks that are sometimes wrong
62 -p perform some of the more picky checks
64 -C don't check anything in header block comments
65 -P check for use of non-POSIX types
67 allow a comma-seperated list of optional constructs:
68 doxygen allow doxygen-style block comments (/** /*!)
69 splint allow splint-style lint comments (/*@ ... @*/)
74 if (!getopts
("cho:pvCP", \
%opts)) {
79 my $check_continuation = $opts{'c'};
80 my $heuristic = $opts{'h'};
81 my $picky = $opts{'p'};
82 my $verbose = $opts{'v'};
83 my $ignore_hdr_comment = $opts{'C'};
84 my $check_posix_types = $opts{'P'};
86 my $doxygen_comments = 0;
87 my $splint_comments = 0;
89 if (defined($opts{'o'})) {
90 for my $x (split /,/, $opts{'o'}) {
91 if ($x eq "doxygen") {
92 $doxygen_comments = 1;
93 } elsif ($x eq "splint") {
96 print "cstyle: unrecognized construct \"$x\"\n";
103 my ($filename, $line, $prev); # shared globals
106 my $hdr_comment_start;
109 $fmt = "%s: %d: %s\n%s\n";
111 $fmt = "%s: %d: %s\n";
114 if ($doxygen_comments) {
115 # doxygen comments look like "/*!" or "/**"; allow them.
116 $hdr_comment_start = qr/^\s*\/\*[\!\*]?$/;
118 $hdr_comment_start = qr/^\s*\/\*$/;
121 # Note, following must be in single quotes so that \s and \w work right.
122 my $typename = '(int|char|short|long|unsigned|float|double' .
123 '|\w+_t|struct\s+\w+|union\s+\w+|FILE)';
125 # mapping of old types to POSIX compatible types
127 'unchar' => 'uchar_t',
128 'ushort' => 'ushort_t',
130 'ulong' => 'ulong_t',
132 'u_short' => 'ushort_t',
133 'u_long' => 'ulong_t',
134 'u_char' => 'uchar_t',
138 my $lint_re = qr/\/\*(?:
139 ARGSUSED[0-9]*|NOTREACHED|LINTLIBRARY|VARARGS[0-9]*|
140 CONSTCOND|CONSTANTCOND|CONSTANTCONDITION|EMPTY|
141 FALLTHRU|FALLTHROUGH|LINTED.*?|PRINTFLIKE[0-9]*|
142 PROTOLIB[0-9]*|SCANFLIKE[0-9]*|CSTYLED.*?
145 my $splint_re = qr/\/\*@.*?@\*\//x;
147 my $warlock_re = qr/\/\*\s*(?:
148 VARIABLES\ PROTECTED\ BY|
149 MEMBERS\ PROTECTED\ BY|
150 ALL\ MEMBERS\ PROTECTED\ BY|
151 READ-ONLY\ VARIABLES:|
153 VARIABLES\ READABLE\ WITHOUT\ LOCK:|
154 MEMBERS\ READABLE\ WITHOUT\ LOCK:|
156 LOCK\ UNNEEDED\ BECAUSE|
158 LOCK\ HELD\ ON\ ENTRY:|
159 READ\ LOCK\ HELD\ ON\ ENTRY:|
160 WRITE\ LOCK\ HELD\ ON\ ENTRY:|
161 LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT:|
162 READ\ LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT:|
163 WRITE\ LOCK\ ACQUIRED\ AS\ SIDE\ EFFECT:|
164 LOCK\ RELEASED\ AS\ SIDE\ EFFECT:|
165 LOCK\ UPGRADED\ AS\ SIDE\ EFFECT:|
166 LOCK\ DOWNGRADED\ AS\ SIDE\ EFFECT:|
167 FUNCTIONS\ CALLED\ THROUGH\ POINTER|
168 FUNCTIONS\ CALLED\ THROUGH\ MEMBER|
172 my $err_stat = 0; # exit status
175 foreach my $arg (@ARGV) {
176 my $fh = new IO::File $arg, "r
";
178 printf "%s: can
not open\n", $arg;
185 &cstyle("<stdin
>", *STDIN);
189 my $no_errs = 0; # set for CSTYLED-protected lines
194 printf $fmt, $filename, $., $error, $line;
200 my ($prevline, $error) = @_;
201 my $out = $prevline."\n".$line;
203 printf $fmt, $filename, $., $error, $out;
211 printf $fmt, $filename, $. - 1, $error, $prev;
218 my ($fn, $filehandle) = @_;
219 $filename = $fn; # share it globally
225 my $in_header_comment = 0;
226 my $comment_done = 0;
227 my $in_warlock_comment = 0;
229 my $in_function_header = 0;
230 my $in_declaration = 0;
237 my ($okmsg, $comment_prefix);
243 line: while (<$filehandle>) {
244 s/\r?\n$//; # strip return and newline
246 # save the original line, then remove all text from within
247 # double or single quotes, we do not want to check such text.
252 # C allows strings to be continued with a backslash at the end of
253 # the line. We translate that into a quoted string on the previous
254 # line followed by an initial quote on the next line.
256 # (we assume that no-one will use backslash-continuation with character
259 $_ = '"' . $_ if ($in_string && !$nocheck && !$in_comment);
262 # normal strings and characters
264 s/'([^\\']|\\[^xX0]|\\0[0-9]*|\\[xX][0-9a-fA-F]*)'/''/g;
265 s/"([^\\"]|\\.)*"/\"\"/g;
268 # detect string continuation
270 if ($nocheck || $in_comment) {
274 # Now that all full strings are replaced with "", we check
275 # for unfinished strings continuing onto the next line.
278 (s/([^"](?:"")*)"([^\\"]|\\.)*\\$/$1""/ ||
279 s/^("")*"([^\\"]|\\.)*\\$/""/);
283 # figure out if we are in a cpp directive
285 $in_cpp = $next_in_cpp || /^\s*#/; # continued or started
286 $next_in_cpp = $in_cpp && /\\$/; # only if continued
288 # strip off trailing backslashes, which appear in long macros
291 # an /* END CSTYLED */ comment ends a no-check block.
293 if (/\/\* *END *CSTYLED *\*\//) {
301 # a /*CSTYLED*/ comment indicates that the next line is ok.
308 if (/\/\* *CSTYLED.*\*\//) {
309 /^.*\/\* *CSTYLED *(.*) *\*\/.*$/;
318 # check length of line.
319 # first, a quick check to see if there is any chance of being too long.
320 if (($line =~ tr/\t/\t/) * 7 + length($line) > 80) {
321 # yes, there is a chance.
322 # replace tabs with spaces and check again.
325 s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
326 if (length($eline) > 80) {
327 err("line > 80 characters");
331 # ignore NOTE(...) annotations (assumes NOTE is on lines by itself).
332 if ($note_level || /\b_?NOTE\s*\(/) { # if in NOTE or this is NOTE
333 s/[^()]//g; # eliminate all non-parens
334 $note_level += s/\(//g - length; # update paren nest level
338 # a /* BEGIN CSTYLED */ comment starts a no-check block.
339 if (/\/\* *BEGIN *CSTYLED *\*\//) {
343 # a /*CSTYLED*/ comment indicates that the next line is ok.
344 if (/\/\* *CSTYLED.*\*\//) {
345 /^.*\/\* *CSTYLED *(.*) *\*\/.*$/;
349 if (/\/\/ *CSTYLED/) {
350 /^.*\/\/ *CSTYLED *(.*)$/;
355 # universal checks; apply to everything
357 err("spaces between tabs");
360 err("tabs between spaces");
363 err("space or tab at end of line");
365 if (/[^ \t(]\/\*/ && !/\w\(\/\*.*\*\/\);/) {
366 err("comment preceded by non-blank");
369 # is this the beginning or ending of a function?
370 # (not if "struct foo\n{\n")
371 if (/^{$/ && $prev =~ /\)\s*(const\s*)?(\/\*.*\*\/\s*)?\\?$/) {
374 $in_function_header = 0;
378 if (/^}\s*(\/\*.*\*\/\s*)*$/) {
379 if ($prev =~ /^\s*return\s*;/) {
380 err_prev("unneeded return at end of function");
383 reset_indent(); # we don't check between functions
388 $in_function_header = 1;
391 if ($in_warlock_comment && /\*\//) {
392 $in_warlock_comment = 0;
397 # a blank line terminates the declarations within a function.
398 # XXX - but still a problem in sub-blocks.
399 if ($in_declaration && /^$/) {
405 $in_header_comment = 0;
408 # does this looks like the start of a block comment?
409 if (/$hdr_comment_start/) {
411 err
("block comment not indented by tabs");
415 $comment_prefix = $1;
416 if ($comment_prefix eq "") {
417 $in_header_comment = 1;
422 # are we still in the block comment?
424 if (/^$comment_prefix \*\/$/) {
428 err
("improper block comment close")
429 unless ($ignore_hdr_comment && $in_header_comment);
430 } elsif (!/^$comment_prefix \*[ \t]/ &&
431 !/^$comment_prefix \*$/) {
432 err
("improper block comment")
433 unless ($ignore_hdr_comment && $in_header_comment);
437 if ($in_header_comment && $ignore_hdr_comment) {
442 # check for errors that might occur in comments and in code.
444 # allow spaces to be used to draw pictures in all comments.
445 if (/[^ ] / && !/".* .*"/ && !$in_comment) {
446 err
("spaces instead of tabs");
448 if (/^ / && !/^ \*[ \t\/]/ && !/^ \
*$/ &&
449 (!/^ \w/ || $in_function != 0)) {
450 err
("indent by spaces instead of tabs");
452 if (/^\t+ [^ \t\*]/ || /^\t+ \S/ || /^\t+ \S/) {
453 err
("continuation line not indented by 4 spaces");
455 if (/$warlock_re/ && !/\*\//) {
456 $in_warlock_comment = 1;
460 if (/^\s*\/\
*./ && !/^\s
*\
/\*.*\*\// && !/$hdr_comment_start/) {
461 err
("improper first line of block comment");
464 if ($in_comment) { # still in comment, don't do further checks
469 if ((/[^(]\/\
*\S
/ || /^\
/\*\S/) &&
470 !(/$lint_re/ || ($splint_comments && /$splint_re/))) {
471 err
("missing blank after open comment");
473 if (/\S\*\/[^)]|\S\
*\
/$/ &&
474 !(/$lint_re/ || ($splint_comments && /$splint_re/))) {
475 err
("missing blank before close comment");
477 if (/\/\
/\S/) { # C++ comments
478 err
("missing blank after start comment");
480 # check for unterminated single line comments, but allow them when
481 # they are used to comment out the argument list of a function
483 if (/\S.*\/\
*/ && !/\S
.*\
/\*.*\*\// && !/\
(\
/\*/) {
484 err
("unterminated single line comment");
487 if (/^(#else|#endif|#include)(.*)$/) {
492 # Enforce ANSI rules for #else and #endif: no noncomment
493 # identifiers are allowed after #endif or #else. Allow
494 # C++ comments since they seem to be a fact of life.
495 if ((($1 eq "#endif") || ($1 eq "#else")) &&
497 (!($clause =~ /^\s+\/\
*.*\
*\
/$/)) &&
498 (!($clause =~ /^\s+\/\
/.*$/))) {
499 err
("non-comment text following " .
500 "$directive (or malformed $directive " .
508 # delete any comments and check everything else. Note that
509 # ".*?" is a non-greedy match, so that we don't get confused by
510 # multiple comments on the same line.
513 s/\/\/.*$/\ 1/; # C++ comments
515 # delete any trailing whitespace; we have already checked for that.
518 # following checks do not apply to text in comments.
520 if (/[^<>\s][!<>=]=/ || /[^<>][!<>=]=[^\s,]/ ||
521 (/[^->]>[^,=>\s]/ && !/[^->]>$/) ||
522 (/[^<]<[^,=<\s]/ && !/[^<]<$/) ||
523 /[^<\s]<[^<]/ || /[^->\s]>[^>]/) {
524 err
("missing space around relational operator");
526 if (/\S>>=/ || /\S<<=/ || />>=\S/ || /<<=\S/ || /\S[-+*\/&|^%]=/ ||
527 (/[^-+*\/&|^%!<>=\s
]=[^=]/ && !/[^-+*\
/&|^%!<>=\s]=$/) ||
528 (/[^!<>=]=[^=\s]/ && !/[^!<>=]=$/)) {
529 # XXX - should only check this for C++ code
530 # XXX - there are probably other forms that should be allowed
531 if (!/\soperator=/) {
532 err
("missing space around assignment operator");
535 if (/[,;]\S/ && !/\bfor \(;;\)/) {
536 err
("comma or semicolon followed by non-blank");
538 # allow "for" statements to have empty "while" clauses
539 if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
540 err
("comma or semicolon preceded by blank");
542 if (/^\s*(&&|\|\|)/) {
543 err
("improper boolean continuation");
545 if (/\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
546 err
("more than one space around boolean operator");
548 if (/\b(for|if|while|switch|sizeof|return|case)\(/) {
549 err
("missing space between keyword and paren");
551 if (/(\b(for|if|while|switch|return)\b.*){2,}/ && !/^#define/) {
552 # multiple "case" and "sizeof" allowed
553 err
("more than one keyword on line");
555 if (/\b(for|if|while|switch|sizeof|return|case)\s\s+\(/ &&
557 err
("extra space between keyword and paren");
559 # try to detect "func (x)" but not "if (x)" or
560 # "#define foo (x)" or "int (*func)();"
563 # strip off all keywords on the line
564 s/\b(for|if|while|switch|return|case|sizeof)\s\(/XXX(/g;
566 s/^#define\s+\w+\s+\(/XXX(/;
567 # do not match things like "void (*f)();"
568 # or "typedef void (func_t)();"
570 s/\b($typename|void)\s+\(+/XXX(/og;
572 err
("extra space between function name and left paren");
576 # try to detect "int foo(x)", but not "extern int foo(x);"
577 # XXX - this still trips over too many legitimate things,
578 # like "int foo(x,\n\ty);"
579 # if (/^(\w+(\s|\*)+)+\w+\(/ && !/\)[;,](\s|\ 1)*$/ &&
580 # !/^(extern|static)\b/) {
581 # err("return type of function not on separate line");
583 # this is a close approximation
584 if (/^(\w+(\s|\*)+)+\w+\(.*\)(\s|\ 1)*$/ &&
585 !/^(extern|static)\b/) {
586 err
("return type of function not on separate line");
589 err
("#define followed by space instead of tab");
591 if (/^\s*return\W[^;]*;/ && !/^\s*return\s*\(.*\);/) {
592 err
("unparenthesized return expression");
594 if (/\bsizeof\b/ && !/\bsizeof\s*\(.*\)/) {
595 err
("unparenthesized sizeof expression");
598 err
("whitespace after left paren");
600 # Allow "for" statements to have empty "continue" clauses.
601 # Allow right paren on its own line unless we're being picky (-p).
602 if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/ && ($picky || !/^\s*\)/)) {
603 err
("whitespace before right paren");
605 if (/^\s*\(void\)[^ ]/) {
606 err
("missing space after (void) cast");
608 if (/\S{/ && !/{{/) {
609 err
("missing space before left brace");
611 if ($in_function && /^\s+{/ &&
612 ($prev =~ /\)\s*$/ || $prev =~ /\bstruct\s+\w+$/)) {
613 err
("left brace starting a line");
615 if (/}(else|while)/) {
616 err
("missing space after right brace");
618 if (/}\s\s+(else|while)/) {
619 err
("extra space after right brace");
621 if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
622 err
("obsolete use of VOID or STATIC");
624 if (/\b$typename\*/o) {
625 err
("missing space between type name and *");
628 err
("preprocessor statement not in column 1");
631 err
("blank after preprocessor #");
633 if (/!\s*(strcmp|strncmp|bcmp)\s*\(/) {
634 err
("don't use boolean ! with comparison functions");
638 # We completely ignore, for purposes of indentation:
639 # * lines outside of functions
640 # * preprocessor lines
642 if ($check_continuation && $in_function && !$in_cpp) {
646 # try to detect spaces after casts, but allow (e.g.)
647 # "sizeof (int) + 1", "void (*funcptr)(int) = foo;", and
648 # "int foo(int) __NORETURN;"
649 if ((/^\($typename( \*+)?\)\s/o ||
650 /\W\($typename( \*+)?\)\s/o) &&
651 !/sizeof\s*\($typename( \*)?\)\s/o &&
652 !/\($typename( \*+)?\)\s+=[^=]/o) {
653 err
("space after cast");
655 if (/\b$typename\s*\*\s/o &&
656 !/\b$typename\s*\*\s+const\b/o) {
657 err
("unary * followed by space");
660 if ($check_posix_types) {
661 # try to detect old non-POSIX types.
662 # POSIX requires all non-standard typedefs to end in _t,
663 # but historically these have been used.
664 if (/\b(unchar|ushort|uint|ulong|u_int|u_short|u_long|u_char|quad)\b/) {
665 err
("non-POSIX typedef $1 used: use $old2posix{$1} instead");
669 # cannot check this everywhere due to "struct {\n...\n} foo;"
670 if ($in_function && !$in_declaration &&
671 /}./ && !/}\s+=/ && !/{.*}[;,]$/ && !/}(\s|\ 1)*$/ &&
672 !/} (else|while)/ && !/}}/) {
673 err
("possible bad text following right brace");
675 # cannot check this because sub-blocks in
676 # the middle of code are ok
677 if ($in_function && /^\s+{/) {
678 err
("possible left brace starting a line");
682 if ($prev =~ /^\s*}$/) {
684 "else and right brace should be on same line");
691 err
("last line in file is blank");
697 # Continuation-line checking
699 # The rest of this file contains the code for the continuation checking
700 # engine. It's a pretty simple state machine which tracks the expression
701 # depth (unmatched '('s and '['s).
703 # Keep in mind that the argument to process_indent() has already been heavily
704 # processed; all comments have been replaced by control-A, and the contents of
705 # strings and character constants have been elided.
708 my $cont_in; # currently inside of a continuation
709 my $cont_off; # skipping an initializer or definition
710 my $cont_noerr; # suppress cascading errors
711 my $cont_start; # the line being continued
712 my $cont_base; # the base indentation
713 my $cont_first; # this is the first line of a statement
714 my $cont_multiseg; # this continuation has multiple segments
716 my $cont_special; # this is a C statement (if, for, etc.)
717 my $cont_macro; # this is a macro
718 my $cont_case; # this is a multi-line case
720 my @cont_paren; # the stack of unmatched ( and [s we've seen
733 # replace labels with tabs. Note that there may be multiple
738 while (/^(\t*)( *(?:(?:\w+\s*)|(?:case\b[^:]*)): *)(.*)$/) {
739 my ($pre_tabs, $label, $rest) = ($1, $2, $3);
741 while ($label =~ s/^([^\t]*)(\t+)//) {
742 $_ .= "\t" x
(length($2) + length($1) / 8);
744 $_ .= ("\t" x
(length($label) / 8)).$rest;
754 local $_ = $_[0]; # preserve the global $_
756 s/\ 1//g; # No comments
757 s/\s+$//; # Strip trailing whitespace
759 return if (/^$/); # skip empty lines
761 # regexps used below; keywords taking (), macros, and continued cases
762 my $special = '(?:(?:\}\s*)?else\s+)?(?:if|for|while|switch)\b';
763 my $macro = '[A-Z_][A-Z_0-9]*\(';
764 my $case = 'case\b[^:]*$';
766 # skip over enumerations, array definitions, initializers, etc.
767 if ($cont_off <= 0 && !/^\s*$special/ &&
768 (/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*)){/ ||
769 (/^\s*{/ && $prev =~ /=\s*(?:\/\
*.*\
*\
/\s*)*$/))) {
771 $cont_off = tr/{/{/ - tr/}/}/;
775 $cont_off += tr/{/{/ - tr/}/}/;
783 err
("non-continuation indented 4 spaces");
784 $cont_noerr = 1; # stop reporting
786 $_ = delabel
($_); # replace labels with tabs
788 # check if the statement is complete
789 return if (/^\s*\}?$/);
790 return if (/^\s*\}?\s*else\s*\{?$/);
791 return if (/^\s*do\s*\{?$/);
793 return if (/}[,;]?$/);
795 # Allow macros on their own lines
796 return if (/^\s*[A-Z_][A-Z_0-9]*$/);
798 # cases we don't deal with, generally non-kosher
800 err
("stuff after {");
804 # Get the base line, and set up the state machine
812 # certain things need special processing
813 $cont_special = /^\s*$special/?
1 : 0;
814 $cont_macro = /^\s*$macro/?
1 : 0;
815 $cont_case = /^\s*$case/?
1 : 0;
819 # Strings may be pulled back to an earlier (half-)tabstop
820 unless ($cont_noerr || /^$cont_base / ||
821 (/^\t*(?: )?(?:gettext\()?\"/ && !/^$cont_base\t/)) {
822 err_prefix
($cont_start,
823 "continuation should be indented 4 spaces");
827 my $rest = $_; # keeps the remainder of the line
830 # The split matches 0 characters, so that each 'special' character
831 # is processed separately. Parens and brackets are pushed and
832 # popped off the @cont_paren stack. For normal processing, we wait
833 # until a ; or { terminates the statement. "special" processing
834 # (if/for/while/switch) is allowed to stop when the stack empties,
835 # as is macro processing. Case statements are terminated with a :
836 # and an empty paren stack.
838 foreach $_ (split /[^\(\)\[\]\{\}\;\:]*/) {
839 next if (length($_) == 0);
841 # rest contains the remainder of the line
842 my $rxp = "[^\Q$_\E]*\Q$_\E";
846 push @cont_paren, $_;
847 } elsif (/\)/ || /\]/) {
851 my $old = (pop @cont_paren);
852 if (!defined($old)) {
853 err
("unexpected '$cur'");
856 } elsif ($old ne $_) {
857 err
("'$cur' mismatched with '$old'");
863 # If the stack is now empty, do special processing
864 # for if/for/while/switch and macro statements.
866 next if (@cont_paren != 0);
868 if ($rest =~ /^\s*{?$/) {
872 if ($rest =~ /^\s*;$/) {
873 err
("empty if/for/while body ".
874 "not on its own line");
878 if (!$cont_first && $cont_multiseg == 1) {
879 err_prefix
($cont_start,
880 "multiple statements continued ".
881 "over multiple lines");
883 } elsif ($cont_multiseg == 0) {
886 # We've finished this section, start
887 # processing the next.
899 } elsif (!$cont_special) {
900 err
("unexpected ;") if (@cont_paren != 0);
901 if (!$cont_first && $cont_multiseg == 1) {
902 err_prefix
($cont_start,
903 "multiple statements continued ".
904 "over multiple lines");
906 } elsif ($cont_multiseg == 0) {
913 if ($rest =~ /^\s*special/) {
914 err
("if/for/while/switch not started ".
920 err
("{ while in parens/brackets") if (@cont_paren != 0);
921 err
("stuff after {") if ($rest =~ /[^\s}]/);
925 err
("} while in parens/brackets") if (@cont_paren != 0);
926 if (!$cont_special && $rest !~ /^\s*(while|else)\b/) {
930 err
("stuff after }");
935 } elsif (/\:/ && $cont_case && @cont_paren == 0) {
936 err
("stuff after multi-line case") if ($rest !~ /$^/);
942 # End of a statement or if/while/for loop. Reset
943 # cont_special and cont_macro based on the rest of the
945 $cont_special = ($rest =~ /^\s*$special/)?
1 : 0;
946 $cont_macro = ($rest =~ /^\s*$macro/)?
1 : 0;
950 $cont_noerr = 0 if (!$cont_in);