Skip to content

Commit

Permalink
scripts/kernel-doc: Escape all literal braces in regexes
Browse files Browse the repository at this point in the history
Commit 701b3a3 ("PATCH scripts/kernel-doc") fixed the two
instances of literal braces that Perl 5.28 warns about, but there are
still more than it doesn't warn about.

Escape all left braces that are treated as literal characters.  Also
escape literal right braces, for consistency and to avoid confusing
bracket-matching in text editors.

Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Jonathan Corbet <[email protected]>
  • Loading branch information
bwhacks authored and Jonathan Corbet committed Aug 6, 2018
1 parent 0bf1bd8 commit 673bb2d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scripts/kernel-doc
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ sub dump_struct($$) {
my $x = shift;
my $file = shift;

if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}/) {
my $decl_type = $1;
$declaration_name = $2;
my $members = $3;
Expand Down Expand Up @@ -1148,20 +1148,20 @@ sub dump_struct($$) {
}
}
}
$members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/;
$members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/;
}

# Ignore other nested elements, like enums
$members =~ s/(\{[^\{\}]*})//g;
$members =~ s/(\{[^\{\}]*\})//g;

create_parameterlist($members, ';', $file, $declaration_name);
check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);

# Adjust declaration for better display
$declaration =~ s/([{;])/$1\n/g;
$declaration =~ s/}\s+;/};/g;
$declaration =~ s/([\{;])/$1\n/g;
$declaration =~ s/\}\s+;/};/g;
# Better handle inlined enums
do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/);
do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);

my @def_args = split /\n/, $declaration;
my $level = 1;
Expand All @@ -1171,12 +1171,12 @@ sub dump_struct($$) {
$clause =~ s/\s+$//;
$clause =~ s/\s+/ /;
next if (!$clause);
$level-- if ($clause =~ m/(})/ && $level > 1);
$level-- if ($clause =~ m/(\})/ && $level > 1);
if (!($clause =~ m/^\s*#/)) {
$declaration .= "\t" x $level;
}
$declaration .= "\t" . $clause . "\n";
$level++ if ($clause =~ m/(\{)/ && !($clause =~m/}/));
$level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
}
output_declaration($declaration_name,
'struct',
Expand Down Expand Up @@ -1244,7 +1244,7 @@ sub dump_enum($$) {
# strip #define macros inside enums
$x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;

if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
if ($x =~ /enum\s+(\w+)\s*\{(.*)\}/) {
$declaration_name = $1;
my $members = $2;
my %_members;
Expand Down Expand Up @@ -1785,7 +1785,7 @@ sub process_proto_type($$) {
}

while (1) {
if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
if( length $prototype ) {
$prototype .= " "
}
Expand Down

0 comments on commit 673bb2d

Please sign in to comment.