summaryrefslogtreecommitdiffstats
path: root/kabc/scripts/makeaddressee
blob: cbc69543ad8045d07dfaf9bb08af21c6204061ce (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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/perl

my $srcdir;
$srcdir = `dirname $0` || die "Can't determine \$srcdir.";
chomp $srcdir;

if (!open( ENTRIES, "$srcdir/entrylist" ) ) {
  print "Can't open $srcdir/entrylist\n";
  exit 1;
}

  while(<ENTRIES>) {
    if (/^#/) { next; }
    chop;
    @entries = split /,/;
    if (!/^.+,(\w+),(\w+)/) { next; }
    push @entryCtrl, @entries[0];
    push @entryRealNames, @entries[1];
    push @entryComments, @entries[2];
    push @entryTypes, @entries[3];
    push @entryNames, @entries[4];
    push @entryCategory, @entries[5];
    push @entryDebug, @entries[6];
  }

close ENTRIES;

if (!open( H_IN, "$srcdir/addressee.src.h" ) ) {
  print "Can't open $srcdir/addressee.src.h\n";
  exit 1;
}
if (!open( H_OUT, ">../addressee.h" ) ) {
  print "Can't open addressee.h\n";
  exit 1;
}
  print H_OUT "/*** Warning! This file has been generated by the script makeaddressee ***/\n";

  while( <H_IN> ) {
    if (/--DECLARATIONS--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] =~ /A/ ) {
          print H_OUT "    /**\n";
          print H_OUT "      Set $entryRealNames[$i].\n";
          print H_OUT "     */\n";
          print H_OUT "    void set" . ucfirst($entryNames[$i]);
          print H_OUT "( const $entryTypes[$i] &$entryNames[$i] );\n";

          print H_OUT "    /**\n";
          print H_OUT "      Return $entryRealNames[$i].\n";
          print H_OUT "     */\n";
          print H_OUT "    $entryTypes[$i] $entryNames[$i]() const;\n";
        }

        if ( $entryCtrl[$i] !~ /L/ ) { next; }
        print H_OUT "    /**\n";
        print H_OUT "      Return translated label for $entryNames[$i] field.\n";
        print H_OUT "     */\n";
        print H_OUT "    static QString $entryNames[$i]Label();\n\n";
      }
    } else {
      print H_OUT;
    }
  }

close H_OUT;
close H_IN;

if (!open( CPP_IN, "$srcdir/addressee.src.cpp" ) ) {
  print "Can't open $srcdir/addressee.src.cpp\n";
  exit 1;
}
if (!open( CPP_OUT, ">../addressee.cpp" ) ) {
  print "Can't open addressee.cpp\n";
  exit 1;
}
  print CPP_OUT "/*** Warning! This file has been generated by the script makeaddressee ***/\n";

  while( <CPP_IN> ) {
    if (/--VARIABLES--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /A/ ) { next; }
        print CPP_OUT "  $entryTypes[$i] $entryNames[$i];\n";
      }
    } elsif (/--DEFINITIONS--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] =~ /A/ ) {
          print CPP_OUT "void Addressee::set" . ucfirst($entryNames[$i]);
          print CPP_OUT "( const $entryTypes[$i] &$entryNames[$i] )\n{\n";        
          print CPP_OUT "  if ( $entryNames[$i] == mData->$entryNames[$i] ) return;\n";
          print CPP_OUT "  detach();\n  mData->empty = false;\n";
          print CPP_OUT "  mData->$entryNames[$i] = $entryNames[$i];\n}\n\n";
        
          print CPP_OUT "$entryTypes[$i] Addressee::$entryNames[$i]() const\n{\n";
          print CPP_OUT "  return mData->$entryNames[$i];\n}\n\n";
        }

        if ( $entryCtrl[$i] !~ /L/ ) { next; }
        @labelwords = split ' ', $entryRealNames[$i];
        for( $j=0; $j < @labelwords; ++$j ) {
          $labelwords[$j] = ucfirst $labelwords[$j];
        }
        $label = join ' ', @labelwords;
        print CPP_OUT "QString Addressee::$entryNames[$i]Label()\n{\n";
        if ( $entryComments[$i] ) {
          print CPP_OUT "  return i18n(\"$entryComments[$i]\",\"$label\");\n";
        } else {
          print CPP_OUT "  return i18n(\"$label\");\n";
        }
        print CPP_OUT "}\n\n\n";
      }
    } elsif (/--EQUALSTEST--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] =~ /E/ ) {
          if ( $entryNames[$i] !~ "revision" ) {
            if ( $entryTypes[$i] =~ "QString" ) {
              print CPP_OUT "  if ( mData->$entryNames[$i] != a.mData->$entryNames[$i] &&\n";
              print CPP_OUT "     !( mData->$entryNames[$i].isEmpty() && a.mData->$entryNames[$i].isEmpty() ) ) {\n";
              print CPP_OUT "    kdDebug(5700) << \"$entryNames[$i] differs\" << endl;\n";
              print CPP_OUT "    return false;\n";
              print CPP_OUT "  }\n";
            } else {
              print CPP_OUT "  if ( mData->$entryNames[$i] != a.mData->$entryNames[$i] ) {\n";
              print CPP_OUT "    kdDebug(5700) << \"$entryNames[$i] differs\" << endl;\n";
              print CPP_OUT "    return false;\n";
              print CPP_OUT "  }\n";
            }
          }
        }
      }        
    } elsif (/--STREAMOUT--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] =~ /A/ ) {
          print CPP_OUT "  s << a.mData->$entryNames[$i];\n";
        }
      }        
    } elsif (/--STREAMIN--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] =~ /A/ ) {
          print CPP_OUT "  s >> a.mData->$entryNames[$i];\n";
        }
      }        
    } elsif (/--DEBUG--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /A/ ) { next; }
        print CPP_OUT "  kdDebug(5700) << \"  " . ucfirst($entryNames[$i]);
        print CPP_OUT ": '\" << $entryNames[$i]()$entryDebug[$i] << \"'\" << endl;\n";
      }
    } else {
      print CPP_OUT;
    }
  }

