Skip to content

Instantly share code, notes, and snippets.

@mignon-p
Created March 2, 2026 01:13
Show Gist options
  • Select an option

  • Save mignon-p/8811912fb57f3c05bfef6982cc25582a to your computer and use it in GitHub Desktop.

Select an option

Save mignon-p/8811912fb57f3c05bfef6982cc25582a to your computer and use it in GitHub Desktop.
Fix declaration-after-label problem in Lite3
#!/usr/bin/perl -w -i
# This script fixes the declaration-after-label problem that occurs
# in three files in Lite3:
#
# src/json_dec.c
# src/json_enc.c
# src/lite3.c
#
# It fixes the problem by inserting a semicolon after the label.
# Now the files will compile with a C11 compiler, rather than
# requiring a C23 compiler.
#
# Because of the "-i" option on the shebang line, this script will
# edit the files in-place. So you can just do:
#
# fix-lite3-labels.pl src/json_dec.c src/json_enc.c src/lite3.c
use strict;
my $hadColon = 0;
my $inComment = 0;
while (<>) {
if ($inComment) {
$inComment = 0 if (m%\*/%);
} else {
if (m%^\s*/\*+\s*$%) {
$inComment = 1;
} elsif (/:\s*$/) {
$hadColon = 1;
} elsif ($hadColon and (/^\s+if/ or
/^\s+while/ or
/^\s+for/ or
/^\s+switch/)) {
$hadColon = 0;
} elsif ($hadColon and /^(\s+)[\w]+[\s\*]+\w+/) {
my $indent = $1;
print $indent, ";";
print "\r" if (/\r/);
print "\n";
$hadColon = 0;
} elsif (not /^\s*$/) {
$hadColon = 0;
}
}
print;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment