1#!/usr/bin/perl -w 2 3# bpmf-sqlconvert.pl: convert bpmf.cin into SQLite database 4# 5# Copyright (c) 2004-2006 The OpenVanilla Project (http://openvanilla.org) 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 12# 1. Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 3. Neither the name of OpenVanilla nor the names of its contributors 18# may be used to endorse or promote products derived from this software 19# without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31# POSSIBILITY OF SUCH DAMAGE. 32 33use strict; 34 35print "begin;\n"; 36while(<>) { 37 if (/%chardef/) { 38 parse_chardef(); 39 } 40 elsif (/%keyname/) { 41 parse_keyname(); 42 } 43 else { 44 parse_property(); 45 } 46} 47print "commit;\n"; 48 49sub parse_property { 50 my @a=split; 51 return if (!scalar(@a)); 52 if ($a[0] =~ /^%.+/) { $a[0]=substr($a[0], 1, length($a[0])-1); } 53 $a[0] =~ s/\'/\'\'/g; 54 if ($a[1]) { $a[1] =~ s/\'/\'\'/g; } else { $a[1]="" }; 55 printf "insert into bpmf values ('_property_%s\', '%s\', -1);\n", lc $a[0], $a[1]; 56} 57 58sub parse_keyname { 59 while(<>) { 60 last if (/%keyname/); 61 my @a=split; 62 $a[0] =~ s/\'/\'\'/g; 63 $a[1] =~ s/\'/\'\'/g; 64 printf "insert into bpmf values ('_key_%s\', '%s', -1);\n", lc $a[0], $a[1]; 65 } 66} 67 68sub parse_chardef { 69 my ($lastbpmf, $lastorder)=("", 0); 70 while (<>) { 71 chomp; 72 last if /%chardef/; 73 my @a=split; 74 if ($a[0] eq $lastbpmf) { 75 $lastorder++; 76 } 77 else 78 { 79 $lastorder=0; 80 $lastbpmf=$a[0]; 81 } 82 $a[0] =~ s/\'/\'\'/g; 83 $a[1] =~ s/\'/\'\'/g; 84 printf "insert into bpmf values('%s', '%s', %s);\n", sprintf("%s", $a[0]), $a[1], $lastorder; 85 } 86} 87