Skip to content

Instantly share code, notes, and snippets.

@yatsuta
Created November 22, 2016 14:20
Show Gist options
  • Save yatsuta/14eb9c5c5cdee1aacbf02491418779bd to your computer and use it in GitHub Desktop.
Save yatsuta/14eb9c5c5cdee1aacbf02491418779bd to your computer and use it in GitHub Desktop.
indent C headers for readability
$reserved = 0;
$indent = 0;
while (<>) {
if ($reserved) {
$indent++;
$reserved = 0;
}
if (/^#if/) {
$reserved = 1;
}
if (/^#else/) {
$indent--;
$reserved = 1;
}
if (/^#endif/) {
$indent--;
}
$space = "";
for ($i = 0; $i < $indent; $i++) {$space .= "__";}
print ($space . $_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment