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
195 printf $fmt, $filename, $., $error, $line;
197 printf $fmt, $filename, $., $error;
204 my ($prevline, $error) = @_;
205 my $out = $prevline."\n".$line;
208 printf $fmt, $filename, $., $error, $out;
210 printf $fmt, $filename, $., $error;
220 printf $fmt, $filename, $. - 1, $error, $prev;
222 printf $fmt, $filename, $. - 1, $error;
230 my ($fn, $filehandle) = @_;
231 $filename = $fn; # share it globally
237 my $in_header_comment = 0;
238 my $comment_done = 0;
239 my $in_warlock_comment = 0;
241 my $in_function_header = 0;
242 my $in_declaration = 0;
249 my ($okmsg, $comment_prefix);
255 line: while (<$filehandle>) {
256 s/\r?\n$//; # strip return and newline
258 # save the original line, then remove all text from within
259 # double or single quotes, we do not want to check such text.
264 # C allows strings to be continued with a backslash at the end of
265 # the line. We translate that into a quoted string on the previous
266 # line followed by an initial quote on the next line.
268 # (we assume that no-one will use backslash-continuation with character
271 $_ = '"' . $_ if ($in_string && !$nocheck && !$in_comment);
274 # normal strings and characters
276 s/'([^\\']|\\[^xX0]|\\0[0-9]*|\\[xX][0-9a-fA-F]*)'/''/g;
277 s/"([^\\"]|\\.)*"/\"\"/g;
280 # detect string continuation
282 if ($nocheck || $in_comment) {
286 # Now that all full strings are replaced with "", we check
287 # for unfinished strings continuing onto the next line.
290 (s/([^"](?:"")*)"([^\\"]|\\.)*\\$/$1""/ ||
291 s/^("")*"([^\\"]|\\.)*\\$/""/);
295 # figure out if we are in a cpp directive
297 $in_cpp = $next_in_cpp || /^\s*#/; # continued or started
298 $next_in_cpp = $in_cpp && /\\$/; # only if continued
300 # strip off trailing backslashes, which appear in long macros
303 # an /* END CSTYLED */ comment ends a no-check block.
305 if (/\/\* *END *CSTYLED *\*\//) {
313 # a /*CSTYLED*/ comment indicates that the next line is ok.
320 if (/\/\* *CSTYLED.*\*\//) {
321 /^.*\/\* *CSTYLED *(.*) *\*\/.*$/;
330 # check length of line.
331 # first, a quick check to see if there is any chance of being too long.
332 if (($line =~ tr/\t/\t/) * 7 + length($line) > 80) {
333 # yes, there is a chance.
334 # replace tabs with spaces and check again.
337 s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
338 if (length($eline) > 80) {
339 err("line > 80 characters");
343 # ignore NOTE(...) annotations (assumes NOTE is on lines by itself).
344 if ($note_level || /\b_?NOTE\s*\(/) { # if in NOTE or this is NOTE
345 s/[^()]//g; # eliminate all non-parens
346 $note_level += s/\(//g - length; # update paren nest level
350 # a /* BEGIN CSTYLED */ comment starts a no-check block.
351 if (/\/\* *BEGIN *CSTYLED *\*\//) {
355 # a /*CSTYLED*/ comment indicates that the next line is ok.
356 if (/\/\* *CSTYLED.*\*\//) {
357 /^.*\/\* *CSTYLED *(.*) *\*\/.*$/;
361 if (/\/\/ *CSTYLED/) {
362 /^.*\/\/ *CSTYLED *(.*)$/;
367 # universal checks; apply to everything
369 err("spaces between tabs");
372 err("tabs between spaces");
375 err("space or tab at end of line");
377 if (/[^ \t(]\/\*/ && !/\w\(\/\*.*\*\/\);/) {
378 err("comment preceded by non-blank");
381 # is this the beginning or ending of a function?
382 # (not if "struct foo\n{\n")
383 if (/^{$/ && $prev =~ /\)\s*(const\s*)?(\/\*.*\*\/\s*)?\\?$/) {
386 $in_function_header = 0;
390 if (/^}\s*(\/\*.*\*\/\s*)*$/) {
391 if ($prev =~ /^\s*return\s*;/) {
392 err_prev("unneeded return at end of function");
395 reset_indent(); # we don't check between functions
400 $in_function_header = 1;
403 if ($in_warlock_comment && /\*\//) {
404 $in_warlock_comment = 0;
409 # a blank line terminates the declarations within a function.
410 # XXX - but still a problem in sub-blocks.
411 if ($in_declaration && /^$/) {
417 $in_header_comment = 0;
420 # does this looks like the start of a block comment?
421 if (/$hdr_comment_start/) {
423 err
("block comment not indented by tabs");
427 $comment_prefix = $1;
428 if ($comment_prefix eq "") {
429 $in_header_comment = 1;
434 # are we still in the block comment?
436 if (/^$comment_prefix \*\/$/) {
440 err
("improper block comment close")
441 unless ($ignore_hdr_comment && $in_header_comment);
442 } elsif (!/^$comment_prefix \*[ \t]/ &&
443 !/^$comment_prefix \*$/) {
444 err
("improper block comment")
445 unless ($ignore_hdr_comment && $in_header_comment);
449 if ($in_header_comment && $ignore_hdr_comment) {
454 # check for errors that might occur in comments and in code.
456 # allow spaces to be used to draw pictures in all comments.
457 if (/[^ ] / && !/".* .*"/ && !$in_comment) {
458 err
("spaces instead of tabs");
460 if (/^ / && !/^ \*[ \t\/]/ && !/^ \
*$/ &&
461 (!/^ \w/ || $in_function != 0)) {
462 err
("indent by spaces instead of tabs");
464 if (/^\t+ [^ \t\*]/ || /^\t+ \S/ || /^\t+ \S/) {
465 err
("continuation line not indented by 4 spaces");
467 if (/$warlock_re/ && !/\*\//) {
468 $in_warlock_comment = 1;
472 if (/^\s*\/\
*./ && !/^\s
*\
/\*.*\*\// && !/$hdr_comment_start/) {
473 err
("improper first line of block comment");
476 if ($in_comment) { # still in comment, don't do further checks
481 if ((/[^(]\/\
*\S
/ || /^\
/\*\S/) &&
482 !(/$lint_re/ || ($splint_comments && /$splint_re/))) {
483 err
("missing blank after open comment");
485 if (/\S\*\/[^)]|\S\
*\
/$/ &&
486 !(/$lint_re/ || ($splint_comments && /$splint_re/))) {
487 err
("missing blank before close comment");
489 if (/\/\
/\S/) { # C++ comments
490 err
("missing blank after start comment");
492 # check for unterminated single line comments, but allow them when
493 # they are used to comment out the argument list of a function
495 if (/\S.*\/\
*/ && !/\S
.*\
/\*.*\*\// && !/\
(\
/\*/) {
496 err
("unterminated single line comment");
499 if (/^(#else|#endif|#include)(.*)$/) {
504 # Enforce ANSI rules for #else and #endif: no noncomment
505 # identifiers are allowed after #endif or #else. Allow
506 # C++ comments since they seem to be a fact of life.
507 if ((($1 eq "#endif") || ($1 eq "#else")) &&
509 (!($clause =~ /^\s+\/\
*.*\
*\
/$/)) &&
510 (!($clause =~ /^\s+\/\
/.*$/))) {
511 err
("non-comment text following " .
512 "$directive (or malformed $directive " .
520 # delete any comments and check everything else. Note that
521 # ".*?" is a non-greedy match, so that we don't get confused by
522 # multiple comments on the same line.
525 s/\/\/.*$/\ 1/; # C++ comments
527 # delete any trailing whitespace; we have already checked for that.
530 # following checks do not apply to text in comments.
532 if (/[^<>\s][!<>=]=/ || /[^<>][!<>=]=[^\s,]/ ||
533 (/[^->]>[^,=>\s]/ && !/[^->]>$/) ||
534 (/[^<]<[^,=<\s]/ && !/[^<]<$/) ||
535 /[^<\s]<[^<]/ || /[^->\s]>[^>]/) {
536 err
("missing space around relational operator");
538 if (/\S>>=/ || /\S<<=/ || />>=\S/ || /<<=\S/ || /\S[-+*\/&|^%]=/ ||
539 (/[^-+*\/&|^%!<>=\s
]=[^=]/ && !/[^-+*\
/&|^%!<>=\s]=$/) ||
540 (/[^!<>=]=[^=\s]/ && !/[^!<>=]=$/)) {
541 # XXX - should only check this for C++ code
542 # XXX - there are probably other forms that should be allowed
543 if (!/\soperator=/) {
544 err
("missing space around assignment operator");
547 if (/[,;]\S/ && !/\bfor \(;;\)/) {
548 err
("comma or semicolon followed by non-blank");
550 # allow "for" statements to have empty "while" clauses
551 if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
552 err
("comma or semicolon preceded by blank");
554 if (/^\s*(&&|\|\|)/) {
555 err
("improper boolean continuation");
557 if (/\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
558 err
("more than one space around boolean operator");
560 if (/\b(for|if|while|switch|sizeof|return|case)\(/) {
561 err
("missing space between keyword and paren");
563 if (/(\b(for|if|while|switch|return)\b.*){2,}/ && !/^#define/) {
564 # multiple "case" and "sizeof" allowed
565 err
("more than one keyword on line");
567 if (/\b(for|if|while|switch|sizeof|return|case)\s\s+\(/ &&
569 err
("extra space between keyword and paren");
571 # try to detect "func (x)" but not "if (x)" or
572 # "#define foo (x)" or "int (*func)();"
575 # strip off all keywords on the line
576 s/\b(for|if|while|switch|return|case|sizeof)\s\(/XXX(/g;
578 s/^#define\s+\w+\s+\(/XXX(/;
579 # do not match things like "void (*f)();"
580 # or "typedef void (func_t)();"
582 s/\b($typename|void)\s+\(+/XXX(/og;
584 err
("extra space between function name and left paren");
588 # try to detect "int foo(x)", but not "extern int foo(x);"
589 # XXX - this still trips over too many legitimate things,
590 # like "int foo(x,\n\ty);"
591 # if (/^(\w+(\s|\*)+)+\w+\(/ && !/\)[;,](\s|\ 1)*$/ &&
592 # !/^(extern|static)\b/) {
593 # err("return type of function not on separate line");
595 # this is a close approximation
596 if (/^(\w+(\s|\*)+)+\w+\(.*\)(\s|\ 1)*$/ &&
597 !/^(extern|static)\b/) {
598 err
("return type of function not on separate line");
601 err
("#define followed by space instead of tab");
603 if (/^\s*return\W[^;]*;/ && !/^\s*return\s*\(.*\);/) {
604 err
("unparenthesized return expression");
606 if (/\bsizeof\b/ && !/\bsizeof\s*\(.*\)/) {
607 err
("unparenthesized sizeof expression");
610 err
("whitespace after left paren");
612 # Allow "for" statements to have empty "continue" clauses.
613 # Allow right paren on its own line unless we're being picky (-p).
614 if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/ && ($picky || !/^\s*\)/)) {
615 err
("whitespace before right paren");
617 if (/^\s*\(void\)[^ ]/) {
618 err
("missing space after (void) cast");
620 if (/\S\{/ && !/\{\{/) {
621 err
("missing space before left brace");
623 if ($in_function && /^\s+{/ &&
624 ($prev =~ /\)\s*$/ || $prev =~ /\bstruct\s+\w+$/)) {
625 err
("left brace starting a line");
627 if (/}(else|while)/) {
628 err
("missing space after right brace");
630 if (/}\s\s+(else|while)/) {
631 err
("extra space after right brace");
633 if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
634 err
("obsolete use of VOID or STATIC");
636 if (/\b$typename\*/o) {
637 err
("missing space between type name and *");
640 err
("preprocessor statement not in column 1");
643 err
("blank after preprocessor #");
645 if (/!\s*(strcmp|strncmp|bcmp)\s*\(/) {
646 err
("don't use boolean ! with comparison functions");
650 # We completely ignore, for purposes of indentation:
651 # * lines outside of functions
652 # * preprocessor lines
654 if ($check_continuation && $in_function && !$in_cpp) {
658 # try to detect spaces after casts, but allow (e.g.)
659 # "sizeof (int) + 1", "void (*funcptr)(int) = foo;", and
660 # "int foo(int) __NORETURN;"
661 if ((/^\($typename( \*+)?\)\s/o ||
662 /\W\($typename( \*+)?\)\s/o) &&
663 !/sizeof\s*\($typename( \*)?\)\s/o &&
664 !/\($typename( \*+)?\)\s+=[^=]/o) {
665 err
("space after cast");
667 if (/\b$typename\s*\*\s/o &&
668 !/\b$typename\s*\*\s+const\b/o) {
669 err
("unary * followed by space");
672 if ($check_posix_types) {
673 # try to detect old non-POSIX types.
674 # POSIX requires all non-standard typedefs to end in _t,
675 # but historically these have been used.
676 if (/\b(unchar|ushort|uint|ulong|u_int|u_short|u_long|u_char|quad)\b/) {
677 err
("non-POSIX typedef $1 used: use $old2posix{$1} instead");
681 # cannot check this everywhere due to "struct {\n...\n} foo;"
682 if ($in_function && !$in_declaration &&
683 /}./ && !/}\s+=/ && !/{.*}[;,]$/ && !/}(\s|\ 1)*$/ &&
684 !/} (else|while)/ && !/}}/) {
685 err
("possible bad text following right brace");
687 # cannot check this because sub-blocks in
688 # the middle of code are ok
689 if ($in_function && /^\s+{/) {
690 err
("possible left brace starting a line");
694 if ($prev =~ /^\s*}$/) {
696 "else and right brace should be on same line");
703 err
("last line in file is blank");
709 # Continuation-line checking
711 # The rest of this file contains the code for the continuation checking
712 # engine. It's a pretty simple state machine which tracks the expression
713 # depth (unmatched '('s and '['s).
715 # Keep in mind that the argument to process_indent() has already been heavily
716 # processed; all comments have been replaced by control-A, and the contents of
717 # strings and character constants have been elided.
720 my $cont_in; # currently inside of a continuation
721 my $cont_off; # skipping an initializer or definition
722 my $cont_noerr; # suppress cascading errors
723 my $cont_start; # the line being continued
724 my $cont_base; # the base indentation
725 my $cont_first; # this is the first line of a statement
726 my $cont_multiseg; # this continuation has multiple segments
728 my $cont_special; # this is a C statement (if, for, etc.)
729 my $cont_macro; # this is a macro
730 my $cont_case; # this is a multi-line case
732 my @cont_paren; # the stack of unmatched ( and [s we've seen
745 # replace labels with tabs. Note that there may be multiple
750 while (/^(\t*)( *(?:(?:\w+\s*)|(?:case\b[^:]*)): *)(.*)$/) {
751 my ($pre_tabs, $label, $rest) = ($1, $2, $3);
753 while ($label =~ s/^([^\t]*)(\t+)//) {
754 $_ .= "\t" x
(length($2) + length($1) / 8);
756 $_ .= ("\t" x
(length($label) / 8)).$rest;
766 local $_ = $_[0]; # preserve the global $_
768 s/\ 1//g; # No comments
769 s/\s+$//; # Strip trailing whitespace
771 return if (/^$/); # skip empty lines
773 # regexps used below; keywords taking (), macros, and continued cases
774 my $special = '(?:(?:\}\s*)?else\s+)?(?:if|for|while|switch)\b';
775 my $macro = '[A-Z_][A-Z_0-9]*\(';
776 my $case = 'case\b[^:]*$';
778 # skip over enumerations, array definitions, initializers, etc.
779 if ($cont_off <= 0 && !/^\s*$special/ &&
780 (/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*)){/ ||
781 (/^\s*{/ && $prev =~ /=\s*(?:\/\
*.*\
*\
/\s*)*$/))) {
783 $cont_off = tr/{/{/ - tr/}/}/;
787 $cont_off += tr/{/{/ - tr/}/}/;
795 err
("non-continuation indented 4 spaces");
796 $cont_noerr = 1; # stop reporting
798 $_ = delabel
($_); # replace labels with tabs
800 # check if the statement is complete
801 return if (/^\s*\}?$/);
802 return if (/^\s*\}?\s*else\s*\{?$/);
803 return if (/^\s*do\s*\{?$/);
805 return if (/}[,;]?$/);
807 # Allow macros on their own lines
808 return if (/^\s*[A-Z_][A-Z_0-9]*$/);
810 # cases we don't deal with, generally non-kosher
812 err
("stuff after {");
816 # Get the base line, and set up the state machine
824 # certain things need special processing
825 $cont_special = /^\s*$special/?
1 : 0;
826 $cont_macro = /^\s*$macro/?
1 : 0;
827 $cont_case = /^\s*$case/?
1 : 0;
831 # Strings may be pulled back to an earlier (half-)tabstop
832 unless ($cont_noerr || /^$cont_base / ||
833 (/^\t*(?: )?(?:gettext\()?\"/ && !/^$cont_base\t/)) {
834 err_prefix
($cont_start,
835 "continuation should be indented 4 spaces");
839 my $rest = $_; # keeps the remainder of the line
842 # The split matches 0 characters, so that each 'special' character
843 # is processed separately. Parens and brackets are pushed and
844 # popped off the @cont_paren stack. For normal processing, we wait
845 # until a ; or { terminates the statement. "special" processing
846 # (if/for/while/switch) is allowed to stop when the stack empties,
847 # as is macro processing. Case statements are terminated with a :
848 # and an empty paren stack.
850 foreach $_ (split /[^\(\)\[\]\{\}\;\:]*/) {
851 next if (length($_) == 0);
853 # rest contains the remainder of the line
854 my $rxp = "[^\Q$_\E]*\Q$_\E";
858 push @cont_paren, $_;
859 } elsif (/\)/ || /\]/) {
863 my $old = (pop @cont_paren);
864 if (!defined($old)) {
865 err
("unexpected '$cur'");
868 } elsif ($old ne $_) {
869 err
("'$cur' mismatched with '$old'");
875 # If the stack is now empty, do special processing
876 # for if/for/while/switch and macro statements.
878 next if (@cont_paren != 0);
880 if ($rest =~ /^\s*{?$/) {
884 if ($rest =~ /^\s*;$/) {
885 err
("empty if/for/while body ".
886 "not on its own line");
890 if (!$cont_first && $cont_multiseg == 1) {
891 err_prefix
($cont_start,
892 "multiple statements continued ".
893 "over multiple lines");
895 } elsif ($cont_multiseg == 0) {
898 # We've finished this section, start
899 # processing the next.
911 } elsif (!$cont_special) {
912 err
("unexpected ;") if (@cont_paren != 0);
913 if (!$cont_first && $cont_multiseg == 1) {
914 err_prefix
($cont_start,
915 "multiple statements continued ".
916 "over multiple lines");
918 } elsif ($cont_multiseg == 0) {
925 if ($rest =~ /^\s*special/) {
926 err
("if/for/while/switch not started ".
932 err
("{ while in parens/brackets") if (@cont_paren != 0);
933 err
("stuff after {") if ($rest =~ /[^\s}]/);
937 err
("} while in parens/brackets") if (@cont_paren != 0);
938 if (!$cont_special && $rest !~ /^\s*(while|else)\b/) {
942 err
("stuff after }");
947 } elsif (/\:/ && $cont_case && @cont_paren == 0) {
948 err
("stuff after multi-line case") if ($rest !~ /$^/);
954 # End of a statement or if/while/for loop. Reset
955 # cont_special and cont_macro based on the rest of the
957 $cont_special = ($rest =~ /^\s*$special/)?
1 : 0;
958 $cont_macro = ($rest =~ /^\s*$macro/)?
1 : 0;
962 $cont_noerr = 0 if (!$cont_in);