File: update-plugin-xref.pl

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (277 lines) | stat: -rwxr-xr-x 9,861 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/perl
#############################################################################
##    Kwave                - update-plugin-xref.pl
##                           -------------------
##    begin                : Sat Mar 28 2015
##    copyright            : (C) 2015 by Thomas Eschenbacher
##    email                : Thomas.Eschenbacher@gmx.de
#############################################################################
#
#############################################################################
##                                                                          #
##    This program is free software; you can redistribute it and/or modify  #
##    it under the terms of the GNU General Public License as published by  #
##    the Free Software Foundation; either version 2 of the License, or     #
##    (at your option) any later version.                                   #
##                                                                          #
#############################################################################

# split argument string
my $src_dir = $ARGV[0];
my $in      = $ARGV[1];
my $out     = $ARGV[2];

open(IN,  "<" . $in ) or die "cannot open input file "  . $in;
open(OUT, ">" . $out) or die "cannot open output file " . $out;

my @scanned_plugins;

sub scan_file
{
    local $file = shift;
#     print "scanning file: '" . $file . "'\n";

    local $name;
    local $version;
    local $description;
    local $author;

    open(IN2, $file);
    while (<IN2>) {
        local $line = $_;
        chomp $line;

        $name        = $1 if ($line =~ /^Name=([\w]+)\s*/ );
        $version     = $1 if ($line =~ /^X-KDE-PluginInfo-Name=(\d+\.\d+)/ );
        $description = $1 if ($line =~ /^Comment=(.+)\s*/ );
        $author      = $1 if ($line =~ /^X-KDE-PluginInfo-Author=(.+)\s*/ );
    }
    close(IN2);

#     print "', '" . $name;
#     print "', '" . $version;
#     print "', '" . $description;
#     print "', '" . $author;
#     print "'\n";

    push(@scanned_plugins, {
        name        => $name,
        version     => $version,
        description => $description,
        author      => $author
    }) if (! grep {$_->{name} eq $name} @scanned_plugin);

}

sub scan_plugin_dir
{
    local $path = shift;

    opendir(DIR, $path) or die "opendir $path: $!";
    local @dirs = grep { !/(^\.)/ } readdir(DIR);
    closedir(DIR);
    @dirs = grep(!/common/, @dirs);
    @dirs = sort { $a cmp $b } @dirs;

    for (@dirs) {
        local $dir = $path . '/' . $_;
        if (-d $dir) {
            opendir(SUBDIR, $dir) or die "opendir $dir: $!";
            local @files = grep { !/(^\.)/ } readdir(SUBDIR);
            closedir(SUBDIR);
            @files = sort { $a cmp $b } @files;
            for (@files) {
                local $file = $_;
                if ($file =~ /\.desktop.in$/) {
                    scan_file $dir . '/' . $file;
                }
            }
        }
    }
}

sub make_stub
{
    local $plugin = shift;
    local $lbl = $plugin->{name};
    print OUT "    \<\!-- \@PLUGIN\@ " . $plugin->{name} . " (TODO) --\>\n";
    $lbl =~ s/[^\w]/_/g;

    print OUT "    <sect1 id=\"plugin_sect_" . $lbl . "\">" .
              "<title id=\"plugin_title_" . $lbl . "\">" .
              "&no-i18n-plugin_" . $lbl . "; (" . $plugin->{description} . ")</title>\n";

    print OUT "    <!-- <screenshot>\n";
    print OUT "\t<screeninfo>Screenshot</screeninfo>\n";
    print OUT "\t<mediaobject>\n";
    print OUT "\t    <imageobject>\n";
    print OUT "\t\t<imagedata fileref=\"kwave-plugin-" . $lbl . ".png\" format=\"PNG\"/>\n";
    print OUT "\t    </imageobject>\n";
    print OUT "\t    <textobject>\n";
    print OUT "\t\t<phrase>Screenshot of the " . $plugin->{description} . " Plugin</phrase>\n";
    print OUT "\t    </textobject>\n";
    print OUT "\t</mediaobject>\n";
    print OUT "    </screenshot> -->\n";

    print OUT "    <variablelist>\n";
    print OUT "\t<varlistentry>\n";
    print OUT "\t    <term><emphasis role=\"bold\">&i18n-plugin_lbl_internal_name;</emphasis></term>\n";
    print OUT "\t    <listitem><para><literal>&no-i18n-plugin_" . $lbl . ";</literal></para></listitem>\n";
    print OUT "\t</varlistentry>\n";

    print OUT "\t<varlistentry>\n";
    print OUT "\t    <term><emphasis role=\"bold\">&i18n-plugin_lbl_type;</emphasis></term>\n";
    print OUT "\t    <listitem><para>effect|codec|encoder|decoder|gui|function</para></listitem>\n";
    print OUT "\t</varlistentry>\n";

    print OUT "\t<varlistentry>\n";
    print OUT "\t    <term><emphasis role=\"bold\">&i18n-plugin_lbl_description;</emphasis></term>\n";
    print OUT "\t    <listitem>\n";
    print OUT "\t    <para>\n";
    print OUT "\t        TODO: description of what the " . $plugin->{description} . " plugin does...\n";
    print OUT "\t    </para>\n";
    print OUT "\t    </listitem>\n";
    print OUT "\t</varlistentry>\n";

    print OUT "\t<!-- varlistentry>\n";
    print OUT "\t    <term><emphasis role=\"bold\">&i18n-plugin_lbl_parameters;</emphasis>:</term>\n";
    print OUT "\t    <listitem>\n";
    print OUT "\t\t<variablelist>\n";
    print OUT "\t\t    <varlistentry>\n";
    print OUT "\t\t\t<term><replaceable>operation</replaceable></term>\n";
    print OUT "\t\t\t<listitem>\n";
    print OUT "\t\t\t    <para>\n";
    print OUT "\t\t\t\tdescription of the parameter\n";
    print OUT "\t\t\t    </para>\n";
    print OUT "\t\t\t</listitem>\n";
    print OUT "\t\t    </varlistentry>\n";
    print OUT "\t\t</variablelist>\n";
    print OUT "\t    </listitem>\n";
    print OUT "\t</varlistentry -->\n";

    print OUT "    </variablelist>\n";
    print OUT "    </sect1>\n";
    print OUT "\n";
}

