summaryrefslogtreecommitdiffstats
path: root/ksvg/scripts/add_static.pl
blob: 9a88c00fd3f0eb78102819af6d340ff5ba04f7c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Add #include "ksvg_lookup.h", GENERATEDDATA and ELEMENTDATA to all headers passed as argument
# Usage: perl -w -i.bak add_static.pl *.h
my $added_ksvg_lookup = 0;
#my $added_staticdata = 0;
my $inclass=0;
my $bracelevel=0;
my $class_bracelevel;
my $has_staticdata=0;
while (<>) {
  $added_ksvg_lookup=0 if (/\#ifndef/); # this while loop runs over multiple files...
  $added_ksvg_lookup=1 if (/\#include \"ksvg_lookup.h\"/); # already there
  if (!$added_ksvg_lookup) {
    if (/^\s*\#\s*include/ || /^namespace/ || /^class/) {
      $added_ksvg_lookup = 1;
      print '#include "ksvg_lookup.h"' . "\n";
    }
  }
  if ( /^class/ && !/;/ ) {
    die if $inclass;
    $inclass=1;
    $class_bracelevel=$bracelevel;
    $has_staticdata=0;
  }
  if ( /{/ ) {
    $bracelevel++;
    die if /{.*{/; # not handled currently
  }
  if ( /}/ ) {
    $bracelevel--;
    die if /}.*}/; # not handled currently
  }
  $has_staticdata = 1 if ( $inclass && /GENERATEDDATA/ );
  if ( $inclass && ($class_bracelevel == $bracelevel) && /};/ ) {
    print "public:\n\tGENERATEDDATA\n" if ( !$has_staticdata );
    $inclass=0;
    # $added_staticdata=1;
  }
  print;
}
die "still in class!" if ($inclass);
die "bracelevel != 0!" if ($bracelevel);
#die "found no class where to add GENERATEDDATA!" if (!$added_staticdata);