1#!/usr/bin/env perl
2#
3# This file is part of the LibreOffice project.
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8#
9
10sub loadData()
11{
12    open (IN, "<custom-shapes.log");
13
14    my %sources;
15
16    while (<IN>)
17    {
18        if (/==csdata== /)
19        {
20            if (/shape name: '/)
21            {
22                chop;
23                s/.*shape name: '([^']+)'.*/$1/;
24                $name = $_;
25            }
26            else
27            {
28                if (/==csdata== begin/)
29                {
30                    $inside = true;
31                    @code = ();
32                }
33                else
34                {
35                    if (/==csdata== end/)
36                    {
37                        s/^  <\/([^>]+)>/$1/;
38                        undef $inside;
39                        $sources{$name} = [ @code ];
40                    }
41                }
42            }
43        }
44        else
45        {
46            if ($inside)
47            {
48                push @code, $_;
49            }
50        }
51    }
52
53    close (IN);
54
55    return \%sources;
56}
57
58sub generateData
59{
60    my $sources = shift;
61    open (OUT, ">oox-drawingml-cs-presets");
62
63    foreach $shape (sort(keys %$sources))
64    {
65        printf OUT "/* %s */\n", $shape;
66        print OUT @{$sources->{$shape}};
67    }
68
69    close OUT;
70}
71
72generateData(loadData());
73
74# vim:set ft=perl shiftwidth=4 softtabstop=4 expandtab: #
75