File: fix.pl

package info (click to toggle)
ximian-setup-tools 0.11.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,432 kB
  • ctags: 3,805
  • sloc: ansic: 28,002; perl: 18,583; sh: 7,683; makefile: 557
file content (138 lines) | stat: -rwxr-xr-x 3,071 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-

# This is a general script to manipulate the GLADE files. It keeps track of 
# the location of the read process using a stack. subst is called every
# time a tag is opened, passing a refference to the stack, the string
# from where the parsing stopped to the eol, and the whole string.

# The first argument must be $(pixmapsdir).

$IN_AA_IMAGE_WIDGET_HACK = 0;
$NO_AA_IMAGE_WIDGET_HACK = 0;

sub image_widget_hack
{
  my ($tag_name, $input) = @_;

     if ($tag_name eq "child" || $tag_name eq "widget") { $IN_AA_IMAGE_WIDGET_HACK = 0; }
  elsif ($tag_name eq "class") { $input =~ s/GnomePixmap/Custom/; }
  elsif ($tag_name eq "name")
  {
    chomp $input;
    $input =~ s/^([ \t]*)(.*)/\1\2\n\1/;
    $input .= "<creation_function>xst_ui_image_widget_create</creation_function>\n";
  }
  elsif ($tag_name eq "filename")
  {
    chomp $input;
    $input =~ s/^([ \t]*)(.*)/\1\2\n\1/;
    $input =~ s/filename>/string1>/g;
    $input .= "<string2></string2><int1>0</int1><int2>0</int2>\n";
  }

  return $input;
}
    

sub subst
{
  my ($stack, $input, $input2) = @_;
  my ($tmp, $pre, $max, $ret);
  
  $input2 =~ /\Q$input\E/;
  $pre = $`;
  $ret = $input2;
  $max = $#stack;

  if (($$stack[$max] eq "name") &&
      ($input =~ /^_[0-9]+/))
  {
    $NO_AA_IMAGE_WIDGET_HACK = 1;
  }

  if ($NO_AA_IMAGE_WIDGET_HACK)
  {
    if (($$stack[$max] eq "class") &&
        ($input =~ /^GnomePixmap/))
    {
      $NO_AA_IMAGE_WIDGET_HACK = 0;
    }
  }
  elsif (($$stack[$max] eq "class") &&
         ($input =~ /^GnomePixmap/)) {
    $IN_AA_IMAGE_WIDGET_HACK = 1;
  }

  if (($$stack[$max - 1] eq "project") &&
	 ($$stack[$max] eq "pixmaps_directory"))
  {
    $input =~ s/^[^<]*//;
    $ret = $pre . $PIXMAPSDIR . $input;
  }
  elsif (($$stack[$max - 1] eq "widget") &&
         ($$stack[$max] eq "filename"))
  {
    $ret = "$pre$PIXMAPSDIR/$input";
  }
  elsif (($$stack[$max] eq "watermark_image") ||
         ($$stack[$max] eq "logo_image"))
  {
    $ret = $pre . "../pixmaps/" . $input;
  }
  
  return &image_widget_hack ($$stack[$max], $ret) if $IN_AA_IMAGE_WIDGET_HACK;
  
  return $ret;
}

my @stack = ();
my $line_no = 0;
my $input;
my $input2;
my $tag;

$PIXMAPSDIR = $ARGV[0];

while ($input = <STDIN>)
{
  
  $input2 = $input;
  $line_no ++;
  
  while ($input =~ s/^[^<]*<([^>]+)>//)
  {
    $tag = $1;
    
    next if ($tag =~ /\/$/); # stand-alone tags. Ignore.
    next if ($tag =~ /\?$/);
    
    if ($tag =~ /^([^\/][^ ]*).*/) # opening tag.
    { 
      push @stack, $1;
      
      # OK, change whatever we may want to change.
      $input2 = &subst (\@stack, $input, $input2);
      
    }
    elsif ($tag =~ /^\/([^ ]*).*/) # closing tag.
    {
      if ($1 eq $stack[$#stack]) # Check sane nesting.
      {
        pop @stack;
      }
      else
      {	
        print STDERR "Excess closing tag \"$1\" at line $line_no.\n";
      }
    }
  }
  
  print $input2;
}

foreach $i (@stack)
{
  print STDERR "Unclosed tag \"$i\" at end of file.\n";
}