#
# scan the list of all plugins
#
scan_plugin_dir($src_dir);
my @remaining_plugins = @scanned_plugins;

my $mode = "normal";

LINE: while (<IN>) {
    my $line = $_;

    if ($mode eq "normal") {

        if ($line =~ /\<\!\-\-\ \@PLUGIN_INDEX_START\@\ \-\-\>/) {
            print OUT $line;
            $mode = "index";
            next LINE;
        }

        if ($line =~ /\<\!\-\-\ \@PLUGIN_ENTITIES_START\@\ \-\-\>/) {
            print OUT $line;
            $mode = "entities";
            next LINE;
        }

        if ($line =~ /\<\!\-\-\ \@PLUGIN\@\ ([\w\:]+)\ (\(TODO\)\ )?\-\-\>/) {
            my $plugin = $1;
            my $todo = $2;
            # print "### found plugin '" . $plugin . "'\n";
            if (not grep {$_->{name} eq $plugin} @scanned_plugins) {
                print STDERR "WARNING: plugin '" . $plugin . "' is not supported / does not exist\n";
            } else {
                while (@remaining_plugins) {
                    my $next_plugin = shift @remaining_plugins;

                    # if plugin is next in list of remaining -> remove from list
                    # print "next_plugin=".$next_plugin.", plugin=".$plugin."\n";
                    if ($plugin eq $next_plugin->{name}) {
                        # print "(FOUND)\n";
                        # show a warning if there documentation is not finished
                        # for this plugin
                        if ($todo) {
                            print STDERR "WARNING: plugin '" . $plugin . "': documentation is not finished (TODO)\n";
                        }
                        print OUT $line;
                        next LINE;
                    }

                    if ($plugin gt $next_plugin->{name}) {
                        print STDERR "WARNING: plugin '" . $next_plugin->{name} . "' is undocumented, adding stub\n";
                        make_stub $next_plugin;
                    } else {
                        last;
                    }
                }
            }
            print OUT $line;
            next LINE;
        }

        if ($line =~ /\<\!\-\-\ \@PLUGIN_END_OF_LIST\@\ \-\-\>/) {
            # print "WARNING: some plugins left\n";
            while (@remaining_plugins) {
                local $plugin = shift @remaining_plugins;
                print STDERR "WARNING: plugin '" . $plugin->{name} . "' is undocumented, adding stub\n";
                make_stub $plugin;
            }
        }

        print OUT $line;
    }

    if ($line =~ /\<\!\-\-\ \@PLUGIN_ENTITIES_END\@\ \-\-\>/) {
        foreach (@scanned_plugins) {
            local $plugin = $_->{name};
            local $lbl = $plugin;
            $lbl =~ s/[^\w]/_/g;
            print OUT "  \<\!ENTITY no-i18n-plugin_" . $lbl . " \"" . $plugin . "\"\>\n";
        }
        print OUT $line;
        $mode = "normal";
        next LINE;
    }

    if ($mode eq "index") {
        if ($line =~ /\<\!\-\-\ \@PLUGIN_INDEX_END\@\ \-\-\>/) {

            # create a new plugin index
            my $first_char = "*";
            foreach (@scanned_plugins) {
                my $plugin = $_->{name};
                my $first = substr($plugin, 0, 1);
                if (not ($first eq $first_char)) {
                    print OUT "\t    </indexdiv>\n" if (not ($first_char eq "*"));
                    print OUT "\t    <indexdiv><title>" . $first . "</title>\n";
                    $first_char = $first;
                }

                $plugin =~ s/[^\w]/_/g;
                print OUT "\t\t<indexentry><primaryie>" .
                    "<link linkend=\"plugin_sect_" . $plugin . "\" " .
                    "endterm=\"plugin_title_" . $plugin . "\"/>" .
                    "</primaryie></indexentry>\n";

            }
            print OUT "\t    </indexdiv>\n";

            # switch back to normal mode
            $mode = "normal";
            print OUT $line;
            next LINE;
        }
    }

}

close(IN);
close(OUT);

#############################################################################
#############################################################################