Skip to content

Commit

Permalink
optlib2c: escape a double quote char in a description string with bac…
Browse files Browse the repository at this point in the history
…kslash

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake authored and dreamtigers committed Mar 1, 2019
1 parent 8f20f8c commit 352a49a
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions misc/optlib2c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,23 @@ sub emit_patterns {
emit_list $_[0], "patterns";
}

sub escape_dquotes {
my $input = shift;
my $output = "";

my $c;

foreach $c (split //, $input) {
if ($c eq '"') {
$output = $output . '\\' . '"';
} else {
$output = $output . $c;
}
}

return $output;
}

sub emit_roledefs {
my $opts = shift;

Expand All @@ -580,8 +597,9 @@ sub emit_roledefs {
static roleDefinition $opts->{'Clangdef'}${Kind}RoleTable [] = {
EOF
for (@{$_->{'roles'}}) {
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{ true, "$_->{'name'}", "$_->{'desc'}" },
{ true, "$_->{'name'}", "$desc" },
EOF
}

Expand Down Expand Up @@ -652,8 +670,9 @@ EOF
print <<EOF;
{
EOF
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
$enabled, \'$_->{'letter'}\', "$_->{'name'}", "$_->{'desc'}",
$enabled, \'$_->{'letter'}\', "$_->{'name'}", "$desc",
EOF
if ($_->{'refonly'}) {
print <<EOF;
Expand Down Expand Up @@ -744,11 +763,12 @@ sub emit_xtags {
EOF
for (@{$opts->{'extradefs'}}) {
my $enabled = $_->{"enabled"}? "true": "false";
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{
.enabled = $enabled,
.name = "$_->{'name'}",
.description = "$_->{'desc'}",
.description = "$desc",
},
EOF
}
Expand All @@ -767,11 +787,12 @@ sub emit_fields {
EOF
for (@{$opts->{'fielddefs'}}) {
my $enabled = $_->{"enabled"}? "true": "false";
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{
.enabled = $enabled,
.name = "$_->{'name'}",
.description = "$_->{'desc'}",
.description = "$desc",
},
EOF
}
Expand Down

0 comments on commit 352a49a

Please sign in to comment.