close CPP_OUT;
close CPP_IN;

if (!open( CPP_IN, "$srcdir/field.src.cpp" ) ) {
  print "Can't open $srcdir/field.src.cpp\n";
  exit 1;
}
if (!open( CPP_OUT, ">../field.cpp" ) ) {
  print "Can't open field.cpp\n";
  exit 1;
}
  print CPP_OUT "/*** Warning! This file has been generated by the script makeaddressee ***/\n";

  while( <CPP_IN> ) {
    if (/--ENUMS--/) {
      $first = 1;
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /F/ ) { next; }
        if ( $first ) { $first = 0; }
        else { print CPP_OUT ",\n"; }
        print CPP_OUT "      " . ucfirst($entryNames[$i]);
      }
      print CPP_OUT "\n";
    } elsif (/--CASELABEL--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /F/ ) { next; }
        if ( $entryCtrl[$i] !~ /L/ ) { next; }
        print CPP_OUT "    case FieldImpl::" . ucfirst($entryNames[$i]) . ":\n";
        print CPP_OUT "      return Addressee::$entryNames[$i]Label();\n";
      }
    } elsif (/--CASEVALUE--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /A/ ) { next; }
        if ( $entryCtrl[$i] !~ /F/ ) { next; }
        if ( $entryTypes[$i] ne "QString" ) { next; }
        print CPP_OUT "    case FieldImpl::" . ucfirst($entryNames[$i]) . ":\n";
        print CPP_OUT "      return a.$entryNames[$i]();\n";
      }
    } elsif (/--CASESETVALUE--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /A/ ) { next; }
        if ( $entryCtrl[$i] !~ /F/ ) { next; }
        if ( $entryTypes[$i] ne "QString" ) { next; }
        print CPP_OUT "    case FieldImpl::" . ucfirst($entryNames[$i]) . ":\n";
        print CPP_OUT "      a.set" . ucfirst($entryNames[$i]) . "( value );\n";
        print CPP_OUT "      return true;\n";
      }
    } elsif (/--CREATEFIELDS--/) {
      for( $i=0; $i<@entryNames; ++$i ) {
        if ( $entryCtrl[$i] !~ /F/ ) { next; }
        print CPP_OUT "    createField( FieldImpl::" . ucfirst($entryNames[$i]);
        if ( $entryCategory[$i] ) {
          print CPP_OUT ", $entryCategory[$i]";
        }
        print CPP_OUT " );\n";
      }
    } else {
      print CPP_OUT;
    }
  }

close CPP_OUT;
close CPP_IN;