summaryrefslogtreecommitdiffstats
path: root/vespalib/fix-hg.pl
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/fix-hg.pl
Publish
Diffstat (limited to 'vespalib/fix-hg.pl')
-rwxr-xr-xvespalib/fix-hg.pl50
1 files changed, 50 insertions, 0 deletions
diff --git a/vespalib/fix-hg.pl b/vespalib/fix-hg.pl
new file mode 100755
index 00000000000..19b41492591
--- /dev/null
+++ b/vespalib/fix-hg.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+foreach $arg ( @ARGV ) {
+ $hgd = $arg; # maybe: . "_";
+ $hgd =~ s{\W}{_}g;
+ $hgd =~ tr{a-z}{A-Z};
+ $hgd =~ s{^_*}{H_};
+
+# print "arg $arg header guard $hgd\n";
+
+ open(FOO, $arg) or die "Cannot open '$arg'\n";
+ $backup = $arg . ".orig";
+ rename ($arg, $backup);
+
+ open(ARGVOUT, ">$arg") or die "cannot write to '$arg'\n";
+ select(ARGVOUT);
+
+ my $eic = 0;
+ my $cnt = 1;
+
+ while (<FOO>) {
+ ++$eic if m{#endif} ;
+ }
+ seek FOO, 0, 0;
+ while (<FOO>) {
+ if ($cnt == 1 and m{^#ifndef}) {
+ s{\s.*}{ $hgd};
+ ++$cnt;
+ }
+ if ($cnt == 2 and m{^#define}) {
+ s{\s.*}{ $hgd};
+ ++$cnt;
+ }
+ if ( m{#endif} ) {
+ --$eic;
+ if ($eic == 0) {
+ s{.*#endif.*}{#endif // header guard};
+ }
+ }
+ print;
+ }
+ close(FOO);
+ select(STDOUT);
+ close(ARGVOUT);
+
+ unlink($backup);
+}
+
+exit 0;